[Python-checkins] peps: PEP 418: list OSes supporting or not CLOCK_MONOTONIC

victor.stinner python-checkins at python.org
Thu Mar 29 01:11:35 CEST 2012


http://hg.python.org/peps/rev/1c2347ed2ea6
changeset:   4163:1c2347ed2ea6
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Mar 29 00:57:15 2012 +0200
summary:
  PEP 418: list OSes supporting or not CLOCK_MONOTONIC

Give also more information about GetTickCount().

files:
  pep-0418.txt |  54 ++++++++++++++++++++++++++++++++++-----
  1 files changed, 47 insertions(+), 7 deletions(-)


diff --git a/pep-0418.txt b/pep-0418.txt
--- a/pep-0418.txt
+++ b/pep-0418.txt
@@ -75,7 +75,8 @@
 backward. Its rate may be adjusted by NTP. The reference point of the returned
 value is undefined so only the difference of consecutive calls is valid.
 
-It is not available on all platforms and may raise an OSError.
+It is not available on all platforms and may raise an OSError. It is not
+available on GNU/Hurd for example.
 
 The monotonic clock may stop while the system is suspended.
 
@@ -145,6 +146,13 @@
         if hasattr(time, 'CLOCK_HIGHRES'):
             monotonic.clocks.append(time.CLOCK_HIGHRES)
 
+.. note::
+
+   time.monotonic() detects GetTickCount() integer overflow (32 bits, roll-over
+   after 49.7 days): it increases a delta by 2\ :sup:`32` each time than an
+   overflow is detected. The delta is stored in the process local state and so
+   time.monotonic() value may be different in two Python processes.
+
 
 time.highres()
 --------------
@@ -193,6 +201,19 @@
 CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW represents monotonic time since some
 unspecified starting point. They cannot be set.
 
+CLOCK_MONOTONIC is available at least on the following operating systems:
+
+ * DragonFly BSD, FreeBSD >= 5.0, OpenBSD, NetBSD
+ * Linux
+ * Solaris
+
+The following operating systems don't support CLOCK_MONOTONIC:
+
+
+ * GNU/Hurd (see `open issues/ clock_gettime <http://www.gnu.org/software/hurd/open_issues/clock_gettime.html>`_)
+ * Mac OS X
+ * Windows
+
 CLOCK_MONOTONIC_RAW is specific to Linux. It is similar to CLOCK_MONOTONIC, but
 provides access to a raw hardware-based time that is not subject to NTP
 adjustments. CLOCK_MONOTONIC_RAW requires Linux 2.6.28 or later.
@@ -236,7 +257,13 @@
 
 GetTickCount64() was added to Windows Vista and Windows Server 2008.
 
-The clock resolution is 1 millisecond.
+The clock resolution is 1 millisecond. Its accuracy is usually around 15 ms. It
+is possible to improve the accuracy using the `undocumented
+NtSetTimerResolution() function
+<http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Time/NtSetTimerResolution.html>`_.
+There are applications using this undocumented function, example:
+`Timer Resolution <http://www.lucashale.com/timer-resolution/>`_.
+
 
 Solaris: CLOCK_HIGHRES
 ^^^^^^^^^^^^^^^^^^^^^^
@@ -414,6 +441,8 @@
 Links
 =====
 
+Related Python issues:
+
  * `Issue #12822: NewGIL should use CLOCK_MONOTONIC if possible.
    <http://bugs.python.org/issue12822>`_
  * `Issue #14222: Use time.steady() to implement timeout
@@ -425,16 +454,27 @@
  * `python-monotonic-time
    <http://code.google.com/p/python-monotonic-time/>`_
    (`github <https://github.com/gavinbeatty/python-monotonic-time>`_)
+
+Librairies exposing monotonic clocks:
+
  * `Qt library: QElapsedTimer
    <http://qt-project.org/doc/qt-4.8/qelapsedtimer.html>`_
+ * `glib library: g_get_monotonic_time ()
+   <http://developer.gnome.org/glib/2.30/glib-Date-and-Time-Functions.html>`_
+   uses GetTickCount64()/GetTickCount() on Windows,
+   clock_gettime(CLOCK_MONOTONIC) on UNIX or falls back to the system clock
  * `monotonic_clock
-   <https://github.com/ThomasHabets/monotonic_clock>`_
+   <https://github.com/ThomasHabets/monotonic_clock>`_ (Python library)
+ * `Perl: Time::HiRes
+   <http://perldoc.perl.org/Time/HiRes.html>`_ exposes
+   clock_gettime(CLOCK_MONOTONIC)
+
+Related documents:
+
+ * `C++ Timeout Specification
+   <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3128.html>`_
  * `Windows: Game Timing and Multicore Processors
    <http://msdn.microsoft.com/en-us/library/ee417693.aspx>`_
  * `Implement a Continuously Updating, High-Resolution Time Provider for Windows
    <http://msdn.microsoft.com/en-us/magazine/cc163996.aspx>`_
- * `Perl: Time::HiRes
-   <http://perldoc.perl.org/Time/HiRes.html>`_
- * `C++ Timeout Specification
-   <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3128.html>`_
 

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list