diff --git a/repos/base/include/spec/x86_32/trace/timestamp.h b/repos/base/include/spec/x86_32/trace/timestamp.h index 9a53e6c9b3..9a73140dad 100644 --- a/repos/base/include/spec/x86_32/trace/timestamp.h +++ b/repos/base/include/spec/x86_32/trace/timestamp.h @@ -26,16 +26,19 @@ namespace Genode { namespace Trace { { uint64_t t; __asm__ __volatile__ ( - "pushl %%ebx\n\t" - "xorl %%eax,%%eax\n\t" - "cpuid\n\t" + "pushl %%ebx\n\t" /* ebx is reserved in PIC mode, but clobbered by cpuid */ + "xorl %%eax,%%eax\n\t" /* provide constant argument to cpuid to reduce variance */ + "cpuid\n\t" /* synchronise, i.e. finish all preceeding instructions */ "popl %%ebx\n\t" : : : "%eax", "%ecx", "%edx" ); __asm__ __volatile__ ( - "rdtsc" : "=A" (t) + "rdtsc" + : "=A" (t) + : + : "memory" /* prevent reordering of asm statements */ ); return t; diff --git a/repos/base/include/spec/x86_64/trace/timestamp.h b/repos/base/include/spec/x86_64/trace/timestamp.h index 4d779ffb92..a432dabb87 100644 --- a/repos/base/include/spec/x86_64/trace/timestamp.h +++ b/repos/base/include/spec/x86_64/trace/timestamp.h @@ -27,14 +27,17 @@ namespace Genode { namespace Trace { { uint32_t lo, hi; __asm__ __volatile__ ( - "xorl %%eax,%%eax\n\t" - "cpuid\n\t" + "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) + "rdtsc" + : "=a" (lo), "=d" (hi) + : + : "memory" /* prevent reordering of asm statements */ ); return (uint64_t)hi << 32 | lo;