From b5a7c219f06b296c0e6c392bf6691495dbfa6425 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Tue, 27 Aug 2024 19:30:58 +0200 Subject: x86: add rdtsc notes --- src/arch/x86_64.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/arch/x86_64.md b/src/arch/x86_64.md index 2635a4e..1f7ffdd 100644 --- a/src/arch/x86_64.md +++ b/src/arch/x86_64.md @@ -147,6 +147,25 @@ mov cx, 0x10 rep stosb ``` +## Time stamp counter - `rdtsc` +```c +static inline uint64_t rdtsc() { + uint32_t eax, edx; + asm volatile("rdtsc" : "=d"(edx), "=a"(eax)::); + return (uint64_t)edx << 32 | eax; +} +``` +> Constant TSC behavior ensures that the duration of each clock tick is uniform +> and supports the use of the TSC as a wall clock timer even if the processor +> core changes frequency. This is the architectural behavior moving forward. +> - 18.17 TIME-STAMP COUNTER - [intel64-vol3][intel64_vol3] + +On linux one can check the `constant_tsc` cpu flag, to validate if the +implemented TSC ticks with a constant frequency. +```sh +grep constant_tsc /proc/cpuinfo +``` + ## [SysV x86_64 ABI][sysvabi] ### Passing arguments to functions -- cgit v1.2.3