Discussion:
[x264-devel] [patch] Prefer clock_gettime(CLOCK_MONOTONIC) on Linux.
Petter Reinholdtsen
2018-06-16 06:01:32 UTC
Permalink
This avoid discontinuous jumps in the system time that affect
gettimeofday() on Linux.

Based on patch from Kieran Kunhya found in x264-obe.

diff --git a/common/osdep.c b/common/osdep.c
index 3f43d483..d1eeb6e8 100644
--- a/common/osdep.c
+++ b/common/osdep.c
@@ -51,6 +51,10 @@ int64_t x264_mdate( void )
struct timeb tb;
ftime( &tb );
return ((int64_t)tb.time * 1000 + (int64_t)tb.millitm) * 1000;
+#elif SYS_LINUX
+ struct timespec ts_current;
+ clock_gettime( CLOCK_MONOTONIC, &ts_current );
+ return (int64_t)ts_current.tv_sec * 1000000 + (int64_t)ts_current.tv_nsec / 1000;
#else
struct timeval tv_date;
gettimeofday( &tv_date, NULL );
--
Happy hacking
Petter Reinholdtsen
Brad Smith
2018-06-24 17:28:23 UTC
Permalink
This should be using a test in the configure script for clock_gettime()
and not limited to Linux.
Post by Petter Reinholdtsen
This avoid discontinuous jumps in the system time that affect
gettimeofday() on Linux.
Based on patch from Kieran Kunhya found in x264-obe.
diff --git a/common/osdep.c b/common/osdep.c
index 3f43d483..d1eeb6e8 100644
--- a/common/osdep.c
+++ b/common/osdep.c
@@ -51,6 +51,10 @@ int64_t x264_mdate( void )
struct timeb tb;
ftime( &tb );
return ((int64_t)tb.time * 1000 + (int64_t)tb.millitm) * 1000;
+#elif SYS_LINUX
+ struct timespec ts_current;
+ clock_gettime( CLOCK_MONOTONIC, &ts_current );
+ return (int64_t)ts_current.tv_sec * 1000000 + (int64_t)ts_current.tv_nsec / 1000;
#else
struct timeval tv_date;
gettimeofday( &tv_date, NULL );
Petter Reinholdtsen
2018-06-24 20:36:45 UTC
Permalink
[Brad Smith]
Post by Brad Smith
This should be using a test in the configure script for clock_gettime()
and not limited to Linux.
Thank you for having a look at my proposed patch.

I am unable to test if clock_gettime() work on any non-Linux platform,
so I can not verify that your proposal will work. I guess this make
implementing such change suitable for someone with more test equipment
than me.

Should the inclusion of my proposed change wait until someone have time
to test it on non-Linux platforms to verify its correctness on non-linux
platforms?
--
Happy hacking
Petter Reinholdtsen
Henrik Gramner
2018-06-24 22:44:58 UTC
Permalink
Post by Petter Reinholdtsen
This avoid discontinuous jumps in the system time that affect
gettimeofday() on Linux.
Based on patch from Kieran Kunhya found in x264-obe.
Pushed a slightly different version with a configuration check to x264-sandbox.
Loading...