ciss(4): tsleep(9) -> tsleep_nsec(9)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ciss(4): tsleep(9) -> tsleep_nsec(9)

Scott Cheloha
Now that we've separated the sleeping path and the busy-waiting path
we can remove the ticks.

"i" is a count of milliseconds here.  Convert it to a timespec to
get a starting interval "ts" and add that to the current time "now"
to get an absolute timeout "end".

Then we chip away at it as we loop through until the poll succeeds or
we reach "end".

An absolute timeout version of tsleep would be better here but we
don't have one yet, so this is the best we can do.

ok?

Index: ic/ciss.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ciss.c,v
retrieving revision 1.77
diff -u -p -r1.77 ciss.c
--- ic/ciss.c 23 Jan 2020 00:30:59 -0000 1.77
+++ ic/ciss.c 23 Jan 2020 00:50:30 -0000
@@ -442,13 +442,15 @@ cissminphys(struct buf *bp, struct scsi_
 int
 ciss_cmd(struct ciss_ccb *ccb, int flags, int wait)
 {
+ struct timespec end, now, ts;
  struct ciss_softc *sc = ccb->ccb_sc;
  struct ciss_cmd *cmd = &ccb->ccb_cmd;
  struct ciss_ccb *ccb1;
  bus_dmamap_t dmap = ccb->ccb_dmamap;
  u_int64_t addr;
+ uint64_t nsecs;
  u_int32_t id;
- int i, tohz, error = 0;
+ int i, error = 0, ret;
 
  splassert(IPL_BIO);
 
@@ -522,29 +524,27 @@ ciss_cmd(struct ciss_ccb *ccb, int flags
  if (!(wait & SCSI_POLL))
  return (error);
 
- struct timeval tv;
- int etick;
  CISS_DPRINTF(CISS_D_CMD, ("waiting "));
 
  i = ccb->ccb_xs? ccb->ccb_xs->timeout : 60000;
- tv.tv_sec = i / 1000;
- tv.tv_usec = (i % 1000) * 1000;
- tohz = tvtohz(&tv);
- if (tohz == 0)
- tohz = 1;
 
  if (!(wait & SCSI_NOSLEEP)) {
- for (etick = tick + tohz;;) {
+ NSEC_TO_TIMESPEC(MSEC_TO_NSEC(i), &ts);
+ nanouptime(&now);
+ timespecadd(&now, &ts, &end);
+
+ for (;;) {
  ccb->ccb_state = CISS_CCB_POLL;
- CISS_DPRINTF(CISS_D_CMD, ("tsleep(%d) ", tohz));
- if (tsleep(ccb, PRIBIO + 1, "ciss_cmd",
-    tohz) == EWOULDBLOCK) {
+ nsecs = TIMESPEC_TO_NSEC(&ts);
+ CISS_DPRINTF(CISS_D_CMD, ("tsleep_nsec(%llu) ", nsecs));
+ ret = tsleep_nsec(ccb, PRIBIO + 1, "ciss_cmd", nsecs);
+ if (ret == EWOULDBLOCK)
  break;
- }
  if (ccb->ccb_state != CISS_CCB_ONQ) {
- tohz = etick - tick;
- if (tohz <= 0)
+ nanouptime(&now);
+ if (timespeccmp(&end, &now, <=))
  break;
+ timespecsub(&end, &now, &ts);
  CISS_DPRINTF(CISS_D_CMD, ("T"));
  continue;
  }