xref: /freebsd/lib/libpmc/libpmc_pmu_util.c (revision 96cbd26a246450fb19e1f1ee6df9f4ae836af57e)
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 
437d1c2b74SMatt Macy #if defined(__amd64__) || defined(__i386__)
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"},
63*96cbd26aSMatt Macy 	{"cycles", "tsc-tsc"},
64*96cbd26aSMatt Macy 	{"instructions", "inst-retired.any_p"},
65*96cbd26aSMatt Macy 	{"branch-mispredicts", "br_misp_retired.all_branches" },
66*96cbd26aSMatt Macy 	{"branches", "br_inst_retired.all_branches" },
67*96cbd26aSMatt Macy 	{"interrupts", "hw_interrupts.received"},
68*96cbd26aSMatt Macy 	{"ic-misses", "frontend_retired.l1i_miss"},
69959826caSMatt Macy 	{NULL, NULL},
70959826caSMatt Macy };
71959826caSMatt Macy 
72a191ed2dSMatt Macy static const char *fixed_mode_cntrs[] = {
73a191ed2dSMatt Macy 	"inst_retired.any",
74a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread",
75a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread_any",
76a191ed2dSMatt Macy 	"cpu_clk_unhalted.ref_tsc",
77a191ed2dSMatt Macy 	NULL
78a191ed2dSMatt Macy };
79a191ed2dSMatt Macy 
80959826caSMatt Macy static const char *
81959826caSMatt Macy pmu_alias_get(const char *name)
82959826caSMatt Macy {
83959826caSMatt Macy 	struct pmu_alias *pa;
84959826caSMatt Macy 
85959826caSMatt Macy 	for (pa = pmu_alias_table; pa->pa_alias != NULL; pa++)
86959826caSMatt Macy 		if (strcasecmp(name, pa->pa_alias) == 0)
87959826caSMatt Macy 			return (pa->pa_name);
88959826caSMatt Macy 	return (name);
89959826caSMatt Macy }
90959826caSMatt Macy 
91959826caSMatt Macy struct pmu_event_desc {
92959826caSMatt Macy 	uint64_t ped_period;
93959826caSMatt Macy 	uint64_t ped_offcore_rsp;
94959826caSMatt Macy 	uint32_t ped_event;
95959826caSMatt Macy 	uint32_t ped_frontend;
96959826caSMatt Macy 	uint32_t ped_ldlat;
97959826caSMatt Macy 	uint32_t ped_config1;
98959826caSMatt Macy 	uint8_t	ped_umask;
99959826caSMatt Macy 	uint8_t	ped_cmask;
100959826caSMatt Macy 	uint8_t	ped_any;
101959826caSMatt Macy 	uint8_t	ped_inv;
102959826caSMatt Macy 	uint8_t	ped_edge;
103959826caSMatt Macy 	uint8_t	ped_fc_mask;
104959826caSMatt Macy 	uint8_t	ped_ch_mask;
105959826caSMatt Macy };
106959826caSMatt Macy 
107959826caSMatt Macy static const struct pmu_events_map *
108959826caSMatt Macy pmu_events_map_get(void)
109959826caSMatt Macy {
110959826caSMatt Macy 	size_t s;
111959826caSMatt Macy 	char buf[64];
112959826caSMatt Macy 	const struct pmu_events_map *pme;
113959826caSMatt Macy 
114959826caSMatt Macy 	if (sysctlbyname("kern.hwpmc.cpuid", (void *)NULL, &s,
115959826caSMatt Macy 	    (void *)NULL, 0) == -1)
116959826caSMatt Macy 		return (NULL);
117959826caSMatt Macy 	if (sysctlbyname("kern.hwpmc.cpuid", buf, &s,
118959826caSMatt Macy 	    (void *)NULL, 0) == -1)
119959826caSMatt Macy 		return (NULL);
120959826caSMatt Macy 	for (pme = pmu_events_map; pme->cpuid != NULL; pme++)
121959826caSMatt Macy 		if (strcmp(buf, pme->cpuid) == 0)
122959826caSMatt Macy 			return (pme);
123959826caSMatt Macy 	return (NULL);
124959826caSMatt Macy }
125959826caSMatt Macy 
126959826caSMatt Macy static const struct pmu_event *
127959826caSMatt Macy pmu_event_get(const char *event_name, int *idx)
128959826caSMatt Macy {
129959826caSMatt Macy 	const struct pmu_events_map *pme;
130959826caSMatt Macy 	const struct pmu_event *pe;
131959826caSMatt Macy 	int i;
132959826caSMatt Macy 
133959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
134959826caSMatt Macy 		return (NULL);
135959826caSMatt Macy 	for (i = 0, pe = pme->table; pe->name || pe->desc || pe->event; pe++, i++) {
136959826caSMatt Macy 		if (pe->name == NULL)
137959826caSMatt Macy 			continue;
138959826caSMatt Macy 		if (strcasecmp(pe->name, event_name) == 0) {
139959826caSMatt Macy 			if (idx)
140959826caSMatt Macy 				*idx = i;
141959826caSMatt Macy 			return (pe);
142959826caSMatt Macy 		}
143959826caSMatt Macy 	}
144959826caSMatt Macy 	return (NULL);
145959826caSMatt Macy }
146959826caSMatt Macy 
147959826caSMatt Macy const char *
14878beed2fSMatt Macy pmc_pmu_event_get_by_idx(int idx)
149959826caSMatt Macy {
150959826caSMatt Macy 	const struct pmu_events_map *pme;
151959826caSMatt Macy 	const struct pmu_event *pe;
152959826caSMatt Macy 	int i;
153959826caSMatt Macy 
154959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
155959826caSMatt Macy 		return (NULL);
1568b20f975SMatt Macy 	for (i = 0, pe = pme->table; (pe->name || pe->desc || pe->event) && i < idx; pe++, i++);
157959826caSMatt Macy 	return (pe->name);
158959826caSMatt Macy }
159959826caSMatt Macy 
160959826caSMatt Macy static int
161959826caSMatt Macy pmu_parse_event(struct pmu_event_desc *ped, const char *eventin)
162959826caSMatt Macy {
163959826caSMatt Macy 	char *event;
1648bed125dSMatt Macy 	char *kvp, *key, *value, *r;
165959826caSMatt Macy 	char *debug;
166959826caSMatt Macy 
167959826caSMatt Macy 	if ((event = strdup(eventin)) == NULL)
168959826caSMatt Macy 		return (ENOMEM);
1698bed125dSMatt Macy 	r = event;
170959826caSMatt Macy 	bzero(ped, sizeof(*ped));
171959826caSMatt Macy 	while ((kvp = strsep(&event, ",")) != NULL) {
172959826caSMatt Macy 		key = strsep(&kvp, "=");
173959826caSMatt Macy 		if (key == NULL)
174959826caSMatt Macy 			abort();
175959826caSMatt Macy 		value = kvp;
176959826caSMatt Macy 		if (strcmp(key, "umask") == 0)
177959826caSMatt Macy 			ped->ped_umask = strtol(value, NULL, 16);
178959826caSMatt Macy 		else if (strcmp(key, "event") == 0)
179959826caSMatt Macy 			ped->ped_event = strtol(value, NULL, 16);
180959826caSMatt Macy 		else if (strcmp(key, "period") == 0)
181959826caSMatt Macy 			ped->ped_period = strtol(value, NULL, 10);
182959826caSMatt Macy 		else if (strcmp(key, "offcore_rsp") == 0)
183959826caSMatt Macy 			ped->ped_offcore_rsp = strtol(value, NULL, 16);
184959826caSMatt Macy 		else if (strcmp(key, "any") == 0)
185959826caSMatt Macy 			ped->ped_any = strtol(value, NULL, 10);
186959826caSMatt Macy 		else if (strcmp(key, "cmask") == 0)
187959826caSMatt Macy 			ped->ped_cmask = strtol(value, NULL, 10);
188959826caSMatt Macy 		else if (strcmp(key, "inv") == 0)
189959826caSMatt Macy 			ped->ped_inv = strtol(value, NULL, 10);
190959826caSMatt Macy 		else if (strcmp(key, "edge") == 0)
191959826caSMatt Macy 			ped->ped_edge = strtol(value, NULL, 10);
192959826caSMatt Macy 		else if (strcmp(key, "frontend") == 0)
193959826caSMatt Macy 			ped->ped_frontend = strtol(value, NULL, 16);
194959826caSMatt Macy 		else if (strcmp(key, "ldlat") == 0)
195959826caSMatt Macy 			ped->ped_ldlat = strtol(value, NULL, 16);
196959826caSMatt Macy 		else if (strcmp(key, "fc_mask") == 0)
197959826caSMatt Macy 			ped->ped_fc_mask = strtol(value, NULL, 16);
198959826caSMatt Macy 		else if (strcmp(key, "ch_mask") == 0)
199959826caSMatt Macy 			ped->ped_ch_mask = strtol(value, NULL, 16);
200959826caSMatt Macy 		else if (strcmp(key, "config1") == 0)
201959826caSMatt Macy 			ped->ped_config1 = strtol(value, NULL, 16);
202959826caSMatt Macy 		else {
203959826caSMatt Macy 			debug = getenv("PMUDEBUG");
204959826caSMatt Macy 			if (debug != NULL && strcmp(debug, "true") == 0 && value != NULL)
205959826caSMatt Macy 				printf("unrecognized kvpair: %s:%s\n", key, value);
206959826caSMatt Macy 		}
207959826caSMatt Macy 	}
2088bed125dSMatt Macy 	free(r);
209959826caSMatt Macy 	return (0);
210959826caSMatt Macy }
211959826caSMatt Macy 
212959826caSMatt Macy uint64_t
213959826caSMatt Macy pmc_pmu_sample_rate_get(const char *event_name)
214959826caSMatt Macy {
215959826caSMatt Macy 	const struct pmu_event *pe;
216959826caSMatt Macy 	struct pmu_event_desc ped;
217959826caSMatt Macy 
218959826caSMatt Macy 	event_name = pmu_alias_get(event_name);
219959826caSMatt Macy 	if ((pe = pmu_event_get(event_name, NULL)) == NULL)
220959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
221959826caSMatt Macy 	if (pe->alias && (pe = pmu_event_get(pe->alias, NULL)) == NULL)
222959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
223959826caSMatt Macy 	if (pe->event == NULL)
224959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
225959826caSMatt Macy 	if (pmu_parse_event(&ped, pe->event))
226959826caSMatt Macy 		return (DEFAULT_SAMPLE_COUNT);
227959826caSMatt Macy 	return (ped.ped_period);
228959826caSMatt Macy }
229959826caSMatt Macy 
230959826caSMatt Macy int
231959826caSMatt Macy pmc_pmu_enabled(void)
232959826caSMatt Macy {
233959826caSMatt Macy 
234959826caSMatt Macy 	return (pmu_events_map_get() != NULL);
235959826caSMatt Macy }
236959826caSMatt Macy 
237959826caSMatt Macy void
238959826caSMatt Macy pmc_pmu_print_counters(void)
239959826caSMatt Macy {
240959826caSMatt Macy 	const struct pmu_events_map *pme;
241959826caSMatt Macy 	const struct pmu_event *pe;
242959826caSMatt Macy 	struct pmu_event_desc ped;
243959826caSMatt Macy 	char *debug;
244959826caSMatt Macy 	int do_debug;
245959826caSMatt Macy 
246959826caSMatt Macy 	debug = getenv("PMUDEBUG");
247959826caSMatt Macy 	do_debug = 0;
248959826caSMatt Macy 
249959826caSMatt Macy 	if (debug != NULL && strcmp(debug, "true") == 0)
250959826caSMatt Macy 		do_debug = 1;
251959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
252959826caSMatt Macy 		return;
253959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
254959826caSMatt Macy 		if (pe->name == NULL)
255959826caSMatt Macy 			continue;
256959826caSMatt Macy 		printf("\t%s\n", pe->name);
257959826caSMatt Macy 		if (do_debug)
258959826caSMatt Macy 			pmu_parse_event(&ped, pe->event);
259959826caSMatt Macy 	}
260959826caSMatt Macy }
261959826caSMatt Macy 
262959826caSMatt Macy void
263959826caSMatt Macy pmc_pmu_print_counter_desc(const char *ev)
264959826caSMatt Macy {
265959826caSMatt Macy 	const struct pmu_events_map *pme;
266959826caSMatt Macy 	const struct pmu_event *pe;
267959826caSMatt Macy 
268959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
269959826caSMatt Macy 		return;
270959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
271959826caSMatt Macy 		if (pe->name == NULL)
272959826caSMatt Macy 			continue;
273959826caSMatt Macy 		if (strcasestr(pe->name, ev) != NULL &&
274959826caSMatt Macy 		    pe->desc != NULL)
275959826caSMatt Macy 			printf("%s:\t%s\n", pe->name, pe->desc);
276959826caSMatt Macy 	}
277959826caSMatt Macy }
278959826caSMatt Macy 
279959826caSMatt Macy void
280959826caSMatt Macy pmc_pmu_print_counter_desc_long(const char *ev)
281959826caSMatt Macy {
282959826caSMatt Macy 	const struct pmu_events_map *pme;
283959826caSMatt Macy 	const struct pmu_event *pe;
284959826caSMatt Macy 
285959826caSMatt Macy 	if ((pme = pmu_events_map_get()) == NULL)
286959826caSMatt Macy 		return;
287959826caSMatt Macy 	for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
288959826caSMatt Macy 		if (pe->name == NULL)
289959826caSMatt Macy 			continue;
290959826caSMatt Macy 		if (strcasestr(pe->name, ev) != NULL) {
291959826caSMatt Macy 			if (pe->long_desc != NULL)
292959826caSMatt Macy 				printf("%s:\n%s\n", pe->name, pe->long_desc);
293959826caSMatt Macy 			else if (pe->desc != NULL)
294959826caSMatt Macy 				printf("%s:\t%s\n", pe->name, pe->desc);
295959826caSMatt Macy 		}
296959826caSMatt Macy 	}
297959826caSMatt Macy }
298959826caSMatt Macy 
299959826caSMatt Macy int
300959826caSMatt Macy pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
301959826caSMatt Macy {
302959826caSMatt Macy 	const struct pmu_event *pe;
303959826caSMatt Macy 	struct pmu_event_desc ped;
304959826caSMatt Macy 	struct pmc_md_iap_op_pmcallocate *iap;
305a191ed2dSMatt Macy 	struct pmc_md_iaf_op_pmcallocate *iaf;
306a191ed2dSMatt Macy 	int idx, isfixed;
307959826caSMatt Macy 
308959826caSMatt Macy 	iap = &pm->pm_md.pm_iap;
309a191ed2dSMatt Macy 	isfixed = 0;
310959826caSMatt Macy 	bzero(iap, sizeof(*iap));
311959826caSMatt Macy 	event_name = pmu_alias_get(event_name);
312a191ed2dSMatt Macy 	pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
313959826caSMatt Macy 	if ((pe = pmu_event_get(event_name, &idx)) == NULL)
314959826caSMatt Macy 		return (ENOENT);
315959826caSMatt Macy 	if (pe->alias && (pe = pmu_event_get(pe->alias, &idx)) == NULL)
316959826caSMatt Macy 		return (ENOENT);
317959826caSMatt Macy 	if (pe->event == NULL)
318959826caSMatt Macy 		return (ENOENT);
319959826caSMatt Macy 	if (pmu_parse_event(&ped, pe->event))
320959826caSMatt Macy 		return (ENOENT);
321959826caSMatt Macy 
322a191ed2dSMatt Macy 	for (idx = 0; fixed_mode_cntrs[idx] != NULL; idx++)
323c53c63f6SMatt Macy 		if (strcmp(fixed_mode_cntrs[idx], event_name) == 0)
324a191ed2dSMatt Macy 			isfixed = 1;
325a191ed2dSMatt Macy 	if (isfixed) {
326785dd70dSMatt Macy 		iaf = &pm->pm_md.pm_iaf;
327785dd70dSMatt Macy 		pm->pm_class = PMC_CLASS_IAF;
328a191ed2dSMatt Macy 		if (strcasestr(pe->desc, "retired") != NULL)
329a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_INSTR_RETIRED_ANY;
330a191ed2dSMatt Macy 		else if (strcasestr(pe->desc, "core") != NULL ||
331a191ed2dSMatt Macy 		    strcasestr(pe->desc, "unhalted"))
332a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_CORE;
333a191ed2dSMatt Macy 		else if (strcasestr(pe->desc, "ref") != NULL)
334a191ed2dSMatt Macy 			pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_REF;
335a191ed2dSMatt Macy 		iaf->pm_iaf_flags |= (IAF_USR | IAF_OS);
336a191ed2dSMatt Macy 		if (ped.ped_any)
337a191ed2dSMatt Macy 			iaf->pm_iaf_flags |= IAF_ANY;
338a191ed2dSMatt Macy 		if (pm->pm_caps & PMC_CAP_INTERRUPT)
339a191ed2dSMatt Macy 			iaf->pm_iaf_flags |= IAF_PMI;
340a191ed2dSMatt Macy 		return (0);
341785dd70dSMatt Macy 	} else if (strcasestr(event_name, "UNC_") == event_name ||
342785dd70dSMatt Macy 			   strcasestr(event_name, "uncore") != NULL) {
343785dd70dSMatt Macy 		pm->pm_class = PMC_CLASS_UCP;
344785dd70dSMatt Macy 	} else {
345a191ed2dSMatt Macy 		pm->pm_caps |= PMC_CAP_QUALIFIER;
346959826caSMatt Macy 		pm->pm_class = PMC_CLASS_IAP;
347785dd70dSMatt Macy 	}
348959826caSMatt Macy 	pm->pm_ev = idx;
349959826caSMatt Macy 	iap->pm_iap_config |= IAP_EVSEL(ped.ped_event);
350959826caSMatt Macy 	iap->pm_iap_config |= IAP_UMASK(ped.ped_umask);
351959826caSMatt Macy 	iap->pm_iap_config |= IAP_CMASK(ped.ped_cmask);
352959826caSMatt Macy 	iap->pm_iap_rsp = ped.ped_offcore_rsp;
353959826caSMatt Macy 
354959826caSMatt Macy 	iap->pm_iap_config |= (IAP_USR | IAP_OS);
355959826caSMatt Macy 	if (ped.ped_edge)
356959826caSMatt Macy 		iap->pm_iap_config |= IAP_EDGE;
357959826caSMatt Macy 	if (ped.ped_any)
358959826caSMatt Macy 		iap->pm_iap_config |= IAP_ANY;
359959826caSMatt Macy 	if (ped.ped_inv)
360959826caSMatt Macy 		iap->pm_iap_config |= IAP_EDGE;
361959826caSMatt Macy 	if (pm->pm_caps & PMC_CAP_INTERRUPT)
362959826caSMatt Macy 		iap->pm_iap_config |= IAP_INT;
363959826caSMatt Macy 	return (0);
364959826caSMatt Macy }
365959826caSMatt Macy 
36678beed2fSMatt Macy /*
36778beed2fSMatt Macy  * Ultimately rely on AMD calling theirs the same
36878beed2fSMatt Macy  */
36978beed2fSMatt Macy static const char *stat_mode_cntrs[] = {
370a191ed2dSMatt Macy 	"cpu_clk_unhalted.thread_any",
37178beed2fSMatt Macy 	"inst_retired.any",
37278beed2fSMatt Macy 	"br_inst_retired.all_branches",
37378beed2fSMatt Macy 	"br_misp_retired.all_branches",
374a191ed2dSMatt Macy 	"longest_lat_cache.reference",
375a191ed2dSMatt Macy 	"longest_lat_cache.miss",
37678beed2fSMatt Macy };
37778beed2fSMatt Macy 
37878beed2fSMatt Macy int
37978beed2fSMatt Macy pmc_pmu_stat_mode(const char ***cntrs)
38078beed2fSMatt Macy {
38178beed2fSMatt Macy 	if (pmc_pmu_enabled()) {
38278beed2fSMatt Macy 		*cntrs = stat_mode_cntrs;
38378beed2fSMatt Macy 		return (0);
38478beed2fSMatt Macy 	}
38578beed2fSMatt Macy 	return (EOPNOTSUPP);
38678beed2fSMatt Macy }
38778beed2fSMatt Macy 
388959826caSMatt Macy #else
3898b20f975SMatt Macy 
3908b20f975SMatt Macy uint64_t
3918b20f975SMatt Macy pmc_pmu_sample_rate_get(const char *event_name __unused)
3928b20f975SMatt Macy {
3938b20f975SMatt Macy 	return (DEFAULT_SAMPLE_COUNT);
3948b20f975SMatt Macy }
3958b20f975SMatt Macy 
3968b20f975SMatt Macy void
3978b20f975SMatt Macy pmc_pmu_print_counters(void)
3988b20f975SMatt Macy {
3998b20f975SMatt Macy }
4008b20f975SMatt Macy 
4018b20f975SMatt Macy void
4028b20f975SMatt Macy pmc_pmu_print_counter_desc(const char *e __unused)
4038b20f975SMatt Macy {
4048b20f975SMatt Macy }
4058b20f975SMatt Macy 
4068b20f975SMatt Macy void
4078b20f975SMatt Macy pmc_pmu_print_counter_desc_long(const char *e __unused)
4088b20f975SMatt Macy {
4098b20f975SMatt Macy }
4108b20f975SMatt Macy 
4118b20f975SMatt Macy int
4128b20f975SMatt Macy pmc_pmu_enabled(void)
4138b20f975SMatt Macy {
4148b20f975SMatt Macy 	return (0);
4158b20f975SMatt Macy }
4168b20f975SMatt Macy 
4178b20f975SMatt Macy int
4188b20f975SMatt Macy pmc_pmu_pmcallocate(const char *e __unused, struct pmc_op_pmcallocate *p __unused)
4198b20f975SMatt Macy {
4208b20f975SMatt Macy 	return (EOPNOTSUPP);
4218b20f975SMatt Macy }
4228b20f975SMatt Macy 
4238b20f975SMatt Macy const char *
4248b20f975SMatt Macy pmc_pmu_event_get_by_idx(int idx __unused)
4258b20f975SMatt Macy {
4268b20f975SMatt Macy 	return (NULL);
4278b20f975SMatt Macy }
4288b20f975SMatt Macy int
4298b20f975SMatt Macy pmc_pmu_stat_mode(const char ***a __unused)
4308b20f975SMatt Macy {
4318b20f975SMatt Macy 	return (EOPNOTSUPP);
4328b20f975SMatt Macy }
433959826caSMatt Macy 
434959826caSMatt Macy #endif
435