MIPS: Make CP0 config registers readable via sysfs.
PATCH 1/1 MIPS: Make CP0 config registers readable via sysfs.
From: "Steven J. Hill" <[email protected]>
Allow reading of CP0 config registers via sysfs for each core in the system. The registers will show up in sysfs at the path:
/sys/devices/system/cpu/cpuX/configX
Only CP0 config registers 0 through 7 are currently supported.
--- arch/mips/kernel/Makefile | 1 + arch/mips/kernel/sysfs.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 arch/mips/kernel/sysfs.c
arch/mips/kernel/Makefile +1 -0
@@ -98,6 +98,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o obj-$(CONFIG_HW_PERF_EVENTS) += perf_event_mipsxx.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o +obj-y += sysfs.o ifeq ($(CONFIG_CPU_MIPS32), y) #
arch/mips/kernel/sysfs.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Hello Steven,
Le 12/07/12 06:31, Steven J. Hill a écrit :
[snip]
Quoted 24 lines
arch/mips/kernel/sysfs.c new file +24
-0+ +#define __BUILD_CP0_SYSFS (reg) \ +static DEFINE_PER_CPU(unsigned int, cpu_config##reg); \ +static ssize_t show_config##reg(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + struct cpu *cpu = container_of(dev, struct cpu, dev); \ + int n = snprintf(buf, PAGE_SIZE-2, "%x\n", \ + per_cpu(cpu_config##reg, cpu->dev.id)); \ + return n; \ +} \ +static DEVICE_ATTR(config##reg, 0444, show_config##reg, NULL); + +__BUILD_CP0_SYSFS(0) +__BUILD_CP0_SYSFS(1) +__BUILD_CP0_SYSFS(2) +__BUILD_CP0_SYSFS(3) +__BUILD_CP0_SYSFS(4) +__BUILD_CP0_SYSFS(5) +__BUILD_CP0_SYSFS(6) +__BUILD_CP0_SYSFS(7) + +static void read_c0_registers (void *arg) +{
arch/mips/kernel/sysfs.c line 48
Quoted 10 lines
arch/mips/kernel/sysfs.c new file +10
-0+struct device *dev =get_cpu_device (smp_processor_id ()); +struct cpu *cpu; +int ok; + +if (dev !=NULL ) { + cpu = container_of(dev, struct cpu, dev); +per_cpu (cpu_config0, cpu->dev.id) =read_c0_config (); +device_create_file (dev, &dev_attr_config0); + ok =per_cpu (cpu_config0, cpu->dev.id) &MIPS_CONF_M ; + }else
Is there any reason you are not using a macro here too? --
Florian
By golly you're right! I can use a macro for the other code block. Thanks.
Quoted 4 lines · Steven J. Hill
From: "Steven J. Hill" <[email protected]>
Allow reading of CP0 config registers via sysfs for each core in the system.
Maybe a stupid question, but why?
Quoted 8 lines
The registers will show up in sysfs at the path:
/sys/devices/system/cpu/cpuX/configXOnly CP0 config registers 0 through 7 are currently supported.
Signed-off-by Steven J. Hill <[email protected]>
[...]
Lars,
This patch was requested by our DSP/Codec group to help with selecting the best user-space codecs at runtime. Simply reading /proc/cpuinfo was insufficient. I posted this patch more for feedback and interest with minimal expectations that it would make it upstream. This patch will always be in our supported branches, but I will defer to everyone else on its worth for upstream.
-Steve
Quoted 3 lines · Steven
Lars,
This patch was requested by our DSP/Codec group to help with selecting the best user-space codecs at runtime. Simply reading
/proc/cpuinfowas insufficient. I posted this patch more for feedback and interest with minimal expectations that it would make it upstream. This patch will always be in our supported branches, but I will defer to everyone else on its worth for upstream.
How do they actually make their choices? Is it just about advertising dsp vs. dspr2 to user-space?
Have you looked into modifying the ELF platform via set_elf_platform() to help these binaries with identify the underlying platform/kernel? --
Florian
Quoted 5 lines · Steven
Lars,
This patch was requested by our DSP/Codec group to help with selecting the best user-space codecs at runtime. Simply reading
/proc/cpuinfowas insufficient. I posted this patch more for feedback and interest with minimal expectations that it would make it upstream. This patch will always be in our supported branches, but I will defer to everyone else on its worth for upstream.-Steve
Well if it is something that is useful it makes sense to upstream it, especially if you are developing applications. Many people before you have learned the hard way that stashing stuff away in their private branches was not the best idea. If you are smart you are going to avoid that.
It may not be the best solution though to just dump all the cp register to userspace. As Florian suggested there might be a smarter way to solve this.
- Lars
Quoted 7 lines · Lars-Peter Clausen
Quoted 5 lines · Steven
Lars,
This patch was requested by our DSP/Codec group to help with selecting the best user-space codecs at runtime. Simply reading
/proc/cpuinfowas insufficient. I posted this patch more for feedback and interest with minimal expectations that it would make it upstream. This patch will always be in our supported branches, but I will defer to everyone else on its worth for upstream.-Steve
Quoted 7 lines
Well if it is something that is useful it makes sense to upstream it, especially if you are developing applications. Many people before you have learned the hard way that stashing stuff away in their private branches was not the best idea. If you are smart you are going to avoid that.
It may not be the best solution though to just dump all the cp register to userspace. As Florian suggested there might be a smarter way to solve this.
If you want to have glibc's ld.so automatically select optimal libraries for a given platform, then the elf_platform is the way to do it.
However I don't think this is necessarily the case here. elf_platform cannot easily handle a bunch of orthogonal capabilities. So I am in favor of the principle of this patch.
There should be a per CPU file (probably in /sys/devices/system/cpu/cpuXX) with the CP0_Config values.
One question I have is: Should it be a single file with one row for each implemented Config register, or one file per register?
David Daney
Quoted 35 lines · David Daney
Quoted 21 lines · Lars-Peter Clausen
Quoted 11 lines · Steven
Lars,
This patch was requested by our DSP/Codec group to help with selecting the best user-space codecs at runtime. Simply reading
/proc/cpuinfowas insufficient. I posted this patch more for feedback and interest with minimal expectations that it would make it upstream. This patch will always be in our supported branches, but I will defer to everyone else on its worth for upstream.-Steve
Well if it is something that is useful it makes sense to upstream it, especially if you are developing applications. Many people before you have learned the hard way that stashing stuff away in their private branches was not
the best idea. If you are smart you are going to avoid that.Quoted 3 lines
It may not be the best solution though to just dump all the cp register to userspace. As Florian suggested there might be a smarter way to solve this.
If you want to have glibc's ld.so automatically select optimal libraries for a given platform, then the
elf_platformis the way to do it.However I don't think this is necessarily the case here.
elf_platformcannot easily handle a bunch of orthogonal capabilities. So I am in favor of the principle of this patch.
Quoted 5 lines
There should be a per CPU file (probably in
/sys/devices/system/cpu/cpuXX) with theCP0_Configvalues.One question I have is: Should it be a single file with one row for each implemented Config register, or one file per register?
I'm all for the one-file-per-register approach. I find it easier to just read the
right register instead of having to find out how many rows to read to get the value I'm looking for.
Thanks!
Manuel