This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] Default to --enable-libstdcxx-time=auto
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>, Benjamin Kosnik <bkoz at redhat dot com>
- Cc: Paolo Carlini <paolo dot carlini at oracle dot com>, libstdc++ <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Rainer Orth <ro at cebitec dot uni-bielefeld dot de>
- Date: Thu, 23 May 2013 12:28:27 +0200
- Subject: Re: [patch] Default to --enable-libstdcxx-time=auto
- References: <519C942D dot 6050100 at oracle dot com> <CAH6eHdTjdi75WSwKYfdGBtOeQwbsSvMbzzxo24qofMexFSmETA at mail dot gmail dot com> <519C9AF5 dot 8090300 at oracle dot com> <519C9CBC dot 4050606 at oracle dot com> <519C9E3B dot 60609 at oracle dot com> <CAH6eHdRXAK1r0g7u+50RobAxTo=6DJsvRZzo75m7x+5ir3opKQ at mail dot gmail dot com> <CAH6eHdS5gqa2nfNJfC0zy9FJq4amgjJbtUuEASM_Qw0GZ8-9aA at mail dot gmail dot com> <20130522111543 dot GG1377 at tucnak dot redhat dot com> <CAH6eHdR0MocSNhvD_xRfhcYiaGugs8P++oJnTyy5DSAiDh=hPg at mail dot gmail dot com> <20130522123540 dot GH1377 at tucnak dot redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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
> #if _GLIBCXX_HAS_SYS_SYSCALL_H
> #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 chrono.cc 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/chrono.cc.jj 2013-03-16 08:07:57.000000000 +0100
+++ libstdc++-v3/src/c++11/chrono.cc 2013-05-23 12:08:04.165686015 +0200
@@ -32,6 +32,9 @@
defined(_GLIBCXX_USE_GETTIMEOFDAY)
#include <sys/time.h>
#endif
+#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC_SYSCALL
+#include <sys/syscall.h>
+#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
@@ -47,7 +50,11 @@ namespace std _GLIBCXX_VISIBILITY(defaul
#ifdef _GLIBCXX_USE_CLOCK_REALTIME
timespec tp;
// -EINVAL, -EFAULT
+#ifdef _GLIBCXX_USE_CLOCK_REALTIME_SYSCALL
+ syscall(SYS_clock_gettime, CLOCK_REALTIME, &tp);
+#else
clock_gettime(CLOCK_REALTIME, &tp);
+#endif
return time_point(duration(chrono::seconds(tp.tv_sec)
+ chrono::nanoseconds(tp.tv_nsec)));
#elif defined(_GLIBCXX_USE_GETTIMEOFDAY)
@@ -70,7 +77,11 @@ namespace std _GLIBCXX_VISIBILITY(defaul
{
timespec tp;
// -EINVAL, -EFAULT
+#ifdef _GLIBCXX_USE_CLOCK_REALTIME_SYSCALL
+ syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &tp);
+#else
clock_gettime(CLOCK_MONOTONIC, &tp);
+#endif
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
@@ -1274,6 +1274,28 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME]
fi
fi
+ if test x"$ac_has_clock_monotonic" != x"yes"; then
+ AC_MSG_CHECKING([for clock_gettime syscall])
+ AC_TRY_COMPILE(
+ [#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
+ AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC_SYSCALL, 1,
+ [ 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
AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1,
[ Defined if clock_gettime has monotonic clock support. ])
Jakub