sh: oprofile: Fix up and extend op_name_from_perf_id().
authorPaul Mundt <lethal@linux-sh.org>
Tue, 12 Oct 2010 18:46:25 +0000 (03:46 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Wed, 27 Oct 2010 07:51:33 +0000 (16:51 +0900)
op_name_from_perf_id() currently returns a local variable, which isn't
terribly productive. As we only handle a single PMU case for now, simply
allocate and free the string from the arch init/exit context and have
op_name_from_perf_id() hand back the cached string.

This also takes UTS_MACHINE in to account, given that we build for
multiple architectures.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/kernel/cpu/sh4/perf_event.c
arch/sh/kernel/cpu/sh4a/perf_event.c
arch/sh/oprofile/Makefile
arch/sh/oprofile/common.c

index 7f9ecc9..dbf3b4b 100644 (file)
@@ -225,7 +225,7 @@ static void sh7750_pmu_enable_all(void)
 }
 
 static struct sh_pmu sh7750_pmu = {
-       .name           = "SH7750",
+       .name           = "sh7750",
        .num_events     = 2,
        .event_map      = sh7750_event_map,
        .max_events     = ARRAY_SIZE(sh7750_general_events),
index b8b873d..5802765 100644 (file)
@@ -259,7 +259,7 @@ static void sh4a_pmu_enable_all(void)
 }
 
 static struct sh_pmu sh4a_pmu = {
-       .name           = "SH-4A",
+       .name           = "sh4a",
        .num_events     = 2,
        .event_map      = sh4a_event_map,
        .max_events     = ARRAY_SIZE(sh4a_general_events),
index e85aae7..ce3b119 100644 (file)
@@ -1,5 +1,7 @@
 obj-$(CONFIG_OPROFILE) += oprofile.o
 
+CFLAGS_common.o        += -DUTS_MACHINE='"$(UTS_MACHINE)"'
+
 DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
                oprof.o cpu_buffer.o buffer_sync.o \
                event_buffer.o oprofile_files.o \
index e10d893..8453314 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * arch/sh/oprofile/init.c
  *
- * Copyright (C) 2003 - 2008  Paul Mundt
+ * Copyright (C) 2003 - 2010  Paul Mundt
  *
  * Based on arch/mips/oprofile/common.c:
  *
 #include <linux/errno.h>
 #include <linux/smp.h>
 #include <linux/perf_event.h>
+#include <linux/slab.h>
 #include <asm/processor.h>
 
 #ifdef CONFIG_HW_PERF_EVENTS
 extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth);
 
+/*
+ * This will need to be reworked when multiple PMUs are supported.
+ */
+static char *sh_pmu_op_name;
+
 char *op_name_from_perf_id(void)
 {
-       const char *pmu;
-       char buf[20];
-       int size;
-
-       pmu = perf_pmu_name();
-       if (!pmu)
-               return NULL;
-
-       size = snprintf(buf, sizeof(buf), "sh/%s", pmu);
-       if (size > -1 && size < sizeof(buf))
-               return buf;
-
-       return NULL;
+       return sh_pmu_op_name;
 }
 
 int __init oprofile_arch_init(struct oprofile_operations *ops)
 {
        ops->backtrace = sh_backtrace;
 
+       if (perf_num_counters() == 0)
+               return -ENODEV;
+
+       sh_pmu_op_name = kasprintf(GFP_KERNEL, "%s/%s",
+                                  UTS_MACHINE, perf_pmu_name());
+       if (unlikely(!sh_pmu_op_name))
+               return -ENOMEM;
+
        return oprofile_perf_init(ops);
 }
 
 void __exit oprofile_arch_exit(void)
 {
        oprofile_perf_exit();
+       kfree(sh_pmu_op_name);
 }
 #else
 int __init oprofile_arch_init(struct oprofile_operations *ops)