2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2010-02-03 03:23:15 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/include/asm/pmu.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ARM_PMU_H__
|
|
|
|
#define __ARM_PMU_H__
|
|
|
|
|
2011-02-08 11:54:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
2011-05-19 17:07:57 +08:00
|
|
|
#include <linux/perf_event.h>
|
2017-10-10 00:09:05 +08:00
|
|
|
#include <linux/platform_device.h>
|
2016-09-09 21:08:26 +08:00
|
|
|
#include <linux/sysfs.h>
|
2014-05-24 01:11:14 +08:00
|
|
|
#include <asm/cputype.h>
|
|
|
|
|
2015-07-06 19:23:53 +08:00
|
|
|
#ifdef CONFIG_ARM_PMU
|
2011-05-19 17:07:57 +08:00
|
|
|
|
2014-05-29 01:08:40 +08:00
|
|
|
/*
|
|
|
|
* The ARMv7 CPU PMU supports up to 32 event counters.
|
|
|
|
*/
|
|
|
|
#define ARMPMU_MAX_HWEVENTS 32
|
|
|
|
|
2018-07-10 16:58:00 +08:00
|
|
|
/*
|
|
|
|
* ARM PMU hw_event flags
|
|
|
|
*/
|
|
|
|
/* Event uses a 64bit counter */
|
|
|
|
#define ARMPMU_EVT_64BIT 1
|
|
|
|
|
2014-05-29 01:08:40 +08:00
|
|
|
#define HW_OP_UNSUPPORTED 0xFFFF
|
|
|
|
#define C(_x) PERF_COUNT_HW_CACHE_##_x
|
|
|
|
#define CACHE_OP_UNSUPPORTED 0xFFFF
|
|
|
|
|
2014-05-30 00:29:51 +08: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 17:07:57 +08: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-14 02:08:19 +08:00
|
|
|
struct perf_event *events[ARMPMU_MAX_HWEVENTS];
|
2011-05-19 17:07:57 +08: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-14 02:08:19 +08:00
|
|
|
DECLARE_BITMAP(used_mask, ARMPMU_MAX_HWEVENTS);
|
2011-05-19 17:07:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hardware lock to serialize accesses to PMU registers. Needed for the
|
|
|
|
* read/modify/write sequences.
|
|
|
|
*/
|
|
|
|
raw_spinlock_t pmu_lock;
|
2014-05-14 02:46:10 +08: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 18:46:14 +08:00
|
|
|
|
|
|
|
int irq;
|
2011-05-19 17:07:57 +08:00
|
|
|
};
|
|
|
|
|
2016-09-09 21:08:26 +08: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 21:08:30 +08:00
|
|
|
ARMPMU_ATTR_GROUP_COMMON,
|
2016-09-09 21:08:26 +08:00
|
|
|
ARMPMU_ATTR_GROUP_EVENTS,
|
|
|
|
ARMPMU_ATTR_GROUP_FORMATS,
|
2020-09-22 13:53:45 +08:00
|
|
|
ARMPMU_ATTR_GROUP_CAPS,
|
2016-09-09 21:08:26 +08:00
|
|
|
ARMPMU_NR_ATTR_GROUPS
|
|
|
|
};
|
|
|
|
|
2011-05-19 17:07:57 +08:00
|
|
|
struct arm_pmu {
|
|
|
|
struct pmu pmu;
|
2015-05-14 00:12:25 +08:00
|
|
|
cpumask_t supported_cpus;
|
2012-07-06 22:45:00 +08:00
|
|
|
char *name;
|
2020-03-03 02:17:52 +08:00
|
|
|
int pmuver;
|
2018-05-10 18:35:15 +08:00
|
|
|
irqreturn_t (*handle_irq)(struct arm_pmu *pmu);
|
2012-07-30 19:00:02 +08:00
|
|
|
void (*enable)(struct perf_event *event);
|
|
|
|
void (*disable)(struct perf_event *event);
|
2011-05-19 17:07:57 +08:00
|
|
|
int (*get_event_idx)(struct pmu_hw_events *hw_events,
|
2012-07-30 19:00:02 +08:00
|
|
|
struct perf_event *event);
|
2014-02-08 05:01:22 +08:00
|
|
|
void (*clear_event_idx)(struct pmu_hw_events *hw_events,
|
|
|
|
struct perf_event *event);
|
2011-05-19 17:07:57 +08:00
|
|
|
int (*set_event_filter)(struct hw_perf_event *evt,
|
|
|
|
struct perf_event_attr *attr);
|
2018-07-10 16:57:59 +08:00
|
|
|
u64 (*read_counter)(struct perf_event *event);
|
|
|
|
void (*write_counter)(struct perf_event *event, u64 val);
|
2012-07-30 19:00:02 +08:00
|
|
|
void (*start)(struct arm_pmu *);
|
|
|
|
void (*stop)(struct arm_pmu *);
|
2011-05-19 17:07:57 +08:00
|
|
|
void (*reset)(void *);
|
|
|
|
int (*map_event)(struct perf_event *event);
|
2018-10-05 20:24:36 +08:00
|
|
|
int (*filter_match)(struct perf_event *event);
|
2011-05-19 17:07:57 +08:00
|
|
|
int num_events;
|
2016-01-14 12:36:26 +08:00
|
|
|
bool secure_access; /* 32-bit ARM only */
|
2018-10-05 20:28:07 +08:00
|
|
|
#define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40
|
2016-04-21 20:58:44 +08:00
|
|
|
DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2018-10-05 20:28:07 +08:00
|
|
|
#define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE 0x4000
|
|
|
|
DECLARE_BITMAP(pmceid_ext_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2011-05-19 17:07:57 +08:00
|
|
|
struct platform_device *plat_device;
|
2014-05-14 02:36:31 +08:00
|
|
|
struct pmu_hw_events __percpu *hw_events;
|
2016-08-18 01:14:20 +08:00
|
|
|
struct hlist_node node;
|
2016-02-24 02:22:39 +08:00
|
|
|
struct notifier_block cpu_pm_nb;
|
2016-09-09 21:08:26 +08:00
|
|
|
/* the attr_groups array must be NULL-terminated */
|
|
|
|
const struct attribute_group *attr_groups[ARMPMU_NR_ATTR_GROUPS + 1];
|
2020-09-22 13:53:45 +08:00
|
|
|
/* store the PMMIR_EL1 to expose slots */
|
|
|
|
u64 reg_pmmir;
|
2017-04-11 16:39:55 +08:00
|
|
|
|
|
|
|
/* Only to be used by ACPI probing code */
|
|
|
|
unsigned long acpi_cpuid;
|
2011-05-19 17:07:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
|
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
u64 armpmu_event_update(struct perf_event *event);
|
2011-05-19 17:07:57 +08:00
|
|
|
|
2012-07-30 19:00:02 +08:00
|
|
|
int armpmu_event_set_period(struct perf_event *event);
|
2011-05-19 17:07:57 +08:00
|
|
|
|
2012-07-29 19:36:28 +08: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 16:39:45 +08:00
|
|
|
typedef int (*armpmu_init_fn)(struct arm_pmu *);
|
|
|
|
|
2014-05-24 01:11:14 +08:00
|
|
|
struct pmu_probe_info {
|
|
|
|
unsigned int cpuid;
|
|
|
|
unsigned int mask;
|
2017-04-11 16:39:45 +08:00
|
|
|
armpmu_init_fn init;
|
2014-05-24 01:11:14 +08: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-27 00:23:35 +08: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 16:39:55 +08: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 16:39:53 +08:00
|
|
|
/* Internal functions only for core arm_pmu code */
|
|
|
|
struct arm_pmu *armpmu_alloc(void);
|
2018-02-06 00:41:58 +08:00
|
|
|
struct arm_pmu *armpmu_alloc_atomic(void);
|
2017-04-11 16:39:53 +08:00
|
|
|
void armpmu_free(struct arm_pmu *pmu);
|
|
|
|
int armpmu_register(struct arm_pmu *pmu);
|
2017-10-10 00:09:05 +08:00
|
|
|
int armpmu_request_irq(int irq, int cpu);
|
|
|
|
void armpmu_free_irq(int irq, int cpu);
|
2017-04-11 16:39:53 +08:00
|
|
|
|
2016-09-15 06:32:31 +08:00
|
|
|
#define ARMV8_PMU_PDEV_NAME "armv8-pmu"
|
|
|
|
|
2015-07-06 19:23:53 +08:00
|
|
|
#endif /* CONFIG_ARM_PMU */
|
2011-05-19 17:07:57 +08:00
|
|
|
|
2019-06-27 05:37:17 +08:00
|
|
|
#define ARMV8_SPE_PDEV_NAME "arm,spe-v1"
|
|
|
|
|
2010-02-03 03:23:15 +08:00
|
|
|
#endif /* __ARM_PMU_H__ */
|