2010-02-02 22:23:15 +03:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/include/asm/pmu.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ARM_PMU_H__
|
|
|
|
#define __ARM_PMU_H__
|
|
|
|
|
2011-02-08 06:54:36 +03:00
|
|
|
#include <linux/interrupt.h>
|
2011-05-19 13:07:57 +04:00
|
|
|
#include <linux/perf_event.h>
|
2017-10-09 19:09:05 +03:00
|
|
|
#include <linux/platform_device.h>
|
2016-09-09 16:08:26 +03:00
|
|
|
#include <linux/sysfs.h>
|
2014-05-23 21:11:14 +04:00
|
|
|
#include <asm/cputype.h>
|
|
|
|
|
2015-07-06 14:23:53 +03:00
|
|
|
#ifdef CONFIG_ARM_PMU
|
2011-05-19 13:07:57 +04:00
|
|
|
|
2014-05-28 21:08:40 +04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2014-05-29 20:29:51 +04:00
|
|
|
#define PERF_MAP_ALL_UNSUPPORTED \
|
|
|
|
[0 ... PERF_COUNT_HW_MAX - 1] = HW_OP_UNSUPPORTED
|
|
|
|
|
|
|
|
#define PERF_CACHE_MAP_ALL_UNSUPPORTED \
|
|
|
|
[0 ... C(MAX) - 1] = { \
|
|
|
|
[0 ... C(OP_MAX) - 1] = { \
|
|
|
|
[0 ... C(RESULT_MAX) - 1] = CACHE_OP_UNSUPPORTED, \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
2011-05-19 13:07:57 +04:00
|
|
|
/* The events for a given PMU register set. */
|
|
|
|
struct pmu_hw_events {
|
|
|
|
/*
|
|
|
|
* The events that are active on the PMU for the given index.
|
|
|
|
*/
|
2014-05-13 22:08:19 +04:00
|
|
|
struct perf_event *events[ARMPMU_MAX_HWEVENTS];
|
2011-05-19 13:07:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A 1 bit for an index indicates that the counter is being used for
|
|
|
|
* an event. A 0 means that the counter can be used.
|
|
|
|
*/
|
2014-05-13 22:08:19 +04:00
|
|
|
DECLARE_BITMAP(used_mask, ARMPMU_MAX_HWEVENTS);
|
2011-05-19 13:07:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hardware lock to serialize accesses to PMU registers. Needed for the
|
|
|
|
* read/modify/write sequences.
|
|
|
|
*/
|
|
|
|
raw_spinlock_t pmu_lock;
|
2014-05-13 22:46:10 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When using percpu IRQs, we need a percpu dev_id. Place it here as we
|
|
|
|
* already have to allocate this struct per cpu.
|
|
|
|
*/
|
|
|
|
struct arm_pmu *percpu_pmu;
|
2017-03-10 13:46:14 +03:00
|
|
|
|
|
|
|
int irq;
|
2011-05-19 13:07:57 +04:00
|
|
|
};
|
|
|
|
|
2016-09-09 16:08:26 +03:00
|
|
|
enum armpmu_attr_groups {
|
drivers/perf: arm_pmu: expose a cpumask in sysfs
In systems with heterogeneous CPUs, there are multiple logical CPU PMUs,
each of which covers a subset of CPUs in the system. In some cases
userspace needs to know which CPUs a given logical PMU covers, so we'd
like to expose a cpumask under sysfs, similar to what is done for uncore
PMUs.
Unfortunately, prior to commit 00e727bb389359c8 ("perf stat: Balance
opening and reading events"), perf stat only correctly handled a cpumask
holding a single CPU, and only when profiling in system-wide mode. In
other cases, the presence of a cpumask file could cause perf stat to
behave erratically.
Thus, exposing a cpumask file would break older perf binaries in cases
where they would otherwise work.
To avoid this issue while still providing userspace with the information
it needs, this patch exposes a differently-named file (cpus) under
sysfs. New tools can look for this and operate correctly, while older
tools will not be adversely affected by its presence.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2016-09-09 16:08:30 +03:00
|
|
|
ARMPMU_ATTR_GROUP_COMMON,
|
2016-09-09 16:08:26 +03:00
|
|
|
ARMPMU_ATTR_GROUP_EVENTS,
|
|
|
|
ARMPMU_ATTR_GROUP_FORMATS,
|
|
|
|
ARMPMU_NR_ATTR_GROUPS
|
|
|
|
};
|
|
|
|
|
2011-05-19 13:07:57 +04:00
|
|
|
struct arm_pmu {
|
|
|
|
struct pmu pmu;
|
2015-05-13 19:12:25 +03:00
|
|
|
cpumask_t supported_cpus;
|
2012-07-06 18:45:00 +04:00
|
|
|
char *name;
|
2018-05-10 13:35:15 +03:00
|
|
|
irqreturn_t (*handle_irq)(struct arm_pmu *pmu);
|
2012-07-30 15:00:02 +04:00
|
|
|
void (*enable)(struct perf_event *event);
|
|
|
|
void (*disable)(struct perf_event *event);
|
2011-05-19 13:07:57 +04:00
|
|
|
int (*get_event_idx)(struct pmu_hw_events *hw_events,
|
2012-07-30 15:00:02 +04:00
|
|
|
struct perf_event *event);
|
2014-02-08 01:01:22 +04:00
|
|
|
void (*clear_event_idx)(struct pmu_hw_events *hw_events,
|
|
|
|
struct perf_event *event);
|
2011-05-19 13:07:57 +04:00
|
|
|
int (*set_event_filter)(struct hw_perf_event *evt,
|
|
|
|
struct perf_event_attr *attr);
|
2018-07-10 11:57:59 +03:00
|
|
|
u64 (*read_counter)(struct perf_event *event);
|
|
|
|
void (*write_counter)(struct perf_event *event, u64 val);
|
2012-07-30 15:00:02 +04:00
|
|
|
void (*start)(struct arm_pmu *);
|
|
|
|
void (*stop)(struct arm_pmu *);
|
2011-05-19 13:07:57 +04:00
|
|
|
void (*reset)(void *);
|
|
|
|
int (*map_event)(struct perf_event *event);
|
|
|
|
int num_events;
|
2016-01-14 07:36:26 +03:00
|
|
|
bool secure_access; /* 32-bit ARM only */
|
2016-04-21 15:58:44 +03:00
|
|
|
#define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40
|
|
|
|
DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2011-05-19 13:07:57 +04:00
|
|
|
struct platform_device *plat_device;
|
2014-05-13 22:36:31 +04:00
|
|
|
struct pmu_hw_events __percpu *hw_events;
|
2016-08-17 20:14:20 +03:00
|
|
|
struct hlist_node node;
|
2016-02-23 21:22:39 +03:00
|
|
|
struct notifier_block cpu_pm_nb;
|
2016-09-09 16:08:26 +03:00
|
|
|
/* the attr_groups array must be NULL-terminated */
|
|
|
|
const struct attribute_group *attr_groups[ARMPMU_NR_ATTR_GROUPS + 1];
|
2017-04-11 11:39:55 +03:00
|
|
|
|
|
|
|
/* Only to be used by ACPI probing code */
|
|
|
|
unsigned long acpi_cpuid;
|
2011-05-19 13:07:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
|
|
|
|
|
2012-07-30 15:00:02 +04:00
|
|
|
u64 armpmu_event_update(struct perf_event *event);
|
2011-05-19 13:07:57 +04:00
|
|
|
|
2012-07-30 15:00:02 +04:00
|
|
|
int armpmu_event_set_period(struct perf_event *event);
|
2011-05-19 13:07:57 +04:00
|
|
|
|
2012-07-29 15:36:28 +04:00
|
|
|
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);
|
|
|
|
|
2017-04-11 11:39:45 +03:00
|
|
|
typedef int (*armpmu_init_fn)(struct arm_pmu *);
|
|
|
|
|
2014-05-23 21:11:14 +04:00
|
|
|
struct pmu_probe_info {
|
|
|
|
unsigned int cpuid;
|
|
|
|
unsigned int mask;
|
2017-04-11 11:39:45 +03:00
|
|
|
armpmu_init_fn init;
|
2014-05-23 21:11:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PMU_PROBE(_cpuid, _mask, _fn) \
|
|
|
|
{ \
|
|
|
|
.cpuid = (_cpuid), \
|
|
|
|
.mask = (_mask), \
|
|
|
|
.init = (_fn), \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ARM_PMU_PROBE(_cpuid, _fn) \
|
|
|
|
PMU_PROBE(_cpuid, ARM_CPU_PART_MASK, _fn)
|
|
|
|
|
|
|
|
#define ARM_PMU_XSCALE_MASK ((0xff << 24) | ARM_CPU_XSCALE_ARCH_MASK)
|
|
|
|
|
|
|
|
#define XSCALE_PMU_PROBE(_version, _fn) \
|
|
|
|
PMU_PROBE(ARM_CPU_IMP_INTEL << 24 | _version, ARM_PMU_XSCALE_MASK, _fn)
|
|
|
|
|
2015-05-26 19:23:35 +03:00
|
|
|
int arm_pmu_device_probe(struct platform_device *pdev,
|
|
|
|
const struct of_device_id *of_table,
|
|
|
|
const struct pmu_probe_info *probe_table);
|
|
|
|
|
2017-04-11 11:39:55 +03:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
int arm_pmu_acpi_probe(armpmu_init_fn init_fn);
|
|
|
|
#else
|
|
|
|
static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; }
|
|
|
|
#endif
|
|
|
|
|
2017-04-11 11:39:53 +03:00
|
|
|
/* Internal functions only for core arm_pmu code */
|
|
|
|
struct arm_pmu *armpmu_alloc(void);
|
2018-02-05 19:41:58 +03:00
|
|
|
struct arm_pmu *armpmu_alloc_atomic(void);
|
2017-04-11 11:39:53 +03:00
|
|
|
void armpmu_free(struct arm_pmu *pmu);
|
|
|
|
int armpmu_register(struct arm_pmu *pmu);
|
2017-10-09 19:09:05 +03:00
|
|
|
int armpmu_request_irq(int irq, int cpu);
|
|
|
|
void armpmu_free_irq(int irq, int cpu);
|
2017-04-11 11:39:53 +03:00
|
|
|
|
2016-09-15 01:32:31 +03:00
|
|
|
#define ARMV8_PMU_PDEV_NAME "armv8-pmu"
|
|
|
|
|
2015-07-06 14:23:53 +03:00
|
|
|
#endif /* CONFIG_ARM_PMU */
|
2011-05-19 13:07:57 +04:00
|
|
|
|
2010-02-02 22:23:15 +03:00
|
|
|
#endif /* __ARM_PMU_H__ */
|