Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 14, 2005 at 10:21:41AM -0700, 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!

Umm.  Except, according to your description of what it's supposed to
do, the above code can have an accumulating error.

	unsigned long timeout, max_timeout, now;

	now = jiffies;
	timeout = now + HZ/100;
	max_timeout = now + HZ/2;

	for (;;) {
		if (ready())
			return 0;
		if (time_after(timeout, jiffies))
			break;
		sleep_until(timeout);
		timeout += HZ/100;
	}

would be even more correct, if we had an absolute schedule_timeout()
called sleep_until().  If we woke up late, we will schedule the next
wakeup exactly 10ms after the previous wakeup _should_ have happened.

Quick!  Convert all the kernel interfaces back to absolute time! 8)

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
-
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/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux