Skip to content
Browse files

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.
  • Loading branch information...
dr-m committed Jun 27, 2019
1 parent 042fc29 commit 0b7fa5a05deecaf52207f00bb02b5c6b460abb11
Showing with 10 additions and 3 deletions.
  1. +10 −3 mysys/my_cpu.c
@@ -24,8 +24,15 @@ unsigned my_cpu_relax_multiplier = 200;

# ifdef _MSC_VER
# include <intrin.h>
# 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 <my_rdtsc.h>
# else
# include <x86intrin.h>
# define my_timer_cycles __rdtsc
# endif

@@ -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();
t1= __rdtsc();
t1= my_timer_cycles();
t2= __rdtsc();
t2= my_timer_cycles();
if (t2 - t1 > 30 * 16 && t1 - t0 > 30 * 16)
my_cpu_relax_multiplier= 20;

0 comments on commit 0b7fa5a

Please sign in to comment.
You can’t perform that action at this time.