2002-08-21 02:11:45

by Nakajima, Jun

[permalink] [raw]
Subject: [PATCH] threads in /proc/cpuinfo and cpu_num_threads (fka smp_num _siblings)

I think this may have been our mistake, but "siblings" sometimes can be
misleading, in the sense that the number of the siblings usually/often does
not include yourself.

At the same time, as Alan pointed out, using cpu_num_threads is clearer than
smp_num_sibling because there are going to be non X86 CPUs around one day
with similar properties and it's a more generic name.

So here is a patch against linux-2.4.20-pre2-ac5.
===========================================================================
diff -urN linux-2.4.20-pre2-ac5/arch/i386/kernel/setup.c
linux-1/arch/i386/kernel/setup.c
--- linux-2.4.20-pre2-ac5/arch/i386/kernel/setup.c Tue Aug 20 15:35:18
2002
+++ linux-1/arch/i386/kernel/setup.c Tue Aug 20 16:45:20 2002
@@ -2331,29 +2331,29 @@
int cpu = smp_processor_id();

cpuid(1, &eax, &ebx, &ecx, &edx);
- smp_num_siblings = (ebx & 0xff0000) >> 16;
+ cpu_num_threads = (ebx & 0xff0000) >> 16;

- if (smp_num_siblings == 1) {
+ if (cpu_num_threads == 1) {
printk(KERN_INFO "CPU: Hyper-Threading is
disabled\n");
- } else if (smp_num_siblings > 1 ) {
+ } else if (cpu_num_threads > 1 ) {
index_lsb = 0;
index_msb = 31;
/*
- * At this point we only support two siblings per
+ * At this point we only support two threads per
* processor package.
*/
-#define NR_SIBLINGS 2
- if (smp_num_siblings != NR_SIBLINGS) {
- printk(KERN_WARNING "CPU: Unsupported number
of the siblings %d", smp_num_siblings);
- smp_num_siblings = 1;
+#define NR_XEON_THREADS 2
+ if (cpu_num_threads != NR_XEON_THREADS) {
+ printk(KERN_WARNING "CPU: Unsupported number
of SMT threads %d", cpu_num_threads);
+ cpu_num_threads = 1;
return;
}
- tmp = smp_num_siblings;
+ tmp = cpu_num_threads;
while ((tmp & 1) == 0) {
tmp >>=1 ;
index_lsb++;
}
- tmp = smp_num_siblings;
+ tmp = cpu_num_threads;
while ((tmp & 0x80000000 ) == 0) {
tmp <<=1 ;
index_msb--;
@@ -2962,7 +2962,7 @@

#ifdef CONFIG_SMP
seq_printf(m, "physical id\t: %d\n",phys_proc_id[n]);
- seq_printf(m, "siblings\t: %d\n",smp_num_siblings);
+ seq_printf(m, "threads\t\t: %d\n",cpu_num_threads);
#endif


/* We use exception 16 if we have hardware math and we've either
seen it or the CPU claims it is internal */
diff -urN linux-2.4.20-pre2-ac5/arch/i386/kernel/smpboot.c
linux-1/arch/i386/kernel/smpboot.c
--- linux-2.4.20-pre2-ac5/arch/i386/kernel/smpboot.c Tue Aug 20 15:35:18
2002
+++ linux-1/arch/i386/kernel/smpboot.c Tue Aug 20 15:39:56 2002
@@ -56,8 +56,8 @@
/* Total count of live CPUs */
int smp_num_cpus = 1;

-/* Number of siblings per CPU package */
-int smp_num_siblings = 1;
+/* Number of threads per CPU package */
+int cpu_num_threads = 1;
int phys_proc_id[NR_CPUS]; /* Package ID of each logical CPU */

/* Bitmask of currently online CPUs */
@@ -1158,7 +1158,7 @@
* that we can tell the sibling CPU efficiently.
*/
if (test_bit(X86_FEATURE_HT, boot_cpu_data.x86_capability)
- && smp_num_siblings > 1) {
+ && cpu_num_threads > 1) {
for (cpu = 0; cpu < NR_CPUS; cpu++)
cpu_sibling_map[cpu] = NO_PROC_ID;

@@ -1175,7 +1175,7 @@
}
}
if (cpu_sibling_map[cpu] == NO_PROC_ID) {
- smp_num_siblings = 1;
+ cpu_num_threads = 1;
printk(KERN_WARNING "WARNING: No sibling
found for CPU %d.\n", cpu);
}
}
diff -urN linux-2.4.20-pre2-ac5/fs/binfmt_elf.c linux-1/fs/binfmt_elf.c
--- linux-2.4.20-pre2-ac5/fs/binfmt_elf.c Tue Aug 20 15:35:20 2002
+++ linux-1/fs/binfmt_elf.c Tue Aug 20 15:39:56 2002
@@ -150,7 +150,7 @@
* removed for 2.5
*/

- if(smp_num_siblings > 1)
+ if(cpu_num_threads > 1)
u_platform = u_platform - ((current->pid % 64) << 7);
#endif

diff -urN linux-2.4.20-pre2-ac5/include/asm-i386/smp.h
linux-1/include/asm-i386/smp.h
--- linux-2.4.20-pre2-ac5/include/asm-i386/smp.h Tue Aug 20 15:35:20
2002
+++ linux-1/include/asm-i386/smp.h Tue Aug 20 16:48:22 2002
@@ -74,7 +74,7 @@
extern unsigned long cpu_online_map;
extern volatile unsigned long smp_invalidate_needed;
extern int pic_mode;
-extern int smp_num_siblings;
+extern int cpu_num_threads;
extern int cpu_sibling_map[];

extern void smp_flush_tlb(void);
diff -urN linux-2.4.20-pre2-ac5/include/asm-i386/smp_balance.h
linux-1/include/asm-i386/smp_balance.h
--- linux-2.4.20-pre2-ac5/include/asm-i386/smp_balance.h Tue Aug 20
15:35:20 2002
+++ linux-1/include/asm-i386/smp_balance.h Tue Aug 20 15:39:56 2002
@@ -28,7 +28,7 @@
static inline int arch_load_balance(int this_cpu, int idle)
{
/* Special hack for hyperthreading */
- if (smp_num_siblings > 1 && idle &&
!idle_cpu(cpu_sibling_map[this_cpu])) {
+ if (cpu_num_threads > 1 && idle &&
!idle_cpu(cpu_sibling_map[this_cpu])) {
int found;
struct runqueue *rq_target;



Attachments:
cpu_num_threads.patch (4.20 kB)