[Cbe-oss-dev] [RFC/PATCH]: User-space access to Cell bookmark registers
Kevin Corry
kevcorry at us.ibm.com
Fri Aug 10 00:37:46 EST 2007
On Thu August 9 2007 7:51 am, Anton Blanchard wrote:
> > Well, smp_call_function_single() will only call smp_call_function_map()
> > if you are not targetting the current CPU, but it doesn't directly run
> > the desired routine if you are targetting the current CPU. So we'd need
> > to do something like:
>
> It was a recent addition:
>
> if (cpu != get_cpu())
> ret = smp_call_function_map(func,info,nonatomic,wait,map);
> else {
> local_irq_disable();
> func(info);
> local_irq_enable();
> }
Ah, yes. I see it now, after checking Linus' latest git tree. I had been
looking at the latest sdk kernel before.
> > Would that be preferrable to the set_cpus_allowed() method?
>
> I did the same affinity trick in arch/powerpc/kernel/sysfs.c.
Which I believe is where I got that code in the first place. :)
Anyway, here's yet another version, using smp_call_function_single(). This
patch is now against linux-2.6.git instead of 2.6.22-5.20070724bsc (but it
should apply cleanly to both).
--
Kevin Corry
kevcorry at us.ibm.com
http://www.ibm.com/linux/
[CELL] User-space access to bookmark registers.
Add the files /sys/devices/system/cpu/cpu*/pmu_bookmark to provide user-space
with a method for writing to the bookmark registers in the Cell processor.
Writes to these registers can be used by the performance monitoring unit to
generate trace data and to trigger the starting and stopping of the hardware
performance counters.
This renames the existing cbe_init_pm_irq() routine to cbe_init_pmu(), and adds
the initialization of these new sysfs files to that init routine.
Signed-off-by: Kevin Corry <kevcorry at us.ibm.com>
diff --git a/arch/powerpc/platforms/cell/pmu.c b/arch/powerpc/platforms/cell/pmu.c
index 66ca4b5..d74eb80 100644
--- a/arch/powerpc/platforms/cell/pmu.c
+++ b/arch/powerpc/platforms/cell/pmu.c
@@ -22,6 +22,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <linux/cpu.h>
#include <linux/interrupt.h>
#include <linux/types.h>
#include <asm/io.h>
@@ -376,7 +377,61 @@ static irqreturn_t cbe_pm_irq(int irq, void *dev_id)
return IRQ_HANDLED;
}
-static int __init cbe_init_pm_irq(void)
+/*
+ * Provide files in sysfs to allow user-space to access the bookmark registers.
+ * The sysfs files are /sys/devices/system/cpu/cpu?/pmu_bookmark. The registers
+ * are write only, so we'll provide "shadow" values so user-space can read the
+ * values as well.
+ */
+
+static DEFINE_PER_CPU(u64, pmu_bookmark);
+
+static void read_bookmark(void *data)
+{
+ u64 *val = data;
+ *val = __get_cpu_var(pmu_bookmark);
+}
+
+static ssize_t cbe_show_pmu_bookmark(struct sys_device *dev, char *buf)
+{
+ int rc, cpu = dev->id;
+ u64 val;
+
+ rc = smp_call_function_single(cpu, read_bookmark, &val, 0, 1);
+ if (rc)
+ return rc;
+
+ return sprintf(buf, "%lu\n", val);
+}
+
+static void write_bookmark(void *data)
+{
+ u64 *val = data;
+ __get_cpu_var(pmu_bookmark) = *val;
+ mtspr(SPRN_BKMK, *val);
+}
+
+static ssize_t cbe_store_pmu_bookmark(struct sys_device *dev,
+ const char *buf, size_t count)
+{
+ int rc, cpu = dev->id;
+ u64 val;
+
+ rc = sscanf(buf, "%lu", &val);
+ if (rc != 1)
+ return -EINVAL;
+
+ rc = smp_call_function_single(cpu, write_bookmark, &val, 0, 1);
+ if (rc)
+ return rc;
+
+ return count;
+}
+
+static SYSDEV_ATTR(pmu_bookmark, 0600,
+ cbe_show_pmu_bookmark, cbe_store_pmu_bookmark);
+
+static int __init cbe_init_pmu(void)
{
unsigned int irq;
int rc, node;
@@ -402,9 +457,9 @@ static int __init cbe_init_pm_irq(void)
}
}
- return 0;
+ return cpu_add_sysdev_attr(&attr_pmu_bookmark);
}
-arch_initcall(cbe_init_pm_irq);
+__initcall(cbe_init_pmu);
void cbe_sync_irq(int node)
{
diff --git a/include/asm-powerpc/reg.h b/include/asm-powerpc/reg.h
index 281011e..d9deeb8 100644
--- a/include/asm-powerpc/reg.h
+++ b/include/asm-powerpc/reg.h
@@ -427,6 +427,8 @@
#define SPRN_SCOMC 0x114 /* SCOM Access Control */
#define SPRN_SCOMD 0x115 /* SCOM Access DATA */
+#define SPRN_BKMK 1020 /* Cell Bookmark Register */
+
/* Performance monitor SPRs */
#ifdef CONFIG_PPC64
#define SPRN_MMCR0 795
More information about the cbe-oss-dev
mailing list