Export cpu topology by sysfs
PATCH 1/1 Export cpu topology by sysfs
From: Zhang, Yanmin <[email protected]>
The patches export the cpu topology info through sysfs.
Based on the opinions of Nathan, Andi, Paul and Venki, I revised the patches. I really appreciate their good comments.
1) The main exportation logic is implemented arch-independently. The specific architectures just need to provides 5 defines; My thread patch provides the defines for i386, x86_64, and ia64. Other architectures need provide their own defines.
2) Add a new document;
3) Current i386 and x86_64 architectures don't save thread_id and don't show thread_id in /proc/cpuinfo. my patches fix it.
The first patch against kernel 2.6.15-rc5 is to save thread_id and show it in /proc/cpuinfo for i386 architecture.
#diffstat collect_thread_id_2.6.15-rc5_i386.patch
arch/i386/kernel/cpu/common.c | 10 +++++++++- arch/i386/kernel/cpu/proc.c | 2 ++ arch/i386/kernel/smpboot.c | 3 +++ include/asm-i386/processor.h | 1 + 4 files changed, 15 insertions, 1 deletion
---
arch/i386/kernel/cpu/common.c +9 -1
@@ -443,7 +443,7 @@ void __devinit identify_cpu(struct cpuinvoid __devinit detect_ht (struct cpuinfo_x86 *c) {u32 eax, ebx, ecx, edx; -int index_msb, core_bits; +int index_msb, core_bits, thread_bits;int cpu =smp_processor_id ();cpuid (1 , &eax, &ebx, &ecx, &edx);
@@ -483,6 +483,14 @@ void __devinit detect_ht(struct cpuinfo_if (c->x86_max_cores >1 )printk (KERN_INFO "CPU: Processor Core ID: %d\n" , cpu_core_id[cpu]); + + thread_bits = index_msb; + cpu_thread_id[cpu] =phys_pkg_id ((ebx >>24 ) &0xFF ,0 ) & + ((1 << thread_bits) -1 ); + +if (smp_num_siblings >1 ) +printk (KERN_INFO "CPU: Processor Thread ID: %d\n" , + cpu_thread_id[cpu]); } }#endif
arch/i386/kernel/cpu/proc.c +2 -0
@@ -100,6 +100,8 @@ static int show_cpuinfo(struct seq_fileseq_printf (m,"core id\t\t: %d\n" , cpu_core_id[n]); seq_printf(m, "cpu cores\t: %d\n", c->booted_cores); } +if (smp_num_siblings >1 ) +seq_printf (m,"thread id\t: %d\n" , cpu_thread_id[n]);#endif /* We use exception 16 if we have hardware math and we've either seen it or the CPU claims it is internal */
arch/i386/kernel/smpboot.c +3 -0
@@ -72,6 +72,9 @@ int phys_proc_id[NR_CPUS] __read_mostly/* Core ID of each logical CPU */ int cpu_core_id[NR_CPUS ]__read_mostly = {[0 ...NR_CPUS -1 ] =BAD_APICID }; +/* Thread ID of each logical CPU */ +int cpu_thread_id[NR_CPUS ]__read_mostly = {[0 ...NR_CPUS -1 ] =BAD_APICID }; +/* representing HT siblings of each logical CPU */ cpumask_t cpu_sibling_map[NR_CPUS ]__read_mostly ;EXPORT_SYMBOL (cpu_sibling_map);
include/asm-i386/processor.h +1 -0
@@ -101,6 +101,7 @@ extern struct cpuinfo_x86 cpu_data[];extern int phys_proc_id[NR_CPUS ];extern int cpu_core_id[NR_CPUS ]; +extern int cpu_thread_id[NR_CPUS ];extern char ignore_fpu_irq;extern void identify_cpu (struct cpuinfo_x86 *);