ref: 82da41a2ebf35abbce6784cdf33cf661cffb5a0a
parent: 5c448c618a89ab8933838da1b5b97ed7c4a42e08
author: cinap_lenrek <[email protected]>
date: Wed Sep 27 15:19:09 EDT 2023
nusbrc: use exponential backoff and timeout usb enumeration nusbrc used to wait forever until initial device enumeration was completed. the reason is mainly so that usb stoage or ethernet devices can be used as boot media. but this can result in a system getting completely stuck on boot if usb enumeration gets stuck. (this really depends on the device driver if some timeouts have been implemented during attach). as a compromise, we will wait for usb enumeration to complete using exponential back-off with a maximum total wait time of ~10 seconds. typical times for single device initial enumeration is 0.4 to 0.6 seconds. largest case i measured with 20 random devices was 7 seconds. so we will probably be safe with the 10 second timeout.
--- a/sys/src/9/boot/nusbrc
+++ b/sys/src/9/boot/nusbrc
@@ -74,8 +74,15 @@
}
# usbd removes this file once all devices have been enumerated
-while(test -e /env/usbbusy)
- sleep 1
+if(test -e /env/usbbusy) sleep 0.6
+if(test -e /env/usbbusy) sleep 0.8
+if(test -e /env/usbbusy) sleep 1.0
+if(test -e /env/usbbusy) sleep 1.2
+if(test -e /env/usbbusy) sleep 1.4
+if(test -e /env/usbbusy) sleep 1.6
+if(test -e /env/usbbusy) sleep 1.8
+if(test -e /env/usbbusy) sleep 2.0
+if(test -e /env/usbbusy) echo $0^': warning: USB device enumeration incomplete.' >[1=2]
bind -a '#σ/usb' /dev
bind -a '#σ/usbnet' /net