Hi,

I'd like to convert all of the wait loops in hvn(4) and hyperv(4) from
using ticks to using real units of time.

Most of them use tsleep(9), so let's do tsleep(9) -> tsleep_nsec(9)
conversions first.

In every case there is an adjacent delay(9) call we use if the kernel
is cold.  I assume it's okay to give the same interval to tsleep_nsec(9)
as we do to delay(9).

mikeb@: This compiles on amd64 but I can't test it.  Can you verify
that these changes don't break anything?

If so, ok?

Also: The loop in hvn_rndis_cmd() delays for 100 microseconds while
all the other loops in that driver delay for 1000 microseconds.  Just
wanted to make sure this was intentional.  I'm sure it's fine, it just
stuck out to me as a possible typo.

Index: if_hvn.c
===================================================================
RCS file: /cvs/src/sys/dev/pv/if_hvn.c,v
retrieving revision 1.42
diff -u -p -r1.42 if_hvn.c
--- if_hvn.c    30 Aug 2020 10:36:33 -0000      1.42
+++ if_hvn.c    2 Dec 2020 17:50:42 -0000
@@ -1048,8 +1048,10 @@ hvn_nvs_cmd(struct hvn_softc *sc, void *
                if (rv == EAGAIN) {
                        if (cold)
                                delay(1000);
-                       else
-                               tsleep(cmd, PRIBIO, "nvsout", 1);
+                       else {
+                               tsleep_nsec(cmd, PRIBIO, "nvsout",
+                                   USEC_TO_NSEC(1000));
+                       }
                } else if (rv) {
                        DPRINTF("%s: NVSP operation %u send error %d\n",
                            sc->sc_dev.dv_xname, hdr->nvs_type, rv);
@@ -1069,8 +1071,10 @@ hvn_nvs_cmd(struct hvn_softc *sc, void *
        do {
                if (cold)
                        delay(1000);
-               else
-                       tsleep(sc, PRIBIO | PCATCH, "nvscmd", 1);
+               else {
+                       tsleep_nsec(sc, PRIBIO | PCATCH, "nvscmd",
+                           USEC_TO_NSEC(1000));
+               }
                s = splnet();
                hvn_nvs_intr(sc);
                splx(s);
@@ -1366,8 +1370,10 @@ hvn_rndis_cmd(struct hvn_softc *sc, stru
                if (rv == EAGAIN) {
                        if (cold)
                                delay(100);
-                       else
-                               tsleep(rc, PRIBIO, "rndisout", 1);
+                       else {
+                               tsleep_nsec(rc, PRIBIO, "rndisout",
+                                   USEC_TO_NSEC(100));
+                       }
                } else if (rv) {
                        DPRINTF("%s: RNDIS operation %u send error %d\n",
                            sc->sc_dev.dv_xname, hdr->rm_type, rv);
@@ -1388,8 +1394,10 @@ hvn_rndis_cmd(struct hvn_softc *sc, stru
        do {
                if (cold)
                        delay(1000);
-               else
-                       tsleep(rc, PRIBIO | PCATCH, "rndiscmd", 1);
+               else {
+                       tsleep_nsec(rc, PRIBIO | PCATCH, "rndiscmd",
+                           USEC_TO_NSEC(1000));
+               }
                s = splnet();
                hvn_nvs_intr(sc);
                splx(s);
Index: hyperv.c
===================================================================
RCS file: /cvs/src/sys/dev/pv/hyperv.c,v
retrieving revision 1.46
diff -u -p -r1.46 hyperv.c
--- hyperv.c    6 Jul 2020 13:33:09 -0000       1.46
+++ hyperv.c    2 Dec 2020 17:50:42 -0000
@@ -558,8 +558,10 @@ hv_start(struct hv_softc *sc, struct hv_
                        s = splnet();
                        hv_intr();
                        splx(s);
-               } else
-                       tsleep(wchan, PRIBIO, wchan, 1);
+               } else {
+                       tsleep_nsec(wchan, PRIBIO, wchan,
+                           USEC_TO_NSEC(delays[i]));
+               }
        }
        if (status != 0) {
                printf("%s: posting vmbus message failed with %d\n",
@@ -620,8 +622,10 @@ hv_wait(struct hv_softc *sc, int (*cond)
                        s = splnet();
                        hv_intr();
                        splx(s);
-               } else
-                       tsleep(wchan, PRIBIO, wmsg ? wmsg : "hvwait", 1);
+               } else {
+                       tsleep_nsec(wchan, PRIBIO, wmsg ? wmsg : "hvwait",
+                           USEC_TO_NSEC(1000));
+               }
        }
 }
 

Reply via email to