tprof_x86.c revision 1.4.2.3 1 1.4.2.3 pgoyette /* $NetBSD: tprof_x86.c,v 1.4.2.3 2018/11/26 01:52:59 pgoyette Exp $ */
2 1.4.2.2 pgoyette
3 1.4.2.2 pgoyette /*
4 1.4.2.2 pgoyette * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 1.4.2.2 pgoyette * All rights reserved.
6 1.4.2.2 pgoyette *
7 1.4.2.2 pgoyette * This code is derived from software contributed to The NetBSD Foundation
8 1.4.2.2 pgoyette * by Maxime Villard.
9 1.4.2.2 pgoyette *
10 1.4.2.2 pgoyette * Redistribution and use in source and binary forms, with or without
11 1.4.2.2 pgoyette * modification, are permitted provided that the following conditions
12 1.4.2.2 pgoyette * are met:
13 1.4.2.2 pgoyette * 1. Redistributions of source code must retain the above copyright
14 1.4.2.2 pgoyette * notice, this list of conditions and the following disclaimer.
15 1.4.2.2 pgoyette * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.2.2 pgoyette * notice, this list of conditions and the following disclaimer in the
17 1.4.2.2 pgoyette * documentation and/or other materials provided with the distribution.
18 1.4.2.2 pgoyette *
19 1.4.2.2 pgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.4.2.2 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.4.2.2 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.4.2.2 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.4.2.2 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.4.2.2 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.4.2.2 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.4.2.2 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.4.2.2 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.4.2.2 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.4.2.2 pgoyette * POSSIBILITY OF SUCH DAMAGE.
30 1.4.2.2 pgoyette */
31 1.4.2.2 pgoyette
32 1.4.2.2 pgoyette #include <sys/cdefs.h>
33 1.4.2.2 pgoyette #include <stdio.h>
34 1.4.2.2 pgoyette #include <stdlib.h>
35 1.4.2.2 pgoyette #include <stdbool.h>
36 1.4.2.2 pgoyette #include <string.h>
37 1.4.2.2 pgoyette #include <unistd.h>
38 1.4.2.2 pgoyette #include <err.h>
39 1.4.2.2 pgoyette #include <machine/specialreg.h>
40 1.4.2.2 pgoyette #include <dev/tprof/tprof_ioctl.h>
41 1.4.2.2 pgoyette #include "../tprof.h"
42 1.4.2.2 pgoyette
43 1.4.2.2 pgoyette int tprof_event_init(uint32_t);
44 1.4.2.2 pgoyette void tprof_event_list(void);
45 1.4.2.2 pgoyette void tprof_event_lookup(const char *, struct tprof_param *);
46 1.4.2.2 pgoyette
47 1.4.2.2 pgoyette struct name_to_event {
48 1.4.2.2 pgoyette const char *name;
49 1.4.2.2 pgoyette uint64_t event;
50 1.4.2.2 pgoyette uint64_t unit;
51 1.4.2.2 pgoyette bool enabled;
52 1.4.2.2 pgoyette };
53 1.4.2.2 pgoyette
54 1.4.2.2 pgoyette struct event_table {
55 1.4.2.2 pgoyette const char *tablename;
56 1.4.2.2 pgoyette struct name_to_event *names;
57 1.4.2.2 pgoyette size_t nevents;
58 1.4.2.2 pgoyette struct event_table *next;
59 1.4.2.2 pgoyette };
60 1.4.2.2 pgoyette
61 1.4.2.2 pgoyette static struct event_table *cpuevents = NULL;
62 1.4.2.2 pgoyette
63 1.4.2.2 pgoyette static void x86_cpuid(unsigned int *eax, unsigned int *ebx,
64 1.4.2.2 pgoyette unsigned int *ecx, unsigned int *edx)
65 1.4.2.2 pgoyette {
66 1.4.2.2 pgoyette asm volatile("cpuid"
67 1.4.2.2 pgoyette : "=a" (*eax),
68 1.4.2.2 pgoyette "=b" (*ebx),
69 1.4.2.2 pgoyette "=c" (*ecx),
70 1.4.2.2 pgoyette "=d" (*edx)
71 1.4.2.2 pgoyette : "0" (*eax), "2" (*ecx));
72 1.4.2.2 pgoyette }
73 1.4.2.2 pgoyette
74 1.4.2.2 pgoyette /* -------------------------------------------------------------------------- */
75 1.4.2.2 pgoyette
76 1.4.2.2 pgoyette /*
77 1.4.2.2 pgoyette * Intel Architectural Version 1.
78 1.4.2.2 pgoyette */
79 1.4.2.2 pgoyette static struct name_to_event intel_arch1_names[] = {
80 1.4.2.2 pgoyette /* Event Name - Event Select - UMask */
81 1.4.2.2 pgoyette { "unhalted-core-cycles", 0x3C, 0x00, true },
82 1.4.2.2 pgoyette { "instruction-retired", 0xC0, 0x00, true },
83 1.4.2.2 pgoyette { "unhalted-reference-cycles", 0x3C, 0x01, true },
84 1.4.2.2 pgoyette { "llc-reference", 0x2E, 0x4F, true },
85 1.4.2.2 pgoyette { "llc-misses", 0x2E, 0x41, true },
86 1.4.2.2 pgoyette { "branch-instruction-retired", 0xC4, 0x00, true },
87 1.4.2.2 pgoyette { "branch-misses-retired", 0xC5, 0x00, true },
88 1.4.2.2 pgoyette };
89 1.4.2.2 pgoyette
90 1.4.2.2 pgoyette static struct event_table intel_arch1 = {
91 1.4.2.2 pgoyette .tablename = "Intel Architectural Version 1",
92 1.4.2.2 pgoyette .names = intel_arch1_names,
93 1.4.2.2 pgoyette .nevents = sizeof(intel_arch1_names) /
94 1.4.2.2 pgoyette sizeof(struct name_to_event),
95 1.4.2.2 pgoyette .next = NULL
96 1.4.2.2 pgoyette };
97 1.4.2.2 pgoyette
98 1.4.2.2 pgoyette static struct event_table *
99 1.4.2.2 pgoyette init_intel_arch1(void)
100 1.4.2.2 pgoyette {
101 1.4.2.2 pgoyette unsigned int eax, ebx, ecx, edx;
102 1.4.2.2 pgoyette struct event_table *table;
103 1.4.2.2 pgoyette size_t i;
104 1.4.2.2 pgoyette
105 1.4.2.2 pgoyette eax = 0x0A;
106 1.4.2.2 pgoyette ebx = 0;
107 1.4.2.2 pgoyette ecx = 0;
108 1.4.2.2 pgoyette edx = 0;
109 1.4.2.2 pgoyette x86_cpuid(&eax, &ebx, &ecx, &edx);
110 1.4.2.2 pgoyette
111 1.4.2.2 pgoyette table = &intel_arch1;
112 1.4.2.2 pgoyette for (i = 0; i < table->nevents; i++) {
113 1.4.2.2 pgoyette /* Disable the unsupported events. */
114 1.4.2.2 pgoyette if ((ebx & (i << 1)) != 0)
115 1.4.2.2 pgoyette table->names[i].enabled = false;
116 1.4.2.2 pgoyette }
117 1.4.2.2 pgoyette
118 1.4.2.2 pgoyette return table;
119 1.4.2.2 pgoyette }
120 1.4.2.2 pgoyette
121 1.4.2.2 pgoyette /*
122 1.4.2.3 pgoyette * Intel Silvermont/Airmont.
123 1.4.2.3 pgoyette */
124 1.4.2.3 pgoyette static struct name_to_event intel_silvermont_airmont_names[] = {
125 1.4.2.3 pgoyette { "REHABQ.LD_BLOCK_ST_FORWARD", 0x03, 0x01, true },
126 1.4.2.3 pgoyette { "REHABQ.LD_BLOCK_STD_NOTREADY", 0x03, 0x02, true },
127 1.4.2.3 pgoyette { "REHABQ.ST_SPLITS", 0x03, 0x04, true },
128 1.4.2.3 pgoyette { "REHABQ.LD_SPLITS", 0x03, 0x08, true },
129 1.4.2.3 pgoyette { "REHABQ.LOCK", 0x03, 0x10, true },
130 1.4.2.3 pgoyette { "REHABQ.STA_FULL", 0x03, 0x20, true },
131 1.4.2.3 pgoyette { "REHABQ.ANY_LD", 0x03, 0x40, true },
132 1.4.2.3 pgoyette { "REHABQ.ANY_ST", 0x03, 0x80, true },
133 1.4.2.3 pgoyette { "MEM_UOPS_RETIRED.L1_MISS_LOADS", 0x04, 0x01, true },
134 1.4.2.3 pgoyette { "MEM_UOPS_RETIRED.L2_HIT_LOADS", 0x04, 0x02, true },
135 1.4.2.3 pgoyette { "MEM_UOPS_RETIRED.L2_MISS_LOADS", 0x04, 0x04, true },
136 1.4.2.3 pgoyette { "MEM_UOPS_RETIRED.DTLB_MISS_LOADS", 0x04, 0x08, true },
137 1.4.2.3 pgoyette { "MEM_UOPS_RETIRED.UTLB_MISS", 0x04, 0x10, true },
138 1.4.2.3 pgoyette { "MEM_UOPS_RETIRED.HITM", 0x04, 0x20, true },
139 1.4.2.3 pgoyette { "MEM_UOPS_RETIRED.ALL_LOADS", 0x04, 0x40, true },
140 1.4.2.3 pgoyette { "MEM_UOP_RETIRED.ALL_STORES", 0x04, 0x80, true },
141 1.4.2.3 pgoyette { "PAGE_WALKS.D_SIDE_CYCLES", 0x05, 0x01, true },
142 1.4.2.3 pgoyette { "PAGE_WALKS.I_SIDE_CYCLES", 0x05, 0x02, true },
143 1.4.2.3 pgoyette { "PAGE_WALKS.WALKS", 0x05, 0x03, true },
144 1.4.2.3 pgoyette { "LONGEST_LAT_CACHE.MISS", 0x2E, 0x41, true },
145 1.4.2.3 pgoyette { "LONGEST_LAT_CACHE.REFERENCE", 0x2E, 0x4F, true },
146 1.4.2.3 pgoyette { "L2_REJECT_XQ.ALL", 0x30, 0x00, true },
147 1.4.2.3 pgoyette { "CORE_REJECT_L2Q.ALL", 0x31, 0x00, true },
148 1.4.2.3 pgoyette { "CPU_CLK_UNHALTED.CORE_P", 0x3C, 0x00, true },
149 1.4.2.3 pgoyette { "CPU_CLK_UNHALTED.REF_P", 0x3C, 0x01, true },
150 1.4.2.3 pgoyette { "ICACHE.HIT", 0x80, 0x01, true },
151 1.4.2.3 pgoyette { "ICACHE.MISSES", 0x80, 0x02, true },
152 1.4.2.3 pgoyette { "ICACHE.ACCESSES", 0x80, 0x03, true },
153 1.4.2.3 pgoyette { "OFFCORE_RESPONSE_0", 0xB7, 0x01, true },
154 1.4.2.3 pgoyette { "OFFCORE_RESPONSE_1", 0xB7, 0x02, true },
155 1.4.2.3 pgoyette { "INST_RETIRED.ANY_P", 0xC0, 0x00, true },
156 1.4.2.3 pgoyette { "UOPS_RETIRED.MS", 0xC2, 0x01, true },
157 1.4.2.3 pgoyette { "UOPS_RETIRED.ALL", 0xC2, 0x10, true },
158 1.4.2.3 pgoyette { "MACHINE_CLEARS.SMC", 0xC3, 0x01, true },
159 1.4.2.3 pgoyette { "MACHINE_CLEARS.MEMORY_ORDERING", 0xC3, 0x02, true },
160 1.4.2.3 pgoyette { "MACHINE_CLEARS.FP_ASSIST", 0xC3, 0x04, true },
161 1.4.2.3 pgoyette { "MACHINE_CLEARS.ALL", 0xC3, 0x08, true },
162 1.4.2.3 pgoyette { "BR_INST_RETIRED.ALL_BRANCHES", 0xC4, 0x00, true },
163 1.4.2.3 pgoyette { "BR_INST_RETIRED.JCC", 0xC4, 0x7E, true },
164 1.4.2.3 pgoyette { "BR_INST_RETIRED.FAR_BRANCH", 0xC4, 0xBF, true },
165 1.4.2.3 pgoyette { "BR_INST_RETIRED.NON_RETURN_IND", 0xC4, 0xEB, true },
166 1.4.2.3 pgoyette { "BR_INST_RETIRED.RETURN", 0xC4, 0xF7, true },
167 1.4.2.3 pgoyette { "BR_INST_RETIRED.CALL", 0xC4, 0xF9, true },
168 1.4.2.3 pgoyette { "BR_INST_RETIRED.IND_CALL", 0xC4, 0xFB, true },
169 1.4.2.3 pgoyette { "BR_INST_RETIRED.REL_CALL", 0xC4, 0xFD, true },
170 1.4.2.3 pgoyette { "BR_INST_RETIRED.TAKEN_JCC", 0xC4, 0xFE, true },
171 1.4.2.3 pgoyette { "BR_MISP_RETIRED.ALL_BRANCHES", 0xC5, 0x00, true },
172 1.4.2.3 pgoyette { "BR_MISP_RETIRED.JCC", 0xC5, 0x7E, true },
173 1.4.2.3 pgoyette { "BR_MISP_RETIRED.FAR", 0xC5, 0xBF, true },
174 1.4.2.3 pgoyette { "BR_MISP_RETIRED.NON_RETURN_IND", 0xC5, 0xEB, true },
175 1.4.2.3 pgoyette { "BR_MISP_RETIRED.RETURN", 0xC5, 0xF7, true },
176 1.4.2.3 pgoyette { "BR_MISP_RETIRED.CALL", 0xC5, 0xF9, true },
177 1.4.2.3 pgoyette { "BR_MISP_RETIRED.IND_CALL", 0xC5, 0xFB, true },
178 1.4.2.3 pgoyette { "BR_MISP_RETIRED.REL_CALL", 0xC5, 0xFD, true },
179 1.4.2.3 pgoyette { "BR_MISP_RETIRED.TAKEN_JCC", 0xC5, 0xFE, true },
180 1.4.2.3 pgoyette { "NO_ALLOC_CYCLES.ROB_FULL", 0xCA, 0x01, true },
181 1.4.2.3 pgoyette { "NO_ALLOC_CYCLES.RAT_STALL", 0xCA, 0x20, true },
182 1.4.2.3 pgoyette { "NO_ALLOC_CYCLES.ALL", 0xCA, 0x3F, true },
183 1.4.2.3 pgoyette { "NO_ALLOC_CYCLES.NOT_DELIVERED", 0xCA, 0x50, true },
184 1.4.2.3 pgoyette { "RS_FULL_STALL.MEC", 0xCB, 0x01, true },
185 1.4.2.3 pgoyette { "RS_FULL_STALL.ALL", 0xCB, 0x1F, true },
186 1.4.2.3 pgoyette { "CYCLES_DIV_BUSY.ANY", 0xCD, 0x01, true },
187 1.4.2.3 pgoyette { "BACLEARS.ALL", 0xE6, 0x01, true },
188 1.4.2.3 pgoyette { "BACLEARS.RETURN", 0xE6, 0x08, true },
189 1.4.2.3 pgoyette { "BACLEARS.COND", 0xE6, 0x10, true },
190 1.4.2.3 pgoyette { "MS_DECODED.MS_ENTRY", 0xE7, 0x01, true },
191 1.4.2.3 pgoyette };
192 1.4.2.3 pgoyette
193 1.4.2.3 pgoyette static struct event_table intel_silvermont_airmont = {
194 1.4.2.3 pgoyette .tablename = "Intel Silvermont/Airmont",
195 1.4.2.3 pgoyette .names = intel_silvermont_airmont_names,
196 1.4.2.3 pgoyette .nevents = sizeof(intel_silvermont_airmont_names) /
197 1.4.2.3 pgoyette sizeof(struct name_to_event),
198 1.4.2.3 pgoyette .next = NULL
199 1.4.2.3 pgoyette };
200 1.4.2.3 pgoyette
201 1.4.2.3 pgoyette static struct event_table *
202 1.4.2.3 pgoyette init_intel_silvermont_airmont(void)
203 1.4.2.3 pgoyette {
204 1.4.2.3 pgoyette
205 1.4.2.3 pgoyette return &intel_silvermont_airmont;
206 1.4.2.3 pgoyette }
207 1.4.2.3 pgoyette
208 1.4.2.3 pgoyette /*
209 1.4.2.2 pgoyette * Intel Skylake/Kabylake.
210 1.4.2.2 pgoyette *
211 1.4.2.2 pgoyette * The events that are not listed, because they are of little interest or
212 1.4.2.2 pgoyette * require extra configuration:
213 1.4.2.2 pgoyette * TX_*
214 1.4.2.2 pgoyette * FRONTEND_RETIRED.*
215 1.4.2.2 pgoyette * FP_ARITH_INST_RETIRED.*
216 1.4.2.2 pgoyette * HLE_RETIRED.*
217 1.4.2.2 pgoyette * RTM_RETIRED.*
218 1.4.2.2 pgoyette * MEM_TRANS_RETIRED.*
219 1.4.2.2 pgoyette * UOPS_DISPATCHED_PORT.*
220 1.4.2.2 pgoyette */
221 1.4.2.2 pgoyette static struct name_to_event intel_skylake_kabylake_names[] = {
222 1.4.2.2 pgoyette /* Event Name - Event Select - UMask */
223 1.4.2.2 pgoyette { "LD_BLOCKS.STORE_FORWARD", 0x03, 0x02, true },
224 1.4.2.2 pgoyette { "LD_BLOCKS.NO_SR", 0x03, 0x08, true },
225 1.4.2.2 pgoyette { "LD_BLOCKS_PARTIAL.ADDRESS_ALIAS", 0x07, 0x01, true },
226 1.4.2.2 pgoyette { "DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK", 0x08, 0x01, true },
227 1.4.2.2 pgoyette { "DTLB_LOAD_MISSES.WALK_COMPLETED_4K", 0x08, 0x02, true },
228 1.4.2.2 pgoyette { "DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M", 0x08, 0x04, true },
229 1.4.2.2 pgoyette { "DTLB_LOAD_MISSES.WALK_COMPLETED_1G", 0x08, 0x08, true },
230 1.4.2.2 pgoyette { "DTLB_LOAD_MISSES.WALK_COMPLETED", 0x08, 0x0E, true },
231 1.4.2.2 pgoyette { "DTLB_LOAD_MISSES.WALK_PENDING", 0x08, 0x10, true },
232 1.4.2.2 pgoyette { "DTLB_LOAD_MISSES.STLB_HIT", 0x08, 0x20, true },
233 1.4.2.2 pgoyette { "INT_MISC.RECOVERY_CYCLES", 0x0D, 0x01, true },
234 1.4.2.2 pgoyette { "INT_MISC.CLEAR_RESTEER_CYCLES", 0x0D, 0x80, true },
235 1.4.2.2 pgoyette { "UOPS_ISSUED.ANY", 0x0E, 0x01, true },
236 1.4.2.2 pgoyette { "UOPS_ISSUED.VECTOR_WIDTH_MISMATCH", 0x0E, 0x02, true },
237 1.4.2.2 pgoyette { "UOPS_ISSUED.SLOW_LEA", 0x0E, 0x20, true },
238 1.4.2.2 pgoyette { "L2_RQSTS.DEMAND_DATA_RD_MISS", 0x24, 0x21, true },
239 1.4.2.2 pgoyette { "L2_RQSTS.RFO_MISS", 0x24, 0x22, true },
240 1.4.2.2 pgoyette { "L2_RQSTS.CODE_RD_MISS", 0x24, 0x24, true },
241 1.4.2.2 pgoyette { "L2_RQSTS.ALL_DEMAND_MISS", 0x24, 0x27, true },
242 1.4.2.2 pgoyette { "L2_RQSTS.PF_MISS", 0x24, 0x38, true },
243 1.4.2.2 pgoyette { "L2_RQSTS.MISS", 0x24, 0x3F, true },
244 1.4.2.2 pgoyette { "L2_RQSTS.DEMAND_DATA_RD_HIT", 0x24, 0x41, true },
245 1.4.2.2 pgoyette { "L2_RQSTS.RFO_HIT", 0x24, 0x42, true },
246 1.4.2.2 pgoyette { "L2_RQSTS.CODE_RD_HIT", 0x24, 0x44, true },
247 1.4.2.2 pgoyette { "L2_RQSTS.PF_HIT", 0x24, 0xD8, true },
248 1.4.2.2 pgoyette { "L2_RQSTS.ALL_DEMAND_DATA_RD", 0x24, 0xE1, true },
249 1.4.2.2 pgoyette { "L2_RQSTS.ALL_RFO", 0x24, 0xE2, true },
250 1.4.2.2 pgoyette { "L2_RQSTS.ALL_CODE_RD", 0x24, 0xE4, true },
251 1.4.2.2 pgoyette { "L2_RQSTS.ALL_DEMAND_REFERENCES", 0x24, 0xE7, true },
252 1.4.2.2 pgoyette { "L2_RQSTS.ALL_PF", 0x24, 0xF8, true },
253 1.4.2.2 pgoyette { "L2_RQSTS.REFERENCES", 0x24, 0xFF, true },
254 1.4.2.2 pgoyette { "SW_PREFETCH_ACCESS.NTA", 0x32, 0x01, true },
255 1.4.2.2 pgoyette { "SW_PREFETCH_ACCESS.T0", 0x32, 0x02, true },
256 1.4.2.2 pgoyette { "SW_PREFETCH_ACCESS.T1_T2", 0x32, 0x04, true },
257 1.4.2.2 pgoyette { "SW_PREFETCH_ACCESS.PREFETCHW", 0x32, 0x08, true },
258 1.4.2.2 pgoyette { "CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE", 0x3C, 0x02, true },
259 1.4.2.2 pgoyette { "CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE", 0x3C, 0x02, true },
260 1.4.2.2 pgoyette { "L1D_PEND_MISS.PENDING", 0x48, 0x01, true },
261 1.4.2.2 pgoyette { "L1D_PEND_MISS.FB_FULL", 0x48, 0x02, true },
262 1.4.2.2 pgoyette { "DTLB_STORE_MISSES.MISS_CAUSES_A_WALK", 0x49, 0x01, true },
263 1.4.2.2 pgoyette { "DTLB_STORE_MISSES.WALK_COMPLETED_4K", 0x49, 0x02, true },
264 1.4.2.2 pgoyette { "DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M", 0x49, 0x04, true },
265 1.4.2.2 pgoyette { "DTLB_STORE_MISSES.WALK_COMPLETED_1G", 0x49, 0x08, true },
266 1.4.2.2 pgoyette { "DTLB_STORE_MISSES.WALK_COMPLETED", 0x49, 0x0E, true },
267 1.4.2.2 pgoyette { "DTLB_STORE_MISSES.WALK_PENDING", 0x49, 0x10, true },
268 1.4.2.2 pgoyette { "DTLB_STORE_MISSES.STLB_HIT", 0x49, 0x20, true },
269 1.4.2.2 pgoyette { "LOAD_HIT_PRE.SW_PF", 0x4C, 0x01, true },
270 1.4.2.2 pgoyette { "EPT.WALK_PENDING", 0x4F, 0x10, true },
271 1.4.2.2 pgoyette { "L1D.REPLACEMENT", 0x51, 0x01, true },
272 1.4.2.2 pgoyette { "RS_EVENTS.EMPTY_CYCLES", 0x5E, 0x01, true },
273 1.4.2.2 pgoyette { "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD", 0x60, 0x01, true },
274 1.4.2.2 pgoyette { "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_CODE_RD", 0x60, 0x02, true },
275 1.4.2.2 pgoyette { "OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO", 0x60, 0x04, true },
276 1.4.2.2 pgoyette { "OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD", 0x60, 0x08, true },
277 1.4.2.2 pgoyette { "OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD", 0x60, 0x10, true },
278 1.4.2.2 pgoyette { "IDQ.MITE_UOPS", 0x79, 0x04, true },
279 1.4.2.2 pgoyette { "IDQ.DSB_UOPS", 0x79, 0x08, true },
280 1.4.2.2 pgoyette { "IDQ.MS_MITE_UOPS", 0x79, 0x20, true },
281 1.4.2.2 pgoyette { "IDQ.MS_UOPS", 0x79, 0x30, true },
282 1.4.2.2 pgoyette { "ICACHE_16B.IFDATA_STALL", 0x80, 0x04, true },
283 1.4.2.2 pgoyette { "ICACHE_64B.IFTAG_HIT", 0x83, 0x01, true },
284 1.4.2.2 pgoyette { "ICACHE_64B.IFTAG_MISS", 0x83, 0x02, true },
285 1.4.2.2 pgoyette { "ICACHE_64B.IFTAG_STALL", 0x83, 0x04, true },
286 1.4.2.2 pgoyette { "ITLB_MISSES.MISS_CAUSES_A_WALK", 0x85, 0x01, true },
287 1.4.2.2 pgoyette { "ITLB_MISSES.WALK_COMPLETED_4K", 0x85, 0x02, true },
288 1.4.2.2 pgoyette { "ITLB_MISSES.WALK_COMPLETED_2M_4M", 0x85, 0x04, true },
289 1.4.2.2 pgoyette { "ITLB_MISSES.WALK_COMPLETED_1G", 0x85, 0x08, true },
290 1.4.2.2 pgoyette { "ITLB_MISSES.WALK_COMPLETED", 0x85, 0x0E, true },
291 1.4.2.2 pgoyette { "ITLB_MISSES.WALK_PENDING", 0x85, 0x10, true },
292 1.4.2.2 pgoyette { "ITLB_MISSES.STLB_HIT", 0x85, 0x20, true },
293 1.4.2.2 pgoyette { "ILD_STALL.LCP", 0x87, 0x01, true },
294 1.4.2.2 pgoyette { "IDQ_UOPS_NOT_DELIVERED.CORE", 0x9C, 0x01, true },
295 1.4.2.2 pgoyette { "RESOURCE_STALLS.ANY", 0xA2, 0x01, true },
296 1.4.2.2 pgoyette { "RESOURCE_STALLS.SB", 0xA2, 0x08, true },
297 1.4.2.2 pgoyette { "EXE_ACTIVITY.EXE_BOUND_0_PORTS", 0xA6, 0x01, true },
298 1.4.2.2 pgoyette { "EXE_ACTIVITY.1_PORTS_UTIL", 0xA6, 0x02, true },
299 1.4.2.2 pgoyette { "EXE_ACTIVITY.2_PORTS_UTIL", 0xA6, 0x04, true },
300 1.4.2.2 pgoyette { "EXE_ACTIVITY.3_PORTS_UTIL", 0xA6, 0x08, true },
301 1.4.2.2 pgoyette { "EXE_ACTIVITY.4_PORTS_UTIL", 0xA6, 0x10, true },
302 1.4.2.2 pgoyette { "EXE_ACTIVITY.BOUND_ON_STORES", 0xA6, 0x40, true },
303 1.4.2.2 pgoyette { "LSD.UOPS", 0xA8, 0x01, true },
304 1.4.2.2 pgoyette { "DSB2MITE_SWITCHES.PENALTY_CYCLES", 0xAB, 0x02, true },
305 1.4.2.2 pgoyette { "ITLB.ITLB_FLUSH", 0xAE, 0x01, true },
306 1.4.2.2 pgoyette { "OFFCORE_REQUESTS.DEMAND_DATA_RD", 0xB0, 0x01, true },
307 1.4.2.2 pgoyette { "OFFCORE_REQUESTS.DEMAND_CODE_RD", 0xB0, 0x02, true },
308 1.4.2.2 pgoyette { "OFFCORE_REQUESTS.DEMAND_RFO", 0xB0, 0x04, true },
309 1.4.2.2 pgoyette { "OFFCORE_REQUESTS.ALL_DATA_RD", 0xB0, 0x08, true },
310 1.4.2.2 pgoyette { "OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD", 0xB0, 0x10, true },
311 1.4.2.2 pgoyette { "OFFCORE_REQUESTS.ALL_REQUESTS", 0xB0, 0x80, true },
312 1.4.2.2 pgoyette { "UOPS_EXECUTED.THREAD", 0xB1, 0x01, true },
313 1.4.2.2 pgoyette { "UOPS_EXECUTED.CORE", 0xB1, 0x02, true },
314 1.4.2.2 pgoyette { "UOPS_EXECUTED.X87", 0xB1, 0x10, true },
315 1.4.2.2 pgoyette { "OFFCORE_REQUESTS_BUFFER.SQ_FULL", 0xB2, 0x01, true },
316 1.4.2.2 pgoyette { "TLB_FLUSH.DTLB_THREAD", 0xBD, 0x01, true },
317 1.4.2.2 pgoyette { "TLB_FLUSH.STLB_ANY", 0xBD, 0x20, true },
318 1.4.2.2 pgoyette { "INST_RETIRED.PREC_DIST", 0xC0, 0x01, true },
319 1.4.2.2 pgoyette { "OTHER_ASSISTS.ANY", 0xC1, 0x3F, true },
320 1.4.2.2 pgoyette { "UOPS_RETIRED.RETIRE_SLOTS", 0xC2, 0x02, true },
321 1.4.2.2 pgoyette { "MACHINE_CLEARS.MEMORY_ORDERING", 0xC3, 0x02, true },
322 1.4.2.2 pgoyette { "MACHINE_CLEARS.SMC", 0xC3, 0x04, true },
323 1.4.2.2 pgoyette { "BR_INST_RETIRED.CONDITIONAL", 0xC4, 0x01, true },
324 1.4.2.2 pgoyette { "BR_INST_RETIRED.NEAR_CALL", 0xC4, 0x02, true },
325 1.4.2.2 pgoyette { "BR_INST_RETIRED.NEAR_RETURN", 0xC4, 0x08, true },
326 1.4.2.2 pgoyette { "BR_INST_RETIRED.NOT_TAKEN", 0xC4, 0x10, true },
327 1.4.2.2 pgoyette { "BR_INST_RETIRED.NEAR_TAKEN", 0xC4, 0x20, true },
328 1.4.2.2 pgoyette { "BR_INST_RETIRED.FAR_BRANCH", 0xC4, 0x40, true },
329 1.4.2.2 pgoyette { "BR_MISP_RETIRED.CONDITIONAL", 0xC5, 0x01, true },
330 1.4.2.2 pgoyette { "BR_MISP_RETIRED.NEAR_CALL", 0xC5, 0x02, true },
331 1.4.2.2 pgoyette { "BR_MISP_RETIRED.NEAR_TAKEN", 0xC5, 0x20, true },
332 1.4.2.2 pgoyette { "HW_INTERRUPTS.RECEIVED", 0xCB, 0x01, true },
333 1.4.2.2 pgoyette { "MEM_INST_RETIRED.STLB_MISS_LOADS", 0xD0, 0x11, true },
334 1.4.2.2 pgoyette { "MEM_INST_RETIRED.STLB_MISS_STORES", 0xD0, 0x12, true },
335 1.4.2.2 pgoyette { "MEM_INST_RETIRED.LOCK_LOADS", 0xD0, 0x21, true },
336 1.4.2.2 pgoyette { "MEM_INST_RETIRED.SPLIT_LOADS", 0xD0, 0x41, true },
337 1.4.2.2 pgoyette { "MEM_INST_RETIRED.SPLIT_STORES", 0xD0, 0x42, true },
338 1.4.2.2 pgoyette { "MEM_INST_RETIRED.ALL_LOADS", 0xD0, 0x81, true },
339 1.4.2.2 pgoyette { "MEM_INST_RETIRED.ALL_STORES", 0xD0, 0x82, true },
340 1.4.2.2 pgoyette { "MEM_LOAD_RETIRED.L1_HIT", 0xD1, 0x01, true },
341 1.4.2.2 pgoyette { "MEM_LOAD_RETIRED.L2_HIT", 0xD1, 0x02, true },
342 1.4.2.2 pgoyette { "MEM_LOAD_RETIRED.L3_HIT", 0xD1, 0x04, true },
343 1.4.2.2 pgoyette { "MEM_LOAD_RETIRED.L1_MISS", 0xD1, 0x08, true },
344 1.4.2.2 pgoyette { "MEM_LOAD_RETIRED.L2_MISS", 0xD1, 0x10, true },
345 1.4.2.2 pgoyette { "MEM_LOAD_RETIRED.L3_MISS", 0xD1, 0x20, true },
346 1.4.2.2 pgoyette { "MEM_LOAD_RETIRED.FB_HIT", 0xD1, 0x40, true },
347 1.4.2.2 pgoyette { "MEM_LOAD_L3_HIT_RETIRED.XSNP_MISS", 0xD2, 0x01, true },
348 1.4.2.2 pgoyette { "MEM_LOAD_L3_HIT_RETIRED.XSNP_HIT", 0xD2, 0x02, true },
349 1.4.2.2 pgoyette { "MEM_LOAD_L3_HIT_RETIRED.XSNP_HITM", 0xD2, 0x04, true },
350 1.4.2.2 pgoyette { "MEM_LOAD_L3_HIT_RETIRED.XSNP_NONE", 0xD2, 0x08, true },
351 1.4.2.2 pgoyette { "MEM_LOAD_MISC_RETIRED.UC", 0xD4, 0x04, true },
352 1.4.2.2 pgoyette { "BACLEARS.ANY", 0xE6, 0x01, true },
353 1.4.2.2 pgoyette { "L2_TRANS.L2_WB", 0xF0, 0x40, true },
354 1.4.2.2 pgoyette { "L2_LINES_IN.ALL", 0xF1, 0x1F, true },
355 1.4.2.2 pgoyette { "L2_LINES_OUT.SILENT", 0xF2, 0x01, true },
356 1.4.2.2 pgoyette { "L2_LINES_OUT.NON_SILENT", 0xF2, 0x02, true },
357 1.4.2.2 pgoyette { "L2_LINES_OUT.USELESS_HWPF", 0xF2, 0x04, true },
358 1.4.2.2 pgoyette { "SQ_MISC.SPLIT_LOCK", 0xF4, 0x10, true },
359 1.4.2.2 pgoyette };
360 1.4.2.2 pgoyette
361 1.4.2.2 pgoyette static struct event_table intel_skylake_kabylake = {
362 1.4.2.2 pgoyette .tablename = "Intel Skylake/Kabylake",
363 1.4.2.2 pgoyette .names = intel_skylake_kabylake_names,
364 1.4.2.2 pgoyette .nevents = sizeof(intel_skylake_kabylake_names) /
365 1.4.2.2 pgoyette sizeof(struct name_to_event),
366 1.4.2.2 pgoyette .next = NULL
367 1.4.2.2 pgoyette };
368 1.4.2.2 pgoyette
369 1.4.2.2 pgoyette static struct event_table *
370 1.4.2.2 pgoyette init_intel_skylake_kabylake(void)
371 1.4.2.2 pgoyette {
372 1.4.2.2 pgoyette return &intel_skylake_kabylake;
373 1.4.2.2 pgoyette }
374 1.4.2.2 pgoyette
375 1.4.2.2 pgoyette static struct event_table *
376 1.4.2.2 pgoyette init_intel_generic(void)
377 1.4.2.2 pgoyette {
378 1.4.2.2 pgoyette unsigned int eax, ebx, ecx, edx;
379 1.4.2.2 pgoyette struct event_table *table;
380 1.4.2.2 pgoyette
381 1.4.2.2 pgoyette /*
382 1.4.2.2 pgoyette * The kernel made sure the Architectural Version 1 PMCs were
383 1.4.2.2 pgoyette * present.
384 1.4.2.2 pgoyette */
385 1.4.2.2 pgoyette table = init_intel_arch1();
386 1.4.2.2 pgoyette
387 1.4.2.2 pgoyette /*
388 1.4.2.2 pgoyette * Now query the additional (non-architectural) events. They
389 1.4.2.2 pgoyette * depend on the CPU model.
390 1.4.2.2 pgoyette */
391 1.4.2.2 pgoyette eax = 0x01;
392 1.4.2.2 pgoyette ebx = 0;
393 1.4.2.2 pgoyette ecx = 0;
394 1.4.2.2 pgoyette edx = 0;
395 1.4.2.2 pgoyette x86_cpuid(&eax, &ebx, &ecx, &edx);
396 1.4.2.2 pgoyette
397 1.4.2.2 pgoyette if (CPUID_TO_FAMILY(eax) == 6) {
398 1.4.2.2 pgoyette switch (CPUID_TO_MODEL(eax)) {
399 1.4.2.3 pgoyette case 0x37: /* Silvermont (Bay Trail) */
400 1.4.2.3 pgoyette case 0x4A: /* Silvermont (Tangier) */
401 1.4.2.3 pgoyette case 0x4C: /* Airmont (Braswell, Cherry Trail) */
402 1.4.2.3 pgoyette case 0x4D: /* Silvermont (Avoton, Rangeley) */
403 1.4.2.3 pgoyette case 0x5A: /* Silvermont (Anniedale) */
404 1.4.2.3 pgoyette case 0x5D: /* Silvermont (SoFIA) */
405 1.4.2.3 pgoyette table->next = init_intel_silvermont_airmont();
406 1.4.2.3 pgoyette break;
407 1.4.2.2 pgoyette case 0x4E: /* Skylake */
408 1.4.2.2 pgoyette case 0x5E: /* Skylake */
409 1.4.2.2 pgoyette case 0x8E: /* Kabylake */
410 1.4.2.2 pgoyette case 0x9E: /* Kabylake */
411 1.4.2.2 pgoyette table->next = init_intel_skylake_kabylake();
412 1.4.2.2 pgoyette break;
413 1.4.2.2 pgoyette }
414 1.4.2.2 pgoyette }
415 1.4.2.2 pgoyette
416 1.4.2.2 pgoyette return table;
417 1.4.2.2 pgoyette }
418 1.4.2.2 pgoyette
419 1.4.2.2 pgoyette /* -------------------------------------------------------------------------- */
420 1.4.2.2 pgoyette
421 1.4.2.2 pgoyette /*
422 1.4.2.2 pgoyette * AMD Family 10h
423 1.4.2.2 pgoyette */
424 1.4.2.2 pgoyette static struct name_to_event amd_f10h_names[] = {
425 1.4.2.2 pgoyette { "seg-load-all", 0x20, 0x7f, true },
426 1.4.2.2 pgoyette { "seg-load-es", 0x20, 0x01, true },
427 1.4.2.2 pgoyette { "seg-load-cs", 0x20, 0x02, true },
428 1.4.2.2 pgoyette { "seg-load-ss", 0x20, 0x04, true },
429 1.4.2.2 pgoyette { "seg-load-ds", 0x20, 0x08, true },
430 1.4.2.2 pgoyette { "seg-load-fs", 0x20, 0x10, true },
431 1.4.2.2 pgoyette { "seg-load-gs", 0x20, 0x20, true },
432 1.4.2.2 pgoyette { "seg-load-hs", 0x20, 0x40, true },
433 1.4.2.2 pgoyette { "l1cache-access", 0x40, 0x00, true },
434 1.4.2.2 pgoyette { "l1cache-miss", 0x41, 0x00, true },
435 1.4.2.2 pgoyette { "l1cache-refill", 0x42, 0x1f, true },
436 1.4.2.2 pgoyette { "l1cache-refill-invalid", 0x42, 0x01, true },
437 1.4.2.2 pgoyette { "l1cache-refill-shared", 0x42, 0x02, true },
438 1.4.2.2 pgoyette { "l1cache-refill-exclusive", 0x42, 0x04, true },
439 1.4.2.2 pgoyette { "l1cache-refill-owner", 0x42, 0x08, true },
440 1.4.2.2 pgoyette { "l1cache-refill-modified", 0x42, 0x10, true },
441 1.4.2.2 pgoyette { "l1cache-load", 0x43, 0x1f, true },
442 1.4.2.2 pgoyette { "l1cache-load-invalid", 0x43, 0x01, true },
443 1.4.2.2 pgoyette { "l1cache-load-shared", 0x43, 0x02, true },
444 1.4.2.2 pgoyette { "l1cache-load-exclusive", 0x43, 0x04, true },
445 1.4.2.2 pgoyette { "l1cache-load-owner", 0x43, 0x08, true },
446 1.4.2.2 pgoyette { "l1cache-load-modified", 0x43, 0x10, true },
447 1.4.2.2 pgoyette { "l1cache-writeback", 0x44, 0x1f, true },
448 1.4.2.2 pgoyette { "l1cache-writeback-invalid", 0x44, 0x01, true },
449 1.4.2.2 pgoyette { "l1cache-writeback-shared", 0x44, 0x02, true },
450 1.4.2.2 pgoyette { "l1cache-writeback-exclusive",0x44, 0x04, true },
451 1.4.2.2 pgoyette { "l1cache-writeback-owner", 0x44, 0x08, true },
452 1.4.2.2 pgoyette { "l1cache-writeback-modified", 0x44, 0x10, true },
453 1.4.2.2 pgoyette { "l1DTLB-hit-all", 0x4D, 0x07, true },
454 1.4.2.2 pgoyette { "l1DTLB-hit-4Kpage", 0x4D, 0x01, true },
455 1.4.2.2 pgoyette { "l1DTLB-hit-2Mpage", 0x4D, 0x02, true },
456 1.4.2.2 pgoyette { "l1DTLB-hit-1Gpage", 0x4D, 0x04, true },
457 1.4.2.2 pgoyette { "l1DTLB-miss-all", 0x45, 0x07, true },
458 1.4.2.2 pgoyette { "l1DTLB-miss-4Kpage", 0x45, 0x01, true },
459 1.4.2.2 pgoyette { "l1DTLB-miss-2Mpage", 0x45, 0x02, true },
460 1.4.2.2 pgoyette { "l1DTLB-miss-1Gpage", 0x45, 0x04, true },
461 1.4.2.2 pgoyette { "l2DTLB-miss-all", 0x46, 0x03, true },
462 1.4.2.2 pgoyette { "l2DTLB-miss-4Kpage", 0x46, 0x01, true },
463 1.4.2.2 pgoyette { "l2DTLB-miss-2Mpage", 0x46, 0x02, true },
464 1.4.2.2 pgoyette /* l2DTLB-miss-1Gpage: reserved on some revisions, so disabled */
465 1.4.2.2 pgoyette { "l1ITLB-miss", 0x84, 0x00, true },
466 1.4.2.2 pgoyette { "l2ITLB-miss-all", 0x85, 0x03, true },
467 1.4.2.2 pgoyette { "l2ITLB-miss-4Kpage", 0x85, 0x01, true },
468 1.4.2.2 pgoyette { "l2ITLB-miss-2Mpage", 0x85, 0x02, true },
469 1.4.2.2 pgoyette { "mem-misalign-ref", 0x47, 0x00, true },
470 1.4.2.2 pgoyette { "ins-fetch", 0x80, 0x00, true },
471 1.4.2.2 pgoyette { "ins-fetch-miss", 0x81, 0x00, true },
472 1.4.2.2 pgoyette { "ins-refill-l2", 0x82, 0x00, true },
473 1.4.2.2 pgoyette { "ins-refill-sys", 0x83, 0x00, true },
474 1.4.2.2 pgoyette { "ins-fetch-stall", 0x87, 0x00, true },
475 1.4.2.2 pgoyette { "ins-retired", 0xC0, 0x00, true },
476 1.4.2.2 pgoyette { "ins-empty", 0xD0, 0x00, true },
477 1.4.2.2 pgoyette { "ops-retired", 0xC1, 0x00, true },
478 1.4.2.2 pgoyette { "branch-retired", 0xC2, 0x00, true },
479 1.4.2.2 pgoyette { "branch-miss-retired", 0xC3, 0x00, true },
480 1.4.2.2 pgoyette { "branch-taken-retired", 0xC4, 0x00, true },
481 1.4.2.2 pgoyette { "branch-taken-miss-retired", 0xC5, 0x00, true },
482 1.4.2.2 pgoyette { "branch-far-retired", 0xC6, 0x00, true },
483 1.4.2.2 pgoyette { "branch-resync-retired", 0xC7, 0x00, true },
484 1.4.2.2 pgoyette { "branch-near-retired", 0xC8, 0x00, true },
485 1.4.2.2 pgoyette { "branch-near-miss-retired", 0xC9, 0x00, true },
486 1.4.2.2 pgoyette { "branch-indirect-miss-retired", 0xCA, 0x00, true },
487 1.4.2.2 pgoyette { "int-hw", 0xCF, 0x00, true },
488 1.4.2.2 pgoyette { "int-cycles-masked", 0xCD, 0x00, true },
489 1.4.2.2 pgoyette { "int-cycles-masked-pending", 0xCE, 0x00, true },
490 1.4.2.2 pgoyette { "fpu-exceptions", 0xDB, 0x00, true },
491 1.4.2.2 pgoyette { "break-match0", 0xDC, 0x00, true },
492 1.4.2.2 pgoyette { "break-match1", 0xDD, 0x00, true },
493 1.4.2.2 pgoyette { "break-match2", 0xDE, 0x00, true },
494 1.4.2.2 pgoyette { "break-match3", 0xDF, 0x00, true },
495 1.4.2.2 pgoyette };
496 1.4.2.2 pgoyette
497 1.4.2.2 pgoyette static struct event_table amd_f10h = {
498 1.4.2.2 pgoyette .tablename = "AMD Family 10h",
499 1.4.2.2 pgoyette .names = amd_f10h_names,
500 1.4.2.2 pgoyette .nevents = sizeof(amd_f10h_names) /
501 1.4.2.2 pgoyette sizeof(struct name_to_event),
502 1.4.2.2 pgoyette .next = NULL
503 1.4.2.2 pgoyette };
504 1.4.2.2 pgoyette
505 1.4.2.2 pgoyette static struct event_table *
506 1.4.2.2 pgoyette init_amd_f10h(void)
507 1.4.2.2 pgoyette {
508 1.4.2.2 pgoyette return &amd_f10h;
509 1.4.2.2 pgoyette }
510 1.4.2.2 pgoyette
511 1.4.2.2 pgoyette static struct event_table *
512 1.4.2.2 pgoyette init_amd_generic(void)
513 1.4.2.2 pgoyette {
514 1.4.2.2 pgoyette unsigned int eax, ebx, ecx, edx;
515 1.4.2.2 pgoyette
516 1.4.2.2 pgoyette eax = 0x01;
517 1.4.2.2 pgoyette ebx = 0;
518 1.4.2.2 pgoyette ecx = 0;
519 1.4.2.2 pgoyette edx = 0;
520 1.4.2.2 pgoyette x86_cpuid(&eax, &ebx, &ecx, &edx);
521 1.4.2.2 pgoyette
522 1.4.2.2 pgoyette switch (CPUID_TO_FAMILY(eax)) {
523 1.4.2.2 pgoyette case 0x10:
524 1.4.2.2 pgoyette return init_amd_f10h();
525 1.4.2.2 pgoyette }
526 1.4.2.2 pgoyette
527 1.4.2.2 pgoyette return NULL;
528 1.4.2.2 pgoyette }
529 1.4.2.2 pgoyette
530 1.4.2.2 pgoyette /* -------------------------------------------------------------------------- */
531 1.4.2.2 pgoyette
532 1.4.2.2 pgoyette int
533 1.4.2.2 pgoyette tprof_event_init(uint32_t ident)
534 1.4.2.2 pgoyette {
535 1.4.2.2 pgoyette switch (ident) {
536 1.4.2.2 pgoyette case TPROF_IDENT_NONE:
537 1.4.2.2 pgoyette return -1;
538 1.4.2.2 pgoyette case TPROF_IDENT_INTEL_GENERIC:
539 1.4.2.2 pgoyette cpuevents = init_intel_generic();
540 1.4.2.2 pgoyette break;
541 1.4.2.2 pgoyette case TPROF_IDENT_AMD_GENERIC:
542 1.4.2.2 pgoyette cpuevents = init_amd_generic();
543 1.4.2.2 pgoyette break;
544 1.4.2.2 pgoyette }
545 1.4.2.2 pgoyette return (cpuevents == NULL) ? -1 : 0;
546 1.4.2.2 pgoyette }
547 1.4.2.2 pgoyette
548 1.4.2.2 pgoyette static void
549 1.4.2.2 pgoyette recursive_event_list(struct event_table *table)
550 1.4.2.2 pgoyette {
551 1.4.2.2 pgoyette size_t i;
552 1.4.2.2 pgoyette
553 1.4.2.2 pgoyette printf("%s:\n", table->tablename);
554 1.4.2.2 pgoyette for (i = 0; i < table->nevents; i++) {
555 1.4.2.2 pgoyette if (!table->names[i].enabled)
556 1.4.2.2 pgoyette continue;
557 1.4.2.2 pgoyette printf("\t%s\n", table->names[i].name);
558 1.4.2.2 pgoyette }
559 1.4.2.2 pgoyette
560 1.4.2.2 pgoyette if (table->next != NULL) {
561 1.4.2.2 pgoyette recursive_event_list(table->next);
562 1.4.2.2 pgoyette }
563 1.4.2.2 pgoyette }
564 1.4.2.2 pgoyette
565 1.4.2.2 pgoyette void
566 1.4.2.2 pgoyette tprof_event_list(void)
567 1.4.2.2 pgoyette {
568 1.4.2.2 pgoyette recursive_event_list(cpuevents);
569 1.4.2.2 pgoyette }
570 1.4.2.2 pgoyette
571 1.4.2.2 pgoyette static void
572 1.4.2.2 pgoyette recursive_event_lookup(struct event_table *table, const char *name,
573 1.4.2.2 pgoyette struct tprof_param *param)
574 1.4.2.2 pgoyette {
575 1.4.2.2 pgoyette size_t i;
576 1.4.2.2 pgoyette
577 1.4.2.2 pgoyette for (i = 0; i < table->nevents; i++) {
578 1.4.2.2 pgoyette if (!table->names[i].enabled)
579 1.4.2.2 pgoyette continue;
580 1.4.2.2 pgoyette if (!strcmp(table->names[i].name, name)) {
581 1.4.2.2 pgoyette param->p_event = table->names[i].event;
582 1.4.2.2 pgoyette param->p_unit = table->names[i].unit;
583 1.4.2.2 pgoyette return;
584 1.4.2.2 pgoyette }
585 1.4.2.2 pgoyette }
586 1.4.2.2 pgoyette
587 1.4.2.2 pgoyette if (table->next != NULL) {
588 1.4.2.2 pgoyette recursive_event_lookup(table->next, name, param);
589 1.4.2.2 pgoyette } else {
590 1.4.2.2 pgoyette errx(EXIT_FAILURE, "event '%s' unknown", name);
591 1.4.2.2 pgoyette }
592 1.4.2.2 pgoyette }
593 1.4.2.2 pgoyette
594 1.4.2.2 pgoyette void
595 1.4.2.2 pgoyette tprof_event_lookup(const char *name, struct tprof_param *param)
596 1.4.2.2 pgoyette {
597 1.4.2.2 pgoyette recursive_event_lookup(cpuevents, name, param);
598 1.4.2.2 pgoyette }
599