1291dcb98SKim Phillips // SPDX-License-Identifier: GPL-2.0 2291dcb98SKim Phillips /* 3291dcb98SKim Phillips * AMD specific. Provide textual annotation for IBS raw sample data. 4291dcb98SKim Phillips */ 5291dcb98SKim Phillips 6291dcb98SKim Phillips #include <unistd.h> 7291dcb98SKim Phillips #include <stdio.h> 8291dcb98SKim Phillips #include <string.h> 9291dcb98SKim Phillips #include <inttypes.h> 10291dcb98SKim Phillips 11291dcb98SKim Phillips #include <linux/string.h> 12291dcb98SKim Phillips #include "../../arch/x86/include/asm/amd-ibs.h" 13291dcb98SKim Phillips 14291dcb98SKim Phillips #include "debug.h" 15291dcb98SKim Phillips #include "session.h" 16291dcb98SKim Phillips #include "evlist.h" 17291dcb98SKim Phillips #include "sample-raw.h" 18291dcb98SKim Phillips #include "pmu-events/pmu-events.h" 199823147dSArnaldo Carvalho de Melo #include "util/sample.h" 20291dcb98SKim Phillips 21291dcb98SKim Phillips static u32 cpu_family, cpu_model, ibs_fetch_type, ibs_op_type; 220429796eSRavi Bangoria static bool zen4_ibs_extensions; 23291dcb98SKim Phillips 24291dcb98SKim Phillips static void pr_ibs_fetch_ctl(union ibs_fetch_ctl reg) 25291dcb98SKim Phillips { 26291dcb98SKim Phillips const char * const ic_miss_strs[] = { 27291dcb98SKim Phillips " IcMiss 0", 28291dcb98SKim Phillips " IcMiss 1", 29291dcb98SKim Phillips }; 30291dcb98SKim Phillips const char * const l1tlb_pgsz_strs[] = { 31291dcb98SKim Phillips " L1TlbPgSz 4KB", 32291dcb98SKim Phillips " L1TlbPgSz 2MB", 33291dcb98SKim Phillips " L1TlbPgSz 1GB", 34291dcb98SKim Phillips " L1TlbPgSz RESERVED" 35291dcb98SKim Phillips }; 36291dcb98SKim Phillips const char * const l1tlb_pgsz_strs_erratum1347[] = { 37291dcb98SKim Phillips " L1TlbPgSz 4KB", 38291dcb98SKim Phillips " L1TlbPgSz 16KB", 39291dcb98SKim Phillips " L1TlbPgSz 2MB", 40291dcb98SKim Phillips " L1TlbPgSz 1GB" 41291dcb98SKim Phillips }; 42291dcb98SKim Phillips const char *ic_miss_str = NULL; 43291dcb98SKim Phillips const char *l1tlb_pgsz_str = NULL; 440429796eSRavi Bangoria char l3_miss_str[sizeof(" L3MissOnly _ FetchOcMiss _ FetchL3Miss _")] = ""; 45291dcb98SKim Phillips 46291dcb98SKim Phillips if (cpu_family == 0x19 && cpu_model < 0x10) { 47291dcb98SKim Phillips /* 48291dcb98SKim Phillips * Erratum #1238 workaround is to ignore MSRC001_1030[IbsIcMiss] 49291dcb98SKim Phillips * Erratum #1347 workaround is to use table provided in erratum 50291dcb98SKim Phillips */ 51291dcb98SKim Phillips if (reg.phy_addr_valid) 52291dcb98SKim Phillips l1tlb_pgsz_str = l1tlb_pgsz_strs_erratum1347[reg.l1tlb_pgsz]; 53291dcb98SKim Phillips } else { 54291dcb98SKim Phillips if (reg.phy_addr_valid) 55291dcb98SKim Phillips l1tlb_pgsz_str = l1tlb_pgsz_strs[reg.l1tlb_pgsz]; 56291dcb98SKim Phillips ic_miss_str = ic_miss_strs[reg.ic_miss]; 57291dcb98SKim Phillips } 58291dcb98SKim Phillips 590429796eSRavi Bangoria if (zen4_ibs_extensions) { 600429796eSRavi Bangoria snprintf(l3_miss_str, sizeof(l3_miss_str), 610429796eSRavi Bangoria " L3MissOnly %d FetchOcMiss %d FetchL3Miss %d", 620429796eSRavi Bangoria reg.l3_miss_only, reg.fetch_oc_miss, reg.fetch_l3_miss); 630429796eSRavi Bangoria } 640429796eSRavi Bangoria 65291dcb98SKim Phillips printf("ibs_fetch_ctl:\t%016llx MaxCnt %7d Cnt %7d Lat %5d En %d Val %d Comp %d%s " 660429796eSRavi Bangoria "PhyAddrValid %d%s L1TlbMiss %d L2TlbMiss %d RandEn %d%s%s\n", 67291dcb98SKim Phillips reg.val, reg.fetch_maxcnt << 4, reg.fetch_cnt << 4, reg.fetch_lat, 68291dcb98SKim Phillips reg.fetch_en, reg.fetch_val, reg.fetch_comp, ic_miss_str ? : "", 69291dcb98SKim Phillips reg.phy_addr_valid, l1tlb_pgsz_str ? : "", reg.l1tlb_miss, reg.l2tlb_miss, 700429796eSRavi Bangoria reg.rand_en, reg.fetch_comp ? (reg.fetch_l2_miss ? " L2Miss 1" : " L2Miss 0") : "", 710429796eSRavi Bangoria l3_miss_str); 72291dcb98SKim Phillips } 73291dcb98SKim Phillips 74291dcb98SKim Phillips static void pr_ic_ibs_extd_ctl(union ic_ibs_extd_ctl reg) 75291dcb98SKim Phillips { 76291dcb98SKim Phillips printf("ic_ibs_ext_ctl:\t%016llx IbsItlbRefillLat %3d\n", reg.val, reg.itlb_refill_lat); 77291dcb98SKim Phillips } 78291dcb98SKim Phillips 79291dcb98SKim Phillips static void pr_ibs_op_ctl(union ibs_op_ctl reg) 80291dcb98SKim Phillips { 810429796eSRavi Bangoria char l3_miss_only[sizeof(" L3MissOnly _")] = ""; 820429796eSRavi Bangoria 830429796eSRavi Bangoria if (zen4_ibs_extensions) 840429796eSRavi Bangoria snprintf(l3_miss_only, sizeof(l3_miss_only), " L3MissOnly %d", reg.l3_miss_only); 850429796eSRavi Bangoria 860429796eSRavi Bangoria printf("ibs_op_ctl:\t%016llx MaxCnt %9d%s En %d Val %d CntCtl %d=%s CurCnt %9d\n", 870429796eSRavi Bangoria reg.val, ((reg.opmaxcnt_ext << 16) | reg.opmaxcnt) << 4, l3_miss_only, 880429796eSRavi Bangoria reg.op_en, reg.op_val, reg.cnt_ctl, 890429796eSRavi Bangoria reg.cnt_ctl ? "uOps" : "cycles", reg.opcurcnt); 90291dcb98SKim Phillips } 91291dcb98SKim Phillips 92291dcb98SKim Phillips static void pr_ibs_op_data(union ibs_op_data reg) 93291dcb98SKim Phillips { 94291dcb98SKim Phillips printf("ibs_op_data:\t%016llx CompToRetCtr %5d TagToRetCtr %5d%s%s%s BrnRet %d " 95291dcb98SKim Phillips " RipInvalid %d BrnFuse %d Microcode %d\n", 96291dcb98SKim Phillips reg.val, reg.comp_to_ret_ctr, reg.tag_to_ret_ctr, 97291dcb98SKim Phillips reg.op_brn_ret ? (reg.op_return ? " OpReturn 1" : " OpReturn 0") : "", 98291dcb98SKim Phillips reg.op_brn_ret ? (reg.op_brn_taken ? " OpBrnTaken 1" : " OpBrnTaken 0") : "", 99291dcb98SKim Phillips reg.op_brn_ret ? (reg.op_brn_misp ? " OpBrnMisp 1" : " OpBrnMisp 0") : "", 100291dcb98SKim Phillips reg.op_brn_ret, reg.op_rip_invalid, reg.op_brn_fuse, reg.op_microcode); 101291dcb98SKim Phillips } 102291dcb98SKim Phillips 1030429796eSRavi Bangoria static void pr_ibs_op_data2_extended(union ibs_op_data2 reg) 1040429796eSRavi Bangoria { 1050429796eSRavi Bangoria static const char * const data_src_str[] = { 1060429796eSRavi Bangoria "", 1070429796eSRavi Bangoria " DataSrc 1=Local L3 or other L1/L2 in CCX", 108*3d3a3a49SRavi Bangoria " DataSrc 2=Another CCX cache in the same NUMA node", 109*3d3a3a49SRavi Bangoria " DataSrc 3=DRAM", 1100429796eSRavi Bangoria " DataSrc 4=(reserved)", 111*3d3a3a49SRavi Bangoria " DataSrc 5=Another CCX cache in a different NUMA node", 112*3d3a3a49SRavi Bangoria " DataSrc 6=Long-latency DIMM", 113*3d3a3a49SRavi Bangoria " DataSrc 7=MMIO/Config/PCI/APIC", 114*3d3a3a49SRavi Bangoria " DataSrc 8=Extension Memory", 1150429796eSRavi Bangoria " DataSrc 9=(reserved)", 1160429796eSRavi Bangoria " DataSrc 10=(reserved)", 1170429796eSRavi Bangoria " DataSrc 11=(reserved)", 118*3d3a3a49SRavi Bangoria " DataSrc 12=Coherent Memory of a different processor type", 1190429796eSRavi Bangoria /* 13 to 31 are reserved. Avoid printing them. */ 1200429796eSRavi Bangoria }; 1210429796eSRavi Bangoria int data_src = (reg.data_src_hi << 3) | reg.data_src_lo; 1220429796eSRavi Bangoria 1230429796eSRavi Bangoria printf("ibs_op_data2:\t%016llx %sRmtNode %d%s\n", reg.val, 1240429796eSRavi Bangoria (data_src == 1 || data_src == 2 || data_src == 5) ? 1250429796eSRavi Bangoria (reg.cache_hit_st ? "CacheHitSt 1=O-State " : "CacheHitSt 0=M-state ") : "", 1260429796eSRavi Bangoria reg.rmt_node, 1270429796eSRavi Bangoria data_src < (int)ARRAY_SIZE(data_src_str) ? data_src_str[data_src] : ""); 1280429796eSRavi Bangoria } 1290429796eSRavi Bangoria 1300429796eSRavi Bangoria static void pr_ibs_op_data2_default(union ibs_op_data2 reg) 131291dcb98SKim Phillips { 132291dcb98SKim Phillips static const char * const data_src_str[] = { 133291dcb98SKim Phillips "", 134291dcb98SKim Phillips " DataSrc 1=(reserved)", 135291dcb98SKim Phillips " DataSrc 2=Local node cache", 136291dcb98SKim Phillips " DataSrc 3=DRAM", 137291dcb98SKim Phillips " DataSrc 4=Remote node cache", 138291dcb98SKim Phillips " DataSrc 5=(reserved)", 139291dcb98SKim Phillips " DataSrc 6=(reserved)", 140291dcb98SKim Phillips " DataSrc 7=Other" 141291dcb98SKim Phillips }; 142291dcb98SKim Phillips 143291dcb98SKim Phillips printf("ibs_op_data2:\t%016llx %sRmtNode %d%s\n", reg.val, 144c1f4f92bSRavi Bangoria reg.data_src_lo == 2 ? (reg.cache_hit_st ? "CacheHitSt 1=O-State " 145291dcb98SKim Phillips : "CacheHitSt 0=M-state ") : "", 146c1f4f92bSRavi Bangoria reg.rmt_node, data_src_str[reg.data_src_lo]); 147291dcb98SKim Phillips } 148291dcb98SKim Phillips 1490429796eSRavi Bangoria static void pr_ibs_op_data2(union ibs_op_data2 reg) 1500429796eSRavi Bangoria { 1510429796eSRavi Bangoria if (zen4_ibs_extensions) 1520429796eSRavi Bangoria return pr_ibs_op_data2_extended(reg); 1530429796eSRavi Bangoria pr_ibs_op_data2_default(reg); 1540429796eSRavi Bangoria } 1550429796eSRavi Bangoria 156291dcb98SKim Phillips static void pr_ibs_op_data3(union ibs_op_data3 reg) 157291dcb98SKim Phillips { 158291dcb98SKim Phillips char l2_miss_str[sizeof(" L2Miss _")] = ""; 159291dcb98SKim Phillips char op_mem_width_str[sizeof(" OpMemWidth _____ bytes")] = ""; 160291dcb98SKim Phillips char op_dc_miss_open_mem_reqs_str[sizeof(" OpDcMissOpenMemReqs __")] = ""; 161291dcb98SKim Phillips 162291dcb98SKim Phillips /* 163291dcb98SKim Phillips * Erratum #1293 164291dcb98SKim Phillips * Ignore L2Miss and OpDcMissOpenMemReqs (and opdata2) if DcMissNoMabAlloc or SwPf set 165291dcb98SKim Phillips */ 166291dcb98SKim Phillips if (!(cpu_family == 0x19 && cpu_model < 0x10 && (reg.dc_miss_no_mab_alloc || reg.sw_pf))) { 167291dcb98SKim Phillips snprintf(l2_miss_str, sizeof(l2_miss_str), " L2Miss %d", reg.l2_miss); 168291dcb98SKim Phillips snprintf(op_dc_miss_open_mem_reqs_str, sizeof(op_dc_miss_open_mem_reqs_str), 169291dcb98SKim Phillips " OpDcMissOpenMemReqs %2d", reg.op_dc_miss_open_mem_reqs); 170291dcb98SKim Phillips } 171291dcb98SKim Phillips 172291dcb98SKim Phillips if (reg.op_mem_width) 173291dcb98SKim Phillips snprintf(op_mem_width_str, sizeof(op_mem_width_str), 174291dcb98SKim Phillips " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1)); 175291dcb98SKim Phillips 176291dcb98SKim Phillips printf("ibs_op_data3:\t%016llx LdOp %d StOp %d DcL1TlbMiss %d DcL2TlbMiss %d " 177291dcb98SKim Phillips "DcL1TlbHit2M %d DcL1TlbHit1G %d DcL2TlbHit2M %d DcMiss %d DcMisAcc %d " 178291dcb98SKim Phillips "DcWcMemAcc %d DcUcMemAcc %d DcLockedOp %d DcMissNoMabAlloc %d DcLinAddrValid %d " 179291dcb98SKim Phillips "DcPhyAddrValid %d DcL2TlbHit1G %d%s SwPf %d%s%s DcMissLat %5d TlbRefillLat %5d\n", 180291dcb98SKim Phillips reg.val, reg.ld_op, reg.st_op, reg.dc_l1tlb_miss, reg.dc_l2tlb_miss, 181291dcb98SKim Phillips reg.dc_l1tlb_hit_2m, reg.dc_l1tlb_hit_1g, reg.dc_l2tlb_hit_2m, reg.dc_miss, 182291dcb98SKim Phillips reg.dc_mis_acc, reg.dc_wc_mem_acc, reg.dc_uc_mem_acc, reg.dc_locked_op, 183291dcb98SKim Phillips reg.dc_miss_no_mab_alloc, reg.dc_lin_addr_valid, reg.dc_phy_addr_valid, 184291dcb98SKim Phillips reg.dc_l2_tlb_hit_1g, l2_miss_str, reg.sw_pf, op_mem_width_str, 185291dcb98SKim Phillips op_dc_miss_open_mem_reqs_str, reg.dc_miss_lat, reg.tlb_refill_lat); 186291dcb98SKim Phillips } 187291dcb98SKim Phillips 188291dcb98SKim Phillips /* 189291dcb98SKim Phillips * IBS Op/Execution MSRs always saved, in order, are: 190291dcb98SKim Phillips * IBS_OP_CTL, IBS_OP_RIP, IBS_OP_DATA, IBS_OP_DATA2, 191291dcb98SKim Phillips * IBS_OP_DATA3, IBS_DC_LINADDR, IBS_DC_PHYSADDR, BP_IBSTGT_RIP 192291dcb98SKim Phillips */ 193291dcb98SKim Phillips static void amd_dump_ibs_op(struct perf_sample *sample) 194291dcb98SKim Phillips { 195291dcb98SKim Phillips struct perf_ibs_data *data = sample->raw_data; 196291dcb98SKim Phillips union ibs_op_ctl *op_ctl = (union ibs_op_ctl *)data->data; 197291dcb98SKim Phillips __u64 *rip = (__u64 *)op_ctl + 1; 198291dcb98SKim Phillips union ibs_op_data *op_data = (union ibs_op_data *)(rip + 1); 199291dcb98SKim Phillips union ibs_op_data3 *op_data3 = (union ibs_op_data3 *)(rip + 3); 200291dcb98SKim Phillips 201291dcb98SKim Phillips pr_ibs_op_ctl(*op_ctl); 202291dcb98SKim Phillips if (!op_data->op_rip_invalid) 203291dcb98SKim Phillips printf("IbsOpRip:\t%016llx\n", *rip); 204291dcb98SKim Phillips pr_ibs_op_data(*op_data); 205291dcb98SKim Phillips /* 206291dcb98SKim Phillips * Erratum #1293: ignore op_data2 if DcMissNoMabAlloc or SwPf are set 207291dcb98SKim Phillips */ 208291dcb98SKim Phillips if (!(cpu_family == 0x19 && cpu_model < 0x10 && 209291dcb98SKim Phillips (op_data3->dc_miss_no_mab_alloc || op_data3->sw_pf))) 210291dcb98SKim Phillips pr_ibs_op_data2(*(union ibs_op_data2 *)(rip + 2)); 211291dcb98SKim Phillips pr_ibs_op_data3(*op_data3); 212291dcb98SKim Phillips if (op_data3->dc_lin_addr_valid) 213291dcb98SKim Phillips printf("IbsDCLinAd:\t%016llx\n", *(rip + 4)); 214291dcb98SKim Phillips if (op_data3->dc_phy_addr_valid) 215291dcb98SKim Phillips printf("IbsDCPhysAd:\t%016llx\n", *(rip + 5)); 216291dcb98SKim Phillips if (op_data->op_brn_ret && *(rip + 6)) 217291dcb98SKim Phillips printf("IbsBrTarget:\t%016llx\n", *(rip + 6)); 218291dcb98SKim Phillips } 219291dcb98SKim Phillips 220291dcb98SKim Phillips /* 221291dcb98SKim Phillips * IBS Fetch MSRs always saved, in order, are: 222291dcb98SKim Phillips * IBS_FETCH_CTL, IBS_FETCH_LINADDR, IBS_FETCH_PHYSADDR, IC_IBS_EXTD_CTL 223291dcb98SKim Phillips */ 224291dcb98SKim Phillips static void amd_dump_ibs_fetch(struct perf_sample *sample) 225291dcb98SKim Phillips { 226291dcb98SKim Phillips struct perf_ibs_data *data = sample->raw_data; 227291dcb98SKim Phillips union ibs_fetch_ctl *fetch_ctl = (union ibs_fetch_ctl *)data->data; 228291dcb98SKim Phillips __u64 *addr = (__u64 *)fetch_ctl + 1; 229291dcb98SKim Phillips union ic_ibs_extd_ctl *extd_ctl = (union ic_ibs_extd_ctl *)addr + 2; 230291dcb98SKim Phillips 231291dcb98SKim Phillips pr_ibs_fetch_ctl(*fetch_ctl); 232291dcb98SKim Phillips printf("IbsFetchLinAd:\t%016llx\n", *addr++); 233291dcb98SKim Phillips if (fetch_ctl->phy_addr_valid) 234291dcb98SKim Phillips printf("IbsFetchPhysAd:\t%016llx\n", *addr); 235291dcb98SKim Phillips pr_ic_ibs_extd_ctl(*extd_ctl); 236291dcb98SKim Phillips } 237291dcb98SKim Phillips 238291dcb98SKim Phillips /* 239291dcb98SKim Phillips * Test for enable and valid bits in captured control MSRs. 240291dcb98SKim Phillips */ 241291dcb98SKim Phillips static bool is_valid_ibs_fetch_sample(struct perf_sample *sample) 242291dcb98SKim Phillips { 243291dcb98SKim Phillips struct perf_ibs_data *data = sample->raw_data; 244291dcb98SKim Phillips union ibs_fetch_ctl *fetch_ctl = (union ibs_fetch_ctl *)data->data; 245291dcb98SKim Phillips 246291dcb98SKim Phillips if (fetch_ctl->fetch_en && fetch_ctl->fetch_val) 247291dcb98SKim Phillips return true; 248291dcb98SKim Phillips 249291dcb98SKim Phillips return false; 250291dcb98SKim Phillips } 251291dcb98SKim Phillips 252291dcb98SKim Phillips static bool is_valid_ibs_op_sample(struct perf_sample *sample) 253291dcb98SKim Phillips { 254291dcb98SKim Phillips struct perf_ibs_data *data = sample->raw_data; 255291dcb98SKim Phillips union ibs_op_ctl *op_ctl = (union ibs_op_ctl *)data->data; 256291dcb98SKim Phillips 257291dcb98SKim Phillips if (op_ctl->op_en && op_ctl->op_val) 258291dcb98SKim Phillips return true; 259291dcb98SKim Phillips 260291dcb98SKim Phillips return false; 261291dcb98SKim Phillips } 262291dcb98SKim Phillips 263291dcb98SKim Phillips /* AMD vendor specific raw sample function. Check for PERF_RECORD_SAMPLE events 264291dcb98SKim Phillips * and if the event was triggered by IBS, display its raw data with decoded text. 265291dcb98SKim Phillips * The function is only invoked when the dump flag -D is set. 266291dcb98SKim Phillips */ 267291dcb98SKim Phillips void evlist__amd_sample_raw(struct evlist *evlist, union perf_event *event, 268291dcb98SKim Phillips struct perf_sample *sample) 269291dcb98SKim Phillips { 270291dcb98SKim Phillips struct evsel *evsel; 271291dcb98SKim Phillips 272291dcb98SKim Phillips if (event->header.type != PERF_RECORD_SAMPLE || !sample->raw_size) 273291dcb98SKim Phillips return; 274291dcb98SKim Phillips 275291dcb98SKim Phillips evsel = evlist__event2evsel(evlist, event); 276291dcb98SKim Phillips if (!evsel) 277291dcb98SKim Phillips return; 278291dcb98SKim Phillips 279291dcb98SKim Phillips if (evsel->core.attr.type == ibs_fetch_type) { 280291dcb98SKim Phillips if (!is_valid_ibs_fetch_sample(sample)) { 281291dcb98SKim Phillips pr_debug("Invalid raw IBS Fetch MSR data encountered\n"); 282291dcb98SKim Phillips return; 283291dcb98SKim Phillips } 284291dcb98SKim Phillips amd_dump_ibs_fetch(sample); 285291dcb98SKim Phillips } else if (evsel->core.attr.type == ibs_op_type) { 286291dcb98SKim Phillips if (!is_valid_ibs_op_sample(sample)) { 287291dcb98SKim Phillips pr_debug("Invalid raw IBS Op MSR data encountered\n"); 288291dcb98SKim Phillips return; 289291dcb98SKim Phillips } 290291dcb98SKim Phillips amd_dump_ibs_op(sample); 291291dcb98SKim Phillips } 292291dcb98SKim Phillips } 293291dcb98SKim Phillips 294291dcb98SKim Phillips static void parse_cpuid(struct perf_env *env) 295291dcb98SKim Phillips { 296291dcb98SKim Phillips const char *cpuid; 297291dcb98SKim Phillips int ret; 298291dcb98SKim Phillips 299291dcb98SKim Phillips cpuid = perf_env__cpuid(env); 300291dcb98SKim Phillips /* 301291dcb98SKim Phillips * cpuid = "AuthenticAMD,family,model,stepping" 302291dcb98SKim Phillips */ 303291dcb98SKim Phillips ret = sscanf(cpuid, "%*[^,],%u,%u", &cpu_family, &cpu_model); 304291dcb98SKim Phillips if (ret != 2) 305291dcb98SKim Phillips pr_debug("problem parsing cpuid\n"); 306291dcb98SKim Phillips } 307291dcb98SKim Phillips 308291dcb98SKim Phillips /* 309291dcb98SKim Phillips * Find and assign the type number used for ibs_op or ibs_fetch samples. 310291dcb98SKim Phillips * Device names can be large - we are only interested in the first 9 characters, 311291dcb98SKim Phillips * to match "ibs_fetch". 312291dcb98SKim Phillips */ 313291dcb98SKim Phillips bool evlist__has_amd_ibs(struct evlist *evlist) 314291dcb98SKim Phillips { 315291dcb98SKim Phillips struct perf_env *env = evlist->env; 316291dcb98SKim Phillips int ret, nr_pmu_mappings = perf_env__nr_pmu_mappings(env); 317291dcb98SKim Phillips const char *pmu_mapping = perf_env__pmu_mappings(env); 318291dcb98SKim Phillips char name[sizeof("ibs_fetch")]; 319291dcb98SKim Phillips u32 type; 320291dcb98SKim Phillips 321291dcb98SKim Phillips while (nr_pmu_mappings--) { 322291dcb98SKim Phillips ret = sscanf(pmu_mapping, "%u:%9s", &type, name); 323291dcb98SKim Phillips if (ret == 2) { 324291dcb98SKim Phillips if (strstarts(name, "ibs_op")) 325291dcb98SKim Phillips ibs_op_type = type; 326291dcb98SKim Phillips else if (strstarts(name, "ibs_fetch")) 327291dcb98SKim Phillips ibs_fetch_type = type; 328291dcb98SKim Phillips } 329291dcb98SKim Phillips pmu_mapping += strlen(pmu_mapping) + 1 /* '\0' */; 330291dcb98SKim Phillips } 331291dcb98SKim Phillips 3320429796eSRavi Bangoria if (perf_env__find_pmu_cap(env, "ibs_op", "zen4_ibs_extensions")) 3330429796eSRavi Bangoria zen4_ibs_extensions = 1; 3340429796eSRavi Bangoria 335291dcb98SKim Phillips if (ibs_fetch_type || ibs_op_type) { 336291dcb98SKim Phillips if (!cpu_family) 337291dcb98SKim Phillips parse_cpuid(env); 338291dcb98SKim Phillips return true; 339291dcb98SKim Phillips } 340291dcb98SKim Phillips 341291dcb98SKim Phillips return false; 342291dcb98SKim Phillips } 343