busy looping in kernel, time question

stevesu at copper.UUCP stevesu at copper.UUCP
Mon Apr 21 08:28:54 AEST 1986


In article <234 at Shasta.ARPA> alex at lancelot writes:
>
>	Assume I want to busy loop in the kernel for 100 milliseconds, how
>many times (approx) should I go around a loop which increments an int?

A fixed-time busy-wait is okay, but everybody should beware of
busy-waits waiting for something to happen.  Some devices (most
notably certain floppy disk controllers -- why is is that
everything about floppy disks is unilaterally disgusting) require
that you write something to a register, wait for a bit to come
high saying that the first bit has been digested, after which you
can write some more information.  This is typically done with
code like

	while(ryaddr->ryics & RY_TR) == 0);

This code comes from a particularly noxious device driver we have
for a horrid floppy controller whose manufacturer I won't mention
since I'm not feeling libelous today.  Under certain poorly
understood circumstances, the use of these floppy drives follows
the following novel course of events:

	1. User inserts disk, forgetting to install
	   write-enable sticker.

	2. User attempts to write to disk

	3. User's terminal hangs

	4. User can't get his terminal back, with control-C,
	   control-\, or kill -9 from another terminal, because
	   the process is sleeping down in the device driver and
	   nothing, not even root, can kill it

	5. User gives up and tries to get his floppy disk back. 
	   The door to the drive won't open...

	6. User discovers that by powering down the floppy drive,
	   the drive will relinquish his disk

	7. User wonders why, when he emerges from the room
	   containing the floppy drive, all the other users are
	   complaining that the machine seems to be dead

	8. The kernel is in fact in an infinite loop at high
	   interrupt priority, waiting for the TR bit which is
	   now never going to come, even when the floppy drive is
	   powered back on, because the drive will have forgotten
	   that it was in the middle of a transaction.

These difficulties could be avoided if peripheral manufacturers
would condescend to market controller boards with sane
interfaces.  Until then, though, if you have to write a device
driver for a demented controller, please break out of the
busy-wait loop after 100 iterations or so and return EIO or
something.  Yeah, you may dump the floppy user on the floor, but
he deserves it for using floppies in the first place, and anyway
he'll probably be able to get his disk out without a screwdriver,
and all the other users won't have to wait for the machine to be
manually halted and rebooted.

                                         Steve Summit
                                         tektronix!copper!stevesu

P.S.  Join the Coalition to Banish Floppies!  They're slow; they
don't hold enough data; they're unreliable; they have universally
disgusting controllers; and people who use them bring the machine
to its knees so I can't get any work done.  Everybody should use
9-track magtape (and none of those grotty streaming drives, either).

P.P.S.  I know floppies and streamers are cheap.  In both senses
of the word.  "You gets what you pays for."



More information about the Comp.unix.wizards mailing list