From 8f411401675e30a56583b7bf9bf012105433d6e6 Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Mon, 9 Jul 2012 10:01:54 +0530 Subject: [PATCH] bug #466 - Updated getticks() to serialize execution of rdtsc with cpuid --- src/util-cpu.c | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/src/util-cpu.c b/src/util-cpu.c index 89f2d0b..106b7e4 100644 --- a/src/util-cpu.c +++ b/src/util-cpu.c @@ -176,15 +176,41 @@ void UtilCpuPrintSummary() { /** * Get the current number of ticks from the CPU. + * + * \todo We'll have to deal with removig ticks from the extra cpuids inbetween + * 2 calls. */ uint64_t UtilCpuGetTicks(void) { uint64_t val; -#if defined(__GNUC__) && (defined(__x86_64) || defined(__i386)) +#if defined(__GNUC__) +#if defined(__x86_64) || defined(_X86_64_) || defined(ia_64) + __asm__ __volatile__ ( + "xorl %%eax,%%eax\n\t" + "cpuid\n\t" + ::: "%rax", "%rbx", "%rcx", "%rdx"); +#else + __asm__ __volatile__ ( + "xorl %%eax,%%eax\n\t" + "cpuid\n\t" + ::: "%eax", "%ebx", "%ecx", "%edx"); +#endif uint32_t a, d; __asm__ __volatile__ ("rdtsc" : "=a" (a), "=d" (d)); val = ((uint64_t)a) | (((uint64_t)d) << 32); +#if defined(__x86_64) || defined(_X86_64_) || defined(ia_64) + __asm__ __volatile__ ( + "xorl %%eax,%%eax\n\t" + "cpuid\n\t" + ::: "%rax", "%rbx", "%rcx", "%rdx"); #else + __asm__ __volatile__ ( + "xorl %%eax,%%eax\n\t" + "cpuid\n\t" + ::: "%eax", "%ebx", "%ecx", "%edx"); +#endif + +#else /* #if defined(__GNU__) */ #warning Using inferior version of UtilCpuGetTicks struct timeval now; gettimeofday(&now, NULL); -- 1.7.1