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"}, 6396cbd26aSMatt Macy {"cycles", "tsc-tsc"}, 6496cbd26aSMatt Macy {"instructions", "inst-retired.any_p"}, 6596cbd26aSMatt Macy {"branch-mispredicts", "br_misp_retired.all_branches" }, 6696cbd26aSMatt Macy {"branches", "br_inst_retired.all_branches" }, 6796cbd26aSMatt Macy {"interrupts", "hw_interrupts.received"}, 6896cbd26aSMatt Macy {"ic-misses", "frontend_retired.l1i_miss"}, 69959826caSMatt Macy {NULL, NULL}, 70959826caSMatt Macy }; 71959826caSMatt Macy 72*07d80fd8SMatt Macy /* 73*07d80fd8SMatt Macy * The Intel fixed mode counters are: 74*07d80fd8SMatt Macy * "inst_retired.any", 75*07d80fd8SMatt Macy * "cpu_clk_unhalted.thread", 76*07d80fd8SMatt Macy * "cpu_clk_unhalted.thread_any", 77*07d80fd8SMatt Macy * "cpu_clk_unhalted.ref_tsc", 78*07d80fd8SMatt Macy * 79*07d80fd8SMatt Macy */ 80a191ed2dSMatt Macy 81959826caSMatt Macy static const char * 82959826caSMatt Macy pmu_alias_get(const char *name) 83959826caSMatt Macy { 84959826caSMatt Macy struct pmu_alias *pa; 85959826caSMatt Macy 86959826caSMatt Macy for (pa = pmu_alias_table; pa->pa_alias != NULL; pa++) 87959826caSMatt Macy if (strcasecmp(name, pa->pa_alias) == 0) 88959826caSMatt Macy return (pa->pa_name); 89959826caSMatt Macy return (name); 90959826caSMatt Macy } 91959826caSMatt Macy 92959826caSMatt Macy struct pmu_event_desc { 93959826caSMatt Macy uint64_t ped_period; 94959826caSMatt Macy uint64_t ped_offcore_rsp; 95959826caSMatt Macy uint32_t ped_event; 96959826caSMatt Macy uint32_t ped_frontend; 97959826caSMatt Macy uint32_t ped_ldlat; 98959826caSMatt Macy uint32_t ped_config1; 99*07d80fd8SMatt Macy int16_t ped_umask; 100959826caSMatt Macy uint8_t ped_cmask; 101959826caSMatt Macy uint8_t ped_any; 102959826caSMatt Macy uint8_t ped_inv; 103959826caSMatt Macy uint8_t ped_edge; 104959826caSMatt Macy uint8_t ped_fc_mask; 105959826caSMatt Macy uint8_t ped_ch_mask; 106959826caSMatt Macy }; 107959826caSMatt Macy 108959826caSMatt Macy static const struct pmu_events_map * 109959826caSMatt Macy pmu_events_map_get(void) 110959826caSMatt Macy { 111959826caSMatt Macy size_t s; 112959826caSMatt Macy char buf[64]; 113959826caSMatt Macy const struct pmu_events_map *pme; 114959826caSMatt Macy 115959826caSMatt Macy if (sysctlbyname("kern.hwpmc.cpuid", (void *)NULL, &s, 116959826caSMatt Macy (void *)NULL, 0) == -1) 117959826caSMatt Macy return (NULL); 118959826caSMatt Macy if (sysctlbyname("kern.hwpmc.cpuid", buf, &s, 119959826caSMatt Macy (void *)NULL, 0) == -1) 120959826caSMatt Macy return (NULL); 121959826caSMatt Macy for (pme = pmu_events_map; pme->cpuid != NULL; pme++) 122959826caSMatt Macy if (strcmp(buf, pme->cpuid) == 0) 123959826caSMatt Macy return (pme); 124959826caSMatt Macy return (NULL); 125959826caSMatt Macy } 126959826caSMatt Macy 127959826caSMatt Macy static const struct pmu_event * 128959826caSMatt Macy pmu_event_get(const char *event_name, int *idx) 129959826caSMatt Macy { 130959826caSMatt Macy const struct pmu_events_map *pme; 131959826caSMatt Macy const struct pmu_event *pe; 132959826caSMatt Macy int i; 133959826caSMatt Macy 134959826caSMatt Macy if ((pme = pmu_events_map_get()) == NULL) 135959826caSMatt Macy return (NULL); 136959826caSMatt Macy for (i = 0, pe = pme->table; pe->name || pe->desc || pe->event; pe++, i++) { 137959826caSMatt Macy if (pe->name == NULL) 138959826caSMatt Macy continue; 139959826caSMatt Macy if (strcasecmp(pe->name, event_name) == 0) { 140959826caSMatt Macy if (idx) 141959826caSMatt Macy *idx = i; 142959826caSMatt Macy return (pe); 143959826caSMatt Macy } 144959826caSMatt Macy } 145959826caSMatt Macy return (NULL); 146959826caSMatt Macy } 147959826caSMatt Macy 148959826caSMatt Macy const char * 14978beed2fSMatt Macy pmc_pmu_event_get_by_idx(int idx) 150959826caSMatt Macy { 151959826caSMatt Macy const struct pmu_events_map *pme; 152959826caSMatt Macy const struct pmu_event *pe; 153959826caSMatt Macy int i; 154959826caSMatt Macy 155959826caSMatt Macy if ((pme = pmu_events_map_get()) == NULL) 156959826caSMatt Macy return (NULL); 1578b20f975SMatt Macy for (i = 0, pe = pme->table; (pe->name || pe->desc || pe->event) && i < idx; pe++, i++); 158959826caSMatt Macy return (pe->name); 159959826caSMatt Macy } 160959826caSMatt Macy 161959826caSMatt Macy static int 162959826caSMatt Macy pmu_parse_event(struct pmu_event_desc *ped, const char *eventin) 163959826caSMatt Macy { 164959826caSMatt Macy char *event; 1658bed125dSMatt Macy char *kvp, *key, *value, *r; 166959826caSMatt Macy char *debug; 167959826caSMatt Macy 168959826caSMatt Macy if ((event = strdup(eventin)) == NULL) 169959826caSMatt Macy return (ENOMEM); 1708bed125dSMatt Macy r = event; 171959826caSMatt Macy bzero(ped, sizeof(*ped)); 172*07d80fd8SMatt Macy ped->ped_umask = -1; 173959826caSMatt Macy while ((kvp = strsep(&event, ",")) != NULL) { 174959826caSMatt Macy key = strsep(&kvp, "="); 175959826caSMatt Macy if (key == NULL) 176959826caSMatt Macy abort(); 177959826caSMatt Macy value = kvp; 178959826caSMatt Macy if (strcmp(key, "umask") == 0) 179959826caSMatt Macy ped->ped_umask = strtol(value, NULL, 16); 180959826caSMatt Macy else if (strcmp(key, "event") == 0) 181959826caSMatt Macy ped->ped_event = strtol(value, NULL, 16); 182959826caSMatt Macy else if (strcmp(key, "period") == 0) 183959826caSMatt Macy ped->ped_period = strtol(value, NULL, 10); 184959826caSMatt Macy else if (strcmp(key, "offcore_rsp") == 0) 185959826caSMatt Macy ped->ped_offcore_rsp = strtol(value, NULL, 16); 186959826caSMatt Macy else if (strcmp(key, "any") == 0) 187959826caSMatt Macy ped->ped_any = strtol(value, NULL, 10); 188959826caSMatt Macy else if (strcmp(key, "cmask") == 0) 189959826caSMatt Macy ped->ped_cmask = strtol(value, NULL, 10); 190959826caSMatt Macy else if (strcmp(key, "inv") == 0) 191959826caSMatt Macy ped->ped_inv = strtol(value, NULL, 10); 192959826caSMatt Macy else if (strcmp(key, "edge") == 0) 193959826caSMatt Macy ped->ped_edge = strtol(value, NULL, 10); 194959826caSMatt Macy else if (strcmp(key, "frontend") == 0) 195959826caSMatt Macy ped->ped_frontend = strtol(value, NULL, 16); 196959826caSMatt Macy else if (strcmp(key, "ldlat") == 0) 197959826caSMatt Macy ped->ped_ldlat = strtol(value, NULL, 16); 198959826caSMatt Macy else if (strcmp(key, "fc_mask") == 0) 199959826caSMatt Macy ped->ped_fc_mask = strtol(value, NULL, 16); 200959826caSMatt Macy else if (strcmp(key, "ch_mask") == 0) 201959826caSMatt Macy ped->ped_ch_mask = strtol(value, NULL, 16); 202959826caSMatt Macy else if (strcmp(key, "config1") == 0) 203959826caSMatt Macy ped->ped_config1 = strtol(value, NULL, 16); 204959826caSMatt Macy else { 205959826caSMatt Macy debug = getenv("PMUDEBUG"); 206959826caSMatt Macy if (debug != NULL && strcmp(debug, "true") == 0 && value != NULL) 207959826caSMatt Macy printf("unrecognized kvpair: %s:%s\n", key, value); 208959826caSMatt Macy } 209959826caSMatt Macy } 2108bed125dSMatt Macy free(r); 211959826caSMatt Macy return (0); 212959826caSMatt Macy } 213959826caSMatt Macy 214959826caSMatt Macy uint64_t 215959826caSMatt Macy pmc_pmu_sample_rate_get(const char *event_name) 216959826caSMatt Macy { 217959826caSMatt Macy const struct pmu_event *pe; 218959826caSMatt Macy struct pmu_event_desc ped; 219959826caSMatt Macy 220959826caSMatt Macy event_name = pmu_alias_get(event_name); 221959826caSMatt Macy if ((pe = pmu_event_get(event_name, NULL)) == NULL) 222959826caSMatt Macy return (DEFAULT_SAMPLE_COUNT); 223959826caSMatt Macy if (pe->alias && (pe = pmu_event_get(pe->alias, NULL)) == NULL) 224959826caSMatt Macy return (DEFAULT_SAMPLE_COUNT); 225959826caSMatt Macy if (pe->event == NULL) 226959826caSMatt Macy return (DEFAULT_SAMPLE_COUNT); 227959826caSMatt Macy if (pmu_parse_event(&ped, pe->event)) 228959826caSMatt Macy return (DEFAULT_SAMPLE_COUNT); 229959826caSMatt Macy return (ped.ped_period); 230959826caSMatt Macy } 231959826caSMatt Macy 232959826caSMatt Macy int 233959826caSMatt Macy pmc_pmu_enabled(void) 234959826caSMatt Macy { 235959826caSMatt Macy 236959826caSMatt Macy return (pmu_events_map_get() != NULL); 237959826caSMatt Macy } 238959826caSMatt Macy 239959826caSMatt Macy void 240fbf962e6SMatt Macy pmc_pmu_print_counters(const char *event_name) 241959826caSMatt Macy { 242959826caSMatt Macy const struct pmu_events_map *pme; 243959826caSMatt Macy const struct pmu_event *pe; 244959826caSMatt Macy struct pmu_event_desc ped; 245959826caSMatt Macy char *debug; 246959826caSMatt Macy int do_debug; 247959826caSMatt Macy 248959826caSMatt Macy debug = getenv("PMUDEBUG"); 249959826caSMatt Macy do_debug = 0; 250959826caSMatt Macy 251959826caSMatt Macy if (debug != NULL && strcmp(debug, "true") == 0) 252959826caSMatt Macy do_debug = 1; 253959826caSMatt Macy if ((pme = pmu_events_map_get()) == NULL) 254959826caSMatt Macy return; 255959826caSMatt Macy for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) { 256959826caSMatt Macy if (pe->name == NULL) 257959826caSMatt Macy continue; 258fbf962e6SMatt Macy if (event_name != NULL && strcasestr(pe->name, event_name) == NULL) 259fbf962e6SMatt Macy continue; 260959826caSMatt Macy printf("\t%s\n", pe->name); 261959826caSMatt Macy if (do_debug) 262959826caSMatt Macy pmu_parse_event(&ped, pe->event); 263959826caSMatt Macy } 264959826caSMatt Macy } 265959826caSMatt Macy 266959826caSMatt Macy void 267959826caSMatt Macy pmc_pmu_print_counter_desc(const char *ev) 268959826caSMatt Macy { 269959826caSMatt Macy const struct pmu_events_map *pme; 270959826caSMatt Macy const struct pmu_event *pe; 271959826caSMatt Macy 272959826caSMatt Macy if ((pme = pmu_events_map_get()) == NULL) 273959826caSMatt Macy return; 274959826caSMatt Macy for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) { 275959826caSMatt Macy if (pe->name == NULL) 276959826caSMatt Macy continue; 277959826caSMatt Macy if (strcasestr(pe->name, ev) != NULL && 278959826caSMatt Macy pe->desc != NULL) 279959826caSMatt Macy printf("%s:\t%s\n", pe->name, pe->desc); 280959826caSMatt Macy } 281959826caSMatt Macy } 282959826caSMatt Macy 283959826caSMatt Macy void 284959826caSMatt Macy pmc_pmu_print_counter_desc_long(const char *ev) 285959826caSMatt Macy { 286959826caSMatt Macy const struct pmu_events_map *pme; 287959826caSMatt Macy const struct pmu_event *pe; 288959826caSMatt Macy 289959826caSMatt Macy if ((pme = pmu_events_map_get()) == NULL) 290959826caSMatt Macy return; 291959826caSMatt Macy for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) { 292959826caSMatt Macy if (pe->name == NULL) 293959826caSMatt Macy continue; 294959826caSMatt Macy if (strcasestr(pe->name, ev) != NULL) { 295959826caSMatt Macy if (pe->long_desc != NULL) 296959826caSMatt Macy printf("%s:\n%s\n", pe->name, pe->long_desc); 297959826caSMatt Macy else if (pe->desc != NULL) 298959826caSMatt Macy printf("%s:\t%s\n", pe->name, pe->desc); 299959826caSMatt Macy } 300959826caSMatt Macy } 301959826caSMatt Macy } 302959826caSMatt Macy 303fbf962e6SMatt Macy void 304fbf962e6SMatt Macy pmc_pmu_print_counter_full(const char *ev) 305fbf962e6SMatt Macy { 306fbf962e6SMatt Macy const struct pmu_events_map *pme; 307fbf962e6SMatt Macy const struct pmu_event *pe; 308fbf962e6SMatt Macy 309fbf962e6SMatt Macy if ((pme = pmu_events_map_get()) == NULL) 310fbf962e6SMatt Macy return; 311fbf962e6SMatt Macy for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) { 312fbf962e6SMatt Macy if (pe->name == NULL) 313fbf962e6SMatt Macy continue; 314fbf962e6SMatt Macy if (strcasestr(pe->name, ev) == NULL) 315fbf962e6SMatt Macy continue; 316fbf962e6SMatt Macy printf("name: %s\n", pe->name); 317fbf962e6SMatt Macy if (pe->long_desc != NULL) 318fbf962e6SMatt Macy printf("desc: %s\n", pe->long_desc); 319fbf962e6SMatt Macy else if (pe->desc != NULL) 320fbf962e6SMatt Macy printf("desc: %s\n", pe->desc); 321fbf962e6SMatt Macy if (pe->event != NULL) 322fbf962e6SMatt Macy printf("event: %s\n", pe->event); 323fbf962e6SMatt Macy if (pe->topic != NULL) 324fbf962e6SMatt Macy printf("topic: %s\n", pe->topic); 325fbf962e6SMatt Macy if (pe->pmu != NULL) 326fbf962e6SMatt Macy printf("pmu: %s\n", pe->pmu); 327fbf962e6SMatt Macy if (pe->unit != NULL) 328fbf962e6SMatt Macy printf("unit: %s\n", pe->unit); 329fbf962e6SMatt Macy if (pe->perpkg != NULL) 330fbf962e6SMatt Macy printf("perpkg: %s\n", pe->perpkg); 331fbf962e6SMatt Macy if (pe->metric_expr != NULL) 332fbf962e6SMatt Macy printf("metric_expr: %s\n", pe->metric_expr); 333fbf962e6SMatt Macy if (pe->metric_name != NULL) 334fbf962e6SMatt Macy printf("metric_name: %s\n", pe->metric_name); 335fbf962e6SMatt Macy if (pe->metric_group != NULL) 336fbf962e6SMatt Macy printf("metric_group: %s\n", pe->metric_group); 337fbf962e6SMatt Macy } 338fbf962e6SMatt Macy } 339fbf962e6SMatt Macy 340959826caSMatt Macy int 341959826caSMatt Macy pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm) 342959826caSMatt Macy { 343959826caSMatt Macy const struct pmu_event *pe; 344959826caSMatt Macy struct pmu_event_desc ped; 345959826caSMatt Macy struct pmc_md_iap_op_pmcallocate *iap; 346a191ed2dSMatt Macy int idx, isfixed; 347959826caSMatt Macy 348959826caSMatt Macy iap = &pm->pm_md.pm_iap; 349a191ed2dSMatt Macy isfixed = 0; 350959826caSMatt Macy bzero(iap, sizeof(*iap)); 351959826caSMatt Macy event_name = pmu_alias_get(event_name); 352a191ed2dSMatt Macy pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE); 353959826caSMatt Macy if ((pe = pmu_event_get(event_name, &idx)) == NULL) 354959826caSMatt Macy return (ENOENT); 355959826caSMatt Macy if (pe->alias && (pe = pmu_event_get(pe->alias, &idx)) == NULL) 356959826caSMatt Macy return (ENOENT); 357959826caSMatt Macy if (pe->event == NULL) 358959826caSMatt Macy return (ENOENT); 359959826caSMatt Macy if (pmu_parse_event(&ped, pe->event)) 360959826caSMatt Macy return (ENOENT); 361959826caSMatt Macy 362*07d80fd8SMatt Macy 363*07d80fd8SMatt Macy if (strcasestr(event_name, "UNC_") == event_name || 364785dd70dSMatt Macy strcasestr(event_name, "uncore") != NULL) { 365785dd70dSMatt Macy pm->pm_class = PMC_CLASS_UCP; 366a191ed2dSMatt Macy pm->pm_caps |= PMC_CAP_QUALIFIER; 367*07d80fd8SMatt Macy } else if ((ped.ped_umask == -1) || 368*07d80fd8SMatt Macy (ped.ped_event == 0x0 && ped.ped_umask == 0x3)) { 369*07d80fd8SMatt Macy pm->pm_class = PMC_CLASS_IAF; 370*07d80fd8SMatt Macy } else { 371959826caSMatt Macy pm->pm_class = PMC_CLASS_IAP; 372*07d80fd8SMatt Macy pm->pm_caps |= PMC_CAP_QUALIFIER; 373785dd70dSMatt Macy } 374959826caSMatt Macy pm->pm_ev = idx; 375959826caSMatt Macy iap->pm_iap_config |= IAP_EVSEL(ped.ped_event); 376*07d80fd8SMatt Macy if (ped.ped_umask > 0) 377959826caSMatt Macy iap->pm_iap_config |= IAP_UMASK(ped.ped_umask); 378959826caSMatt Macy iap->pm_iap_config |= IAP_CMASK(ped.ped_cmask); 379959826caSMatt Macy iap->pm_iap_rsp = ped.ped_offcore_rsp; 380959826caSMatt Macy 381959826caSMatt Macy iap->pm_iap_config |= (IAP_USR | IAP_OS); 382959826caSMatt Macy if (ped.ped_edge) 383959826caSMatt Macy iap->pm_iap_config |= IAP_EDGE; 384959826caSMatt Macy if (ped.ped_any) 385959826caSMatt Macy iap->pm_iap_config |= IAP_ANY; 386959826caSMatt Macy if (ped.ped_inv) 387959826caSMatt Macy iap->pm_iap_config |= IAP_EDGE; 388959826caSMatt Macy if (pm->pm_caps & PMC_CAP_INTERRUPT) 389959826caSMatt Macy iap->pm_iap_config |= IAP_INT; 390959826caSMatt Macy return (0); 391959826caSMatt Macy } 392959826caSMatt Macy 39378beed2fSMatt Macy /* 39478beed2fSMatt Macy * Ultimately rely on AMD calling theirs the same 39578beed2fSMatt Macy */ 39678beed2fSMatt Macy static const char *stat_mode_cntrs[] = { 397a191ed2dSMatt Macy "cpu_clk_unhalted.thread_any", 39878beed2fSMatt Macy "inst_retired.any", 39978beed2fSMatt Macy "br_inst_retired.all_branches", 40078beed2fSMatt Macy "br_misp_retired.all_branches", 401a191ed2dSMatt Macy "longest_lat_cache.reference", 402a191ed2dSMatt Macy "longest_lat_cache.miss", 40378beed2fSMatt Macy }; 40478beed2fSMatt Macy 40578beed2fSMatt Macy int 40678beed2fSMatt Macy pmc_pmu_stat_mode(const char ***cntrs) 40778beed2fSMatt Macy { 40878beed2fSMatt Macy if (pmc_pmu_enabled()) { 40978beed2fSMatt Macy *cntrs = stat_mode_cntrs; 41078beed2fSMatt Macy return (0); 41178beed2fSMatt Macy } 41278beed2fSMatt Macy return (EOPNOTSUPP); 41378beed2fSMatt Macy } 41478beed2fSMatt Macy 415959826caSMatt Macy #else 4168b20f975SMatt Macy 4178b20f975SMatt Macy uint64_t 4188b20f975SMatt Macy pmc_pmu_sample_rate_get(const char *event_name __unused) 4198b20f975SMatt Macy { 4208b20f975SMatt Macy return (DEFAULT_SAMPLE_COUNT); 4218b20f975SMatt Macy } 4228b20f975SMatt Macy 4238b20f975SMatt Macy void 424fbf962e6SMatt Macy pmc_pmu_print_counters(const char *event_name __unused) 4258b20f975SMatt Macy { 4268b20f975SMatt Macy } 4278b20f975SMatt Macy 4288b20f975SMatt Macy void 4298b20f975SMatt Macy pmc_pmu_print_counter_desc(const char *e __unused) 4308b20f975SMatt Macy { 4318b20f975SMatt Macy } 4328b20f975SMatt Macy 4338b20f975SMatt Macy void 4348b20f975SMatt Macy pmc_pmu_print_counter_desc_long(const char *e __unused) 4358b20f975SMatt Macy { 4368b20f975SMatt Macy } 4378b20f975SMatt Macy 438fbf962e6SMatt Macy void 439fbf962e6SMatt Macy pmc_pmu_print_counter_full(const char *e __unused) 440fbf962e6SMatt Macy { 441fbf962e6SMatt Macy 442fbf962e6SMatt Macy } 443fbf962e6SMatt Macy 4448b20f975SMatt Macy int 4458b20f975SMatt Macy pmc_pmu_enabled(void) 4468b20f975SMatt Macy { 4478b20f975SMatt Macy return (0); 4488b20f975SMatt Macy } 4498b20f975SMatt Macy 4508b20f975SMatt Macy int 4518b20f975SMatt Macy pmc_pmu_pmcallocate(const char *e __unused, struct pmc_op_pmcallocate *p __unused) 4528b20f975SMatt Macy { 4538b20f975SMatt Macy return (EOPNOTSUPP); 4548b20f975SMatt Macy } 4558b20f975SMatt Macy 4568b20f975SMatt Macy const char * 4578b20f975SMatt Macy pmc_pmu_event_get_by_idx(int idx __unused) 4588b20f975SMatt Macy { 4598b20f975SMatt Macy return (NULL); 4608b20f975SMatt Macy } 4618b20f975SMatt Macy int 4628b20f975SMatt Macy pmc_pmu_stat_mode(const char ***a __unused) 4638b20f975SMatt Macy { 4648b20f975SMatt Macy return (EOPNOTSUPP); 4658b20f975SMatt Macy } 466959826caSMatt Macy 467959826caSMatt Macy #endif 468