Skip to contentSkip to conversation

x86: Report Intel platform_id in /proc/cpuinfo

PATCH In review Andi Kleen 2 participants 3 messages Jun 1, 2016 – Jun 2, 2016

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 x86: Report Intel platform_id in /proc/cpuinfo

From: Andi Kleen <[email protected]>

We have a need to distinguish systems based on their platform ID. For example this is useful to distinguish systems with L4 cache versus ones without.

There is a 5 bit identifier (also called processor flags) in the IA32_PLATFORM_ID MSR that can give a more fine grained identification of the CPU than just the model number/stepping.

IA32_PLATFORM_ID is architectural.

The processor flags are already used in the microcode driver. The MSR can be also accessed through /dev/cpu/*/msr, but that requires root and is awkward.

This patch just exports the value retrieved by the microcode driver in /proc/cpuinfo. If the microcode driver is disabled it won't be shown, but that seems reasonable.

---
 arch/x86/include/asm/processor.h      | 1 +
 arch/x86/kernel/cpu/microcode/intel.c | 1 +
 arch/x86/kernel/cpu/proc.c            | 2 ++
 3 files changed, 4 insertions(+)
arch/x86/include/asm/processor.h +1 -0
index 20c11d1..bc4b0ef 100644
@@ -136,6 +136,7 @@ struct cpuinfo_x86 {
 	/* Index into per_cpu list: */
 	u16			cpu_index;
 	u32			microcode;
+	u32			platform_id;
 };
 
 #define X86_VENDOR_INTEL	0
arch/x86/kernel/cpu/microcode/intel.c +1 -0
index ee81c54..6244a88 100644
@@ -812,6 +812,7 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
 		/* get processor flags from MSR 0x17 */
 		rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
 		csig->pf = 1 << ((val[1] >> 18) & 7);
+		cpu_data(cpu_num).platform_id = (val[1] >> 18) & 7;
 	}
 
 	csig->rev = c->microcode;
arch/x86/kernel/cpu/proc.c +2 -0
index 18ca99f..1c4e4f5 100644
@@ -76,6 +76,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 		seq_puts(m, "stepping\t: unknown\n");
 	if (c->microcode)
 		seq_printf(m, "microcode\t: 0x%x\n", c->microcode);
+	if (c->platform_id)
+		seq_printf(m, "platform_id\t: %d\n", c->platform_id);
 
 	if (cpu_has(c, X86_FEATURE_TSC)) {
 		unsigned int freq = cpufreq_quick_get(cpu);
Signature · 1 line
2.8.2
#1 lore raw
Quoted 5 lines · Andi Kleen

We have a need to distinguish systems based on their platform ID. For example this is useful to distinguish systems with L4 cache versus ones without.

There is a 5 bit identifier (also called processor flags) in

There is a 3 bit identifier...

Quoted 12 lines

the IA32_PLATFORM_ID MSR that can give a more fine grained identification of the CPU than just the model number/stepping.

IA32_PLATFORM_ID is architectural.

The processor flags are already used in the microcode driver. The MSR can be also accessed through /dev/cpu/*/msr, but that requires root and is awkward.

This patch just exports the value retrieved by the microcode driver in /proc/cpuinfo. If the microcode driver is disabled it won't be shown, but that seems reasonable.

...

arch/x86/kernel/cpu/microcode/intel.c static int collect_cpu_info(int cpu_num, struct cpu_signature *csig) · line 815

Quoted 9 lines
arch/x86/kernel/cpu/microcode/intel.c +1 -0
index ee81c54..6244a88 100644
@@ -812,6 +812,7 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
 		/* get processor flags from MSR 0x17 */
 		rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
 		csig->pf = 1 << ((val[1] >> 18) & 7);
+		cpu_data(cpu_num).platform_id = (val[1] >> 18) & 7;

See below. It might be better to have "cpu_data(cpu_num).platform_id = csig->pf" instead.

arch/x86/kernel/cpu/proc.c static int show_cpuinfo(struct seq_file *m, void *v) · line 80

Quoted 10 lines
arch/x86/kernel/cpu/proc.c +2 -0
index 18ca99f..1c4e4f5 100644
@@ -76,6 +76,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 		seq_puts(m, "stepping\t: unknown\n");
 	if (c->microcode)
 		seq_printf(m, "microcode\t: 0x%x\n", c->microcode);
+	if (c->platform_id)
+		seq_printf(m, "platform_id\t: %d\n", c->platform_id);

platform_id can meaningfully be zero on Intel, and in fact it often is (just look for output from the microcode driver that logs pf=0x1). In those processors, (MSR(17) >> 18 & 7) is zero, and csig->pf is 1.

May I humbly suggest using the mask "(1 << value)" notation for platform_id as used by the microcode driver? We already do it for csig->pf, and it has the advantage that mask notation will never be zero (so, the field is always non-zero where relevant).

Alterntively, the patch could be changed to always print platform_id on Intel processors, instead of just printing it out when it is non-zero.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
author
#2 lore raw
Quoted 8 lines · Henrique de Moraes Holschuh
Quoted 5 lines · Andi Kleen

We have a need to distinguish systems based on their platform ID. For example this is useful to distinguish systems with L4 cache versus ones without.

There is a 5 bit identifier (also called processor flags) in

There is a 3 bit identifier...

Thanks.

Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/cpu/microcode/intel.c +0 -0
index ee81c54..6244a88 100644
Quoted 8 lines

arch/x86/kernel/cpu/microcode/intel.c static int collect_cpu_info(int cpu_num, struct cpu_signature *csig) · line 815

Quoted 5 lines
arch/x86/kernel/cpu/microcode/intel.c +1 -0
@@ -812,6 +812,7 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
 		/* get processor flags from MSR 0x17 */
 		rdmsr(MSR_IA32_PLATFORM_ID, val[0], val[1]);
 		csig->pf = 1 << ((val[1] >> 18) & 7);
+		cpu_data(cpu_num).platform_id = (val[1] >> 18) & 7;

See below. It might be better to have "cpu_data(cpu_num).platform_id = csig->pf" instead.

Ok.

Quoted 16 lines

arch/x86/kernel/cpu/proc.c static int show_cpuinfo(struct seq_file *m, void *v) · line 80

Quoted 11 lines
arch/x86/kernel/cpu/proc.c +2 -0
index 18ca99f..1c4e4f5 100644
@@ -76,6 +76,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 		seq_puts(m, "stepping\t: unknown\n");
 	if (c->microcode)
 		seq_printf(m, "microcode\t: 0x%x\n", c->microcode);
+	if (c->platform_id)
+		seq_printf(m, "platform_id\t: %d\n", c->platform_id);

platform_id can meaningfully be zero on Intel, and in fact it often is (just look for output from the microcode driver that logs pf=0x1). In those processors, (MSR(17) >> 18 & 7) is zero, and csig->pf is 1.

Quoted 4 lines

May I humbly suggest using the mask "(1 << value)" notation for platform_id as used by the microcode driver? We already do it for csig->pf, and it has the advantage that mask notation will never be zero (so, the field is always non-zero where relevant).

That would be confusing because the value is used in some documents. I would prefer to match them.

Quoted 3 lines

Alterntively, the patch could be changed to always print platform_id on Intel processors, instead of just printing it out when it is non-zero.

What I can do is to add an extra flag and print it when the flag is set, even if it is zero.

Thanks for the review.

-Andi