Skip to contentSkip to conversation

MIPS: Make CP0 config registers readable via sysfs.

PATCH Superseded Steven J. Hill 5 participants 9 messages Dec 7, 2012 – Dec 12, 2012 MIPS

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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
index e034ad6..e208a6b 100644
@@ -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
#1 lore raw

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

#4 lore raw
In reply to Lars-Peter Clausen

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

#5 lore raw
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/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.

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

#6 lore raw
In reply to Hill, Steven
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/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

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

#7 lore raw
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/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 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

#8 lore raw
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/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

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_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.

Quoted 5 lines

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?

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