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