perf, x86: Use ALTERNATIVE() to check for X86_FEATURE_PERFCTR_CORE
authorRobert Richter <[email protected]>
Sat, 16 Apr 2011 00:27:55 +0000 (02:27 +0200)
committerIngo Molnar <[email protected]>
Tue, 19 Apr 2011 08:08:12 +0000 (10:08 +0200)
Using ALTERNATIVE() when checking for X86_FEATURE_PERFCTR_CORE avoids
an extra pointer chase and data cache hit.

Signed-off-by: Robert Richter <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
arch/x86/kernel/cpu/perf_event.c

index eed3673a8656f5688d54f6b4d72fd9774c831fcb..224a84f7080cd38e94aaf58047aafbb8a0ce037a 100644 (file)
@@ -31,6 +31,7 @@
 #include <asm/nmi.h>
 #include <asm/compat.h>
 #include <asm/smp.h>
+#include <asm/alternative.h>
 
 #if 0
 #undef wrmsrl
@@ -363,12 +364,18 @@ again:
        return new_raw_count;
 }
 
-/* using X86_FEATURE_PERFCTR_CORE to later implement ALTERNATIVE() here */
 static inline int x86_pmu_addr_offset(int index)
 {
-       if (boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
-               return index << 1;
-       return index;
+       int offset;
+
+       /* offset = X86_FEATURE_PERFCTR_CORE ? index << 1 : index */
+       alternative_io(ASM_NOP2,
+                      "shll $1, %%eax",
+                      X86_FEATURE_PERFCTR_CORE,
+                      "=a" (offset),
+                      "a"  (index));
+
+       return offset;
 }
 
 static inline unsigned int x86_pmu_config_addr(int index)