From owner-freebsd-hackers Wed Jul 21 17:31:24 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from allegro.lemis.com (allegro.lemis.com [192.109.197.134]) by hub.freebsd.org (Postfix) with ESMTP id 9946A14CA1; Wed, 21 Jul 1999 17:31:12 -0700 (PDT) (envelope-from grog@freebie.lemis.com) Received: from freebie.lemis.com (freebie.lemis.com [192.109.197.137]) by allegro.lemis.com (8.9.1/8.9.0) with ESMTP id KAA24213; Thu, 22 Jul 1999 10:00:50 +0930 (CST) Received: (from grog@localhost) by freebie.lemis.com (8.9.3/8.9.0) id KAA51287; Thu, 22 Jul 1999 10:00:45 +0930 (CST) Date: Thu, 22 Jul 1999 10:00:45 +0930 From: Greg Lehey To: Jeff Hagendaz Cc: FreeBSD Hackers Subject: Re: polling in device driver Message-ID: <19990722100045.I84734@freebie.lemis.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.4i In-Reply-To: ; from Jeff Hagendaz on Wed, Jul 21, 1999 at 04:20:48PM -0700 WWW-Home-Page: http://www.lemis.com/~grog X-PGP-Fingerprint: 6B 7B C3 8C 61 CD 54 AF 13 24 52 F8 6D A4 95 EF Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG [returning to -hackers] On Wednesday, 21 July 1999 at 16:20:48 -0700, Jeff Hagendaz wrote: > Hi, > > I asked this in -hackers, but didn't get an answer. > Guess it is too simple to quanlify into -hackers, > I am moving it here. Your help is highly appreciated. No, -hackers is the right place. Just because you don't get an answer doesn't mean that you posted in the wrong place :-) > I am reading a Linux device driver. At some point it > polls a device to check if it is ready. The timeout > is set to 5 second. It uses the system jiffies to > count the time: > > u32 time_out = jiffies + 5 * HZ; > for (;;) { > /* code to check if dev is ready */ > ........ > if (ready) break; > if (intr_count == 0) schedule(); > if (jiffies > time_out) return ERROR; > } > > How do I implement such polling in FreeBSD? Thanks. If at all possible, you don't. If it's in the bottom half, you don't. You should try to find a better way to find when the device is ready: the driver appears to be counting interrupts, so you can probably tsleep for 5 seconds and wakeup from the lower half when you get an interrupt. It's difficult to give an example from the code you show. Greg -- When replying to this message, please copy the original recipients. For more information, see http://www.lemis.com/questions.html See complete headers for address, home page and phone numbers finger grog@lemis.com for PGP public key To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message