9front - general discussion about 9front
 help / color / mirror / Atom feed
* Don't try to unstall USB media when it's unnecessary.
@ 2018-12-24  3:23 ori
  0 siblings, 0 replies; only message in thread
From: ori @ 2018-12-24  3:23 UTC (permalink / raw)
  To: 9front

I've got a USB SD card reader that blocks boot for minutes. It seems like
we're trying to unstall it repeatedly as part of the boot process, and each
unstall can take tens of seconds. We don't need to unstall it, because the
device isn't stalled: It's happily reporting that there's no SD card plugged
in.

This patch adds a check to skip unstalling if we're in that case. There are
probably a few more errors that we could skip trying to unstall on.

This brings boot times from potentially multiple minutes to a few seconds.

Let me know if this looks sane to commit.

--- a/sys/src/cmd/nusb/disk/disk.c	Sun Dec 23 22:43:29 2018 +0100
+++ b/sys/src/cmd/nusb/disk/disk.c	Sun Dec 23 19:12:05 2018 -0800
@@ -361,6 +361,15 @@
 	return 0;
 }
 
+static int
+needunstall(int n)
+{
+	char buf[128];
+
+	rerrstr(buf, sizeof(buf));
+	return n < 0 || strstr(buf, "medium not present") == nil;
+}
+
 
 /*
  * called by SR*() commands provided by scuzz's scsireq
@@ -412,15 +421,14 @@
 			if (n >= 0 && n < nio)	/* didn't fill data->p? */
 				memset(data->p + n, 0, nio - n);
 		}
-		nio = n;
 		if(diskdebug)
 			if(n < 0)
 				fprint(2, "disk: data: %r\n");
 			else
-				fprint(2, "disk: data: %d bytes\n", n);
-		if(n <= 0)
-			if(data->write == 0)
-				unstall(dev, ums->epin, Ein);
+				fprint(2, "disk: data: %d bytes (nio: %d)\n", n, nio);
+		nio = n;
+		if(n <= 0 && (needunstall(n) || data->write == 0))
+			unstall(dev, ums->epin, Ein);
 	}
 
 	/* read the transfer's status */





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-12-24  3:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-24  3:23 Don't try to unstall USB media when it's unnecessary ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).