From 7cc65773f04e0f4252428c40dcbb784a39b58cd1 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 24 Oct 2018 02:19:15 -0700 Subject: x86: Support RDTSCP for benchtests RDTSCP waits until all previous instructions have executed and all previous loads are globally visible before reading the counter. RDTSC doesn't wait until all previous instructions have been executed before reading the counter. All x86 processors since 2010 support RDTSCP instruction. This patch adds RDTSCP support to benchtests. * benchtests/Makefile (CPPFLAGS-nonlib): Add -DUSE_RDTSCP if USE_RDTSCP is defined. * sysdeps/x86/hp-timing.h (HP_TIMING_NOW): Use RDTSCP if USE_RDTSCP is defined. --- sysdeps/x86/hp-timing.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sysdeps/x86') diff --git a/sysdeps/x86/hp-timing.h b/sysdeps/x86/hp-timing.h index 77a1360748..0aa6f5e3f8 100644 --- a/sysdeps/x86/hp-timing.h +++ b/sysdeps/x86/hp-timing.h @@ -40,7 +40,19 @@ typedef unsigned long long int hp_timing_t; NB: Use __builtin_ia32_rdtsc directly since including makes building glibc very slow. */ -# define HP_TIMING_NOW(Var) ((Var) = __builtin_ia32_rdtsc ()) +# ifdef USE_RDTSCP +/* RDTSCP waits until all previous instructions have executed and all + previous loads are globally visible before reading the counter. + RDTSC doesn't wait until all previous instructions have been executed + before reading the counter. */ +# define HP_TIMING_NOW(Var) \ + (__extension__ ({ \ + unsigned int __aux; \ + (Var) = __builtin_ia32_rdtscp (&__aux); \ + })) +# else +# define HP_TIMING_NOW(Var) ((Var) = __builtin_ia32_rdtsc ()) +# endif # include #else -- cgit 1.4.1