xref: /freebsd/lib/libpmc/libpmc_pmu_util.c (revision 8bed125da7bf33e140386cc47a2432a108e6993b)
1959826caSMatt Macy /*-
2959826caSMatt Macy  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3959826caSMatt Macy  *
4959826caSMatt Macy  * Copyright (c) 2018, Matthew Macy
5959826caSMatt Macy  *
6959826caSMatt Macy  * Redistribution and use in source and binary forms, with or without
7959826caSMatt Macy  * modification, are permitted provided that the following conditions
8959826caSMatt Macy  * are met:
9959826caSMatt Macy  * 1. Redistributions of source code must retain the above copyright
10959826caSMatt Macy  *    notice, this list of conditions and the following disclaimer.
11959826caSMatt Macy  * 2. Redistributions in binary form must reproduce the above copyright
12959826caSMatt Macy  *    notice, this list of conditions and the following disclaimer in the
13959826caSMatt Macy  *    documentation and/or other materials provided with the distribution.
14959826caSMatt Macy  *
15959826caSMatt Macy  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16959826caSMatt Macy  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17959826caSMatt Macy  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18959826caSMatt Macy  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19959826caSMatt Macy  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20959826caSMatt Macy  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21959826caSMatt Macy  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22959826caSMatt Macy  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23959826caSMatt Macy  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24959826caSMatt Macy  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25959826caSMatt Macy  * SUCH DAMAGE.
26959826caSMatt Macy  *
27959826caSMatt Macy  * $FreeBSD$
28959826caSMatt Macy  *
29959826caSMatt Macy  */
30959826caSMatt Macy 
31959826caSMatt Macy #include <sys/types.h>
32959826caSMatt Macy #include <sys/errno.h>
33959826caSMatt Macy #include <sys/sysctl.h>
34959826caSMatt Macy #include <stddef.h>
35959826caSMatt Macy #include <stdlib.h>
36959826caSMatt Macy #include <limits.h>
37959826caSMatt Macy #include <string.h>
38959826caSMatt Macy #include <pmc.h>
39959826caSMatt Macy #include <pmclog.h>
40959826caSMatt Macy #include <libpmcstat.h>
41959826caSMatt Macy #include "pmu-events/pmu-events.h"
42959826caSMatt Macy 
43959826caSMatt Macy #if defined(__amd64__)
44959826caSMatt Macy struct pmu_alias {
45959826caSMatt Macy 	const char *pa_alias;
46959826caSMatt Macy 	const char *pa_name;
47959826caSMatt Macy };
48959826caSMatt Macy static struct pmu_alias pmu_alias_table[] = {
49959826caSMatt Macy     { "UNHALTED_CORE_CYCLES", "CPU_CLK_UNHALTED.THREAD_P_ANY"},
50959826caSMatt Macy     { "UNHALTED-CORE-CYCLES", "CPU_CLK_UNHALTED.THREAD_P_ANY"},
51959826caSMatt Macy 	{ "LLC_MISSES", "LONGEST_LAT_CACHE.MISS"},
52959826caSMatt Macy 	{ "LLC-MISSES", "LONGEST_LAT_CACHE.MISS"},
53959826caSMatt Macy 	{ "LLC_REFERENCE", "LONGEST_LAT_CACHE.REFERENCE"},
54959826caSMatt Macy 	{ "LLC-REFERENCE", "LONGEST_LAT_CACHE.REFERENCE"},
55959826caSMatt Macy 	{ "LLC_MISS_RHITM", "mem_load_l3_miss_retired.remote_hitm"},
56959826caSMatt Macy 	{ "LLC-MISS-RHITM", "mem_load_l3_miss_retired.remote_hitm"},
57959826caSMatt Macy 	{ "RESOURCE_STALL", "RESOURCE_STALLS.ANY"},
58959826caSMatt Macy 	{ "RESOURCE_STALLS_ANY", "RESOURCE_STALLS.ANY"},
59959826caSMatt Macy 	{ "BRANCH_INSTRUCTION_RETIRED", "BR_INST_RETIRED.ALL_BRANCHES"},
60959826caSMatt Macy 	{ "BRANCH-INSTRUCTION-RETIRED", "BR_INST_RETIRED.ALL_BRANCHES"},
61959826caSMatt Macy 	{ "BRANCH_MISSES_RETIRED", "BR_MISP_RETIRED.ALL_BRANCHES"},
62959826caSMatt Macy 	{ "BRANCH-MISSES-RETIRED", "BR_MISP_RETIRED.ALL_BRANCHES"},
63959826caSMatt Macy 	{ NULL, NULL },
64959826caSMatt Macy };
65959826caSMatt Macy 
66a191ed2dSMatt Macy static const char *fixed_mode_cntrs[] = {
67a191ed2dSMatt Macy 	"inst_retired.any",
68a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread",
69a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread_any",
70a191ed2dSMatt Macy 	"cpu_clk_unhalted.ref_tsc",
71a191ed2dSMatt Macy 	NULL
72a191ed2dSMatt Macy };
73a191ed2dSMatt Macy 
74959826caSMatt Macy static const char *
75959826caSMatt Macy pmu_alias_get(const char *name)
76959826caSMatt Macy {
77959826caSMatt Macy 	struct pmu_alias *pa;
78959826caSMatt Macy 
79959826caSMatt Macy 	for (pa = pmu_alias_table; pa->pa_alias != NULL; pa++)
80959826caSMatt Macy 		if (strcasecmp(name, pa->pa_alias) == 0)
81959826caSMatt Macy 			return (pa->pa_name);
82959826caSMatt Macy 	return (name);
83959826caSMatt Macy }
84959826caSMatt Macy 
85959826caSMatt Macy struct pmu_event_desc {
86959826caSMatt Macy 	uint64_t ped_period;
87959826caSMatt Macy 	uint64_t ped_offcore_rsp;
88959826caSMatt Macy 	uint32_t ped_event;
89959826caSMatt Macy 	uint32_t ped_frontend;
90959826caSMatt Macy 	uint32_t ped_ldlat;
91959826caSMatt Macy 	uint32_t ped_config1;
92959826caSMatt Macy 	uint8_t ped_umask;
93959826caSMatt Macy 	uint8_t ped_cmask;
94959826caSMatt Macy 	uint8_t ped_any;
95959826caSMatt Macy 	uint8_t ped_inv;
96959826caSMatt Macy 	uint8_t ped_edge;
97959826caSMatt Macy 	uint8_t ped_fc_mask;
98959826caSMatt Macy 	uint8_t ped_ch_mask;
99959826caSMatt Macy };
100959826caSMatt Macy 
101959826caSMatt Macy static const struct pmu_events_map *
102959826caSMatt Macy pmu_events_map_get(void)
103959826caSMatt Macy {
104959826caSMatt Macy 	size_t s;
105959826caSMatt Macy 	char buf[64];
106959826caSMatt Macy 	const struct pmu_events_map *pme;
107959826caSMatt Macy 
108959826caSMatt Macy 	if (sysctlbyname("kern.hwpmc.cpuid", (void *)NULL, &s,
109959826caSMatt Macy 					 (void *)NULL, 0) == -1)
110959826caSMatt Macy 		return (NULL);
111959826caSMatt Macy 	if (sysctlbyname("kern.hwpmc.cpuid", buf, &s,
112959826caSMatt Macy 					 (void *)NULL, 0) == -1)
113959826caSMatt Macy 		return (NULL);
114959826caSMatt Macy 	for (pme = pmu_events_map; pme->cpuid != NULL; pme++)
115959826caSMatt Macy 		if (strcmp(buf, pme->cpuid) == 0)
116959826caSMatt Macy 			return (pme);
117959826caSMatt Macy 	return (NULL);
118959826caSMatt Macy }
119959826caSMatt Macy 
120959826caSMatt Macy static const struct pmu_event *
121959826caSMatt Macy pmu_event_get(const char *event_name, int *idx)
122959826caSMatt Macy {
123959826caSMatt Macy 	const struct pmu_events_map *pme;
124959826caSMatt Macy 	const struct pmu_event *pe;
125959826caSMatt Macy 	int i;
126959826caSMatt Macy 
127959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
128959826caSMatt Macy 		return (NULL);
129959826caSMatt Macy 	for (i = 0, pe = pme->table; pe->name || pe->desc || pe->event; pe++, i++) {
130959826caSMatt Macy 		if (pe->name == NULL)
131959826caSMatt Macy 			continue;
132959826caSMatt Macy 		if (strcasecmp(pe->name, event_name) == 0) {
133959826caSMatt Macy 			if (idx)
134959826caSMatt Macy 				*idx = i;
135959826caSMatt Macy 			return (pe);
136959826caSMatt Macy 		}
137959826caSMatt Macy 	}
138959826caSMatt Macy 	return (NULL);
139959826caSMatt Macy }
140959826caSMatt Macy 
141959826caSMatt Macy const char *
14278beed2fSMatt Macy pmc_pmu_event_get_by_idx(int idx)
143959826caSMatt Macy {
144959826caSMatt Macy 	const struct pmu_events_map *pme;
145959826caSMatt Macy 	const struct pmu_event *pe;
146959826caSMatt Macy 	int i;
147959826caSMatt Macy 
148959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
149959826caSMatt Macy 		return (NULL);
150959826caSMatt Macy 	for (i = 0, pe = pme->table; (pe->name || pe->desc || pe->event) && i < idx; pe++, i++)
151959826caSMatt Macy 		;
152959826caSMatt Macy 	return (pe->name);
153959826caSMatt Macy }
154959826caSMatt Macy 
155959826caSMatt Macy static int
156959826caSMatt Macy pmu_parse_event(struct pmu_event_desc *ped, const char *eventin)
157959826caSMatt Macy {
158959826caSMatt Macy 	char *event;
159*8bed125dSMatt Macy 	char *kvp, *key, *value, *r;
160959826caSMatt Macy 	char *debug;
161959826caSMatt Macy 
162959826caSMatt Macy 	if ((event = strdup(eventin)) == NULL)
163959826caSMatt Macy 		return (ENOMEM);
164*8bed125dSMatt Macy 	r = event;
165959826caSMatt Macy 	bzero(ped, sizeof(*ped));
166959826caSMatt Macy 	while ((kvp = strsep(&event, ",")) != NULL) {
167959826caSMatt Macy 		key = strsep(&kvp, "=");
168959826caSMatt Macy 		if (key == NULL)
169959826caSMatt Macy 			abort();
170959826caSMatt Macy 		value = kvp;
171959826caSMatt Macy 		if (strcmp(key, "umask") == 0)
172959826caSMatt Macy 			ped->ped_umask = strtol(value, NULL, 16);
173959826caSMatt Macy 		else if (strcmp(key, "event") == 0)
174959826caSMatt Macy 			ped->ped_event = strtol(value, NULL, 16);
175959826caSMatt Macy 		else if (strcmp(key, "period") == 0)
176959826caSMatt Macy 			ped->ped_period = strtol(value, NULL, 10);
177959826caSMatt Macy 		else if (strcmp(key, "offcore_rsp") == 0)
178959826caSMatt Macy 			ped->ped_offcore_rsp = strtol(value, NULL, 16);
179959826caSMatt Macy 		else if (strcmp(key, "any") == 0)
180959826caSMatt Macy 			ped->ped_any = strtol(value, NULL, 10);
181959826caSMatt Macy 		else if (strcmp(key, "cmask") == 0)
182959826caSMatt Macy 			ped->ped_cmask = strtol(value, NULL, 10);
183959826caSMatt Macy 		else if (strcmp(key, "inv") == 0)
184959826caSMatt Macy 			ped->ped_inv = strtol(value, NULL, 10);
185959826caSMatt Macy 		else if (strcmp(key, "edge") == 0)
186959826caSMatt Macy 			ped->ped_edge = strtol(value, NULL, 10);
187959826caSMatt Macy 		else if (strcmp(key, "frontend") == 0)
188959826caSMatt Macy 			ped->ped_frontend = strtol(value, NULL, 16);
189959826caSMatt Macy 		else if (strcmp(key, "ldlat") == 0)
190959826caSMatt Macy 			ped->ped_ldlat = strtol(value, NULL, 16);
191959826caSMatt Macy 		else if (strcmp(key, "fc_mask") == 0)
192959826caSMatt Macy 			ped->ped_fc_mask = strtol(value, NULL, 16);
193959826caSMatt Macy 		else if (strcmp(key, "ch_mask") == 0)
194959826caSMatt Macy 			ped->ped_ch_mask = strtol(value, NULL, 16);
195959826caSMatt Macy 		else if (strcmp(key, "config1") == 0)
196959826caSMatt Macy 			ped->ped_config1 = strtol(value, NULL, 16);
197959826caSMatt Macy 		else {
198959826caSMatt Macy 			debug = getenv("PMUDEBUG");
199959826caSMatt Macy 			if (debug != NULL && strcmp(debug, "true") == 0 && value != NULL)
200959826caSMatt Macy 				printf("unrecognized kvpair: %s:%s\n", key, value);
201959826caSMatt Macy 		}
202959826caSMatt Macy 	}
203*8bed125dSMatt Macy 	free(r);
204959826caSMatt Macy 	return (0);
205959826caSMatt Macy }
206959826caSMatt Macy 
207959826caSMatt Macy uint64_t
208959826caSMatt Macy pmc_pmu_sample_rate_get(const char *event_name)
209959826caSMatt Macy {
210959826caSMatt Macy 	const struct pmu_event *pe;
211959826caSMatt Macy 	struct pmu_event_desc ped;
212959826caSMatt Macy 
213959826caSMatt Macy 	event_name = pmu_alias_get(event_name);
214959826caSMatt Macy 	if ((pe = pmu_event_get(event_name, NULL)) == NULL)
215959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
216959826caSMatt Macy 	if (pe->alias && (pe = pmu_event_get(pe->alias, NULL)) == NULL)
217959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
218959826caSMatt Macy 	if (pe->event == NULL)
219959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
220959826caSMatt Macy 	if (pmu_parse_event(&ped, pe->event))
221959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
222959826caSMatt Macy 	return (ped.ped_period);
223959826caSMatt Macy }
224959826caSMatt Macy 
225959826caSMatt Macy int
226959826caSMatt Macy pmc_pmu_enabled(void)
227959826caSMatt Macy {
228959826caSMatt Macy 
229959826caSMatt Macy 	return (pmu_events_map_get() != NULL);
230959826caSMatt Macy }
231959826caSMatt Macy 
232959826caSMatt Macy void
233959826caSMatt Macy pmc_pmu_print_counters(void)
234959826caSMatt Macy {
235959826caSMatt Macy 	const struct pmu_events_map *pme;
236959826caSMatt Macy 	const struct pmu_event *pe;
237959826caSMatt Macy 	struct pmu_event_desc ped;
238959826caSMatt Macy 	char *debug;
239959826caSMatt Macy 	int do_debug;
240959826caSMatt Macy 
241959826caSMatt Macy 	debug = getenv("PMUDEBUG");
242959826caSMatt Macy 	do_debug = 0;
243959826caSMatt Macy 
244959826caSMatt Macy 	if (debug != NULL && strcmp(debug, "true") == 0)
245959826caSMatt Macy 		do_debug = 1;
246959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
247959826caSMatt Macy 		return;
248959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
249959826caSMatt Macy 		if (pe->name == NULL)
250959826caSMatt Macy 			continue;
251959826caSMatt Macy 		printf("\t%s\n", pe->name);
252959826caSMatt Macy 		if (do_debug)
253959826caSMatt Macy 			pmu_parse_event(&ped, pe->event);
254959826caSMatt Macy 	}
255959826caSMatt Macy }
256959826caSMatt Macy 
257959826caSMatt Macy void
258959826caSMatt Macy pmc_pmu_print_counter_desc(const char *ev)
259959826caSMatt Macy {
260959826caSMatt Macy 	const struct pmu_events_map *pme;
261959826caSMatt Macy 	const struct pmu_event *pe;
262959826caSMatt Macy 
263959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
264959826caSMatt Macy 		return;
265959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
266959826caSMatt Macy 		if (pe->name == NULL)
267959826caSMatt Macy 			continue;
268959826caSMatt Macy 		if (strcasestr(pe->name, ev) != NULL &&
269959826caSMatt Macy 			pe->desc != NULL)
270959826caSMatt Macy 				printf("%s:\t%s\n", pe->name, pe->desc);
271959826caSMatt Macy 	}
272959826caSMatt Macy }
273959826caSMatt Macy 
274959826caSMatt Macy void
275959826caSMatt Macy pmc_pmu_print_counter_desc_long(const char *ev)
276959826caSMatt Macy {
277959826caSMatt Macy 	const struct pmu_events_map *pme;
278959826caSMatt Macy 	const struct pmu_event *pe;
279959826caSMatt Macy 
280959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
281959826caSMatt Macy 		return;
282959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
283959826caSMatt Macy 		if (pe->name == NULL)
284959826caSMatt Macy 			continue;
285959826caSMatt Macy 		if (strcasestr(pe->name, ev) != NULL) {
286959826caSMatt Macy 			if (pe->long_desc != NULL)
287959826caSMatt Macy 				printf("%s:\n%s\n", pe->name, pe->long_desc);
288959826caSMatt Macy 			else if (pe->desc != NULL)
289959826caSMatt Macy 				printf("%s:\t%s\n", pe->name, pe->desc);
290959826caSMatt Macy 		}
291959826caSMatt Macy 	}
292959826caSMatt Macy }
293959826caSMatt Macy 
294959826caSMatt Macy int
295959826caSMatt Macy pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
296959826caSMatt Macy {
297959826caSMatt Macy 	const struct pmu_event *pe;
298959826caSMatt Macy 	struct pmu_event_desc ped;
299959826caSMatt Macy 	struct pmc_md_iap_op_pmcallocate *iap;
300a191ed2dSMatt Macy 	struct pmc_md_iaf_op_pmcallocate *iaf;
301a191ed2dSMatt Macy 	int idx, isfixed;
302959826caSMatt Macy 
303959826caSMatt Macy 	iap = &pm->pm_md.pm_iap;
304a191ed2dSMatt Macy 	iaf = &pm->pm_md.pm_iaf;
305a191ed2dSMatt Macy 	isfixed = 0;
306959826caSMatt Macy 	bzero(iap, sizeof(*iap));
307959826caSMatt Macy 	event_name = pmu_alias_get(event_name);
308a191ed2dSMatt Macy 	pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
309959826caSMatt Macy 	if ((pe = pmu_event_get(event_name, &idx)) == NULL)
310959826caSMatt Macy 		return (ENOENT);
311959826caSMatt Macy 	if (pe->alias && (pe = pmu_event_get(pe->alias, &idx)) == NULL)
312959826caSMatt Macy 		return (ENOENT);
313959826caSMatt Macy 	if (pe->event == NULL)
314959826caSMatt Macy 		return (ENOENT);
315959826caSMatt Macy 	if (pmu_parse_event(&ped, pe->event))
316959826caSMatt Macy 		return (ENOENT);
317959826caSMatt Macy 
318a191ed2dSMatt Macy 	for (idx = 0; fixed_mode_cntrs[idx] != NULL; idx++)
319c53c63f6SMatt Macy 		if (strcmp(fixed_mode_cntrs[idx], event_name) == 0)
320a191ed2dSMatt Macy 			isfixed = 1;
321a191ed2dSMatt Macy 
322a191ed2dSMatt Macy 	if (isfixed) {
323a191ed2dSMatt Macy 		if (strcasestr(pe->desc, "retired") != NULL)
324a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_INSTR_RETIRED_ANY;
325a191ed2dSMatt Macy 		else if (strcasestr(pe->desc, "core") != NULL ||
326a191ed2dSMatt Macy 				 strcasestr(pe->desc, "unhalted"))
327a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_CORE;
328a191ed2dSMatt Macy 		else if (strcasestr(pe->desc, "ref") != NULL)
329a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_REF;
330a191ed2dSMatt Macy 		iaf->pm_iaf_flags |= (IAF_USR | IAF_OS);
331a191ed2dSMatt Macy 		if (ped.ped_any)
332a191ed2dSMatt Macy 			iaf->pm_iaf_flags |= IAF_ANY;
333a191ed2dSMatt Macy 		if (pm->pm_caps & PMC_CAP_INTERRUPT)
334a191ed2dSMatt Macy 			iaf->pm_iaf_flags |= IAF_PMI;
335a191ed2dSMatt Macy 		pm->pm_class = PMC_CLASS_IAF;
336a191ed2dSMatt Macy 		return (0);
337a191ed2dSMatt Macy 	}
338a191ed2dSMatt Macy 	pm->pm_caps |= PMC_CAP_QUALIFIER;
339959826caSMatt Macy 	pm->pm_class = PMC_CLASS_IAP;
340959826caSMatt Macy 	pm->pm_ev = idx;
341959826caSMatt Macy 	iap->pm_iap_config |= IAP_EVSEL(ped.ped_event);
342959826caSMatt Macy 	iap->pm_iap_config |= IAP_UMASK(ped.ped_umask);
343959826caSMatt Macy 	iap->pm_iap_config |= IAP_CMASK(ped.ped_cmask);
344959826caSMatt Macy 	iap->pm_iap_rsp = ped.ped_offcore_rsp;
345959826caSMatt Macy 
346959826caSMatt Macy 	iap->pm_iap_config |= (IAP_USR | IAP_OS);
347959826caSMatt Macy 	if (ped.ped_edge)
348959826caSMatt Macy 		iap->pm_iap_config |= IAP_EDGE;
349959826caSMatt Macy 	if (ped.ped_any)
350959826caSMatt Macy 		iap->pm_iap_config |= IAP_ANY;
351959826caSMatt Macy 	if (ped.ped_inv)
352959826caSMatt Macy 		iap->pm_iap_config |= IAP_EDGE;
353959826caSMatt Macy 	if (pm->pm_caps & PMC_CAP_INTERRUPT)
354959826caSMatt Macy 		iap->pm_iap_config |= IAP_INT;
355959826caSMatt Macy 	return (0);
356959826caSMatt Macy }
357959826caSMatt Macy 
35878beed2fSMatt Macy /*
35978beed2fSMatt Macy  * Ultimately rely on AMD calling theirs the same
36078beed2fSMatt Macy  */
36178beed2fSMatt Macy static const char *stat_mode_cntrs[] = {
362a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread_any",
36378beed2fSMatt Macy 	"inst_retired.any",
36478beed2fSMatt Macy 	"br_inst_retired.all_branches",
36578beed2fSMatt Macy 	"br_misp_retired.all_branches",
366a191ed2dSMatt Macy 	"longest_lat_cache.reference",
367a191ed2dSMatt Macy 	"longest_lat_cache.miss",
36878beed2fSMatt Macy };
36978beed2fSMatt Macy 
37078beed2fSMatt Macy int
37178beed2fSMatt Macy pmc_pmu_stat_mode(const char ***cntrs)
37278beed2fSMatt Macy {
37378beed2fSMatt Macy 	if (pmc_pmu_enabled()) {
37478beed2fSMatt Macy 		*cntrs = stat_mode_cntrs;
37578beed2fSMatt Macy 		return (0);
37678beed2fSMatt Macy 	}
37778beed2fSMatt Macy 	return (EOPNOTSUPP);
37878beed2fSMatt Macy }
37978beed2fSMatt Macy 
380959826caSMatt Macy #else
381959826caSMatt Macy uint64_t pmc_pmu_sample_rate_get(const char *event_name __unused) { return (DEFAULT_SAMPLE_COUNT); }
382959826caSMatt Macy void pmc_pmu_print_counters(void) {}
383959826caSMatt Macy void pmc_pmu_print_counter_desc(const char *e __unused) {}
384959826caSMatt Macy void pmc_pmu_print_counter_desc_long(const char *e __unused) {}
385959826caSMatt Macy int pmc_pmu_enabled(void) { return (0); }
386959826caSMatt Macy int pmc_pmu_pmcallocate(const char *e __unused, struct pmc_op_pmcallocate *p __unused) { return (EOPNOTSUPP); }
38778beed2fSMatt Macy const char *pmc_pmu_event_get_by_idx(int idx __unused) { return (NULL); }
38878beed2fSMatt Macy int pmc_pmu_stat_mode(const char ***a __unused) { return (EOPNOTSUPP); }
389959826caSMatt Macy 
390959826caSMatt Macy #endif
391