Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!aurora!labrea!decwrl!sun!pitstop!texsun!convex!hal6000!authorplaceholder From: iv@hal6000.UUCP Newsgroups: comp.unix.wizards Subject: Re: Device driver timeout question ... Message-ID: <-10440186@hal6000> Date: Mon, 24-Aug-87 15:34:00 EDT Article-I.D.: hal6000.-10440186 Posted: Mon Aug 24 15:34:00 1987 Date-Received: Sat, 19-Sep-87 11:42:35 EDT References: <570@obiwan.UUCP> Lines: 94 Nf-ID: #R:obiwan.UUCP:-57000:hal6000:-10440186:000:3298 Nf-From: hal6000.UUCP!iv Aug 24 14:34:00 1987 ---- | The above does some nasty stuff now when the cable is connected. | Since the "timeout" is for N minutes, and requests to the device can | be much quicker than this, it looks like I can expect to have several | outstanding "timeout"s working; one of which may be valid. [ . . . ] | -Rogue Monster | -- | UUCP: {decvax,ucbvax,ihnp4}!decwrl!mips!roger OR roger@mips.com | USPS: MIPS Computer Systems, 930 Arques, Sunnyvale, CA 94086, (408) 991-0220 ---- Another solution that we've used is to have ONE timeout that gets started by the stragedy, uh, strategy routine and that requeues itself. This way, you only use at most two timeout table slots. It can look something like this [please note that however much this may resemble real kernel code, it is really pseudo-code intended to show the general idea]: io_poll() { register int p; static int running = 0; /* This way we can just call io_poll() to prime the polling. * You can just call it from the stragedy routine each time, * or make "running" a global that stragedy() can look at. */ if (running) /* Is another copy of me running already? */ return; /* "driver_running" should be a flag maintained by your stragedy * and interrupt routines which indicates whether there is work * to do. It is possible in most drivers to catch them at a * time where there is no I/O outstanding, yet there is work in * the queue. The idea is, we don't want to tie up system * resources polling for an idle driver. */ p = SPL(); /* Protect against interrupt races */ if (!driver_running) { running = 0; splx(s); return; } /* "io_in_progress" should be a flag maintained by your driver * start routine and interrupt routine to indicate that there * is an I/O operation in progress we need to watch and * potentially timeout */ if (!io_in_progress) goto out; /* Okay. Now here we need to have the start routine leave * enough information around to be able to decide if the * current I/O operation has gone on too long. Here we assume * that the start routine put the start time of the operation * in "started_time" and that the I/O is overdue after 2 secs. * Notice that interrupts are still disabled. /*/ if (started_time + (2 * HZ) < time) goto out; /* Here, of course, you abort your overdue I/O operation */ /* Oh, oh... No word from planet DMA! */ printf("Shut her down, Scotty, she's sucking DMA again...\n"); abort_IO_stuff(); out: /* On and on... I just keep on timing, * and after a while I feel like cryyyying * on and on, on and on, on aaaaand on... */ timeout(io_poll, (caddr_t)0, LaterTime); splx(s); } Anyway. I hope this helps. ---- IV (aka John Elliott IV) Domain: iv@hal6000.Tandy.COM 1300 Two Tandy Center UUCP: ...!ihnp4!sys1!hal6000!iv Tandy Systems Software or: ...!decvax!microsoft!trsvax!hal6000!iv Fort Worth, TX 76102 Phone: 817/390-2701; 9:30am-6:00pm CST [This information was provided by an individual and is not nor should be construed as being provided by Radio Shack or Tandy Corporation. Radio Shack and/or Tandy Corporation have no obligation to support the information provided. The author will, however, cheerfully accept mail. This note will self-destruct in 5 seconds. Good luck, %s.]