18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Linux performance counter support for ARC 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2014-2015 Synopsys, Inc. (www.synopsys.com) 68c2ecf20Sopenharmony_ci * Copyright (C) 2011-2013 Synopsys, Inc. (www.synopsys.com) 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef __ASM_PERF_EVENT_H 108c2ecf20Sopenharmony_ci#define __ASM_PERF_EVENT_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* Max number of counters that PCT block may ever have */ 138c2ecf20Sopenharmony_ci#define ARC_PERF_MAX_COUNTERS 32 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define ARC_REG_CC_BUILD 0xF6 168c2ecf20Sopenharmony_ci#define ARC_REG_CC_INDEX 0x240 178c2ecf20Sopenharmony_ci#define ARC_REG_CC_NAME0 0x241 188c2ecf20Sopenharmony_ci#define ARC_REG_CC_NAME1 0x242 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define ARC_REG_PCT_BUILD 0xF5 218c2ecf20Sopenharmony_ci#define ARC_REG_PCT_COUNTL 0x250 228c2ecf20Sopenharmony_ci#define ARC_REG_PCT_COUNTH 0x251 238c2ecf20Sopenharmony_ci#define ARC_REG_PCT_SNAPL 0x252 248c2ecf20Sopenharmony_ci#define ARC_REG_PCT_SNAPH 0x253 258c2ecf20Sopenharmony_ci#define ARC_REG_PCT_CONFIG 0x254 268c2ecf20Sopenharmony_ci#define ARC_REG_PCT_CONTROL 0x255 278c2ecf20Sopenharmony_ci#define ARC_REG_PCT_INDEX 0x256 288c2ecf20Sopenharmony_ci#define ARC_REG_PCT_INT_CNTL 0x25C 298c2ecf20Sopenharmony_ci#define ARC_REG_PCT_INT_CNTH 0x25D 308c2ecf20Sopenharmony_ci#define ARC_REG_PCT_INT_CTRL 0x25E 318c2ecf20Sopenharmony_ci#define ARC_REG_PCT_INT_ACT 0x25F 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define ARC_REG_PCT_CONFIG_USER (1 << 18) /* count in user mode */ 348c2ecf20Sopenharmony_ci#define ARC_REG_PCT_CONFIG_KERN (1 << 19) /* count in kernel mode */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define ARC_REG_PCT_CONTROL_CC (1 << 16) /* clear counts */ 378c2ecf20Sopenharmony_ci#define ARC_REG_PCT_CONTROL_SN (1 << 17) /* snapshot */ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistruct arc_reg_pct_build { 408c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_BIG_ENDIAN 418c2ecf20Sopenharmony_ci unsigned int m:8, c:8, r:5, i:1, s:2, v:8; 428c2ecf20Sopenharmony_ci#else 438c2ecf20Sopenharmony_ci unsigned int v:8, s:2, i:1, r:5, c:8, m:8; 448c2ecf20Sopenharmony_ci#endif 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistruct arc_reg_cc_build { 488c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_BIG_ENDIAN 498c2ecf20Sopenharmony_ci unsigned int c:16, r:8, v:8; 508c2ecf20Sopenharmony_ci#else 518c2ecf20Sopenharmony_ci unsigned int v:8, r:8, c:16; 528c2ecf20Sopenharmony_ci#endif 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_DCLM (PERF_COUNT_HW_MAX + 0) 568c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_DCSM (PERF_COUNT_HW_MAX + 1) 578c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_ICM (PERF_COUNT_HW_MAX + 2) 588c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_BPOK (PERF_COUNT_HW_MAX + 3) 598c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_EDTLB (PERF_COUNT_HW_MAX + 4) 608c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_EITLB (PERF_COUNT_HW_MAX + 5) 618c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_LDC (PERF_COUNT_HW_MAX + 6) 628c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_STC (PERF_COUNT_HW_MAX + 7) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define PERF_COUNT_ARC_HW_MAX (PERF_COUNT_HW_MAX + 8) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci * Some ARC pct quirks: 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * PERF_COUNT_HW_STALLED_CYCLES_BACKEND 708c2ecf20Sopenharmony_ci * PERF_COUNT_HW_STALLED_CYCLES_FRONTEND 718c2ecf20Sopenharmony_ci * The ARC 700 can either measure stalls per pipeline stage, or all stalls 728c2ecf20Sopenharmony_ci * combined; for now we assign all stalls to STALLED_CYCLES_BACKEND 738c2ecf20Sopenharmony_ci * and all pipeline flushes (e.g. caused by mispredicts, etc.) to 748c2ecf20Sopenharmony_ci * STALLED_CYCLES_FRONTEND. 758c2ecf20Sopenharmony_ci * 768c2ecf20Sopenharmony_ci * We could start multiple performance counters and combine everything 778c2ecf20Sopenharmony_ci * afterwards, but that makes it complicated. 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * Note that I$ cache misses aren't counted by either of the two! 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* 838c2ecf20Sopenharmony_ci * ARC PCT has hardware conditions with fixed "names" but variable "indexes" 848c2ecf20Sopenharmony_ci * (based on a specific RTL build) 858c2ecf20Sopenharmony_ci * Below is the static map between perf generic/arc specific event_id and 868c2ecf20Sopenharmony_ci * h/w condition names. 878c2ecf20Sopenharmony_ci * At the time of probe, we loop thru each index and find it's name to 888c2ecf20Sopenharmony_ci * complete the mapping of perf event_id to h/w index as latter is needed 898c2ecf20Sopenharmony_ci * to program the counter really 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_cistatic const char * const arc_pmu_ev_hw_map[] = { 928c2ecf20Sopenharmony_ci /* count cycles */ 938c2ecf20Sopenharmony_ci [PERF_COUNT_HW_CPU_CYCLES] = "crun", 948c2ecf20Sopenharmony_ci [PERF_COUNT_HW_REF_CPU_CYCLES] = "crun", 958c2ecf20Sopenharmony_ci [PERF_COUNT_HW_BUS_CYCLES] = "crun", 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = "bflush", 988c2ecf20Sopenharmony_ci [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = "bstall", 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci /* counts condition */ 1018c2ecf20Sopenharmony_ci [PERF_COUNT_HW_INSTRUCTIONS] = "iall", 1028c2ecf20Sopenharmony_ci /* All jump instructions that are taken */ 1038c2ecf20Sopenharmony_ci [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmptak", 1048c2ecf20Sopenharmony_ci#ifdef CONFIG_ISA_ARCV2 1058c2ecf20Sopenharmony_ci [PERF_COUNT_HW_BRANCH_MISSES] = "bpmp", 1068c2ecf20Sopenharmony_ci#else 1078c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_BPOK] = "bpok", /* NP-NT, PT-T, PNT-NT */ 1088c2ecf20Sopenharmony_ci [PERF_COUNT_HW_BRANCH_MISSES] = "bpfail", /* NP-T, PT-NT, PNT-T */ 1098c2ecf20Sopenharmony_ci#endif 1108c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_LDC] = "imemrdc", /* Instr: mem read cached */ 1118c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_STC] = "imemwrc", /* Instr: mem write cached */ 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_DCLM] = "dclm", /* D-cache Load Miss */ 1148c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_DCSM] = "dcsm", /* D-cache Store Miss */ 1158c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_ICM] = "icm", /* I-cache Miss */ 1168c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_EDTLB] = "edtlb", /* D-TLB Miss */ 1178c2ecf20Sopenharmony_ci [PERF_COUNT_ARC_EITLB] = "eitlb", /* I-TLB Miss */ 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci [PERF_COUNT_HW_CACHE_REFERENCES] = "imemrdc", /* Instr: mem read cached */ 1208c2ecf20Sopenharmony_ci [PERF_COUNT_HW_CACHE_MISSES] = "dclm", /* D-cache Load Miss */ 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define C(_x) PERF_COUNT_HW_CACHE_##_x 1248c2ecf20Sopenharmony_ci#define CACHE_OP_UNSUPPORTED 0xffff 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic const unsigned arc_pmu_cache_map[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = { 1278c2ecf20Sopenharmony_ci [C(L1D)] = { 1288c2ecf20Sopenharmony_ci [C(OP_READ)] = { 1298c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = PERF_COUNT_ARC_LDC, 1308c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = PERF_COUNT_ARC_DCLM, 1318c2ecf20Sopenharmony_ci }, 1328c2ecf20Sopenharmony_ci [C(OP_WRITE)] = { 1338c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = PERF_COUNT_ARC_STC, 1348c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = PERF_COUNT_ARC_DCSM, 1358c2ecf20Sopenharmony_ci }, 1368c2ecf20Sopenharmony_ci [C(OP_PREFETCH)] = { 1378c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1388c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1398c2ecf20Sopenharmony_ci }, 1408c2ecf20Sopenharmony_ci }, 1418c2ecf20Sopenharmony_ci [C(L1I)] = { 1428c2ecf20Sopenharmony_ci [C(OP_READ)] = { 1438c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = PERF_COUNT_HW_INSTRUCTIONS, 1448c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = PERF_COUNT_ARC_ICM, 1458c2ecf20Sopenharmony_ci }, 1468c2ecf20Sopenharmony_ci [C(OP_WRITE)] = { 1478c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1488c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1498c2ecf20Sopenharmony_ci }, 1508c2ecf20Sopenharmony_ci [C(OP_PREFETCH)] = { 1518c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1528c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1538c2ecf20Sopenharmony_ci }, 1548c2ecf20Sopenharmony_ci }, 1558c2ecf20Sopenharmony_ci [C(LL)] = { 1568c2ecf20Sopenharmony_ci [C(OP_READ)] = { 1578c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1588c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1598c2ecf20Sopenharmony_ci }, 1608c2ecf20Sopenharmony_ci [C(OP_WRITE)] = { 1618c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1628c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1638c2ecf20Sopenharmony_ci }, 1648c2ecf20Sopenharmony_ci [C(OP_PREFETCH)] = { 1658c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1668c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1678c2ecf20Sopenharmony_ci }, 1688c2ecf20Sopenharmony_ci }, 1698c2ecf20Sopenharmony_ci [C(DTLB)] = { 1708c2ecf20Sopenharmony_ci [C(OP_READ)] = { 1718c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = PERF_COUNT_ARC_LDC, 1728c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = PERF_COUNT_ARC_EDTLB, 1738c2ecf20Sopenharmony_ci }, 1748c2ecf20Sopenharmony_ci /* DTLB LD/ST Miss not segregated by h/w*/ 1758c2ecf20Sopenharmony_ci [C(OP_WRITE)] = { 1768c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1778c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1788c2ecf20Sopenharmony_ci }, 1798c2ecf20Sopenharmony_ci [C(OP_PREFETCH)] = { 1808c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1818c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1828c2ecf20Sopenharmony_ci }, 1838c2ecf20Sopenharmony_ci }, 1848c2ecf20Sopenharmony_ci [C(ITLB)] = { 1858c2ecf20Sopenharmony_ci [C(OP_READ)] = { 1868c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1878c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = PERF_COUNT_ARC_EITLB, 1888c2ecf20Sopenharmony_ci }, 1898c2ecf20Sopenharmony_ci [C(OP_WRITE)] = { 1908c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1918c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1928c2ecf20Sopenharmony_ci }, 1938c2ecf20Sopenharmony_ci [C(OP_PREFETCH)] = { 1948c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 1958c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 1968c2ecf20Sopenharmony_ci }, 1978c2ecf20Sopenharmony_ci }, 1988c2ecf20Sopenharmony_ci [C(BPU)] = { 1998c2ecf20Sopenharmony_ci [C(OP_READ)] = { 2008c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = PERF_COUNT_HW_BRANCH_INSTRUCTIONS, 2018c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = PERF_COUNT_HW_BRANCH_MISSES, 2028c2ecf20Sopenharmony_ci }, 2038c2ecf20Sopenharmony_ci [C(OP_WRITE)] = { 2048c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 2058c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 2068c2ecf20Sopenharmony_ci }, 2078c2ecf20Sopenharmony_ci [C(OP_PREFETCH)] = { 2088c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 2098c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 2108c2ecf20Sopenharmony_ci }, 2118c2ecf20Sopenharmony_ci }, 2128c2ecf20Sopenharmony_ci [C(NODE)] = { 2138c2ecf20Sopenharmony_ci [C(OP_READ)] = { 2148c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 2158c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 2168c2ecf20Sopenharmony_ci }, 2178c2ecf20Sopenharmony_ci [C(OP_WRITE)] = { 2188c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 2198c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 2208c2ecf20Sopenharmony_ci }, 2218c2ecf20Sopenharmony_ci [C(OP_PREFETCH)] = { 2228c2ecf20Sopenharmony_ci [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED, 2238c2ecf20Sopenharmony_ci [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED, 2248c2ecf20Sopenharmony_ci }, 2258c2ecf20Sopenharmony_ci }, 2268c2ecf20Sopenharmony_ci}; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci#endif /* __ASM_PERF_EVENT_H */ 229