From a7be2f184dd5a7e05c99b24213aeced52e9b6742 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 11 Apr 2012 22:48:14 +0200 Subject: [PATCH] PEP 418: Add a table with performances of TSC, ACPI PM and HPET clocks --- pep-0418.txt | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pep-0418.txt b/pep-0418.txt index c23b1d0ab..718f8d66f 100644 --- a/pep-0418.txt +++ b/pep-0418.txt @@ -299,7 +299,7 @@ Hardware clocks 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 +* 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 @@ -310,6 +310,30 @@ Hardware clocks * RTC (Real-time clock). Most RTCs use a crystal oscillator with a frequency of 32,768 Hz +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). + +======================== ====== ======= ====== +Function TSC ACPI PM HPET +======================== ====== ======= ====== +time() 2 ns 2 ns 2 ns +CLOCK_REALTIME_COARSE 10 ns 10 ns 10 ns +CLOCK_MONOTONIC_COARSE 12 ns 13 ns 12 ns +CLOCK_THREAD_CPUTIME_ID 134 ns 135 ns 135 ns +CLOCK_PROCESS_CPUTIME_ID 127 ns 129 ns 129 ns +clock() 146 ns 146 ns 143 ns +gettimeofday() 23 ns 726 ns 637 ns +CLOCK_MONOTONIC_RAW 31 ns 716 ns 607 ns +CLOCK_REALTIME 27 ns 707 ns 629 ns +CLOCK_MONOTONIC 27 ns 723 ns 635 ns +======================== ====== ======= ====== + +Each function was called 10,000,000 times and CLOCK_MONOTONIC was used to get +the time before and after. The benchmark was run 5 times to keep the minimum +time. + + NTP adjustment ==============