Hi,

softraid(4) is another driver still using tsleep(9).

softraid(4) uses tsleep(9) in one spot to poll for completion.  It
uses it in two other spots to momentarily yield the CPU to permit a
different thread to make progress.

In all cases the length of the timeout is totally arbitrary.  We're
just spinning or yielding.  The duration doesn't matter much.

Currently we tsleep(9) for up to 1 tick.  Instead let's tsleep_nsec(9)
for 1 millisecond.

ok?

Index: softraid.c
===================================================================
RCS file: /cvs/src/sys/dev/softraid.c,v
retrieving revision 1.416
diff -u -p -r1.416 softraid.c
--- softraid.c  15 Oct 2020 00:13:47 -0000      1.416
+++ softraid.c  4 Dec 2020 03:29:20 -0000
@@ -3885,7 +3885,7 @@ sr_discipline_shutdown(struct sr_discipl
        if (sd->sd_reb_active) {
                sd->sd_reb_abort = 1;
                while (sd->sd_reb_active)
-                       tsleep(sd, PWAIT, "sr_shutdown", 1);
+                       tsleep_nsec(sd, PWAIT, "sr_shutdown", MSEC_TO_NSEC(1));
        }
 
        if (meta_save)
@@ -4765,7 +4765,7 @@ sr_rebuild(struct sr_discipline *sd)
                }
                /* yield if we didn't sleep */
                if (slept == 0)
-                       tsleep(sc, PWAIT, "sr_yield", 1);
+                       tsleep_nsec(sc, PWAIT, "sr_yield", MSEC_TO_NSEC(1));
 
                sr_scsi_wu_put(sd, wu_r);
                sr_scsi_wu_put(sd, wu_w);
Index: softraid_raid5.c
===================================================================
RCS file: /cvs/src/sys/dev/softraid_raid5.c,v
retrieving revision 1.30
diff -u -p -r1.30 softraid_raid5.c
--- softraid_raid5.c    26 Mar 2020 11:28:23 -0000      1.30
+++ softraid_raid5.c    4 Dec 2020 03:29:20 -0000
@@ -857,8 +857,10 @@ sr_raid5_rebuild(struct sr_discipline *s
                        tsleep_nsec(wu_w, PRIBIO, "sr_rebuild", INFSLP);
                        slept = 1;
                }
-               if (!slept)
-                       tsleep(sd->sd_sc, PWAIT, "sr_yield", 1);
+               if (!slept) {
+                       tsleep_nsec(sd->sd_sc, PWAIT, "sr_yield",
+                           MSEC_TO_NSEC(1));
+               }
 
                sr_scsi_wu_put(sd, wu_r);
                sr_scsi_wu_put(sd, wu_w);

Reply via email to