tprof_x86.c revision 1.16 1 1.16 msaitoh /* $NetBSD: tprof_x86.c,v 1.16 2023/04/10 06:08:56 msaitoh Exp $ */
2 1.1 maxv
3 1.1 maxv /*
4 1.8 maxv * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
5 1.1 maxv * All rights reserved.
6 1.1 maxv *
7 1.1 maxv * This code is derived from software contributed to The NetBSD Foundation
8 1.1 maxv * by Maxime Villard.
9 1.1 maxv *
10 1.1 maxv * Redistribution and use in source and binary forms, with or without
11 1.1 maxv * modification, are permitted provided that the following conditions
12 1.1 maxv * are met:
13 1.1 maxv * 1. Redistributions of source code must retain the above copyright
14 1.1 maxv * notice, this list of conditions and the following disclaimer.
15 1.1 maxv * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 maxv * notice, this list of conditions and the following disclaimer in the
17 1.1 maxv * documentation and/or other materials provided with the distribution.
18 1.1 maxv *
19 1.1 maxv * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 maxv * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 maxv * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 maxv * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 maxv * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 maxv * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 maxv * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 maxv * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 maxv * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 maxv * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 maxv * POSSIBILITY OF SUCH DAMAGE.
30 1.1 maxv */
31 1.1 maxv
32 1.1 maxv #include <sys/cdefs.h>
33 1.1 maxv #include <stdio.h>
34 1.1 maxv #include <stdlib.h>
35 1.1 maxv #include <stdbool.h>
36 1.1 maxv #include <string.h>
37 1.1 maxv #include <unistd.h>
38 1.1 maxv #include <err.h>
39 1.1 maxv #include <machine/specialreg.h>
40 1.1 maxv #include <dev/tprof/tprof_ioctl.h>
41 1.1 maxv #include "../tprof.h"
42 1.1 maxv
43 1.1 maxv int tprof_event_init(uint32_t);
44 1.1 maxv void tprof_event_list(void);
45 1.1 maxv void tprof_event_lookup(const char *, struct tprof_param *);
46 1.1 maxv
47 1.1 maxv struct name_to_event {
48 1.1 maxv const char *name;
49 1.1 maxv uint64_t event;
50 1.1 maxv uint64_t unit;
51 1.1 maxv bool enabled;
52 1.1 maxv };
53 1.1 maxv
54 1.1 maxv struct event_table {
55 1.1 maxv const char *tablename;
56 1.1 maxv struct name_to_event *names;
57 1.1 maxv size_t nevents;
58 1.1 maxv struct event_table *next;
59 1.1 maxv };
60 1.1 maxv
61 1.1 maxv static struct event_table *cpuevents = NULL;
62 1.1 maxv
63 1.1 maxv static void x86_cpuid(unsigned int *eax, unsigned int *ebx,
64 1.1 maxv unsigned int *ecx, unsigned int *edx)
65 1.1 maxv {
66 1.1 maxv asm volatile("cpuid"
67 1.1 maxv : "=a" (*eax),
68 1.1 maxv "=b" (*ebx),
69 1.1 maxv "=c" (*ecx),
70 1.1 maxv "=d" (*edx)
71 1.1 maxv : "0" (*eax), "2" (*ecx));
72 1.1 maxv }
73 1.1 maxv
74 1.13 msaitoh /* ------------------------------------------------------------------------- */
75 1.1 maxv
76 1.1 maxv /*
77 1.1 maxv * Intel Architectural Version 1.
78 1.1 maxv */
79 1.1 maxv static struct name_to_event intel_arch1_names[] = {
80 1.1 maxv /* Event Name - Event Select - UMask */
81 1.14 msaitoh { "unhalted-core-cycles", 0x3c, 0x00, true },
82 1.14 msaitoh { "instruction-retired", 0xc0, 0x00, true },
83 1.14 msaitoh { "unhalted-reference-cycles", 0x3c, 0x01, true },
84 1.14 msaitoh { "llc-reference", 0x2e, 0x4f, true },
85 1.14 msaitoh { "llc-misses", 0x2e, 0x41, true },
86 1.14 msaitoh { "branch-instruction-retired", 0xc4, 0x00, true },
87 1.14 msaitoh { "branch-misses-retired", 0xc5, 0x00, true },
88 1.14 msaitoh { "topdown-slots", 0xa4, 0x01, true },
89 1.1 maxv };
90 1.1 maxv
91 1.1 maxv static struct event_table intel_arch1 = {
92 1.1 maxv .tablename = "Intel Architectural Version 1",
93 1.1 maxv .names = intel_arch1_names,
94 1.1 maxv .nevents = sizeof(intel_arch1_names) /
95 1.1 maxv sizeof(struct name_to_event),
96 1.1 maxv .next = NULL
97 1.1 maxv };
98 1.1 maxv
99 1.1 maxv static struct event_table *
100 1.1 maxv init_intel_arch1(void)
101 1.1 maxv {
102 1.12 msaitoh unsigned int eax, ebx, ecx, edx, vectorlen;
103 1.1 maxv struct event_table *table;
104 1.1 maxv size_t i;
105 1.1 maxv
106 1.14 msaitoh eax = 0x0a;
107 1.1 maxv ebx = 0;
108 1.1 maxv ecx = 0;
109 1.1 maxv edx = 0;
110 1.1 maxv x86_cpuid(&eax, &ebx, &ecx, &edx);
111 1.1 maxv
112 1.12 msaitoh vectorlen = __SHIFTOUT(eax, CPUID_PERF_BVECLEN);
113 1.12 msaitoh
114 1.1 maxv table = &intel_arch1;
115 1.1 maxv for (i = 0; i < table->nevents; i++) {
116 1.12 msaitoh /*
117 1.12 msaitoh * Disable the unsupported events from:
118 1.12 msaitoh * a) the bit vector length in EAX.
119 1.12 msaitoh * b) the disable bit in EBX.
120 1.12 msaitoh */
121 1.12 msaitoh if (i >= vectorlen)
122 1.12 msaitoh table->names[i].enabled = false;
123 1.1 maxv if ((ebx & (i << 1)) != 0)
124 1.1 maxv table->names[i].enabled = false;
125 1.1 maxv }
126 1.1 maxv
127 1.1 maxv return table;
128 1.1 maxv }
129 1.1 maxv
130 1.1 maxv /*
131 1.5 knakahar * Intel Silvermont/Airmont.
132 1.5 knakahar */
133 1.5 knakahar static struct name_to_event intel_silvermont_airmont_names[] = {
134 1.5 knakahar { "REHABQ.LD_BLOCK_ST_FORWARD", 0x03, 0x01, true },
135 1.5 knakahar { "REHABQ.LD_BLOCK_STD_NOTREADY", 0x03, 0x02, true },
136 1.5 knakahar { "REHABQ.ST_SPLITS", 0x03, 0x04, true },
137 1.5 knakahar { "REHABQ.LD_SPLITS", 0x03, 0x08, true },
138 1.5 knakahar { "REHABQ.LOCK", 0x03, 0x10, true },
139 1.5 knakahar { "REHABQ.STA_FULL", 0x03, 0x20, true },
140 1.5 knakahar { "REHABQ.ANY_LD", 0x03, 0x40, true },
141 1.5 knakahar { "REHABQ.ANY_ST", 0x03, 0x80, true },
142 1.5 knakahar { "MEM_UOPS_RETIRED.L1_MISS_LOADS", 0x04, 0x01, true },
143 1.5 knakahar { "MEM_UOPS_RETIRED.L2_HIT_LOADS", 0x04, 0x02, true },
144 1.5 knakahar { "MEM_UOPS_RETIRED.L2_MISS_LOADS", 0x04, 0x04, true },
145 1.5 knakahar { "MEM_UOPS_RETIRED.DTLB_MISS_LOADS", 0x04, 0x08, true },
146 1.5 knakahar { "MEM_UOPS_RETIRED.UTLB_MISS", 0x04, 0x10, true },
147 1.5 knakahar { "MEM_UOPS_RETIRED.HITM", 0x04, 0x20, true },
148 1.5 knakahar { "MEM_UOPS_RETIRED.ALL_LOADS", 0x04, 0x40, true },
149 1.5 knakahar { "MEM_UOP_RETIRED.ALL_STORES", 0x04, 0x80, true },
150 1.5 knakahar { "PAGE_WALKS.D_SIDE_CYCLES", 0x05, 0x01, true },
151 1.5 knakahar { "PAGE_WALKS.I_SIDE_CYCLES", 0x05, 0x02, true },
152 1.5 knakahar { "PAGE_WALKS.WALKS", 0x05, 0x03, true },
153 1.14 msaitoh { "LONGEST_LAT_CACHE.MISS", 0x2e, 0x41, true },
154 1.14 msaitoh { "LONGEST_LAT_CACHE.REFERENCE", 0x2e, 0x4f, true },
155 1.5 knakahar { "L2_REJECT_XQ.ALL", 0x30, 0x00, true },
156 1.5 knakahar { "CORE_REJECT_L2Q.ALL", 0x31, 0x00, true },
157 1.14 msaitoh { "CPU_CLK_UNHALTED.CORE_P", 0x3c, 0x00, true },
158 1.14 msaitoh { "CPU_CLK_UNHALTED.REF_P", 0x3c, 0x01, true },
159 1.5 knakahar { "ICACHE.HIT", 0x80, 0x01, true },
160 1.5 knakahar { "ICACHE.MISSES", 0x80, 0x02, true },
161 1.5 knakahar { "ICACHE.ACCESSES", 0x80, 0x03, true },
162 1.14 msaitoh { "OFFCORE_RESPONSE_0", 0xb7, 0x01, true },
163 1.14 msaitoh { "OFFCORE_RESPONSE_1", 0xb7, 0x02, true },
164 1.14 msaitoh { "INST_RETIRED.ANY_P", 0xc0, 0x00, true },
165 1.14 msaitoh { "UOPS_RETIRED.MS", 0xc2, 0x01, true },
166 1.14 msaitoh { "UOPS_RETIRED.ALL", 0xc2, 0x10, true },
167 1.14 msaitoh { "MACHINE_CLEARS.SMC", 0xc3, 0x01, true },
168 1.14 msaitoh { "MACHINE_CLEARS.MEMORY_ORDERING", 0xc3, 0x02, true },
169 1.14 msaitoh { "MACHINE_CLEARS.FP_ASSIST", 0xc3, 0x04, true },
170 1.14 msaitoh { "MACHINE_CLEARS.ALL", 0xc3, 0x08, true },
171 1.14 msaitoh { "BR_INST_RETIRED.ALL_BRANCHES", 0xc4, 0x00, true },
172 1.14 msaitoh { "BR_INST_RETIRED.JCC", 0xc4, 0x7e, true },
173 1.14 msaitoh { "BR_INST_RETIRED.FAR_BRANCH", 0xc4, 0xbf, true },
174 1.14 msaitoh { "BR_INST_RETIRED.NON_RETURN_IND", 0xc4, 0xeb, true },
175 1.14 msaitoh { "BR_INST_RETIRED.RETURN", 0xc4, 0xf7, true },
176 1.14 msaitoh { "BR_INST_RETIRED.CALL", 0xc4, 0xf9, true },
177 1.14 msaitoh { "BR_INST_RETIRED.IND_CALL", 0xc4, 0xfb, true },
178 1.14 msaitoh { "BR_INST_RETIRED.REL_CALL", 0xc4, 0xfd, true },
179 1.14 msaitoh { "BR_INST_RETIRED.TAKEN_JCC", 0xc4, 0xfe, true },
180 1.14 msaitoh { "BR_MISP_RETIRED.ALL_BRANCHES", 0xc5, 0x00, true },
181 1.14 msaitoh { "BR_MISP_RETIRED.JCC", 0xc5, 0x7e, true },
182 1.14 msaitoh { "BR_MISP_RETIRED.FAR", 0xc5, 0xbf, true },
183 1.14 msaitoh { "BR_MISP_RETIRED.NON_RETURN_IND", 0xc5, 0xeb, true },
184 1.14 msaitoh { "BR_MISP_RETIRED.RETURN", 0xc5, 0xf7, true },
185 1.14 msaitoh { "BR_MISP_RETIRED.CALL", 0xc5, 0xf9, true },
186 1.14 msaitoh { "BR_MISP_RETIRED.IND_CALL", 0xc5, 0xfb, true },
187 1.14 msaitoh { "BR_MISP_RETIRED.REL_CALL", 0xc5, 0xfd, true },
188 1.14 msaitoh { "BR_MISP_RETIRED.TAKEN_JCC", 0xc5, 0xfe, true },
189 1.14 msaitoh { "NO_ALLOC_CYCLES.ROB_FULL", 0xca, 0x01, true },
190 1.14 msaitoh { "NO_ALLOC_CYCLES.RAT_STALL", 0xca, 0x20, true },
191 1.14 msaitoh { "NO_ALLOC_CYCLES.ALL", 0xca, 0x3f, true },
192 1.14 msaitoh { "NO_ALLOC_CYCLES.NOT_DELIVERED", 0xca, 0x50, true },
193 1.14 msaitoh { "RS_FULL_STALL.MEC", 0xcb, 0x01, true },
194 1.14 msaitoh { "RS_FULL_STALL.ALL", 0xcb, 0x1f, true },
195 1.14 msaitoh { "CYCLES_DIV_BUSY.ANY", 0xcd, 0x01, true },
196 1.14 msaitoh { "BACLEARS.ALL", 0xe6, 0x01, true },
197 1.14 msaitoh { "BACLEARS.RETURN", 0xe6, 0x08, true },
198 1.14 msaitoh { "BACLEARS.COND", 0xe6, 0x10, true },
199 1.14 msaitoh { "MS_DECODED.MS_ENTRY", 0xe7, 0x01, true },
200 1.5 knakahar };
201 1.5 knakahar
202 1.5 knakahar static struct event_table intel_silvermont_airmont = {
203 1.5 knakahar .tablename = "Intel Silvermont/Airmont",
204 1.5 knakahar .names = intel_silvermont_airmont_names,
205 1.5 knakahar .nevents = sizeof(intel_silvermont_airmont_names) /
206 1.5 knakahar sizeof(struct name_to_event),
207 1.5 knakahar .next = NULL
208 1.5 knakahar };
209 1.5 knakahar
210 1.5 knakahar static struct event_table *
211 1.5 knakahar init_intel_silvermont_airmont(void)
212 1.5 knakahar {
213 1.5 knakahar
214 1.5 knakahar return &intel_silvermont_airmont;
215 1.5 knakahar }
216 1.5 knakahar
217 1.5 knakahar /*
218 1.6 knakahar * Intel Goldmont
219 1.6 knakahar */
220 1.6 knakahar static struct name_to_event intel_goldmont_names[] = {
221 1.6 knakahar { "LD_BLOCKS.ALL_BLOCK", 0x03, 0x10, true },
222 1.6 knakahar { "LD_BLOCKS.UTLB_MISS", 0x03, 0x08, true },
223 1.6 knakahar { "LD_BLOCKS.STORE_FORWARD", 0x03, 0x02, true },
224 1.6 knakahar { "LD_BLOCKS.DATA_UNKNOWN", 0x03, 0x01, true },
225 1.6 knakahar { "LD_BLOCKS.4K_ALIAS", 0x03, 0x04, true },
226 1.6 knakahar { "PAGE_WALKS.D_SIDE_CYCLES", 0x05, 0x01, true },
227 1.6 knakahar { "PAGE_WALKS.I_SIDE_CYCLES", 0x05, 0x02, true },
228 1.6 knakahar { "PAGE_WALKS.CYCLES", 0x05, 0x03, true },
229 1.14 msaitoh { "UOPS_ISSUED.ANY", 0x0e, 0x00, true },
230 1.6 knakahar { "MISALIGN_MEM_REF.LOAD_PAGE_SPLIT", 0x13, 0x02, true },
231 1.6 knakahar { "MISALIGN_MEM_REF.STORE_PAGE_SPLIT", 0x13, 0x04, true },
232 1.14 msaitoh { "LONGEST_LAT_CACHE.REFERENCE", 0x2e, 0x4f, true },
233 1.14 msaitoh { "LONGEST_LAT_CACHE.MISS", 0x2e, 0x41, true },
234 1.6 knakahar { "L2_REJECT_XQ.ALL", 0x30, 0x00, true },
235 1.6 knakahar { "CORE_REJECT_L2Q.ALL", 0x31, 0x00, true },
236 1.14 msaitoh { "CPU_CLK_UNHALTED.CORE_P", 0x3c, 0x00, true },
237 1.14 msaitoh { "CPU_CLK_UNHALTED.REF", 0x3c, 0x01, true },
238 1.6 knakahar { "DL1.DIRTY_EVICTION", 0x51, 0x01, true },
239 1.6 knakahar { "ICACHE.HIT", 0x80, 0x01, true },
240 1.6 knakahar { "ICACHE.MISSES", 0x80, 0x02, true },
241 1.6 knakahar { "ICACHE.ACCESSES", 0x80, 0x03, true },
242 1.6 knakahar { "ITLB.MISS", 0x81, 0x04, true },
243 1.6 knakahar { "FETCH_STALL.ALL", 0x86, 0x00, true },
244 1.6 knakahar { "FETCH_STALL.ITLB_FILL_PENDING_CYCLES", 0x86, 0x01, true },
245 1.6 knakahar { "FETCH_STALL.ICACHE_FILL_PENDING_CYCLES", 0x86, 0x02, true },
246 1.14 msaitoh { "UOPS_NOT_DELIVERED.ANY", 0x9c, 0x00, true },
247 1.14 msaitoh { "OFFCORE_RESPONSE.0", 0xb7, 0x01, true },
248 1.14 msaitoh { "OFFCORE_RESPONSE.1", 0xb7, 0x02, true },
249 1.14 msaitoh { "INST_RETIRED.ANY_P", 0xc0, 0x00, true },
250 1.14 msaitoh { "UOPS_RETIRED.ANY", 0xc2, 0x00, true },
251 1.14 msaitoh { "UOPS_RETIRED.MS", 0xc2, 0x01, true },
252 1.14 msaitoh { "UOPS_RETIRED.FPDIV", 0xc2, 0x08, true },
253 1.14 msaitoh { "UOPS_RETIRED.IDIV", 0xc2, 0x10, true },
254 1.14 msaitoh { "MACHINE_CLEARS.SMC", 0xc3, 0x01, true },
255 1.14 msaitoh { "MACHINE_CLEARS.MEMORY_ORDERING", 0xc3, 0x02, true },
256 1.14 msaitoh { "MACHINE_CLEARS.FP_ASSIST", 0xc3, 0x04, true },
257 1.14 msaitoh { "MACHINE_CLEARS.DISAMBIGUATION", 0xc3, 0x08, true },
258 1.14 msaitoh { "MACHINE_CLEARS.ALL", 0xc3, 0x00, true },
259 1.14 msaitoh { "BR_INST_RETIRED.ALL_BRANCHES", 0xc4, 0x00, true },
260 1.14 msaitoh { "BR_INST_RETIRED.JCC", 0xc4, 0x7e, true },
261 1.14 msaitoh { "BR_INST_RETIRED.ALL_TAKEN_BRANCHES", 0xc4, 0x80, true },
262 1.14 msaitoh { "BR_INST_RETIRED.TAKEN_JCC", 0xc4, 0xfe, true },
263 1.14 msaitoh { "BR_INST_RETIRED.CALL", 0xc4, 0xf9, true },
264 1.14 msaitoh { "BR_INST_RETIRED.REL_CALL", 0xc4, 0xfd, true },
265 1.14 msaitoh { "BR_INST_RETIRED.IND_CALL", 0xc4, 0xfb, true },
266 1.14 msaitoh { "BR_INST_RETIRED.RETURN", 0xc4, 0xf7, true },
267 1.14 msaitoh { "BR_INST_RETIRED.NON_RETURN_IND", 0xc4, 0xeb, true },
268 1.14 msaitoh { "BR_INST_RETIRED.FAR_BRANCH", 0xc4, 0xbf, true },
269 1.14 msaitoh { "BR_MISP_RETIRED.ALL_BRANCHES", 0xc5, 0x00, true },
270 1.14 msaitoh { "BR_MISP_RETIRED.JCC", 0xc5, 0x7e, true },
271 1.14 msaitoh { "BR_MISP_RETIRED.TAKEN_JCC", 0xc5, 0xfe, true },
272 1.14 msaitoh { "BR_MISP_RETIRED.IND_CALL", 0xc5, 0xfb, true },
273 1.14 msaitoh { "BR_MISP_RETIRED.RETURN", 0xc5, 0xf7, true },
274 1.14 msaitoh { "BR_MISP_RETIRED.NON_RETURN_IND", 0xc5, 0xeb, true },
275 1.14 msaitoh { "ISSUE_SLOTS_NOT_CONSUMED.RESOURCE_FULL", 0xca, 0x01, true },
276 1.14 msaitoh { "ISSUE_SLOTS_NOT_CONSUMED.RECOVERY", 0xca, 0x02, true },
277 1.14 msaitoh { "ISSUE_SLOTS_NOT_CONSUMED.ANY", 0xca, 0x00, true },
278 1.14 msaitoh { "HW_INTERRUPTS.RECEIVED", 0xcb, 0x01, true },
279 1.14 msaitoh { "HW_INTERRUPTS.MASKED", 0xcb, 0x02, true },
280 1.14 msaitoh { "HW_INTERRUPTS.PENDING_AND_MASKED", 0xcb, 0x04, true },
281 1.14 msaitoh { "CYCLES_DIV_BUSY.ALL", 0xcd, 0x00, true },
282 1.14 msaitoh { "CYCLES_DIV_BUSY.IDIV", 0xcd, 0x01, true },
283 1.14 msaitoh { "CYCLES_DIV_BUSY.FPDIV", 0xcd, 0x02, true },
284 1.14 msaitoh { "MEM_UOPS_RETIRED.ALL_LOADS", 0xd0, 0x81, true },
285 1.14 msaitoh { "MEM_UOPS_RETIRED.ALL_STORES", 0xd0, 0x82, true },
286 1.14 msaitoh { "MEM_UOPS_RETIRED.ALL", 0xd0, 0x83, true },
287 1.14 msaitoh { "MEM_UOPS_RETIRED.DTLB_MISS_LOADS", 0xd0, 0x11, true },
288 1.14 msaitoh { "MEM_UOPS_RETIRED.DTLB_MISS_STORES", 0xd0, 0x12, true },
289 1.14 msaitoh { "MEM_UOPS_RETIRED.DTLB_MISS", 0xd0, 0x13, true },
290 1.14 msaitoh { "MEM_UOPS_RETIRED.LOCK_LOADS", 0xd0, 0x21, true },
291 1.14 msaitoh { "MEM_UOPS_RETIRED.SPLIT_LOADS", 0xd0, 0x41, true },
292 1.14 msaitoh { "MEM_UOPS_RETIRED.SPLIT_STORES", 0xd0, 0x42, true },
293 1.14 msaitoh { "MEM_UOPS_RETIRED.SPLIT", 0xd0, 0x43, true },
294 1.14 msaitoh { "MEM_LOAD_UOPS_RETIRED.L1_HIT", 0xd1, 0x01, true },
295 1.14 msaitoh { "MEM_LOAD_UOPS_RETIRED.L1_MISS", 0xd1, 0x08, true },
296 1.14 msaitoh { "MEM_LOAD_UOPS_RETIRED.L2_HIT", 0xd1, 0x02, true },
297 1.14 msaitoh { "MEM_LOAD_UOPS_RETIRED.L2_MISS", 0xd1, 0x10, true },
298 1.14 msaitoh { "MEM_LOAD_UOPS_RETIRED.HITM", 0xd1, 0x20, true },
299 1.14 msaitoh { "MEM_LOAD_UOPS_RETIRED.WCB_HIT", 0xd1, 0x40, true },
300 1.14 msaitoh { "MEM_LOAD_UOPS_RETIRED.DRAM_HIT", 0xd1, 0x80, true },
301 1.14 msaitoh { "BACLEARS.ALL", 0xe6, 0x01, true },
302 1.14 msaitoh { "BACLEARS.RETURN", 0xe6, 0x08, true },
303 1.14 msaitoh { "BACLEAR.CONDS", 0xe6, 0x10, true },
304 1.14 msaitoh { "MS_DECODED.MS_ENTRY", 0xe7, 0x01, true },
305 1.14 msaitoh { "DECODED_RESTRICTION.PREDECODE_WRONG", 0xe9, 0x01, true },
306 1.6 knakahar };
307 1.6 knakahar
308 1.6 knakahar static struct event_table intel_goldmont = {
309 1.6 knakahar .tablename = "Intel Goldmont",
310 1.6 knakahar .names = intel_goldmont_names,
311 1.6 knakahar .nevents = sizeof(intel_goldmont_names) /
312 1.6 knakahar sizeof(struct name_to_event),
313 1.6 knakahar .next = NULL
314 1.6 knakahar };
315 1.6 knakahar
316 1.6 knakahar static struct event_table *
317 1.6 knakahar init_intel_goldmont(void)
318 1.6 knakahar {
319 1.6 knakahar
320 1.6 knakahar return &intel_goldmont;
321 1.6 knakahar }
322 1.6 knakahar
323 1.6 knakahar /*
324 1.7 knakahar * Intel Goldmont Plus (Additions from Goldmont)
325 1.7 knakahar */
326 1.7 knakahar static struct name_to_event intel_goldmontplus_names[] = {
327 1.7 knakahar { "INST_RETIRED.ANY", 0x00, 0x01, true },
328 1.7 knakahar { "DTLB_LOAD_MISSES.WALK_COMPLETED_4K", 0x08, 0x02, true },
329 1.7 knakahar { "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M", 0x08, 0x04, true },
330 1.7 knakahar { "DTLB_LOAD_MISSES.WALK_COMPLETED_1GB", 0x08, 0x08, true },
331 1.7 knakahar { "DTLB_LOAD_MISSES.WALK_PENDING", 0x08, 0x10, true },
332 1.7 knakahar { "DTLB_STORE_MISSES.WALK_COMPLETED_4K", 0x49, 0x02, true },
333 1.7 knakahar { "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M", 0x49, 0x04, true },
334 1.7 knakahar { "DTLB_STORE_MISSES.WALK_COMPLETED_1GB", 0x49, 0x08, true },
335 1.7 knakahar { "DTLB_STORE_MISSES.WALK_PENDING", 0x49, 0x10, true },
336 1.14 msaitoh { "EPT.WALK_PENDING", 0x4f, 0x10, true },
337 1.7 knakahar { "ITLB_MISSES.WALK_COMPLETED_4K", 0x85, 0x08, true },
338 1.7 knakahar { "ITLB_MISSES.WALK_COMPLETED_2M_4M", 0x85, 0x04, true },
339 1.7 knakahar { "ITLB_MISSES.WALK_COMPLETED_1GB", 0x85, 0x08, true },
340 1.7 knakahar { "ITLB_MISSES.WALK_PENDING", 0x85, 0x10, true },
341 1.14 msaitoh { "TLB_FLUSHES.STLB_ANY", 0xbd, 0x20, true },
342 1.14 msaitoh { "MACHINE_CLEARS.PAGE_FAULT", 0xc3, 0x20, true },
343 1.7 knakahar };
344 1.7 knakahar
345 1.7 knakahar static struct event_table intel_goldmontplus = {
346 1.7 knakahar .tablename = "Intel Goldmont Plus",
347 1.7 knakahar .names = intel_goldmontplus_names,
348 1.7 knakahar .nevents = sizeof(intel_goldmontplus_names) /
349 1.7 knakahar sizeof(struct name_to_event),
350 1.7 knakahar .next = NULL
351 1.7 knakahar };
352 1.7 knakahar
353 1.7 knakahar static struct event_table *
354 1.7 knakahar init_intel_goldmontplus(void)
355 1.7 knakahar {
356 1.7 knakahar
357 1.7 knakahar intel_goldmont.next = &intel_goldmontplus;
358 1.7 knakahar
359 1.7 knakahar return &intel_goldmont;
360 1.7 knakahar }
361 1.7 knakahar
362 1.7 knakahar /*
363 1.4 maxv * Intel Skylake/Kabylake.
364 1.4 maxv *
365 1.4 maxv * The events that are not listed, because they are of little interest or
366 1.4 maxv * require extra configuration:
367 1.4 maxv * TX_*
368 1.4 maxv * FRONTEND_RETIRED.*
369 1.4 maxv * FP_ARITH_INST_RETIRED.*
370 1.4 maxv * HLE_RETIRED.*
371 1.4 maxv * RTM_RETIRED.*
372 1.4 maxv * MEM_TRANS_RETIRED.*
373 1.4 maxv * UOPS_DISPATCHED_PORT.*
374 1.1 maxv */
375 1.1 maxv static struct name_to_event intel_skylake_kabylake_names[] = {
376 1.1 maxv /* Event Name - Event Select - UMask */
377 1.13 msaitoh { "LD_BLOCKS.STORE_FORWARD", 0x03, 0x02, true },
378 1.13 msaitoh { "LD_BLOCKS.NO_SR", 0x03, 0x08, true },
379 1.13 msaitoh { "LD_BLOCKS_PARTIAL.ADDRESS_ALIAS", 0x07, 0x01, true },
380 1.13 msaitoh { "DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK", 0x08, 0x01, true },
381 1.13 msaitoh { "DTLB_LOAD_MISSES.WALK_COMPLETED_4K", 0x08, 0x02, true },
382 1.13 msaitoh { "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M", 0x08, 0x04, true },
383 1.13 msaitoh { "DTLB_LOAD_MISSES.WALK_COMPLETED_1G", 0x08, 0x08, true },
384 1.14 msaitoh { "DTLB_LOAD_MISSES.WALK_COMPLETED", 0x08, 0x0e, true },
385 1.13 msaitoh { "DTLB_LOAD_MISSES.WALK_PENDING", 0x08, 0x10, true },
386 1.13 msaitoh { "DTLB_LOAD_MISSES.STLB_HIT", 0x08, 0x20, true },
387 1.14 msaitoh { "INT_MISC.RECOVERY_CYCLES", 0x0d, 0x01, true },
388 1.14 msaitoh { "INT_MISC.CLEAR_RESTEER_CYCLES", 0x0d, 0x80, true },
389 1.14 msaitoh { "UOPS_ISSUED.ANY", 0x0e, 0x01, true },
390 1.14 msaitoh { "UOPS_ISSUED.VECTOR_WIDTH_MISMATCH", 0x0e, 0x02, true },
391 1.14 msaitoh { "UOPS_ISSUED.SLOW_LEA", 0x0e, 0x20, true },
392 1.13 msaitoh { "L2_RQSTS.DEMAND_DATA_RD_MISS", 0x24, 0x21, true },
393 1.13 msaitoh { "L2_RQSTS.RFO_MISS", 0x24, 0x22, true },
394 1.13 msaitoh { "L2_RQSTS.CODE_RD_MISS", 0x24, 0x24, true },
395 1.13 msaitoh { "L2_RQSTS.ALL_DEMAND_MISS", 0x24, 0x27, true },
396 1.13 msaitoh { "L2_RQSTS.PF_MISS", 0x24, 0x38, true },
397 1.14 msaitoh { "L2_RQSTS.MISS", 0x24, 0x3f, true },
398 1.13 msaitoh { "L2_RQSTS.DEMAND_DATA_RD_HIT", 0x24, 0x41, true },
399 1.13 msaitoh { "L2_RQSTS.RFO_HIT", 0x24, 0x42, true },
400 1.13 msaitoh { "L2_RQSTS.CODE_RD_HIT", 0x24, 0x44, true },
401 1.14 msaitoh { "L2_RQSTS.PF_HIT", 0x24, 0xd8, true },
402 1.14 msaitoh { "L2_RQSTS.ALL_DEMAND_DATA_RD", 0x24, 0xe1, true },
403 1.14 msaitoh { "L2_RQSTS.ALL_RFO", 0x24, 0xe2, true },
404 1.14 msaitoh { "L2_RQSTS.ALL_CODE_RD", 0x24, 0xe4, true },
405 1.14 msaitoh { "L2_RQSTS.ALL_DEMAND_REFERENCES", 0x24, 0xe7, true },
406 1.14 msaitoh { "L2_RQSTS.ALL_PF", 0x24, 0xf8, true },
407 1.14 msaitoh { "L2_RQSTS.REFERENCES", 0x24, 0xff, true },
408 1.13 msaitoh { "SW_PREFETCH_ACCESS.NTA", 0x32, 0x01, true },
409 1.13 msaitoh { "SW_PREFETCH_ACCESS.T0", 0x32, 0x02, true },
410 1.13 msaitoh { "SW_PREFETCH_ACCESS.T1_T2", 0x32, 0x04, true },
411 1.13 msaitoh { "SW_PREFETCH_ACCESS.PREFETCHW", 0x32, 0x08, true },
412 1.14 msaitoh { "CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE", 0x3c, 0x02, true },
413 1.14 msaitoh { "CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE", 0x3c, 0x02, true },
414 1.13 msaitoh { "L1D_PEND_MISS.PENDING", 0x48, 0x01, true },
415 1.13 msaitoh { "L1D_PEND_MISS.FB_FULL", 0x48, 0x02, true },
416 1.13 msaitoh { "DTLB_STORE_MISSES.MISS_CAUSES_A_WALK", 0x49, 0x01, true },
417 1.13 msaitoh { "DTLB_STORE_MISSES.WALK_COMPLETED_4K", 0x49, 0x02, true },
418 1.13 msaitoh { "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M", 0x49, 0x04, true },
419 1.13 msaitoh { "DTLB_STORE_MISSES.WALK_COMPLETED_1G", 0x49, 0x08, true },
420 1.14 msaitoh { "DTLB_STORE_MISSES.WALK_COMPLETED", 0x49, 0x0e, true },
421 1.13 msaitoh { "DTLB_STORE_MISSES.WALK_PENDING", 0x49, 0x10, true },
422 1.13 msaitoh { "DTLB_STORE_MISSES.STLB_HIT", 0x49, 0x20, true },
423 1.14 msaitoh { "LOAD_HIT_PRE.SW_PF", 0x4c, 0x01, true },
424 1.14 msaitoh { "EPT.WALK_PENDING", 0x4f, 0x10, true },
425 1.13 msaitoh { "L1D.REPLACEMENT", 0x51, 0x01, true },
426 1.14 msaitoh { "RS_EVENTS.EMPTY_CYCLES", 0x5e, 0x01, true },
427 1.13 msaitoh { "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD", 0x60, 0x01, true },
428 1.13 msaitoh { "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_CODE_RD", 0x60, 0x02, true },
429 1.13 msaitoh { "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO", 0x60, 0x04, true },
430 1.13 msaitoh { "OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD", 0x60, 0x08, true },
431 1.13 msaitoh { "OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD",
432 1.13 msaitoh 0x60, 0x10, true },
433 1.13 msaitoh { "IDQ.MITE_UOPS", 0x79, 0x04, true },
434 1.13 msaitoh { "IDQ.DSB_UOPS", 0x79, 0x08, true },
435 1.13 msaitoh { "IDQ.MS_MITE_UOPS", 0x79, 0x20, true },
436 1.13 msaitoh { "IDQ.MS_UOPS", 0x79, 0x30, true },
437 1.13 msaitoh { "ICACHE_16B.IFDATA_STALL", 0x80, 0x04, true },
438 1.13 msaitoh { "ICACHE_64B.IFTAG_HIT", 0x83, 0x01, true },
439 1.13 msaitoh { "ICACHE_64B.IFTAG_MISS", 0x83, 0x02, true },
440 1.13 msaitoh { "ICACHE_64B.IFTAG_STALL", 0x83, 0x04, true },
441 1.13 msaitoh { "ITLB_MISSES.MISS_CAUSES_A_WALK", 0x85, 0x01, true },
442 1.13 msaitoh { "ITLB_MISSES.WALK_COMPLETED_4K", 0x85, 0x02, true },
443 1.13 msaitoh { "ITLB_MISSES.WALK_COMPLETED_2M_4M", 0x85, 0x04, true },
444 1.13 msaitoh { "ITLB_MISSES.WALK_COMPLETED_1G", 0x85, 0x08, true },
445 1.14 msaitoh { "ITLB_MISSES.WALK_COMPLETED", 0x85, 0x0e, true },
446 1.13 msaitoh { "ITLB_MISSES.WALK_PENDING", 0x85, 0x10, true },
447 1.13 msaitoh { "ITLB_MISSES.STLB_HIT", 0x85, 0x20, true },
448 1.13 msaitoh { "ILD_STALL.LCP", 0x87, 0x01, true },
449 1.14 msaitoh { "IDQ_UOPS_NOT_DELIVERED.CORE", 0x9c, 0x01, true },
450 1.14 msaitoh { "RESOURCE_STALLS.ANY", 0xa2, 0x01, true },
451 1.14 msaitoh { "RESOURCE_STALLS.SB", 0xa2, 0x08, true },
452 1.14 msaitoh { "EXE_ACTIVITY.EXE_BOUND_0_PORTS", 0xa6, 0x01, true },
453 1.14 msaitoh { "EXE_ACTIVITY.1_PORTS_UTIL", 0xa6, 0x02, true },
454 1.14 msaitoh { "EXE_ACTIVITY.2_PORTS_UTIL", 0xa6, 0x04, true },
455 1.14 msaitoh { "EXE_ACTIVITY.3_PORTS_UTIL", 0xa6, 0x08, true },
456 1.14 msaitoh { "EXE_ACTIVITY.4_PORTS_UTIL", 0xa6, 0x10, true },
457 1.14 msaitoh { "EXE_ACTIVITY.BOUND_ON_STORES", 0xa6, 0x40, true },
458 1.14 msaitoh { "LSD.UOPS", 0xa8, 0x01, true },
459 1.14 msaitoh { "DSB2MITE_SWITCHES.PENALTY_CYCLES", 0xab, 0x02, true },
460 1.14 msaitoh { "ITLB.ITLB_FLUSH", 0xae, 0x01, true },
461 1.14 msaitoh { "OFFCORE_REQUESTS.DEMAND_DATA_RD", 0xb0, 0x01, true },
462 1.14 msaitoh { "OFFCORE_REQUESTS.DEMAND_CODE_RD", 0xb0, 0x02, true },
463 1.14 msaitoh { "OFFCORE_REQUESTS.DEMAND_RFO", 0xb0, 0x04, true },
464 1.14 msaitoh { "OFFCORE_REQUESTS.ALL_DATA_RD", 0xb0, 0x08, true },
465 1.14 msaitoh { "OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD", 0xb0, 0x10, true },
466 1.14 msaitoh { "OFFCORE_REQUESTS.ALL_REQUESTS", 0xb0, 0x80, true },
467 1.14 msaitoh { "UOPS_EXECUTED.THREAD", 0xb1, 0x01, true },
468 1.14 msaitoh { "UOPS_EXECUTED.CORE", 0xb1, 0x02, true },
469 1.14 msaitoh { "UOPS_EXECUTED.X87", 0xb1, 0x10, true },
470 1.14 msaitoh { "OFFCORE_REQUESTS_BUFFER.SQ_FULL", 0xb2, 0x01, true },
471 1.14 msaitoh { "TLB_FLUSH.DTLB_THREAD", 0xbd, 0x01, true },
472 1.14 msaitoh { "TLB_FLUSH.STLB_ANY", 0xbd, 0x20, true },
473 1.14 msaitoh { "INST_RETIRED.PREC_DIST", 0xc0, 0x01, true },
474 1.14 msaitoh { "OTHER_ASSISTS.ANY", 0xc1, 0x3f, true },
475 1.14 msaitoh { "UOPS_RETIRED.RETIRE_SLOTS", 0xc2, 0x02, true },
476 1.14 msaitoh { "MACHINE_CLEARS.MEMORY_ORDERING", 0xc3, 0x02, true },
477 1.14 msaitoh { "MACHINE_CLEARS.SMC", 0xc3, 0x04, true },
478 1.14 msaitoh { "BR_INST_RETIRED.CONDITIONAL", 0xc4, 0x01, true },
479 1.14 msaitoh { "BR_INST_RETIRED.NEAR_CALL", 0xc4, 0x02, true },
480 1.14 msaitoh { "BR_INST_RETIRED.NEAR_RETURN", 0xc4, 0x08, true },
481 1.14 msaitoh { "BR_INST_RETIRED.NOT_TAKEN", 0xc4, 0x10, true },
482 1.14 msaitoh { "BR_INST_RETIRED.NEAR_TAKEN", 0xc4, 0x20, true },
483 1.14 msaitoh { "BR_INST_RETIRED.FAR_BRANCH", 0xc4, 0x40, true },
484 1.14 msaitoh { "BR_MISP_RETIRED.CONDITIONAL", 0xc5, 0x01, true },
485 1.14 msaitoh { "BR_MISP_RETIRED.NEAR_CALL", 0xc5, 0x02, true },
486 1.14 msaitoh { "BR_MISP_RETIRED.NEAR_TAKEN", 0xc5, 0x20, true },
487 1.14 msaitoh { "HW_INTERRUPTS.RECEIVED", 0xcb, 0x01, true },
488 1.14 msaitoh { "MEM_INST_RETIRED.STLB_MISS_LOADS", 0xd0, 0x11, true },
489 1.14 msaitoh { "MEM_INST_RETIRED.STLB_MISS_STORES", 0xd0, 0x12, true },
490 1.14 msaitoh { "MEM_INST_RETIRED.LOCK_LOADS", 0xd0, 0x21, true },
491 1.14 msaitoh { "MEM_INST_RETIRED.SPLIT_LOADS", 0xd0, 0x41, true },
492 1.14 msaitoh { "MEM_INST_RETIRED.SPLIT_STORES", 0xd0, 0x42, true },
493 1.14 msaitoh { "MEM_INST_RETIRED.ALL_LOADS", 0xd0, 0x81, true },
494 1.14 msaitoh { "MEM_INST_RETIRED.ALL_STORES", 0xd0, 0x82, true },
495 1.14 msaitoh { "MEM_LOAD_RETIRED.L1_HIT", 0xd1, 0x01, true },
496 1.14 msaitoh { "MEM_LOAD_RETIRED.L2_HIT", 0xd1, 0x02, true },
497 1.14 msaitoh { "MEM_LOAD_RETIRED.L3_HIT", 0xd1, 0x04, true },
498 1.14 msaitoh { "MEM_LOAD_RETIRED.L1_MISS", 0xd1, 0x08, true },
499 1.14 msaitoh { "MEM_LOAD_RETIRED.L2_MISS", 0xd1, 0x10, true },
500 1.14 msaitoh { "MEM_LOAD_RETIRED.L3_MISS", 0xd1, 0x20, true },
501 1.14 msaitoh { "MEM_LOAD_RETIRED.FB_HIT", 0xd1, 0x40, true },
502 1.14 msaitoh { "MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS", 0xd2, 0x01, true },
503 1.14 msaitoh { "MEM_LOAD_L3_HIT_RETIRED.XSNP_HIT", 0xd2, 0x02, true },
504 1.14 msaitoh { "MEM_LOAD_L3_HIT_RETIRED.XSNP_HITM", 0xd2, 0x04, true },
505 1.14 msaitoh { "MEM_LOAD_L3_HIT_RETIRED.XSNP_NONE", 0xd2, 0x08, true },
506 1.14 msaitoh { "MEM_LOAD_MISC_RETIRED.UC", 0xd4, 0x04, true },
507 1.14 msaitoh { "BACLEARS.ANY", 0xe6, 0x01, true },
508 1.14 msaitoh { "L2_TRANS.L2_WB", 0xf0, 0x40, true },
509 1.14 msaitoh { "L2_LINES_IN.ALL", 0xf1, 0x1f, true },
510 1.14 msaitoh { "L2_LINES_OUT.SILENT", 0xf2, 0x01, true },
511 1.14 msaitoh { "L2_LINES_OUT.NON_SILENT", 0xf2, 0x02, true },
512 1.14 msaitoh { "L2_LINES_OUT.USELESS_HWPF", 0xf2, 0x04, true },
513 1.14 msaitoh { "SQ_MISC.SPLIT_LOCK", 0xf4, 0x10, true },
514 1.1 maxv };
515 1.1 maxv
516 1.1 maxv static struct event_table intel_skylake_kabylake = {
517 1.1 maxv .tablename = "Intel Skylake/Kabylake",
518 1.1 maxv .names = intel_skylake_kabylake_names,
519 1.1 maxv .nevents = sizeof(intel_skylake_kabylake_names) /
520 1.1 maxv sizeof(struct name_to_event),
521 1.1 maxv .next = NULL
522 1.1 maxv };
523 1.1 maxv
524 1.1 maxv static struct event_table *
525 1.1 maxv init_intel_skylake_kabylake(void)
526 1.1 maxv {
527 1.13 msaitoh
528 1.1 maxv return &intel_skylake_kabylake;
529 1.1 maxv }
530 1.1 maxv
531 1.1 maxv static struct event_table *
532 1.1 maxv init_intel_generic(void)
533 1.1 maxv {
534 1.1 maxv unsigned int eax, ebx, ecx, edx;
535 1.1 maxv struct event_table *table;
536 1.1 maxv
537 1.1 maxv /*
538 1.1 maxv * The kernel made sure the Architectural Version 1 PMCs were
539 1.1 maxv * present.
540 1.1 maxv */
541 1.1 maxv table = init_intel_arch1();
542 1.1 maxv
543 1.1 maxv /*
544 1.1 maxv * Now query the additional (non-architectural) events. They
545 1.1 maxv * depend on the CPU model.
546 1.1 maxv */
547 1.1 maxv eax = 0x01;
548 1.1 maxv ebx = 0;
549 1.1 maxv ecx = 0;
550 1.1 maxv edx = 0;
551 1.1 maxv x86_cpuid(&eax, &ebx, &ecx, &edx);
552 1.1 maxv
553 1.3 maxv if (CPUID_TO_FAMILY(eax) == 6) {
554 1.3 maxv switch (CPUID_TO_MODEL(eax)) {
555 1.5 knakahar case 0x37: /* Silvermont (Bay Trail) */
556 1.14 msaitoh case 0x4a: /* Silvermont (Tangier) */
557 1.14 msaitoh case 0x4c: /* Airmont (Braswell, Cherry Trail) */
558 1.14 msaitoh case 0x4d: /* Silvermont (Avoton, Rangeley) */
559 1.14 msaitoh case 0x5a: /* Silvermont (Anniedale) */
560 1.14 msaitoh case 0x5d: /* Silvermont (SoFIA) */
561 1.5 knakahar table->next = init_intel_silvermont_airmont();
562 1.5 knakahar break;
563 1.14 msaitoh case 0x5c: /* Goldmont (Apollo Lake) */
564 1.14 msaitoh case 0x5f: /* Goldmont (Denverton) */
565 1.6 knakahar table->next = init_intel_goldmont();
566 1.6 knakahar break;
567 1.14 msaitoh case 0x7a: /* Goldmont Plus (Gemini Lake) */
568 1.7 knakahar table->next = init_intel_goldmontplus();
569 1.7 knakahar break;
570 1.14 msaitoh case 0x4e: /* Skylake */
571 1.14 msaitoh case 0x5e: /* Skylake */
572 1.14 msaitoh case 0x8e: /* Kabylake */
573 1.14 msaitoh case 0x9e: /* Kabylake */
574 1.16 msaitoh case 0xa5: /* Cometlake */
575 1.16 msaitoh case 0xa6: /* Cometlake */
576 1.3 maxv table->next = init_intel_skylake_kabylake();
577 1.3 maxv break;
578 1.3 maxv }
579 1.1 maxv }
580 1.1 maxv
581 1.1 maxv return table;
582 1.1 maxv }
583 1.1 maxv
584 1.13 msaitoh /* ------------------------------------------------------------------------- */
585 1.1 maxv
586 1.1 maxv /*
587 1.1 maxv * AMD Family 10h
588 1.1 maxv */
589 1.1 maxv static struct name_to_event amd_f10h_names[] = {
590 1.2 maxv { "seg-load-all", 0x20, 0x7f, true },
591 1.2 maxv { "seg-load-es", 0x20, 0x01, true },
592 1.2 maxv { "seg-load-cs", 0x20, 0x02, true },
593 1.2 maxv { "seg-load-ss", 0x20, 0x04, true },
594 1.2 maxv { "seg-load-ds", 0x20, 0x08, true },
595 1.2 maxv { "seg-load-fs", 0x20, 0x10, true },
596 1.2 maxv { "seg-load-gs", 0x20, 0x20, true },
597 1.2 maxv { "seg-load-hs", 0x20, 0x40, true },
598 1.2 maxv { "l1cache-access", 0x40, 0x00, true },
599 1.2 maxv { "l1cache-miss", 0x41, 0x00, true },
600 1.2 maxv { "l1cache-refill", 0x42, 0x1f, true },
601 1.2 maxv { "l1cache-refill-invalid", 0x42, 0x01, true },
602 1.2 maxv { "l1cache-refill-shared", 0x42, 0x02, true },
603 1.2 maxv { "l1cache-refill-exclusive", 0x42, 0x04, true },
604 1.2 maxv { "l1cache-refill-owner", 0x42, 0x08, true },
605 1.2 maxv { "l1cache-refill-modified", 0x42, 0x10, true },
606 1.2 maxv { "l1cache-load", 0x43, 0x1f, true },
607 1.2 maxv { "l1cache-load-invalid", 0x43, 0x01, true },
608 1.2 maxv { "l1cache-load-shared", 0x43, 0x02, true },
609 1.2 maxv { "l1cache-load-exclusive", 0x43, 0x04, true },
610 1.2 maxv { "l1cache-load-owner", 0x43, 0x08, true },
611 1.2 maxv { "l1cache-load-modified", 0x43, 0x10, true },
612 1.2 maxv { "l1cache-writeback", 0x44, 0x1f, true },
613 1.2 maxv { "l1cache-writeback-invalid", 0x44, 0x01, true },
614 1.2 maxv { "l1cache-writeback-shared", 0x44, 0x02, true },
615 1.2 maxv { "l1cache-writeback-exclusive",0x44, 0x04, true },
616 1.2 maxv { "l1cache-writeback-owner", 0x44, 0x08, true },
617 1.2 maxv { "l1cache-writeback-modified", 0x44, 0x10, true },
618 1.14 msaitoh { "l1DTLB-hit-all", 0x4d, 0x07, true },
619 1.14 msaitoh { "l1DTLB-hit-4Kpage", 0x4d, 0x01, true },
620 1.14 msaitoh { "l1DTLB-hit-2Mpage", 0x4d, 0x02, true },
621 1.14 msaitoh { "l1DTLB-hit-1Gpage", 0x4d, 0x04, true },
622 1.2 maxv { "l1DTLB-miss-all", 0x45, 0x07, true },
623 1.2 maxv { "l1DTLB-miss-4Kpage", 0x45, 0x01, true },
624 1.2 maxv { "l1DTLB-miss-2Mpage", 0x45, 0x02, true },
625 1.2 maxv { "l1DTLB-miss-1Gpage", 0x45, 0x04, true },
626 1.2 maxv { "l2DTLB-miss-all", 0x46, 0x03, true },
627 1.2 maxv { "l2DTLB-miss-4Kpage", 0x46, 0x01, true },
628 1.2 maxv { "l2DTLB-miss-2Mpage", 0x46, 0x02, true },
629 1.1 maxv /* l2DTLB-miss-1Gpage: reserved on some revisions, so disabled */
630 1.2 maxv { "l1ITLB-miss", 0x84, 0x00, true },
631 1.2 maxv { "l2ITLB-miss-all", 0x85, 0x03, true },
632 1.2 maxv { "l2ITLB-miss-4Kpage", 0x85, 0x01, true },
633 1.2 maxv { "l2ITLB-miss-2Mpage", 0x85, 0x02, true },
634 1.2 maxv { "mem-misalign-ref", 0x47, 0x00, true },
635 1.2 maxv { "ins-fetch", 0x80, 0x00, true },
636 1.2 maxv { "ins-fetch-miss", 0x81, 0x00, true },
637 1.2 maxv { "ins-refill-l2", 0x82, 0x00, true },
638 1.2 maxv { "ins-refill-sys", 0x83, 0x00, true },
639 1.2 maxv { "ins-fetch-stall", 0x87, 0x00, true },
640 1.14 msaitoh { "ins-retired", 0xc0, 0x00, true },
641 1.14 msaitoh { "ins-empty", 0xd0, 0x00, true },
642 1.14 msaitoh { "ops-retired", 0xc1, 0x00, true },
643 1.14 msaitoh { "branch-retired", 0xc2, 0x00, true },
644 1.14 msaitoh { "branch-miss-retired", 0xc3, 0x00, true },
645 1.14 msaitoh { "branch-taken-retired", 0xc4, 0x00, true },
646 1.14 msaitoh { "branch-taken-miss-retired", 0xc5, 0x00, true },
647 1.14 msaitoh { "branch-far-retired", 0xc6, 0x00, true },
648 1.14 msaitoh { "branch-resync-retired", 0xc7, 0x00, true },
649 1.14 msaitoh { "branch-near-retired", 0xc8, 0x00, true },
650 1.14 msaitoh { "branch-near-miss-retired", 0xc9, 0x00, true },
651 1.14 msaitoh { "branch-indirect-miss-retired", 0xca, 0x00, true },
652 1.14 msaitoh { "int-hw", 0xcf, 0x00, true },
653 1.14 msaitoh { "int-cycles-masked", 0xcd, 0x00, true },
654 1.14 msaitoh { "int-cycles-masked-pending", 0xce, 0x00, true },
655 1.14 msaitoh { "fpu-exceptions", 0xdb, 0x00, true },
656 1.14 msaitoh { "break-match0", 0xdc, 0x00, true },
657 1.14 msaitoh { "break-match1", 0xdd, 0x00, true },
658 1.14 msaitoh { "break-match2", 0xde, 0x00, true },
659 1.14 msaitoh { "break-match3", 0xdf, 0x00, true },
660 1.1 maxv };
661 1.1 maxv
662 1.1 maxv static struct event_table amd_f10h = {
663 1.1 maxv .tablename = "AMD Family 10h",
664 1.1 maxv .names = amd_f10h_names,
665 1.1 maxv .nevents = sizeof(amd_f10h_names) /
666 1.1 maxv sizeof(struct name_to_event),
667 1.1 maxv .next = NULL
668 1.1 maxv };
669 1.1 maxv
670 1.8 maxv /*
671 1.9 jmcneill * AMD Family 15h
672 1.9 jmcneill */
673 1.9 jmcneill static struct name_to_event amd_f15h_names[] = {
674 1.9 jmcneill { "FpPipeAssignment", 0x000, 0x77, true },
675 1.9 jmcneill { "FpSchedulerEmpty", 0x001, 0x00, true },
676 1.9 jmcneill { "FpRetSseAvxOps", 0x003, 0xff, true },
677 1.9 jmcneill { "FpNumMovElim", 0x004, 0x0f, true },
678 1.9 jmcneill { "FpRetiredSerOps", 0x005, 0x0f, true },
679 1.9 jmcneill { "LsSegRegLoads", 0x020, 0x7f, true },
680 1.9 jmcneill { "LsPipeRestartSelfMod", 0x021, 0x00, true },
681 1.9 jmcneill { "LsPipeRestartVarious", 0x022, 0x1f, true },
682 1.9 jmcneill { "LsLoadQueueStoreQFull", 0x023, 0x03, true },
683 1.9 jmcneill { "LsLockedOps", 0x024, 0x00, true },
684 1.9 jmcneill { "LsRetClflushInstr", 0x026, 0x00, true },
685 1.9 jmcneill { "LsRetCpuidInstr", 0x027, 0x00, true },
686 1.9 jmcneill { "LsDispatch", 0x029, 0x07, true },
687 1.9 jmcneill { "LsCanStoreToLoadFwOps", 0x02a, 0x03, true },
688 1.9 jmcneill { "LsSmisReceived", 0x02b, 0x00, true },
689 1.9 jmcneill { "LsExecClflushInstr", 0x030, 0x00, true },
690 1.9 jmcneill { "LsMisalignStore", 0x032, 0x00, true },
691 1.9 jmcneill { "LsFpLoadBufStall", 0x034, 0x00, true },
692 1.9 jmcneill { "LsStlf", 0x035, 0x00, true },
693 1.9 jmcneill { "DcCacheAccess", 0x040, 0x00, true },
694 1.9 jmcneill { "DcCacheMiss", 0x041, 0x00, true },
695 1.9 jmcneill { "DcCacheFillL2Sys", 0x042, 0x1f, true },
696 1.9 jmcneill { "DcCacheFillSys", 0x043, 0x00, true },
697 1.9 jmcneill { "DcUnifiedTlbHit", 0x045, 0x77, true },
698 1.9 jmcneill { "DcUnifiedTlbMiss", 0x046, 0x77, true },
699 1.9 jmcneill { "DcMisalignAccess", 0x047, 0x00, true },
700 1.9 jmcneill { "DcPrefetchInstrDisp", 0x04b, 0x07, true },
701 1.9 jmcneill { "DcIneffSwPrefetch", 0x052, 0x09, true },
702 1.9 jmcneill { "CuCmdVictimBuf", 0x060, 0x98, true },
703 1.9 jmcneill { "CuCmdMaskedOps", 0x061, 0x65, true },
704 1.9 jmcneill { "CuCmdReadBlkOps", 0x062, 0x77, true },
705 1.9 jmcneill { "CuCmdChgDirtyOps", 0x063, 0x08, true },
706 1.9 jmcneill { "CuDramSysReq", 0x064, 0x00, true },
707 1.9 jmcneill { "CuMemReqByType", 0x065, 0x83, true },
708 1.9 jmcneill { "CuDataCachePrefetch", 0x067, 0x03, true },
709 1.9 jmcneill { "CuMabReq", 0x068, 0xff, true },
710 1.9 jmcneill { "CuMabWaitCyc", 0x069, 0xff, true },
711 1.9 jmcneill { "CuSysRespCacheFill", 0x06c, 0x3f, true },
712 1.9 jmcneill { "CuOctwordsWritten", 0x06d, 0x01, true },
713 1.9 jmcneill { "CuCacheXInv", 0x075, 0x0f, true },
714 1.9 jmcneill { "CuCpuClkNotHalted", 0x076, 0x00, true },
715 1.9 jmcneill { "CuL2Req", 0x07d, 0x5f, true },
716 1.9 jmcneill { "CuL2Miss", 0x07e, 0x17, true },
717 1.9 jmcneill { "CuL2FillWb", 0x07f, 0x07, true },
718 1.9 jmcneill { "CuPageSplintering", 0x165, 0x07, true },
719 1.9 jmcneill { "CuL2PrefetchTrigEv", 0x16c, 0x03, true },
720 1.9 jmcneill { "CuXabAllocStall", 0x177, 0x03, true },
721 1.9 jmcneill { "CuFreeXabEntries", 0x17f, 0x01, true },
722 1.9 jmcneill { "IcCacheFetch", 0x080, 0x00, true },
723 1.9 jmcneill { "IcCacheMiss", 0x081, 0x00, true },
724 1.9 jmcneill { "IcCacheFillL2", 0x082, 0x00, true },
725 1.9 jmcneill { "IcCacheFillSys", 0x083, 0x00, true },
726 1.9 jmcneill { "IcL1TlbMissL2Hit", 0x084, 0x00, true },
727 1.9 jmcneill { "IcL1TlbMissL2Miss", 0x085, 0x07, true },
728 1.9 jmcneill { "IcPipeRestartInstrStrProbe", 0x086, 0x00, true },
729 1.9 jmcneill { "IcFetchStall", 0x087, 0x00, true },
730 1.9 jmcneill { "IcRetStackHits", 0x088, 0x00, true },
731 1.9 jmcneill { "IcRetStackOver", 0x089, 0x00, true },
732 1.9 jmcneill { "IcCacheVictims", 0x08b, 0x00, true },
733 1.9 jmcneill { "IcCacheLinesInv", 0x08c, 0x0f, true },
734 1.9 jmcneill { "IcTlbReload", 0x099, 0x00, true },
735 1.9 jmcneill { "IcTlbReloadAbort", 0x09a, 0x00, true },
736 1.9 jmcneill { "IcUopsDispatched", 0x186, 0x01, true },
737 1.9 jmcneill { "ExRetInstr", 0x0c0, 0x00, true },
738 1.9 jmcneill { "ExRetCops", 0x0c1, 0x00, true },
739 1.9 jmcneill { "ExRetBrn", 0x0c2, 0x00, true },
740 1.9 jmcneill { "ExRetBrnMisp", 0x0c3, 0x00, true },
741 1.9 jmcneill { "ExRetBrnTkn", 0x0c4, 0x00, true },
742 1.9 jmcneill { "ExRetBrnTknMisp", 0x0c5, 0x00, true },
743 1.9 jmcneill { "ExRetBrnFar", 0x0c6, 0x00, true },
744 1.9 jmcneill { "ExRetBrnResync", 0x0c7, 0x00, true },
745 1.9 jmcneill { "ExRetNearRet", 0x0c8, 0x00, true },
746 1.9 jmcneill { "ExRetNearRetMispred", 0x0c9, 0x00, true },
747 1.9 jmcneill { "ExRetBrnIndMisp", 0x0ca, 0x00, true },
748 1.9 jmcneill { "ExRetMmxFpInstr@X87", 0x0cb, 0x01, true },
749 1.9 jmcneill { "ExRetMmxFpInstr@Mmx", 0x0cb, 0x02, true },
750 1.9 jmcneill { "ExRetMmxFpInstr@Sse", 0x0cb, 0x04, true },
751 1.9 jmcneill { "ExIntMaskedCyc", 0x0cd, 0x00, true },
752 1.9 jmcneill { "ExIntMaskedCycIntPend", 0x0ce, 0x00, true },
753 1.9 jmcneill { "ExIntTaken", 0x0cf, 0x00, true },
754 1.9 jmcneill { "ExDecEmpty", 0x0d0, 0x00, true },
755 1.9 jmcneill { "ExDispStall", 0x0d1, 0x00, true },
756 1.9 jmcneill { "ExUseqStallSer", 0x0d2, 0x00, true },
757 1.9 jmcneill { "ExDispStallInstrRetQFull", 0x0d5, 0x00, true },
758 1.9 jmcneill { "ExDispStallIntSchedQFull", 0x0d6, 0x00, true },
759 1.9 jmcneill { "ExDispStallFpSchedQFull", 0x0d7, 0x00, true },
760 1.9 jmcneill { "ExDispStallLdqFull", 0x0d8, 0x00, true },
761 1.9 jmcneill { "ExUseqStallAllQuiet", 0x0d9, 0x00, true },
762 1.9 jmcneill { "ExFpuEx", 0x0db, 0x1f, true },
763 1.9 jmcneill { "ExBpDr0", 0x0dc, 0x8f, true },
764 1.9 jmcneill { "ExBpDr1", 0x0dd, 0x8f, true },
765 1.9 jmcneill { "ExBpDr2", 0x0de, 0x8f, true },
766 1.9 jmcneill { "ExBpDr3", 0x0df, 0x8f, true },
767 1.9 jmcneill { "ExRetx87FpOps", 0x1c0, 0x07, true },
768 1.9 jmcneill { "ExTaggedIbsOps", 0x1cf, 0x07, true },
769 1.9 jmcneill { "ExRetFusBrInstr", 0x1d0, 0x00, true },
770 1.9 jmcneill { "ExDispStallStqFull", 0x1d8, 0x00, true },
771 1.9 jmcneill { "ExCycNoDispIntPrfTok", 0x1dd, 0x00, true },
772 1.9 jmcneill { "ExCycNoDispfpPrfTok", 0x1de, 0x00, true },
773 1.9 jmcneill { "ExFpDispContention", 0x1df, 0x0f, true },
774 1.9 jmcneill };
775 1.9 jmcneill
776 1.9 jmcneill static struct event_table amd_f15h = {
777 1.9 jmcneill .tablename = "AMD Family 15h",
778 1.9 jmcneill .names = amd_f15h_names,
779 1.9 jmcneill .nevents = sizeof(amd_f15h_names) /
780 1.9 jmcneill sizeof(struct name_to_event),
781 1.9 jmcneill .next = NULL
782 1.9 jmcneill };
783 1.9 jmcneill
784 1.9 jmcneill /*
785 1.8 maxv * AMD Family 17h
786 1.8 maxv */
787 1.8 maxv static struct name_to_event amd_f17h_names[] = {
788 1.8 maxv { "FpRetx87FpOps", 0x02, __BITS(2,0), true },
789 1.8 maxv { "FpRetSseAvxOps", 0x03, __BITS(7,0), true },
790 1.8 maxv { "FpRetiredSerOps", 0x05, __BITS(3,0), true },
791 1.8 maxv { "LsL1DTlbMiss", 0x45, __BITS(7,0), true },
792 1.8 maxv { "LsTableWalker", 0x46, __BITS(3,0), true },
793 1.8 maxv { "LsMisalAccesses", 0x47, 0x00, true },
794 1.8 maxv { "LsInefSwPref", 0x52, __BITS(1,0), true },
795 1.8 maxv { "LsNotHaltedCyc", 0x76, 0x00, true },
796 1.8 maxv { "IcFw32", 0x80, 0x00, true },
797 1.8 maxv { "IcFw32Miss", 0x81, 0x00, true },
798 1.8 maxv { "IcCacheFillL2", 0x82, 0x00, true },
799 1.8 maxv { "IcCacheFillSys", 0x83, 0x00, true },
800 1.8 maxv { "IcFetchStall", 0x87, __BITS(2,0), true },
801 1.14 msaitoh { "IcCacheInval", 0x8c, __BITS(1,0), true },
802 1.8 maxv { "BpL1TlbMissL2Hit", 0x84, 0x00, true },
803 1.8 maxv { "BpL1TlbMissL2Miss", 0x85, 0x00, true },
804 1.8 maxv { "BpSnpReSync", 0x86, 0x00, true },
805 1.14 msaitoh { "BpL1BTBCorrect", 0x8a, 0x00, true },
806 1.14 msaitoh { "BpL2BTBCorrect", 0x8b, 0x00, true },
807 1.8 maxv { "BpTlbRel", 0x99, 0x00, true },
808 1.14 msaitoh { "ExRetInstr", 0xc0, 0x00, true },
809 1.14 msaitoh { "ExRetCops", 0xc1, 0x00, true },
810 1.14 msaitoh { "ExRetBrn", 0xc2, 0x00, true },
811 1.14 msaitoh { "ExRetBrnMisp", 0xc3, 0x00, true },
812 1.14 msaitoh { "ExRetBrnTkn", 0xc4, 0x00, true },
813 1.14 msaitoh { "ExRetBrnTknMisp", 0xc5, 0x00, true },
814 1.14 msaitoh { "ExRetBrnFar", 0xc6, 0x00, true },
815 1.14 msaitoh { "ExRetBrnResync", 0xc7, 0x00, true },
816 1.14 msaitoh { "ExRetBrnIndMisp", 0xca, 0x00, true },
817 1.14 msaitoh { "ExRetNearRet", 0xc8, 0x00, true },
818 1.14 msaitoh { "ExRetNearRetMispred", 0xc9, 0x00, true },
819 1.14 msaitoh { "ExRetMmxFpInstr@X87", 0xcb, __BIT(0), true },
820 1.14 msaitoh { "ExRetMmxFpInstr@Mmx", 0xcb, __BIT(1), true },
821 1.14 msaitoh { "ExRetMmxFpInstr@Sse", 0xcb, __BIT(2), true },
822 1.14 msaitoh { "ExRetCond", 0xd1, 0x00, true },
823 1.14 msaitoh { "ExRetCondMisp", 0xd2, 0x00, true },
824 1.14 msaitoh { "ExDivBusy", 0xd3, 0x00, true },
825 1.14 msaitoh { "ExDivCount", 0xd4, 0x00, true },
826 1.8 maxv };
827 1.8 maxv
828 1.8 maxv static struct event_table amd_f17h = {
829 1.8 maxv .tablename = "AMD Family 17h",
830 1.8 maxv .names = amd_f17h_names,
831 1.8 maxv .nevents = sizeof(amd_f17h_names) /
832 1.8 maxv sizeof(struct name_to_event),
833 1.8 maxv .next = NULL
834 1.8 maxv };
835 1.1 maxv
836 1.15 msaitoh /*
837 1.15 msaitoh * AMD Family 19h
838 1.15 msaitoh * From PPR:
839 1.15 msaitoh * - f19h model 01h B1 (zen3)
840 1.15 msaitoh * - f19h model 11h B1 (zen4)
841 1.15 msaitoh * - f19h model 21h B1 (zen3)
842 1.15 msaitoh * - f19h model 51h A1 (zen3)
843 1.15 msaitoh */
844 1.15 msaitoh static struct name_to_event amd_f19h_names[] = {
845 1.15 msaitoh /* Model 1x only */
846 1.15 msaitoh { "FpRetx87FpOps", 0x02, __BITS(2,0), true },
847 1.15 msaitoh
848 1.15 msaitoh /* Only model 1x has bit 4 */
849 1.15 msaitoh { "FpRetSseAvxOps", 0x03, __BITS(4,0), true },
850 1.15 msaitoh
851 1.15 msaitoh { "FpRetiredSerOps", 0x05, __BITS(3,0), true },
852 1.15 msaitoh
853 1.15 msaitoh /* Model 1x only */
854 1.15 msaitoh { "FpOpsRetiredByWidth", 0x08, __BITS(5,0), true },
855 1.15 msaitoh { "FpOpsRetiredByType", 0x0a, __BITS(7,0), true },
856 1.15 msaitoh { "SseAvxOpsRetired", 0x0b, __BITS(7,0), true },
857 1.15 msaitoh { "FpPackOpsRetired", 0x0c, __BITS(7,0), true },
858 1.15 msaitoh { "PackedIntOpType", 0x0d, __BITS(7,0), true },
859 1.15 msaitoh
860 1.15 msaitoh { "FpDispFaults", 0x0e, __BITS(3,0), true },
861 1.15 msaitoh { "LsBadStatus2", 0x24, __BIT(1), true },
862 1.15 msaitoh { "LsLocks", 0x25, __BIT(0), true },
863 1.15 msaitoh { "LsRetClClush", 0x26, 0x00, true },
864 1.15 msaitoh { "LsRetCpuid", 0x27, 0x00, true },
865 1.15 msaitoh { "LsDispatch", 0x29, __BITS(2,0), true },
866 1.15 msaitoh { "LsSmiRx", 0x2b, 0x00, true },
867 1.15 msaitoh { "LsIntTaken", 0x2c, 0x00, true },
868 1.15 msaitoh { "LsSTLF", 0x35, 0x00, true },
869 1.15 msaitoh { "LsStCommitCancel2", 0x37, __BIT(0), true },
870 1.15 msaitoh { "LsMabAlloc-ls", 0x41, 0x3f, true },
871 1.15 msaitoh { "LsMabAlloc-hp", 0x41, 0x40, true },
872 1.15 msaitoh { "LsMabAlloc-all", 0x41, 0x7f, true },
873 1.15 msaitoh { "LsDmndFillsFromSys", 0x43, 0x5f, true },
874 1.15 msaitoh
875 1.15 msaitoh /* Only model 1x has bit 7 */
876 1.15 msaitoh { "LsAnyFillsFromSys", 0x44, 0xdf, true },
877 1.15 msaitoh
878 1.15 msaitoh { "LsL1DTlbMiss", 0x45, __BITS(7,0), true },
879 1.15 msaitoh { "LsMisalLoads-MA64", 0x47, __BIT(0), true },
880 1.15 msaitoh { "LsMisalLoads-MA4K", 0x47, __BIT(1), true },
881 1.15 msaitoh { "LsMisalLoads-all", 0x47, __BITS(1,0), true },
882 1.15 msaitoh { "LsPrefInstrDisp", 0x4b, __BITS(2,0), true },
883 1.15 msaitoh { "LsInefSwPref", 0x52, __BITS(1,0), true },
884 1.15 msaitoh
885 1.15 msaitoh /* Only model 1x has bit 7 */
886 1.15 msaitoh { "LsSwPfDcFills", 0x59, 0xdf, true },
887 1.15 msaitoh { "LsHwPfDcFills", 0x5a, 0xdf, true },
888 1.15 msaitoh
889 1.15 msaitoh { "LsAllocMabCount", 0x5f, 0x00, true },
890 1.15 msaitoh { "LsNotHaltedCyc", 0x76, 0x00, true },
891 1.15 msaitoh
892 1.15 msaitoh /* Model 0x, 1x and 2x only */
893 1.15 msaitoh { "LsTlbFlush", 0x78, 0xff, true },
894 1.15 msaitoh
895 1.15 msaitoh /* Model 1x only */
896 1.15 msaitoh { "LsNotHaltedP0Cyc", 0x120, __BIT(0), true },
897 1.15 msaitoh
898 1.15 msaitoh { "IcCacheFillL2", 0x82, 0x00, true },
899 1.15 msaitoh { "IcCacheFillSys", 0x83, 0x00, true },
900 1.15 msaitoh { "BpL1TlbMissL2TlbHit", 0x84, 0x00, true },
901 1.15 msaitoh { "BpL1TlbMissL2TlbMiss-IF4K", 0x85, __BIT(0), true },
902 1.15 msaitoh { "BpL1TlbMissL2TlbMiss-IF2M", 0x85, __BIT(1), true },
903 1.15 msaitoh { "BpL1TlbMissL2TlbMiss-IF1G", 0x85, __BIT(2), true },
904 1.15 msaitoh { "BpL1TlbMissL2TlbMiss-Coalesced4K", 0x85, __BIT(3), true },
905 1.15 msaitoh { "BpL1TlbMissL2TlbMiss-all", 0x85, __BITS(3,0), true },
906 1.15 msaitoh
907 1.15 msaitoh { "BpL2BTBCorrect", 0x8b, 0x00, true },
908 1.15 msaitoh { "BpDynIndPred", 0x8e, 0x00, true },
909 1.15 msaitoh { "BpDeReDirect", 0x91, 0x00, true },
910 1.15 msaitoh { "BpL1TlbFetchHit-IF4K", 0x94, __BIT(0), true },
911 1.15 msaitoh { "BpL1TlbFetchHit-IF2M", 0x94, __BIT(1), true },
912 1.15 msaitoh { "BpL1TlbFetchHit-IF1G", 0x94, __BIT(2), true },
913 1.15 msaitoh { "BpL1TlbFetchHit-all", 0x94, __BITS(2,0), true },
914 1.15 msaitoh
915 1.15 msaitoh /* Model 1x only */
916 1.15 msaitoh { "ResyncsOrNcRedirects", 0x96, 0x00, true },
917 1.15 msaitoh
918 1.15 msaitoh { "IcTagHitMiss-hit", 0x18e, 0x07, true },
919 1.15 msaitoh { "IcTagHitMiss-miss", 0x18e, 0x18, true },
920 1.15 msaitoh { "IcTagHitMiss-all", 0x18e, 0x1f, true },
921 1.15 msaitoh { "OpCacheHitMiss-hit", 0x28f, 0x03, true },
922 1.15 msaitoh { "OpCacheHitMiss-miss", 0x28f, 0x04, true },
923 1.15 msaitoh { "OpCacheHitMiss-all", 0x28f, 0x07, true },
924 1.15 msaitoh { "DeOpQueueEmpty", 0xa9, 0x00, true },
925 1.15 msaitoh
926 1.15 msaitoh /*
927 1.15 msaitoh * Model 0x and 1x only.
928 1.15 msaitoh * Only model 1x has bit 2.
929 1.15 msaitoh */
930 1.15 msaitoh { "DeSrcOpDisp", 0xaa, __BITS(2,0), true },
931 1.15 msaitoh
932 1.15 msaitoh { "DeDisOpsFromDecoder-Fp-Ibs", 0xab, 0x04, true },
933 1.15 msaitoh { "DeDisOpsFromDecoder-Int-Ibs", 0xab, 0x08, true },
934 1.15 msaitoh
935 1.15 msaitoh /* Model 0x, 2x and newer */
936 1.15 msaitoh { "DeDisOpsFromDecoder-Fp-Ret", 0xab, 0x84, true },
937 1.15 msaitoh { "DeDisOpsFromDecoder-Int-Ret", 0xab, 0x88, true },
938 1.15 msaitoh
939 1.15 msaitoh { "DeDisDispatchTokenStalls1", 0xae, 0xf7, true },
940 1.15 msaitoh { "DeDisDispatchTokenStalls2", 0xaf, 0x2f, true },
941 1.15 msaitoh
942 1.15 msaitoh /* Model 1x only */
943 1.15 msaitoh { "DeNoDispatchPerSolt-empty", 0x1a0, 0x01, true },
944 1.15 msaitoh { "DeNoDispatchPerSolt-backend", 0x1a0, 0x1e, true },
945 1.15 msaitoh { "DeNoDispatchPerSolt-otherSMT", 0x1a0, 0x60, true },
946 1.15 msaitoh { "DeAdditionalResourceStalls", 0x1a2, 0x30, true },
947 1.15 msaitoh
948 1.15 msaitoh { "ExRetInstr", 0xc0, 0x00, true },
949 1.15 msaitoh { "ExRetCops", 0xc1, 0x00, true },
950 1.15 msaitoh { "ExRetBrn", 0xc2, 0x00, true },
951 1.15 msaitoh { "ExRetBrnMisp", 0xc3, 0x00, true },
952 1.15 msaitoh { "ExRetBrnTkn", 0xc4, 0x00, true },
953 1.15 msaitoh { "ExRetBrnTknMisp", 0xc5, 0x00, true },
954 1.15 msaitoh { "ExRetBrnFar", 0xc6, 0x00, true },
955 1.15 msaitoh { "ExRetBrnIndMisp", 0xca, 0x00, true },
956 1.15 msaitoh { "ExRetNearRet", 0xc8, 0x00, true },
957 1.15 msaitoh { "ExRetNearRetMispred", 0xc9, 0x00, true },
958 1.15 msaitoh { "ExRetMmxFpInstr@X87", 0xcb, __BIT(0), true },
959 1.15 msaitoh { "ExRetMmxFpInstr@Mmx", 0xcb, __BIT(1), true },
960 1.15 msaitoh { "ExRetMmxFpInstr@Sse", 0xcb, __BIT(2), true },
961 1.15 msaitoh { "ExRetIndBrchInstr", 0xcc, 0x00, true },
962 1.15 msaitoh { "ExRetCond", 0xd1, 0x00, true },
963 1.15 msaitoh { "ExDivBusy", 0xd3, 0x00, true },
964 1.15 msaitoh { "ExDivCount", 0xd4, 0x00, true },
965 1.15 msaitoh
966 1.15 msaitoh /* Model 1x only */
967 1.15 msaitoh { "ExDivCount-LoadAndALU", 0xd6, 0x1f, true },
968 1.15 msaitoh { "ExDivCount-Load", 0xd6, 0xbf, true },
969 1.15 msaitoh { "ExRetUcodeInstr", 0x1c1, 0x00, true },
970 1.15 msaitoh { "ExRetUcodeOps", 0x1c2, 0x00, true },
971 1.15 msaitoh
972 1.15 msaitoh { "ExRetMsprdBrnchInstrDirMsmtch", 0x1c7, 0x00, true },
973 1.15 msaitoh
974 1.15 msaitoh /* Model 1x only */
975 1.15 msaitoh { "ExRetUncondBrnchInstrMspred", 0x1c8, 0x00, true },
976 1.15 msaitoh { "ExRetUncondBrnchInstr", 0x1c8, 0x00, true },
977 1.15 msaitoh
978 1.15 msaitoh { "ExTaggedIbsOps", 0x1cf, __BITS(2,0), true },
979 1.15 msaitoh { "ExRetFusedInstr", 0x1d0, 0x00, true },
980 1.15 msaitoh
981 1.15 msaitoh /* Only model 1x has bit 0 */
982 1.15 msaitoh { "L2RequestG1", 0x60, __BITS(7,1), true },
983 1.15 msaitoh
984 1.15 msaitoh { "L2CacheReqStart", 0x64, __BITS(7,0), true },
985 1.15 msaitoh { "L2PfHitL2-L2", 0x70, __BITS(4,0), true },
986 1.15 msaitoh { "L2PfHitL2-L1", 0x70, __BITS(7,5), true },
987 1.15 msaitoh { "L2PfHitL2-all", 0x70, __BITS(7,0), true },
988 1.15 msaitoh { "L2PfMissL2HitL3-L2", 0x71, __BITS(4,0), true },
989 1.15 msaitoh { "L2PfMissL2HitL3-L1", 0x71, __BITS(7,5), true },
990 1.15 msaitoh { "L2PfMIssL2HitL3-all", 0x71, __BITS(7,0), true },
991 1.15 msaitoh { "L2PfMissL2L3-L2", 0x72, __BITS(4,0), true },
992 1.15 msaitoh { "L2PfMissL2L3-L1", 0x72, __BITS(7,5), true },
993 1.15 msaitoh { "L2PfMIssL2L3-all", 0x72, __BITS(7,0), true },
994 1.15 msaitoh
995 1.15 msaitoh { "L3LookupState-L3Miss", 0x04, __BIT(0), true },
996 1.15 msaitoh { "L3LookupState-L3Hit", 0x04, __BITS(7,1), true },
997 1.15 msaitoh { "L3LookupState-all", 0x04, __BITS(7,0), true },
998 1.15 msaitoh
999 1.15 msaitoh /* Model 0x, 2x and newer */
1000 1.15 msaitoh { "XiSysFillLatency", 0x90, 0x00, true },
1001 1.15 msaitoh { "XiCcxSdpReq1", 0x9a, 0x00, true },
1002 1.15 msaitoh
1003 1.15 msaitoh /* Model 1x only */
1004 1.15 msaitoh { "XiSampledLatency", 0xac, 0x00, true },
1005 1.15 msaitoh { "XiSampledLatencyRequests", 0xad, 0x00, true },
1006 1.15 msaitoh };
1007 1.15 msaitoh
1008 1.15 msaitoh static struct event_table amd_f19h = {
1009 1.15 msaitoh .tablename = "AMD Family 19h",
1010 1.15 msaitoh .names = amd_f19h_names,
1011 1.15 msaitoh .nevents = sizeof(amd_f19h_names) /
1012 1.15 msaitoh sizeof(struct name_to_event),
1013 1.15 msaitoh .next = NULL
1014 1.15 msaitoh };
1015 1.15 msaitoh
1016 1.1 maxv static struct event_table *
1017 1.1 maxv init_amd_generic(void)
1018 1.1 maxv {
1019 1.1 maxv unsigned int eax, ebx, ecx, edx;
1020 1.1 maxv
1021 1.1 maxv eax = 0x01;
1022 1.1 maxv ebx = 0;
1023 1.1 maxv ecx = 0;
1024 1.1 maxv edx = 0;
1025 1.1 maxv x86_cpuid(&eax, &ebx, &ecx, &edx);
1026 1.1 maxv
1027 1.1 maxv switch (CPUID_TO_FAMILY(eax)) {
1028 1.1 maxv case 0x10:
1029 1.8 maxv return &amd_f10h;
1030 1.9 jmcneill case 0x15:
1031 1.9 jmcneill return &amd_f15h;
1032 1.8 maxv case 0x17:
1033 1.8 maxv return &amd_f17h;
1034 1.15 msaitoh case 0x19:
1035 1.15 msaitoh return &amd_f19h;
1036 1.1 maxv }
1037 1.1 maxv
1038 1.1 maxv return NULL;
1039 1.1 maxv }
1040 1.1 maxv
1041 1.13 msaitoh /* ------------------------------------------------------------------------- */
1042 1.1 maxv
1043 1.1 maxv int
1044 1.1 maxv tprof_event_init(uint32_t ident)
1045 1.1 maxv {
1046 1.13 msaitoh
1047 1.1 maxv switch (ident) {
1048 1.1 maxv case TPROF_IDENT_NONE:
1049 1.1 maxv return -1;
1050 1.1 maxv case TPROF_IDENT_INTEL_GENERIC:
1051 1.1 maxv cpuevents = init_intel_generic();
1052 1.1 maxv break;
1053 1.1 maxv case TPROF_IDENT_AMD_GENERIC:
1054 1.1 maxv cpuevents = init_amd_generic();
1055 1.1 maxv break;
1056 1.1 maxv }
1057 1.1 maxv return (cpuevents == NULL) ? -1 : 0;
1058 1.1 maxv }
1059 1.1 maxv
1060 1.1 maxv static void
1061 1.1 maxv recursive_event_list(struct event_table *table)
1062 1.1 maxv {
1063 1.1 maxv size_t i;
1064 1.1 maxv
1065 1.1 maxv printf("%s:\n", table->tablename);
1066 1.1 maxv for (i = 0; i < table->nevents; i++) {
1067 1.1 maxv if (!table->names[i].enabled)
1068 1.1 maxv continue;
1069 1.1 maxv printf("\t%s\n", table->names[i].name);
1070 1.1 maxv }
1071 1.1 maxv
1072 1.13 msaitoh if (table->next != NULL)
1073 1.1 maxv recursive_event_list(table->next);
1074 1.1 maxv }
1075 1.1 maxv
1076 1.1 maxv void
1077 1.1 maxv tprof_event_list(void)
1078 1.1 maxv {
1079 1.13 msaitoh
1080 1.1 maxv recursive_event_list(cpuevents);
1081 1.1 maxv }
1082 1.1 maxv
1083 1.1 maxv static void
1084 1.1 maxv recursive_event_lookup(struct event_table *table, const char *name,
1085 1.1 maxv struct tprof_param *param)
1086 1.1 maxv {
1087 1.1 maxv size_t i;
1088 1.1 maxv
1089 1.1 maxv for (i = 0; i < table->nevents; i++) {
1090 1.1 maxv if (!table->names[i].enabled)
1091 1.1 maxv continue;
1092 1.1 maxv if (!strcmp(table->names[i].name, name)) {
1093 1.1 maxv param->p_event = table->names[i].event;
1094 1.1 maxv param->p_unit = table->names[i].unit;
1095 1.1 maxv return;
1096 1.1 maxv }
1097 1.1 maxv }
1098 1.1 maxv
1099 1.13 msaitoh if (table->next != NULL)
1100 1.1 maxv recursive_event_lookup(table->next, name, param);
1101 1.13 msaitoh else
1102 1.1 maxv errx(EXIT_FAILURE, "event '%s' unknown", name);
1103 1.1 maxv }
1104 1.1 maxv
1105 1.1 maxv void
1106 1.1 maxv tprof_event_lookup(const char *name, struct tprof_param *param)
1107 1.1 maxv {
1108 1.13 msaitoh
1109 1.1 maxv recursive_event_lookup(cpuevents, name, param);
1110 1.1 maxv }
1111