2019-06-04 08:11:33 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2010-02-02 19:23:15 +00: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 03:54:36 +00:00
|
|
|
#include <linux/interrupt.h>
|
2011-05-19 09:07:57 +00:00
|
|
|
#include <linux/perf_event.h>
|
2017-10-09 16:09:05 +00:00
|
|
|
#include <linux/platform_device.h>
|
2016-09-09 13:08:26 +00:00
|
|
|
#include <linux/sysfs.h>
|
2014-05-23 17:11:14 +00:00
|
|
|
#include <asm/cputype.h>
|
|
|
|
|
2015-07-06 11:23:53 +00:00
|
|
|
#ifdef CONFIG_ARM_PMU
|
2011-05-19 09:07:57 +00:00
|
|
|
|
2014-05-28 17:08:40 +00:00
|
|
|
/*
|
|
|
|
* The ARMv7 CPU PMU supports up to 32 event counters.
|
|
|
|
*/
|
|
|
|
#define ARMPMU_MAX_HWEVENTS 32
|
|
|
|
|
2018-07-10 08:58:00 +00:00
|
|
|
/*
|
|
|
|
* ARM PMU hw_event flags
|
|
|
|
*/
|
2022-09-07 09:19:23 +00:00
|
|
|
#define ARMPMU_EVT_64BIT 0x00001 /* Event uses a 64bit counter */
|
|
|
|
#define ARMPMU_EVT_47BIT 0x00002 /* Event uses a 47bit counter */
|
|
|
|
|
|
|
|
static_assert((PERF_EVENT_FLAG_ARCH & ARMPMU_EVT_64BIT) == ARMPMU_EVT_64BIT);
|
|
|
|
static_assert((PERF_EVENT_FLAG_ARCH & ARMPMU_EVT_47BIT) == ARMPMU_EVT_47BIT);
|
2018-07-10 08:58:00 +00:00
|
|
|
|
2014-05-28 17:08:40 +00:00
|
|
|
#define HW_OP_UNSUPPORTED 0xFFFF
|
|
|
|
#define C(_x) PERF_COUNT_HW_CACHE_##_x
|
|
|
|
#define CACHE_OP_UNSUPPORTED 0xFFFF
|
|
|
|
|
2014-05-29 16:29:51 +00: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 09:07:57 +00: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 18:08:19 +00:00
|
|
|
struct perf_event *events[ARMPMU_MAX_HWEVENTS];
|
2011-05-19 09:07:57 +00: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 18:08:19 +00:00
|
|
|
DECLARE_BITMAP(used_mask, ARMPMU_MAX_HWEVENTS);
|
2011-05-19 09:07:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hardware lock to serialize accesses to PMU registers. Needed for the
|
|
|
|
* read/modify/write sequences.
|
|
|
|
*/
|
|
|
|
raw_spinlock_t pmu_lock;
|
2014-05-13 18:46:10 +00: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 10:46:14 +00:00
|
|
|
|
|
|
|
int irq;
|
2011-05-19 09:07:57 +00:00
|
|
|
};
|
|
|
|
|
2016-09-09 13:08:26 +00: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 13:08:30 +00:00
|
|
|
ARMPMU_ATTR_GROUP_COMMON,
|
2016-09-09 13:08:26 +00:00
|
|
|
ARMPMU_ATTR_GROUP_EVENTS,
|
|
|
|
ARMPMU_ATTR_GROUP_FORMATS,
|
2020-09-22 05:53:45 +00:00
|
|
|
ARMPMU_ATTR_GROUP_CAPS,
|
2016-09-09 13:08:26 +00:00
|
|
|
ARMPMU_NR_ATTR_GROUPS
|
|
|
|
};
|
|
|
|
|
2011-05-19 09:07:57 +00:00
|
|
|
struct arm_pmu {
|
|
|
|
struct pmu pmu;
|
2015-05-13 16:12:25 +00:00
|
|
|
cpumask_t supported_cpus;
|
2012-07-06 14:45:00 +00:00
|
|
|
char *name;
|
2020-03-02 18:17:52 +00:00
|
|
|
int pmuver;
|
2018-05-10 10:35:15 +00:00
|
|
|
irqreturn_t (*handle_irq)(struct arm_pmu *pmu);
|
2012-07-30 11:00:02 +00:00
|
|
|
void (*enable)(struct perf_event *event);
|
|
|
|
void (*disable)(struct perf_event *event);
|
2011-05-19 09:07:57 +00:00
|
|
|
int (*get_event_idx)(struct pmu_hw_events *hw_events,
|
2012-07-30 11:00:02 +00:00
|
|
|
struct perf_event *event);
|
2014-02-07 21:01:22 +00:00
|
|
|
void (*clear_event_idx)(struct pmu_hw_events *hw_events,
|
|
|
|
struct perf_event *event);
|
2011-05-19 09:07:57 +00:00
|
|
|
int (*set_event_filter)(struct hw_perf_event *evt,
|
|
|
|
struct perf_event_attr *attr);
|
2018-07-10 08:57:59 +00:00
|
|
|
u64 (*read_counter)(struct perf_event *event);
|
|
|
|
void (*write_counter)(struct perf_event *event, u64 val);
|
2012-07-30 11:00:02 +00:00
|
|
|
void (*start)(struct arm_pmu *);
|
|
|
|
void (*stop)(struct arm_pmu *);
|
2011-05-19 09:07:57 +00:00
|
|
|
void (*reset)(void *);
|
|
|
|
int (*map_event)(struct perf_event *event);
|
perf: Rewrite core context handling
There have been various issues and limitations with the way perf uses
(task) contexts to track events. Most notable is the single hardware
PMU task context, which has resulted in a number of yucky things (both
proposed and merged).
Notably:
- HW breakpoint PMU
- ARM big.little PMU / Intel ADL PMU
- Intel Branch Monitoring PMU
- AMD IBS PMU
- S390 cpum_cf PMU
- PowerPC trace_imc PMU
*Current design:*
Currently we have a per task and per cpu perf_event_contexts:
task_struct::perf_events_ctxp[] <-> perf_event_context <-> perf_cpu_context
^ | ^ | ^
`---------------------------------' | `--> pmu ---'
v ^
perf_event ------'
Each task has an array of pointers to a perf_event_context. Each
perf_event_context has a direct relation to a PMU and a group of
events for that PMU. The task related perf_event_context's have a
pointer back to that task.
Each PMU has a per-cpu pointer to a per-cpu perf_cpu_context, which
includes a perf_event_context, which again has a direct relation to
that PMU, and a group of events for that PMU.
The perf_cpu_context also tracks which task context is currently
associated with that CPU and includes a few other things like the
hrtimer for rotation etc.
Each perf_event is then associated with its PMU and one
perf_event_context.
*Proposed design:*
New design proposed by this patch reduce to a single task context and
a single CPU context but adds some intermediate data-structures:
task_struct::perf_event_ctxp -> perf_event_context <- perf_cpu_context
^ | ^ ^
`---------------------------' | |
| | perf_cpu_pmu_context <--.
| `----. ^ |
| | | |
| v v |
| ,--> perf_event_pmu_context |
| | |
| | |
v v |
perf_event ---> pmu ----------------'
With the new design, perf_event_context will hold all events for all
pmus in the (respective pinned/flexible) rbtrees. This can be achieved
by adding pmu to rbtree key:
{cpu, pmu, cgroup, group_index}
Each perf_event_context carries a list of perf_event_pmu_context which
is used to hold per-pmu-per-context state. For example, it keeps track
of currently active events for that pmu, a pmu specific task_ctx_data,
a flag to tell whether rotation is required or not etc.
Additionally, perf_cpu_pmu_context is used to hold per-pmu-per-cpu
state like hrtimer details to drive the event rotation, a pointer to
perf_event_pmu_context of currently running task and some other
ancillary information.
Each perf_event is associated to it's pmu, perf_event_context and
perf_event_pmu_context.
Further optimizations to current implementation are possible. For
example, ctx_resched() can be optimized to reschedule only single pmu
events.
Much thanks to Ravi for picking this up and pushing it towards
completion.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Co-developed-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20221008062424.313-1-ravi.bangoria@amd.com
2022-10-08 06:24:24 +00:00
|
|
|
bool (*filter)(struct pmu *pmu, int cpu);
|
2011-05-19 09:07:57 +00:00
|
|
|
int num_events;
|
2016-01-14 04:36:26 +00:00
|
|
|
bool secure_access; /* 32-bit ARM only */
|
2018-10-05 12:28:07 +00:00
|
|
|
#define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40
|
2016-04-21 12:58:44 +00:00
|
|
|
DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2018-10-05 12:28:07 +00:00
|
|
|
#define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE 0x4000
|
|
|
|
DECLARE_BITMAP(pmceid_ext_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2011-05-19 09:07:57 +00:00
|
|
|
struct platform_device *plat_device;
|
2014-05-13 18:36:31 +00:00
|
|
|
struct pmu_hw_events __percpu *hw_events;
|
2016-08-17 17:14:20 +00:00
|
|
|
struct hlist_node node;
|
2016-02-23 18:22:39 +00:00
|
|
|
struct notifier_block cpu_pm_nb;
|
2016-09-09 13:08:26 +00:00
|
|
|
/* the attr_groups array must be NULL-terminated */
|
|
|
|
const struct attribute_group *attr_groups[ARMPMU_NR_ATTR_GROUPS + 1];
|
2020-09-22 05:53:45 +00:00
|
|
|
/* store the PMMIR_EL1 to expose slots */
|
|
|
|
u64 reg_pmmir;
|
2017-04-11 08:39:55 +00:00
|
|
|
|
|
|
|
/* Only to be used by ACPI probing code */
|
|
|
|
unsigned long acpi_cpuid;
|
2011-05-19 09:07:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
|
|
|
|
|
2012-07-30 11:00:02 +00:00
|
|
|
u64 armpmu_event_update(struct perf_event *event);
|
2011-05-19 09:07:57 +00:00
|
|
|
|
2012-07-30 11:00:02 +00:00
|
|
|
int armpmu_event_set_period(struct perf_event *event);
|
2011-05-19 09:07:57 +00:00
|
|
|
|
2012-07-29 11:36:28 +00: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 08:39:45 +00:00
|
|
|
typedef int (*armpmu_init_fn)(struct arm_pmu *);
|
|
|
|
|
2014-05-23 17:11:14 +00:00
|
|
|
struct pmu_probe_info {
|
|
|
|
unsigned int cpuid;
|
|
|
|
unsigned int mask;
|
2017-04-11 08:39:45 +00:00
|
|
|
armpmu_init_fn init;
|
2014-05-23 17:11:14 +00: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 16:23:35 +00: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 08:39:55 +00: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
|
|
|
|
|
2021-09-19 13:09:49 +00:00
|
|
|
#ifdef CONFIG_KVM
|
|
|
|
void kvm_host_pmu_init(struct arm_pmu *pmu);
|
|
|
|
#else
|
|
|
|
#define kvm_host_pmu_init(x) do { } while(0)
|
|
|
|
#endif
|
|
|
|
|
2017-04-11 08:39:53 +00:00
|
|
|
/* Internal functions only for core arm_pmu code */
|
|
|
|
struct arm_pmu *armpmu_alloc(void);
|
2018-02-05 16:41:58 +00:00
|
|
|
struct arm_pmu *armpmu_alloc_atomic(void);
|
2017-04-11 08:39:53 +00:00
|
|
|
void armpmu_free(struct arm_pmu *pmu);
|
|
|
|
int armpmu_register(struct arm_pmu *pmu);
|
2017-10-09 16:09:05 +00:00
|
|
|
int armpmu_request_irq(int irq, int cpu);
|
|
|
|
void armpmu_free_irq(int irq, int cpu);
|
2017-04-11 08:39:53 +00:00
|
|
|
|
2016-09-14 22:32:31 +00:00
|
|
|
#define ARMV8_PMU_PDEV_NAME "armv8-pmu"
|
|
|
|
|
2015-07-06 11:23:53 +00:00
|
|
|
#endif /* CONFIG_ARM_PMU */
|
2011-05-19 09:07:57 +00:00
|
|
|
|
2019-06-26 21:37:17 +00:00
|
|
|
#define ARMV8_SPE_PDEV_NAME "arm,spe-v1"
|
|
|
|
|
2010-02-02 19:23:15 +00:00
|
|
|
#endif /* __ARM_PMU_H__ */
|