ARM: perf: prepare for moving CPU PMU code into separate file
The CPU PMU code is tightly coupled with generic ARM PMU handling code. This makes it cumbersome when trying to add support for other ARM PMUs (e.g. interconnect, L2 cache controller, bus) as the generic parts of the code are not readily reusable. This patch cleans up perf_event.c so that reusable code is exposed via header files to other potential PMU drivers. The CPU code is consistently named to identify it as such and also to prepare for moving it into a separate file. Signed-off-by: Will Deacon <will.deacon@arm.com>
This commit is contained in:
parent
04236f9fe0
commit
6dbc002970
|
@ -12,6 +12,13 @@
|
||||||
#ifndef __ARM_PERF_EVENT_H__
|
#ifndef __ARM_PERF_EVENT_H__
|
||||||
#define __ARM_PERF_EVENT_H__
|
#define __ARM_PERF_EVENT_H__
|
||||||
|
|
||||||
/* Nothing to see here... */
|
/*
|
||||||
|
* The ARMv7 CPU PMU supports up to 32 event counters.
|
||||||
|
*/
|
||||||
|
#define ARMPMU_MAX_HWEVENTS 32
|
||||||
|
|
||||||
|
#define HW_OP_UNSUPPORTED 0xFFFF
|
||||||
|
#define C(_x) PERF_COUNT_HW_CACHE_##_x
|
||||||
|
#define CACHE_OP_UNSUPPORTED 0xFFFF
|
||||||
|
|
||||||
#endif /* __ARM_PERF_EVENT_H__ */
|
#endif /* __ARM_PERF_EVENT_H__ */
|
||||||
|
|
|
@ -89,7 +89,9 @@ struct arm_pmu {
|
||||||
|
|
||||||
#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
|
#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
|
||||||
|
|
||||||
int __init armpmu_register(struct arm_pmu *armpmu, char *name, int type);
|
extern const struct dev_pm_ops armpmu_dev_pm_ops;
|
||||||
|
|
||||||
|
int armpmu_register(struct arm_pmu *armpmu, char *name, int type);
|
||||||
|
|
||||||
u64 armpmu_event_update(struct perf_event *event,
|
u64 armpmu_event_update(struct perf_event *event,
|
||||||
struct hw_perf_event *hwc,
|
struct hw_perf_event *hwc,
|
||||||
|
@ -99,6 +101,13 @@ int armpmu_event_set_period(struct perf_event *event,
|
||||||
struct hw_perf_event *hwc,
|
struct hw_perf_event *hwc,
|
||||||
int idx);
|
int idx);
|
||||||
|
|
||||||
|
int armpmu_map_event(struct perf_event *event,
|
||||||
|
const unsigned (*event_map)[PERF_COUNT_HW_MAX],
|
||||||
|
const unsigned (*cache_map)[PERF_COUNT_HW_CACHE_MAX]
|
||||||
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
||||||
|
[PERF_COUNT_HW_CACHE_RESULT_MAX],
|
||||||
|
u32 raw_event_mask);
|
||||||
|
|
||||||
#endif /* CONFIG_HW_PERF_EVENTS */
|
#endif /* CONFIG_HW_PERF_EVENTS */
|
||||||
|
|
||||||
#endif /* __ARM_PMU_H__ */
|
#endif /* __ARM_PMU_H__ */
|
||||||
|
|
|
@ -29,26 +29,17 @@
|
||||||
#include <asm/pmu.h>
|
#include <asm/pmu.h>
|
||||||
#include <asm/stacktrace.h>
|
#include <asm/stacktrace.h>
|
||||||
|
|
||||||
/*
|
/* Set at runtime when we know what CPU type we are. */
|
||||||
* ARMv6 supports a maximum of 3 events, starting from index 0. If we add
|
static struct arm_pmu *cpu_pmu;
|
||||||
* another platform that supports more, we need to increase this to be the
|
|
||||||
* largest of all platforms.
|
|
||||||
*
|
|
||||||
* ARMv7 supports up to 32 events:
|
|
||||||
* cycle counter CCNT + 31 events counters CNT0..30.
|
|
||||||
* Cortex-A8 has 1+4 counters, Cortex-A9 has 1+6 counters.
|
|
||||||
*/
|
|
||||||
#define ARMPMU_MAX_HWEVENTS 32
|
|
||||||
|
|
||||||
static DEFINE_PER_CPU(struct perf_event * [ARMPMU_MAX_HWEVENTS], hw_events);
|
static DEFINE_PER_CPU(struct perf_event * [ARMPMU_MAX_HWEVENTS], hw_events);
|
||||||
static DEFINE_PER_CPU(unsigned long [BITS_TO_LONGS(ARMPMU_MAX_HWEVENTS)], used_mask);
|
static DEFINE_PER_CPU(unsigned long [BITS_TO_LONGS(ARMPMU_MAX_HWEVENTS)], used_mask);
|
||||||
static DEFINE_PER_CPU(struct pmu_hw_events, cpu_hw_events);
|
static DEFINE_PER_CPU(struct pmu_hw_events, cpu_hw_events);
|
||||||
|
|
||||||
#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
|
/*
|
||||||
|
* Despite the names, these two functions are CPU-specific and are used
|
||||||
/* Set at runtime when we know what CPU type we are. */
|
* by the OProfile/perf code.
|
||||||
static struct arm_pmu *cpu_pmu;
|
*/
|
||||||
|
|
||||||
const char *perf_pmu_name(void)
|
const char *perf_pmu_name(void)
|
||||||
{
|
{
|
||||||
if (!cpu_pmu)
|
if (!cpu_pmu)
|
||||||
|
@ -69,13 +60,6 @@ int perf_num_counters(void)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(perf_num_counters);
|
EXPORT_SYMBOL_GPL(perf_num_counters);
|
||||||
|
|
||||||
#define HW_OP_UNSUPPORTED 0xFFFF
|
|
||||||
|
|
||||||
#define C(_x) \
|
|
||||||
PERF_COUNT_HW_CACHE_##_x
|
|
||||||
|
|
||||||
#define CACHE_OP_UNSUPPORTED 0xFFFF
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
armpmu_map_cache_event(const unsigned (*cache_map)
|
armpmu_map_cache_event(const unsigned (*cache_map)
|
||||||
[PERF_COUNT_HW_CACHE_MAX]
|
[PERF_COUNT_HW_CACHE_MAX]
|
||||||
|
@ -106,7 +90,7 @@ armpmu_map_cache_event(const unsigned (*cache_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
armpmu_map_event(const unsigned (*event_map)[PERF_COUNT_HW_MAX], u64 config)
|
armpmu_map_hw_event(const unsigned (*event_map)[PERF_COUNT_HW_MAX], u64 config)
|
||||||
{
|
{
|
||||||
int mapping = (*event_map)[config];
|
int mapping = (*event_map)[config];
|
||||||
return mapping == HW_OP_UNSUPPORTED ? -ENOENT : mapping;
|
return mapping == HW_OP_UNSUPPORTED ? -ENOENT : mapping;
|
||||||
|
@ -118,19 +102,20 @@ armpmu_map_raw_event(u32 raw_event_mask, u64 config)
|
||||||
return (int)(config & raw_event_mask);
|
return (int)(config & raw_event_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int map_cpu_event(struct perf_event *event,
|
int
|
||||||
const unsigned (*event_map)[PERF_COUNT_HW_MAX],
|
armpmu_map_event(struct perf_event *event,
|
||||||
const unsigned (*cache_map)
|
const unsigned (*event_map)[PERF_COUNT_HW_MAX],
|
||||||
[PERF_COUNT_HW_CACHE_MAX]
|
const unsigned (*cache_map)
|
||||||
[PERF_COUNT_HW_CACHE_OP_MAX]
|
[PERF_COUNT_HW_CACHE_MAX]
|
||||||
[PERF_COUNT_HW_CACHE_RESULT_MAX],
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
||||||
u32 raw_event_mask)
|
[PERF_COUNT_HW_CACHE_RESULT_MAX],
|
||||||
|
u32 raw_event_mask)
|
||||||
{
|
{
|
||||||
u64 config = event->attr.config;
|
u64 config = event->attr.config;
|
||||||
|
|
||||||
switch (event->attr.type) {
|
switch (event->attr.type) {
|
||||||
case PERF_TYPE_HARDWARE:
|
case PERF_TYPE_HARDWARE:
|
||||||
return armpmu_map_event(event_map, config);
|
return armpmu_map_hw_event(event_map, config);
|
||||||
case PERF_TYPE_HW_CACHE:
|
case PERF_TYPE_HW_CACHE:
|
||||||
return armpmu_map_cache_event(cache_map, config);
|
return armpmu_map_cache_event(cache_map, config);
|
||||||
case PERF_TYPE_RAW:
|
case PERF_TYPE_RAW:
|
||||||
|
@ -594,6 +579,10 @@ static int armpmu_runtime_suspend(struct device *dev)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const struct dev_pm_ops armpmu_dev_pm_ops = {
|
||||||
|
SET_RUNTIME_PM_OPS(armpmu_runtime_suspend, armpmu_runtime_resume, NULL)
|
||||||
|
};
|
||||||
|
|
||||||
static void __init armpmu_init(struct arm_pmu *armpmu)
|
static void __init armpmu_init(struct arm_pmu *armpmu)
|
||||||
{
|
{
|
||||||
atomic_set(&armpmu->active_events, 0);
|
atomic_set(&armpmu->active_events, 0);
|
||||||
|
@ -624,7 +613,7 @@ int armpmu_register(struct arm_pmu *armpmu, char *name, int type)
|
||||||
#include "perf_event_v6.c"
|
#include "perf_event_v6.c"
|
||||||
#include "perf_event_v7.c"
|
#include "perf_event_v7.c"
|
||||||
|
|
||||||
static struct pmu_hw_events *armpmu_get_cpu_events(void)
|
static struct pmu_hw_events *cpu_pmu_get_cpu_events(void)
|
||||||
{
|
{
|
||||||
return &__get_cpu_var(cpu_hw_events);
|
return &__get_cpu_var(cpu_hw_events);
|
||||||
}
|
}
|
||||||
|
@ -638,7 +627,7 @@ static void __devinit cpu_pmu_init(struct arm_pmu *cpu_pmu)
|
||||||
events->used_mask = per_cpu(used_mask, cpu);
|
events->used_mask = per_cpu(used_mask, cpu);
|
||||||
raw_spin_lock_init(&events->pmu_lock);
|
raw_spin_lock_init(&events->pmu_lock);
|
||||||
}
|
}
|
||||||
cpu_pmu->get_hw_events = armpmu_get_cpu_events;
|
cpu_pmu->get_hw_events = cpu_pmu_get_cpu_events;
|
||||||
|
|
||||||
/* Ensure the PMU has sane values out of reset. */
|
/* Ensure the PMU has sane values out of reset. */
|
||||||
if (cpu_pmu && cpu_pmu->reset)
|
if (cpu_pmu && cpu_pmu->reset)
|
||||||
|
@ -651,8 +640,8 @@ static void __devinit cpu_pmu_init(struct arm_pmu *cpu_pmu)
|
||||||
* UNKNOWN at reset, the PMU must be explicitly reset to avoid reading
|
* UNKNOWN at reset, the PMU must be explicitly reset to avoid reading
|
||||||
* junk values out of them.
|
* junk values out of them.
|
||||||
*/
|
*/
|
||||||
static int __cpuinit pmu_cpu_notify(struct notifier_block *b,
|
static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
|
||||||
unsigned long action, void *hcpu)
|
unsigned long action, void *hcpu)
|
||||||
{
|
{
|
||||||
if ((action & ~CPU_TASKS_FROZEN) != CPU_STARTING)
|
if ((action & ~CPU_TASKS_FROZEN) != CPU_STARTING)
|
||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
|
@ -663,12 +652,8 @@ static int __cpuinit pmu_cpu_notify(struct notifier_block *b,
|
||||||
return NOTIFY_OK;
|
return NOTIFY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct notifier_block __cpuinitdata pmu_cpu_notifier = {
|
static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
|
||||||
.notifier_call = pmu_cpu_notify,
|
.notifier_call = cpu_pmu_notify,
|
||||||
};
|
|
||||||
|
|
||||||
static const struct dev_pm_ops armpmu_dev_pm_ops = {
|
|
||||||
SET_RUNTIME_PM_OPS(armpmu_runtime_suspend, armpmu_runtime_resume, NULL)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -771,7 +756,7 @@ static int __devinit cpu_pmu_device_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
cpu_pmu->plat_device = pdev;
|
cpu_pmu->plat_device = pdev;
|
||||||
cpu_pmu_init(cpu_pmu);
|
cpu_pmu_init(cpu_pmu);
|
||||||
register_cpu_notifier(&pmu_cpu_notifier);
|
register_cpu_notifier(&cpu_pmu_hotplug_notifier);
|
||||||
armpmu_register(cpu_pmu, cpu_pmu->name, PERF_TYPE_RAW);
|
armpmu_register(cpu_pmu, cpu_pmu->name, PERF_TYPE_RAW);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -645,7 +645,7 @@ armv6mpcore_pmu_disable_event(struct hw_perf_event *hwc,
|
||||||
|
|
||||||
static int armv6_map_event(struct perf_event *event)
|
static int armv6_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &armv6_perf_map,
|
return armpmu_map_event(event, &armv6_perf_map,
|
||||||
&armv6_perf_cache_map, 0xFF);
|
&armv6_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,7 +679,7 @@ static struct arm_pmu *__devinit armv6pmu_init(void)
|
||||||
|
|
||||||
static int armv6mpcore_map_event(struct perf_event *event)
|
static int armv6mpcore_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &armv6mpcore_perf_map,
|
return armpmu_map_event(event, &armv6mpcore_perf_map,
|
||||||
&armv6mpcore_perf_cache_map, 0xFF);
|
&armv6mpcore_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1204,31 +1204,31 @@ static void armv7pmu_reset(void *info)
|
||||||
|
|
||||||
static int armv7_a8_map_event(struct perf_event *event)
|
static int armv7_a8_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &armv7_a8_perf_map,
|
return armpmu_map_event(event, &armv7_a8_perf_map,
|
||||||
&armv7_a8_perf_cache_map, 0xFF);
|
&armv7_a8_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int armv7_a9_map_event(struct perf_event *event)
|
static int armv7_a9_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &armv7_a9_perf_map,
|
return armpmu_map_event(event, &armv7_a9_perf_map,
|
||||||
&armv7_a9_perf_cache_map, 0xFF);
|
&armv7_a9_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int armv7_a5_map_event(struct perf_event *event)
|
static int armv7_a5_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &armv7_a5_perf_map,
|
return armpmu_map_event(event, &armv7_a5_perf_map,
|
||||||
&armv7_a5_perf_cache_map, 0xFF);
|
&armv7_a5_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int armv7_a15_map_event(struct perf_event *event)
|
static int armv7_a15_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &armv7_a15_perf_map,
|
return armpmu_map_event(event, &armv7_a15_perf_map,
|
||||||
&armv7_a15_perf_cache_map, 0xFF);
|
&armv7_a15_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int armv7_a7_map_event(struct perf_event *event)
|
static int armv7_a7_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &armv7_a7_perf_map,
|
return armpmu_map_event(event, &armv7_a7_perf_map,
|
||||||
&armv7_a7_perf_cache_map, 0xFF);
|
&armv7_a7_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -430,7 +430,7 @@ xscale1pmu_write_counter(int counter, u32 val)
|
||||||
|
|
||||||
static int xscale_map_event(struct perf_event *event)
|
static int xscale_map_event(struct perf_event *event)
|
||||||
{
|
{
|
||||||
return map_cpu_event(event, &xscale_perf_map,
|
return armpmu_map_event(event, &xscale_perf_map,
|
||||||
&xscale_perf_cache_map, 0xFF);
|
&xscale_perf_cache_map, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue