From 7a53462109e73a94af6f3a85704dd325568bd869 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 23 Jul 2024 16:24:01 +0200 Subject: [PATCH] Added helper function to read out TSC. --- src/mx/system/environment.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mx/system/environment.h b/src/mx/system/environment.h index f975a83..bc94ec7 100644 --- a/src/mx/system/environment.h +++ b/src/mx/system/environment.h @@ -24,6 +24,23 @@ public: return true; } + static uint64_t timestamp() + { + uint32_t lo, hi; + __asm__ __volatile__("xorl %%eax,%%eax\n\t" /* provide constant argument to cpuid to reduce variance */ + "cpuid\n\t" /* synchronise, i.e. finish all preceeding instructions */ + : + : + : "%rax", "%rbx", "%rcx", "%rdx"); + __asm__ __volatile__("rdtsc" + : "=a"(lo), "=d"(hi) + : + : "memory" /* prevent reordering of asm statements */ + ); + + return (uint64_t)hi << 32 | lo; + } + static constexpr auto is_sse2() { #ifdef USE_SSE2