[Cbe-oss-dev] [RFC/PATCH]: User-space access to Cell bookmark registers
Kevin Corry
kevcorry at us.ibm.com
Thu Aug 9 04:47:10 EST 2007
Hi,
While working on the Perfmon2 code for Cell, I've gotten requests to enable
access to the Cell bookmark special-purpose-registers. These are not part of
the actual PMU, but writing to them can trigger actions in the PMU, such as
starting and/or stopping the hardware performance counters and generating
trace data. To provide user-space with access to these registers, I've
written a patch that adds the files /sys/devices/system/cpu/cpu*/bookmark.
The registers are write-only, so the sysfs files are also write-only.
A couple of questions: Is this the correct method (using sysfs) to provide
access to these registers (or other SPRs)? The patch adds the new code to the
arch/powerpc/platforms/cell/pmu.c file. However, the registers aren't
actually part of the PMU. Is pmu.c appropriate for this code or should it go
in some other file?
Please let me know if anyone has comments about this patch.
Thanks,
--
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*/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.
Signed-off-by: Kevin Corry <kevcorry at us.ibm.com>
Index: linux-2.6.22-5.20070724bsc/arch/powerpc/platforms/cell/pmu.c
===================================================================
--- linux-2.6.22-5.20070724bsc.orig/arch/powerpc/platforms/cell/pmu.c
+++ linux-2.6.22-5.20070724bsc/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>
@@ -424,3 +425,38 @@ void cbe_sync_irq(int node)
}
EXPORT_SYMBOL_GPL(cbe_sync_irq);
+/*
+ * Provide files in sysfs to allow user-space to write to the bookmark
+ * registers. The sysfs files are /sys/devices/system/cpu/cpu?/bookmark.
+ */
+
+#define BOOKMARK_SPR_ADDR 1020
+
+static ssize_t cbe_store_bookmark(struct sys_device *dev,
+ const char *buf, size_t count)
+{
+ cpumask_t old_affinity = current->cpus_allowed;
+ int rc, cpu = dev->id;
+ u64 val;
+
+ rc = sscanf(buf, "%lu", &val);
+ if (rc != 1)
+ return -EINVAL;
+
+ if (set_cpus_allowed(current, cpumask_of_cpu(cpu)))
+ return -EINVAL;
+
+ mtspr(BOOKMARK_SPR_ADDR, val);
+
+ set_cpus_allowed(current, old_affinity);
+
+ return count;
+}
+
+static SYSDEV_ATTR(bookmark, 0200, NULL, cbe_store_bookmark);
+
+static int __init cbe_bookmark_init(void)
+{
+ return cpu_add_sysdev_attr(&attr_bookmark);
+}
+__initcall(cbe_bookmark_init);
More information about the cbe-oss-dev
mailing list