x86: don't need 'level' passed to amd/intel init functions
[fio.git] / arch / arch-x86-common.h
index d533d22d536bce1ffbc162a1cdb50af1ae4f3848..5140f238fb78557d20e176d6160b72a7a4a97334 100644 (file)
@@ -1,18 +1,23 @@
 #ifndef FIO_ARCH_X86_COMMON
 #define FIO_ARCH_X86_COMMON
 
-static inline void do_cpuid(unsigned int *eax, unsigned int *ebx,
-                           unsigned int *ecx, unsigned int *edx)
+#include <string.h>
+
+static inline void cpuid(unsigned int op,
+                        unsigned int *eax, unsigned int *ebx,
+                        unsigned int *ecx, unsigned int *edx)
 {
-       asm volatile("cpuid"
-               : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
-               : "0" (*eax), "2" (*ecx)
-               : "memory");
+       *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[])
+
+extern bool tsc_reliable;
+extern int arch_random;
+
+static inline void arch_init_intel(void)
 {
        unsigned int eax, ebx, ecx = 0, edx;
 
@@ -22,15 +27,51 @@ static inline int arch_init(char *envp[])
        eax = 1;
        do_cpuid(&eax, &ebx, &ecx, &edx);
        if (!(edx & (1U << 4)))
-               return 0;
+               return;
 
        /*
         * Check for constant rate and synced (across cores) TSC
         */
        eax = 0x80000007;
        do_cpuid(&eax, &ebx, &ecx, &edx);
-       tsc_reliable = edx & (1U << 8);
-       return 0;
+       tsc_reliable = (edx & (1U << 8)) != 0;
+
+       /*
+        * Check for FDRAND
+        */
+       eax = 0x1;
+       do_cpuid(&eax, &ebx, &ecx, &edx);
+       arch_random = (ecx & (1U << 30)) != 0;
+}
+
+static inline void arch_init_amd(void)
+{
+       unsigned int eax, ebx, ecx, edx;
+
+       cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
+       if (eax < 0x80000007)
+               return;
+
+       cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
+       tsc_reliable = (edx & (1U << 8)) != 0;
+}
+
+static inline void arch_init(char *envp[])
+{
+       unsigned int level;
+       char str[13];
+
+       arch_random = tsc_reliable = 0;
+
+       cpuid(0, &level, (unsigned int *) &str[0],
+                        (unsigned int *) &str[8],
+                        (unsigned int *) &str[4]);
+
+       str[12] = '\0';
+       if (!strcmp(str, "GenuineIntel"))
+               arch_init_intel();
+       else if (!strcmp(str, "AuthenticAMD"))
+               arch_init_amd();
 }
 
 #endif