Difference between revisions of "Kernel Timer Systems"

From eLinux.org
Jump to: navigation, search
m (Bot (Edward's framework))
 
Line 1: Line 1:
This page has links to information about various proposals for new timer systems for the Linux kernel.
+
This page has links to information about the (relatively) new timer systems for the Linux kernel.
The current linux kernel (2.6.11 as of this writing) has a few problems, particularly for realtime
+
The current linux kernel received a major enhancement to it's timer system (as of about 2.6.21),
systems or for virtualized systems.
+
which solved a number of problems.
  
 +
A good article on the subject is at at lwn.net: [http://lwn.net/Articles/223185/ Clockevents and dyntick]
  
 +
-------------------
 +
= Material needs rework =
 +
A bunch of material below this line needs to be reworked to take into account the new
 +
ktimer system by Thomas Gleixner.
  
== Current Linux Timer System ==
+
== Timer Wheel, Jiffies and HZ (or, the way it was) ==
To understand the proposals, you need to understand the current
+
The original kernel timer system (called the "timer wheel) was based on
timer system in Linux.  The current timer system is based on
 
 
incrementing a kernel-internal value (jiffies) every timer
 
incrementing a kernel-internal value (jiffies) every timer
 
interrupt.  The timer interrupt becomes the default scheduling
 
interrupt.  The timer interrupt becomes the default scheduling
Line 19: Line 23:
 
changed HZ for i386 to 250.  (1000 was deemed too high).
 
changed HZ for i386 to 250.  (1000 was deemed too high).
  
[should continue this description]
+
=== Ingo Molnar's explanation of timer wheel performance ===
 +
Ingo Molnar did an in-depth explanation about the performance of
 +
the current "timer wheel" implementation of timers.  This was
 +
part of a series of messages trying to justify the addition
 +
of ktimers (which have different characteristics).
 +
 
 +
It is possibly the best explanation of the timer wheel avaiable:
 +
See http://lkml.org/lkml/2005/10/19/46
 +
and http://lwn.net/Articles/156329/
 +
 
 
  - timer structures
 
  - timer structures
- timer API
+
  - timer wheel
 +
== ktimers ==
 +
=== clock events ===
 +
=== clock sources ===
 +
 
 +
== dynamic ticks ==
 +
See [http://lwn.net/Articles/223185/ Clockevents and dyntick]
 +
 
 +
== timer API ==
 +
  - interval timers
 +
  - posix timer API
 +
  _ sleep, usleep and nanosleep
 +
 
 +
== time API ==
 
  - do_gettimeofday
 
  - do_gettimeofday
  - why is it
 
  
 
== High Resolution Timers ==
 
== High Resolution Timers ==
George Anzinger authored [[High Resolution Timers]], which provide sub-jiffy timers.
+
See [[High Resolution Timers]], which provide sub-jiffy timers.
This patch has not been mainlined.
 
  
== Jun Sun's "tock" proposal ==
+
== Old timer wheel/jiffy replacement proposals ==
 +
=== Jun Sun's "tock" proposal ===
 
See http://linux.junsun.net/HRT/index.html
 
See http://linux.junsun.net/HRT/index.html
  
Line 35: Line 60:
 
and proposes a strategy for migrating to that.
 
and proposes a strategy for migrating to that.
  
== John Stultz ==
+
=== John Stultz ===
John Stultz has proposed changes to the timers to use a 64-bit nanosecond value as the base.
+
In 2005, John Stultz proposed changes to the timers to use a 64-bit nanosecond value as the base.
 
He did a presentation and BOF at OLS 2005. (It should be available online)
 
He did a presentation and BOF at OLS 2005. (It should be available online)
  
Line 57: Line 82:
 
  - high res timer for periodic absolute wakeup (wake up every 10 ms, whether last one was late or nt
 
  - high res timer for periodic absolute wakeup (wake up every 10 ms, whether last one was late or nt
 
  - high res timer for periodic relative wakeup (wake up 10 ms from now)
 
  - high res timer for periodic relative wakeup (wake up 10 ms from now)
 
== Ingo Molnar's explanation of timer wheel performance ==
 
Ingo Molnar did an in-depth explanation about the performance of
 
the current "timer wheel" implementation of timers.  This was
 
part of a series of messages trying to justify the addition
 
of ktimers (which have different characteristics).
 
 
It is possibly the best explanation of the timer wheel avaiable:
 
See http://lkml.org/lkml/2005/10/19/46
 
and http://lwn.net/Articles/156329/
 

Revision as of 15:31, 18 October 2007

This page has links to information about the (relatively) new timer systems for the Linux kernel. The current linux kernel received a major enhancement to it's timer system (as of about 2.6.21), which solved a number of problems.

A good article on the subject is at at lwn.net: Clockevents and dyntick


Material needs rework

A bunch of material below this line needs to be reworked to take into account the new ktimer system by Thomas Gleixner.

Timer Wheel, Jiffies and HZ (or, the way it was)

The original kernel timer system (called the "timer wheel) was based on incrementing a kernel-internal value (jiffies) every timer interrupt. The timer interrupt becomes the default scheduling quamtum, and all other timers are based on jiffies. The timer interrupt rate (and jiffy increment rate) is defined by a compile-time constant called HZ. Different platforms use different values for HZ. Historically, the kernel used 100 as the value for HZ, yielding a jiffy interval of 10 ms. With 2.4, the HZ value for i386 was changed to 1000, yeilding a jiffy interval of 1 ms. Recently (2.6.13) the kernel changed HZ for i386 to 250. (1000 was deemed too high).

Ingo Molnar's explanation of timer wheel performance

Ingo Molnar did an in-depth explanation about the performance of the current "timer wheel" implementation of timers. This was part of a series of messages trying to justify the addition of ktimers (which have different characteristics).

It is possibly the best explanation of the timer wheel avaiable: See http://lkml.org/lkml/2005/10/19/46 and http://lwn.net/Articles/156329/

- timer structures
  - timer wheel

ktimers

clock events

clock sources

dynamic ticks

See Clockevents and dyntick

timer API

  - interval timers
  - posix timer API
  _ sleep, usleep and nanosleep

time API

- do_gettimeofday

High Resolution Timers

See High Resolution Timers, which provide sub-jiffy timers.

Old timer wheel/jiffy replacement proposals

Jun Sun's "tock" proposal

See http://linux.junsun.net/HRT/index.html

This systems replaces jiffies and xtime with tocks (arch-dependent), mtime (monotonic time) and wtime (wall time), and proposes a strategy for migrating to that.

John Stultz

In 2005, John Stultz proposed changes to the timers to use a 64-bit nanosecond value as the base. He did a presentation and BOF at OLS 2005. (It should be available online)

Timer Tick Thread - LKML July 2005

There was a very long thread about timers, jiffies, and related subjects in July of 2005 on the kernel mailing list.

The title was: "Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt"

Linus said jiffies is not going away

- still need 32-bit counter, shouldn't be real-time value (too much overhead to calculate)
- high-res timers shouldn't be sub-HZ, but instead, HZ should be high and timer tick should not be 1:1 with HZ
  - in other words, have HZ be high (like 2K), have the timer interrupt fire off at some lower frequency,
  and increment jiffies by more than one on each interrupt.
  - rationale for this is to keep a single sub-system

Arjan had good points about coalescing low-res timers

- 3 use cases:
- low res timeouts
- high res timer for periodic absolute wakeup (wake up every 10 ms, whether last one was late or nt
- high res timer for periodic relative wakeup (wake up 10 ms from now)