]>
Commit | Line | Data |
---|---|---|
72771e53 | 1 | /* High precision, low overhead timing functions. x86 version. |
2b778ceb | 2 | Copyright (C) 2018-2021 Free Software Foundation, Inc. |
db276fa1 | 3 | This file is part of the GNU C Library. |
db276fa1 UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
db276fa1 UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
db276fa1 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
db276fa1 UD |
18 | |
19 | #ifndef _HP_TIMING_H | |
20 | #define _HP_TIMING_H 1 | |
21 | ||
72771e53 L |
22 | #include <isa.h> |
23 | ||
24 | #if MINIMUM_ISA == 686 || MINIMUM_ISA == 8664 | |
db276fa1 | 25 | /* We indeed have inlined functions. */ |
72771e53 | 26 | # define HP_TIMING_INLINE (1) |
db276fa1 UD |
27 | |
28 | /* We use 64bit values for the times. */ | |
29 | typedef unsigned long long int hp_timing_t; | |
30 | ||
db276fa1 UD |
31 | /* That's quite simple. Use the `rdtsc' instruction. Note that the value |
32 | might not be 100% accurate since there might be some more instructions | |
33 | running in this moment. This could be changed by using a barrier like | |
34 | 'cpuid' right before the `rdtsc' instruciton. But we are not interested | |
2dd8e58c L |
35 | in accurate clock cycles here so we don't do this. |
36 | ||
37 | NB: Use __builtin_ia32_rdtsc directly since including <x86intrin.h> | |
38 | makes building glibc very slow. */ | |
7cc65773 L |
39 | # ifdef USE_RDTSCP |
40 | /* RDTSCP waits until all previous instructions have executed and all | |
41 | previous loads are globally visible before reading the counter. | |
42 | RDTSC doesn't wait until all previous instructions have been executed | |
43 | before reading the counter. */ | |
44 | # define HP_TIMING_NOW(Var) \ | |
45 | (__extension__ ({ \ | |
46 | unsigned int __aux; \ | |
47 | (Var) = __builtin_ia32_rdtscp (&__aux); \ | |
48 | })) | |
49 | # else | |
50 | # define HP_TIMING_NOW(Var) ((Var) = __builtin_ia32_rdtsc ()) | |
51 | # endif | |
db276fa1 | 52 | |
72771e53 L |
53 | # include <hp-timing-common.h> |
54 | #else | |
55 | /* NB: Undefine _HP_TIMING_H so that <sysdeps/generic/hp-timing.h> will | |
56 | be included. */ | |
57 | # undef _HP_TIMING_H | |
58 | # include <sysdeps/generic/hp-timing.h> | |
59 | #endif | |
db276fa1 | 60 | |
72771e53 | 61 | #endif /* hp-timing.h */ |