18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_PERF_EVENT_H 38c2ecf20Sopenharmony_ci#define _ASM_X86_PERF_EVENT_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* 68c2ecf20Sopenharmony_ci * Performance event hw details: 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define INTEL_PMC_MAX_GENERIC 32 108c2ecf20Sopenharmony_ci#define INTEL_PMC_MAX_FIXED 4 118c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_FIXED 32 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define X86_PMC_IDX_MAX 64 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_PERFCTR0 0xc1 168c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_PERFCTR1 0xc2 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_EVENTSEL0 0x186 198c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_EVENTSEL1 0x187 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_EVENT 0x000000FFULL 228c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_UMASK 0x0000FF00ULL 238c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_USR (1ULL << 16) 248c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_OS (1ULL << 17) 258c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_EDGE (1ULL << 18) 268c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_PIN_CONTROL (1ULL << 19) 278c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_INT (1ULL << 20) 288c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_ANY (1ULL << 21) 298c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_ENABLE (1ULL << 22) 308c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_INV (1ULL << 23) 318c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTSEL_CMASK 0xFF000000ULL 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define HSW_IN_TX (1ULL << 32) 348c2ecf20Sopenharmony_ci#define HSW_IN_TX_CHECKPOINTED (1ULL << 33) 358c2ecf20Sopenharmony_ci#define ICL_EVENTSEL_ADAPTIVE (1ULL << 34) 368c2ecf20Sopenharmony_ci#define ICL_FIXED_0_ADAPTIVE (1ULL << 32) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define AMD64_EVENTSEL_INT_CORE_ENABLE (1ULL << 36) 398c2ecf20Sopenharmony_ci#define AMD64_EVENTSEL_GUESTONLY (1ULL << 40) 408c2ecf20Sopenharmony_ci#define AMD64_EVENTSEL_HOSTONLY (1ULL << 41) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define AMD64_EVENTSEL_INT_CORE_SEL_SHIFT 37 438c2ecf20Sopenharmony_ci#define AMD64_EVENTSEL_INT_CORE_SEL_MASK \ 448c2ecf20Sopenharmony_ci (0xFULL << AMD64_EVENTSEL_INT_CORE_SEL_SHIFT) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define AMD64_EVENTSEL_EVENT \ 478c2ecf20Sopenharmony_ci (ARCH_PERFMON_EVENTSEL_EVENT | (0x0FULL << 32)) 488c2ecf20Sopenharmony_ci#define INTEL_ARCH_EVENT_MASK \ 498c2ecf20Sopenharmony_ci (ARCH_PERFMON_EVENTSEL_UMASK | ARCH_PERFMON_EVENTSEL_EVENT) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define AMD64_L3_SLICE_SHIFT 48 528c2ecf20Sopenharmony_ci#define AMD64_L3_SLICE_MASK \ 538c2ecf20Sopenharmony_ci (0xFULL << AMD64_L3_SLICE_SHIFT) 548c2ecf20Sopenharmony_ci#define AMD64_L3_SLICEID_MASK \ 558c2ecf20Sopenharmony_ci (0x7ULL << AMD64_L3_SLICE_SHIFT) 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define AMD64_L3_THREAD_SHIFT 56 588c2ecf20Sopenharmony_ci#define AMD64_L3_THREAD_MASK \ 598c2ecf20Sopenharmony_ci (0xFFULL << AMD64_L3_THREAD_SHIFT) 608c2ecf20Sopenharmony_ci#define AMD64_L3_F19H_THREAD_MASK \ 618c2ecf20Sopenharmony_ci (0x3ULL << AMD64_L3_THREAD_SHIFT) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define AMD64_L3_EN_ALL_CORES BIT_ULL(47) 648c2ecf20Sopenharmony_ci#define AMD64_L3_EN_ALL_SLICES BIT_ULL(46) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define AMD64_L3_COREID_SHIFT 42 678c2ecf20Sopenharmony_ci#define AMD64_L3_COREID_MASK \ 688c2ecf20Sopenharmony_ci (0x7ULL << AMD64_L3_COREID_SHIFT) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define X86_RAW_EVENT_MASK \ 718c2ecf20Sopenharmony_ci (ARCH_PERFMON_EVENTSEL_EVENT | \ 728c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_UMASK | \ 738c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_EDGE | \ 748c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_INV | \ 758c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_CMASK) 768c2ecf20Sopenharmony_ci#define X86_ALL_EVENT_FLAGS \ 778c2ecf20Sopenharmony_ci (ARCH_PERFMON_EVENTSEL_EDGE | \ 788c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_INV | \ 798c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_CMASK | \ 808c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_ANY | \ 818c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_PIN_CONTROL | \ 828c2ecf20Sopenharmony_ci HSW_IN_TX | \ 838c2ecf20Sopenharmony_ci HSW_IN_TX_CHECKPOINTED) 848c2ecf20Sopenharmony_ci#define AMD64_RAW_EVENT_MASK \ 858c2ecf20Sopenharmony_ci (X86_RAW_EVENT_MASK | \ 868c2ecf20Sopenharmony_ci AMD64_EVENTSEL_EVENT) 878c2ecf20Sopenharmony_ci#define AMD64_RAW_EVENT_MASK_NB \ 888c2ecf20Sopenharmony_ci (AMD64_EVENTSEL_EVENT | \ 898c2ecf20Sopenharmony_ci ARCH_PERFMON_EVENTSEL_UMASK) 908c2ecf20Sopenharmony_ci#define AMD64_NUM_COUNTERS 4 918c2ecf20Sopenharmony_ci#define AMD64_NUM_COUNTERS_CORE 6 928c2ecf20Sopenharmony_ci#define AMD64_NUM_COUNTERS_NB 4 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL 0x3c 958c2ecf20Sopenharmony_ci#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) 968c2ecf20Sopenharmony_ci#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX 0 978c2ecf20Sopenharmony_ci#define ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT \ 988c2ecf20Sopenharmony_ci (1 << (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX)) 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define ARCH_PERFMON_BRANCH_MISSES_RETIRED 6 1018c2ecf20Sopenharmony_ci#define ARCH_PERFMON_EVENTS_COUNT 7 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define PEBS_DATACFG_MEMINFO BIT_ULL(0) 1048c2ecf20Sopenharmony_ci#define PEBS_DATACFG_GP BIT_ULL(1) 1058c2ecf20Sopenharmony_ci#define PEBS_DATACFG_XMMS BIT_ULL(2) 1068c2ecf20Sopenharmony_ci#define PEBS_DATACFG_LBRS BIT_ULL(3) 1078c2ecf20Sopenharmony_ci#define PEBS_DATACFG_LBR_SHIFT 24 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* 1108c2ecf20Sopenharmony_ci * Intel "Architectural Performance Monitoring" CPUID 1118c2ecf20Sopenharmony_ci * detection/enumeration details: 1128c2ecf20Sopenharmony_ci */ 1138c2ecf20Sopenharmony_ciunion cpuid10_eax { 1148c2ecf20Sopenharmony_ci struct { 1158c2ecf20Sopenharmony_ci unsigned int version_id:8; 1168c2ecf20Sopenharmony_ci unsigned int num_counters:8; 1178c2ecf20Sopenharmony_ci unsigned int bit_width:8; 1188c2ecf20Sopenharmony_ci unsigned int mask_length:8; 1198c2ecf20Sopenharmony_ci } split; 1208c2ecf20Sopenharmony_ci unsigned int full; 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciunion cpuid10_ebx { 1248c2ecf20Sopenharmony_ci struct { 1258c2ecf20Sopenharmony_ci unsigned int no_unhalted_core_cycles:1; 1268c2ecf20Sopenharmony_ci unsigned int no_instructions_retired:1; 1278c2ecf20Sopenharmony_ci unsigned int no_unhalted_reference_cycles:1; 1288c2ecf20Sopenharmony_ci unsigned int no_llc_reference:1; 1298c2ecf20Sopenharmony_ci unsigned int no_llc_misses:1; 1308c2ecf20Sopenharmony_ci unsigned int no_branch_instruction_retired:1; 1318c2ecf20Sopenharmony_ci unsigned int no_branch_misses_retired:1; 1328c2ecf20Sopenharmony_ci } split; 1338c2ecf20Sopenharmony_ci unsigned int full; 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ciunion cpuid10_edx { 1378c2ecf20Sopenharmony_ci struct { 1388c2ecf20Sopenharmony_ci unsigned int num_counters_fixed:5; 1398c2ecf20Sopenharmony_ci unsigned int bit_width_fixed:8; 1408c2ecf20Sopenharmony_ci unsigned int reserved1:2; 1418c2ecf20Sopenharmony_ci unsigned int anythread_deprecated:1; 1428c2ecf20Sopenharmony_ci unsigned int reserved2:16; 1438c2ecf20Sopenharmony_ci } split; 1448c2ecf20Sopenharmony_ci unsigned int full; 1458c2ecf20Sopenharmony_ci}; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/* 1488c2ecf20Sopenharmony_ci * Intel Architectural LBR CPUID detection/enumeration details: 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_ciunion cpuid28_eax { 1518c2ecf20Sopenharmony_ci struct { 1528c2ecf20Sopenharmony_ci /* Supported LBR depth values */ 1538c2ecf20Sopenharmony_ci unsigned int lbr_depth_mask:8; 1548c2ecf20Sopenharmony_ci unsigned int reserved:22; 1558c2ecf20Sopenharmony_ci /* Deep C-state Reset */ 1568c2ecf20Sopenharmony_ci unsigned int lbr_deep_c_reset:1; 1578c2ecf20Sopenharmony_ci /* IP values contain LIP */ 1588c2ecf20Sopenharmony_ci unsigned int lbr_lip:1; 1598c2ecf20Sopenharmony_ci } split; 1608c2ecf20Sopenharmony_ci unsigned int full; 1618c2ecf20Sopenharmony_ci}; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ciunion cpuid28_ebx { 1648c2ecf20Sopenharmony_ci struct { 1658c2ecf20Sopenharmony_ci /* CPL Filtering Supported */ 1668c2ecf20Sopenharmony_ci unsigned int lbr_cpl:1; 1678c2ecf20Sopenharmony_ci /* Branch Filtering Supported */ 1688c2ecf20Sopenharmony_ci unsigned int lbr_filter:1; 1698c2ecf20Sopenharmony_ci /* Call-stack Mode Supported */ 1708c2ecf20Sopenharmony_ci unsigned int lbr_call_stack:1; 1718c2ecf20Sopenharmony_ci } split; 1728c2ecf20Sopenharmony_ci unsigned int full; 1738c2ecf20Sopenharmony_ci}; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ciunion cpuid28_ecx { 1768c2ecf20Sopenharmony_ci struct { 1778c2ecf20Sopenharmony_ci /* Mispredict Bit Supported */ 1788c2ecf20Sopenharmony_ci unsigned int lbr_mispred:1; 1798c2ecf20Sopenharmony_ci /* Timed LBRs Supported */ 1808c2ecf20Sopenharmony_ci unsigned int lbr_timed_lbr:1; 1818c2ecf20Sopenharmony_ci /* Branch Type Field Supported */ 1828c2ecf20Sopenharmony_ci unsigned int lbr_br_type:1; 1838c2ecf20Sopenharmony_ci } split; 1848c2ecf20Sopenharmony_ci unsigned int full; 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistruct x86_pmu_capability { 1888c2ecf20Sopenharmony_ci int version; 1898c2ecf20Sopenharmony_ci int num_counters_gp; 1908c2ecf20Sopenharmony_ci int num_counters_fixed; 1918c2ecf20Sopenharmony_ci int bit_width_gp; 1928c2ecf20Sopenharmony_ci int bit_width_fixed; 1938c2ecf20Sopenharmony_ci unsigned int events_mask; 1948c2ecf20Sopenharmony_ci int events_mask_len; 1958c2ecf20Sopenharmony_ci}; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci/* 1988c2ecf20Sopenharmony_ci * Fixed-purpose performance events: 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* RDPMC offset for Fixed PMCs */ 2028c2ecf20Sopenharmony_ci#define INTEL_PMC_FIXED_RDPMC_BASE (1 << 30) 2038c2ecf20Sopenharmony_ci#define INTEL_PMC_FIXED_RDPMC_METRICS (1 << 29) 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci/* 2068c2ecf20Sopenharmony_ci * All the fixed-mode PMCs are configured via this single MSR: 2078c2ecf20Sopenharmony_ci */ 2088c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_FIXED_CTR_CTRL 0x38d 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* 2118c2ecf20Sopenharmony_ci * There is no event-code assigned to the fixed-mode PMCs. 2128c2ecf20Sopenharmony_ci * 2138c2ecf20Sopenharmony_ci * For a fixed-mode PMC, which has an equivalent event on a general-purpose 2148c2ecf20Sopenharmony_ci * PMC, the event-code of the equivalent event is used for the fixed-mode PMC, 2158c2ecf20Sopenharmony_ci * e.g., Instr_Retired.Any and CPU_CLK_Unhalted.Core. 2168c2ecf20Sopenharmony_ci * 2178c2ecf20Sopenharmony_ci * For a fixed-mode PMC, which doesn't have an equivalent event, a 2188c2ecf20Sopenharmony_ci * pseudo-encoding is used, e.g., CPU_CLK_Unhalted.Ref and TOPDOWN.SLOTS. 2198c2ecf20Sopenharmony_ci * The pseudo event-code for a fixed-mode PMC must be 0x00. 2208c2ecf20Sopenharmony_ci * The pseudo umask-code is 0xX. The X equals the index of the fixed 2218c2ecf20Sopenharmony_ci * counter + 1, e.g., the fixed counter 2 has the pseudo-encoding 0x0300. 2228c2ecf20Sopenharmony_ci * 2238c2ecf20Sopenharmony_ci * The counts are available in separate MSRs: 2248c2ecf20Sopenharmony_ci */ 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci/* Instr_Retired.Any: */ 2278c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_FIXED_CTR0 0x309 2288c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_FIXED_INSTRUCTIONS (INTEL_PMC_IDX_FIXED + 0) 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci/* CPU_CLK_Unhalted.Core: */ 2318c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_FIXED_CTR1 0x30a 2328c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_FIXED_CPU_CYCLES (INTEL_PMC_IDX_FIXED + 1) 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci/* CPU_CLK_Unhalted.Ref: event=0x00,umask=0x3 (pseudo-encoding) */ 2358c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_FIXED_CTR2 0x30b 2368c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_FIXED_REF_CYCLES (INTEL_PMC_IDX_FIXED + 2) 2378c2ecf20Sopenharmony_ci#define INTEL_PMC_MSK_FIXED_REF_CYCLES (1ULL << INTEL_PMC_IDX_FIXED_REF_CYCLES) 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci/* TOPDOWN.SLOTS: event=0x00,umask=0x4 (pseudo-encoding) */ 2408c2ecf20Sopenharmony_ci#define MSR_ARCH_PERFMON_FIXED_CTR3 0x30c 2418c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_FIXED_SLOTS (INTEL_PMC_IDX_FIXED + 3) 2428c2ecf20Sopenharmony_ci#define INTEL_PMC_MSK_FIXED_SLOTS (1ULL << INTEL_PMC_IDX_FIXED_SLOTS) 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/* 2458c2ecf20Sopenharmony_ci * We model BTS tracing as another fixed-mode PMC. 2468c2ecf20Sopenharmony_ci * 2478c2ecf20Sopenharmony_ci * We choose the value 47 for the fixed index of BTS, since lower 2488c2ecf20Sopenharmony_ci * values are used by actual fixed events and higher values are used 2498c2ecf20Sopenharmony_ci * to indicate other overflow conditions in the PERF_GLOBAL_STATUS msr. 2508c2ecf20Sopenharmony_ci */ 2518c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_FIXED_BTS (INTEL_PMC_IDX_FIXED + 15) 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci/* 2548c2ecf20Sopenharmony_ci * The PERF_METRICS MSR is modeled as several magic fixed-mode PMCs, one for 2558c2ecf20Sopenharmony_ci * each TopDown metric event. 2568c2ecf20Sopenharmony_ci * 2578c2ecf20Sopenharmony_ci * Internally the TopDown metric events are mapped to the FxCtr 3 (SLOTS). 2588c2ecf20Sopenharmony_ci */ 2598c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_METRIC_BASE (INTEL_PMC_IDX_FIXED + 16) 2608c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_TD_RETIRING (INTEL_PMC_IDX_METRIC_BASE + 0) 2618c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_TD_BAD_SPEC (INTEL_PMC_IDX_METRIC_BASE + 1) 2628c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_TD_FE_BOUND (INTEL_PMC_IDX_METRIC_BASE + 2) 2638c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_TD_BE_BOUND (INTEL_PMC_IDX_METRIC_BASE + 3) 2648c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_METRIC_END INTEL_PMC_IDX_TD_BE_BOUND 2658c2ecf20Sopenharmony_ci#define INTEL_PMC_MSK_TOPDOWN ((0xfull << INTEL_PMC_IDX_METRIC_BASE) | \ 2668c2ecf20Sopenharmony_ci INTEL_PMC_MSK_FIXED_SLOTS) 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci/* 2698c2ecf20Sopenharmony_ci * There is no event-code assigned to the TopDown events. 2708c2ecf20Sopenharmony_ci * 2718c2ecf20Sopenharmony_ci * For the slots event, use the pseudo code of the fixed counter 3. 2728c2ecf20Sopenharmony_ci * 2738c2ecf20Sopenharmony_ci * For the metric events, the pseudo event-code is 0x00. 2748c2ecf20Sopenharmony_ci * The pseudo umask-code starts from the middle of the pseudo event 2758c2ecf20Sopenharmony_ci * space, 0x80. 2768c2ecf20Sopenharmony_ci */ 2778c2ecf20Sopenharmony_ci#define INTEL_TD_SLOTS 0x0400 /* TOPDOWN.SLOTS */ 2788c2ecf20Sopenharmony_ci/* Level 1 metrics */ 2798c2ecf20Sopenharmony_ci#define INTEL_TD_METRIC_RETIRING 0x8000 /* Retiring metric */ 2808c2ecf20Sopenharmony_ci#define INTEL_TD_METRIC_BAD_SPEC 0x8100 /* Bad speculation metric */ 2818c2ecf20Sopenharmony_ci#define INTEL_TD_METRIC_FE_BOUND 0x8200 /* FE bound metric */ 2828c2ecf20Sopenharmony_ci#define INTEL_TD_METRIC_BE_BOUND 0x8300 /* BE bound metric */ 2838c2ecf20Sopenharmony_ci#define INTEL_TD_METRIC_MAX INTEL_TD_METRIC_BE_BOUND 2848c2ecf20Sopenharmony_ci#define INTEL_TD_METRIC_NUM 4 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic inline bool is_metric_idx(int idx) 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci return (unsigned)(idx - INTEL_PMC_IDX_METRIC_BASE) < INTEL_TD_METRIC_NUM; 2898c2ecf20Sopenharmony_ci} 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistatic inline bool is_topdown_idx(int idx) 2928c2ecf20Sopenharmony_ci{ 2938c2ecf20Sopenharmony_ci return is_metric_idx(idx) || idx == INTEL_PMC_IDX_FIXED_SLOTS; 2948c2ecf20Sopenharmony_ci} 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci#define INTEL_PMC_OTHER_TOPDOWN_BITS(bit) \ 2978c2ecf20Sopenharmony_ci (~(0x1ull << bit) & INTEL_PMC_MSK_TOPDOWN) 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_COND_CHG BIT_ULL(63) 3008c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_BUFFER_OVF_BIT 62 3018c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_BUFFER_OVF BIT_ULL(GLOBAL_STATUS_BUFFER_OVF_BIT) 3028c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_UNC_OVF BIT_ULL(61) 3038c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_ASIF BIT_ULL(60) 3048c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_COUNTERS_FROZEN BIT_ULL(59) 3058c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_LBRS_FROZEN_BIT 58 3068c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_LBRS_FROZEN BIT_ULL(GLOBAL_STATUS_LBRS_FROZEN_BIT) 3078c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_TRACE_TOPAPMI_BIT 55 3088c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_TRACE_TOPAPMI BIT_ULL(GLOBAL_STATUS_TRACE_TOPAPMI_BIT) 3098c2ecf20Sopenharmony_ci#define GLOBAL_STATUS_PERF_METRICS_OVF_BIT 48 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci#define GLOBAL_CTRL_EN_PERF_METRICS 48 3128c2ecf20Sopenharmony_ci/* 3138c2ecf20Sopenharmony_ci * We model guest LBR event tracing as another fixed-mode PMC like BTS. 3148c2ecf20Sopenharmony_ci * 3158c2ecf20Sopenharmony_ci * We choose bit 58 because it's used to indicate LBR stack frozen state 3168c2ecf20Sopenharmony_ci * for architectural perfmon v4, also we unconditionally mask that bit in 3178c2ecf20Sopenharmony_ci * the handle_pmi_common(), so it'll never be set in the overflow handling. 3188c2ecf20Sopenharmony_ci * 3198c2ecf20Sopenharmony_ci * With this fake counter assigned, the guest LBR event user (such as KVM), 3208c2ecf20Sopenharmony_ci * can program the LBR registers on its own, and we don't actually do anything 3218c2ecf20Sopenharmony_ci * with then in the host context. 3228c2ecf20Sopenharmony_ci */ 3238c2ecf20Sopenharmony_ci#define INTEL_PMC_IDX_FIXED_VLBR (GLOBAL_STATUS_LBRS_FROZEN_BIT) 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci/* 3268c2ecf20Sopenharmony_ci * Pseudo-encoding the guest LBR event as event=0x00,umask=0x1b, 3278c2ecf20Sopenharmony_ci * since it would claim bit 58 which is effectively Fixed26. 3288c2ecf20Sopenharmony_ci */ 3298c2ecf20Sopenharmony_ci#define INTEL_FIXED_VLBR_EVENT 0x1b00 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci/* 3328c2ecf20Sopenharmony_ci * Adaptive PEBS v4 3338c2ecf20Sopenharmony_ci */ 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_cistruct pebs_basic { 3368c2ecf20Sopenharmony_ci u64 format_size; 3378c2ecf20Sopenharmony_ci u64 ip; 3388c2ecf20Sopenharmony_ci u64 applicable_counters; 3398c2ecf20Sopenharmony_ci u64 tsc; 3408c2ecf20Sopenharmony_ci}; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_cistruct pebs_meminfo { 3438c2ecf20Sopenharmony_ci u64 address; 3448c2ecf20Sopenharmony_ci u64 aux; 3458c2ecf20Sopenharmony_ci u64 latency; 3468c2ecf20Sopenharmony_ci u64 tsx_tuning; 3478c2ecf20Sopenharmony_ci}; 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cistruct pebs_gprs { 3508c2ecf20Sopenharmony_ci u64 flags, ip, ax, cx, dx, bx, sp, bp, si, di; 3518c2ecf20Sopenharmony_ci u64 r8, r9, r10, r11, r12, r13, r14, r15; 3528c2ecf20Sopenharmony_ci}; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_cistruct pebs_xmm { 3558c2ecf20Sopenharmony_ci u64 xmm[16*2]; /* two entries for each register */ 3568c2ecf20Sopenharmony_ci}; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci/* 3598c2ecf20Sopenharmony_ci * IBS cpuid feature detection 3608c2ecf20Sopenharmony_ci */ 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci#define IBS_CPUID_FEATURES 0x8000001b 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci/* 3658c2ecf20Sopenharmony_ci * Same bit mask as for IBS cpuid feature flags (Fn8000_001B_EAX), but 3668c2ecf20Sopenharmony_ci * bit 0 is used to indicate the existence of IBS. 3678c2ecf20Sopenharmony_ci */ 3688c2ecf20Sopenharmony_ci#define IBS_CAPS_AVAIL (1U<<0) 3698c2ecf20Sopenharmony_ci#define IBS_CAPS_FETCHSAM (1U<<1) 3708c2ecf20Sopenharmony_ci#define IBS_CAPS_OPSAM (1U<<2) 3718c2ecf20Sopenharmony_ci#define IBS_CAPS_RDWROPCNT (1U<<3) 3728c2ecf20Sopenharmony_ci#define IBS_CAPS_OPCNT (1U<<4) 3738c2ecf20Sopenharmony_ci#define IBS_CAPS_BRNTRGT (1U<<5) 3748c2ecf20Sopenharmony_ci#define IBS_CAPS_OPCNTEXT (1U<<6) 3758c2ecf20Sopenharmony_ci#define IBS_CAPS_RIPINVALIDCHK (1U<<7) 3768c2ecf20Sopenharmony_ci#define IBS_CAPS_OPBRNFUSE (1U<<8) 3778c2ecf20Sopenharmony_ci#define IBS_CAPS_FETCHCTLEXTD (1U<<9) 3788c2ecf20Sopenharmony_ci#define IBS_CAPS_OPDATA4 (1U<<10) 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci#define IBS_CAPS_DEFAULT (IBS_CAPS_AVAIL \ 3818c2ecf20Sopenharmony_ci | IBS_CAPS_FETCHSAM \ 3828c2ecf20Sopenharmony_ci | IBS_CAPS_OPSAM) 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci/* 3858c2ecf20Sopenharmony_ci * IBS APIC setup 3868c2ecf20Sopenharmony_ci */ 3878c2ecf20Sopenharmony_ci#define IBSCTL 0x1cc 3888c2ecf20Sopenharmony_ci#define IBSCTL_LVT_OFFSET_VALID (1ULL<<8) 3898c2ecf20Sopenharmony_ci#define IBSCTL_LVT_OFFSET_MASK 0x0F 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci/* IBS fetch bits/masks */ 3928c2ecf20Sopenharmony_ci#define IBS_FETCH_RAND_EN (1ULL<<57) 3938c2ecf20Sopenharmony_ci#define IBS_FETCH_VAL (1ULL<<49) 3948c2ecf20Sopenharmony_ci#define IBS_FETCH_ENABLE (1ULL<<48) 3958c2ecf20Sopenharmony_ci#define IBS_FETCH_CNT 0xFFFF0000ULL 3968c2ecf20Sopenharmony_ci#define IBS_FETCH_MAX_CNT 0x0000FFFFULL 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci/* 3998c2ecf20Sopenharmony_ci * IBS op bits/masks 4008c2ecf20Sopenharmony_ci * The lower 7 bits of the current count are random bits 4018c2ecf20Sopenharmony_ci * preloaded by hardware and ignored in software 4028c2ecf20Sopenharmony_ci */ 4038c2ecf20Sopenharmony_ci#define IBS_OP_CUR_CNT (0xFFF80ULL<<32) 4048c2ecf20Sopenharmony_ci#define IBS_OP_CUR_CNT_RAND (0x0007FULL<<32) 4058c2ecf20Sopenharmony_ci#define IBS_OP_CNT_CTL (1ULL<<19) 4068c2ecf20Sopenharmony_ci#define IBS_OP_VAL (1ULL<<18) 4078c2ecf20Sopenharmony_ci#define IBS_OP_ENABLE (1ULL<<17) 4088c2ecf20Sopenharmony_ci#define IBS_OP_MAX_CNT 0x0000FFFFULL 4098c2ecf20Sopenharmony_ci#define IBS_OP_MAX_CNT_EXT 0x007FFFFFULL /* not a register bit mask */ 4108c2ecf20Sopenharmony_ci#define IBS_OP_MAX_CNT_EXT_MASK (0x7FULL<<20) /* separate upper 7 bits */ 4118c2ecf20Sopenharmony_ci#define IBS_RIP_INVALID (1ULL<<38) 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_LOCAL_APIC 4148c2ecf20Sopenharmony_ciextern u32 get_ibs_caps(void); 4158c2ecf20Sopenharmony_ciextern int forward_event_to_ibs(struct perf_event *event); 4168c2ecf20Sopenharmony_ci#else 4178c2ecf20Sopenharmony_cistatic inline u32 get_ibs_caps(void) { return 0; } 4188c2ecf20Sopenharmony_cistatic inline int forward_event_to_ibs(struct perf_event *event) { return -ENOENT; } 4198c2ecf20Sopenharmony_ci#endif 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci#ifdef CONFIG_PERF_EVENTS 4228c2ecf20Sopenharmony_ciextern void perf_events_lapic_init(void); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci/* 4258c2ecf20Sopenharmony_ci * Abuse bits {3,5} of the cpu eflags register. These flags are otherwise 4268c2ecf20Sopenharmony_ci * unused and ABI specified to be 0, so nobody should care what we do with 4278c2ecf20Sopenharmony_ci * them. 4288c2ecf20Sopenharmony_ci * 4298c2ecf20Sopenharmony_ci * EXACT - the IP points to the exact instruction that triggered the 4308c2ecf20Sopenharmony_ci * event (HW bugs exempt). 4318c2ecf20Sopenharmony_ci * VM - original X86_VM_MASK; see set_linear_ip(). 4328c2ecf20Sopenharmony_ci */ 4338c2ecf20Sopenharmony_ci#define PERF_EFLAGS_EXACT (1UL << 3) 4348c2ecf20Sopenharmony_ci#define PERF_EFLAGS_VM (1UL << 5) 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_cistruct pt_regs; 4378c2ecf20Sopenharmony_cistruct x86_perf_regs { 4388c2ecf20Sopenharmony_ci struct pt_regs regs; 4398c2ecf20Sopenharmony_ci u64 *xmm_regs; 4408c2ecf20Sopenharmony_ci}; 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ciextern unsigned long perf_instruction_pointer(struct pt_regs *regs); 4438c2ecf20Sopenharmony_ciextern unsigned long perf_misc_flags(struct pt_regs *regs); 4448c2ecf20Sopenharmony_ci#define perf_misc_flags(regs) perf_misc_flags(regs) 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci#include <asm/stacktrace.h> 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci/* 4498c2ecf20Sopenharmony_ci * We abuse bit 3 from flags to pass exact information, see perf_misc_flags 4508c2ecf20Sopenharmony_ci * and the comment with PERF_EFLAGS_EXACT. 4518c2ecf20Sopenharmony_ci */ 4528c2ecf20Sopenharmony_ci#define perf_arch_fetch_caller_regs(regs, __ip) { \ 4538c2ecf20Sopenharmony_ci (regs)->ip = (__ip); \ 4548c2ecf20Sopenharmony_ci (regs)->sp = (unsigned long)__builtin_frame_address(0); \ 4558c2ecf20Sopenharmony_ci (regs)->cs = __KERNEL_CS; \ 4568c2ecf20Sopenharmony_ci regs->flags = 0; \ 4578c2ecf20Sopenharmony_ci} 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_cistruct perf_guest_switch_msr { 4608c2ecf20Sopenharmony_ci unsigned msr; 4618c2ecf20Sopenharmony_ci u64 host, guest; 4628c2ecf20Sopenharmony_ci}; 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_cistruct x86_pmu_lbr { 4658c2ecf20Sopenharmony_ci unsigned int nr; 4668c2ecf20Sopenharmony_ci unsigned int from; 4678c2ecf20Sopenharmony_ci unsigned int to; 4688c2ecf20Sopenharmony_ci unsigned int info; 4698c2ecf20Sopenharmony_ci}; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ciextern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap); 4728c2ecf20Sopenharmony_ciextern void perf_check_microcode(void); 4738c2ecf20Sopenharmony_ciextern int x86_perf_rdpmc_index(struct perf_event *event); 4748c2ecf20Sopenharmony_ci#else 4758c2ecf20Sopenharmony_cistatic inline void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap) 4768c2ecf20Sopenharmony_ci{ 4778c2ecf20Sopenharmony_ci memset(cap, 0, sizeof(*cap)); 4788c2ecf20Sopenharmony_ci} 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_cistatic inline void perf_events_lapic_init(void) { } 4818c2ecf20Sopenharmony_cistatic inline void perf_check_microcode(void) { } 4828c2ecf20Sopenharmony_ci#endif 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci#if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) 4858c2ecf20Sopenharmony_ciextern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); 4868c2ecf20Sopenharmony_ciextern int x86_perf_get_lbr(struct x86_pmu_lbr *lbr); 4878c2ecf20Sopenharmony_ci#else 4888c2ecf20Sopenharmony_cistatic inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) 4898c2ecf20Sopenharmony_ci{ 4908c2ecf20Sopenharmony_ci *nr = 0; 4918c2ecf20Sopenharmony_ci return NULL; 4928c2ecf20Sopenharmony_ci} 4938c2ecf20Sopenharmony_cistatic inline int x86_perf_get_lbr(struct x86_pmu_lbr *lbr) 4948c2ecf20Sopenharmony_ci{ 4958c2ecf20Sopenharmony_ci return -1; 4968c2ecf20Sopenharmony_ci} 4978c2ecf20Sopenharmony_ci#endif 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_SUP_INTEL 5008c2ecf20Sopenharmony_ci extern void intel_pt_handle_vmx(int on); 5018c2ecf20Sopenharmony_ci#else 5028c2ecf20Sopenharmony_cistatic inline void intel_pt_handle_vmx(int on) 5038c2ecf20Sopenharmony_ci{ 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci} 5068c2ecf20Sopenharmony_ci#endif 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci#if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_AMD) 5098c2ecf20Sopenharmony_ci extern void amd_pmu_enable_virt(void); 5108c2ecf20Sopenharmony_ci extern void amd_pmu_disable_virt(void); 5118c2ecf20Sopenharmony_ci#else 5128c2ecf20Sopenharmony_ci static inline void amd_pmu_enable_virt(void) { } 5138c2ecf20Sopenharmony_ci static inline void amd_pmu_disable_virt(void) { } 5148c2ecf20Sopenharmony_ci#endif 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci#define arch_perf_out_copy_user copy_from_user_nmi 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci#endif /* _ASM_X86_PERF_EVENT_H */ 519