summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorJulius Goryavsky <julius.goryavsky@mariadb.com>2021-12-23 14:14:04 +0100
committerJulius Goryavsky <julius.goryavsky@mariadb.com>2021-12-23 14:14:04 +0100
commit3376668ca8799f2dc79b3d71a55c062d55e0f09b (patch)
tree5b61e2482ea1829c2722faa6e0d5b0e4ee4b25c2 /mysys
parenta5ef74e7eb4bab09c9bda4fcd7fab12302526ea4 (diff)
parent12087d67579e641cfc07ee6b8c46b75171e9708c (diff)
downloadmariadb-git-3376668ca8799f2dc79b3d71a55c062d55e0f09b.tar.gz
Merge branch 10.2 into 10.3
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_rdtsc.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/mysys/my_rdtsc.c b/mysys/my_rdtsc.c
index b020e224a59..605ac20350c 100644
--- a/mysys/my_rdtsc.c
+++ b/mysys/my_rdtsc.c
@@ -356,9 +356,29 @@ 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_SYS_TIMEB_H) && defined(HAVE_FTIME)
+#if defined(MY_CLOCK_ID)
+ struct timespec tp;
+ 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 */
struct timeb ft;
ftime(&ft);
@@ -631,7 +651,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;