Skip to contentSkip to conversation

How to get number of physical CPU in linux from user space?

PATCH In review Nakajima, Jun 4 participants 8 messages Oct 25, 2002 – Oct 26, 2002

lore
Share & tools
lore
#0 lore raw

You might want to remove __initdata (in smpboot.c):
int __initdata phys_proc_id[NR_CPUS];

Jun Nakajima

-----Original Message-----
From: Nakajima, Jun
Sent: Friday, October 25, 2002 12:49 PM
To: Robert Love; Dave Jones; [email protected]
Cc: [email protected]; Nakajima, Jun; [email protected]; Martin J. Bligh
Subject: RE: [PATCH] How to get number of physical CPU in linux from user space?

One more request :-)

Actually "processor" keyword was not good in "physical processor ID" (someone may be grepping it to find out the number of processors), and it was one of the reasons it was changed/fixed in the AC tree.

Since (H/W) threads (rather than "siblings") in a CPU is generic (i.e. not just an Intel thing), I would like to propose this ("physical id" is from AC). Alan also simplified "number of simblings" to "siblings".

+#ifdef CONFIG_SMP
+ if (cpu_has_ht) {
+ seq_printf(m, "physical id\t: %d\n", phys_proc_id[n]);
+ seq_printf(m, "threads\t\t: %d\n", smp_num_siblings);
+ }
+#endif

Thanks,
Jun

-----Original Message-----
From: Robert Love [mailto:[email protected]]
Sent: Friday, October 25, 2002 12:21 PM
To: Dave Jones; [email protected]
Cc: [email protected]; Nakajima, Jun; [email protected]; Martin J. Bligh
Subject: Re: [PATCH] How to get number of physical CPU in linux from user space?

Quoted 2 lines · Dave Jones

Should this be wrapped in a if (cpu_has_ht(c)) { } ? Seems silly to be displaying HT information on non-HT CPUs.

I am neutral, but is fine with me. It is just "cpu_has_ht", btw.

Take two...

This displays the physical processor id and number of siblings of each processor in /proc/cpuinfo.

Robert Love

.proc.c.swp |binary

 proc.c      |    7 +++++++
 2 files changed, 7 insertions(+)

