Skip to content

Commit a582c54

Browse files
amlutoIngo Molnar
authored andcommitted
x86/vdso: Use RDPID in preference to LSL when available
RDPID is a new instruction that reads MSR_TSC_AUX quickly. This should be considerably faster than reading the GDT. Add a cpufeature for it and use it from __vdso_getcpu() when available. Tested-by: Megha Dey <megha.dey@intel.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/4f6c3a22012d10f1c65b9ca15800e01b42c7d39d.1479320367.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 89a01c5 commit a582c54

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
#define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
284284
#define X86_FEATURE_PKU (16*32+ 3) /* Protection Keys for Userspace */
285285
#define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */
286+
#define X86_FEATURE_RDPID (16*32+ 22) /* RDPID instruction */
286287

287288
/* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */
288289
#define X86_FEATURE_OVERFLOW_RECOV (17*32+0) /* MCA overflow recovery support */

arch/x86/include/asm/vgtod.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ static inline unsigned int __getcpu(void)
8989
* works on all CPUs. This is volatile so that it orders
9090
* correctly wrt barrier() and to keep gcc from cleverly
9191
* hoisting it out of the calling function.
92+
*
93+
* If RDPID is available, use it.
9294
*/
93-
asm volatile ("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
95+
alternative_io ("lsl %[p],%[seg]",
96+
".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
97+
X86_FEATURE_RDPID,
98+
[p] "=a" (p), [seg] "r" (__PER_CPU_SEG));
9499

95100
return p;
96101
}

0 commit comments

Comments
 (0)