This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/21305] clock_gettime(CLOCK_MONOTONIC_RAW) can and should use rdtsc instructions instead of entering kernel through VDSO


https://sourceware.org/bugzilla/show_bug.cgi?id=21305

--- Comment #5 from Jason Vas Dias <jason.vas.dias at gmail dot com> ---
Created attachment 9941
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9941&action=edit
testcase / demo of problem

A simple testcase / demo of the issue :
$ tar -xpf ttsc.tar
$ cd ttsc
$ make
...
$ ./ttsc1
max_extended_leaf: 80000008
has tsc: 1 constant: 1
Invariant TSC is enabled: Actual TSC freq: 2.893299GHz - TSC adjust: 1.
ts2 - ts1: 157 ts3 - ts2: 87 ns1: 0.000000755 ns2: 0.000003167
ts3 - ts2: 184 ns1: 0.000000763
ts3 - ts2: 19 ns1: 0.000000729
ts3 - ts2: 20 ns1: 0.000000783
ts3 - ts2: 22 ns1: 0.000001284
ts3 - ts2: 23 ns1: 0.000001344
ts3 - ts2: 21 ns1: 0.000001221
ts3 - ts2: 21 ns1: 0.000001216
ts3 - ts2: 21 ns1: 0.000001025
ts3 - ts2: 28 ns1: 0.000001196
ts3 - ts2: 18 ns1: 0.000001237
t1 - t0: 104579 - ns2: 0.000107727


The number shown as 'ts3 - ts2' is the difference between 
    ts2=IA64_s_ns_since_start();
    ts3=IA64_s_ns_since_start();
obtained by invoking rdtscp in user space,
and ns1 is the difference between the 
timestamps in tsp1 & tsp2 after:
    clock_gettime(CLOCK_MONOTONIC_RAW,&tsp1);
    clock_gettime(CLOCK_MONOTONIC_RAW,&tsp2);

The total at the end (t1 - t0) is the total
elapsed time as measured by rdtscp in userspace: 104579ns
versus the total measured by clock_gettime     : 107727ns
which are very close; they would be closer if precisely
the same values were used for gtod->mult and gtod-shift
were used as the kernel uses, but this version uses the
values calculated from tsc_khz , not the vvar_vdso_gtod_data
values.

So now I need to know : will a future version of glibc 
ever consider providing an interface to rdtscp in user-space 
for such platforms as my machine ?

If so, I will submit a patch to make glibc do this.

If not, I will need to expand ttsc.tar into a full featured
'libIA64_tsc.so' library, which will be used by my code if
it runs on a glibc system, but not if on an Ubuntu/Debian libc6
system, because as already noted Ubuntu + Debian already redirect
calls to clock_gettime(CLOCK_MONOTONIC_RAW,&ts) to a function that
does an unlocked 'rdtscp' instruction in userspace.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]