On Thu, Jul 14, 2005 Linus Torvalds wrote: > In other words, the _right_ way to do this is literally > > unsigned long timeout = jiffies + HZ/2; > for (;;) { > if (ready()) > return 0; > if (time_after(timeout, jiffies)) > break; > msleep(10); > } > > which is unquestionably more complex, yes, but it's more complex because > it is CORRECT! Since you emphasised on correctness, your code is actually buggy for the preemptible kernel. It could get preempted after the ready() test, but before the time_after(), for quite a whie if a high priority process keeps the system busy. This code is better: unsigned long timeout = jiffies + HZ/2; int err; for (;;) { err = time_after(timeout, jiffies); if (ready()) return 0; if (err) break; msleep(10); } This way the condition is always re-tested before reporting timeout. Johannes - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- References:
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: dean gaudet <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Chris Wedgwood <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: dean gaudet <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Lee Revell <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Linus Torvalds <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Arjan van de Ven <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Vojtech Pavlik <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Linus Torvalds <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Arjan van de Ven <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- From: Linus Torvalds <[email protected]>
- Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- Prev by Date: Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- Next by Date: Re: [rfc patch 2/2] direct-io: remove address alignment check
- Previous by thread: Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- Next by thread: RE: [PATCH] i386: Selectable Frequency of the Timer Interrupt
- Index(es):