From 196140e2213d68d6b54f2e2d0b359019eec58211 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 1 Apr 2012 04:03:15 +0200 Subject: [PATCH] PEP 418: Add a "Hardware clocks" section * Mention the QueryPerformanceCounter() issue on CPU with variable frequency --- pep-0418.txt | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/pep-0418.txt b/pep-0418.txt index 6ed34e5a2..3c7f2147c 100644 --- a/pep-0418.txt +++ b/pep-0418.txt @@ -209,8 +209,30 @@ Pseudo-code:: highres.use_monotonic = hasattr(time, 'monotonic') -Clocks -====== +Hardware clocks +=============== + +* HPET: An 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. +* 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. The instructor RDTSC can be used to read this counter. +* 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. +* 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. +* PIT (programmable interrupt timer): Intel 8253/8254 chipsets with a + configurable frequency in range 18.2 Hz - 1.2 MHz. It is a 16-bit counter. +* RTC (Real-time clock). Most RTCs use a crystal oscillator with a frequency of + 32,768 Hz + + +Operating system clocks +======================= Monotonic clocks ---------------- @@ -363,6 +385,8 @@ Bugs: * Windows XP had a bug (see `KB896256`_): on a multiprocessor computer, QueryPerformanceCounter() returned a different value for each processor. The bug was fixed in Windows XP SP2. +* Issues with processor with variable frequency: the frequency is changed + depending on the workload to reduce memory consumption. .. _KB896256: http://support.microsoft.com/?id=896256 .. _KB274323: http://support.microsoft.com/?id=274323 @@ -390,6 +414,11 @@ NtSetTimerResolution() function There are applications using this undocumented function, example: `Timer Resolution `_. +WaitForSingleObject() use the same timer than GetTickCount() with the same +resolution. + +GetTickCount() has an accuracy of 55 ms on Windows 9x. + Windows: timeGetTime ^^^^^^^^^^^^^^^^^^^^ @@ -610,19 +639,25 @@ Read also the `time(7) manual page Alternatives: API design ======================== -Name of the "monotonic or fallback" function name -------------------------------------------------- +Other names for new functions +----------------------------- -Other names were proposed: +time.highres(): * time.hires(): "hires" can be read as "to hire" as in "he hires a car to go on holiday", rather than a "HIgh-RESolution clock". +* time.timer(): "it would be too easy to confuse with (or misspell as) + time.time()" + +time.monotonic(): + * time.steady(): no OS provides a clock advancing at a steady rate, so "steady" should be avoided. * time.try_monotonic(): it is a clear and obvious solution for the use-case of "I prefer the monotonic clock, if it is available, otherwise I'll take my chances with a best-effect clock." -* time.wallclock() +* time.wallclock(): it is not the system time aka the "wall clock", but + a monotonic clock with an unspecified starting point One function, no flag