I think __volatile__ is needed when we calculate rdtsc in get_cycles().
because this simple program will print the wrong value otherwise.
Regards,
Tigran.
/*
Compile with: CFLAGS = -Wall -Wstrict-prototypes -O2 -g -fomit-frame-pointer
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
typedef unsigned long cycles_t;
static inline cycles_t get_cycles(void)
{
unsigned long eax, edx;
__asm__ __volatile__ ("rdtsc":"=a" (eax), "=d" (edx));
return eax;
}
int main(int argc, char *argv[])
{
cycles_t x, y;
x = get_cycles();
__asm__("cpuid");
y = get_cycles();
fprintf(stderr, "%lu\n", y - x);
return 0;
}
Hence this simple patch (for include/asm-i386/timex.h):
--- timex.h.0 Sat Mar 27 12:41:54 1999
+++ timex.h Sat Mar 27 12:42:07 1999
@@ -39,7 +39,7 @@
#else
unsigned long eax, edx;
- __asm__("rdtsc":"=a" (eax), "=d" (edx));
+ __asm__ __volatile__ ("rdtsc":"=a" (eax), "=d" (edx));
return eax;
#endif
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/