The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Efficient use of low-precision kernel timers
@ 2007-07-10 18:59 Alan Stern
  2007-07-10 20:28 ` Thomas Gleixner
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Stern @ 2007-07-10 18:59 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Oliver Neukum, Kernel development list

Thomas:

Here's a question for you or anyone else who can help.

I've got a low-precision kernel timer, with a delay measured in seconds
(and rounded off to a second boundary).  Under some circumstances the
timer might be cancelled and restarted many times in quick succession
(a few thousand times perhaps).  Alternatively the timer could simply
be allowed to expire and then restarted, with the callback routine
doing a rather small amount of work.

Which is the most efficient?  Or to put it another way, how many times 
can I cancel and restart a low-precision timer before it uses up as 
much CPU time as allowing the timer to expire once?

Is there a reasonable way to answer this?  I can't think of any good 
tests.  Or is the difference in overhead so small as to be meaningless?

Alan Stern


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Efficient use of low-precision kernel timers
  2007-07-10 18:59 Efficient use of low-precision kernel timers Alan Stern
@ 2007-07-10 20:28 ` Thomas Gleixner
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2007-07-10 20:28 UTC (permalink / raw)
  To: Alan Stern; +Cc: Oliver Neukum, Kernel development list

Alan,

On Tue, 2007-07-10 at 14:59 -0400, Alan Stern wrote:
> Thomas:
> 
> Here's a question for you or anyone else who can help.
> 
> I've got a low-precision kernel timer, with a delay measured in seconds
> (and rounded off to a second boundary).  Under some circumstances the
> timer might be cancelled and restarted many times in quick succession
> (a few thousand times perhaps).  Alternatively the timer could simply
> be allowed to expire and then restarted, with the callback routine
> doing a rather small amount of work.
> 
> Which is the most efficient?  Or to put it another way, how many times 
> can I cancel and restart a low-precision timer before it uses up as 
> much CPU time as allowing the timer to expire once?

Hard to tell.

> Is there a reasonable way to answer this?  I can't think of any good 
> tests.  Or is the difference in overhead so small as to be meaningless?

The insertion / deletion needs to take the timer->base->lock, but this
is cheap as long as the insert / cancel happens on the same CPU.

The other overhead which might be "visible" is when the timer needs to
be re-cascaded in the wheel. See the table below:

         100 250 1000 HZ
[1] 256   10    4   1 ms
[2]  64 2560 1024 256 ms
[3]  64  164   66  16  s
[4]  64  175   70  17  m
[5]  64  186   75  19  h

In the 250Hz case the timer < 1024ms is never re-cascaded. A timer <66s
is re-cascaded at max. once.

So I guess your frequent cancel/restart scheme is just fine. It does not
re-trigger any kind of hardware event and the insertion/deletion is
O(1).

The network code relies on this cheap mechanism on high loaded server
machines.

Hope that helps,

	tglx



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-07-10 20:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-10 18:59 Efficient use of low-precision kernel timers Alan Stern
2007-07-10 20:28 ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox