2019-06-03 05:44:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-03-05 11:49:32 +00:00
|
|
|
/*
|
2018-10-05 12:31:10 +00:00
|
|
|
* ARMv8 PMUv3 Performance Events handling code.
|
2012-03-05 11:49:32 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 ARM Limited
|
|
|
|
* Author: Will Deacon <will.deacon@arm.com>
|
|
|
|
*
|
|
|
|
* This code is based heavily on the ARMv7 perf event code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/irq_regs.h>
|
2016-03-24 16:01:16 +00:00
|
|
|
#include <asm/perf_event.h>
|
2016-01-25 17:31:13 +00:00
|
|
|
#include <asm/virt.h>
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2020-07-16 05:11:27 +00:00
|
|
|
#include <clocksource/arm_arch_timer.h>
|
|
|
|
|
2016-09-14 22:32:29 +00:00
|
|
|
#include <linux/acpi.h>
|
2023-12-11 16:13:14 +00:00
|
|
|
#include <linux/bitfield.h>
|
arm64: perf: Add cap_user_time aarch64
It is useful to get the running time of a thread. Doing so in an
efficient manner can be important for performance of user applications.
Avoiding system calls in `clock_gettime` when handling
CLOCK_THREAD_CPUTIME_ID is important. Other clocks are handled in the
VDSO, but CLOCK_THREAD_CPUTIME_ID falls back on the system call.
CLOCK_THREAD_CPUTIME_ID is not handled in the VDSO since it would have
costs associated with maintaining updated user space accessible time
offsets. These offsets have to be updated everytime the a thread is
scheduled/descheduled. However, for programs regularly checking the
running time of a thread, this is a performance improvement.
This patch takes a middle ground, and adds support for cap_user_time an
optional feature of the perf_event API. This way costs are only
incurred when the perf_event api is enabled. This is done the same way
as it is in x86.
Ultimately this allows calculating the thread running time in userspace
on aarch64 as follows (adapted from perf_event_open manpage):
u32 seq, time_mult, time_shift;
u64 running, count, time_offset, quot, rem, delta;
struct perf_event_mmap_page *pc;
pc = buf; // buf is the perf event mmaped page as documented in the API.
if (pc->cap_usr_time) {
do {
seq = pc->lock;
barrier();
running = pc->time_running;
count = readCNTVCT_EL0(); // Read ARM hardware clock.
time_offset = pc->time_offset;
time_mult = pc->time_mult;
time_shift = pc->time_shift;
barrier();
} while (pc->lock != seq);
quot = (count >> time_shift);
rem = count & (((u64)1 << time_shift) - 1);
delta = time_offset + quot * time_mult +
((rem * time_mult) >> time_shift);
running += delta;
// running now has the current nanosecond level thread time.
}
Summary of changes in the patch:
For aarch64 systems, make arch_perf_update_userpage update the timing
information stored in the perf_event page. Requiring the following
calculations:
- Calculate the appropriate time_mult, and time_shift factors to convert
ticks to nano seconds for the current clock frequency.
- Adjust the mult and shift factors to avoid shift factors of 32 bits.
(possibly unnecessary)
- The time_offset userspace should apply when doing calculations:
negative the current sched time (now), because time_running and
time_enabled fields of the perf_event page have just been updated.
Toggle bits to appropriate values:
- Enable cap_user_time
Signed-off-by: Michael O'Farrell <micpof@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2018-07-30 20:14:34 +00:00
|
|
|
#include <linux/clocksource.h>
|
2015-10-02 09:55:03 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/perf/arm_pmu.h>
|
2023-03-17 19:50:20 +00:00
|
|
|
#include <linux/perf/arm_pmuv3.h>
|
2015-10-02 09:55:03 +00:00
|
|
|
#include <linux/platform_device.h>
|
2020-07-16 05:11:26 +00:00
|
|
|
#include <linux/sched_clock.h>
|
2019-08-20 15:57:45 +00:00
|
|
|
#include <linux/smp.h>
|
2023-05-19 17:18:42 +00:00
|
|
|
#include <linux/nmi.h>
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2015-10-02 09:55:04 +00:00
|
|
|
/* ARMv8 Cortex-A53 specific event types. */
|
2016-04-21 12:58:41 +00:00
|
|
|
#define ARMV8_A53_PERFCTR_PREF_LINEFILL 0xC2
|
2015-10-02 09:55:04 +00:00
|
|
|
|
2016-02-18 16:50:11 +00:00
|
|
|
/* ARMv8 Cavium ThunderX specific event types. */
|
2016-04-21 12:58:41 +00:00
|
|
|
#define ARMV8_THUNDER_PERFCTR_L1D_CACHE_MISS_ST 0xE9
|
|
|
|
#define ARMV8_THUNDER_PERFCTR_L1D_CACHE_PREF_ACCESS 0xEA
|
|
|
|
#define ARMV8_THUNDER_PERFCTR_L1D_CACHE_PREF_MISS 0xEB
|
|
|
|
#define ARMV8_THUNDER_PERFCTR_L1I_CACHE_PREF_ACCESS 0xEC
|
|
|
|
#define ARMV8_THUNDER_PERFCTR_L1I_CACHE_PREF_MISS 0xED
|
2015-10-02 09:55:05 +00:00
|
|
|
|
2016-09-14 22:32:30 +00:00
|
|
|
/*
|
|
|
|
* ARMv8 Architectural defined events, not all of these may
|
2018-10-05 12:28:07 +00:00
|
|
|
* be supported on any given implementation. Unsupported events will
|
|
|
|
* be disabled at run-time based on the PMCEID registers.
|
2016-09-14 22:32:30 +00:00
|
|
|
*/
|
2012-03-05 11:49:32 +00:00
|
|
|
static const unsigned armv8_pmuv3_perf_map[PERF_COUNT_HW_MAX] = {
|
2015-07-21 10:36:39 +00:00
|
|
|
PERF_MAP_ALL_UNSUPPORTED,
|
2016-04-21 12:58:41 +00:00
|
|
|
[PERF_COUNT_HW_CPU_CYCLES] = ARMV8_PMUV3_PERFCTR_CPU_CYCLES,
|
|
|
|
[PERF_COUNT_HW_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_INST_RETIRED,
|
|
|
|
[PERF_COUNT_HW_CACHE_REFERENCES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE,
|
|
|
|
[PERF_COUNT_HW_CACHE_MISSES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL,
|
|
|
|
[PERF_COUNT_HW_BRANCH_MISSES] = ARMV8_PMUV3_PERFCTR_BR_MIS_PRED,
|
2016-09-14 22:32:30 +00:00
|
|
|
[PERF_COUNT_HW_BUS_CYCLES] = ARMV8_PMUV3_PERFCTR_BUS_CYCLES,
|
|
|
|
[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = ARMV8_PMUV3_PERFCTR_STALL_FRONTEND,
|
|
|
|
[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = ARMV8_PMUV3_PERFCTR_STALL_BACKEND,
|
2012-03-05 11:49:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned armv8_pmuv3_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
|
2015-07-21 10:36:39 +00:00
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
2016-04-21 12:58:41 +00:00
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_L1D_CACHE,
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL,
|
2015-07-21 10:36:39 +00:00
|
|
|
|
2016-09-14 22:32:30 +00:00
|
|
|
[C(L1I)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_L1I_CACHE,
|
|
|
|
[C(L1I)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L1I_CACHE_REFILL,
|
|
|
|
|
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L1D_TLB_REFILL,
|
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_L1D_TLB,
|
|
|
|
|
|
|
|
[C(ITLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L1I_TLB_REFILL,
|
|
|
|
[C(ITLB)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_L1I_TLB,
|
|
|
|
|
2020-08-11 05:35:05 +00:00
|
|
|
[C(LL)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_LL_CACHE_MISS_RD,
|
|
|
|
[C(LL)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_LL_CACHE_RD,
|
|
|
|
|
2016-04-21 12:58:41 +00:00
|
|
|
[C(BPU)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_BR_PRED,
|
|
|
|
[C(BPU)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_BR_MIS_PRED,
|
2012-03-05 11:49:32 +00:00
|
|
|
};
|
|
|
|
|
2015-10-02 09:55:04 +00:00
|
|
|
static const unsigned armv8_a53_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
|
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
2016-04-21 12:58:41 +00:00
|
|
|
[C(L1D)][C(OP_PREFETCH)][C(RESULT_MISS)] = ARMV8_A53_PERFCTR_PREF_LINEFILL,
|
2015-10-02 09:55:04 +00:00
|
|
|
|
2017-07-25 16:27:36 +00:00
|
|
|
[C(NODE)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_BUS_ACCESS_RD,
|
|
|
|
[C(NODE)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_BUS_ACCESS_WR,
|
2015-10-02 09:55:04 +00:00
|
|
|
};
|
|
|
|
|
2015-10-02 09:55:05 +00:00
|
|
|
static const unsigned armv8_a57_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
|
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
2016-04-21 12:58:41 +00:00
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_RD,
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_REFILL_RD,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_WR,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_REFILL_WR,
|
2015-10-02 09:55:05 +00:00
|
|
|
|
2016-04-21 12:58:41 +00:00
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_REFILL_RD,
|
|
|
|
[C(DTLB)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_REFILL_WR,
|
2015-10-02 09:55:05 +00:00
|
|
|
|
2017-07-25 16:27:36 +00:00
|
|
|
[C(NODE)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_BUS_ACCESS_RD,
|
|
|
|
[C(NODE)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_BUS_ACCESS_WR,
|
2015-10-02 09:55:05 +00:00
|
|
|
};
|
|
|
|
|
2017-08-09 16:46:38 +00:00
|
|
|
static const unsigned armv8_a73_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
|
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_RD,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_WR,
|
|
|
|
};
|
|
|
|
|
2016-02-18 16:50:11 +00:00
|
|
|
static const unsigned armv8_thunder_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
|
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
2016-04-21 12:58:41 +00:00
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_RD,
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_REFILL_RD,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_WR,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV8_THUNDER_PERFCTR_L1D_CACHE_MISS_ST,
|
|
|
|
[C(L1D)][C(OP_PREFETCH)][C(RESULT_ACCESS)] = ARMV8_THUNDER_PERFCTR_L1D_CACHE_PREF_ACCESS,
|
|
|
|
[C(L1D)][C(OP_PREFETCH)][C(RESULT_MISS)] = ARMV8_THUNDER_PERFCTR_L1D_CACHE_PREF_MISS,
|
|
|
|
|
|
|
|
[C(L1I)][C(OP_PREFETCH)][C(RESULT_ACCESS)] = ARMV8_THUNDER_PERFCTR_L1I_CACHE_PREF_ACCESS,
|
|
|
|
[C(L1I)][C(OP_PREFETCH)][C(RESULT_MISS)] = ARMV8_THUNDER_PERFCTR_L1I_CACHE_PREF_MISS,
|
|
|
|
|
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_RD,
|
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_REFILL_RD,
|
|
|
|
[C(DTLB)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_WR,
|
|
|
|
[C(DTLB)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_REFILL_WR,
|
2015-10-02 09:55:05 +00:00
|
|
|
};
|
|
|
|
|
2016-04-21 12:58:45 +00:00
|
|
|
static const unsigned armv8_vulcan_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
|
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_RD,
|
|
|
|
[C(L1D)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_REFILL_RD,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_WR,
|
|
|
|
[C(L1D)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_CACHE_REFILL_WR,
|
|
|
|
|
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_RD,
|
|
|
|
[C(DTLB)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_WR,
|
|
|
|
[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_REFILL_RD,
|
|
|
|
[C(DTLB)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV8_IMPDEF_PERFCTR_L1D_TLB_REFILL_WR,
|
|
|
|
|
|
|
|
[C(NODE)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_BUS_ACCESS_RD,
|
|
|
|
[C(NODE)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_IMPDEF_PERFCTR_BUS_ACCESS_WR,
|
|
|
|
};
|
2016-04-21 12:58:44 +00:00
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
armv8pmu_events_sysfs_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *page)
|
|
|
|
{
|
|
|
|
struct perf_pmu_events_attr *pmu_attr;
|
|
|
|
|
|
|
|
pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
|
|
|
|
|
2020-06-18 13:35:44 +00:00
|
|
|
return sprintf(page, "event=0x%04llx\n", pmu_attr->id);
|
2016-04-21 12:58:44 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 03:46:17 +00:00
|
|
|
#define ARMV8_EVENT_ATTR(name, config) \
|
2021-06-09 06:41:03 +00:00
|
|
|
PMU_EVENT_ATTR_ID(name, armv8pmu_events_sysfs_show, config)
|
2015-10-22 14:07:32 +00:00
|
|
|
|
|
|
|
static struct attribute *armv8_pmuv3_event_attrs[] = {
|
drivers/perf: pmuv3: don't expose SW_INCR event in sysfs
The SW_INCR event is somewhat unusual, and depends on the specific HW
counter that it is programmed into. When programmed into PMEVCNTR<n>,
SW_INCR will count any writes to PMSWINC_EL0 with bit n set, ignoring
writes to SW_INCR with bit n clear.
Event rotation means that there's no fixed relationship between
perf_events and HW counters, so this isn't all that useful.
Further, we program PMUSERENR.{SW,EN}=={0,0}, which causes EL0 writes to
PMSWINC_EL0 to be trapped and handled as UNDEFINED, resulting in a
SIGILL to userspace.
Given that, it's not a good idea to expose SW_INCR in sysfs. Hide it as
we did for CHAIN back in commit:
4ba2578fa7b55701 ("arm64: perf: don't expose CHAIN event in sysfs")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20231204115847.2993026-1-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-04 11:58:47 +00:00
|
|
|
/*
|
|
|
|
* Don't expose the sw_incr event in /sys. It's not usable as writes to
|
|
|
|
* PMSWINC_EL0 will trap as PMUSERENR.{SW,EN}=={0,0} and event rotation
|
|
|
|
* means we don't have a fixed event<->counter relationship regardless.
|
|
|
|
*/
|
2019-10-30 03:46:17 +00:00
|
|
|
ARMV8_EVENT_ATTR(l1i_cache_refill, ARMV8_PMUV3_PERFCTR_L1I_CACHE_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l1i_tlb_refill, ARMV8_PMUV3_PERFCTR_L1I_TLB_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l1d_cache_refill, ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l1d_cache, ARMV8_PMUV3_PERFCTR_L1D_CACHE),
|
|
|
|
ARMV8_EVENT_ATTR(l1d_tlb_refill, ARMV8_PMUV3_PERFCTR_L1D_TLB_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(ld_retired, ARMV8_PMUV3_PERFCTR_LD_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(st_retired, ARMV8_PMUV3_PERFCTR_ST_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(inst_retired, ARMV8_PMUV3_PERFCTR_INST_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(exc_taken, ARMV8_PMUV3_PERFCTR_EXC_TAKEN),
|
|
|
|
ARMV8_EVENT_ATTR(exc_return, ARMV8_PMUV3_PERFCTR_EXC_RETURN),
|
|
|
|
ARMV8_EVENT_ATTR(cid_write_retired, ARMV8_PMUV3_PERFCTR_CID_WRITE_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(pc_write_retired, ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(br_immed_retired, ARMV8_PMUV3_PERFCTR_BR_IMMED_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(br_return_retired, ARMV8_PMUV3_PERFCTR_BR_RETURN_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(unaligned_ldst_retired, ARMV8_PMUV3_PERFCTR_UNALIGNED_LDST_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(br_mis_pred, ARMV8_PMUV3_PERFCTR_BR_MIS_PRED),
|
|
|
|
ARMV8_EVENT_ATTR(cpu_cycles, ARMV8_PMUV3_PERFCTR_CPU_CYCLES),
|
|
|
|
ARMV8_EVENT_ATTR(br_pred, ARMV8_PMUV3_PERFCTR_BR_PRED),
|
|
|
|
ARMV8_EVENT_ATTR(mem_access, ARMV8_PMUV3_PERFCTR_MEM_ACCESS),
|
|
|
|
ARMV8_EVENT_ATTR(l1i_cache, ARMV8_PMUV3_PERFCTR_L1I_CACHE),
|
|
|
|
ARMV8_EVENT_ATTR(l1d_cache_wb, ARMV8_PMUV3_PERFCTR_L1D_CACHE_WB),
|
|
|
|
ARMV8_EVENT_ATTR(l2d_cache, ARMV8_PMUV3_PERFCTR_L2D_CACHE),
|
|
|
|
ARMV8_EVENT_ATTR(l2d_cache_refill, ARMV8_PMUV3_PERFCTR_L2D_CACHE_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l2d_cache_wb, ARMV8_PMUV3_PERFCTR_L2D_CACHE_WB),
|
|
|
|
ARMV8_EVENT_ATTR(bus_access, ARMV8_PMUV3_PERFCTR_BUS_ACCESS),
|
|
|
|
ARMV8_EVENT_ATTR(memory_error, ARMV8_PMUV3_PERFCTR_MEMORY_ERROR),
|
|
|
|
ARMV8_EVENT_ATTR(inst_spec, ARMV8_PMUV3_PERFCTR_INST_SPEC),
|
|
|
|
ARMV8_EVENT_ATTR(ttbr_write_retired, ARMV8_PMUV3_PERFCTR_TTBR_WRITE_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(bus_cycles, ARMV8_PMUV3_PERFCTR_BUS_CYCLES),
|
|
|
|
/* Don't expose the chain event in /sys, since it's useless in isolation */
|
|
|
|
ARMV8_EVENT_ATTR(l1d_cache_allocate, ARMV8_PMUV3_PERFCTR_L1D_CACHE_ALLOCATE),
|
|
|
|
ARMV8_EVENT_ATTR(l2d_cache_allocate, ARMV8_PMUV3_PERFCTR_L2D_CACHE_ALLOCATE),
|
|
|
|
ARMV8_EVENT_ATTR(br_retired, ARMV8_PMUV3_PERFCTR_BR_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(br_mis_pred_retired, ARMV8_PMUV3_PERFCTR_BR_MIS_PRED_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(stall_frontend, ARMV8_PMUV3_PERFCTR_STALL_FRONTEND),
|
|
|
|
ARMV8_EVENT_ATTR(stall_backend, ARMV8_PMUV3_PERFCTR_STALL_BACKEND),
|
|
|
|
ARMV8_EVENT_ATTR(l1d_tlb, ARMV8_PMUV3_PERFCTR_L1D_TLB),
|
|
|
|
ARMV8_EVENT_ATTR(l1i_tlb, ARMV8_PMUV3_PERFCTR_L1I_TLB),
|
|
|
|
ARMV8_EVENT_ATTR(l2i_cache, ARMV8_PMUV3_PERFCTR_L2I_CACHE),
|
|
|
|
ARMV8_EVENT_ATTR(l2i_cache_refill, ARMV8_PMUV3_PERFCTR_L2I_CACHE_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l3d_cache_allocate, ARMV8_PMUV3_PERFCTR_L3D_CACHE_ALLOCATE),
|
|
|
|
ARMV8_EVENT_ATTR(l3d_cache_refill, ARMV8_PMUV3_PERFCTR_L3D_CACHE_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l3d_cache, ARMV8_PMUV3_PERFCTR_L3D_CACHE),
|
|
|
|
ARMV8_EVENT_ATTR(l3d_cache_wb, ARMV8_PMUV3_PERFCTR_L3D_CACHE_WB),
|
|
|
|
ARMV8_EVENT_ATTR(l2d_tlb_refill, ARMV8_PMUV3_PERFCTR_L2D_TLB_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l2i_tlb_refill, ARMV8_PMUV3_PERFCTR_L2I_TLB_REFILL),
|
|
|
|
ARMV8_EVENT_ATTR(l2d_tlb, ARMV8_PMUV3_PERFCTR_L2D_TLB),
|
|
|
|
ARMV8_EVENT_ATTR(l2i_tlb, ARMV8_PMUV3_PERFCTR_L2I_TLB),
|
|
|
|
ARMV8_EVENT_ATTR(remote_access, ARMV8_PMUV3_PERFCTR_REMOTE_ACCESS),
|
|
|
|
ARMV8_EVENT_ATTR(ll_cache, ARMV8_PMUV3_PERFCTR_LL_CACHE),
|
|
|
|
ARMV8_EVENT_ATTR(ll_cache_miss, ARMV8_PMUV3_PERFCTR_LL_CACHE_MISS),
|
|
|
|
ARMV8_EVENT_ATTR(dtlb_walk, ARMV8_PMUV3_PERFCTR_DTLB_WALK),
|
|
|
|
ARMV8_EVENT_ATTR(itlb_walk, ARMV8_PMUV3_PERFCTR_ITLB_WALK),
|
|
|
|
ARMV8_EVENT_ATTR(ll_cache_rd, ARMV8_PMUV3_PERFCTR_LL_CACHE_RD),
|
|
|
|
ARMV8_EVENT_ATTR(ll_cache_miss_rd, ARMV8_PMUV3_PERFCTR_LL_CACHE_MISS_RD),
|
|
|
|
ARMV8_EVENT_ATTR(remote_access_rd, ARMV8_PMUV3_PERFCTR_REMOTE_ACCESS_RD),
|
2020-07-21 10:49:33 +00:00
|
|
|
ARMV8_EVENT_ATTR(l1d_cache_lmiss_rd, ARMV8_PMUV3_PERFCTR_L1D_CACHE_LMISS_RD),
|
|
|
|
ARMV8_EVENT_ATTR(op_retired, ARMV8_PMUV3_PERFCTR_OP_RETIRED),
|
|
|
|
ARMV8_EVENT_ATTR(op_spec, ARMV8_PMUV3_PERFCTR_OP_SPEC),
|
|
|
|
ARMV8_EVENT_ATTR(stall, ARMV8_PMUV3_PERFCTR_STALL),
|
|
|
|
ARMV8_EVENT_ATTR(stall_slot_backend, ARMV8_PMUV3_PERFCTR_STALL_SLOT_BACKEND),
|
|
|
|
ARMV8_EVENT_ATTR(stall_slot_frontend, ARMV8_PMUV3_PERFCTR_STALL_SLOT_FRONTEND),
|
|
|
|
ARMV8_EVENT_ATTR(stall_slot, ARMV8_PMUV3_PERFCTR_STALL_SLOT),
|
2019-10-30 03:46:17 +00:00
|
|
|
ARMV8_EVENT_ATTR(sample_pop, ARMV8_SPE_PERFCTR_SAMPLE_POP),
|
|
|
|
ARMV8_EVENT_ATTR(sample_feed, ARMV8_SPE_PERFCTR_SAMPLE_FEED),
|
|
|
|
ARMV8_EVENT_ATTR(sample_filtrate, ARMV8_SPE_PERFCTR_SAMPLE_FILTRATE),
|
|
|
|
ARMV8_EVENT_ATTR(sample_collision, ARMV8_SPE_PERFCTR_SAMPLE_COLLISION),
|
2020-07-21 10:49:33 +00:00
|
|
|
ARMV8_EVENT_ATTR(cnt_cycles, ARMV8_AMU_PERFCTR_CNT_CYCLES),
|
|
|
|
ARMV8_EVENT_ATTR(stall_backend_mem, ARMV8_AMU_PERFCTR_STALL_BACKEND_MEM),
|
|
|
|
ARMV8_EVENT_ATTR(l1i_cache_lmiss, ARMV8_PMUV3_PERFCTR_L1I_CACHE_LMISS),
|
|
|
|
ARMV8_EVENT_ATTR(l2d_cache_lmiss_rd, ARMV8_PMUV3_PERFCTR_L2D_CACHE_LMISS_RD),
|
|
|
|
ARMV8_EVENT_ATTR(l2i_cache_lmiss, ARMV8_PMUV3_PERFCTR_L2I_CACHE_LMISS),
|
|
|
|
ARMV8_EVENT_ATTR(l3d_cache_lmiss_rd, ARMV8_PMUV3_PERFCTR_L3D_CACHE_LMISS_RD),
|
2022-03-03 08:54:19 +00:00
|
|
|
ARMV8_EVENT_ATTR(trb_wrap, ARMV8_PMUV3_PERFCTR_TRB_WRAP),
|
|
|
|
ARMV8_EVENT_ATTR(trb_trig, ARMV8_PMUV3_PERFCTR_TRB_TRIG),
|
|
|
|
ARMV8_EVENT_ATTR(trcextout0, ARMV8_PMUV3_PERFCTR_TRCEXTOUT0),
|
|
|
|
ARMV8_EVENT_ATTR(trcextout1, ARMV8_PMUV3_PERFCTR_TRCEXTOUT1),
|
|
|
|
ARMV8_EVENT_ATTR(trcextout2, ARMV8_PMUV3_PERFCTR_TRCEXTOUT2),
|
|
|
|
ARMV8_EVENT_ATTR(trcextout3, ARMV8_PMUV3_PERFCTR_TRCEXTOUT3),
|
|
|
|
ARMV8_EVENT_ATTR(cti_trigout4, ARMV8_PMUV3_PERFCTR_CTI_TRIGOUT4),
|
|
|
|
ARMV8_EVENT_ATTR(cti_trigout5, ARMV8_PMUV3_PERFCTR_CTI_TRIGOUT5),
|
|
|
|
ARMV8_EVENT_ATTR(cti_trigout6, ARMV8_PMUV3_PERFCTR_CTI_TRIGOUT6),
|
|
|
|
ARMV8_EVENT_ATTR(cti_trigout7, ARMV8_PMUV3_PERFCTR_CTI_TRIGOUT7),
|
2020-07-21 10:49:33 +00:00
|
|
|
ARMV8_EVENT_ATTR(ldst_align_lat, ARMV8_PMUV3_PERFCTR_LDST_ALIGN_LAT),
|
|
|
|
ARMV8_EVENT_ATTR(ld_align_lat, ARMV8_PMUV3_PERFCTR_LD_ALIGN_LAT),
|
|
|
|
ARMV8_EVENT_ATTR(st_align_lat, ARMV8_PMUV3_PERFCTR_ST_ALIGN_LAT),
|
|
|
|
ARMV8_EVENT_ATTR(mem_access_checked, ARMV8_MTE_PERFCTR_MEM_ACCESS_CHECKED),
|
|
|
|
ARMV8_EVENT_ATTR(mem_access_checked_rd, ARMV8_MTE_PERFCTR_MEM_ACCESS_CHECKED_RD),
|
|
|
|
ARMV8_EVENT_ATTR(mem_access_checked_wr, ARMV8_MTE_PERFCTR_MEM_ACCESS_CHECKED_WR),
|
2015-12-22 14:42:57 +00:00
|
|
|
NULL,
|
2015-10-22 14:07:32 +00:00
|
|
|
};
|
|
|
|
|
2016-04-21 12:58:44 +00:00
|
|
|
static umode_t
|
|
|
|
armv8pmu_event_attr_is_visible(struct kobject *kobj,
|
|
|
|
struct attribute *attr, int unused)
|
|
|
|
{
|
|
|
|
struct device *dev = kobj_to_dev(kobj);
|
|
|
|
struct pmu *pmu = dev_get_drvdata(dev);
|
|
|
|
struct arm_pmu *cpu_pmu = container_of(pmu, struct arm_pmu, pmu);
|
|
|
|
struct perf_pmu_events_attr *pmu_attr;
|
|
|
|
|
|
|
|
pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);
|
|
|
|
|
2018-10-05 12:28:07 +00:00
|
|
|
if (pmu_attr->id < ARMV8_PMUV3_MAX_COMMON_EVENTS &&
|
|
|
|
test_bit(pmu_attr->id, cpu_pmu->pmceid_bitmap))
|
|
|
|
return attr->mode;
|
|
|
|
|
2020-06-18 13:35:44 +00:00
|
|
|
if (pmu_attr->id >= ARMV8_PMUV3_EXT_COMMON_EVENT_BASE) {
|
|
|
|
u64 id = pmu_attr->id - ARMV8_PMUV3_EXT_COMMON_EVENT_BASE;
|
|
|
|
|
|
|
|
if (id < ARMV8_PMUV3_MAX_COMMON_EVENTS &&
|
|
|
|
test_bit(id, cpu_pmu->pmceid_ext_bitmap))
|
|
|
|
return attr->mode;
|
|
|
|
}
|
2016-04-21 12:58:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-31 14:36:15 +00:00
|
|
|
static const struct attribute_group armv8_pmuv3_events_attr_group = {
|
2015-10-22 14:07:32 +00:00
|
|
|
.name = "events",
|
|
|
|
.attrs = armv8_pmuv3_event_attrs,
|
2016-04-21 12:58:44 +00:00
|
|
|
.is_visible = armv8pmu_event_attr_is_visible,
|
2015-10-22 14:07:32 +00:00
|
|
|
};
|
|
|
|
|
2023-12-11 16:13:18 +00:00
|
|
|
/* User ABI */
|
|
|
|
#define ATTR_CFG_FLD_event_CFG config
|
|
|
|
#define ATTR_CFG_FLD_event_LO 0
|
|
|
|
#define ATTR_CFG_FLD_event_HI 15
|
|
|
|
#define ATTR_CFG_FLD_long_CFG config1
|
|
|
|
#define ATTR_CFG_FLD_long_LO 0
|
|
|
|
#define ATTR_CFG_FLD_long_HI 0
|
|
|
|
#define ATTR_CFG_FLD_rdpmc_CFG config1
|
|
|
|
#define ATTR_CFG_FLD_rdpmc_LO 1
|
|
|
|
#define ATTR_CFG_FLD_rdpmc_HI 1
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
#define ATTR_CFG_FLD_threshold_count_CFG config1 /* PMEVTYPER.TC[0] */
|
|
|
|
#define ATTR_CFG_FLD_threshold_count_LO 2
|
|
|
|
#define ATTR_CFG_FLD_threshold_count_HI 2
|
|
|
|
#define ATTR_CFG_FLD_threshold_compare_CFG config1 /* PMEVTYPER.TC[2:1] */
|
|
|
|
#define ATTR_CFG_FLD_threshold_compare_LO 3
|
|
|
|
#define ATTR_CFG_FLD_threshold_compare_HI 4
|
|
|
|
#define ATTR_CFG_FLD_threshold_CFG config1 /* PMEVTYPER.TH */
|
|
|
|
#define ATTR_CFG_FLD_threshold_LO 5
|
|
|
|
#define ATTR_CFG_FLD_threshold_HI 16
|
2023-12-11 16:13:18 +00:00
|
|
|
|
|
|
|
GEN_PMU_FORMAT_ATTR(event);
|
|
|
|
GEN_PMU_FORMAT_ATTR(long);
|
|
|
|
GEN_PMU_FORMAT_ATTR(rdpmc);
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
GEN_PMU_FORMAT_ATTR(threshold_count);
|
|
|
|
GEN_PMU_FORMAT_ATTR(threshold_compare);
|
|
|
|
GEN_PMU_FORMAT_ATTR(threshold);
|
2018-07-10 08:58:04 +00:00
|
|
|
|
2021-12-08 20:11:22 +00:00
|
|
|
static int sysctl_perf_user_access __read_mostly;
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static bool armv8pmu_event_is_64bit(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
2023-12-11 16:13:18 +00:00
|
|
|
return ATTR_CFG_GET_FLD(&event->attr, long);
|
2018-07-10 08:58:04 +00:00
|
|
|
}
|
2015-12-22 14:42:57 +00:00
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static bool armv8pmu_event_want_user_access(struct perf_event *event)
|
2021-12-08 20:11:23 +00:00
|
|
|
{
|
2023-12-11 16:13:18 +00:00
|
|
|
return ATTR_CFG_GET_FLD(&event->attr, rdpmc);
|
2021-12-08 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
2024-06-26 22:32:25 +00:00
|
|
|
static u32 armv8pmu_event_get_threshold(struct perf_event_attr *attr)
|
|
|
|
{
|
|
|
|
return ATTR_CFG_GET_FLD(attr, threshold);
|
|
|
|
}
|
|
|
|
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
static u8 armv8pmu_event_threshold_control(struct perf_event_attr *attr)
|
|
|
|
{
|
|
|
|
u8 th_compare = ATTR_CFG_GET_FLD(attr, threshold_compare);
|
|
|
|
u8 th_count = ATTR_CFG_GET_FLD(attr, threshold_count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The count bit is always the bottom bit of the full control field, and
|
|
|
|
* the comparison is the upper two bits, but it's not explicitly
|
|
|
|
* labelled in the Arm ARM. For the Perf interface we split it into two
|
|
|
|
* fields, so reconstruct it here.
|
|
|
|
*/
|
|
|
|
return (th_compare << 1) | th_count;
|
|
|
|
}
|
|
|
|
|
2015-12-22 14:42:57 +00:00
|
|
|
static struct attribute *armv8_pmuv3_format_attrs[] = {
|
|
|
|
&format_attr_event.attr,
|
2018-07-10 08:58:04 +00:00
|
|
|
&format_attr_long.attr,
|
2021-12-08 20:11:23 +00:00
|
|
|
&format_attr_rdpmc.attr,
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
&format_attr_threshold.attr,
|
|
|
|
&format_attr_threshold_compare.attr,
|
|
|
|
&format_attr_threshold_count.attr,
|
2015-12-22 14:42:57 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2021-01-31 14:36:15 +00:00
|
|
|
static const struct attribute_group armv8_pmuv3_format_attr_group = {
|
2015-12-22 14:42:57 +00:00
|
|
|
.name = "format",
|
|
|
|
.attrs = armv8_pmuv3_format_attrs,
|
|
|
|
};
|
|
|
|
|
2020-09-22 05:53:45 +00:00
|
|
|
static ssize_t slots_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *page)
|
|
|
|
{
|
|
|
|
struct pmu *pmu = dev_get_drvdata(dev);
|
|
|
|
struct arm_pmu *cpu_pmu = container_of(pmu, struct arm_pmu, pmu);
|
2023-12-11 16:13:15 +00:00
|
|
|
u32 slots = FIELD_GET(ARMV8_PMU_SLOTS, cpu_pmu->reg_pmmir);
|
2020-09-22 05:53:45 +00:00
|
|
|
|
2021-05-20 07:59:45 +00:00
|
|
|
return sysfs_emit(page, "0x%08x\n", slots);
|
2020-09-22 05:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RO(slots);
|
|
|
|
|
2021-06-03 07:15:02 +00:00
|
|
|
static ssize_t bus_slots_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *page)
|
|
|
|
{
|
|
|
|
struct pmu *pmu = dev_get_drvdata(dev);
|
|
|
|
struct arm_pmu *cpu_pmu = container_of(pmu, struct arm_pmu, pmu);
|
2023-12-11 16:13:15 +00:00
|
|
|
u32 bus_slots = FIELD_GET(ARMV8_PMU_BUS_SLOTS, cpu_pmu->reg_pmmir);
|
2021-06-03 07:15:02 +00:00
|
|
|
|
|
|
|
return sysfs_emit(page, "0x%08x\n", bus_slots);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RO(bus_slots);
|
|
|
|
|
|
|
|
static ssize_t bus_width_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *page)
|
|
|
|
{
|
|
|
|
struct pmu *pmu = dev_get_drvdata(dev);
|
|
|
|
struct arm_pmu *cpu_pmu = container_of(pmu, struct arm_pmu, pmu);
|
2023-12-11 16:13:15 +00:00
|
|
|
u32 bus_width = FIELD_GET(ARMV8_PMU_BUS_WIDTH, cpu_pmu->reg_pmmir);
|
2021-06-03 07:15:02 +00:00
|
|
|
u32 val = 0;
|
|
|
|
|
|
|
|
/* Encoded as Log2(number of bytes), plus one */
|
|
|
|
if (bus_width > 2 && bus_width < 13)
|
|
|
|
val = 1 << (bus_width - 1);
|
|
|
|
|
|
|
|
return sysfs_emit(page, "0x%08x\n", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RO(bus_width);
|
|
|
|
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
static u32 threshold_max(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* PMMIR.THWIDTH is readable and non-zero on aarch32, but it would be
|
|
|
|
* impossible to write the threshold in the upper 32 bits of PMEVTYPER.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_ARM))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The largest value that can be written to PMEVTYPER<n>_EL0.TH is
|
|
|
|
* (2 ^ PMMIR.THWIDTH) - 1.
|
|
|
|
*/
|
|
|
|
return (1 << FIELD_GET(ARMV8_PMU_THWIDTH, cpu_pmu->reg_pmmir)) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t threshold_max_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *page)
|
|
|
|
{
|
|
|
|
struct pmu *pmu = dev_get_drvdata(dev);
|
|
|
|
struct arm_pmu *cpu_pmu = container_of(pmu, struct arm_pmu, pmu);
|
|
|
|
|
|
|
|
return sysfs_emit(page, "0x%08x\n", threshold_max(cpu_pmu));
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RO(threshold_max);
|
|
|
|
|
2020-09-22 05:53:45 +00:00
|
|
|
static struct attribute *armv8_pmuv3_caps_attrs[] = {
|
|
|
|
&dev_attr_slots.attr,
|
2021-06-03 07:15:02 +00:00
|
|
|
&dev_attr_bus_slots.attr,
|
|
|
|
&dev_attr_bus_width.attr,
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
&dev_attr_threshold_max.attr,
|
2020-09-22 05:53:45 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2021-01-31 14:36:15 +00:00
|
|
|
static const struct attribute_group armv8_pmuv3_caps_attr_group = {
|
2020-09-22 05:53:45 +00:00
|
|
|
.name = "caps",
|
|
|
|
.attrs = armv8_pmuv3_caps_attrs,
|
|
|
|
};
|
|
|
|
|
2020-03-02 18:17:52 +00:00
|
|
|
/*
|
|
|
|
* We unconditionally enable ARMv8.5-PMU long event counter support
|
|
|
|
* (64-bit events) where supported. Indicate if this arm_pmu has long
|
|
|
|
* event counter support.
|
2023-03-17 19:50:26 +00:00
|
|
|
*
|
|
|
|
* On AArch32, long counters make no sense (you can't access the top
|
|
|
|
* bits), so we only enable this on AArch64.
|
2020-03-02 18:17:52 +00:00
|
|
|
*/
|
|
|
|
static bool armv8pmu_has_long_event(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2023-03-17 19:50:26 +00:00
|
|
|
return (IS_ENABLED(CONFIG_ARM64) && is_pmuv3p5(cpu_pmu->pmuver));
|
2020-03-02 18:17:52 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static bool armv8pmu_event_has_user_read(struct perf_event *event)
|
2021-12-08 20:11:23 +00:00
|
|
|
{
|
|
|
|
return event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT;
|
|
|
|
}
|
|
|
|
|
2018-07-10 08:58:04 +00:00
|
|
|
/*
|
|
|
|
* We must chain two programmable counters for 64 bit events,
|
|
|
|
* except when we have allocated the 64bit cycle counter (for CPU
|
2021-12-08 20:11:23 +00:00
|
|
|
* cycles event) or when user space counter access is enabled.
|
2018-07-10 08:58:04 +00:00
|
|
|
*/
|
2023-12-11 16:13:13 +00:00
|
|
|
static bool armv8pmu_event_is_chained(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
|
|
|
int idx = event->hw.idx;
|
2020-03-02 18:17:52 +00:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
2018-07-10 08:58:04 +00:00
|
|
|
|
2021-12-08 20:11:23 +00:00
|
|
|
return !armv8pmu_event_has_user_read(event) &&
|
2018-07-10 08:58:04 +00:00
|
|
|
armv8pmu_event_is_64bit(event) &&
|
2020-03-02 18:17:52 +00:00
|
|
|
!armv8pmu_has_long_event(cpu_pmu) &&
|
2024-07-31 16:51:18 +00:00
|
|
|
(idx < ARMV8_PMU_MAX_GENERAL_COUNTERS);
|
2018-07-10 08:58:04 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
/*
|
|
|
|
* ARMv8 low level PMU access
|
|
|
|
*/
|
2023-12-11 16:13:13 +00:00
|
|
|
static u64 armv8pmu_pmcr_read(void)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2023-03-17 19:50:21 +00:00
|
|
|
return read_pmcr();
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_pmcr_write(u64 val)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2016-03-24 16:01:16 +00:00
|
|
|
val &= ARMV8_PMU_PMCR_MASK;
|
2012-03-05 11:49:32 +00:00
|
|
|
isb();
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmcr(val);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static int armv8pmu_has_overflowed(u64 pmovsr)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2024-07-31 16:51:19 +00:00
|
|
|
return !!(pmovsr & ARMV8_PMU_OVERFLOWED_MASK);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static int armv8pmu_counter_has_overflowed(u64 pmnc, int idx)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2024-07-31 16:51:19 +00:00
|
|
|
return !!(pmnc & BIT(idx));
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static u64 armv8pmu_read_evcntr(int idx)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2024-07-31 16:51:18 +00:00
|
|
|
return read_pmevcntrn(idx);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static u64 armv8pmu_read_hw_counter(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
|
|
|
int idx = event->hw.idx;
|
2021-04-01 11:16:41 +00:00
|
|
|
u64 val = armv8pmu_read_evcntr(idx);
|
2018-07-10 08:58:04 +00:00
|
|
|
|
|
|
|
if (armv8pmu_event_is_chained(event))
|
|
|
|
val = (val << 32) | armv8pmu_read_evcntr(idx - 1);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2020-03-02 18:17:52 +00:00
|
|
|
/*
|
|
|
|
* The cycle counter is always a 64-bit counter. When ARMV8_PMU_PMCR_LP
|
|
|
|
* is set the event counters also become 64-bit counters. Unless the
|
|
|
|
* user has requested a long counter (attr.config1) then we want to
|
|
|
|
* interrupt upon 32-bit overflow - we achieve this by applying a bias.
|
|
|
|
*/
|
|
|
|
static bool armv8pmu_event_needs_bias(struct perf_event *event)
|
|
|
|
{
|
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int idx = hwc->idx;
|
|
|
|
|
|
|
|
if (armv8pmu_event_is_64bit(event))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (armv8pmu_has_long_event(cpu_pmu) ||
|
2024-07-31 16:51:18 +00:00
|
|
|
idx >= ARMV8_PMU_MAX_GENERAL_COUNTERS)
|
2020-03-02 18:17:52 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 armv8pmu_bias_long_counter(struct perf_event *event, u64 value)
|
|
|
|
{
|
|
|
|
if (armv8pmu_event_needs_bias(event))
|
2023-03-17 19:50:24 +00:00
|
|
|
value |= GENMASK_ULL(63, 32);
|
2020-03-02 18:17:52 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 armv8pmu_unbias_long_counter(struct perf_event *event, u64 value)
|
|
|
|
{
|
|
|
|
if (armv8pmu_event_needs_bias(event))
|
2023-03-17 19:50:24 +00:00
|
|
|
value &= ~GENMASK_ULL(63, 32);
|
2020-03-02 18:17:52 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-04-11 16:16:46 +00:00
|
|
|
static u64 armv8pmu_read_counter(struct perf_event *event)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2015-10-02 09:55:03 +00:00
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int idx = hwc->idx;
|
2021-04-01 11:16:41 +00:00
|
|
|
u64 value;
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2024-07-31 16:51:22 +00:00
|
|
|
if (idx == ARMV8_PMU_CYCLE_IDX)
|
2023-03-17 19:50:21 +00:00
|
|
|
value = read_pmccntr();
|
2024-07-31 16:51:24 +00:00
|
|
|
else if (idx == ARMV8_PMU_INSTR_IDX)
|
|
|
|
value = read_pmicntr();
|
2018-07-10 08:58:02 +00:00
|
|
|
else
|
2018-07-10 08:58:04 +00:00
|
|
|
value = armv8pmu_read_hw_counter(event);
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2020-03-02 18:17:52 +00:00
|
|
|
return armv8pmu_unbias_long_counter(event, value);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_write_evcntr(int idx, u64 value)
|
2018-07-10 08:58:02 +00:00
|
|
|
{
|
2024-07-31 16:51:18 +00:00
|
|
|
write_pmevcntrn(idx, value);
|
2018-07-10 08:58:02 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_write_hw_counter(struct perf_event *event,
|
2018-07-10 08:58:04 +00:00
|
|
|
u64 value)
|
|
|
|
{
|
|
|
|
int idx = event->hw.idx;
|
|
|
|
|
|
|
|
if (armv8pmu_event_is_chained(event)) {
|
|
|
|
armv8pmu_write_evcntr(idx, upper_32_bits(value));
|
|
|
|
armv8pmu_write_evcntr(idx - 1, lower_32_bits(value));
|
|
|
|
} else {
|
|
|
|
armv8pmu_write_evcntr(idx, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-11 16:16:46 +00:00
|
|
|
static void armv8pmu_write_counter(struct perf_event *event, u64 value)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2015-10-02 09:55:03 +00:00
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int idx = hwc->idx;
|
|
|
|
|
2020-03-02 18:17:52 +00:00
|
|
|
value = armv8pmu_bias_long_counter(event, value);
|
|
|
|
|
2024-07-31 16:51:22 +00:00
|
|
|
if (idx == ARMV8_PMU_CYCLE_IDX)
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmccntr(value);
|
2024-07-31 16:51:24 +00:00
|
|
|
else if (idx == ARMV8_PMU_INSTR_IDX)
|
|
|
|
write_pmicntr(value);
|
2020-03-02 18:17:52 +00:00
|
|
|
else
|
2018-07-10 08:58:04 +00:00
|
|
|
armv8pmu_write_hw_counter(event, value);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
static void armv8pmu_write_evtype(int idx, unsigned long val)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2023-12-11 16:13:17 +00:00
|
|
|
unsigned long mask = ARMV8_PMU_EVTYPE_EVENT |
|
|
|
|
ARMV8_PMU_INCLUDE_EL2 |
|
|
|
|
ARMV8_PMU_EXCLUDE_EL0 |
|
|
|
|
ARMV8_PMU_EXCLUDE_EL1;
|
arm64: perf: Avoid PMXEV* indirection
Currently we access the counter registers and their respective type
registers indirectly. This requires us to write to PMSELR, issue an ISB,
then access the relevant PMXEV* registers.
This is unfortunate, because:
* Under virtualization, accessing one register requires two traps to
the hypervisor, even though we could access the register directly with
a single trap.
* We have to issue an ISB which we could otherwise avoid the cost of.
* When we use NMIs, the NMI handler will have to save/restore the select
register in case the code it preempted was attempting to access a
counter or its type register.
We can avoid these issues by directly accessing the relevant registers.
This patch adds helpers to do so.
In armv8pmu_enable_event() we still need the ISB to prevent the PE from
reordering the write to PMINTENSET_EL1 register. If the interrupt is
enabled before we disable the counter and the new event is configured,
we might get an interrupt triggered by the previously programmed event
overflowing, but which we wrongly attribute to the event that we are
enabling. Execute an ISB after we disable the counter.
In the process, remove the comment that refers to the ARMv7 PMU.
[Julien T.: Don't inline read/write functions to avoid big code-size
increase, remove unused read_pmevtypern function,
fix counter index issue.]
[Alexandru E.: Removed comment, removed trailing semicolons in macros,
added ISB]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Julien Thierry <julien.thierry@arm.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Tested-by: Sumit Garg <sumit.garg@linaro.org> (Developerbox)
Cc: Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20200924110706.254996-3-alexandru.elisei@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2020-09-24 11:07:01 +00:00
|
|
|
|
2023-12-11 16:13:17 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ARM64))
|
|
|
|
mask |= ARMV8_PMU_EVTYPE_TC | ARMV8_PMU_EVTYPE_TH;
|
|
|
|
|
|
|
|
val &= mask;
|
2024-07-31 16:51:18 +00:00
|
|
|
write_pmevtypern(idx, val);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_write_event_type(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int idx = hwc->idx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For chained events, the low counter is programmed to count
|
|
|
|
* the event of interest and the high counter is programmed
|
|
|
|
* with CHAIN event code with filters set to count at all ELs.
|
|
|
|
*/
|
|
|
|
if (armv8pmu_event_is_chained(event)) {
|
|
|
|
u32 chain_evt = ARMV8_PMUV3_PERFCTR_CHAIN |
|
|
|
|
ARMV8_PMU_INCLUDE_EL2;
|
|
|
|
|
|
|
|
armv8pmu_write_evtype(idx - 1, hwc->config_base);
|
|
|
|
armv8pmu_write_evtype(idx, chain_evt);
|
|
|
|
} else {
|
2024-07-31 16:51:22 +00:00
|
|
|
if (idx == ARMV8_PMU_CYCLE_IDX)
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmccfiltr(hwc->config_base);
|
2024-07-31 16:51:24 +00:00
|
|
|
else if (idx == ARMV8_PMU_INSTR_IDX)
|
|
|
|
write_pmicfiltr(hwc->config_base);
|
arm64: perf: Avoid PMXEV* indirection
Currently we access the counter registers and their respective type
registers indirectly. This requires us to write to PMSELR, issue an ISB,
then access the relevant PMXEV* registers.
This is unfortunate, because:
* Under virtualization, accessing one register requires two traps to
the hypervisor, even though we could access the register directly with
a single trap.
* We have to issue an ISB which we could otherwise avoid the cost of.
* When we use NMIs, the NMI handler will have to save/restore the select
register in case the code it preempted was attempting to access a
counter or its type register.
We can avoid these issues by directly accessing the relevant registers.
This patch adds helpers to do so.
In armv8pmu_enable_event() we still need the ISB to prevent the PE from
reordering the write to PMINTENSET_EL1 register. If the interrupt is
enabled before we disable the counter and the new event is configured,
we might get an interrupt triggered by the previously programmed event
overflowing, but which we wrongly attribute to the event that we are
enabling. Execute an ISB after we disable the counter.
In the process, remove the comment that refers to the ARMv7 PMU.
[Julien T.: Don't inline read/write functions to avoid big code-size
increase, remove unused read_pmevtypern function,
fix counter index issue.]
[Alexandru E.: Removed comment, removed trailing semicolons in macros,
added ISB]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Julien Thierry <julien.thierry@arm.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Tested-by: Sumit Garg <sumit.garg@linaro.org> (Developerbox)
Cc: Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20200924110706.254996-3-alexandru.elisei@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2020-09-24 11:07:01 +00:00
|
|
|
else
|
|
|
|
armv8pmu_write_evtype(idx, hwc->config_base);
|
2018-07-10 08:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static u64 armv8pmu_event_cnten_mask(struct perf_event *event)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2024-07-31 16:51:18 +00:00
|
|
|
int counter = event->hw.idx;
|
2024-07-31 16:51:19 +00:00
|
|
|
u64 mask = BIT(counter);
|
2020-03-17 18:22:54 +00:00
|
|
|
|
|
|
|
if (armv8pmu_event_is_chained(event))
|
|
|
|
mask |= BIT(counter - 1);
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static void armv8pmu_enable_counter(u64 mask)
|
2020-03-17 18:22:54 +00:00
|
|
|
{
|
2020-09-24 11:07:00 +00:00
|
|
|
/*
|
|
|
|
* Make sure event configuration register writes are visible before we
|
|
|
|
* enable the counter.
|
|
|
|
* */
|
|
|
|
isb();
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmcntenset(mask);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_enable_event_counter(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
2019-04-09 19:22:13 +00:00
|
|
|
struct perf_event_attr *attr = &event->attr;
|
2024-07-31 16:51:19 +00:00
|
|
|
u64 mask = armv8pmu_event_cnten_mask(event);
|
2019-04-09 19:22:13 +00:00
|
|
|
|
2020-03-17 18:22:54 +00:00
|
|
|
kvm_set_pmu_events(mask, attr);
|
2019-04-09 19:22:13 +00:00
|
|
|
|
|
|
|
/* We rely on the hypervisor switch code to enable guest counters */
|
2020-03-17 18:22:54 +00:00
|
|
|
if (!kvm_pmu_counter_deferred(attr))
|
|
|
|
armv8pmu_enable_counter(mask);
|
2018-07-10 08:58:04 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static void armv8pmu_disable_counter(u64 mask)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmcntenclr(mask);
|
arm64: perf: Avoid PMXEV* indirection
Currently we access the counter registers and their respective type
registers indirectly. This requires us to write to PMSELR, issue an ISB,
then access the relevant PMXEV* registers.
This is unfortunate, because:
* Under virtualization, accessing one register requires two traps to
the hypervisor, even though we could access the register directly with
a single trap.
* We have to issue an ISB which we could otherwise avoid the cost of.
* When we use NMIs, the NMI handler will have to save/restore the select
register in case the code it preempted was attempting to access a
counter or its type register.
We can avoid these issues by directly accessing the relevant registers.
This patch adds helpers to do so.
In armv8pmu_enable_event() we still need the ISB to prevent the PE from
reordering the write to PMINTENSET_EL1 register. If the interrupt is
enabled before we disable the counter and the new event is configured,
we might get an interrupt triggered by the previously programmed event
overflowing, but which we wrongly attribute to the event that we are
enabling. Execute an ISB after we disable the counter.
In the process, remove the comment that refers to the ARMv7 PMU.
[Julien T.: Don't inline read/write functions to avoid big code-size
increase, remove unused read_pmevtypern function,
fix counter index issue.]
[Alexandru E.: Removed comment, removed trailing semicolons in macros,
added ISB]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Julien Thierry <julien.thierry@arm.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Tested-by: Sumit Garg <sumit.garg@linaro.org> (Developerbox)
Cc: Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20200924110706.254996-3-alexandru.elisei@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2020-09-24 11:07:01 +00:00
|
|
|
/*
|
|
|
|
* Make sure the effects of disabling the counter are visible before we
|
|
|
|
* start configuring the event.
|
|
|
|
*/
|
|
|
|
isb();
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_disable_event_counter(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
2019-04-09 19:22:13 +00:00
|
|
|
struct perf_event_attr *attr = &event->attr;
|
2024-07-31 16:51:19 +00:00
|
|
|
u64 mask = armv8pmu_event_cnten_mask(event);
|
2018-07-10 08:58:04 +00:00
|
|
|
|
2020-03-17 18:22:54 +00:00
|
|
|
kvm_clr_pmu_events(mask);
|
2019-04-09 19:22:13 +00:00
|
|
|
|
|
|
|
/* We rely on the hypervisor switch code to disable guest counters */
|
2020-03-17 18:22:54 +00:00
|
|
|
if (!kvm_pmu_counter_deferred(attr))
|
|
|
|
armv8pmu_disable_counter(mask);
|
2018-07-10 08:58:04 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static void armv8pmu_enable_intens(u64 mask)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmintenset(mask);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_enable_event_irq(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
2024-07-31 16:51:18 +00:00
|
|
|
armv8pmu_enable_intens(BIT(event->hw.idx));
|
2018-07-10 08:58:04 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static void armv8pmu_disable_intens(u64 mask)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmintenclr(mask);
|
2012-03-05 11:49:32 +00:00
|
|
|
isb();
|
|
|
|
/* Clear the overflow flag in case an interrupt is pending. */
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmovsclr(mask);
|
2012-03-05 11:49:32 +00:00
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
2023-12-11 16:13:13 +00:00
|
|
|
static void armv8pmu_disable_event_irq(struct perf_event *event)
|
2018-07-10 08:58:04 +00:00
|
|
|
{
|
2024-07-31 16:51:18 +00:00
|
|
|
armv8pmu_disable_intens(BIT(event->hw.idx));
|
2018-07-10 08:58:04 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:19 +00:00
|
|
|
static u64 armv8pmu_getreset_flags(void)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2024-07-31 16:51:19 +00:00
|
|
|
u64 value;
|
2012-03-05 11:49:32 +00:00
|
|
|
|
|
|
|
/* Read */
|
2023-03-17 19:50:21 +00:00
|
|
|
value = read_pmovsclr();
|
2012-03-05 11:49:32 +00:00
|
|
|
|
|
|
|
/* Write to clear flags */
|
2023-12-11 16:13:16 +00:00
|
|
|
value &= ARMV8_PMU_OVERFLOWED_MASK;
|
2023-03-17 19:50:21 +00:00
|
|
|
write_pmovsclr(value);
|
2012-03-05 11:49:32 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2023-06-03 02:50:35 +00:00
|
|
|
static void update_pmuserenr(u64 val)
|
|
|
|
{
|
|
|
|
lockdep_assert_irqs_disabled();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The current PMUSERENR_EL0 value might be the value for the guest.
|
|
|
|
* If that's the case, have KVM keep tracking of the register value
|
|
|
|
* for the host EL0 so that KVM can restore it before returning to
|
|
|
|
* the host EL0. Otherwise, update the register now.
|
|
|
|
*/
|
|
|
|
if (kvm_set_pmuserenr(val))
|
|
|
|
return;
|
|
|
|
|
|
|
|
write_pmuserenr(val);
|
|
|
|
}
|
|
|
|
|
2021-12-08 20:11:23 +00:00
|
|
|
static void armv8pmu_disable_user_access(void)
|
|
|
|
{
|
2023-06-03 02:50:35 +00:00
|
|
|
update_pmuserenr(0);
|
2021-12-08 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void armv8pmu_enable_user_access(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct pmu_hw_events *cpuc = this_cpu_ptr(cpu_pmu->hw_events);
|
|
|
|
|
2024-10-02 18:43:24 +00:00
|
|
|
if (is_pmuv3p9(cpu_pmu->pmuver)) {
|
|
|
|
u64 mask = 0;
|
|
|
|
for_each_set_bit(i, cpuc->used_mask, ARMPMU_MAX_HWEVENTS) {
|
|
|
|
if (armv8pmu_event_has_user_read(cpuc->events[i]))
|
|
|
|
mask |= BIT(i);
|
|
|
|
}
|
|
|
|
write_pmuacr(mask);
|
|
|
|
} else {
|
|
|
|
/* Clear any unused counters to avoid leaking their contents */
|
|
|
|
for_each_andnot_bit(i, cpu_pmu->cntr_mask, cpuc->used_mask,
|
|
|
|
ARMPMU_MAX_HWEVENTS) {
|
|
|
|
if (i == ARMV8_PMU_CYCLE_IDX)
|
|
|
|
write_pmccntr(0);
|
|
|
|
else if (i == ARMV8_PMU_INSTR_IDX)
|
|
|
|
write_pmicntr(0);
|
|
|
|
else
|
|
|
|
armv8pmu_write_evcntr(i, 0);
|
|
|
|
}
|
2021-12-08 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
2024-10-02 18:43:24 +00:00
|
|
|
update_pmuserenr(ARMV8_PMU_USERENR_ER | ARMV8_PMU_USERENR_CR | ARMV8_PMU_USERENR_UEN);
|
2021-12-08 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:55:03 +00:00
|
|
|
static void armv8pmu_enable_event(struct perf_event *event)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Enable counter and interrupt, and set the counter to count
|
|
|
|
* the event that we're interested in.
|
|
|
|
*/
|
2018-07-10 08:58:04 +00:00
|
|
|
armv8pmu_disable_event_counter(event);
|
|
|
|
armv8pmu_write_event_type(event);
|
|
|
|
armv8pmu_enable_event_irq(event);
|
|
|
|
armv8pmu_enable_event_counter(event);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:55:03 +00:00
|
|
|
static void armv8pmu_disable_event(struct perf_event *event)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2018-07-10 08:58:04 +00:00
|
|
|
armv8pmu_disable_event_counter(event);
|
|
|
|
armv8pmu_disable_event_irq(event);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 08:58:03 +00:00
|
|
|
static void armv8pmu_start(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
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
|
|
|
struct perf_event_context *ctx;
|
|
|
|
int nr_user = 0;
|
2021-12-08 20:11:23 +00:00
|
|
|
|
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
|
|
|
ctx = perf_cpu_task_ctx();
|
|
|
|
if (ctx)
|
|
|
|
nr_user = ctx->nr_user;
|
|
|
|
|
|
|
|
if (sysctl_perf_user_access && nr_user)
|
2021-12-08 20:11:23 +00:00
|
|
|
armv8pmu_enable_user_access(cpu_pmu);
|
|
|
|
else
|
|
|
|
armv8pmu_disable_user_access();
|
|
|
|
|
2018-07-10 08:58:03 +00:00
|
|
|
/* Enable all counters */
|
|
|
|
armv8pmu_pmcr_write(armv8pmu_pmcr_read() | ARMV8_PMU_PMCR_E);
|
KVM: arm64: pmu: Resync EL0 state on counter rotation
Huang Shijie reports that, when profiling a guest from the host
with a number of events that exceeds the number of available
counters, the reported counts are wildly inaccurate. Without
the counter oversubscription, the reported counts are correct.
Their investigation indicates that upon counter rotation (which
takes place on the back of a timer interrupt), we fail to
re-apply the guest EL0 enabling, leading to the counting of host
events instead of guest events.
In order to solve this, add yet another hook between the host PMU
driver and KVM, re-applying the guest EL0 configuration if the
right conditions apply (the host is VHE, we are in interrupt
context, and we interrupted a running vcpu). This triggers a new
vcpu request which will apply the correct configuration on guest
reentry.
With this, we have the correct counts, even when the counters are
oversubscribed.
Reported-by: Huang Shijie <shijie@os.amperecomputing.com>
Suggested-by: Oliver Upton <oliver.upton@linux.dev>
Tested_by: Huang Shijie <shijie@os.amperecomputing.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20230809013953.7692-1-shijie@os.amperecomputing.com
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20230820090108.177817-1-maz@kernel.org
2023-08-20 09:01:08 +00:00
|
|
|
|
|
|
|
kvm_vcpu_pmu_resync_el0();
|
2018-07-10 08:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void armv8pmu_stop(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
/* Disable all counters */
|
|
|
|
armv8pmu_pmcr_write(armv8pmu_pmcr_read() & ~ARMV8_PMU_PMCR_E);
|
|
|
|
}
|
|
|
|
|
2018-05-10 10:35:15 +00:00
|
|
|
static irqreturn_t armv8pmu_handle_irq(struct arm_pmu *cpu_pmu)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2024-07-31 16:51:19 +00:00
|
|
|
u64 pmovsr;
|
2012-03-05 11:49:32 +00:00
|
|
|
struct perf_sample_data data;
|
2015-10-02 09:55:03 +00:00
|
|
|
struct pmu_hw_events *cpuc = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-03-05 11:49:32 +00:00
|
|
|
struct pt_regs *regs;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get and reset the IRQ flags
|
|
|
|
*/
|
|
|
|
pmovsr = armv8pmu_getreset_flags();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Did an overflow occur?
|
|
|
|
*/
|
|
|
|
if (!armv8pmu_has_overflowed(pmovsr))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle the counter(s) overflow(s)
|
|
|
|
*/
|
|
|
|
regs = get_irq_regs();
|
|
|
|
|
2018-07-10 08:58:03 +00:00
|
|
|
/*
|
|
|
|
* Stop the PMU while processing the counter overflows
|
|
|
|
* to prevent skews in group events.
|
|
|
|
*/
|
|
|
|
armv8pmu_stop(cpu_pmu);
|
2024-07-31 16:51:18 +00:00
|
|
|
for_each_set_bit(idx, cpu_pmu->cntr_mask, ARMPMU_MAX_HWEVENTS) {
|
2012-03-05 11:49:32 +00:00
|
|
|
struct perf_event *event = cpuc->events[idx];
|
|
|
|
struct hw_perf_event *hwc;
|
|
|
|
|
|
|
|
/* Ignore if we don't have an event. */
|
|
|
|
if (!event)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have a single interrupt for all counters. Check that
|
|
|
|
* each counter has overflowed before we process it.
|
|
|
|
*/
|
|
|
|
if (!armv8pmu_counter_has_overflowed(pmovsr, idx))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hwc = &event->hw;
|
2015-10-02 09:55:03 +00:00
|
|
|
armpmu_event_update(event);
|
2012-03-05 11:49:32 +00:00
|
|
|
perf_sample_data_init(&data, 0, hwc->last_period);
|
2015-10-02 09:55:03 +00:00
|
|
|
if (!armpmu_event_set_period(event))
|
2012-03-05 11:49:32 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-24 11:07:03 +00:00
|
|
|
/*
|
|
|
|
* Perf event overflow will queue the processing of the event as
|
|
|
|
* an irq_work which will be taken care of in the handling of
|
|
|
|
* IPI_IRQ_WORK.
|
|
|
|
*/
|
2012-03-05 11:49:32 +00:00
|
|
|
if (perf_event_overflow(event, &data, regs))
|
2015-10-02 09:55:03 +00:00
|
|
|
cpu_pmu->disable(event);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
2018-07-10 08:58:03 +00:00
|
|
|
armv8pmu_start(cpu_pmu);
|
2012-03-05 11:49:32 +00:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2018-07-10 08:58:04 +00:00
|
|
|
static int armv8pmu_get_single_idx(struct pmu_hw_events *cpuc,
|
|
|
|
struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
2024-07-31 16:51:18 +00:00
|
|
|
for_each_set_bit(idx, cpu_pmu->cntr_mask, ARMV8_PMU_MAX_GENERAL_COUNTERS) {
|
2018-07-10 08:58:04 +00:00
|
|
|
if (!test_and_set_bit(idx, cpuc->used_mask))
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int armv8pmu_get_chain_idx(struct pmu_hw_events *cpuc,
|
|
|
|
struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Chaining requires two consecutive event counters, where
|
|
|
|
* the lower idx must be even.
|
|
|
|
*/
|
2024-07-31 16:51:18 +00:00
|
|
|
for_each_set_bit(idx, cpu_pmu->cntr_mask, ARMV8_PMU_MAX_GENERAL_COUNTERS) {
|
|
|
|
if (!(idx & 0x1))
|
|
|
|
continue;
|
2018-07-10 08:58:04 +00:00
|
|
|
if (!test_and_set_bit(idx, cpuc->used_mask)) {
|
|
|
|
/* Check if the preceding even counter is available */
|
|
|
|
if (!test_and_set_bit(idx - 1, cpuc->used_mask))
|
|
|
|
return idx;
|
|
|
|
/* Release the Odd counter */
|
|
|
|
clear_bit(idx, cpuc->used_mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
static int armv8pmu_get_event_idx(struct pmu_hw_events *cpuc,
|
2015-10-02 09:55:03 +00:00
|
|
|
struct perf_event *event)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2015-10-02 09:55:03 +00:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
2016-03-24 16:01:16 +00:00
|
|
|
unsigned long evtype = hwc->config_base & ARMV8_PMU_EVTYPE_EVENT;
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2017-07-01 06:33:35 +00:00
|
|
|
/* Always prefer to place a cycle counter into the cycle counter. */
|
2024-06-26 22:32:25 +00:00
|
|
|
if ((evtype == ARMV8_PMUV3_PERFCTR_CPU_CYCLES) &&
|
|
|
|
!armv8pmu_event_get_threshold(&event->attr)) {
|
2024-07-31 16:51:22 +00:00
|
|
|
if (!test_and_set_bit(ARMV8_PMU_CYCLE_IDX, cpuc->used_mask))
|
|
|
|
return ARMV8_PMU_CYCLE_IDX;
|
2021-12-08 20:11:23 +00:00
|
|
|
else if (armv8pmu_event_is_64bit(event) &&
|
|
|
|
armv8pmu_event_want_user_access(event) &&
|
|
|
|
!armv8pmu_has_long_event(cpu_pmu))
|
|
|
|
return -EAGAIN;
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 16:51:24 +00:00
|
|
|
/*
|
|
|
|
* Always prefer to place a instruction counter into the instruction counter,
|
|
|
|
* but don't expose the instruction counter to userspace access as userspace
|
|
|
|
* may not know how to handle it.
|
|
|
|
*/
|
|
|
|
if ((evtype == ARMV8_PMUV3_PERFCTR_INST_RETIRED) &&
|
|
|
|
!armv8pmu_event_get_threshold(&event->attr) &&
|
|
|
|
test_bit(ARMV8_PMU_INSTR_IDX, cpu_pmu->cntr_mask) &&
|
|
|
|
!armv8pmu_event_want_user_access(event)) {
|
|
|
|
if (!test_and_set_bit(ARMV8_PMU_INSTR_IDX, cpuc->used_mask))
|
|
|
|
return ARMV8_PMU_INSTR_IDX;
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
/*
|
2017-07-01 06:33:35 +00:00
|
|
|
* Otherwise use events counters
|
2012-03-05 11:49:32 +00:00
|
|
|
*/
|
2021-12-08 20:11:23 +00:00
|
|
|
if (armv8pmu_event_is_chained(event))
|
2018-07-10 08:58:04 +00:00
|
|
|
return armv8pmu_get_chain_idx(cpuc, cpu_pmu);
|
|
|
|
else
|
|
|
|
return armv8pmu_get_single_idx(cpuc, cpu_pmu);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 08:58:01 +00:00
|
|
|
static void armv8pmu_clear_event_idx(struct pmu_hw_events *cpuc,
|
2018-07-10 08:58:04 +00:00
|
|
|
struct perf_event *event)
|
2018-07-10 08:58:01 +00:00
|
|
|
{
|
2018-07-10 08:58:04 +00:00
|
|
|
int idx = event->hw.idx;
|
|
|
|
|
|
|
|
clear_bit(idx, cpuc->used_mask);
|
|
|
|
if (armv8pmu_event_is_chained(event))
|
|
|
|
clear_bit(idx - 1, cpuc->used_mask);
|
2018-07-10 08:58:01 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 20:11:23 +00:00
|
|
|
static int armv8pmu_user_event_idx(struct perf_event *event)
|
|
|
|
{
|
|
|
|
if (!sysctl_perf_user_access || !armv8pmu_event_has_user_read(event))
|
|
|
|
return 0;
|
|
|
|
|
2024-07-31 16:51:18 +00:00
|
|
|
return event->hw.idx + 1;
|
2021-12-08 20:11:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
/*
|
2019-01-18 14:02:27 +00:00
|
|
|
* Add an event filter to a given event.
|
2012-03-05 11:49:32 +00:00
|
|
|
*/
|
|
|
|
static int armv8pmu_set_event_filter(struct hw_perf_event *event,
|
|
|
|
struct perf_event_attr *attr)
|
|
|
|
{
|
|
|
|
unsigned long config_base = 0;
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
struct perf_event *perf_event = container_of(attr, struct perf_event,
|
|
|
|
attr);
|
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(perf_event->pmu);
|
|
|
|
u32 th;
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2023-12-11 16:13:21 +00:00
|
|
|
if (attr->exclude_idle) {
|
|
|
|
pr_debug("ARM performance counters do not support mode exclusion\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2017-05-02 16:29:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're running in hyp mode, then we *are* the hypervisor.
|
|
|
|
* Therefore we ignore exclude_hv in this configuration, since
|
|
|
|
* there's no hypervisor to sample anyway. This is consistent
|
|
|
|
* with other architectures (x86 and Power).
|
|
|
|
*/
|
|
|
|
if (is_kernel_in_hyp_mode()) {
|
2019-04-09 19:22:15 +00:00
|
|
|
if (!attr->exclude_kernel && !attr->exclude_host)
|
2017-05-02 16:29:34 +00:00
|
|
|
config_base |= ARMV8_PMU_INCLUDE_EL2;
|
2019-04-09 19:22:15 +00:00
|
|
|
if (attr->exclude_guest)
|
2017-05-02 16:29:34 +00:00
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL1;
|
2019-04-09 19:22:15 +00:00
|
|
|
if (attr->exclude_host)
|
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL0;
|
2017-05-02 16:29:34 +00:00
|
|
|
} else {
|
2019-04-09 19:22:13 +00:00
|
|
|
if (!attr->exclude_hv && !attr->exclude_host)
|
2017-05-02 16:29:34 +00:00
|
|
|
config_base |= ARMV8_PMU_INCLUDE_EL2;
|
|
|
|
}
|
2019-04-09 19:22:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Filter out !VHE kernels and guest kernels
|
|
|
|
*/
|
|
|
|
if (attr->exclude_kernel)
|
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL1;
|
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
if (attr->exclude_user)
|
2016-03-24 16:01:16 +00:00
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL0;
|
2012-03-05 11:49:32 +00:00
|
|
|
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
/*
|
|
|
|
* If FEAT_PMUv3_TH isn't implemented, then THWIDTH (threshold_max) will
|
|
|
|
* be 0 and will also trigger this check, preventing it from being used.
|
|
|
|
*/
|
2024-06-26 22:32:25 +00:00
|
|
|
th = armv8pmu_event_get_threshold(attr);
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
if (th > threshold_max(cpu_pmu)) {
|
|
|
|
pr_debug("PMU event threshold exceeds max value\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2024-06-26 22:32:26 +00:00
|
|
|
if (th) {
|
arm64: perf: Add support for event counting threshold
FEAT_PMUv3_TH (Armv8.8) permits a PMU counter to increment only on
events whose count meets a specified threshold condition. For example if
PMEVTYPERn.TC (Threshold Control) is set to 0b101 (Greater than or
equal, count), and the threshold is set to 2, then the PMU counter will
now only increment by 1 when an event would have previously incremented
the PMU counter by 2 or more on a single processor cycle.
Three new Perf event config fields, 'threshold', 'threshold_compare' and
'threshold_count' have been added to control the feature.
threshold_compare maps to the upper two bits of PMEVTYPERn.TC and
threshold_count maps to the first bit of TC. These separate attributes
have been picked rather than enumerating all the possible combinations
of the TC field as in the Arm ARM. The attributes would be used on a
Perf command line like this:
$ perf stat -e stall_slot/threshold=2,threshold_compare=2/
A new capability for reading out the maximum supported threshold value
has also been added:
$ cat /sys/bus/event_source/devices/armv8_pmuv3/caps/threshold_max
0x000000ff
If a threshold higher than threshold_max is provided, then an error is
generated. If FEAT_PMUv3_TH isn't implemented or a 32 bit kernel is
running, then threshold_max reads zero, and attempting to set a
threshold value will also result in an error.
The threshold is per PMU counter, and there are potentially different
threshold_max values per PMU type on heterogeneous systems.
Bits higher than 32 now need to be written into PMEVTYPER, so
armv8pmu_write_evtype() has to be updated to take an unsigned long value
rather than u32 which gives the correct behavior on both aarch32 and 64.
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-11-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-11 16:13:22 +00:00
|
|
|
config_base |= FIELD_PREP(ARMV8_PMU_EVTYPE_TH, th);
|
|
|
|
config_base |= FIELD_PREP(ARMV8_PMU_EVTYPE_TC,
|
|
|
|
armv8pmu_event_threshold_control(attr));
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
/*
|
|
|
|
* Install the filter into config_base as this is used to
|
|
|
|
* construct the event type.
|
|
|
|
*/
|
|
|
|
event->config_base = config_base;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void armv8pmu_reset(void *info)
|
|
|
|
{
|
2020-03-02 18:17:52 +00:00
|
|
|
struct arm_pmu *cpu_pmu = (struct arm_pmu *)info;
|
2024-07-31 16:51:19 +00:00
|
|
|
u64 pmcr, mask;
|
|
|
|
|
|
|
|
bitmap_to_arr64(&mask, cpu_pmu->cntr_mask, ARMPMU_MAX_HWEVENTS);
|
2020-03-02 18:17:52 +00:00
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
/* The counter and interrupt enable registers are unknown at reset. */
|
2024-07-31 16:51:19 +00:00
|
|
|
armv8pmu_disable_counter(mask);
|
|
|
|
armv8pmu_disable_intens(mask);
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2019-04-09 19:22:13 +00:00
|
|
|
/* Clear the counters we flip at guest entry/exit */
|
2024-07-31 16:51:19 +00:00
|
|
|
kvm_clr_pmu_events(mask);
|
2019-04-09 19:22:13 +00:00
|
|
|
|
2016-02-18 16:50:13 +00:00
|
|
|
/*
|
|
|
|
* Initialize & Reset PMNC. Request overflow interrupt for
|
|
|
|
* 64 bit cycle counter but cheat in armv8pmu_write_counter().
|
|
|
|
*/
|
2020-03-02 18:17:52 +00:00
|
|
|
pmcr = ARMV8_PMU_PMCR_P | ARMV8_PMU_PMCR_C | ARMV8_PMU_PMCR_LC;
|
|
|
|
|
|
|
|
/* Enable long event counter support where available */
|
|
|
|
if (armv8pmu_has_long_event(cpu_pmu))
|
|
|
|
pmcr |= ARMV8_PMU_PMCR_LP;
|
|
|
|
|
|
|
|
armv8pmu_pmcr_write(pmcr);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 09:38:09 +00:00
|
|
|
static int __armv8_pmuv3_map_event_id(struct arm_pmu *armpmu,
|
|
|
|
struct perf_event *event)
|
|
|
|
{
|
|
|
|
if (event->attr.type == PERF_TYPE_HARDWARE &&
|
|
|
|
event->attr.config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) {
|
|
|
|
|
|
|
|
if (test_bit(ARMV8_PMUV3_PERFCTR_BR_RETIRED,
|
|
|
|
armpmu->pmceid_bitmap))
|
|
|
|
return ARMV8_PMUV3_PERFCTR_BR_RETIRED;
|
|
|
|
|
2024-09-06 19:15:39 +00:00
|
|
|
if (test_bit(ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED,
|
|
|
|
armpmu->pmceid_bitmap))
|
|
|
|
return ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED;
|
|
|
|
|
2023-04-11 09:38:09 +00:00
|
|
|
return HW_OP_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return armpmu_map_event(event, &armv8_pmuv3_perf_map,
|
|
|
|
&armv8_pmuv3_perf_cache_map,
|
|
|
|
ARMV8_PMU_EVTYPE_EVENT);
|
|
|
|
}
|
|
|
|
|
2017-08-08 15:58:33 +00:00
|
|
|
static int __armv8_pmuv3_map_event(struct perf_event *event,
|
|
|
|
const unsigned (*extra_event_map)
|
|
|
|
[PERF_COUNT_HW_MAX],
|
|
|
|
const unsigned (*extra_cache_map)
|
|
|
|
[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_COUNT_HW_CACHE_RESULT_MAX])
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2016-09-14 22:32:30 +00:00
|
|
|
int hw_event_id;
|
|
|
|
struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
|
|
|
|
|
2023-04-11 09:38:09 +00:00
|
|
|
hw_event_id = __armv8_pmuv3_map_event_id(armpmu, event);
|
2016-09-14 22:32:30 +00:00
|
|
|
|
2023-02-16 14:12:39 +00:00
|
|
|
/*
|
|
|
|
* CHAIN events only work when paired with an adjacent counter, and it
|
|
|
|
* never makes sense for a user to open one in isolation, as they'll be
|
|
|
|
* rotated arbitrarily.
|
|
|
|
*/
|
|
|
|
if (hw_event_id == ARMV8_PMUV3_PERFCTR_CHAIN)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-07-10 08:58:04 +00:00
|
|
|
if (armv8pmu_event_is_64bit(event))
|
|
|
|
event->hw.flags |= ARMPMU_EVT_64BIT;
|
|
|
|
|
2021-12-08 20:11:23 +00:00
|
|
|
/*
|
|
|
|
* User events must be allocated into a single counter, and so
|
|
|
|
* must not be chained.
|
|
|
|
*
|
|
|
|
* Most 64-bit events require long counter support, but 64-bit
|
|
|
|
* CPU_CYCLES events can be placed into the dedicated cycle
|
|
|
|
* counter when this is free.
|
|
|
|
*/
|
|
|
|
if (armv8pmu_event_want_user_access(event)) {
|
|
|
|
if (!(event->attach_state & PERF_ATTACH_TASK))
|
|
|
|
return -EINVAL;
|
|
|
|
if (armv8pmu_event_is_64bit(event) &&
|
|
|
|
(hw_event_id != ARMV8_PMUV3_PERFCTR_CPU_CYCLES) &&
|
|
|
|
!armv8pmu_has_long_event(armpmu))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
event->hw.flags |= PERF_EVENT_FLAG_USER_READ_CNT;
|
|
|
|
}
|
|
|
|
|
2018-10-06 07:57:38 +00:00
|
|
|
/* Only expose micro/arch events supported by this PMU */
|
2017-08-08 15:58:33 +00:00
|
|
|
if ((hw_event_id > 0) && (hw_event_id < ARMV8_PMUV3_MAX_COMMON_EVENTS)
|
|
|
|
&& test_bit(hw_event_id, armpmu->pmceid_bitmap)) {
|
|
|
|
return hw_event_id;
|
2016-09-14 22:32:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 15:58:33 +00:00
|
|
|
return armpmu_map_event(event, extra_event_map, extra_cache_map,
|
|
|
|
ARMV8_PMU_EVTYPE_EVENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int armv8_pmuv3_map_event(struct perf_event *event)
|
|
|
|
{
|
|
|
|
return __armv8_pmuv3_map_event(event, NULL, NULL);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:55:04 +00:00
|
|
|
static int armv8_a53_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 16:11:27 +00:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL, &armv8_a53_perf_cache_map);
|
2015-10-02 09:55:04 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:55:05 +00:00
|
|
|
static int armv8_a57_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 16:11:27 +00:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL, &armv8_a57_perf_cache_map);
|
2015-10-02 09:55:05 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 16:46:38 +00:00
|
|
|
static int armv8_a73_map_event(struct perf_event *event)
|
|
|
|
{
|
|
|
|
return __armv8_pmuv3_map_event(event, NULL, &armv8_a73_perf_cache_map);
|
|
|
|
}
|
|
|
|
|
2016-02-18 16:50:11 +00:00
|
|
|
static int armv8_thunder_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 16:11:27 +00:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL,
|
2017-08-08 15:58:33 +00:00
|
|
|
&armv8_thunder_perf_cache_map);
|
2016-02-18 16:50:11 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 12:58:45 +00:00
|
|
|
static int armv8_vulcan_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 16:11:27 +00:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL,
|
2017-08-08 15:58:33 +00:00
|
|
|
&armv8_vulcan_perf_cache_map);
|
2016-04-21 12:58:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-11 08:39:56 +00:00
|
|
|
struct armv8pmu_probe_info {
|
|
|
|
struct arm_pmu *pmu;
|
|
|
|
bool present;
|
|
|
|
};
|
|
|
|
|
2016-04-21 12:58:44 +00:00
|
|
|
static void __armv8pmu_probe_pmu(void *info)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2017-04-11 08:39:56 +00:00
|
|
|
struct armv8pmu_probe_info *probe = info;
|
|
|
|
struct arm_pmu *cpu_pmu = probe->pmu;
|
2018-10-05 12:28:07 +00:00
|
|
|
u64 pmceid_raw[2];
|
2016-04-21 12:58:44 +00:00
|
|
|
u32 pmceid[2];
|
2017-04-25 11:08:50 +00:00
|
|
|
int pmuver;
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2023-03-17 19:50:21 +00:00
|
|
|
pmuver = read_pmuver();
|
2023-03-17 19:50:22 +00:00
|
|
|
if (!pmuv3_implemented(pmuver))
|
2017-04-11 08:39:56 +00:00
|
|
|
return;
|
|
|
|
|
2020-03-02 18:17:52 +00:00
|
|
|
cpu_pmu->pmuver = pmuver;
|
2017-04-11 08:39:56 +00:00
|
|
|
probe->present = true;
|
|
|
|
|
2012-03-05 11:49:32 +00:00
|
|
|
/* Read the nb of CNTx counters supported from PMNC */
|
2024-07-31 16:51:18 +00:00
|
|
|
bitmap_set(cpu_pmu->cntr_mask,
|
|
|
|
0, FIELD_GET(ARMV8_PMU_PMCR_N, armv8pmu_pmcr_read()));
|
2012-03-05 11:49:32 +00:00
|
|
|
|
2015-10-02 09:55:03 +00:00
|
|
|
/* Add the CPU cycles counter */
|
2024-07-31 16:51:22 +00:00
|
|
|
set_bit(ARMV8_PMU_CYCLE_IDX, cpu_pmu->cntr_mask);
|
2016-04-21 12:58:44 +00:00
|
|
|
|
2024-07-31 16:51:24 +00:00
|
|
|
/* Add the CPU instructions counter */
|
|
|
|
if (pmuv3_has_icntr())
|
|
|
|
set_bit(ARMV8_PMU_INSTR_IDX, cpu_pmu->cntr_mask);
|
|
|
|
|
2023-03-17 19:50:21 +00:00
|
|
|
pmceid[0] = pmceid_raw[0] = read_pmceid0();
|
|
|
|
pmceid[1] = pmceid_raw[1] = read_pmceid1();
|
2016-04-21 12:58:44 +00:00
|
|
|
|
2018-02-06 23:38:06 +00:00
|
|
|
bitmap_from_arr32(cpu_pmu->pmceid_bitmap,
|
|
|
|
pmceid, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2018-10-05 12:28:07 +00:00
|
|
|
|
|
|
|
pmceid[0] = pmceid_raw[0] >> 32;
|
|
|
|
pmceid[1] = pmceid_raw[1] >> 32;
|
|
|
|
|
|
|
|
bitmap_from_arr32(cpu_pmu->pmceid_ext_bitmap,
|
|
|
|
pmceid, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2020-09-22 05:53:45 +00:00
|
|
|
|
2023-03-17 19:50:21 +00:00
|
|
|
/* store PMMIR register for sysfs */
|
2023-10-13 02:43:54 +00:00
|
|
|
if (is_pmuv3p4(pmuver))
|
2023-03-17 19:50:21 +00:00
|
|
|
cpu_pmu->reg_pmmir = read_pmmir();
|
2020-09-22 05:53:45 +00:00
|
|
|
else
|
|
|
|
cpu_pmu->reg_pmmir = 0;
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 12:58:44 +00:00
|
|
|
static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2017-04-11 08:39:56 +00:00
|
|
|
struct armv8pmu_probe_info probe = {
|
|
|
|
.pmu = cpu_pmu,
|
|
|
|
.present = false,
|
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = smp_call_function_any(&cpu_pmu->supported_cpus,
|
2016-04-21 12:58:44 +00:00
|
|
|
__armv8pmu_probe_pmu,
|
2017-04-11 08:39:56 +00:00
|
|
|
&probe, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return probe.present ? 0 : -ENODEV;
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 20:11:23 +00:00
|
|
|
static void armv8pmu_disable_user_access_ipi(void *unused)
|
|
|
|
{
|
|
|
|
armv8pmu_disable_user_access();
|
|
|
|
}
|
|
|
|
|
sysctl: treewide: constify the ctl_table argument of proc_handlers
const qualify the struct ctl_table argument in the proc_handler function
signatures. This is a prerequisite to moving the static ctl_table
structs into .rodata data which will ensure that proc_handler function
pointers cannot be modified.
This patch has been generated by the following coccinelle script:
```
virtual patch
@r1@
identifier ctl, write, buffer, lenp, ppos;
identifier func !~ "appldata_(timer|interval)_handler|sched_(rt|rr)_handler|rds_tcp_skbuf_handler|proc_sctp_do_(hmac_alg|rto_min|rto_max|udp_port|alpha_beta|auth|probe_interval)";
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos);
@r2@
identifier func, ctl, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos)
{ ... }
@r3@
identifier func;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int , void *, size_t *, loff_t *);
@r4@
identifier func, ctl;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int , void *, size_t *, loff_t *);
@r5@
identifier func, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int write, void *buffer, size_t *lenp, loff_t *ppos);
```
* Code formatting was adjusted in xfs_sysctl.c to comply with code
conventions. The xfs_stats_clear_proc_handler,
xfs_panic_mask_proc_handler and xfs_deprecated_dointvec_minmax where
adjusted.
* The ctl_table argument in proc_watchdog_common was const qualified.
This is called from a proc_handler itself and is calling back into
another proc_handler, making it necessary to change it as part of the
proc_handler migration.
Co-developed-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Co-developed-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: Joel Granados <j.granados@samsung.com>
2024-07-24 18:59:29 +00:00
|
|
|
static int armv8pmu_proc_user_access_handler(const struct ctl_table *table, int write,
|
2021-12-08 20:11:23 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
|
|
|
{
|
|
|
|
int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
|
|
|
|
if (ret || !write || sysctl_perf_user_access)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
on_each_cpu(armv8pmu_disable_user_access_ipi, NULL, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-08 20:11:22 +00:00
|
|
|
static struct ctl_table armv8_pmu_sysctl_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "perf_user_access",
|
|
|
|
.data = &sysctl_perf_user_access,
|
|
|
|
.maxlen = sizeof(unsigned int),
|
|
|
|
.mode = 0644,
|
2021-12-08 20:11:23 +00:00
|
|
|
.proc_handler = armv8pmu_proc_user_access_handler,
|
2021-12-08 20:11:22 +00:00
|
|
|
.extra1 = SYSCTL_ZERO,
|
|
|
|
.extra2 = SYSCTL_ONE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-04 14:57:14 +00:00
|
|
|
static void armv8_pmu_register_sysctl_table(void)
|
|
|
|
{
|
|
|
|
static u32 tbl_registered = 0;
|
|
|
|
|
|
|
|
if (!cmpxchg_relaxed(&tbl_registered, 0, 1))
|
|
|
|
register_sysctl("kernel", armv8_pmu_sysctl_table);
|
|
|
|
}
|
|
|
|
|
2020-02-21 19:35:31 +00:00
|
|
|
static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name,
|
2023-10-16 02:54:36 +00:00
|
|
|
int (*map_event)(struct perf_event *event))
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2017-04-11 08:39:56 +00:00
|
|
|
int ret = armv8pmu_probe_pmu(cpu_pmu);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-10-05 12:26:21 +00:00
|
|
|
cpu_pmu->handle_irq = armv8pmu_handle_irq;
|
|
|
|
cpu_pmu->enable = armv8pmu_enable_event;
|
|
|
|
cpu_pmu->disable = armv8pmu_disable_event;
|
|
|
|
cpu_pmu->read_counter = armv8pmu_read_counter;
|
|
|
|
cpu_pmu->write_counter = armv8pmu_write_counter;
|
|
|
|
cpu_pmu->get_event_idx = armv8pmu_get_event_idx;
|
|
|
|
cpu_pmu->clear_event_idx = armv8pmu_clear_event_idx;
|
|
|
|
cpu_pmu->start = armv8pmu_start;
|
|
|
|
cpu_pmu->stop = armv8pmu_stop;
|
|
|
|
cpu_pmu->reset = armv8pmu_reset;
|
2015-10-02 09:55:04 +00:00
|
|
|
cpu_pmu->set_event_filter = armv8pmu_set_event_filter;
|
2017-04-11 08:39:56 +00:00
|
|
|
|
2021-12-08 20:11:23 +00:00
|
|
|
cpu_pmu->pmu.event_idx = armv8pmu_user_event_idx;
|
|
|
|
|
2020-02-21 19:35:31 +00:00
|
|
|
cpu_pmu->name = name;
|
|
|
|
cpu_pmu->map_event = map_event;
|
2023-10-16 02:54:36 +00:00
|
|
|
cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = &armv8_pmuv3_events_attr_group;
|
|
|
|
cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = &armv8_pmuv3_format_attr_group;
|
|
|
|
cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_CAPS] = &armv8_pmuv3_caps_attr_group;
|
2022-01-04 14:57:14 +00:00
|
|
|
armv8_pmu_register_sysctl_table();
|
2017-04-11 08:39:56 +00:00
|
|
|
return 0;
|
2015-10-02 09:55:04 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 14:16:14 +00:00
|
|
|
#define PMUV3_INIT_SIMPLE(name) \
|
|
|
|
static int name##_pmu_init(struct arm_pmu *cpu_pmu) \
|
|
|
|
{ \
|
2023-10-16 02:54:36 +00:00
|
|
|
return armv8_pmu_init(cpu_pmu, #name, armv8_pmuv3_map_event); \
|
2015-10-02 09:55:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-14 06:16:56 +00:00
|
|
|
#define PMUV3_INIT_MAP_EVENT(name, map_event) \
|
|
|
|
static int name##_pmu_init(struct arm_pmu *cpu_pmu) \
|
|
|
|
{ \
|
|
|
|
return armv8_pmu_init(cpu_pmu, #name, map_event); \
|
|
|
|
}
|
|
|
|
|
2021-12-14 14:16:14 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv8_pmuv3)
|
|
|
|
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_a34)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_a55)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_a65)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_a75)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_a76)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_a77)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_a78)
|
2021-12-14 14:16:15 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_a510)
|
2023-07-06 20:55:04 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_a520)
|
2021-12-14 14:16:15 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_a710)
|
2023-07-06 20:55:04 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_a715)
|
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_a720)
|
2024-06-28 14:56:12 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_a725)
|
2021-12-14 14:16:15 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv8_cortex_x1)
|
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_x2)
|
2023-07-06 20:55:04 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_x3)
|
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_x4)
|
2024-06-28 14:56:12 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_cortex_x925)
|
2021-12-14 14:16:14 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv8_neoverse_e1)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_neoverse_n1)
|
2021-12-14 14:16:15 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_neoverse_n2)
|
2024-06-28 14:56:12 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv9_neoverse_n3)
|
2021-12-14 14:16:15 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv8_neoverse_v1)
|
2024-06-28 14:56:12 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv8_neoverse_v2)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_neoverse_v3)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_neoverse_v3ae)
|
2021-12-14 14:16:14 +00:00
|
|
|
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_nvidia_carmel)
|
|
|
|
PMUV3_INIT_SIMPLE(armv8_nvidia_denver)
|
2020-02-21 19:35:32 +00:00
|
|
|
|
2024-10-26 20:28:09 +00:00
|
|
|
PMUV3_INIT_SIMPLE(armv8_samsung_mongoose)
|
|
|
|
|
2023-11-14 06:16:56 +00:00
|
|
|
PMUV3_INIT_MAP_EVENT(armv8_cortex_a35, armv8_a53_map_event)
|
|
|
|
PMUV3_INIT_MAP_EVENT(armv8_cortex_a53, armv8_a53_map_event)
|
|
|
|
PMUV3_INIT_MAP_EVENT(armv8_cortex_a57, armv8_a57_map_event)
|
|
|
|
PMUV3_INIT_MAP_EVENT(armv8_cortex_a72, armv8_a57_map_event)
|
|
|
|
PMUV3_INIT_MAP_EVENT(armv8_cortex_a73, armv8_a73_map_event)
|
|
|
|
PMUV3_INIT_MAP_EVENT(armv8_cavium_thunder, armv8_thunder_map_event)
|
|
|
|
PMUV3_INIT_MAP_EVENT(armv8_brcm_vulcan, armv8_vulcan_map_event)
|
2016-04-21 12:58:45 +00:00
|
|
|
|
2015-10-02 09:55:03 +00:00
|
|
|
static const struct of_device_id armv8_pmu_of_device_ids[] = {
|
2021-12-14 14:16:14 +00:00
|
|
|
{.compatible = "arm,armv8-pmuv3", .data = armv8_pmuv3_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a34-pmu", .data = armv8_cortex_a34_pmu_init},
|
2023-11-14 06:16:56 +00:00
|
|
|
{.compatible = "arm,cortex-a35-pmu", .data = armv8_cortex_a35_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a53-pmu", .data = armv8_cortex_a53_pmu_init},
|
2021-12-14 14:16:14 +00:00
|
|
|
{.compatible = "arm,cortex-a55-pmu", .data = armv8_cortex_a55_pmu_init},
|
2023-11-14 06:16:56 +00:00
|
|
|
{.compatible = "arm,cortex-a57-pmu", .data = armv8_cortex_a57_pmu_init},
|
2021-12-14 14:16:14 +00:00
|
|
|
{.compatible = "arm,cortex-a65-pmu", .data = armv8_cortex_a65_pmu_init},
|
2023-11-14 06:16:56 +00:00
|
|
|
{.compatible = "arm,cortex-a72-pmu", .data = armv8_cortex_a72_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a73-pmu", .data = armv8_cortex_a73_pmu_init},
|
2021-12-14 14:16:14 +00:00
|
|
|
{.compatible = "arm,cortex-a75-pmu", .data = armv8_cortex_a75_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a76-pmu", .data = armv8_cortex_a76_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a77-pmu", .data = armv8_cortex_a77_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a78-pmu", .data = armv8_cortex_a78_pmu_init},
|
2021-12-14 14:16:15 +00:00
|
|
|
{.compatible = "arm,cortex-a510-pmu", .data = armv9_cortex_a510_pmu_init},
|
2023-07-06 20:55:04 +00:00
|
|
|
{.compatible = "arm,cortex-a520-pmu", .data = armv9_cortex_a520_pmu_init},
|
2021-12-14 14:16:15 +00:00
|
|
|
{.compatible = "arm,cortex-a710-pmu", .data = armv9_cortex_a710_pmu_init},
|
2023-07-06 20:55:04 +00:00
|
|
|
{.compatible = "arm,cortex-a715-pmu", .data = armv9_cortex_a715_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a720-pmu", .data = armv9_cortex_a720_pmu_init},
|
2024-06-28 14:56:12 +00:00
|
|
|
{.compatible = "arm,cortex-a725-pmu", .data = armv9_cortex_a725_pmu_init},
|
2021-12-14 14:16:15 +00:00
|
|
|
{.compatible = "arm,cortex-x1-pmu", .data = armv8_cortex_x1_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-x2-pmu", .data = armv9_cortex_x2_pmu_init},
|
2023-07-06 20:55:04 +00:00
|
|
|
{.compatible = "arm,cortex-x3-pmu", .data = armv9_cortex_x3_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-x4-pmu", .data = armv9_cortex_x4_pmu_init},
|
2024-06-28 14:56:12 +00:00
|
|
|
{.compatible = "arm,cortex-x925-pmu", .data = armv9_cortex_x925_pmu_init},
|
2021-12-14 14:16:14 +00:00
|
|
|
{.compatible = "arm,neoverse-e1-pmu", .data = armv8_neoverse_e1_pmu_init},
|
|
|
|
{.compatible = "arm,neoverse-n1-pmu", .data = armv8_neoverse_n1_pmu_init},
|
2021-12-14 14:16:15 +00:00
|
|
|
{.compatible = "arm,neoverse-n2-pmu", .data = armv9_neoverse_n2_pmu_init},
|
2024-06-28 14:56:12 +00:00
|
|
|
{.compatible = "arm,neoverse-n3-pmu", .data = armv9_neoverse_n3_pmu_init},
|
2021-12-14 14:16:15 +00:00
|
|
|
{.compatible = "arm,neoverse-v1-pmu", .data = armv8_neoverse_v1_pmu_init},
|
2024-06-28 14:56:12 +00:00
|
|
|
{.compatible = "arm,neoverse-v2-pmu", .data = armv8_neoverse_v2_pmu_init},
|
|
|
|
{.compatible = "arm,neoverse-v3-pmu", .data = armv8_neoverse_v3_pmu_init},
|
|
|
|
{.compatible = "arm,neoverse-v3ae-pmu", .data = armv8_neoverse_v3ae_pmu_init},
|
2023-11-14 06:16:56 +00:00
|
|
|
{.compatible = "cavium,thunder-pmu", .data = armv8_cavium_thunder_pmu_init},
|
|
|
|
{.compatible = "brcm,vulcan-pmu", .data = armv8_brcm_vulcan_pmu_init},
|
2021-12-14 14:16:14 +00:00
|
|
|
{.compatible = "nvidia,carmel-pmu", .data = armv8_nvidia_carmel_pmu_init},
|
|
|
|
{.compatible = "nvidia,denver-pmu", .data = armv8_nvidia_denver_pmu_init},
|
2024-10-26 20:28:09 +00:00
|
|
|
{.compatible = "samsung,mongoose-pmu", .data = armv8_samsung_mongoose_pmu_init},
|
2012-03-05 11:49:32 +00:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2015-10-02 09:55:03 +00:00
|
|
|
static int armv8_pmu_device_probe(struct platform_device *pdev)
|
2012-03-05 11:49:32 +00:00
|
|
|
{
|
2017-04-11 08:39:57 +00:00
|
|
|
return arm_pmu_device_probe(pdev, armv8_pmu_of_device_ids, NULL);
|
2012-03-05 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 09:55:03 +00:00
|
|
|
static struct platform_driver armv8_pmu_driver = {
|
2012-03-05 11:49:32 +00:00
|
|
|
.driver = {
|
2016-09-14 22:32:31 +00:00
|
|
|
.name = ARMV8_PMU_PDEV_NAME,
|
2015-10-02 09:55:03 +00:00
|
|
|
.of_match_table = armv8_pmu_of_device_ids,
|
2018-10-17 15:26:22 +00:00
|
|
|
.suppress_bind_attrs = true,
|
2012-03-05 11:49:32 +00:00
|
|
|
},
|
2015-10-02 09:55:03 +00:00
|
|
|
.probe = armv8_pmu_device_probe,
|
2012-03-05 11:49:32 +00:00
|
|
|
};
|
|
|
|
|
2017-04-11 08:39:57 +00:00
|
|
|
static int __init armv8_pmu_driver_init(void)
|
|
|
|
{
|
2023-05-19 17:18:42 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-04-11 08:39:57 +00:00
|
|
|
if (acpi_disabled)
|
2023-05-19 17:18:42 +00:00
|
|
|
ret = platform_driver_register(&armv8_pmu_driver);
|
2017-04-11 08:39:57 +00:00
|
|
|
else
|
2023-05-19 17:18:42 +00:00
|
|
|
ret = arm_pmu_acpi_probe(armv8_pmuv3_pmu_init);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
lockup_detector_retry_init();
|
|
|
|
|
|
|
|
return ret;
|
2017-04-11 08:39:57 +00:00
|
|
|
}
|
|
|
|
device_initcall(armv8_pmu_driver_init)
|
arm64: perf: Add cap_user_time aarch64
It is useful to get the running time of a thread. Doing so in an
efficient manner can be important for performance of user applications.
Avoiding system calls in `clock_gettime` when handling
CLOCK_THREAD_CPUTIME_ID is important. Other clocks are handled in the
VDSO, but CLOCK_THREAD_CPUTIME_ID falls back on the system call.
CLOCK_THREAD_CPUTIME_ID is not handled in the VDSO since it would have
costs associated with maintaining updated user space accessible time
offsets. These offsets have to be updated everytime the a thread is
scheduled/descheduled. However, for programs regularly checking the
running time of a thread, this is a performance improvement.
This patch takes a middle ground, and adds support for cap_user_time an
optional feature of the perf_event API. This way costs are only
incurred when the perf_event api is enabled. This is done the same way
as it is in x86.
Ultimately this allows calculating the thread running time in userspace
on aarch64 as follows (adapted from perf_event_open manpage):
u32 seq, time_mult, time_shift;
u64 running, count, time_offset, quot, rem, delta;
struct perf_event_mmap_page *pc;
pc = buf; // buf is the perf event mmaped page as documented in the API.
if (pc->cap_usr_time) {
do {
seq = pc->lock;
barrier();
running = pc->time_running;
count = readCNTVCT_EL0(); // Read ARM hardware clock.
time_offset = pc->time_offset;
time_mult = pc->time_mult;
time_shift = pc->time_shift;
barrier();
} while (pc->lock != seq);
quot = (count >> time_shift);
rem = count & (((u64)1 << time_shift) - 1);
delta = time_offset + quot * time_mult +
((rem * time_mult) >> time_shift);
running += delta;
// running now has the current nanosecond level thread time.
}
Summary of changes in the patch:
For aarch64 systems, make arch_perf_update_userpage update the timing
information stored in the perf_event page. Requiring the following
calculations:
- Calculate the appropriate time_mult, and time_shift factors to convert
ticks to nano seconds for the current clock frequency.
- Adjust the mult and shift factors to avoid shift factors of 32 bits.
(possibly unnecessary)
- The time_offset userspace should apply when doing calculations:
negative the current sched time (now), because time_running and
time_enabled fields of the perf_event page have just been updated.
Toggle bits to appropriate values:
- Enable cap_user_time
Signed-off-by: Michael O'Farrell <micpof@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2018-07-30 20:14:34 +00:00
|
|
|
|
|
|
|
void arch_perf_update_userpage(struct perf_event *event,
|
|
|
|
struct perf_event_mmap_page *userpg, u64 now)
|
|
|
|
{
|
2020-07-16 05:11:26 +00:00
|
|
|
struct clock_read_data *rd;
|
|
|
|
unsigned int seq;
|
|
|
|
u64 ns;
|
arm64: perf: Add cap_user_time aarch64
It is useful to get the running time of a thread. Doing so in an
efficient manner can be important for performance of user applications.
Avoiding system calls in `clock_gettime` when handling
CLOCK_THREAD_CPUTIME_ID is important. Other clocks are handled in the
VDSO, but CLOCK_THREAD_CPUTIME_ID falls back on the system call.
CLOCK_THREAD_CPUTIME_ID is not handled in the VDSO since it would have
costs associated with maintaining updated user space accessible time
offsets. These offsets have to be updated everytime the a thread is
scheduled/descheduled. However, for programs regularly checking the
running time of a thread, this is a performance improvement.
This patch takes a middle ground, and adds support for cap_user_time an
optional feature of the perf_event API. This way costs are only
incurred when the perf_event api is enabled. This is done the same way
as it is in x86.
Ultimately this allows calculating the thread running time in userspace
on aarch64 as follows (adapted from perf_event_open manpage):
u32 seq, time_mult, time_shift;
u64 running, count, time_offset, quot, rem, delta;
struct perf_event_mmap_page *pc;
pc = buf; // buf is the perf event mmaped page as documented in the API.
if (pc->cap_usr_time) {
do {
seq = pc->lock;
barrier();
running = pc->time_running;
count = readCNTVCT_EL0(); // Read ARM hardware clock.
time_offset = pc->time_offset;
time_mult = pc->time_mult;
time_shift = pc->time_shift;
barrier();
} while (pc->lock != seq);
quot = (count >> time_shift);
rem = count & (((u64)1 << time_shift) - 1);
delta = time_offset + quot * time_mult +
((rem * time_mult) >> time_shift);
running += delta;
// running now has the current nanosecond level thread time.
}
Summary of changes in the patch:
For aarch64 systems, make arch_perf_update_userpage update the timing
information stored in the perf_event page. Requiring the following
calculations:
- Calculate the appropriate time_mult, and time_shift factors to convert
ticks to nano seconds for the current clock frequency.
- Adjust the mult and shift factors to avoid shift factors of 32 bits.
(possibly unnecessary)
- The time_offset userspace should apply when doing calculations:
negative the current sched time (now), because time_running and
time_enabled fields of the perf_event page have just been updated.
Toggle bits to appropriate values:
- Enable cap_user_time
Signed-off-by: Michael O'Farrell <micpof@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2018-07-30 20:14:34 +00:00
|
|
|
|
2020-07-16 05:11:27 +00:00
|
|
|
userpg->cap_user_time = 0;
|
|
|
|
userpg->cap_user_time_zero = 0;
|
2020-07-16 05:11:29 +00:00
|
|
|
userpg->cap_user_time_short = 0;
|
2021-12-08 20:11:23 +00:00
|
|
|
userpg->cap_user_rdpmc = armv8pmu_event_has_user_read(event);
|
|
|
|
|
|
|
|
if (userpg->cap_user_rdpmc) {
|
|
|
|
if (event->hw.flags & ARMPMU_EVT_64BIT)
|
|
|
|
userpg->pmc_width = 64;
|
|
|
|
else
|
|
|
|
userpg->pmc_width = 32;
|
|
|
|
}
|
2020-07-16 05:11:26 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
rd = sched_clock_read_begin(&seq);
|
|
|
|
|
2020-07-16 05:11:27 +00:00
|
|
|
if (rd->read_sched_clock != arch_timer_read_counter)
|
|
|
|
return;
|
|
|
|
|
2020-07-16 05:11:26 +00:00
|
|
|
userpg->time_mult = rd->mult;
|
|
|
|
userpg->time_shift = rd->shift;
|
|
|
|
userpg->time_zero = rd->epoch_ns;
|
2020-07-16 05:11:29 +00:00
|
|
|
userpg->time_cycles = rd->epoch_cyc;
|
|
|
|
userpg->time_mask = rd->sched_clock_mask;
|
2020-07-16 05:11:26 +00:00
|
|
|
|
|
|
|
/*
|
2020-07-16 05:11:29 +00:00
|
|
|
* Subtract the cycle base, such that software that
|
|
|
|
* doesn't know about cap_user_time_short still 'works'
|
|
|
|
* assuming no wraps.
|
2020-07-16 05:11:26 +00:00
|
|
|
*/
|
|
|
|
ns = mul_u64_u32_shr(rd->epoch_cyc, rd->mult, rd->shift);
|
|
|
|
userpg->time_zero -= ns;
|
|
|
|
|
|
|
|
} while (sched_clock_read_retry(seq));
|
|
|
|
|
|
|
|
userpg->time_offset = userpg->time_zero - now;
|
arm64: perf: Add cap_user_time aarch64
It is useful to get the running time of a thread. Doing so in an
efficient manner can be important for performance of user applications.
Avoiding system calls in `clock_gettime` when handling
CLOCK_THREAD_CPUTIME_ID is important. Other clocks are handled in the
VDSO, but CLOCK_THREAD_CPUTIME_ID falls back on the system call.
CLOCK_THREAD_CPUTIME_ID is not handled in the VDSO since it would have
costs associated with maintaining updated user space accessible time
offsets. These offsets have to be updated everytime the a thread is
scheduled/descheduled. However, for programs regularly checking the
running time of a thread, this is a performance improvement.
This patch takes a middle ground, and adds support for cap_user_time an
optional feature of the perf_event API. This way costs are only
incurred when the perf_event api is enabled. This is done the same way
as it is in x86.
Ultimately this allows calculating the thread running time in userspace
on aarch64 as follows (adapted from perf_event_open manpage):
u32 seq, time_mult, time_shift;
u64 running, count, time_offset, quot, rem, delta;
struct perf_event_mmap_page *pc;
pc = buf; // buf is the perf event mmaped page as documented in the API.
if (pc->cap_usr_time) {
do {
seq = pc->lock;
barrier();
running = pc->time_running;
count = readCNTVCT_EL0(); // Read ARM hardware clock.
time_offset = pc->time_offset;
time_mult = pc->time_mult;
time_shift = pc->time_shift;
barrier();
} while (pc->lock != seq);
quot = (count >> time_shift);
rem = count & (((u64)1 << time_shift) - 1);
delta = time_offset + quot * time_mult +
((rem * time_mult) >> time_shift);
running += delta;
// running now has the current nanosecond level thread time.
}
Summary of changes in the patch:
For aarch64 systems, make arch_perf_update_userpage update the timing
information stored in the perf_event page. Requiring the following
calculations:
- Calculate the appropriate time_mult, and time_shift factors to convert
ticks to nano seconds for the current clock frequency.
- Adjust the mult and shift factors to avoid shift factors of 32 bits.
(possibly unnecessary)
- The time_offset userspace should apply when doing calculations:
negative the current sched time (now), because time_running and
time_enabled fields of the perf_event page have just been updated.
Toggle bits to appropriate values:
- Enable cap_user_time
Signed-off-by: Michael O'Farrell <micpof@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2018-07-30 20:14:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* time_shift is not expected to be greater than 31 due to
|
|
|
|
* the original published conversion algorithm shifting a
|
|
|
|
* 32-bit value (now specifies a 64-bit value) - refer
|
|
|
|
* perf_event_mmap_page documentation in perf_event.h.
|
|
|
|
*/
|
2020-07-16 05:11:26 +00:00
|
|
|
if (userpg->time_shift == 32) {
|
|
|
|
userpg->time_shift = 31;
|
arm64: perf: Add cap_user_time aarch64
It is useful to get the running time of a thread. Doing so in an
efficient manner can be important for performance of user applications.
Avoiding system calls in `clock_gettime` when handling
CLOCK_THREAD_CPUTIME_ID is important. Other clocks are handled in the
VDSO, but CLOCK_THREAD_CPUTIME_ID falls back on the system call.
CLOCK_THREAD_CPUTIME_ID is not handled in the VDSO since it would have
costs associated with maintaining updated user space accessible time
offsets. These offsets have to be updated everytime the a thread is
scheduled/descheduled. However, for programs regularly checking the
running time of a thread, this is a performance improvement.
This patch takes a middle ground, and adds support for cap_user_time an
optional feature of the perf_event API. This way costs are only
incurred when the perf_event api is enabled. This is done the same way
as it is in x86.
Ultimately this allows calculating the thread running time in userspace
on aarch64 as follows (adapted from perf_event_open manpage):
u32 seq, time_mult, time_shift;
u64 running, count, time_offset, quot, rem, delta;
struct perf_event_mmap_page *pc;
pc = buf; // buf is the perf event mmaped page as documented in the API.
if (pc->cap_usr_time) {
do {
seq = pc->lock;
barrier();
running = pc->time_running;
count = readCNTVCT_EL0(); // Read ARM hardware clock.
time_offset = pc->time_offset;
time_mult = pc->time_mult;
time_shift = pc->time_shift;
barrier();
} while (pc->lock != seq);
quot = (count >> time_shift);
rem = count & (((u64)1 << time_shift) - 1);
delta = time_offset + quot * time_mult +
((rem * time_mult) >> time_shift);
running += delta;
// running now has the current nanosecond level thread time.
}
Summary of changes in the patch:
For aarch64 systems, make arch_perf_update_userpage update the timing
information stored in the perf_event page. Requiring the following
calculations:
- Calculate the appropriate time_mult, and time_shift factors to convert
ticks to nano seconds for the current clock frequency.
- Adjust the mult and shift factors to avoid shift factors of 32 bits.
(possibly unnecessary)
- The time_offset userspace should apply when doing calculations:
negative the current sched time (now), because time_running and
time_enabled fields of the perf_event page have just been updated.
Toggle bits to appropriate values:
- Enable cap_user_time
Signed-off-by: Michael O'Farrell <micpof@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2018-07-30 20:14:34 +00:00
|
|
|
userpg->time_mult >>= 1;
|
|
|
|
}
|
2020-07-16 05:11:26 +00:00
|
|
|
|
2020-07-16 05:11:27 +00:00
|
|
|
/*
|
|
|
|
* Internal timekeeping for enabled/running/stopped times
|
|
|
|
* is always computed with the sched_clock.
|
|
|
|
*/
|
|
|
|
userpg->cap_user_time = 1;
|
|
|
|
userpg->cap_user_time_zero = 1;
|
2020-07-16 05:11:29 +00:00
|
|
|
userpg->cap_user_time_short = 1;
|
arm64: perf: Add cap_user_time aarch64
It is useful to get the running time of a thread. Doing so in an
efficient manner can be important for performance of user applications.
Avoiding system calls in `clock_gettime` when handling
CLOCK_THREAD_CPUTIME_ID is important. Other clocks are handled in the
VDSO, but CLOCK_THREAD_CPUTIME_ID falls back on the system call.
CLOCK_THREAD_CPUTIME_ID is not handled in the VDSO since it would have
costs associated with maintaining updated user space accessible time
offsets. These offsets have to be updated everytime the a thread is
scheduled/descheduled. However, for programs regularly checking the
running time of a thread, this is a performance improvement.
This patch takes a middle ground, and adds support for cap_user_time an
optional feature of the perf_event API. This way costs are only
incurred when the perf_event api is enabled. This is done the same way
as it is in x86.
Ultimately this allows calculating the thread running time in userspace
on aarch64 as follows (adapted from perf_event_open manpage):
u32 seq, time_mult, time_shift;
u64 running, count, time_offset, quot, rem, delta;
struct perf_event_mmap_page *pc;
pc = buf; // buf is the perf event mmaped page as documented in the API.
if (pc->cap_usr_time) {
do {
seq = pc->lock;
barrier();
running = pc->time_running;
count = readCNTVCT_EL0(); // Read ARM hardware clock.
time_offset = pc->time_offset;
time_mult = pc->time_mult;
time_shift = pc->time_shift;
barrier();
} while (pc->lock != seq);
quot = (count >> time_shift);
rem = count & (((u64)1 << time_shift) - 1);
delta = time_offset + quot * time_mult +
((rem * time_mult) >> time_shift);
running += delta;
// running now has the current nanosecond level thread time.
}
Summary of changes in the patch:
For aarch64 systems, make arch_perf_update_userpage update the timing
information stored in the perf_event page. Requiring the following
calculations:
- Calculate the appropriate time_mult, and time_shift factors to convert
ticks to nano seconds for the current clock frequency.
- Adjust the mult and shift factors to avoid shift factors of 32 bits.
(possibly unnecessary)
- The time_offset userspace should apply when doing calculations:
negative the current sched time (now), because time_running and
time_enabled fields of the perf_event page have just been updated.
Toggle bits to appropriate values:
- Enable cap_user_time
Signed-off-by: Michael O'Farrell <micpof@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2018-07-30 20:14:34 +00:00
|
|
|
}
|