* [PATCH] A steadier steady_clock
@ 2012-10-21 14:17 Sam Varshavchik
2012-10-21 19:34 ` Paolo Carlini
2012-10-21 21:26 ` Florian Weimer
0 siblings, 2 replies; 5+ messages in thread
From: Sam Varshavchik @ 2012-10-21 14:17 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 750 bytes --]
Based on a casual browsing of clock_gettime(3), CLOCK_MONOTONIC_RAW seems to
be a better fit for std::chrono::steady_clock's requirements as given in
20.11.7.2, with recent Linux kernels,
Something like this:
Index: libstdc++-v3/src/c++11/chrono.cc
===================================================================
--- libstdc++-v3/src/c++11/chrono.cc (revision 192652)
+++ libstdc++-v3/src/c++11/chrono.cc (working copy)
@@ -70,7 +70,11 @@
{
timespec tp;
// -EINVAL, -EFAULT
+#ifdef CLOCK_MONOTONIC_RAW
+ clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
+#else
clock_gettime(CLOCK_MONOTONIC, &tp);
+#endif
return time_point(duration(chrono::seconds(tp.tv_sec)
+ chrono::nanoseconds(tp.tv_nsec)));
}
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] A steadier steady_clock
2012-10-21 14:17 [PATCH] A steadier steady_clock Sam Varshavchik
@ 2012-10-21 19:34 ` Paolo Carlini
2012-10-22 1:54 ` Ulrich Drepper
2012-10-21 21:26 ` Florian Weimer
1 sibling, 1 reply; 5+ messages in thread
From: Paolo Carlini @ 2012-10-21 19:34 UTC (permalink / raw)
To: Sam Varshavchik; +Cc: gcc-patches, libstdc++
On 10/21/2012 04:00 PM, Sam Varshavchik wrote:
> Based on a casual browsing of clock_gettime(3), CLOCK_MONOTONIC_RAW
> seems to be a better fit for std::chrono::steady_clock's requirements
> as given in 20.11.7.2, with recent Linux kernels,
>
> Something like this:
Please always CC library patches to libstdc++@gcc.gnu.org.
>
>
> Index: libstdc++-v3/src/c++11/chrono.cc
> ===================================================================
> --- libstdc++-v3/src/c++11/chrono.cc (revision 192652)
> +++ libstdc++-v3/src/c++11/chrono.cc (working copy)
> @@ -70,7 +70,11 @@
> {
> timespec tp;
> // -EINVAL, -EFAULT
> +#ifdef CLOCK_MONOTONIC_RAW
> + clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
> +#else
> clock_gettime(CLOCK_MONOTONIC, &tp);
> +#endif
> return time_point(duration(chrono::seconds(tp.tv_sec)
> + chrono::nanoseconds(tp.tv_nsec)));
> }
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] A steadier steady_clock
2012-10-21 14:17 [PATCH] A steadier steady_clock Sam Varshavchik
2012-10-21 19:34 ` Paolo Carlini
@ 2012-10-21 21:26 ` Florian Weimer
2012-10-22 3:47 ` Sam Varshavchik
1 sibling, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2012-10-21 21:26 UTC (permalink / raw)
To: Sam Varshavchik; +Cc: gcc-patches, libstdc++
* Sam Varshavchik:
> Based on a casual browsing of clock_gettime(3), CLOCK_MONOTONIC_RAW
> seems to be a better fit for std::chrono::steady_clock's requirements
> as given in 20.11.7.2, with recent Linux kernels,
Are the Linux clock semantics documented somewhere in detail?
> +#ifdef CLOCK_MONOTONIC_RAW
> + clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
> +#else
> clock_gettime(CLOCK_MONOTONIC, &tp);
> +#endif
If a #define is available at compile time, it's not necessarily the
case that the feature is present at run time. If CLOCK_MONOTONIC_RAW
is indeed what we want, we need fallback code.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] A steadier steady_clock
2012-10-21 19:34 ` Paolo Carlini
@ 2012-10-22 1:54 ` Ulrich Drepper
0 siblings, 0 replies; 5+ messages in thread
From: Ulrich Drepper @ 2012-10-22 1:54 UTC (permalink / raw)
To: Paolo Carlini; +Cc: Sam Varshavchik, gcc-patches, libstdc++
On Sun, Oct 21, 2012 at 12:11 PM, Paolo Carlini
<paolo.carlini@oracle.com> wrote:
\>> @@ -70,7 +70,11 @@
>> {
>> timespec tp;
>> // -EINVAL, -EFAULT
>> +#ifdef CLOCK_MONOTONIC_RAW
>> + clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
>> +#else
>> clock_gettime(CLOCK_MONOTONIC, &tp);
>> +#endif
>> return time_point(duration(chrono::seconds(tp.tv_sec)
>> + chrono::nanoseconds(tp.tv_nsec)));
>> }
That'll have to be something like
#ifdef CLOCK_MONOTONIC_RAW
if (clock_gettime(CLOCK_MONOTONIC_RAW, &tp) != 0)
#endif
clock_gettime(CLOCK_MONOTONIC, &tp);
Only way out of this is when you introduce a check for a minimum
kernel ABI somewhere, just like glibc does.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] A steadier steady_clock
2012-10-21 21:26 ` Florian Weimer
@ 2012-10-22 3:47 ` Sam Varshavchik
0 siblings, 0 replies; 5+ messages in thread
From: Sam Varshavchik @ 2012-10-22 3:47 UTC (permalink / raw)
To: Florian Weimer; +Cc: gcc-patches, libstdc++
[-- Attachment #1: Type: text/plain, Size: 622 bytes --]
Florian Weimer writes:
> * Sam Varshavchik:
>
> > Based on a casual browsing of clock_gettime(3), CLOCK_MONOTONIC_RAW
> > seems to be a better fit for std::chrono::steady_clock's requirements
> > as given in 20.11.7.2, with recent Linux kernels,
>
> Are the Linux clock semantics documented somewhere in detail?
clock_gettime(3) says:
# CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
# Similar to CLOCK_MONOTONIC, but provides access to a raw hard‐
# ware-based time that is not subject to NTP adjustments.
That looks like a better fit for what 20.11.7.2 says steady_clock should be.
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-10-22 1:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-21 14:17 [PATCH] A steadier steady_clock Sam Varshavchik
2012-10-21 19:34 ` Paolo Carlini
2012-10-22 1:54 ` Ulrich Drepper
2012-10-21 21:26 ` Florian Weimer
2012-10-22 3:47 ` Sam Varshavchik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).