]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86: Support RDTSCP for benchtests
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 24 Oct 2018 09:19:15 +0000 (02:19 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 24 Oct 2018 09:19:34 +0000 (02:19 -0700)
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.

ChangeLog
benchtests/Makefile
benchtests/README
sysdeps/x86/hp-timing.h

index 6cb7d604ce48eaf38a2021c696b65b9d59216f9f..cda75db202b269acb46992fa9af97b515b634f58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-10-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * 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.
+
 2018-10-23  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        * misc/tst-preadvwritev2-common.c (IOV_MAX): Define if not
index bcd6a9c26d9a0005a09439b0b1c6aa5b3a218754..45aeb5febe8f13ac598f5edbb6696364f3be1d32 100644 (file)
@@ -131,6 +131,12 @@ CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC
 # HP_TIMING if it is available.
 ifdef USE_CLOCK_GETTIME
 CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME
+else
+# On x86 processors, use RDTSCP, instead of RDTSC, to measure performance
+# of functions.  All x86 processors since 2010 support RDTSCP instruction.
+ifdef USE_RDTSCP
+CPPFLAGS-nonlib += -DUSE_RDTSCP
+endif
 endif
 
 DETAILED_OPT :=
index 4ddff794d136f65fefb90c23f0fd6a4f5babaea2..aaf0b659e2b25627230a7280cd858a29f5532392 100644 (file)
@@ -34,6 +34,15 @@ the benchmark to use clock_gettime by invoking make as follows:
 
 Again, one must run `make bench-clean' before changing the measurement method.
 
+On x86 processors, RDTSCP instruction provides more precise timing data
+than RDTSC instruction.  All x86 processors since 2010 support RDTSCP
+instruction.  One can force the benchmark to use RDTSCP by invoking make
+as follows:
+
+  $ make USE_RDTSCP=1 bench
+
+One must run `make bench-clean' before changing the measurement method.
+
 Running benchmarks on another target:
 ====================================
 
index 77a1360748ca453549c565094350e5f91cf1df63..0aa6f5e3f83e0d34e64ba32b0a70855713f1e4e0 100644 (file)
@@ -40,7 +40,19 @@ typedef unsigned long long int hp_timing_t;
 
    NB: Use __builtin_ia32_rdtsc directly since including <x86intrin.h>
    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 <hp-timing-common.h>
 #else