Re: lpt(4): timeout_add(9) -> timeout_add_msec(9), tsleep(9) -> tsleep_nsec(9)

2020-01-15 Thread Scott Cheloha
On Wed, Jan 15, 2020 at 11:08:04AM +0100, Martin Pieuchot wrote:
> On 14/01/20(Tue) 18:37, Scott Cheloha wrote:
> > Ticks to milliseconds.
> > [...]
> > @@ -303,16 +304,17 @@ lptpushbytes(struct lpt_softc *sc)
> > while (NOT_READY()) {
> > if (++spin < sc->sc_spinmax)
> > continue;
> > -   tic = 0;
> > +   msecs = 10;
> > /* adapt busy-wait algorithm */
> > sc->sc_spinmax++;
> > while (NOT_READY_ERR()) {
> > /* exponential backoff */
> > -   tic = tic + tic + 1;
> > -   if (tic > TIMEOUT)
> > -   tic = TIMEOUT;
> > -   error = tsleep((caddr_t)sc,
> > -   LPTPRI | PCATCH, "lptpsh", tic);
> > +   msecs = msecs + msecs + 1;
> 
> Shouldn't the backoff algorithm be:
> 
>   msecs = 0;
>   while (/* not ready */) {
>   msecs = msecs + msecs + 10;
>   ...
>   }

Yep, that'd be closer to the original.

Index: ic/lpt.c
===
RCS file: /cvs/src/sys/dev/ic/lpt.c,v
retrieving revision 1.14
diff -u -p -r1.14 lpt.c
--- ic/lpt.c11 May 2015 02:01:01 -  1.14
+++ ic/lpt.c15 Jan 2020 16:07:26 -
@@ -71,8 +71,8 @@
 
 #include "lpt.h"
 
-#defineTIMEOUT hz*16   /* wait up to 16 seconds for a ready */
-#defineSTEPhz/4
+#defineTIMEOUT 16000   /* wait up to 16 seconds for a ready */
+#defineSTEP250 /* 1/4 seconds */
 
 #defineLPTPRI  (PZERO+8)
 #defineLPT_BSIZE   1024
@@ -199,7 +199,8 @@ lptopen(dev_t dev, int flag, int mode, s
}
 
/* wait 1/4 second, give up if we get a signal */
-   error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "lptopen", STEP);
+   error = tsleep_nsec(sc, LPTPRI | PCATCH, "lptopen",
+   MSEC_TO_NSEC(STEP));
if (sc->sc_state == 0)
return (EIO);
if (error != EWOULDBLOCK) {
@@ -256,7 +257,7 @@ lptwakeup(void *arg)
splx(s);
 
if (sc->sc_state != 0)
-   timeout_add(>sc_wakeup_tmo, STEP);
+   timeout_add_msec(>sc_wakeup_tmo, STEP);
 }
 
 /*
@@ -293,7 +294,7 @@ lptpushbytes(struct lpt_softc *sc)
int error;
 
if (sc->sc_flags & LPT_NOINTR) {
-   int spin, tic;
+   int msecs, spin;
u_int8_t control = sc->sc_control;
 
while (sc->sc_count > 0) {
@@ -303,16 +304,17 @@ lptpushbytes(struct lpt_softc *sc)
while (NOT_READY()) {
if (++spin < sc->sc_spinmax)
continue;
-   tic = 0;
+   msecs = 0;
/* adapt busy-wait algorithm */
sc->sc_spinmax++;
while (NOT_READY_ERR()) {
/* exponential backoff */
-   tic = tic + tic + 1;
-   if (tic > TIMEOUT)
-   tic = TIMEOUT;
-   error = tsleep((caddr_t)sc,
-   LPTPRI | PCATCH, "lptpsh", tic);
+   msecs = msecs + msecs + 10;
+   if (msecs > TIMEOUT)
+   msecs = TIMEOUT;
+   error = tsleep_nsec(sc,
+   LPTPRI | PCATCH, "lptpsh",
+   MSEC_TO_NSEC(msecs));
if (sc->sc_state == 0)
error = EIO;
if (error != EWOULDBLOCK)
@@ -345,8 +347,8 @@ lptpushbytes(struct lpt_softc *sc)
}
if (sc->sc_state == 0)
return (EIO);
-   error = tsleep((caddr_t)sc, LPTPRI | PCATCH,
-   "lptwrite2", 0);
+   error = tsleep_nsec(sc, LPTPRI | PCATCH,
+   "lptwrite2", INFSLP);
if (sc->sc_state == 0)
error = EIO;
if (error)



Re: lpt(4): timeout_add(9) -> timeout_add_msec(9), tsleep(9) -> tsleep_nsec(9)

2020-01-15 Thread Martin Pieuchot
On 14/01/20(Tue) 18:37, Scott Cheloha wrote:
> Ticks to milliseconds.
> [...]
> @@ -303,16 +304,17 @@ lptpushbytes(struct lpt_softc *sc)
>   while (NOT_READY()) {
>   if (++spin < sc->sc_spinmax)
>   continue;
> - tic = 0;
> + msecs = 10;
>   /* adapt busy-wait algorithm */
>   sc->sc_spinmax++;
>   while (NOT_READY_ERR()) {
>   /* exponential backoff */
> - tic = tic + tic + 1;
> - if (tic > TIMEOUT)
> - tic = TIMEOUT;
> - error = tsleep((caddr_t)sc,
> - LPTPRI | PCATCH, "lptpsh", tic);
> + msecs = msecs + msecs + 1;

Shouldn't the backoff algorithm be:

msecs = 0;
while (/* not ready */) {
msecs = msecs + msecs + 10;
...
}



lpt(4): timeout_add(9) -> timeout_add_msec(9), tsleep(9) -> tsleep_nsec(9)

2020-01-14 Thread Scott Cheloha
Ticks to milliseconds.

I've changed "tic" to "msecs" in the backoff loop to make the units
more obvious.  I went with 10ms as the starting sleep.  A perfect
conversion would start at something like (tick / 1000), but obviously
we're trying to move away from that sort of thing.  Absent a better
idea, 10ms seems safe.

Everything else here is straightforward.

ok?

Index: ic/lpt.c
===
RCS file: /cvs/src/sys/dev/ic/lpt.c,v
retrieving revision 1.14
diff -u -p -r1.14 lpt.c
--- ic/lpt.c11 May 2015 02:01:01 -  1.14
+++ ic/lpt.c15 Jan 2020 00:33:47 -
@@ -71,8 +71,8 @@
 
 #include "lpt.h"
 
-#defineTIMEOUT hz*16   /* wait up to 16 seconds for a ready */
-#defineSTEPhz/4
+#defineTIMEOUT 16000   /* wait up to 16 seconds for a ready */
+#defineSTEP250 /* 1/4 seconds */
 
 #defineLPTPRI  (PZERO+8)
 #defineLPT_BSIZE   1024
@@ -199,7 +199,8 @@ lptopen(dev_t dev, int flag, int mode, s
}
 
/* wait 1/4 second, give up if we get a signal */
-   error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "lptopen", STEP);
+   error = tsleep_nsec(sc, LPTPRI | PCATCH, "lptopen",
+   MSEC_TO_NSEC(STEP));
if (sc->sc_state == 0)
return (EIO);
if (error != EWOULDBLOCK) {
@@ -256,7 +257,7 @@ lptwakeup(void *arg)
splx(s);
 
if (sc->sc_state != 0)
-   timeout_add(>sc_wakeup_tmo, STEP);
+   timeout_add_msec(>sc_wakeup_tmo, STEP);
 }
 
 /*
@@ -293,7 +294,7 @@ lptpushbytes(struct lpt_softc *sc)
int error;
 
if (sc->sc_flags & LPT_NOINTR) {
-   int spin, tic;
+   int msecs, spin;
u_int8_t control = sc->sc_control;
 
while (sc->sc_count > 0) {
@@ -303,16 +304,17 @@ lptpushbytes(struct lpt_softc *sc)
while (NOT_READY()) {
if (++spin < sc->sc_spinmax)
continue;
-   tic = 0;
+   msecs = 10;
/* adapt busy-wait algorithm */
sc->sc_spinmax++;
while (NOT_READY_ERR()) {
/* exponential backoff */
-   tic = tic + tic + 1;
-   if (tic > TIMEOUT)
-   tic = TIMEOUT;
-   error = tsleep((caddr_t)sc,
-   LPTPRI | PCATCH, "lptpsh", tic);
+   msecs = msecs + msecs + 1;
+   if (msecs > TIMEOUT)
+   msecs = TIMEOUT;
+   error = tsleep_nsec(sc,
+   LPTPRI | PCATCH, "lptpsh",
+   MSEC_TO_NSEC(msecs));
if (sc->sc_state == 0)
error = EIO;
if (error != EWOULDBLOCK)
@@ -345,8 +347,8 @@ lptpushbytes(struct lpt_softc *sc)
}
if (sc->sc_state == 0)
return (EIO);
-   error = tsleep((caddr_t)sc, LPTPRI | PCATCH,
-   "lptwrite2", 0);
+   error = tsleep_nsec(sc, LPTPRI | PCATCH,
+   "lptwrite2", INFSLP);
if (sc->sc_state == 0)
error = EIO;
if (error)