Hi,

In hvn_alloc_cmd() we spin within a mutex while the freelist is empty.
Because we're using a mutex there is no way to miss the wakeup(9) from
hvn_free_cmd(), so we don't even need a timeout here.  Instead of
doing msleep(9) for 1 tick repeatedly we can msleep_nsec(9) without a
timeout (INFSLP) repeatedly and poll less in this spot.

Once again I can't test this.  But the principle of protecting the
sleep with a mutex is sound.

ok?

Index: if_hvn.c
===================================================================
RCS file: /cvs/src/sys/dev/pv/if_hvn.c,v
retrieving revision 1.43
diff -u -p -r1.43 if_hvn.c
--- if_hvn.c    4 Dec 2020 03:22:46 -0000       1.43
+++ if_hvn.c    4 Dec 2020 03:35:25 -0000
@@ -1127,8 +1127,8 @@ hvn_alloc_cmd(struct hvn_softc *sc)
 
        mtx_enter(&sc->sc_cntl_fqlck);
        while ((rc = TAILQ_FIRST(&sc->sc_cntl_fq)) == NULL)
-               msleep(&sc->sc_cntl_fq, &sc->sc_cntl_fqlck,
-                   PRIBIO, "nvsalloc", 1);
+               msleep_nsec(&sc->sc_cntl_fq, &sc->sc_cntl_fqlck,
+                   PRIBIO, "nvsalloc", INFSLP);
        TAILQ_REMOVE(&sc->sc_cntl_fq, rc, rc_entry);
        mtx_leave(&sc->sc_cntl_fqlck);
        return (rc);

Reply via email to