]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/cpu/intel: Define helper to get CPU core native ID
authorDapeng Mi <dapeng1.mi@linux.intel.com>
Tue, 20 Aug 2024 07:38:51 +0000 (07:38 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 7 Oct 2024 07:28:43 +0000 (09:28 +0200)
Define helper get_this_hybrid_cpu_native_id() to return the CPU core
native ID. This core native ID combining with core type can be used to
figure out the CPU core uarch uniquely.

Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Yongwei Ma <yongwei.ma@intel.com>
Link: https://lkml.kernel.org/r/20240820073853.1974746-3-dapeng1.mi@linux.intel.com
arch/x86/include/asm/cpu.h
arch/x86/kernel/cpu/intel.c

index aa30fd8cad7f5285534c9e4b24e2846d1429f480..5af69b5be2fb7378a5585acfcd1fcddac8c042b6 100644 (file)
@@ -32,6 +32,7 @@ extern bool handle_user_split_lock(struct pt_regs *regs, long error_code);
 extern bool handle_guest_split_lock(unsigned long ip);
 extern void handle_bus_lock(struct pt_regs *regs);
 u8 get_this_hybrid_cpu_type(void);
+u32 get_this_hybrid_cpu_native_id(void);
 #else
 static inline void __init sld_setup(struct cpuinfo_x86 *c) {}
 static inline bool handle_user_split_lock(struct pt_regs *regs, long error_code)
@@ -50,6 +51,11 @@ static inline u8 get_this_hybrid_cpu_type(void)
 {
        return 0;
 }
+
+static inline u32 get_this_hybrid_cpu_native_id(void)
+{
+       return 0;
+}
 #endif
 #ifdef CONFIG_IA32_FEAT_CTL
 void init_ia32_feat_ctl(struct cpuinfo_x86 *c);
index e7656cbef68d54ba8459991984d130568c0c5c47..624397e43ac68e4659de1221272bb38c5dcb655b 100644 (file)
@@ -1299,3 +1299,18 @@ u8 get_this_hybrid_cpu_type(void)
 
        return cpuid_eax(0x0000001a) >> X86_HYBRID_CPU_TYPE_ID_SHIFT;
 }
+
+/**
+ * get_this_hybrid_cpu_native_id() - Get the native id of this hybrid CPU
+ *
+ * Returns the uarch native ID [23:0] of a CPU in a hybrid processor.
+ * If the processor is not hybrid, returns 0.
+ */
+u32 get_this_hybrid_cpu_native_id(void)
+{
+       if (!cpu_feature_enabled(X86_FEATURE_HYBRID_CPU))
+               return 0;
+
+       return cpuid_eax(0x0000001a) &
+              (BIT_ULL(X86_HYBRID_CPU_TYPE_ID_SHIFT) - 1);
+}