The perf-events backend for OProfile that Will Deacon wrote in
8c1fc96f6fd1f361428ba805103af0d0eee65179 ("ARM: 6072/1: oprofile: use
perf-events framework as backend") is of use to more architectures
than just ARM. Move the code into drivers/oprofile/ so that SH can use
it instead of the nearly identical copy of its OProfile code.
The benefit of the backend is that it becomes necessary to only
maintain one copy of the PMU accessor functions for each architecture,
with bug fixes and new features benefiting both OProfile and perf.
Note that I haven't been able to test these patches on an ARM board to
see if I've caused any regressions. If anyone else could do that I'd
appreciate it. Though, I have been able to compile this version of the
series.
This patch series is based on,
git://git.kernel.org/pub/scm/linux/kernel/git/rric/oprofile.git core
These patches can also be found at,
git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/sh-2.6.git perf-oprofile
Robert, I haven't rebased this work on your oprofile updates for
2.6.37. If you need me to do that, just shout. If you have any comments
I'll respin this ASAP but it's probably ready for merging now.
Changes from v4:
- SH is the only arch that doesn't default perf_pmu_name()
- Changed perf_nr_counters to num_counters
Changes from v3:
- New perf_pmu_name() function
- Sprinkled an EXPORT_SYMBOL_GPL()
- Don't repeatedly call perf_num_counters()
- Change name of oprofile_driver to "oprofile-perf"
- Hard overwrite the oprofile_operations in oprofile_perf_init()
- Dropped the patch that made oprofile depend on HW_PERF_EVENTS for ARM
Changes from v2:
- Rebased against Robert's oprofile core branch
- Moved even more of the ARM code into the generic oprofile code
- Broke the patches up into more logical steps
Changes from v1:
- Prefix the new functons with "oprofile_" instead of "op_".
- Fix ARM compilation errors
- Move all the oprofile-perf logic into oprofile_perf.c
- Include ...In preparation for moving the generic functions out of this file, give
the functions more general names (e.g. remove "arm" from the names).
Signed-off-by: Matt Fleming <matt@console-pimps.org>
Tested-by: Will Deacon <will.deacon@arm.com>
---
arch/arm/oprofile/common.c | 58 ++++++++++++++++++++++----------------------
1 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c
index 4f67cfa..fd6e323 100644
--- a/arch/arm/oprofile/common.c
+++ b/arch/arm/oprofile/common.c
@@ -38,8 +38,8 @@ struct op_counter_config {
struct perf_event_attr attr;
};
-static int op_arm_enabled;
-static DEFINE_MUTEX(op_arm_mutex);
+static int oprofile_perf_enabled;
+static DEFINE_MUTEX(oprofile_perf_mutex);
static struct op_counter_config *counter_config;
static struct perf_event **perf_events[nr_cpumask_bits];
@@ -66,7 +66,7 @@ static void op_overflow_handler(struct perf_event *event, int unused,
}
/*
- * Called by op_arm_setup to create perf attributes to mirror the oprofile
+ * Called by oprofile_perf_setup to create perf attributes to mirror the oprofile
* settings in counter_config. Attributes are created as `pinned' events and
* so are permanently scheduled on the PMU.
*/
@@ -123,7 +123,7 @@ static void op_destroy_counter(int cpu, int event)
}
/*
- * Called by op_arm_start to create active perf events based on the
+ * Called by oprofile_perf_start to create active perf events based on the
* perviously configured attributes.
*/
static int op_perf_start(void)
@@ -143,7 +143,7 @@ out:
}
/*
- * Called by op_arm_stop at the end of a profiling run.
+ * Called by oprofile_perf_stop at the end of a profiling run.
*/
static void op_perf_stop(void)
{
@@ -177,7 +177,7 @@ char *op_name_from_perf_id(void)
}
}
-static int op_arm_create_files(struct super_block *sb, struct dentry *root)
+static int oprofile_perf_create_files(struct super_block *sb, struct dentry *root)
{
...Make op_name_from_perf_id() global so that we have a way for each
architecture to construct an oprofile name for op->cpu_type. We need to
remove the argument from the function prototype so that we can hide all
implementation details inside the function.
Signed-off-by: Matt Fleming <matt@console-pimps.org>
---
arch/arm/oprofile/common.c | 6 ++++--
include/linux/oprofile.h | 4 ++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c
index 1e971a7..4f67cfa 100644
--- a/arch/arm/oprofile/common.c
+++ b/arch/arm/oprofile/common.c
@@ -155,8 +155,10 @@ static void op_perf_stop(void)
}
-static char *op_name_from_perf_id(enum arm_perf_pmu_ids id)
+char *op_name_from_perf_id(void)
{
+ enum arm_perf_pmu_ids id = armpmu_get_pmu_id();
+
switch (id) {
case ARM_PERF_PMU_ID_XSCALE1:
return "arm/xscale1";
@@ -391,7 +393,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
ops->start = op_arm_start;
ops->stop = op_arm_stop;
ops->shutdown = op_arm_stop;
- ops->cpu_type = op_name_from_perf_id(armpmu_get_pmu_id());
+ ops->cpu_type = op_name_from_perf_id();
if (!ops->cpu_type)
ret = -ENODEV;
diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
index 5171639..1574d4a 100644
--- a/include/linux/oprofile.h
+++ b/include/linux/oprofile.h
@@ -185,4 +185,8 @@ int oprofile_add_data(struct op_entry *entry, unsigned long val);
int oprofile_add_data64(struct op_entry *entry, u64 val);
int oprofile_write_commit(struct op_entry *entry);
+#ifdef CONFIG_PERF_EVENTS
+char *op_name_from_perf_id(void);
+#endif /* CONFIG_PERF_EVENTS */
+
#endif /* OPROFILE_H */
--
1.7.1
--
There is a compile breakage caused by patch #4. Will move the renames to patch #4 when applying the patch. -- Advanced Micro Devices, Inc. Operating System Research Center --
(For some reason I did not receive your mail 0/7, so I reply here.) Matt, on the first glance you patches are looking good (the above is the only thing I found). Will do some further testing and waiting for more replies. If all goes well I am going to apply them. Thanks, -Robert -- Advanced Micro Devices, Inc. Operating System Research Center --
Sorry, I don't know how this happened. These renames were originally in patch #4 but seem to have moved into #5 when I was reshuffling stuff. --
Thanks Matt, I applied your patches to the oprofile tree and merged them with the core branch. As I already wrote, I modified patch #4 to fix the compile breakage. The patches are available for testing in git://git.kernel.org/pub/scm/linux/kernel/git/rric/oprofile.git core Thanks again, -Robert -- Advanced Micro Devices, Inc. Operating System Research Center --
Thanks Robert, I've just read through the merge and it looks good! --
