xref: /openbmc/linux/tools/perf/arch/arm64/util/pmu.c (revision 9d5da30e)
1e126bef5SJohn Garry // SPDX-License-Identifier: GPL-2.0
2e126bef5SJohn Garry 
3c4d9d95fSIan Rogers #include <internal/cpumap.h>
4b96da02bSIan Rogers #include "../../../util/cpumap.h"
5*9d5da30eSJames Clark #include "../../../util/header.h"
6b96da02bSIan Rogers #include "../../../util/pmu.h"
71eaf496eSIan Rogers #include "../../../util/pmus.h"
8acef233bSJing Zhang #include <api/fs/fs.h>
9acef233bSJing Zhang #include <math.h>
10e126bef5SJohn Garry 
pmu_metrics_table__find(void)11f8ea2c15SIan Rogers const struct pmu_metrics_table *pmu_metrics_table__find(void)
12f8ea2c15SIan Rogers {
13f8ea2c15SIan Rogers 	struct perf_pmu *pmu = pmu__find_core_pmu();
14f8ea2c15SIan Rogers 
15f8ea2c15SIan Rogers 	if (pmu)
16f8ea2c15SIan Rogers 		return perf_pmu__find_metrics_table(pmu);
17e126bef5SJohn Garry 
18e126bef5SJohn Garry 	return NULL;
19e126bef5SJohn Garry }
20acef233bSJing Zhang 
pmu_events_table__find(void)21acef233bSJing Zhang const struct pmu_events_table *pmu_events_table__find(void)
22acef233bSJing Zhang {
23acef233bSJing Zhang 	struct perf_pmu *pmu = pmu__find_core_pmu();
24acef233bSJing Zhang 
25acef233bSJing Zhang 	if (pmu)
2696d2a746SIan Rogers 		return perf_pmu__find_events_table(pmu);
27acef233bSJing Zhang 
28acef233bSJing Zhang 	return NULL;
29acef233bSJing Zhang }
30acef233bSJing Zhang 
perf_pmu__cpu_slots_per_cycle(void)31acef233bSJing Zhang double perf_pmu__cpu_slots_per_cycle(void)
32acef233bSJing Zhang {
33acef233bSJing Zhang 	char path[PATH_MAX];
34acef233bSJing Zhang 	unsigned long long slots = 0;
35acef233bSJing Zhang 	struct perf_pmu *pmu = pmu__find_core_pmu();
36acef233bSJing Zhang 
37acef233bSJing Zhang 	if (pmu) {
38f8ad6018SJames Clark 		perf_pmu__pathname_scnprintf(path, sizeof(path),
39f8ad6018SJames Clark 					     pmu->name, "caps/slots");
40acef233bSJing Zhang 		/*
419754353dSHaixin Yu 		 * The value of slots is not greater than 32 bits, but
429754353dSHaixin Yu 		 * filename__read_int can't read value with 0x prefix,
439754353dSHaixin Yu 		 * so use filename__read_ull instead.
44acef233bSJing Zhang 		 */
459754353dSHaixin Yu 		filename__read_ull(path, &slots);
46acef233bSJing Zhang 	}
47acef233bSJing Zhang 
48acef233bSJing Zhang 	return slots ? (double)slots : NAN;
49acef233bSJing Zhang }
50