Subject: Can I sleep until interrupts are enabled?
To: None <tech-kern@netbsd.org>
From: Thor Lancelot Simon <tls@rek.tjls.com>
List: tech-kern
Date: 09/09/2003 05:13:48
A number of disk device drivers use threads to manage bus events,
for example the isp driver, the mlx and mly drivers, and the I2O
drivers.

During a recent extremely painful debugging session with the isp
driver and a two FibreChannel cards, it became clear to me why
some of these device drivers seem to leave the kernel hung indefinitely
at boot when used in certain system configurations.  The sole difference
between the revision of the isp driver that worked with my hardware and
the one that hung forever was the addition of the NOSETTLE flag to the
SCSI channels.  Why'd this hang the machine?  Because the fc_thread
is created at driver attach time.  

It periodically wakes up and looks to see if various things happened -- 
things that it would learn about when the interrupt-driven part of the 
driver received interrupts from the card telling it so.

In practice, there is no way to guarantee that interrupts for the device
are actually enabled when the thread wakes up.  In fact, with the i386
port, it appears that this is highly dependent on which other devices
are in the machine _and_ how the interrupt code is configured (since
we now have two different kinds of interrupt code for this port).

In the case of isp, the 2-second sleep to let the scsibus settle before
the first SCSI command is issued lets things proceed in the normal
order.  I'm experimenting now with adding sleeps to the other device
drivers that use threads (I have a machine where mlx and iop always hang
on the first scan of their child devices at boot time) to see of this
fixes them.  However, I think we really need either:

1) A guarantee that kernel threads won't run until interrupts are enabled,
   regardless of the port and system configuration

or

2) A way for a thread to sleep until interrupts are enabled.

Is there an elegant way to get either of these right now?

-- 
 Thor Lancelot Simon	                                      tls@rek.tjls.com
   But as he knew no bad language, he had called him all the names of common
 objects that he could think of, and had screamed: "You lamp!  You towel!  You
 plate!" and so on.              --Sigmund Freud