Move the perf-events backend from arch/arm/oprofile into
drivers/oprofile so that the code can be shared between architectures.
This allows each architecture to maintain only a single copy of the
PMU accessor functions instead of one for both perf and OProfile. It
also becomes possible for other architectures to delete much of their
OProfile code in favour of the common code now available in
drivers/oprofile/oprofile_perf.c.
Signed-off-by: Matt Fleming <matt@console-pimps.org>
---
arch/arm/oprofile/Makefile | 4 +
arch/arm/oprofile/common.c | 215 +++-----------------------------------
drivers/oprofile/oprofile_perf.c | 209 ++++++++++++++++++++++++++++++++++++
include/linux/oprofile.h | 12 ++
4 files changed, 242 insertions(+), 198 deletions(-)
create mode 100644 drivers/oprofile/oprofile_perf.c
diff --git a/arch/arm/oprofile/Makefile b/arch/arm/oprofile/Makefile
index e666eaf..038d7af 100644
--- a/arch/arm/oprofile/Makefile
+++ b/arch/arm/oprofile/Makefile
@@ -6,4 +6,8 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
oprofilefs.o oprofile_stats.o \
timer_int.o )
+ifeq ($(CONFIG_HW_PERF_EVENTS), y)
+DRIVER_OBJS += $(addprefix ../../../drivers/oprofile/, oprofile_perf.o)
+endif
+
oprofile-y := $(DRIVER_OBJS) common.o
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c
index 482779c..f4ea5f8 100644
--- a/arch/arm/oprofile/common.c
+++ b/arch/arm/oprofile/common.c
@@ -25,136 +25,9 @@
#include <asm/ptrace.h>
#ifdef CONFIG_HW_PERF_EVENTS
-/*
- * Per performance monitor configuration as set via oprofilefs.
- */
-struct op_counter_config {
- unsigned long count;
- unsigned long enabled;
- unsigned long event;
- unsigned long unit_mask;
- unsigned long kernel;
- unsigned long user;
- struct perf_event_attr attr;
-};
-
static int op_arm_enabled;
static DEFINE_MUTEX(op_arm_mutex);
-static struct op_counter_config *counter_config;
-static struct perf_event ...Hi Matt,
I'm still not happy with the init/exit alloc/free code:
On Thu, 2010-08-26 at 20:09 +0100, Matt Fleming wrote:
So here, if the perf_events allocation fails for a cpu, we free the
stuff we've already allocated [including counter_config] and return
-ENOMEM. Looking at drivers/oprofile/oprof.c:
static int __init oprofile_init(void)
{
int err;
err = oprofile_arch_init(&oprofile_ops);
if (err < 0 || timer) {
printk(KERN_INFO "oprofile: using timer interrupt.\n");
err = oprofile_timer_init(&oprofile_ops);
if (err)
goto out_arch;
}
err = oprofilefs_register();
if (err)
goto out_arch;
return 0;
out_arch:
oprofile_arch_exit();
return err;
}
So now, if timer_init fails or oprofilefs_register fails, we will
meaning that we will free everything again! This is what I
was trying to avoid in patch 1/4, by moving the counter_config
freeing into the *_exit function. Looking at it again, I think
all the freeing should be moved to the *_exit function and the init
function should just return error when allocation fails. What do you
typo :)
For what it's worth, I tested the series on my Cortex-A9 board and
everything seemed to work fine. I'll give the patches another spin when
we've sorted out these memory issues.
Cheers,
Will
--
*facepalm* I dunno how I forgot to fix up that patch. Sorry. You're completely right, I forgot to role your changes from patch 1/4 into 3/4 when I Excellent news. Thanks for testing! I'll get the next version of patch 3/4 out tonight. --
Could we split this patch in 2 for better review? One that only moves the code and a 2nd that changes it. -Robert -- Advanced Micro Devices, Inc. Operating System Research Center --
We need empty function stubs for all this functions for the !CONFIG_PERF_EVENTS case returning -ENODEV or so. Otherwise compliation will fail for it. For arm this does not happen because of #ifdefs, but for sh. Again, please first change the code and then move it without functional changes, one patch each. Thanks, -- Advanced Micro Devices, Inc. Operating System Research Center --
