The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Oliver Neukum <oliver@neukum.name>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: Efficient use of low-precision kernel timers
Date: Tue, 10 Jul 2007 22:28:49 +0200	[thread overview]
Message-ID: <1184099329.12353.20.camel@chaos> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0707101452570.2556-100000@iolanthe.rowland.org>

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



      reply	other threads:[~2007-07-10 20:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-10 18:59 Efficient use of low-precision kernel timers Alan Stern
2007-07-10 20:28 ` Thomas Gleixner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1184099329.12353.20.camel@chaos \
    --to=tglx@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver@neukum.name \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox