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

Russell King
2005-07-14T20:33:32Z

On Thu, Jul 14, 2005 at 01:06:00PM -0700, Linus Torvalds wrote:
> On Thu, 14 Jul 2005, Russell King wrote:
> > Umm. Except, according to your description of what it's supposed to
> > do, the above code can have an accumulating error.
>
> No. It can have a local drift, but the point is, the error never gets
> worse - it _stays_ local.
>
> There's no point in polling twice in immediate succession just because a
> sleep overslept. That's like a security guard testing each door twice for
> being locked, just because he overslept one round. Pointless.

That depends what you're trying to achieve. If you're trying to achieve
an average interval of 10ms over half a second, your solution won't get
that, whereas mine will.

> But what matters is that you don't let your local errors accumulate into
> the big picture.

Precisely - it's all about "the big picture" and what the requirements
there are. My requirements for "once every 10ms" may be different from
yours.

An example may be best. You need to toggle an IO output at 50Hz for
half a second but you don't care at all about the duty cycle. You
do care about it being as close as possible 50Hz, and not 40Hz
because for whatever reason it's taking you a hypothetical (*) 2ms
latency between timer expiry either time.

(* - yes, I know we don't like that word here... 8) but I'm trying
to make a point through exaggeration, so I'm covering my ass when
someone says "but 2ms is a bloody stupid latency!".)

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core