PEP 418: Move Linux clocksource and FreeBSD timecounter
Remove duplicate info on hardware clocks
This commit is contained in:
parent
976aae2d30
commit
2d861df8bf
176
pep-0418.txt
176
pep-0418.txt
|
@ -368,17 +368,20 @@ Glossary
|
|||
Hardware clocks
|
||||
===============
|
||||
|
||||
* HPET: An HPET chip consists of a 64-bit up-counter (main counter)
|
||||
List of hardware clocks
|
||||
-----------------------
|
||||
|
||||
* HPET: An High Precision Event Timer (HPET) chip consists of a 64-bit up-counter (main counter)
|
||||
counting at least at 10 MHz and a set of up to 256 comparators (at
|
||||
least 3). Each HPET can have up to 32 timers.
|
||||
least 3). Each HPET can have up to 32 timers. HPET can cause around 3 seconds of drift per day.
|
||||
* TSC (Time Stamp Counter): Historically, the TSC increased with every internal
|
||||
processor clock cycle, but now the rate is usually constant (even if the
|
||||
processor changes frequency) and usually equals the maximum processor
|
||||
frequency. Multiple cores having different TSC values. Hibernation of system
|
||||
will reset TSC value. The RDTSC instruction can be used to read this counter.
|
||||
CPU frequency scaling for power saving.
|
||||
* ACPI PMTMR (Power Management TiMeR): ACPI 24-bit timer with a frequency
|
||||
of 3.5 MHz (3,579,545 Hz). HPET can cause around 3 seconds of drift per day.
|
||||
* ACPI Power Management Timer: ACPI 24-bit timer with a frequency
|
||||
of 3.5 MHz (3,579,545 Hz).
|
||||
* Cyclone: The Cyclone timer uses a 32-bit counter on IBM Extended
|
||||
X-Architecture (EXA) chipsets which include computers that use the
|
||||
IBM "Summit" series chipsets (ex: x440). This is available in IA32
|
||||
|
@ -388,6 +391,84 @@ Hardware clocks
|
|||
* RTC (Real-time clock). Most RTCs use a crystal oscillator with a frequency of
|
||||
32,768 Hz
|
||||
|
||||
|
||||
Linux clocksource
|
||||
-----------------
|
||||
|
||||
There were 4 implementations of the time in the Linux kernel: UTIME
|
||||
(1996), timer wheel (1997), HRT (2001) and hrtimers (2007). The
|
||||
latter is the result of the "high-res-timers" project started by
|
||||
George Anzinger in 2001, with contributions by Thomas Gleixner and
|
||||
Douglas Niehaus. hrtimers implementation was merged into Linux
|
||||
2.6.21, released in 2007.
|
||||
|
||||
hrtimers supports various clock sources. It sets a priority to each
|
||||
source to decide which one will be used. Linux supports the following
|
||||
clock sources:
|
||||
|
||||
* tsc
|
||||
* hpet
|
||||
* pit
|
||||
* pmtmr: ACPI Power Management Timer
|
||||
* cyclone
|
||||
|
||||
High-resolution timers are not supported on all hardware
|
||||
architectures. They are at least provided on x86/x86_64, ARM and
|
||||
PowerPC.
|
||||
|
||||
The /sys/devices/system/clocksource/clocksource0 directory contains two useful files:
|
||||
|
||||
* available_clocksource: list of available clock sources
|
||||
* current_clocksource: clock source currently used. It is possible to change
|
||||
the current clocksource by writing the name of a clocksource into this
|
||||
file.
|
||||
|
||||
/proc/timer_list contains the list of all hardware timers.
|
||||
|
||||
Read also the `time(7) manual page
|
||||
<http://www.kernel.org/doc/man-pages/online/pages/man7/time.7.html>`_:
|
||||
"overview of time and timers".
|
||||
|
||||
|
||||
FreeBSD timecounter
|
||||
-------------------
|
||||
|
||||
kern.timecounter.choice list available hardward clocks with their priority.
|
||||
The sysctl program can be used to change the timecounter. Example::
|
||||
|
||||
# dmesg|grep Timecounter
|
||||
Timecounter "i8254" frequency 1193182 Hz quality 0
|
||||
Timecounter "ACPI-safe" frequency 3579545 Hz quality 850
|
||||
Timecounter "HPET" frequency 100000000 Hz quality 900
|
||||
Timecounter "TSC" frequency 3411154800 Hz quality 800
|
||||
Timecounters tick every 10.000 msec
|
||||
# sysctl kern.timecounter.choice
|
||||
kern.timecounter.choice: TSC(800) HPET(900) ACPI-safe(850) i8254(0) dummy(-1000000)
|
||||
# sysctl kern.timecounter.hardware="ACPI-fast"
|
||||
kern.timecounter.hardware: HPET -> ACPI-fast
|
||||
|
||||
Available clocks:
|
||||
|
||||
* "TSC": Time Stamp Counter of the procesor
|
||||
* "HPET": High Precision Event Timer
|
||||
* "ACPI-fast": ACPI Power Management timer (fast mode)
|
||||
* "ACPI-safe": ACPI Power Management timer (safe mode)
|
||||
* "i8254": PIT with Intel 8254 chipset
|
||||
|
||||
The `commit 222222
|
||||
<http://svnweb.freebsd.org/base?view=revision&revision=222222>`_ (May 2011)
|
||||
decreased ACPI-fast timecounter quality to 900 and increased HPET timecounter
|
||||
quality to 950: "HPET on modern platforms usually have better resolution and
|
||||
lower latency than ACPI timer".
|
||||
|
||||
Read `Timecounters: Efficient and precise timekeeping in SMP kernels
|
||||
<http://phk.freebsd.dk/pubs/timecounter.pdf>`_ by Poul-Henning Kamp (2002) for
|
||||
the FreeBSD Project.
|
||||
|
||||
|
||||
Performances
|
||||
------------
|
||||
|
||||
Reading an hardware clock has a cost. The following table compares the
|
||||
performance of different hardware clocks on Linux 3.3 with Intel Core i7-2600
|
||||
at 3.40GHz (8 cores).
|
||||
|
@ -914,90 +995,6 @@ QueryUnbiasedInterruptTime() is not monotonic.
|
|||
QueryUnbiasedInterruptTime() was introduced in Windows 7.
|
||||
|
||||
|
||||
Linux timers
|
||||
------------
|
||||
|
||||
There were 4 implementations of the time in the Linux kernel: UTIME
|
||||
(1996), timer wheel (1997), HRT (2001) and hrtimers (2007). The
|
||||
latter is the result of the "high-res-timers" project started by
|
||||
George Anzinger in 2001, with contributions by Thomas Gleixner and
|
||||
Douglas Niehaus. hrtimers implementation was merged into Linux
|
||||
2.6.21, released in 2007.
|
||||
|
||||
hrtimers supports various clock sources. It sets a priority to each
|
||||
source to decide which one will be used.
|
||||
|
||||
* TSC (Time Stamp Counter): Internal processor clock incremented at
|
||||
each processor cycle. Its frequency is the processor frequency and
|
||||
so usually higher than 1 GHz. Its priority is 300 by default, but
|
||||
falls to 0 if the processor frequency changes and the counter
|
||||
becomes unstable.
|
||||
* HPET: An High Precision Event Timer (HPET) chip consists of a 64-bit
|
||||
up-counter (main counter) counting at least at 10 MHz and a set of up to 256
|
||||
comparators (at least 3). Each HPET can have up to 32 timers. HPET can
|
||||
cause around 3 seconds of drift per day.
|
||||
* PIT (programmable interrupt timer): Intel 8253/8254 chipsets with a
|
||||
configurable frequency in range 18.2 Hz - 1.2 MHz. Linux uses the
|
||||
frequency 1,193,181.8 Hz. It is a 16-bit counter.
|
||||
* PMTMR (power management timer): ACPI 24-bit timer with a frequency
|
||||
of 3.5 MHz (3,579,545 Hz). Its priority is 200 by default, but
|
||||
changes to 110 if the chipset is broken and need a software
|
||||
workaround.
|
||||
* Cyclone: The Cyclone timer uses a 32-bit counter on IBM Extended
|
||||
X-Architecture (EXA) chipsets which include computers that use the
|
||||
IBM "Summit" series chipsets (ex: x440). This is available in IA32
|
||||
and IA64 architectures.
|
||||
|
||||
High-resolution timers are not supported on all hardware
|
||||
architectures. They are at least provided on x86/x86_64, ARM and
|
||||
PowerPC.
|
||||
|
||||
The list of available clock sources can be read in
|
||||
/sys/devices/system/clocksource/clocksource0/available_clocksource.
|
||||
It is possible to force a clocksource at runtime by writing its name
|
||||
into /sys/devices/system/clocksource/clocksource0/current_clocksource.
|
||||
/proc/timer_list contains the list of all hardware timers.
|
||||
|
||||
Read also the `time(7) manual page
|
||||
<http://www.kernel.org/doc/man-pages/online/pages/man7/time.7.html>`_:
|
||||
"overview of time and timers".
|
||||
|
||||
FreeBSD timers
|
||||
--------------
|
||||
|
||||
kern.timecounter.choice list available hardward clocks with their priority.
|
||||
The sysctl program can be used to change the timecounter. Example::
|
||||
|
||||
# dmesg|grep Timecounter
|
||||
Timecounter "i8254" frequency 1193182 Hz quality 0
|
||||
Timecounter "ACPI-safe" frequency 3579545 Hz quality 850
|
||||
Timecounter "HPET" frequency 100000000 Hz quality 900
|
||||
Timecounter "TSC" frequency 3411154800 Hz quality 800
|
||||
Timecounters tick every 10.000 msec
|
||||
# sysctl kern.timecounter.choice
|
||||
kern.timecounter.choice: TSC(800) HPET(900) ACPI-safe(850) i8254(0) dummy(-1000000)
|
||||
# sysctl kern.timecounter.hardware="ACPI-fast"
|
||||
kern.timecounter.hardware: HPET -> ACPI-fast
|
||||
|
||||
Available clocks:
|
||||
|
||||
* "TSC": Time Stamp Counter of the procesor
|
||||
* "HPET": High Precision Event Timer
|
||||
* "ACPI-fast": ACPI Power Management timer (fast mode)
|
||||
* "ACPI-safe": ACPI Power Management timer (safe mode)
|
||||
* "i8254": PIT with Intel 8254 chipset
|
||||
|
||||
The `commit 222222
|
||||
<http://svnweb.freebsd.org/base?view=revision&revision=222222>`_ (May 2011)
|
||||
decreased ACPI-fast timecounter quality to 900 and increased HPET timecounter
|
||||
quality to 950: "HPET on modern platforms usually have better resolution and
|
||||
lower latency than ACPI timer".
|
||||
|
||||
Read `Timecounters: Efficient and precise timekeeping in SMP kernels
|
||||
<http://phk.freebsd.dk/pubs/timecounter.pdf>`_ by Poul-Henning Kamp (2002) for
|
||||
the FreeBSD Project.
|
||||
|
||||
|
||||
Sleep, suspend and monotonic time
|
||||
=================================
|
||||
|
||||
|
@ -1062,6 +1059,7 @@ poll() 1 ms
|
|||
WaitForSingleObject() 1 ms
|
||||
======================== ==========
|
||||
|
||||
|
||||
Classic functions
|
||||
-----------------
|
||||
|
||||
|
@ -1072,6 +1070,7 @@ Classic functions
|
|||
<http://www.kernel.org/doc/man-pages/online/pages/man2/nanosleep.2.html>`_
|
||||
* delay(milliseconds)
|
||||
|
||||
|
||||
clock_nanosleep
|
||||
---------------
|
||||
|
||||
|
@ -1088,6 +1087,7 @@ POSIX.1 specifies that changing the value of the CLOCK_REALTIME clock via
|
|||
clock_settime(2) shall have no effect on a thread that is blocked on a relative
|
||||
clock_nanosleep().
|
||||
|
||||
|
||||
select()
|
||||
--------
|
||||
|
||||
|
|
Loading…
Reference in New Issue