On Mon, Feb 17, 2020 at 07:40:40PM -0500, Kenneth R Westerback wrote:
> On Mon, Feb 17, 2020 at 06:23:01PM -0600, Scott Cheloha wrote:
> > On Sat, Jan 11, 2020 at 02:57:14AM -0600, Scott Cheloha wrote:
> > > The sleep duration is in milliseconds.  We can rip out the timeval and
> > > tvtohz(9) and use MSEC_TO_NSEC() directly instead.  I've added a local
> > > "msecs" variable because "timo" (a) feels a bit ambiguous and (b) is
> > > used with different units earlier in the same function.
> > > 
> > > [...]
> > 
> > Bump and rebase.
> > 
> > This is a straightforward ticks-to-milliseconds change.  We also kill
> > off one of the remaining tvtohz(9) calls.
> > 
> > ok?
> 
> Looks good to me. But can't timo be deleted by using the new msec in
> the for loop above? ok krw@ either way.

timo is used in the SCSI_NOSLEEP path.

... while we're here we can pick a better variable name,
though.

Does this look alright to you?  Instead of ten thousand
100-microsecond chunks we count out each of the million
microseconds in the for-loop.

Index: ips.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/ips.c,v
retrieving revision 1.117
diff -u -p -r1.117 ips.c
--- ips.c       14 Feb 2020 18:37:03 -0000      1.117
+++ ips.c       18 Feb 2020 15:10:01 -0000
@@ -1409,8 +1409,7 @@ ips_cmd(struct ips_softc *sc, struct ips
 int
 ips_poll(struct ips_softc *sc, struct ips_ccb *ccb)
 {
-       struct timeval tv;
-       int error, timo;
+       int error, msecs, usecs;
 
        splassert(IPL_BIO);
 
@@ -1419,7 +1418,7 @@ ips_poll(struct ips_softc *sc, struct ip
                DPRINTF(IPS_D_XFER, ("%s: ips_poll: busy-wait\n",
                    sc->sc_dev.dv_xname));
 
-               for (timo = 10000; timo > 0; timo--) {
+               for (usecs = 1000000; usecs > 0; usecs -= 100) {
                        delay(100);
                        ips_intr(sc);
                        if (ccb->c_state == IPS_CCB_DONE)
@@ -1427,14 +1426,11 @@ ips_poll(struct ips_softc *sc, struct ip
                }
        } else {
                /* sleep */
-               timo = ccb->c_xfer ? ccb->c_xfer->timeout : IPS_TIMEOUT;
-               tv.tv_sec = timo / 1000;
-               tv.tv_usec = (timo % 1000) * 1000;
-               timo = tvtohz(&tv);
+               msecs = ccb->c_xfer ? ccb->c_xfer->timeout : IPS_TIMEOUT;
 
-               DPRINTF(IPS_D_XFER, ("%s: ips_poll: sleep %d hz\n",
-                   sc->sc_dev.dv_xname, timo));
-               tsleep(ccb, PRIBIO + 1, "ipscmd", timo);
+               DPRINTF(IPS_D_XFER, ("%s: ips_poll: sleep %d ms\n",
+                   sc->sc_dev.dv_xname, msecs));
+               tsleep_nsec(ccb, PRIBIO + 1, "ipscmd", MSEC_TO_NSEC(msecs));
        }
        DPRINTF(IPS_D_XFER, ("%s: ips_poll: state %d\n", sc->sc_dev.dv_xname,
            ccb->c_state));

Reply via email to