This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Default to --enable-libstdcxx-time=auto

On Wed, May 22, 2013 at 02:35:40PM +0200, Jakub Jelinek wrote:
> non-steady clock instead.  Or, have you also considered just using
> for this routine
> #include <sys/syscall.h>
> #endif
> #if defined (SYS_clock_gettime) && defined (CLOCK_MONOTONIC)
> syscall (SYS_clock_gettime, CLOCK_MONOTONIC, &tp);
> #endif
> if clock_gettime isn't available, at least on Linux?
> The implementation seems to ignore ENOSYS from clock_gettime, so ignoring it
> even here wouldn't make it worse.

I mean something like completely untested following patch, then it would
be pretty much enabled for all non-prehistoric Linux builds (there is a risk
of it returning garbage on 2.4.x and earlier kernels, if you compile it on
something that defines __NR_clock_gettime in their headers, but the exact
same risk is if you do the same with --enable-libstdcxx-time=rt
(clock_gettime wrapper in glibc will return -1/ENOSYS in that case, so will
the syscall, but seems to ignore that return value)).
2.6+ kernels (2004-ish and later or so) should support CLOCK_MONOTONIC just
fine.  Of course, there is a possibility of fallback, at least for the
clock_gettime/syscall CLOCK_RUNTIME or gettimeofday, if they fail, fall
through into the time case, and for CLOCK_MONOTONIC perhaps just lie and
return time as well, shouldn't really affect almost anybody.

Still, the ABI question is there, would we want to apply to 4.8.1 (can we
get agreement on that RSN, this is pretty much the only blocker for 4.8.1
rc2 right now) and, would we export that symbol as @@GLIBCXX_3.4.18 (with
all trunk @@GLIBCXX_3.4.18 symbols moved to 3.4.19) and add @GLIBCXX_3.4.17
alias for backwards compatibility with those that configured with
--enable-libstdcxx-time=rt ?

--- libstdc++-v3/src/c++11/	2013-03-16 08:07:57.000000000 +0100
+++ libstdc++-v3/src/c++11/	2013-05-23 12:08:04.165686015 +0200
@@ -32,6 +32,9 @@
 #include <sys/time.h>
+#include <sys/syscall.h>
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -47,7 +50,11 @@ namespace std _GLIBCXX_VISIBILITY(defaul
       timespec tp;
       // -EINVAL, -EFAULT
+      syscall(SYS_clock_gettime, CLOCK_REALTIME, &tp);
       clock_gettime(CLOCK_REALTIME, &tp);
       return time_point(duration(chrono::seconds(tp.tv_sec)
 				 + chrono::nanoseconds(tp.tv_nsec)));
@@ -70,7 +77,11 @@ namespace std _GLIBCXX_VISIBILITY(defaul
       timespec tp;
       // -EINVAL, -EFAULT
+      syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &tp);
       clock_gettime(CLOCK_MONOTONIC, &tp);
       return time_point(duration(chrono::seconds(tp.tv_sec)
 				 + chrono::nanoseconds(tp.tv_nsec)));
--- libstdc++-v3/acinclude.m4.jj	2013-04-10 08:32:08.000000000 +0200
+++ libstdc++-v3/acinclude.m4	2013-05-23 12:03:29.626014601 +0200
+  if test x"$ac_has_clock_monotonic" != x"yes"; then
+    AC_MSG_CHECKING([for clock_gettime syscall])
+      [#include <unistd.h>
+       #include <time.h>
+       #include <sys/syscall.h>
+      ],
+      [#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
+	timespec tp;
+       #endif
+       syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &tp);
+       syscall(SYS_clock_gettime, CLOCK_REALTIME, &tp);
+      ], [ac_has_clock_monotonic_syscall=yes], [ac_has_clock_monotonic_syscall=no])
+    AC_MSG_RESULT($ac_has_clock_monotonic_syscall)
+    if test x"$ac_has_clock_monotonic_syscall" = x"yes"; then
+      [ Defined if clock_gettime syscall has monotonic clock support. ])
+      ac_has_clock_monotonic=yes
+      ac_has_clock_realtime=yes
+    fi
+  fi
   if test x"$ac_has_clock_monotonic" = x"yes"; then
       [ Defined if clock_gettime has monotonic clock support. ])


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]