Access to the Timestamp Counter (of the current Core)
More...
Access to the Timestamp Counter (of the current Core)
Intel Manual Vol. 3, 17.17 Time-Stamp Counter
◆ Instruction
Enumerator |
---|
RDTSC | TSC Read with possible out-of-order execution.
|
RDTSCP | Pseudo serializing.
|
CPUID_RDTSC | Serializing (via CPUID) TSC read for begin of benchmark.
|
RDTSCP_CPUID | Serializing (via CPUID) TSC read for end of benchmark.
|
CR0_RDTSC | Serializing (via CR0) TSC read for end of benchmark if RDTSCP is not supported.
|
◆ ticksByProcessorInfo()
static uint32_t TSC::ticksByProcessorInfo |
( |
void |
| ) |
|
|
static |
Calculate the TSC frequency, if possible.
- Note
- Does not work in QEMU
- Returns
- Ticks per millisecond, or 0 if not possible
◆ ticksByPIT()
static uint32_t TSC::ticksByPIT |
( |
void |
| ) |
|
|
static |
Measure the TSC frequency using PIT.
- Returns
- TSC ticks per millisecond
◆ ticks()
uint32_t TSC::ticks |
( |
bool |
use_pit = false | ) |
|
Gather the TSC frequency in ticks per milliseconds.
- Parameters
-
use_pit | Enforces the usage of the PIT if set, otherwise the processor infos are queried, at first. |
- Returns
- Number of TSC ticks per milliseconds
- Optional:
- Implement calibration via PIT (in the local function ticksByPit()). For testing, it might be useful to compare the return values with different values of
use_pit
. The returned values should be similar :)
◆ available()
Check availability of TSC.
- Parameters
-
instruction | Test for the (unserialized) RDTSC or pseudo serializing RDTSCP instruction |
- Returns
- true if RDTSC[P] is available
◆ nanoseconds()
Convert a timestamp delta value to nanoseconds.
- Note
- It is necessary to execute
TSC::ticks()
prior calling this function the first time, since it uses the cached TSC frequency value gathered by ticks()
for the calculation.
- Parameters
-
delta | Delta between two timestamps |
- Returns
- Equivalent time in nanoseconds
- Optional:
- Implement conversion
◆ delay()
Actively wait the provided waiting time.
- Note
- It is necessary to execute
TSC::ticks()
prior calling this function the first time, since it uses the cached TSC frequency value gathered by ticks()
for the calculation.
- Parameters
-
us | waiting time in microseconds |
- Optional:
- Implement conversion
◆ read()
Reads the current timestamp counter.
While reading the timestamp counter is quite easy, it is difficult to prevent out-of-order execution.
- See also
- How to Benchmark Code Execution Times on IntelĀ® IA-32 and IA-64 Instruction Set Architectures [benchmark_code_execution.pdf]
- Parameters
-
instruction | Instruction(s) used to read timestamp counter |
- Returns
- Timestamp in TSC ticks
◆ ticks_value