time stamp counter in "make check"

Dmitrieva Liubov liubov.dmitrieva@gmail.com
Thu Jul 12 14:58:00 GMT 2012


Hello All,

So at the moment in "make check" RDTSC instruction is used for
computation timing on x86, but this instruction produces misleading
results on out-of-order machines.

Especially dramatically it can be seen on Core i-7.

Examples:

>From string/test-memcpy.out

Length   21, alignment  0/21:   -20     0       24
Length   21, alignment 21/21:   -20     8       20
Length   22, alignment  0/ 0:   4       8       24
Length   22, alignment 22/ 0:   -20     -20     28
Length   22, alignment  0/22:   -20     0       28
...

>From  string/test-strlen.out

Length   28, alignment 28/ 0:   -20     -20     44
Length   28, alignment  0/28:   -20     -20     44
Length   28, alignment 28/28:   -20     0       40
Length   29, alignment  0/ 0:   0       4       44
Length   29, alignment 29/ 0:   16      0       48
Length   29, alignment  0/29:   -20     4       48
Length   29, alignment 29/29:   0       -20     44
Length   30, alignment  0/ 0:   4       4       48


Almost in every test-<some string function>.out negative execution
time :) can be seen.

So, my proposal is to change from "rdtsc" instruction to "rdtscp"
instruction (which is a serializing variant of the RDTSC)  if rdtscp
is available for target architecture.
This definitely solves the issue with negatives values.

All places with "rdtsc":

-bash-4.2$ grep -r "rdtsc" .
./sysdeps/x86_64/memusage.h:    #define GETTIME(low,high) asm
("rdtscp" : "=a" (low), "=d" (high))
./sysdeps/x86_64/hp-timing.h:       asm volatile ("rdtscp" : "=a"
(_lo), "=d" (_hi)); \
./sysdeps/i386/i686/memusage.h:  #define GETTIME(low,high) asm
("rdtsc" : "=a" (low), "=d" (high))
./sysdeps/i386/i686/hp-timing.h:    /* That's quite simple.  Use the
`rdtsc' instruction.  Note that the value
./sysdeps/i386/i686/hp-timing.h:    'cpuid' right before the `rdtsc'
instruciton.  But we are not interested
./sysdeps/i386/i686/hp-timing.h:   #define HP_TIMING_NOW(Var)
__asm__ __volatile__ ("rdtsc" : "=A" (Var))
./sysdeps/i386/i686/hp-timing.h:   /* Use two 'rdtsc' instructions in
a row to find out how long it takes.  */
./nptl/perf.c:           #define HP_TIMING_NOW(Var)        __asm__
__volatile__ ("rdtsc" : "=A" (Var))
./nptl/perf.c:           asm volatile ("rdtsc" : "=a" (_lo), "=d" (_hi)); \
./nptl/sockperf.c:    #define HP_TIMING_NOW(Var)    __asm__
__volatile__ ("rdtsc" : "=A" (Var))


--
Liubov Dmitrieva
Intel Corporation



More information about the Libc-alpha mailing list