[libcxx-commits] [PATCH] D93542: [SystemZ][ZOS] Provide CLOCK_MONOTONIC alternative

Zbigniew Sarbinowski via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 18 07:23:51 PST 2020

zibi created this revision.
zibi added a project: libc++.
zibi requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

We need CLOCK_MONOTONIC equivalent implementation for z/OS within libc++. The default implementation is asserting.

On z/OS the lack of  'clock_gettime()' and 'time_point()' force us to look for alternatives.
The current proposal is to use `gettimeofday()` for CLOCK_MONOTONIC  which is also used in CLOCK_REALTIME.  This will allow us to skip the assertion with compromised CLOCK_MONOTONIC implementation which will not guarantee to never go back in time because it will use `gettimeofday()` but only when it's set.

Is this a good compromise for platforms which does not support monotonic clock?
Hopefully this will spark the discussion and agreement how to proceed in this situation.

  rG LLVM Github Monorepo



Index: libcxx/src/chrono.cpp
--- libcxx/src/chrono.cpp
+++ libcxx/src/chrono.cpp
@@ -156,6 +156,15 @@
   return steady_clock::time_point(steady_clock::duration(counter.QuadPart * nano::den / freq.QuadPart));
+#elif defined(__MVS__)
+static steady_clock::time_point __libcpp_steady_clock_now() {
+  timeval tv;
+  gettimeofday(&tv, 0);
+  return steady_clock::time_point(seconds(tv.tv_sec) +
+                                  nanoseconds(tv.tv_usec * 1000));
 #elif defined(CLOCK_MONOTONIC)
 static steady_clock::time_point __libcpp_steady_clock_now() {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93542.312787.patch
Type: text/x-patch
Size: 636 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201218/90d7d649/attachment.bin>

More information about the libcxx-commits mailing list