diff -urN linux-2.5.44/arch/i386/kernel/cpu/proc.c linux/arch/i386/kernel/cpu/proc.c
--- linux-2.5.44/arch/i386/kernel/cpu/proc.c 2002-10-19
00:02:29.000000000 -0400
+++ linux/arch/i386/kernel/cpu/proc.c 2002-10-25 15:18:03.000000000 -0400
@@ -17,6 +17,7 @@
* applications want to get the raw CPUID data, they should access
* /dev/cpu/<cpu_nr>/cpuid instead.
*/
+ extern int phys_proc_id[NR_CPUS];
static char *x86_cap_flags[] = {
/* Intel-defined */
"fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
@@ -74,6 +75,12 @@
/* Cache size */
if (c->x86_cache_size >= 0)
seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
+#ifdef CONFIG_SMP
+ if (cpu_has_ht) {
+ seq_printf(m, "physical processor ID\t: %d\n",
phys_proc_id[n]);
+ seq_printf(m, "number of siblings\t: %d\n",
smp_num_siblings);
+ }
+#endif

/* We use exception 16 if we have hardware math and we've either
seen it or the CPU claims it is internal */
fpu_exception = c->hard_math && (ignore_irq13 || cpu_has_fpu);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw

PATCH 1/1 hyper-threading information in /proc/cpuinfo

Take three. This patch displays hyper-threading information in /proc/cpuinfo.

Changes since first post:

	- wrap print in "if (cpu_has_ht) { ... }"   (Dave Jones)
	- remove initdata from phys_proc_id         (Jun Nakajima)
	- match field names in latest 2.4-ac        (Alan Cox)

Patch is against 2.5.44.

Robert Love

 cpu/proc.c |    7 +++++++
 smpboot.c  |    2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
arch/i386/kernel/cpu/proc.c +7 -0
diff -urN linux-2.5.44/arch/i386/kernel/cpu/proc.c linux/arch/i386/kernel/cpu/proc.c
@@ -17,6 +17,7 @@
 	 * applications want to get the raw CPUID data, they should access
 	 * /dev/cpu/<cpu_nr>/cpuid instead.
 	 */
+	extern int phys_proc_id[NR_CPUS];
 	static char *x86_cap_flags[] = {
 		/* Intel-defined */
 	        "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
@@ -74,6 +75,12 @@
 	/* Cache size */
 	if (c->x86_cache_size >= 0)
 		seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
+#ifdef CONFIG_SMP
+	if (cpu_has_ht) {
+		seq_printf(m, "physical processor ID\t: %d\n", phys_proc_id[n]);
+		seq_printf(m, "number of siblings\t: %d\n", smp_num_siblings);
+	}
+#endif
 	
 	/* We use exception 16 if we have hardware math and we've either seen it or the CPU claims it is internal */
 	fpu_exception = c->hard_math && (ignore_irq13 || cpu_has_fpu);
arch/i386/kernel/smpboot.c +1 -1
diff -urN linux-2.5.44/arch/i386/kernel/smpboot.c linux/arch/i386/kernel/smpboot.c
@@ -58,7 +58,7 @@
 
 /* Number of siblings per CPU package */
 int smp_num_siblings = 1;
-int __initdata phys_proc_id[NR_CPUS]; /* Package ID of each logical CPU */
+int phys_proc_id[NR_CPUS]; /* Package ID of each logical CPU */
 
 /* Bitmask of currently online CPUs */
 unsigned long cpu_online_map;
#2 lore raw

Re: [PATCH] hyper-threading information in /proc/cpuinfo

Quoted 3 lines · Robert Love
	- wrap print in "if (cpu_has_ht) { ... }"   (Dave Jones)
	- remove initdata from phys_proc_id         (Jun Nakajima)
	- match field names in latest 2.4-ac        (Alan Cox)

missing this last bit, sorry..

Robert Love

 cpu/proc.c |    7 +++++++
 smpboot.c  |    2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
arch/i386/kernel/cpu/proc.c +7 -0
diff -urN linux-2.5.44/arch/i386/kernel/cpu/proc.c linux/arch/i386/kernel/cpu/proc.c
@@ -17,6 +17,7 @@
 	 * applications want to get the raw CPUID data, they should access
 	 * /dev/cpu/<cpu_nr>/cpuid instead.
 	 */
+	extern int phys_proc_id[NR_CPUS];
 	static char *x86_cap_flags[] = {
 		/* Intel-defined */
 	        "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
@@ -74,6 +75,12 @@
 	/* Cache size */
 	if (c->x86_cache_size >= 0)
 		seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
+#ifdef CONFIG_SMP
+	if (cpu_has_ht) {
+		seq_printf(m, "physical id\t: %d\n", phys_proc_id[n]);
+		seq_printf(m, "siblings\t: %d\n", smp_num_siblings);
+	}
+#endif
 	
 	/* We use exception 16 if we have hardware math and we've either seen it or the CPU claims it is internal */
 	fpu_exception = c->hard_math && (ignore_irq13 || cpu_has_fpu);
arch/i386/kernel/smpboot.c +1 -1
diff -urN linux-2.5.44/arch/i386/kernel/smpboot.c linux/arch/i386/kernel/smpboot.c
@@ -58,7 +58,7 @@
 
 /* Number of siblings per CPU package */
 int smp_num_siblings = 1;
-int __initdata phys_proc_id[NR_CPUS]; /* Package ID of each logical CPU */
+int phys_proc_id[NR_CPUS]; /* Package ID of each logical CPU */
 
 /* Bitmask of currently online CPUs */
 unsigned long cpu_online_map;
#3 lore raw

Re: [PATCH] hyper-threading information in /proc/cpuinfo

In reply to Robert Love

arch/i386/kernel/cpu/proc.c line 83

Quoted 6 lines · Robert Love
arch/i386/kernel/cpu/proc.c +6 -0
+#ifdef CONFIG_SMP
+	if (cpu_has_ht) {
+		seq_printf(m, "physical processor ID\t: %d\n", phys_proc_id[n]);
+		seq_printf(m, "number of siblings\t: %d\n", smp_num_siblings);
+	}
+#endif

Something else looks suspect to me here. smp_num_siblings is going to say the same value on every CPU in the system. It's questionable whether we want to print it out n times.

Dave

Signature · 1 line
| Dave Jones.        http://www.codemonkey.org.uk
#4 lore raw

Re: [PATCH] hyper-threading information in /proc/cpuinfo

Quoted 14 lines · Dave Jones

arch/i386/kernel/cpu/proc.c line 83

Quoted 6 lines · Robert Love
arch/i386/kernel/cpu/proc.c +6 -0
+#ifdef CONFIG_SMP
+	if (cpu_has_ht) {
+		seq_printf(m, "physical processor ID\t: %d\n", phys_proc_id[n]);
+		seq_printf(m, "number of siblings\t: %d\n", smp_num_siblings);
+	}
+#endif

Something else looks suspect to me here. smp_num_siblings is going to say the same value on every CPU in the system. It's questionable whether we want to print it out n times.

Not really... we print out other information that is duplicated N times, because it is the common case that N-way systems have matched processors with matched capabilities. The above caught my eye as well, but the alternative is to subvert the standard /proc/cpuinfo format and print something out only once, that clearly applies to each processor.

Jeff

#5 lore raw

Re: [PATCH] hyper-threading information in /proc/cpuinfo

Quoted 3 lines · Jeff Garzik

Not really... we print out other information that is duplicated N times, because it is the common case that N-way systems have matched processors with matched capabilities.

Not really. We print out the 'duplicate' info because it's read that way from different CPUs. The smp_num_siblings is a single global variable. Theoretically, the other stuff /could/ change in an asymetrical system, but the num_siblings thing is constant.

Dave

Signature · 1 line
| Dave Jones.        http://www.codemonkey.org.uk
#6 lore raw

Re: [PATCH] hyper-threading information in /proc/cpuinfo

Quoted 10 lines · Dave Jones
Quoted 1 line · Jeff Garzik

Not really... we print out other information that is duplicated N times, because it is the common case that N-way systems have matched processors with matched capabilities.

Not really. We print out the 'duplicate' info because it's read that way from different CPUs. The smp_num_siblings is a single global variable. Theoretically, the other stuff /could/ change in an asymetrical system, but the num_siblings thing is constant.

Sure, but you snipped the other part of the argument :) Printing stuff only once is changes the format which has previously been to print out the same fields [but not necessarily the same values] for each CPU; so the alternative is to create /proc/global_cpu_info just to print out num-siblings only once :) IOW, I don't see it as a big deal to print out the duplicated info, because that maintains the other assumptions about output format.

That said, on IRC my preference was to create smp_num_siblings[] and store the info per-cpu. But right now that's only for software engineering masturbation :) since it would store the same value N times on current CPUs.

Jeff

#7 lore raw

Re: [PATCH] hyper-threading information in /proc/cpuinfo

Quoted 4 lines · Jeff Garzik

That said, on IRC my preference was to create smp_num_siblings[] and store the info per-cpu. But right now that's only for software engineering masturbation :) since it would store the same value N times on current CPUs.

I agree with Jeff here - mostly because subverting the format is no good, either.

In the future, or perhaps on other architectures, smp_num_siblings could be per-processor. So now we can extend this in the future and not break the /proc interface.

Its just a by-product of the P4 that smp_num_siblings is global on arch-i386.

Robert Love