xref: /freebsd/lib/libpmc/libpmc_pmu_util.c (revision a191ed2d9f1059fb651157fcc1ad12994e51f66d)
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 
66*a191ed2dSMatt Macy static const char *fixed_mode_cntrs[] = {
67*a191ed2dSMatt Macy 	"inst_retired.any",
68*a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread",
69*a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread_any",
70*a191ed2dSMatt Macy 	"cpu_clk_unhalted.ref_tsc",
71*a191ed2dSMatt Macy 	NULL
72*a191ed2dSMatt Macy };
73*a191ed2dSMatt 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;
159959826caSMatt Macy 	char *kvp, *key, *value;
160959826caSMatt Macy 	char *debug;
161959826caSMatt Macy 
162959826caSMatt Macy 	if ((event = strdup(eventin)) == NULL)
163959826caSMatt Macy 		return (ENOMEM);
164959826caSMatt Macy 	bzero(ped, sizeof(*ped));
165959826caSMatt Macy 	while ((kvp = strsep(&event, ",")) != NULL) {
166959826caSMatt Macy 		key = strsep(&kvp, "=");
167959826caSMatt Macy 		if (key == NULL)
168959826caSMatt Macy 			abort();
169959826caSMatt Macy 		value = kvp;
170959826caSMatt Macy 		if (strcmp(key, "umask") == 0)
171959826caSMatt Macy 			ped->ped_umask = strtol(value, NULL, 16);
172959826caSMatt Macy 		else if (strcmp(key, "event") == 0)
173959826caSMatt Macy 			ped->ped_event = strtol(value, NULL, 16);
174959826caSMatt Macy 		else if (strcmp(key, "period") == 0)
175959826caSMatt Macy 			ped->ped_period = strtol(value, NULL, 10);
176959826caSMatt Macy 		else if (strcmp(key, "offcore_rsp") == 0)
177959826caSMatt Macy 			ped->ped_offcore_rsp = strtol(value, NULL, 16);
178959826caSMatt Macy 		else if (strcmp(key, "any") == 0)
179959826caSMatt Macy 			ped->ped_any = strtol(value, NULL, 10);
180959826caSMatt Macy 		else if (strcmp(key, "cmask") == 0)
181959826caSMatt Macy 			ped->ped_cmask = strtol(value, NULL, 10);
182959826caSMatt Macy 		else if (strcmp(key, "inv") == 0)
183959826caSMatt Macy 			ped->ped_inv = strtol(value, NULL, 10);
184959826caSMatt Macy 		else if (strcmp(key, "edge") == 0)
185959826caSMatt Macy 			ped->ped_edge = strtol(value, NULL, 10);
186959826caSMatt Macy 		else if (strcmp(key, "frontend") == 0)
187959826caSMatt Macy 			ped->ped_frontend = strtol(value, NULL, 16);
188959826caSMatt Macy 		else if (strcmp(key, "ldlat") == 0)
189959826caSMatt Macy 			ped->ped_ldlat = strtol(value, NULL, 16);
190959826caSMatt Macy 		else if (strcmp(key, "fc_mask") == 0)
191959826caSMatt Macy 			ped->ped_fc_mask = strtol(value, NULL, 16);
192959826caSMatt Macy 		else if (strcmp(key, "ch_mask") == 0)
193959826caSMatt Macy 			ped->ped_ch_mask = strtol(value, NULL, 16);
194959826caSMatt Macy 		else if (strcmp(key, "config1") == 0)
195959826caSMatt Macy 			ped->ped_config1 = strtol(value, NULL, 16);
196959826caSMatt Macy 		else {
197959826caSMatt Macy 			debug = getenv("PMUDEBUG");
198959826caSMatt Macy 			if (debug != NULL && strcmp(debug, "true") == 0 && value != NULL)
199959826caSMatt Macy 				printf("unrecognized kvpair: %s:%s\n", key, value);
200959826caSMatt Macy 		}
201959826caSMatt Macy 	}
202959826caSMatt Macy 	free(event);
203959826caSMatt Macy 	return (0);
204959826caSMatt Macy }
205959826caSMatt Macy 
206959826caSMatt Macy uint64_t
207959826caSMatt Macy pmc_pmu_sample_rate_get(const char *event_name)
208959826caSMatt Macy {
209959826caSMatt Macy 	const struct pmu_event *pe;
210959826caSMatt Macy 	struct pmu_event_desc ped;
211959826caSMatt Macy 
212959826caSMatt Macy 	event_name = pmu_alias_get(event_name);
213959826caSMatt Macy 	if ((pe = pmu_event_get(event_name, NULL)) == NULL)
214959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
215959826caSMatt Macy 	if (pe->alias && (pe = pmu_event_get(pe->alias, NULL)) == NULL)
216959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
217959826caSMatt Macy 	if (pe->event == NULL)
218959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
219959826caSMatt Macy 	if (pmu_parse_event(&ped, pe->event))
220959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
221959826caSMatt Macy 	return (ped.ped_period);
222959826caSMatt Macy }
223959826caSMatt Macy 
224959826caSMatt Macy int
225959826caSMatt Macy pmc_pmu_enabled(void)
226959826caSMatt Macy {
227959826caSMatt Macy 
228959826caSMatt Macy 	return (pmu_events_map_get() != NULL);
229959826caSMatt Macy }
230959826caSMatt Macy 
231959826caSMatt Macy void
232959826caSMatt Macy pmc_pmu_print_counters(void)
233959826caSMatt Macy {
234959826caSMatt Macy 	const struct pmu_events_map *pme;
235959826caSMatt Macy 	const struct pmu_event *pe;
236959826caSMatt Macy 	struct pmu_event_desc ped;
237959826caSMatt Macy 	char *debug;
238959826caSMatt Macy 	int do_debug;
239959826caSMatt Macy 
240959826caSMatt Macy 	debug = getenv("PMUDEBUG");
241959826caSMatt Macy 	do_debug = 0;
242959826caSMatt Macy 
243959826caSMatt Macy 	if (debug != NULL && strcmp(debug, "true") == 0)
244959826caSMatt Macy 		do_debug = 1;
245959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
246959826caSMatt Macy 		return;
247959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
248959826caSMatt Macy 		if (pe->name == NULL)
249959826caSMatt Macy 			continue;
250959826caSMatt Macy 		printf("\t%s\n", pe->name);
251959826caSMatt Macy 		if (do_debug)
252959826caSMatt Macy 			pmu_parse_event(&ped, pe->event);
253959826caSMatt Macy 	}
254959826caSMatt Macy }
255959826caSMatt Macy 
256959826caSMatt Macy void
257959826caSMatt Macy pmc_pmu_print_counter_desc(const char *ev)
258959826caSMatt Macy {
259959826caSMatt Macy 	const struct pmu_events_map *pme;
260959826caSMatt Macy 	const struct pmu_event *pe;
261959826caSMatt Macy 
262959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
263959826caSMatt Macy 		return;
264959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
265959826caSMatt Macy 		if (pe->name == NULL)
266959826caSMatt Macy 			continue;
267959826caSMatt Macy 		if (strcasestr(pe->name, ev) != NULL &&
268959826caSMatt Macy 			pe->desc != NULL)
269959826caSMatt Macy 				printf("%s:\t%s\n", pe->name, pe->desc);
270959826caSMatt Macy 	}
271959826caSMatt Macy }
272959826caSMatt Macy 
273959826caSMatt Macy void
274959826caSMatt Macy pmc_pmu_print_counter_desc_long(const char *ev)
275959826caSMatt Macy {
276959826caSMatt Macy 	const struct pmu_events_map *pme;
277959826caSMatt Macy 	const struct pmu_event *pe;
278959826caSMatt Macy 
279959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
280959826caSMatt Macy 		return;
281959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
282959826caSMatt Macy 		if (pe->name == NULL)
283959826caSMatt Macy 			continue;
284959826caSMatt Macy 		if (strcasestr(pe->name, ev) != NULL) {
285959826caSMatt Macy 			if (pe->long_desc != NULL)
286959826caSMatt Macy 				printf("%s:\n%s\n", pe->name, pe->long_desc);
287959826caSMatt Macy 			else if (pe->desc != NULL)
288959826caSMatt Macy 				printf("%s:\t%s\n", pe->name, pe->desc);
289959826caSMatt Macy 		}
290959826caSMatt Macy 	}
291959826caSMatt Macy }
292959826caSMatt Macy 
293959826caSMatt Macy int
294959826caSMatt Macy pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
295959826caSMatt Macy {
296959826caSMatt Macy 	const struct pmu_event *pe;
297959826caSMatt Macy 	struct pmu_event_desc ped;
298959826caSMatt Macy 	struct pmc_md_iap_op_pmcallocate *iap;
299*a191ed2dSMatt Macy 	struct pmc_md_iaf_op_pmcallocate *iaf;
300*a191ed2dSMatt Macy 	int idx, isfixed;
301959826caSMatt Macy 
302959826caSMatt Macy 	iap = &pm->pm_md.pm_iap;
303*a191ed2dSMatt Macy 	iaf = &pm->pm_md.pm_iaf;
304*a191ed2dSMatt Macy 	isfixed = 0;
305959826caSMatt Macy 	bzero(iap, sizeof(*iap));
306959826caSMatt Macy 	event_name = pmu_alias_get(event_name);
307*a191ed2dSMatt Macy 	pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
308959826caSMatt Macy 	if ((pe = pmu_event_get(event_name, &idx)) == NULL)
309959826caSMatt Macy 		return (ENOENT);
310959826caSMatt Macy 	if (pe->alias && (pe = pmu_event_get(pe->alias, &idx)) == NULL)
311959826caSMatt Macy 		return (ENOENT);
312959826caSMatt Macy 	if (pe->event == NULL)
313959826caSMatt Macy 		return (ENOENT);
314959826caSMatt Macy 	if (pmu_parse_event(&ped, pe->event))
315959826caSMatt Macy 		return (ENOENT);
316959826caSMatt Macy 
317*a191ed2dSMatt Macy 	for (idx = 0; fixed_mode_cntrs[idx] != NULL; idx++)
318*a191ed2dSMatt Macy 		if (strcmp(fixed_mode_cntrs[idx], event_name) == 0) {
319*a191ed2dSMatt Macy 			isfixed = 1;
320*a191ed2dSMatt Macy 			printf("%s is fixed\n", event_name);
321*a191ed2dSMatt Macy 		}
322*a191ed2dSMatt Macy 
323*a191ed2dSMatt Macy 	if (isfixed) {
324*a191ed2dSMatt Macy 		if (strcasestr(pe->desc, "retired") != NULL)
325*a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_INSTR_RETIRED_ANY;
326*a191ed2dSMatt Macy 		else if (strcasestr(pe->desc, "core") != NULL ||
327*a191ed2dSMatt Macy 				 strcasestr(pe->desc, "unhalted"))
328*a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_CORE;
329*a191ed2dSMatt Macy 		else if (strcasestr(pe->desc, "ref") != NULL)
330*a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_REF;
331*a191ed2dSMatt Macy 		iaf->pm_iaf_flags |= (IAF_USR | IAF_OS);
332*a191ed2dSMatt Macy 		if (ped.ped_any)
333*a191ed2dSMatt Macy 			iaf->pm_iaf_flags |= IAF_ANY;
334*a191ed2dSMatt Macy 		if (pm->pm_caps & PMC_CAP_INTERRUPT)
335*a191ed2dSMatt Macy 			iaf->pm_iaf_flags |= IAF_PMI;
336*a191ed2dSMatt Macy 		pm->pm_class = PMC_CLASS_IAF;
337*a191ed2dSMatt Macy 		return (0);
338*a191ed2dSMatt Macy 	}
339*a191ed2dSMatt Macy 	pm->pm_caps |= PMC_CAP_QUALIFIER;
340959826caSMatt Macy 	pm->pm_class = PMC_CLASS_IAP;
341959826caSMatt Macy 	pm->pm_ev = idx;
342959826caSMatt Macy 	iap->pm_iap_config |= IAP_EVSEL(ped.ped_event);
343959826caSMatt Macy 	iap->pm_iap_config |= IAP_UMASK(ped.ped_umask);
344959826caSMatt Macy 	iap->pm_iap_config |= IAP_CMASK(ped.ped_cmask);
345959826caSMatt Macy 	iap->pm_iap_rsp = ped.ped_offcore_rsp;
346959826caSMatt Macy 
347959826caSMatt Macy 	iap->pm_iap_config |= (IAP_USR | IAP_OS);
348959826caSMatt Macy 	if (ped.ped_edge)
349959826caSMatt Macy 		iap->pm_iap_config |= IAP_EDGE;
350959826caSMatt Macy 	if (ped.ped_any)
351959826caSMatt Macy 		iap->pm_iap_config |= IAP_ANY;
352959826caSMatt Macy 	if (ped.ped_inv)
353959826caSMatt Macy 		iap->pm_iap_config |= IAP_EDGE;
354959826caSMatt Macy 	if (pm->pm_caps & PMC_CAP_INTERRUPT)
355959826caSMatt Macy 		iap->pm_iap_config |= IAP_INT;
356959826caSMatt Macy 	return (0);
357959826caSMatt Macy }
358959826caSMatt Macy 
35978beed2fSMatt Macy /*
36078beed2fSMatt Macy  * Ultimately rely on AMD calling theirs the same
36178beed2fSMatt Macy  */
36278beed2fSMatt Macy static const char *stat_mode_cntrs[] = {
363*a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread_any",
36478beed2fSMatt Macy 	"inst_retired.any",
36578beed2fSMatt Macy 	"br_inst_retired.all_branches",
36678beed2fSMatt Macy 	"br_misp_retired.all_branches",
367*a191ed2dSMatt Macy 	"longest_lat_cache.reference",
368*a191ed2dSMatt Macy 	"longest_lat_cache.miss",
36978beed2fSMatt Macy };
37078beed2fSMatt Macy 
37178beed2fSMatt Macy int
37278beed2fSMatt Macy pmc_pmu_stat_mode(const char ***cntrs)
37378beed2fSMatt Macy {
37478beed2fSMatt Macy 	if (pmc_pmu_enabled()) {
37578beed2fSMatt Macy 		*cntrs = stat_mode_cntrs;
37678beed2fSMatt Macy 		return (0);
37778beed2fSMatt Macy 	}
37878beed2fSMatt Macy 	return (EOPNOTSUPP);
37978beed2fSMatt Macy }
38078beed2fSMatt Macy 
381959826caSMatt Macy #else
382959826caSMatt Macy uint64_t pmc_pmu_sample_rate_get(const char *event_name __unused) { return (DEFAULT_SAMPLE_COUNT); }
383959826caSMatt Macy void pmc_pmu_print_counters(void) {}
384959826caSMatt Macy void pmc_pmu_print_counter_desc(const char *e __unused) {}
385959826caSMatt Macy void pmc_pmu_print_counter_desc_long(const char *e __unused) {}
386959826caSMatt Macy int pmc_pmu_enabled(void) { return (0); }
387959826caSMatt Macy int pmc_pmu_pmcallocate(const char *e __unused, struct pmc_op_pmcallocate *p __unused) { return (EOPNOTSUPP); }
38878beed2fSMatt Macy const char *pmc_pmu_event_get_by_idx(int idx __unused) { return (NULL); }
38978beed2fSMatt Macy int pmc_pmu_stat_mode(const char ***a __unused) { return (EOPNOTSUPP); }
390959826caSMatt Macy 
391959826caSMatt Macy #endif
392