PEP 418: Add the accuracy of process and thread time clocks

This commit is contained in:
Victor Stinner 2012-04-03 01:14:28 +02:00
parent 7ba7cc657f
commit f0107e6f66
1 changed files with 90 additions and 57 deletions

View File

@ -275,21 +275,18 @@ Operating system clocks
Monotonic clocks
----------------
========================= =============== =============== ================ ====================
Name Resolution Accuracy Adjusted by NTP? Action on suspend
========================= =============== =============== ================ ====================
CLOCK_MONOTONIC_RAW 1 ns (*) No Stopped
gethrtime 1 ns (*) No Not stopped
CLOCK_HIGHRES 1 ns (*) No ?
CLOCK_MONOTONIC 1 ns (*) Slewed on Linux Stopped on Linux
mach_absolute_time() 1 ns (*) No ?
QueryPerformanceCounter() \- 0.3 ns - 5 ns No Accuracy issue
GetTickCount[64]() 1 ms 1 ms - 15 ms No Include suspend time
timeGetTime() 1 ms 1 ms - 15 ms No ?
========================= =============== =============== ================ ====================
(*) The accuracy of monotonic clocks depends on the operating system
and the hardware clock.
========================= =============== ================ ====================
Name Resolution Adjusted by NTP? Action on suspend
========================= =============== ================ ====================
CLOCK_MONOTONIC_RAW 1 ns No Stopped
gethrtime 1 ns No Not stopped
CLOCK_HIGHRES 1 ns No ?
CLOCK_MONOTONIC 1 ns Slewed on Linux Stopped on Linux
mach_absolute_time() 1 ns No ?
QueryPerformanceCounter() \- No Accuracy issue
GetTickCount[64]() 1 ms No Include suspend time
timeGetTime() 1 ms No ?
========================= =============== ================ ====================
The resolution is the smallest difference between two timestamps
supported by the format used by the clock. For example,
@ -310,10 +307,10 @@ CLOCK_MONOTONIC_RAW Linux 3.2 1 ns
CLOCK_MONOTONIC Linux 3.2 1 ns
CLOCK_HIGHRES SunOS 5.11 2 ns
CLOCK_MONOTONIC SunOS 5.11 2 ns
QueryPerformanceCounter Windows Vista 10 ns
QueryPerformanceCounter Windows Seven 10 ns
CLOCK_MONOTONIC FreeBSD 8.2 11 ns
CLOCK_MONOTONIC OpenBSD 5.0 10 ms
GetTickCount Windows Vista 15.6 ms
GetTickCount Windows Seven 15.6 ms
========================= ================ ===============
For CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW, the accuracy of this table is the
@ -533,18 +530,15 @@ On Solaris, gethrtime() is the same as clock_gettime(CLOCK_MONOTONIC).
System time clocks
------------------
========================= =============== ===============
Name Resolution Accuracy
========================= =============== ===============
CLOCK_REALTIME 1 ns (*)
GetSystemTimeAsFileTime 100 ns 1 ms - 15 ms
gettimeofday() 1 µs (*)
ftime() 1 ms (*)
time() 1 sec 1 sec
========================= =============== ===============
(*) The accuracy of system clocks depends on the operating system and
the hardware clock.
========================= ===============
Name Resolution
========================= ===============
CLOCK_REALTIME 1 ns
GetSystemTimeAsFileTime 100 ns
gettimeofday() 1 µs
ftime() 1 ms
time() 1 sec
========================= ===============
Examples of clock accuracy on x86_64:
@ -555,7 +549,7 @@ CLOCK_REALTIME Linux 3.2 1 ns
CLOCK_REALTIME FreeBSD 8.2 11 ns
CLOCK_REALTIME SunOS 5.11 10 ms
CLOCK_REALTIME OpenBSD 5.0 10 ms
GetSystemTimeAsFileTime Windows Vista 15.6 ms
GetSystemTimeAsFileTime Windows Seven 15.6 ms
========================= ================ ===============
For CLOCK_REALTIME, the accuracy of this table is the result of clock_getres().
@ -587,7 +581,7 @@ return the system clock.
Resolution:
* clock_gettime(): clock_getres(CLOCK_REALTIME), 1 nanosecond on Linux
* clock_gettime(): clock_getres(CLOCK_REALTIME)
* gettimeofday(): 1 microsecond
* ftime(): 1 millisecond
* time(): 1 second
@ -596,14 +590,41 @@ The system time can be set using settimeofday() or
clock_settime(CLOCK_REALTIME).
Process and thread time
-----------------------
Process time
------------
The process and thread time cannot be set. They are not monotonic:
the clocks stop while the process/thread is idle.
The process time cannot be set. It is not monotonic: the clocks stop while the
process is idle.
Process
^^^^^^^
========================= ===============
Name Resolution
========================= ===============
GetProcessTimes() 100 ns
CLOCK_PROCESS_CPUTIME_ID 1 ns
clock() \-
========================= ===============
Examples of clock accuracy on x86_64:
========================= ================ ===============
Name Operating system Accuracy
========================= ================ ===============
CLOCK_PROCESS_CPUTIME_ID Linux 3.2 1 ns
clock() Linux 3.2 1 µs
clock() SunOS 5.11 1 µs
clock() FreeBSD 8.2 7.8 ms
clock() OpenBSD 5.0 10 ms
GetProcessTimes() Windows Seven 15.6 ms
========================= ================ ===============
The accuracy of clock() in this table is the result of 1 / CLOCKS_PER_SEC.
For CLOCK_PROCESS_CPUTIME_ID, the accuracy of this table is the result of
clock_getres(). It looks like Linux does not implement clock_getres() and
always return 1 nanosecond. For GetProcessTimes(), the accuracy is read using
GetSystemTimeAdjustment().
Functions
^^^^^^^^^
* Windows: GetProcessTimes()
* clock_gettime(CLOCK_PROCESS_CPUTIME_ID): High-resolution per-process
@ -622,28 +643,41 @@ Process
Resolution:
* clock() rate is CLOCKS_PER_SEC. It was called CLK_TCK in Microsoft
C before 6.0. On Linux 3, clock() has a resolution of 1
microsecond.
C before 6.0.
* The clock resolution can be read using clock_getres().
clock_getres(CLOCK_REALTIME) is 1 nanosecond on Linux.
* GetProcessTimes(): call GetSystemTimeAdjustment().
Thread time
-----------
The thread time cannot be set. It is not monotonic: the clocks stop while the
thread is idle.
========================= ===============
Name Resolution
========================= ===============
GetThreadTimes() 100 ns
CLOCK_THREAD_CPUTIME_ID 1 ns
========================= ===============
Examples of clock accuracy on x86_64:
========================= ================ ===============
Name Operating system Accuracy
========================= ================ ===============
clock() Linux 3.2 1 ms
clock() SunOS 5.11 1 ms
clock() FreeBSD 8.2 7.8 ms
clock() OpenBSD 5.0 10 ms
CLOCK_THREAD_CPUTIME_ID Linux 3.2 1 ns
CLOCK_THREAD_CPUTIME_ID FreeBSD 8.2 1 µs
GetThreadTimes() Windows Seven 15.6 ms
========================= ================ ===============
The accuracy of clock() in this table is the result of 1 / CLOCKS_PER_SEC.
For CLOCK_THREAD_CPUTIME_ID, the accuracy of this table is the result of
clock_getres(). It looks like Linux does not implement clock_getres() and
always return 1 nanosecond. For GetThreadTimes(), the accuracy is read using
GetSystemTimeAdjustment().
Thread
^^^^^^
Functions
^^^^^^^^^
* Windows: GetThreadTimes()
* clock_gettime(CLOCK_THREAD_CPUTIME_ID): Thread-specific CPU-time
@ -651,15 +685,14 @@ Thread
Resolution:
* CLOCK_THREAD_CPUTIME_ID: call clock_getres(). 1 nanosecond on
Linux.
* CLOCK_THREAD_CPUTIME_ID: call clock_getres().
* GetThreadTimes(): call GetSystemTimeAdjustment()
See also pthread_getcpuclockid().
Windows: QueryUnbiasedInterruptTime
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----------------------------------
Gets the current unbiased interrupt time from the biased interrupt
time and the current sleep bias amount. This time is not affected by