summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Black <daniel@mariadb.org>2020-07-15 11:23:19 +1000
committerDaniel Black <daniel@mariadb.org>2020-07-24 17:40:17 +1000
commit8be327e256703d9999f453c143f91d66aa7d4aca (patch)
tree770ae264f59a89c9aeddc8772d8d4bbd9bcc7e9c
parenta18639f1a913b446f32d7fbe531aa0d5782cf720 (diff)
downloadmariadb-git-bb-10.5-danielblack-MDEV-23175-clock_gettime_multios.tar.gz
MDEV-23175: my_timer_milliseconds clock_gettime for multiple platfomrsbb-10.5-danielblack-MDEV-23175-clock_gettime_multios
Small postfix to MDEV-23175 to ensure faster option on FreeBSD and compatibility to Solaris that isn't high resolution. ftime is left as a backup in case an implementation doesn't contain any of these clocks. FreeBSD $ ./unittest/mysys/my_rdtsc-t 1..11 # ----- Routine --------------- # myt.cycles.routine : 5 # myt.nanoseconds.routine : 11 # myt.microseconds.routine : 13 # myt.milliseconds.routine : 11 # myt.ticks.routine : 17 # ----- Frequency ------------- # myt.cycles.frequency : 3610295566 # myt.nanoseconds.frequency : 1000000000 # myt.microseconds.frequency : 1000000 # myt.milliseconds.frequency : 899 # myt.ticks.frequency : 136 # ----- Resolution ------------ # myt.cycles.resolution : 1 # myt.nanoseconds.resolution : 1 # myt.microseconds.resolution : 1 # myt.milliseconds.resolution : 7 # myt.ticks.resolution : 1 # ----- Overhead -------------- # myt.cycles.overhead : 26 # myt.nanoseconds.overhead : 19140 # myt.microseconds.overhead : 19036 # myt.milliseconds.overhead : 578 # myt.ticks.overhead : 21544 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
-rw-r--r--configure.cmake5
-rw-r--r--mysys/my_rdtsc.c32
2 files changed, 23 insertions, 14 deletions
diff --git a/configure.cmake b/configure.cmake
index f3f68775b50..a7e044b13d2 100644
--- a/configure.cmake
+++ b/configure.cmake
@@ -441,12 +441,9 @@ CHECK_INCLUDE_FILES(ia64intrin.h HAVE_IA64INTRIN_H)
CHECK_FUNCTION_EXISTS(times HAVE_TIMES)
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
CHECK_FUNCTION_EXISTS(read_real_time HAVE_READ_REAL_TIME)
-
-IF(NOT HAVE_CLOCK_GETTIME)
# This should work on AIX.
-CHECK_FUNCTION_EXISTS(ftime HAVE_FTIME)
-ENDIF()
+CHECK_FUNCTION_EXISTS(ftime HAVE_FTIME)
# This is still a normal call for milliseconds.
CHECK_FUNCTION_EXISTS(time HAVE_TIME)
diff --git a/mysys/my_rdtsc.c b/mysys/my_rdtsc.c
index 514fd4c74ea..40b78986985 100644
--- a/mysys/my_rdtsc.c
+++ b/mysys/my_rdtsc.c
@@ -75,7 +75,7 @@
#endif
#endif
-#if !defined(CLOCK_GETTIME) && defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
+#if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
#include <sys/timeb.h> /* for ftime */
#endif
@@ -173,17 +173,27 @@ ulonglong my_timer_microseconds(void)
milliseconds.
*/
+#if defined(HAVE_CLOCK_GETTIME)
+#if defined(CLOCK_MONOTONIC_FAST)
+/* FreeBSD */
+#define MY_CLOCK_ID CLOCK_MONOTONIC_FAST
+#elif defined(CLOCK_MONOTONIC_COARSE)
+/* Linux */
+#define MY_CLOCK_ID CLOCK_MONOTONIC_COARSE
+#elif defined(CLOCK_MONOTONIC)
+/* POSIX (includes OSX) */
+#define MY_CLOCK_ID CLOCK_MONOTONIC
+#elif defined(CLOCK_REALTIME)
+/* Solaris (which doesn't seem to have MONOTONIC) */
+#define MY_CLOCK_ID CLOCK_REALTIME
+#endif
+#endif
+
ulonglong my_timer_milliseconds(void)
{
-#if defined(HAVE_CLOCK_GETTIME)
+#if defined(MY_CLOCK_ID)
struct timespec tp;
-#ifdef CLOCK_MONOTONIC_COARSE
- /* Linux */
- clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);
-#else
- /* POSIX */
- clock_gettime(CLOCK_MONOTONIC, &tp);
-#endif
+ clock_gettime(MY_CLOCK_ID, &tp);
return (ulonglong)tp.tv_sec * 1000 + (ulonglong)tp.tv_nsec / 1000000;
#elif defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
/* ftime() is obsolete but maybe the platform is old */
@@ -436,7 +446,9 @@ void my_timer_init(MY_TIMER_INFO *mti)
/* milliseconds */
mti->milliseconds.frequency= 1000; /* initial assumption */
-#if defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
+#ifdef MY_CLOCK_ID
+ mti->milliseconds.routine= MY_TIMER_ROUTINE_CLOCK_GETTIME;
+#elif defined(HAVE_SYS_TIMEB_H) && defined(HAVE_FTIME)
mti->milliseconds.routine= MY_TIMER_ROUTINE_FTIME;
#elif defined(_WIN32)
mti->milliseconds.routine= MY_TIMER_ROUTINE_GETSYSTEMTIMEASFILETIME;