arm64: Fix finding the pmc event ID

The lower pmc event bits were masked off to find the PMC event ID.
The doesn't work when there are more events. Switch it to use the
offser relative to the first event while also checking the ID is
in the expected range.

Reviewed by:	gnn, ray
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D29600
This commit is contained in:
Andrew Turner 2021-04-01 14:38:09 +00:00
parent d6a53211a7
commit 24b2f4ea49
2 changed files with 3 additions and 2 deletions

View File

@ -181,7 +181,9 @@ arm64_allocate_pmc(int cpu, int ri, struct pmc *pm,
}
pe = a->pm_ev;
config = (pe & EVENT_ID_MASK);
config = (uint32_t)pe - PMC_EV_ARMV8_FIRST;
if (config > (PMC_EV_ARMV8_LAST - PMC_EV_ARMV8_FIRST))
return (EINVAL);
pm->pm_md.pm_arm64.pm_arm64_evsel = config;
PMCDBG2(MDP, ALL, 2, "arm64-allocate ri=%d -> config=0x%x", ri, config);

View File

@ -40,7 +40,6 @@
#define ARMV8_RELOAD_COUNT_TO_PERFCTR_VALUE(R) (-(R))
#define ARMV8_PERFCTR_VALUE_TO_RELOAD_COUNT(P) (-(P))
#define EVENT_ID_MASK 0xFF
#ifdef _KERNEL
/* MD extension for 'struct pmc' */