ARM: kernel: update cpuinfo to print all online CPUs features
RFC PATCH 1/1 ARM: kernel: update cpuinfo to print all online CPUs features
Currently, reading /proc/cpuinfo provides userspace with CPU ID of the CPU carrying out the read from the file. This is fine as long as all CPUs in the system are the same. With the advent of big.LITTLE and heterogenous ARM systems this approach provides user space with incorrect bits of information since CPU ids in the system might differ from the one provided by the CPU reading the file.
This patch updates the cpuinfo show function and some internal data structures so that a read from /proc/cpuinfo prints HW information for all online CPUs at once, mirroring x86 behaviour.
---
Posting it as a way to get advice on the best way to improve /proc/cpuinfo for heterogenous multi-cluster systems and to provide proper information to userspace without breaking existing semantics, no more than that.
Comments more than welcome.
Thanks,
Lorenzo
arch/arm/include/asm/cpu.h | 1 + arch/arm/kernel/setup.c | 66 +++++++++++++++++++++++----------------------- arch/arm/kernel/smp.c | 1 + 3 files changed, 35 insertions(+), 33 deletions(-)
arch/arm/include/asm/cpu.h +1 -0
@@ -15,6 +15,7 @@struct cpuinfo_arm {struct cpu cpu; +u32 cpuid;#ifdef CONFIG_SMP unsigned int loops_per_jiffy;#endif
arch/arm/kernel/setup.c +33 -33
88 lines not on this page · raw message
arch/arm/kernel/smp.c +1 -0
@@ -211,6 +211,7 @@ static void __cpuinit smp_store_cpu_info(unsigned int cpuid)struct cpuinfo_arm *cpu_info = &per_cpu (cpu_data, cpuid); cpu_info->loops_per_jiffy = loops_per_jiffy; + cpu_info->cpuid =read_cpuid_id ();store_cpu_topology (cpuid); }
Signature · 1 line
1.7.12
RFC PATCH 1/1 ARM: kernel: update cpuinfo to print all online CPUs features
Quoted 28 lines · Lorenzo Pieralisi
Currently, reading
/proc/cpuinfoprovides userspace with CPU ID of the CPU carrying out the read from the file. This is fine as long as all CPUs in the system are the same. With the advent of big.LITTLE and heterogenous ARM systems this approach provides user space with incorrect bits of information since CPU ids in the system might differ from the one provided by the CPU reading the file.This patch updates the cpuinfo show function and some internal data structures so that a read from
/proc/cpuinfoprints HW information for all online CPUs at once, mirroring x86 behaviour.Signed-off-by Lorenzo Pieralisi <[email protected]>---
Posting it as a way to get advice on the best way to improve
/proc/cpuinfofor heterogenous multi-cluster systems and to provide proper information to userspace without breaking existing semantics, no more than that.Comments more than welcome.
Thanks,
Lorenzoarch/arm/include/asm/cpu.h | 1 + arch/arm/kernel/setup.c | 66 +++++++++++++++++++++++----------------------- arch/arm/kernel/smp.c | 1 + 3 files changed, 35 insertions(+), 33 deletions(-)
[...]
Quoted 9 lines
arch/arm/kernel/setup.c +0
-1@@ -1054,13 +1054,15 @@ static const char *hwcap_str[] = {static int c_show (struct seq_file *m,void *v) { -int i;
arch/arm/kernel/setup.c static const char *hwcap_str[] = { · line 1064
Quoted 10 lines
arch/arm/kernel/setup.c +6
-2+int i, j; +u32 cpuid; -seq_printf (m,"Processor\t: %s rev %d (%s)\n" , - cpu_name,read_cpuid_id () &15 , elf_platform); +for_each_online_cpu (i) { + cpuid =is_smp () ?per_cpu (cpu_data, i).cpuid :read_cpuid_id (); +seq_printf (m,"Processor\t: %s rev %d (%s)\n" , + cpu_name, cpuid &15 , elf_platform);
Not exactly related to the $subject patch, but I remember doing a patch to have cat /proc/cpuinfo spitting only online CPUs just like x86 using for_each_online_cpu(i).
At that point Russell mentioned about a possibility of read() syscall spreading over the hot-plug operation and hence the above may not be safe.
is that right Russell ?
regards
Santosh
RFC PATCH 1/1 ARM: kernel: update cpuinfo to print all online CPUs features
Quoted 8 lines · Santosh Shilimkar
Not exactly related to the $subject patch, but I remember doing a patch to have cat
/proc/cpuinfospitting only online CPUs just like x86 usingfor_each_online_cpu(i).
At that point Russell mentioned about a possibility ofread()syscall spreading over the hot-plug operation and hence the above may not be safe.is that right Russell ?
That is correct, but you will notice that the code now uses the online cpus rather than the present, inspite of my objections. I gave up fighting the case, so now people get to live with the consequences of this.
This will be fun with dynamic hotplugging with big.LITTLE when people come to read any of these files which change their output with the online CPUs. Oh what fun we're in for there.
I guess the only way to convince people is to let them make their mistakes in the kernel.
RFC PATCH 1/1 ARM: kernel: update cpuinfo to print all online CPUs features
Quoted 10 lines · Russell King - ARM Linux
Quoted 8 lines · Santosh Shilimkar
Not exactly related to the $subject patch, but I remember doing a patch to have cat
/proc/cpuinfospitting only online CPUs just like x86 usingfor_each_online_cpu(i).
At that point Russell mentioned about a possibility ofread()syscall spreading over the hot-plug operation and hence the above may not be safe.is that right Russell ?
Quoted 8 lines
That is correct, but you will notice that the code now uses the online cpus rather than the present, inspite of my objections. I gave up fighting the case, so now people get to live with the consequences of this.
This will be fun with dynamic hotplugging with big.LITTLE when people come to read any of these files which change their output with the online CPUs. Oh what fun we're in for there.
I had a look at how glibc currently detects cpus in __get_nprocs() and all methods end up relying on online CPUs:
- /sys/devices/system/cpu/online
- /proc/stat
- /proc/cpuinfo
Given the thread:
http://lists.infradead.org/pipermail/linux-arm-kernel/2011-June/054081.html
I do not think there is room to change the current behaviour of /proc/cpuinfo as far as the online vs. present argument goes, and I certainly did not try.
I posted this code just to understand if it makes sense to expose all CPU ids in /proc/cpuinfo the way I did (the same way x86 does, even though the code is slightly different).
Quoted 2 lines
I guess the only way to convince people is to let them make their mistakes in the kernel.
That's what I wanted to prevent by posting this code, namely getting feedback on the best way to improve /proc/cpuinfo for systems where CPU ids are not homogeneous.
The "online vs. present" issue is already there as Russell pointed out.
Thank you very much for the review, any further feedback appreciated.
Lorenzo