aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-08-27 19:30:58 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-08-27 19:30:58 +0200
commitb5a7c219f06b296c0e6c392bf6691495dbfa6425 (patch)
tree1ecbac038da673500f4dad77163c878b83a74189 /src
parent4b9f5c11fe4c2bebd92033cebe215dfc0d5f9397 (diff)
downloadnotes-b5a7c219f06b296c0e6c392bf6691495dbfa6425.tar.gz
notes-b5a7c219f06b296c0e6c392bf6691495dbfa6425.zip
x86: add rdtsc notes
Diffstat (limited to 'src')
-rw-r--r--src/arch/x86_64.md19
1 files changed, 19 insertions, 0 deletions
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