2019-06-03 12:44:50 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-03-05 18:49:32 +07:00
|
|
|
/*
|
2018-10-05 19:31:10 +07:00
|
|
|
* ARMv8 PMUv3 Performance Events handling code.
|
2012-03-05 18:49:32 +07: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 23:01:16 +07:00
|
|
|
#include <asm/perf_event.h>
|
2016-04-21 19:58:43 +07:00
|
|
|
#include <asm/sysreg.h>
|
2016-01-26 00:31:13 +07:00
|
|
|
#include <asm/virt.h>
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2016-09-15 05:32:29 +07:00
|
|
|
#include <linux/acpi.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-31 03:14:34 +07:00
|
|
|
#include <linux/clocksource.h>
|
2019-04-10 02:22:13 +07:00
|
|
|
#include <linux/kvm_host.h>
|
2015-10-02 16:55:03 +07:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/perf/arm_pmu.h>
|
|
|
|
#include <linux/platform_device.h>
|
2019-08-20 22:57:45 +07:00
|
|
|
#include <linux/smp.h>
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2015-10-02 16:55:04 +07:00
|
|
|
/* ARMv8 Cortex-A53 specific event types. */
|
2016-04-21 19:58:41 +07:00
|
|
|
#define ARMV8_A53_PERFCTR_PREF_LINEFILL 0xC2
|
2015-10-02 16:55:04 +07:00
|
|
|
|
2016-02-18 23:50:11 +07:00
|
|
|
/* ARMv8 Cavium ThunderX specific event types. */
|
2016-04-21 19:58:41 +07: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 16:55:05 +07:00
|
|
|
|
2016-09-15 05:32:30 +07:00
|
|
|
/*
|
|
|
|
* ARMv8 Architectural defined events, not all of these may
|
2018-10-05 19:28:07 +07:00
|
|
|
* be supported on any given implementation. Unsupported events will
|
|
|
|
* be disabled at run-time based on the PMCEID registers.
|
2016-09-15 05:32:30 +07:00
|
|
|
*/
|
2012-03-05 18:49:32 +07:00
|
|
|
static const unsigned armv8_pmuv3_perf_map[PERF_COUNT_HW_MAX] = {
|
2015-07-21 17:36:39 +07:00
|
|
|
PERF_MAP_ALL_UNSUPPORTED,
|
2016-04-21 19:58:41 +07: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,
|
2016-09-15 05:32:30 +07:00
|
|
|
[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED,
|
2016-04-21 19:58:41 +07:00
|
|
|
[PERF_COUNT_HW_BRANCH_MISSES] = ARMV8_PMUV3_PERFCTR_BR_MIS_PRED,
|
2016-09-15 05:32:30 +07: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 18:49:32 +07: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 17:36:39 +07:00
|
|
|
PERF_CACHE_MAP_ALL_UNSUPPORTED,
|
|
|
|
|
2016-04-21 19:58:41 +07: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 17:36:39 +07:00
|
|
|
|
2016-09-15 05:32:30 +07: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,
|
|
|
|
|
2016-04-21 19:58:41 +07: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 18:49:32 +07:00
|
|
|
};
|
|
|
|
|
2015-10-02 16:55:04 +07: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 19:58:41 +07:00
|
|
|
[C(L1D)][C(OP_PREFETCH)][C(RESULT_MISS)] = ARMV8_A53_PERFCTR_PREF_LINEFILL,
|
2015-10-02 16:55:04 +07:00
|
|
|
|
2017-07-25 23:27:36 +07: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 16:55:04 +07:00
|
|
|
};
|
|
|
|
|
2015-10-02 16:55:05 +07: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 19:58:41 +07: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 16:55:05 +07:00
|
|
|
|
2016-04-21 19:58:41 +07: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 16:55:05 +07:00
|
|
|
|
2017-07-25 23:27:36 +07: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 16:55:05 +07:00
|
|
|
};
|
|
|
|
|
2017-08-09 23:46:38 +07: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 23:50:11 +07: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 19:58:41 +07: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 16:55:05 +07:00
|
|
|
};
|
|
|
|
|
2016-04-21 19:58:45 +07: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 19:58:44 +07: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);
|
|
|
|
|
|
|
|
return sprintf(page, "event=0x%03llx\n", pmu_attr->id);
|
|
|
|
}
|
|
|
|
|
2019-10-30 10:46:17 +07:00
|
|
|
#define ARMV8_EVENT_ATTR(name, config) \
|
|
|
|
(&((struct perf_pmu_events_attr) { \
|
|
|
|
.attr = __ATTR(name, 0444, armv8pmu_events_sysfs_show, NULL), \
|
|
|
|
.id = config, \
|
|
|
|
}).attr.attr)
|
2015-10-22 21:07:32 +07:00
|
|
|
|
|
|
|
static struct attribute *armv8_pmuv3_event_attrs[] = {
|
2019-10-30 10:46:17 +07:00
|
|
|
ARMV8_EVENT_ATTR(sw_incr, ARMV8_PMUV3_PERFCTR_SW_INCR),
|
|
|
|
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),
|
|
|
|
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),
|
2015-12-22 21:42:57 +07:00
|
|
|
NULL,
|
2015-10-22 21:07:32 +07:00
|
|
|
};
|
|
|
|
|
2016-04-21 19:58:44 +07: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 19:28:07 +07:00
|
|
|
if (pmu_attr->id < ARMV8_PMUV3_MAX_COMMON_EVENTS &&
|
|
|
|
test_bit(pmu_attr->id, cpu_pmu->pmceid_bitmap))
|
|
|
|
return attr->mode;
|
|
|
|
|
|
|
|
pmu_attr->id -= ARMV8_PMUV3_EXT_COMMON_EVENT_BASE;
|
|
|
|
if (pmu_attr->id < ARMV8_PMUV3_MAX_COMMON_EVENTS &&
|
|
|
|
test_bit(pmu_attr->id, cpu_pmu->pmceid_ext_bitmap))
|
2016-04-21 19:58:44 +07:00
|
|
|
return attr->mode;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-22 21:07:32 +07:00
|
|
|
static struct attribute_group armv8_pmuv3_events_attr_group = {
|
|
|
|
.name = "events",
|
|
|
|
.attrs = armv8_pmuv3_event_attrs,
|
2016-04-21 19:58:44 +07:00
|
|
|
.is_visible = armv8pmu_event_attr_is_visible,
|
2015-10-22 21:07:32 +07:00
|
|
|
};
|
|
|
|
|
2017-05-24 14:43:18 +07:00
|
|
|
PMU_FORMAT_ATTR(event, "config:0-15");
|
2018-07-10 15:58:04 +07:00
|
|
|
PMU_FORMAT_ATTR(long, "config1:0");
|
|
|
|
|
|
|
|
static inline bool armv8pmu_event_is_64bit(struct perf_event *event)
|
|
|
|
{
|
|
|
|
return event->attr.config1 & 0x1;
|
|
|
|
}
|
2015-12-22 21:42:57 +07:00
|
|
|
|
|
|
|
static struct attribute *armv8_pmuv3_format_attrs[] = {
|
|
|
|
&format_attr_event.attr,
|
2018-07-10 15:58:04 +07:00
|
|
|
&format_attr_long.attr,
|
2015-12-22 21:42:57 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group armv8_pmuv3_format_attr_group = {
|
|
|
|
.name = "format",
|
|
|
|
.attrs = armv8_pmuv3_format_attrs,
|
|
|
|
};
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
/*
|
|
|
|
* Perf Events' indices
|
|
|
|
*/
|
|
|
|
#define ARMV8_IDX_CYCLE_COUNTER 0
|
|
|
|
#define ARMV8_IDX_COUNTER0 1
|
2015-10-02 16:55:03 +07:00
|
|
|
#define ARMV8_IDX_COUNTER_LAST(cpu_pmu) \
|
|
|
|
(ARMV8_IDX_CYCLE_COUNTER + cpu_pmu->num_events - 1)
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2020-03-03 01:17:52 +07: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.
|
|
|
|
*/
|
|
|
|
static bool armv8pmu_has_long_event(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return (cpu_pmu->pmuver >= ID_AA64DFR0_PMUVER_8_5);
|
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
/*
|
|
|
|
* We must chain two programmable counters for 64 bit events,
|
|
|
|
* except when we have allocated the 64bit cycle counter (for CPU
|
|
|
|
* cycles event). This must be called only when the event has
|
|
|
|
* a counter allocated.
|
|
|
|
*/
|
|
|
|
static inline bool armv8pmu_event_is_chained(struct perf_event *event)
|
|
|
|
{
|
|
|
|
int idx = event->hw.idx;
|
2020-03-03 01:17:52 +07:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
2018-07-10 15:58:04 +07:00
|
|
|
|
|
|
|
return !WARN_ON(idx < 0) &&
|
|
|
|
armv8pmu_event_is_64bit(event) &&
|
2020-03-03 01:17:52 +07:00
|
|
|
!armv8pmu_has_long_event(cpu_pmu) &&
|
2018-07-10 15:58:04 +07:00
|
|
|
(idx != ARMV8_IDX_CYCLE_COUNTER);
|
|
|
|
}
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
/*
|
|
|
|
* ARMv8 low level PMU access
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perf Event to low level counters mapping
|
|
|
|
*/
|
|
|
|
#define ARMV8_IDX_TO_COUNTER(x) \
|
2016-03-24 23:01:16 +07:00
|
|
|
(((x) - ARMV8_IDX_COUNTER0) & ARMV8_PMU_COUNTER_MASK)
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
static inline u32 armv8pmu_pmcr_read(void)
|
|
|
|
{
|
2016-04-21 19:58:43 +07:00
|
|
|
return read_sysreg(pmcr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void armv8pmu_pmcr_write(u32 val)
|
|
|
|
{
|
2016-03-24 23:01:16 +07:00
|
|
|
val &= ARMV8_PMU_PMCR_MASK;
|
2012-03-05 18:49:32 +07:00
|
|
|
isb();
|
2016-04-21 19:58:43 +07:00
|
|
|
write_sysreg(val, pmcr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int armv8pmu_has_overflowed(u32 pmovsr)
|
|
|
|
{
|
2016-03-24 23:01:16 +07:00
|
|
|
return pmovsr & ARMV8_PMU_OVERFLOWED_MASK;
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
static inline int armv8pmu_counter_valid(struct arm_pmu *cpu_pmu, int idx)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2015-10-02 16:55:03 +07:00
|
|
|
return idx >= ARMV8_IDX_CYCLE_COUNTER &&
|
|
|
|
idx <= ARMV8_IDX_COUNTER_LAST(cpu_pmu);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int armv8pmu_counter_has_overflowed(u32 pmnc, int idx)
|
|
|
|
{
|
2015-10-02 16:55:03 +07:00
|
|
|
return pmnc & BIT(ARMV8_IDX_TO_COUNTER(idx));
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:02 +07:00
|
|
|
static inline void armv8pmu_select_counter(int idx)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2015-10-02 16:55:03 +07:00
|
|
|
u32 counter = ARMV8_IDX_TO_COUNTER(idx);
|
2016-04-21 19:58:43 +07:00
|
|
|
write_sysreg(counter, pmselr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
isb();
|
2018-07-10 15:58:02 +07:00
|
|
|
}
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2020-03-03 01:17:52 +07:00
|
|
|
static inline u64 armv8pmu_read_evcntr(int idx)
|
2018-07-10 15:58:02 +07:00
|
|
|
{
|
|
|
|
armv8pmu_select_counter(idx);
|
|
|
|
return read_sysreg(pmxevcntr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
static inline u64 armv8pmu_read_hw_counter(struct perf_event *event)
|
|
|
|
{
|
|
|
|
int idx = event->hw.idx;
|
|
|
|
u64 val = 0;
|
|
|
|
|
|
|
|
val = armv8pmu_read_evcntr(idx);
|
|
|
|
if (armv8pmu_event_is_chained(event))
|
|
|
|
val = (val << 32) | armv8pmu_read_evcntr(idx - 1);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:17:52 +07: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) ||
|
|
|
|
idx == ARMV8_IDX_CYCLE_COUNTER)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 armv8pmu_bias_long_counter(struct perf_event *event, u64 value)
|
|
|
|
{
|
|
|
|
if (armv8pmu_event_needs_bias(event))
|
|
|
|
value |= GENMASK(63, 32);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 armv8pmu_unbias_long_counter(struct perf_event *event, u64 value)
|
|
|
|
{
|
|
|
|
if (armv8pmu_event_needs_bias(event))
|
|
|
|
value &= ~GENMASK(63, 32);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-04-11 23:16:46 +07:00
|
|
|
static u64 armv8pmu_read_counter(struct perf_event *event)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2015-10-02 16:55:03 +07:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int idx = hwc->idx;
|
2018-07-10 15:58:04 +07:00
|
|
|
u64 value = 0;
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
if (!armv8pmu_counter_valid(cpu_pmu, idx))
|
2012-03-05 18:49:32 +07:00
|
|
|
pr_err("CPU%u reading wrong counter %d\n",
|
|
|
|
smp_processor_id(), idx);
|
|
|
|
else if (idx == ARMV8_IDX_CYCLE_COUNTER)
|
2016-04-21 19:58:43 +07:00
|
|
|
value = read_sysreg(pmccntr_el0);
|
2018-07-10 15:58:02 +07:00
|
|
|
else
|
2018-07-10 15:58:04 +07:00
|
|
|
value = armv8pmu_read_hw_counter(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2020-03-03 01:17:52 +07:00
|
|
|
return armv8pmu_unbias_long_counter(event, value);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2020-03-03 01:17:52 +07:00
|
|
|
static inline void armv8pmu_write_evcntr(int idx, u64 value)
|
2018-07-10 15:58:02 +07:00
|
|
|
{
|
|
|
|
armv8pmu_select_counter(idx);
|
|
|
|
write_sysreg(value, pmxevcntr_el0);
|
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
static inline void armv8pmu_write_hw_counter(struct perf_event *event,
|
|
|
|
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 23:16:46 +07:00
|
|
|
static void armv8pmu_write_counter(struct perf_event *event, u64 value)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2015-10-02 16:55:03 +07:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
|
|
|
int idx = hwc->idx;
|
|
|
|
|
2020-03-03 01:17:52 +07:00
|
|
|
value = armv8pmu_bias_long_counter(event, value);
|
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
if (!armv8pmu_counter_valid(cpu_pmu, idx))
|
2012-03-05 18:49:32 +07:00
|
|
|
pr_err("CPU%u writing wrong counter %d\n",
|
|
|
|
smp_processor_id(), idx);
|
2020-03-03 01:17:52 +07:00
|
|
|
else if (idx == ARMV8_IDX_CYCLE_COUNTER)
|
2018-07-10 15:57:59 +07:00
|
|
|
write_sysreg(value, pmccntr_el0);
|
2020-03-03 01:17:52 +07:00
|
|
|
else
|
2018-07-10 15:58:04 +07:00
|
|
|
armv8pmu_write_hw_counter(event, value);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void armv8pmu_write_evtype(int idx, u32 val)
|
|
|
|
{
|
2018-07-10 15:58:02 +07:00
|
|
|
armv8pmu_select_counter(idx);
|
|
|
|
val &= ARMV8_PMU_EVTYPE_MASK;
|
|
|
|
write_sysreg(val, pmxevtyper_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
static inline void armv8pmu_write_event_type(struct perf_event *event)
|
|
|
|
{
|
|
|
|
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 {
|
|
|
|
armv8pmu_write_evtype(idx, hwc->config_base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
static u32 armv8pmu_event_cnten_mask(struct perf_event *event)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2020-03-18 01:22:54 +07:00
|
|
|
int counter = ARMV8_IDX_TO_COUNTER(event->hw.idx);
|
|
|
|
u32 mask = BIT(counter);
|
|
|
|
|
|
|
|
if (armv8pmu_event_is_chained(event))
|
|
|
|
mask |= BIT(counter - 1);
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void armv8pmu_enable_counter(u32 mask)
|
|
|
|
{
|
|
|
|
write_sysreg(mask, pmcntenset_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
static inline void armv8pmu_enable_event_counter(struct perf_event *event)
|
|
|
|
{
|
2019-04-10 02:22:13 +07:00
|
|
|
struct perf_event_attr *attr = &event->attr;
|
2020-03-18 01:22:54 +07:00
|
|
|
u32 mask = armv8pmu_event_cnten_mask(event);
|
2019-04-10 02:22:13 +07:00
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
kvm_set_pmu_events(mask, attr);
|
2019-04-10 02:22:13 +07:00
|
|
|
|
|
|
|
/* We rely on the hypervisor switch code to enable guest counters */
|
2020-03-18 01:22:54 +07:00
|
|
|
if (!kvm_pmu_counter_deferred(attr))
|
|
|
|
armv8pmu_enable_counter(mask);
|
2018-07-10 15:58:04 +07:00
|
|
|
}
|
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
static inline void armv8pmu_disable_counter(u32 mask)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2020-03-18 01:22:54 +07:00
|
|
|
write_sysreg(mask, pmcntenclr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
static inline void armv8pmu_disable_event_counter(struct perf_event *event)
|
|
|
|
{
|
2019-04-10 02:22:13 +07:00
|
|
|
struct perf_event_attr *attr = &event->attr;
|
2020-03-18 01:22:54 +07:00
|
|
|
u32 mask = armv8pmu_event_cnten_mask(event);
|
2018-07-10 15:58:04 +07:00
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
kvm_clr_pmu_events(mask);
|
2019-04-10 02:22:13 +07:00
|
|
|
|
|
|
|
/* We rely on the hypervisor switch code to disable guest counters */
|
2020-03-18 01:22:54 +07:00
|
|
|
if (!kvm_pmu_counter_deferred(attr))
|
|
|
|
armv8pmu_disable_counter(mask);
|
2018-07-10 15:58:04 +07:00
|
|
|
}
|
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
static inline void armv8pmu_enable_intens(u32 mask)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2020-03-18 01:22:54 +07:00
|
|
|
write_sysreg(mask, pmintenset_el1);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
static inline void armv8pmu_enable_event_irq(struct perf_event *event)
|
2018-07-10 15:58:04 +07:00
|
|
|
{
|
2020-03-18 01:22:54 +07:00
|
|
|
u32 counter = ARMV8_IDX_TO_COUNTER(event->hw.idx);
|
|
|
|
armv8pmu_enable_intens(BIT(counter));
|
2018-07-10 15:58:04 +07:00
|
|
|
}
|
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
static inline void armv8pmu_disable_intens(u32 mask)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2020-03-18 01:22:54 +07:00
|
|
|
write_sysreg(mask, pmintenclr_el1);
|
2012-03-05 18:49:32 +07:00
|
|
|
isb();
|
|
|
|
/* Clear the overflow flag in case an interrupt is pending. */
|
2020-03-18 01:22:54 +07:00
|
|
|
write_sysreg(mask, pmovsclr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
2020-03-18 01:22:54 +07:00
|
|
|
static inline void armv8pmu_disable_event_irq(struct perf_event *event)
|
2018-07-10 15:58:04 +07:00
|
|
|
{
|
2020-03-18 01:22:54 +07:00
|
|
|
u32 counter = ARMV8_IDX_TO_COUNTER(event->hw.idx);
|
|
|
|
armv8pmu_disable_intens(BIT(counter));
|
2018-07-10 15:58:04 +07:00
|
|
|
}
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
static inline u32 armv8pmu_getreset_flags(void)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
|
|
|
|
/* Read */
|
2016-04-21 19:58:43 +07:00
|
|
|
value = read_sysreg(pmovsclr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/* Write to clear flags */
|
2016-03-24 23:01:16 +07:00
|
|
|
value &= ARMV8_PMU_OVSR_MASK;
|
2016-04-21 19:58:43 +07:00
|
|
|
write_sysreg(value, pmovsclr_el0);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
static void armv8pmu_enable_event(struct perf_event *event)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2015-10-02 16:55:03 +07:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable counter and interrupt, and set the counter to count
|
|
|
|
* the event that we're interested in.
|
|
|
|
*/
|
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable counter
|
|
|
|
*/
|
2018-07-10 15:58:04 +07:00
|
|
|
armv8pmu_disable_event_counter(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set event (if destined for PMNx counters).
|
|
|
|
*/
|
2018-07-10 15:58:04 +07:00
|
|
|
armv8pmu_write_event_type(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable interrupt for this counter
|
|
|
|
*/
|
2018-07-10 15:58:04 +07:00
|
|
|
armv8pmu_enable_event_irq(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable counter
|
|
|
|
*/
|
2018-07-10 15:58:04 +07:00
|
|
|
armv8pmu_enable_event_counter(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
static void armv8pmu_disable_event(struct perf_event *event)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2015-10-02 16:55:03 +07:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable counter and interrupt
|
|
|
|
*/
|
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable counter
|
|
|
|
*/
|
2018-07-10 15:58:04 +07:00
|
|
|
armv8pmu_disable_event_counter(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable interrupt for this counter
|
|
|
|
*/
|
2018-07-10 15:58:04 +07:00
|
|
|
armv8pmu_disable_event_irq(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:03 +07:00
|
|
|
static void armv8pmu_start(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
|
|
|
|
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
|
|
|
/* Enable all counters */
|
|
|
|
armv8pmu_pmcr_write(armv8pmu_pmcr_read() | ARMV8_PMU_PMCR_E);
|
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void armv8pmu_stop(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct pmu_hw_events *events = this_cpu_ptr(cpu_pmu->hw_events);
|
|
|
|
|
|
|
|
raw_spin_lock_irqsave(&events->pmu_lock, flags);
|
|
|
|
/* Disable all counters */
|
|
|
|
armv8pmu_pmcr_write(armv8pmu_pmcr_read() & ~ARMV8_PMU_PMCR_E);
|
|
|
|
raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
|
|
|
|
}
|
|
|
|
|
2018-05-10 17:35:15 +07:00
|
|
|
static irqreturn_t armv8pmu_handle_irq(struct arm_pmu *cpu_pmu)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
|
|
|
u32 pmovsr;
|
|
|
|
struct perf_sample_data data;
|
2015-10-02 16:55:03 +07:00
|
|
|
struct pmu_hw_events *cpuc = this_cpu_ptr(cpu_pmu->hw_events);
|
2012-03-05 18:49:32 +07: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 15:58:03 +07:00
|
|
|
/*
|
|
|
|
* Stop the PMU while processing the counter overflows
|
|
|
|
* to prevent skews in group events.
|
|
|
|
*/
|
|
|
|
armv8pmu_stop(cpu_pmu);
|
2012-03-05 18:49:32 +07:00
|
|
|
for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
|
|
|
|
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 16:55:03 +07:00
|
|
|
armpmu_event_update(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
perf_sample_data_init(&data, 0, hwc->last_period);
|
2015-10-02 16:55:03 +07:00
|
|
|
if (!armpmu_event_set_period(event))
|
2012-03-05 18:49:32 +07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (perf_event_overflow(event, &data, regs))
|
2015-10-02 16:55:03 +07:00
|
|
|
cpu_pmu->disable(event);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
2018-07-10 15:58:03 +07:00
|
|
|
armv8pmu_start(cpu_pmu);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle the pending perf events.
|
|
|
|
*
|
|
|
|
* Note: this call *must* be run with interrupts disabled. For
|
|
|
|
* platforms that can have the PMU interrupts raised as an NMI, this
|
|
|
|
* will not work.
|
|
|
|
*/
|
|
|
|
irq_work_run();
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
static int armv8pmu_get_single_idx(struct pmu_hw_events *cpuc,
|
|
|
|
struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
for (idx = ARMV8_IDX_COUNTER0; idx < cpu_pmu->num_events; idx ++) {
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
for (idx = ARMV8_IDX_COUNTER0 + 1; idx < cpu_pmu->num_events; idx += 2) {
|
|
|
|
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 18:49:32 +07:00
|
|
|
static int armv8pmu_get_event_idx(struct pmu_hw_events *cpuc,
|
2015-10-02 16:55:03 +07:00
|
|
|
struct perf_event *event)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2015-10-02 16:55:03 +07:00
|
|
|
struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
|
|
|
|
struct hw_perf_event *hwc = &event->hw;
|
2016-03-24 23:01:16 +07:00
|
|
|
unsigned long evtype = hwc->config_base & ARMV8_PMU_EVTYPE_EVENT;
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2017-07-01 13:33:35 +07:00
|
|
|
/* Always prefer to place a cycle counter into the cycle counter. */
|
2016-04-21 19:58:41 +07:00
|
|
|
if (evtype == ARMV8_PMUV3_PERFCTR_CPU_CYCLES) {
|
2017-07-01 13:33:35 +07:00
|
|
|
if (!test_and_set_bit(ARMV8_IDX_CYCLE_COUNTER, cpuc->used_mask))
|
|
|
|
return ARMV8_IDX_CYCLE_COUNTER;
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-07-01 13:33:35 +07:00
|
|
|
* Otherwise use events counters
|
2012-03-05 18:49:32 +07:00
|
|
|
*/
|
2020-03-03 01:17:52 +07:00
|
|
|
if (armv8pmu_event_is_64bit(event) &&
|
|
|
|
!armv8pmu_has_long_event(cpu_pmu))
|
2018-07-10 15:58:04 +07:00
|
|
|
return armv8pmu_get_chain_idx(cpuc, cpu_pmu);
|
|
|
|
else
|
|
|
|
return armv8pmu_get_single_idx(cpuc, cpu_pmu);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2018-07-10 15:58:01 +07:00
|
|
|
static void armv8pmu_clear_event_idx(struct pmu_hw_events *cpuc,
|
2018-07-10 15:58:04 +07:00
|
|
|
struct perf_event *event)
|
2018-07-10 15:58:01 +07:00
|
|
|
{
|
2018-07-10 15:58:04 +07: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 15:58:01 +07:00
|
|
|
}
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
/*
|
2019-01-18 21:02:27 +07:00
|
|
|
* Add an event filter to a given event.
|
2012-03-05 18:49:32 +07:00
|
|
|
*/
|
|
|
|
static int armv8pmu_set_event_filter(struct hw_perf_event *event,
|
|
|
|
struct perf_event_attr *attr)
|
|
|
|
{
|
|
|
|
unsigned long config_base = 0;
|
|
|
|
|
|
|
|
if (attr->exclude_idle)
|
|
|
|
return -EPERM;
|
2017-05-02 23:29:34 +07: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-10 02:22:15 +07:00
|
|
|
if (!attr->exclude_kernel && !attr->exclude_host)
|
2017-05-02 23:29:34 +07:00
|
|
|
config_base |= ARMV8_PMU_INCLUDE_EL2;
|
2019-04-10 02:22:15 +07:00
|
|
|
if (attr->exclude_guest)
|
2017-05-02 23:29:34 +07:00
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL1;
|
2019-04-10 02:22:15 +07:00
|
|
|
if (attr->exclude_host)
|
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL0;
|
2017-05-02 23:29:34 +07:00
|
|
|
} else {
|
2019-04-10 02:22:13 +07:00
|
|
|
if (!attr->exclude_hv && !attr->exclude_host)
|
2017-05-02 23:29:34 +07:00
|
|
|
config_base |= ARMV8_PMU_INCLUDE_EL2;
|
|
|
|
}
|
2019-04-10 02:22:13 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Filter out !VHE kernels and guest kernels
|
|
|
|
*/
|
|
|
|
if (attr->exclude_kernel)
|
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL1;
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
if (attr->exclude_user)
|
2016-03-24 23:01:16 +07:00
|
|
|
config_base |= ARMV8_PMU_EXCLUDE_EL0;
|
2012-03-05 18:49:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Install the filter into config_base as this is used to
|
|
|
|
* construct the event type.
|
|
|
|
*/
|
|
|
|
event->config_base = config_base;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-05 19:24:36 +07:00
|
|
|
static int armv8pmu_filter_match(struct perf_event *event)
|
|
|
|
{
|
|
|
|
unsigned long evtype = event->hw.config_base & ARMV8_PMU_EVTYPE_EVENT;
|
|
|
|
return evtype != ARMV8_PMUV3_PERFCTR_CHAIN;
|
|
|
|
}
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
static void armv8pmu_reset(void *info)
|
|
|
|
{
|
2020-03-03 01:17:52 +07:00
|
|
|
struct arm_pmu *cpu_pmu = (struct arm_pmu *)info;
|
|
|
|
u32 pmcr;
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
/* The counter and interrupt enable registers are unknown at reset. */
|
2020-03-18 01:22:54 +07:00
|
|
|
armv8pmu_disable_counter(U32_MAX);
|
|
|
|
armv8pmu_disable_intens(U32_MAX);
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2019-04-10 02:22:13 +07:00
|
|
|
/* Clear the counters we flip at guest entry/exit */
|
|
|
|
kvm_clr_pmu_events(U32_MAX);
|
|
|
|
|
2016-02-18 23:50:13 +07:00
|
|
|
/*
|
|
|
|
* Initialize & Reset PMNC. Request overflow interrupt for
|
|
|
|
* 64 bit cycle counter but cheat in armv8pmu_write_counter().
|
|
|
|
*/
|
2020-03-03 01:17:52 +07: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 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2017-08-08 22:58:33 +07: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 18:49:32 +07:00
|
|
|
{
|
2016-09-15 05:32:30 +07:00
|
|
|
int hw_event_id;
|
|
|
|
struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
|
|
|
|
|
|
|
|
hw_event_id = armpmu_map_event(event, &armv8_pmuv3_perf_map,
|
|
|
|
&armv8_pmuv3_perf_cache_map,
|
|
|
|
ARMV8_PMU_EVTYPE_EVENT);
|
|
|
|
|
2018-07-10 15:58:04 +07:00
|
|
|
if (armv8pmu_event_is_64bit(event))
|
|
|
|
event->hw.flags |= ARMPMU_EVT_64BIT;
|
|
|
|
|
2018-10-06 14:57:38 +07:00
|
|
|
/* Only expose micro/arch events supported by this PMU */
|
2017-08-08 22:58:33 +07: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-15 05:32:30 +07:00
|
|
|
}
|
|
|
|
|
2017-08-08 22:58:33 +07: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 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:04 +07:00
|
|
|
static int armv8_a53_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 23:11:27 +07:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL, &armv8_a53_perf_cache_map);
|
2015-10-02 16:55:04 +07:00
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:05 +07:00
|
|
|
static int armv8_a57_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 23:11:27 +07:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL, &armv8_a57_perf_cache_map);
|
2015-10-02 16:55:05 +07:00
|
|
|
}
|
|
|
|
|
2017-08-09 23:46:38 +07: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 23:50:11 +07:00
|
|
|
static int armv8_thunder_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 23:11:27 +07:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL,
|
2017-08-08 22:58:33 +07:00
|
|
|
&armv8_thunder_perf_cache_map);
|
2016-02-18 23:50:11 +07:00
|
|
|
}
|
|
|
|
|
2016-04-21 19:58:45 +07:00
|
|
|
static int armv8_vulcan_map_event(struct perf_event *event)
|
|
|
|
{
|
2017-08-08 23:11:27 +07:00
|
|
|
return __armv8_pmuv3_map_event(event, NULL,
|
2017-08-08 22:58:33 +07:00
|
|
|
&armv8_vulcan_perf_cache_map);
|
2016-04-21 19:58:45 +07:00
|
|
|
}
|
|
|
|
|
2017-04-11 15:39:56 +07:00
|
|
|
struct armv8pmu_probe_info {
|
|
|
|
struct arm_pmu *pmu;
|
|
|
|
bool present;
|
|
|
|
};
|
|
|
|
|
2016-04-21 19:58:44 +07:00
|
|
|
static void __armv8pmu_probe_pmu(void *info)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2017-04-11 15:39:56 +07:00
|
|
|
struct armv8pmu_probe_info *probe = info;
|
|
|
|
struct arm_pmu *cpu_pmu = probe->pmu;
|
2017-04-25 18:08:50 +07:00
|
|
|
u64 dfr0;
|
2018-10-05 19:28:07 +07:00
|
|
|
u64 pmceid_raw[2];
|
2016-04-21 19:58:44 +07:00
|
|
|
u32 pmceid[2];
|
2017-04-25 18:08:50 +07:00
|
|
|
int pmuver;
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2017-04-11 15:39:56 +07:00
|
|
|
dfr0 = read_sysreg(id_aa64dfr0_el1);
|
2018-02-15 00:21:57 +07:00
|
|
|
pmuver = cpuid_feature_extract_unsigned_field(dfr0,
|
2017-04-11 15:39:56 +07:00
|
|
|
ID_AA64DFR0_PMUVER_SHIFT);
|
2018-02-15 00:21:57 +07:00
|
|
|
if (pmuver == 0xf || pmuver == 0)
|
2017-04-11 15:39:56 +07:00
|
|
|
return;
|
|
|
|
|
2020-03-03 01:17:52 +07:00
|
|
|
cpu_pmu->pmuver = pmuver;
|
2017-04-11 15:39:56 +07:00
|
|
|
probe->present = true;
|
|
|
|
|
2012-03-05 18:49:32 +07:00
|
|
|
/* Read the nb of CNTx counters supported from PMNC */
|
2016-04-21 19:58:44 +07:00
|
|
|
cpu_pmu->num_events = (armv8pmu_pmcr_read() >> ARMV8_PMU_PMCR_N_SHIFT)
|
|
|
|
& ARMV8_PMU_PMCR_N_MASK;
|
2012-03-05 18:49:32 +07:00
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
/* Add the CPU cycles counter */
|
2016-04-21 19:58:44 +07:00
|
|
|
cpu_pmu->num_events += 1;
|
|
|
|
|
2018-10-05 19:28:07 +07:00
|
|
|
pmceid[0] = pmceid_raw[0] = read_sysreg(pmceid0_el0);
|
|
|
|
pmceid[1] = pmceid_raw[1] = read_sysreg(pmceid1_el0);
|
2016-04-21 19:58:44 +07:00
|
|
|
|
2018-02-07 06:38:06 +07:00
|
|
|
bitmap_from_arr32(cpu_pmu->pmceid_bitmap,
|
|
|
|
pmceid, ARMV8_PMUV3_MAX_COMMON_EVENTS);
|
2018-10-05 19:28:07 +07: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);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2016-04-21 19:58:44 +07:00
|
|
|
static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2017-04-11 15:39:56 +07: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 19:58:44 +07:00
|
|
|
__armv8pmu_probe_pmu,
|
2017-04-11 15:39:56 +07:00
|
|
|
&probe, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return probe.present ? 0 : -ENODEV;
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2020-02-22 02:35:31 +07:00
|
|
|
static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name,
|
|
|
|
int (*map_event)(struct perf_event *event),
|
|
|
|
const struct attribute_group *events,
|
|
|
|
const struct attribute_group *format)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2017-04-11 15:39:56 +07:00
|
|
|
int ret = armv8pmu_probe_pmu(cpu_pmu);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-10-05 19:26:21 +07: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 16:55:04 +07:00
|
|
|
cpu_pmu->set_event_filter = armv8pmu_set_event_filter;
|
2018-10-05 19:24:36 +07:00
|
|
|
cpu_pmu->filter_match = armv8pmu_filter_match;
|
2017-04-11 15:39:56 +07:00
|
|
|
|
2020-02-22 02:35:31 +07:00
|
|
|
cpu_pmu->name = name;
|
|
|
|
cpu_pmu->map_event = map_event;
|
|
|
|
cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = events ?
|
|
|
|
events : &armv8_pmuv3_events_attr_group;
|
|
|
|
cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = format ?
|
|
|
|
format : &armv8_pmuv3_format_attr_group;
|
|
|
|
|
2017-04-11 15:39:56 +07:00
|
|
|
return 0;
|
2015-10-02 16:55:04 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int armv8_pmuv3_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_pmuv3",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
2015-10-02 16:55:04 +07:00
|
|
|
}
|
|
|
|
|
2020-02-22 02:35:32 +07:00
|
|
|
static int armv8_a34_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a34",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2017-08-09 23:46:39 +07:00
|
|
|
static int armv8_a35_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a35",
|
|
|
|
armv8_a53_map_event, NULL, NULL);
|
2017-08-09 23:46:39 +07:00
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:04 +07:00
|
|
|
static int armv8_a53_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a53",
|
|
|
|
armv8_a53_map_event, NULL, NULL);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2020-02-22 02:35:32 +07:00
|
|
|
static int armv8_a55_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a55",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:05 +07:00
|
|
|
static int armv8_a57_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a57",
|
|
|
|
armv8_a57_map_event, NULL, NULL);
|
2015-10-02 16:55:05 +07:00
|
|
|
}
|
|
|
|
|
2020-02-22 02:35:32 +07:00
|
|
|
static int armv8_a65_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a65",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2015-12-22 21:45:35 +07:00
|
|
|
static int armv8_a72_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a72",
|
|
|
|
armv8_a57_map_event, NULL, NULL);
|
2015-12-22 21:45:35 +07:00
|
|
|
}
|
|
|
|
|
2017-08-09 23:46:38 +07:00
|
|
|
static int armv8_a73_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a73",
|
|
|
|
armv8_a73_map_event, NULL, NULL);
|
2017-08-09 23:46:38 +07:00
|
|
|
}
|
|
|
|
|
2020-02-22 02:35:32 +07:00
|
|
|
static int armv8_a75_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a75",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int armv8_a76_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a76",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int armv8_a77_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cortex_a77",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int armv8_e1_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_neoverse_e1",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int armv8_n1_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_neoverse_n1",
|
|
|
|
armv8_pmuv3_map_event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-18 23:50:11 +07:00
|
|
|
static int armv8_thunder_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_cavium_thunder",
|
|
|
|
armv8_thunder_map_event, NULL, NULL);
|
2016-02-18 23:50:11 +07:00
|
|
|
}
|
|
|
|
|
2016-04-21 19:58:45 +07:00
|
|
|
static int armv8_vulcan_pmu_init(struct arm_pmu *cpu_pmu)
|
|
|
|
{
|
2020-02-22 02:35:31 +07:00
|
|
|
return armv8_pmu_init(cpu_pmu, "armv8_brcm_vulcan",
|
|
|
|
armv8_vulcan_map_event, NULL, NULL);
|
2016-04-21 19:58:45 +07:00
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
static const struct of_device_id armv8_pmu_of_device_ids[] = {
|
|
|
|
{.compatible = "arm,armv8-pmuv3", .data = armv8_pmuv3_init},
|
2020-02-22 02:35:32 +07:00
|
|
|
{.compatible = "arm,cortex-a34-pmu", .data = armv8_a34_pmu_init},
|
2017-08-09 23:46:39 +07:00
|
|
|
{.compatible = "arm,cortex-a35-pmu", .data = armv8_a35_pmu_init},
|
2015-10-02 16:55:04 +07:00
|
|
|
{.compatible = "arm,cortex-a53-pmu", .data = armv8_a53_pmu_init},
|
2020-02-22 02:35:32 +07:00
|
|
|
{.compatible = "arm,cortex-a55-pmu", .data = armv8_a55_pmu_init},
|
2015-10-02 16:55:05 +07:00
|
|
|
{.compatible = "arm,cortex-a57-pmu", .data = armv8_a57_pmu_init},
|
2020-02-22 02:35:32 +07:00
|
|
|
{.compatible = "arm,cortex-a65-pmu", .data = armv8_a65_pmu_init},
|
2015-12-22 21:45:35 +07:00
|
|
|
{.compatible = "arm,cortex-a72-pmu", .data = armv8_a72_pmu_init},
|
2017-08-09 23:46:38 +07:00
|
|
|
{.compatible = "arm,cortex-a73-pmu", .data = armv8_a73_pmu_init},
|
2020-02-22 02:35:32 +07:00
|
|
|
{.compatible = "arm,cortex-a75-pmu", .data = armv8_a75_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a76-pmu", .data = armv8_a76_pmu_init},
|
|
|
|
{.compatible = "arm,cortex-a77-pmu", .data = armv8_a77_pmu_init},
|
|
|
|
{.compatible = "arm,neoverse-e1-pmu", .data = armv8_e1_pmu_init},
|
|
|
|
{.compatible = "arm,neoverse-n1-pmu", .data = armv8_n1_pmu_init},
|
2016-02-18 23:50:11 +07:00
|
|
|
{.compatible = "cavium,thunder-pmu", .data = armv8_thunder_pmu_init},
|
2016-04-21 19:58:45 +07:00
|
|
|
{.compatible = "brcm,vulcan-pmu", .data = armv8_vulcan_pmu_init},
|
2012-03-05 18:49:32 +07:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
static int armv8_pmu_device_probe(struct platform_device *pdev)
|
2012-03-05 18:49:32 +07:00
|
|
|
{
|
2017-04-11 15:39:57 +07:00
|
|
|
return arm_pmu_device_probe(pdev, armv8_pmu_of_device_ids, NULL);
|
2012-03-05 18:49:32 +07:00
|
|
|
}
|
|
|
|
|
2015-10-02 16:55:03 +07:00
|
|
|
static struct platform_driver armv8_pmu_driver = {
|
2012-03-05 18:49:32 +07:00
|
|
|
.driver = {
|
2016-09-15 05:32:31 +07:00
|
|
|
.name = ARMV8_PMU_PDEV_NAME,
|
2015-10-02 16:55:03 +07:00
|
|
|
.of_match_table = armv8_pmu_of_device_ids,
|
2018-10-17 22:26:22 +07:00
|
|
|
.suppress_bind_attrs = true,
|
2012-03-05 18:49:32 +07:00
|
|
|
},
|
2015-10-02 16:55:03 +07:00
|
|
|
.probe = armv8_pmu_device_probe,
|
2012-03-05 18:49:32 +07:00
|
|
|
};
|
|
|
|
|
2017-04-11 15:39:57 +07:00
|
|
|
static int __init armv8_pmu_driver_init(void)
|
|
|
|
{
|
|
|
|
if (acpi_disabled)
|
|
|
|
return platform_driver_register(&armv8_pmu_driver);
|
|
|
|
else
|
|
|
|
return arm_pmu_acpi_probe(armv8_pmuv3_init);
|
|
|
|
}
|
|
|
|
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-31 03:14:34 +07:00
|
|
|
|
|
|
|
void arch_perf_update_userpage(struct perf_event *event,
|
|
|
|
struct perf_event_mmap_page *userpg, u64 now)
|
|
|
|
{
|
|
|
|
u32 freq;
|
|
|
|
u32 shift;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal timekeeping for enabled/running/stopped times
|
|
|
|
* is always computed with the sched_clock.
|
|
|
|
*/
|
|
|
|
freq = arch_timer_get_rate();
|
|
|
|
userpg->cap_user_time = 1;
|
|
|
|
|
|
|
|
clocks_calc_mult_shift(&userpg->time_mult, &shift, freq,
|
|
|
|
NSEC_PER_SEC, 0);
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (shift == 32) {
|
|
|
|
shift = 31;
|
|
|
|
userpg->time_mult >>= 1;
|
|
|
|
}
|
|
|
|
userpg->time_shift = (u16)shift;
|
|
|
|
userpg->time_offset = -now;
|
|
|
|
}
|