From 0b7fa5a05deecaf52207f00bb02b5c6b460abb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 27 Jun 2019 12:19:51 +0300 Subject: MDEV-19845: Fix the build on some x86 targets The RDTSC instruction, which was introduced in the Intel Pentium, has been used in MariaDB for a long time. But, the __rdtsc() wrapper is not available by default in some x86 build environments. The simplest solution seems to replace the inlined instruction with a call to the wrapper function my_timer_cycles(). The overhead for the call should not affect the measurement threshold. On Windows and on AMD64, we will keep using __rdtsc() directly. --- mysys/my_cpu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'mysys/my_cpu.c') diff --git a/mysys/my_cpu.c b/mysys/my_cpu.c index cd13624df0f..dd8ff4b6a02 100644 --- a/mysys/my_cpu.c +++ b/mysys/my_cpu.c @@ -24,8 +24,15 @@ unsigned my_cpu_relax_multiplier = 200; # ifdef _MSC_VER # include +# define my_timer_cycles __rdtsc +# elif !defined __x86_64__ +/* On some x86 targets, __rdtsc() causes an unresolved external symbol error, +instead of being inlined. Let us fall back to my_timer_cycles(), which +internally invokes rdtsc. */ +# include # else # include +# define my_timer_cycles __rdtsc # endif #define PAUSE4 MY_RELAX_CPU(); MY_RELAX_CPU(); MY_RELAX_CPU(); MY_RELAX_CPU() @@ -70,11 +77,11 @@ unsigned my_cpu_relax_multiplier = 200; void my_cpu_init(void) { uint64_t t0, t1, t2; - t0= __rdtsc(); + t0= my_timer_cycles(); PAUSE16; - t1= __rdtsc(); + t1= my_timer_cycles(); PAUSE16; - t2= __rdtsc(); + t2= my_timer_cycles(); if (t2 - t1 > 30 * 16 && t1 - t0 > 30 * 16) my_cpu_relax_multiplier= 20; } -- cgit v1.2.1