* [PATCH] MIPS: Make CP0 config registers readable via sysfs.
@ 2012-12-07 5:31 Steven J. Hill
2012-12-12 14:26 ` Florian Fainelli
2012-12-12 14:45 ` Lars-Peter Clausen
0 siblings, 2 replies; 9+ messages in thread
From: Steven J. Hill @ 2012-12-07 5:31 UTC (permalink / raw)
To: linux-mips; +Cc: Steven J. Hill, ralf
From: "Steven J. Hill" <sjhill@mips.com>
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.
Signed-off-by: Steven J. Hill <sjhill@mips.com>
---
arch/mips/kernel/Makefile | 1 +
arch/mips/kernel/sysfs.c | 93 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+)
create mode 100644 arch/mips/kernel/sysfs.c
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index e034ad6..e208a6b 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -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)
#
diff --git a/arch/mips/kernel/sysfs.c b/arch/mips/kernel/sysfs.c
new file mode 100644
index 0000000..a64f559
--- /dev/null
+++ b/arch/mips/kernel/sysfs.c
@@ -0,0 +1,93 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
+ */
+#include <linux/init.h>
+#include <linux/string.h>
+#include <linux/cpu.h>
+#include <linux/percpu.h>
+
+#include <asm/page.h>
+
+
+#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)
+{
+ 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
+ return;
+
+ if (ok) {
+ per_cpu(cpu_config1, cpu->dev.id) = read_c0_config1();
+ device_create_file(dev, &dev_attr_config1);
+ ok = per_cpu(cpu_config1, cpu->dev.id) & MIPS_CONF_M;
+ }
+ if (ok) {
+ per_cpu(cpu_config2, cpu->dev.id) = read_c0_config2();
+ device_create_file(dev, &dev_attr_config2);
+ ok = per_cpu(cpu_config2, cpu->dev.id) & MIPS_CONF_M;
+ }
+ if (ok) {
+ per_cpu(cpu_config3, cpu->dev.id) = read_c0_config3();
+ device_create_file(dev, &dev_attr_config3);
+ ok = per_cpu(cpu_config3, cpu->dev.id) & MIPS_CONF_M;
+ }
+ if (ok) {
+ per_cpu(cpu_config4, cpu->dev.id) = read_c0_config4();
+ device_create_file(dev, &dev_attr_config4);
+ ok = per_cpu(cpu_config4, cpu->dev.id) & MIPS_CONF_M;
+ }
+ if (ok) {
+ per_cpu(cpu_config5, cpu->dev.id) = read_c0_config5();
+ device_create_file(dev, &dev_attr_config5);
+ ok = per_cpu(cpu_config5, cpu->dev.id) & MIPS_CONF_M;
+ }
+ if (ok) {
+ per_cpu(cpu_config6, cpu->dev.id) = read_c0_config6();
+ device_create_file(dev, &dev_attr_config6);
+ ok = per_cpu(cpu_config6, cpu->dev.id) & MIPS_CONF_M;
+ }
+ if (ok) {
+ per_cpu(cpu_config7, cpu->dev.id) = read_c0_config7();
+ device_create_file(dev, &dev_attr_config7);
+ ok = per_cpu(cpu_config7, cpu->dev.id) & MIPS_CONF_M;
+ }
+}
+
+static int __init mips_sysfs_registers(void)
+{
+ on_each_cpu(read_c0_registers, NULL, 1);
+ return 0;
+}
+late_initcall(mips_sysfs_registers);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-07 5:31 [PATCH] MIPS: Make CP0 config registers readable via sysfs Steven J. Hill
@ 2012-12-12 14:26 ` Florian Fainelli
2012-12-12 16:45 ` Hill, Steven
2012-12-12 14:45 ` Lars-Peter Clausen
1 sibling, 1 reply; 9+ messages in thread
From: Florian Fainelli @ 2012-12-12 14:26 UTC (permalink / raw)
To: Steven J. Hill; +Cc: linux-mips, ralf
Hello Steven,
Le 12/07/12 06:31, Steven J. Hill a écrit :
[snip]
> +
> +#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)
> +{
> + 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-07 5:31 [PATCH] MIPS: Make CP0 config registers readable via sysfs Steven J. Hill
2012-12-12 14:26 ` Florian Fainelli
@ 2012-12-12 14:45 ` Lars-Peter Clausen
2012-12-12 16:44 ` Hill, Steven
1 sibling, 1 reply; 9+ messages in thread
From: Lars-Peter Clausen @ 2012-12-12 14:45 UTC (permalink / raw)
To: Steven J. Hill; +Cc: linux-mips, ralf
On 12/07/2012 06:31 AM, Steven J. Hill wrote:
> From: "Steven J. Hill" <sjhill@mips.com>
>
> Allow reading of CP0 config registers via sysfs for each core
> in the system.
Maybe a stupid question, but why?
> 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.
>
> Signed-off-by: Steven J. Hill <sjhill@mips.com>
[...]
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-12 14:45 ` Lars-Peter Clausen
@ 2012-12-12 16:44 ` Hill, Steven
2012-12-12 17:03 ` Florian Fainelli
2012-12-12 18:49 ` Lars-Peter Clausen
0 siblings, 2 replies; 9+ messages in thread
From: Hill, Steven @ 2012-12-12 16:44 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: linux-mips@linux-mips.org
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-12 14:26 ` Florian Fainelli
@ 2012-12-12 16:45 ` Hill, Steven
0 siblings, 0 replies; 9+ messages in thread
From: Hill, Steven @ 2012-12-12 16:45 UTC (permalink / raw)
To: Florian Fainelli; +Cc: linux-mips@linux-mips.org, ralf@linux-mips.org
By golly you're right! I can use a macro for the other code block. Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-12 16:44 ` Hill, Steven
@ 2012-12-12 17:03 ` Florian Fainelli
2012-12-12 18:49 ` Lars-Peter Clausen
1 sibling, 0 replies; 9+ messages in thread
From: Florian Fainelli @ 2012-12-12 17:03 UTC (permalink / raw)
To: Hill, Steven; +Cc: Lars-Peter Clausen, linux-mips@linux-mips.org
Le 12/12/12 17:44, Hill, Steven a écrit :
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-12 16:44 ` Hill, Steven
2012-12-12 17:03 ` Florian Fainelli
@ 2012-12-12 18:49 ` Lars-Peter Clausen
2012-12-12 19:08 ` David Daney
1 sibling, 1 reply; 9+ messages in thread
From: Lars-Peter Clausen @ 2012-12-12 18:49 UTC (permalink / raw)
To: Hill, Steven; +Cc: linux-mips@linux-mips.org
On 12/12/2012 05:44 PM, Hill, Steven wrote:
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-12 18:49 ` Lars-Peter Clausen
@ 2012-12-12 19:08 ` David Daney
2012-12-12 19:14 ` Manuel Lauss
0 siblings, 1 reply; 9+ messages in thread
From: David Daney @ 2012-12-12 19:08 UTC (permalink / raw)
To: Lars-Peter Clausen, Hill, Steven, Ralf Baechle; +Cc: linux-mips@linux-mips.org
On 12/12/2012 10:49 AM, Lars-Peter Clausen wrote:
> On 12/12/2012 05:44 PM, Hill, Steven wrote:
>> 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.
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] MIPS: Make CP0 config registers readable via sysfs.
2012-12-12 19:08 ` David Daney
@ 2012-12-12 19:14 ` Manuel Lauss
0 siblings, 0 replies; 9+ messages in thread
From: Manuel Lauss @ 2012-12-12 19:14 UTC (permalink / raw)
To: David Daney
Cc: Lars-Peter Clausen, Hill, Steven, Ralf Baechle,
linux-mips@linux-mips.org
On Wed, Dec 12, 2012 at 8:08 PM, David Daney <ddaney.cavm@gmail.com> wrote:
> On 12/12/2012 10:49 AM, Lars-Peter Clausen wrote:
>>
>> On 12/12/2012 05:44 PM, Hill, Steven wrote:
>>>
>>> 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.
>
>
>
> 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?
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
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-12-12 19:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-07 5:31 [PATCH] MIPS: Make CP0 config registers readable via sysfs Steven J. Hill
2012-12-12 14:26 ` Florian Fainelli
2012-12-12 16:45 ` Hill, Steven
2012-12-12 14:45 ` Lars-Peter Clausen
2012-12-12 16:44 ` Hill, Steven
2012-12-12 17:03 ` Florian Fainelli
2012-12-12 18:49 ` Lars-Peter Clausen
2012-12-12 19:08 ` David Daney
2012-12-12 19:14 ` Manuel Lauss
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.