gettime: fixup AMD constant TSC detection

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/arch/arch-x86-common.h b/arch/arch-x86-common.h
index d533d22..78fd40c 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 <string.h>
+
 static inline void do_cpuid(unsigned int *eax, unsigned int *ebx,
 			    unsigned int *ecx, unsigned int *edx)
 {
@@ -10,9 +12,20 @@
 		: "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 @@
 	 */
 	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 5c0e445..cc9dcb7 100644
--- a/gettime.c
+++ b/gettime.c
@@ -342,14 +342,6 @@
 		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();