Skip to content

Commit 20512a6

Browse files
grooverdankevgs
authored andcommitted
MDEV-23175: my_timer_milliseconds ftime deprecated - clock_gettime replacement
Linux glibc has deprecated ftime resutlting in a compile error on Fedora-32. Per manual clock_gettime is the suggested replacement. Because my_timer_milliseconds is a relative time used by largely the perfomrance schema, CLOCK_MONOTONIC_COARSE is used. This has been available since Linux-2.6.32. The low overhead is shows in the unittest: $ unittest/mysys/my_rdtsc-t 1..11 # ----- Routine --------------- # myt.cycles.routine : 5 # myt.nanoseconds.routine : 11 # myt.microseconds.routine : 13 # myt.milliseconds.routine : 18 # myt.ticks.routine : 17 # ----- Frequency ------------- # myt.cycles.frequency : 3596597014 # myt.nanoseconds.frequency : 1000000000 # myt.microseconds.frequency : 1000000 # myt.milliseconds.frequency : 1039 # myt.ticks.frequency : 103 # ----- Resolution ------------ # myt.cycles.resolution : 1 # myt.nanoseconds.resolution : 1 # myt.microseconds.resolution : 1 # myt.milliseconds.resolution : 1 # myt.ticks.resolution : 1 # ----- Overhead -------------- # myt.cycles.overhead : 118 # myt.nanoseconds.overhead : 234 # myt.microseconds.overhead : 222 # myt.milliseconds.overhead : 30 # myt.ticks.overhead : 4946 ok 1 - my_timer_init() did not crash ok 2 - The cycle timer is strictly increasing ok 3 - The cycle timer is implemented ok 4 - The nanosecond timer is increasing ok 5 - The nanosecond timer is implemented ok 6 - The microsecond timer is increasing ok 7 - The microsecond timer is implemented ok 8 - The millisecond timer is increasing ok 9 - The millisecond timer is implemented ok 10 - The tick timer is increasing ok 11 - The tick timer is implemented
1 parent e67daa5 commit 20512a6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

configure.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,12 @@ CHECK_INCLUDE_FILES(ia64intrin.h HAVE_IA64INTRIN_H)
441441
CHECK_FUNCTION_EXISTS(times HAVE_TIMES)
442442
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
443443
CHECK_FUNCTION_EXISTS(read_real_time HAVE_READ_REAL_TIME)
444-
# This should work on AIX.
445444

445+
IF(NOT HAVE_CLOCK_GETTIME)
446+
# This should work on AIX.
446447
CHECK_FUNCTION_EXISTS(ftime HAVE_FTIME)
448+
ENDIF()
449+
447450
# This is still a normal call for milliseconds.
448451

449452
CHECK_FUNCTION_EXISTS(time HAVE_TIME)

mysys/my_rdtsc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#endif
7676
#endif
7777

78-
#if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
78+
#if !defined(CLOCK_GETTIME) && defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
7979
#include <sys/timeb.h> /* for ftime */
8080
#endif
8181

@@ -175,7 +175,17 @@ ulonglong my_timer_microseconds(void)
175175

176176
ulonglong my_timer_milliseconds(void)
177177
{
178-
#if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
178+
#if defined(HAVE_CLOCK_GETTIME)
179+
struct timespec tp;
180+
#ifdef CLOCK_MONOTONIC_COARSE
181+
/* Linux */
182+
clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);
183+
#else
184+
/* POSIX */
185+
clock_gettime(CLOCK_MONOTONIC, &tp);
186+
#endif
187+
return (ulonglong)tp.tv_sec * 1000 + (ulonglong)tp.tv_nsec / 1000000;
188+
#elif defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
179189
/* ftime() is obsolete but maybe the platform is old */
180190
struct timeb ft;
181191
ftime(&ft);

0 commit comments

Comments
 (0)