From 7189c969816dbea1c4c73209e61332b75cf882c7 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sun, 3 Feb 2013 20:54:26 +0100 Subject: [PATCH] gettime: fixup AMD constant TSC detection Signed-off-by: Jens Axboe --- arch/arch-x86-common.h | 48 ++++++++++++++++++++++++++++++++++++++++-- gettime.c | 8 ------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/arch/arch-x86-common.h b/arch/arch-x86-common.h index d533d22d..78fd40c0 100644 --- a/arch/arch-x86-common.h +++ b/arch/arch-x86-common.h @@ -1,6 +1,8 @@ #ifndef FIO_ARCH_X86_COMMON #define FIO_ARCH_X86_COMMON +#include + static inline void do_cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { @@ -10,9 +12,20 @@ static inline void do_cpuid(unsigned int *eax, unsigned int *ebx, : "memory"); } +static inline void cpuid(unsigned int op, + unsigned int *eax, unsigned int *ebx, + unsigned int *ecx, unsigned int *edx) +{ + *eax = op; + *ecx = 0; + do_cpuid(eax, ebx, ecx, edx); +} + #define ARCH_HAVE_INIT + extern int tsc_reliable; -static inline int arch_init(char *envp[]) + +static inline int arch_init_intel(unsigned int level) { unsigned int eax, ebx, ecx = 0, edx; @@ -29,7 +42,38 @@ static inline int arch_init(char *envp[]) */ eax = 0x80000007; do_cpuid(&eax, &ebx, &ecx, &edx); - tsc_reliable = edx & (1U << 8); + return edx & (1U << 8); +} + +static inline int arch_init_amd(unsigned int level) +{ + unsigned int eax, ebx, ecx, edx; + + cpuid(0x80000000, &eax, &ebx, &ecx, &edx); + if (eax < 0x80000007) + return 0; + + cpuid(0x80000007, &eax, &ebx, &ecx, &edx); + if (edx & (1 << 8)) + return 1; + + return 0; +} + +static inline int arch_init(char *envp[]) +{ + unsigned int level; + char str[12]; + + cpuid(0, &level, (unsigned int *) &str[0], + (unsigned int *) &str[8], + (unsigned int *) &str[4]); + + if (!strcmp(str, "GenuineIntel")) + tsc_reliable = arch_init_intel(level); + else if (!strcmp(str, "AuthenticAMD")) + tsc_reliable = arch_init_amd(level); + return 0; } diff --git a/gettime.c b/gettime.c index 5c0e4457..cc9dcb7b 100644 --- a/gettime.c +++ b/gettime.c @@ -342,14 +342,6 @@ void fio_clock_init(void) log_err("fio: can't create TLS key\n"); #endif - /* - * Probably an AMD issue, will need to investigate. Until that - * is done, disable the CPU clock. - */ -#if FIO_OS == os_solaris - tsc_reliable = 0; -#endif - fio_clock_source_inited = fio_clock_source; calibrate_cpu_clock(); -- 2.25.1