2 * Netburst Perfomance Events (P4, old Xeon)
4 * Copyright (C) 2010 Parallels, Inc., Cyrill Gorcunov <gorcunov@openvz.org>
5 * Copyright (C) 2010 Intel Corporation, Lin Ming <ming.m.lin@intel.com>
7 * For licencing details see kernel-base/COPYING
10 #ifdef CONFIG_CPU_SUP_INTEL
12 #include <asm/perf_event_p4.h>
14 #define P4_CNTR_LIMIT 3
16 * array indices: 0,1 - HT threads, used with HT enabled cpu
18 struct p4_event_bind
{
19 unsigned int opcode
; /* Event code and ESCR selector */
20 unsigned int escr_msr
[2]; /* ESCR MSR for this event */
21 unsigned int escr_emask
; /* valid ESCR EventMask bits */
22 unsigned int shared
; /* event is shared across threads */
23 char cntr
[2][P4_CNTR_LIMIT
]; /* counter index (offset), -1 on abscence */
27 unsigned int metric_pebs
;
28 unsigned int metric_vert
;
31 /* it sets P4_PEBS_ENABLE_UOP_TAG as well */
32 #define P4_GEN_PEBS_BIND(name, pebs, vert) \
33 [P4_PEBS_METRIC__##name] = { \
34 .metric_pebs = pebs | P4_PEBS_ENABLE_UOP_TAG, \
35 .metric_vert = vert, \
39 * note we have P4_PEBS_ENABLE_UOP_TAG always set here
41 * it's needed for mapping P4_PEBS_CONFIG_METRIC_MASK bits of
42 * event configuration to find out which values are to be
43 * written into MSR_IA32_PEBS_ENABLE and MSR_P4_PEBS_MATRIX_VERT
46 static struct p4_pebs_bind p4_pebs_bind_map
[] = {
47 P4_GEN_PEBS_BIND(1stl_cache_load_miss_retired
, 0x0000001, 0x0000001),
48 P4_GEN_PEBS_BIND(2ndl_cache_load_miss_retired
, 0x0000002, 0x0000001),
49 P4_GEN_PEBS_BIND(dtlb_load_miss_retired
, 0x0000004, 0x0000001),
50 P4_GEN_PEBS_BIND(dtlb_store_miss_retired
, 0x0000004, 0x0000002),
51 P4_GEN_PEBS_BIND(dtlb_all_miss_retired
, 0x0000004, 0x0000003),
52 P4_GEN_PEBS_BIND(tagged_mispred_branch
, 0x0018000, 0x0000010),
53 P4_GEN_PEBS_BIND(mob_load_replay_retired
, 0x0000200, 0x0000001),
54 P4_GEN_PEBS_BIND(split_load_retired
, 0x0000400, 0x0000001),
55 P4_GEN_PEBS_BIND(split_store_retired
, 0x0000400, 0x0000002),
59 * Note that we don't use CCCR1 here, there is an
60 * exception for P4_BSQ_ALLOCATION but we just have
63 * consider this binding as resources which particular
64 * event may borrow, it doesn't contain EventMask,
65 * Tags and friends -- they are left to a caller
67 static struct p4_event_bind p4_event_bind_map
[] = {
68 [P4_EVENT_TC_DELIVER_MODE
] = {
69 .opcode
= P4_OPCODE(P4_EVENT_TC_DELIVER_MODE
),
70 .escr_msr
= { MSR_P4_TC_ESCR0
, MSR_P4_TC_ESCR1
},
72 P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE
, DD
) |
73 P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE
, DB
) |
74 P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE
, DI
) |
75 P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE
, BD
) |
76 P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE
, BB
) |
77 P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE
, BI
) |
78 P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE
, ID
),
80 .cntr
= { {4, 5, -1}, {6, 7, -1} },
82 [P4_EVENT_BPU_FETCH_REQUEST
] = {
83 .opcode
= P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST
),
84 .escr_msr
= { MSR_P4_BPU_ESCR0
, MSR_P4_BPU_ESCR1
},
86 P4_ESCR_EMASK_BIT(P4_EVENT_BPU_FETCH_REQUEST
, TCMISS
),
87 .cntr
= { {0, -1, -1}, {2, -1, -1} },
89 [P4_EVENT_ITLB_REFERENCE
] = {
90 .opcode
= P4_OPCODE(P4_EVENT_ITLB_REFERENCE
),
91 .escr_msr
= { MSR_P4_ITLB_ESCR0
, MSR_P4_ITLB_ESCR1
},
93 P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE
, HIT
) |
94 P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE
, MISS
) |
95 P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE
, HIT_UK
),
96 .cntr
= { {0, -1, -1}, {2, -1, -1} },
98 [P4_EVENT_MEMORY_CANCEL
] = {
99 .opcode
= P4_OPCODE(P4_EVENT_MEMORY_CANCEL
),
100 .escr_msr
= { MSR_P4_DAC_ESCR0
, MSR_P4_DAC_ESCR1
},
102 P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_CANCEL
, ST_RB_FULL
) |
103 P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_CANCEL
, 64K_CONF
),
104 .cntr
= { {8, 9, -1}, {10, 11, -1} },
106 [P4_EVENT_MEMORY_COMPLETE
] = {
107 .opcode
= P4_OPCODE(P4_EVENT_MEMORY_COMPLETE
),
108 .escr_msr
= { MSR_P4_SAAT_ESCR0
, MSR_P4_SAAT_ESCR1
},
110 P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_COMPLETE
, LSC
) |
111 P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_COMPLETE
, SSC
),
112 .cntr
= { {8, 9, -1}, {10, 11, -1} },
114 [P4_EVENT_LOAD_PORT_REPLAY
] = {
115 .opcode
= P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY
),
116 .escr_msr
= { MSR_P4_SAAT_ESCR0
, MSR_P4_SAAT_ESCR1
},
118 P4_ESCR_EMASK_BIT(P4_EVENT_LOAD_PORT_REPLAY
, SPLIT_LD
),
119 .cntr
= { {8, 9, -1}, {10, 11, -1} },
121 [P4_EVENT_STORE_PORT_REPLAY
] = {
122 .opcode
= P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY
),
123 .escr_msr
= { MSR_P4_SAAT_ESCR0
, MSR_P4_SAAT_ESCR1
},
125 P4_ESCR_EMASK_BIT(P4_EVENT_STORE_PORT_REPLAY
, SPLIT_ST
),
126 .cntr
= { {8, 9, -1}, {10, 11, -1} },
128 [P4_EVENT_MOB_LOAD_REPLAY
] = {
129 .opcode
= P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY
),
130 .escr_msr
= { MSR_P4_MOB_ESCR0
, MSR_P4_MOB_ESCR1
},
132 P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY
, NO_STA
) |
133 P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY
, NO_STD
) |
134 P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY
, PARTIAL_DATA
) |
135 P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY
, UNALGN_ADDR
),
136 .cntr
= { {0, -1, -1}, {2, -1, -1} },
138 [P4_EVENT_PAGE_WALK_TYPE
] = {
139 .opcode
= P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE
),
140 .escr_msr
= { MSR_P4_PMH_ESCR0
, MSR_P4_PMH_ESCR1
},
142 P4_ESCR_EMASK_BIT(P4_EVENT_PAGE_WALK_TYPE
, DTMISS
) |
143 P4_ESCR_EMASK_BIT(P4_EVENT_PAGE_WALK_TYPE
, ITMISS
),
145 .cntr
= { {0, -1, -1}, {2, -1, -1} },
147 [P4_EVENT_BSQ_CACHE_REFERENCE
] = {
148 .opcode
= P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE
),
149 .escr_msr
= { MSR_P4_BSU_ESCR0
, MSR_P4_BSU_ESCR1
},
151 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_HITS
) |
152 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_HITE
) |
153 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_HITM
) |
154 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_HITS
) |
155 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_HITE
) |
156 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_HITM
) |
157 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_MISS
) |
158 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_MISS
) |
159 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, WR_2ndL_MISS
),
160 .cntr
= { {0, -1, -1}, {2, -1, -1} },
162 [P4_EVENT_IOQ_ALLOCATION
] = {
163 .opcode
= P4_OPCODE(P4_EVENT_IOQ_ALLOCATION
),
164 .escr_msr
= { MSR_P4_FSB_ESCR0
, MSR_P4_FSB_ESCR1
},
166 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, DEFAULT
) |
167 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, ALL_READ
) |
168 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, ALL_WRITE
) |
169 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, MEM_UC
) |
170 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, MEM_WC
) |
171 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, MEM_WT
) |
172 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, MEM_WP
) |
173 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, MEM_WB
) |
174 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, OWN
) |
175 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, OTHER
) |
176 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION
, PREFETCH
),
177 .cntr
= { {0, -1, -1}, {2, -1, -1} },
179 [P4_EVENT_IOQ_ACTIVE_ENTRIES
] = { /* shared ESCR */
180 .opcode
= P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES
),
181 .escr_msr
= { MSR_P4_FSB_ESCR1
, MSR_P4_FSB_ESCR1
},
183 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, DEFAULT
) |
184 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, ALL_READ
) |
185 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, ALL_WRITE
) |
186 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, MEM_UC
) |
187 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, MEM_WC
) |
188 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, MEM_WT
) |
189 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, MEM_WP
) |
190 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, MEM_WB
) |
191 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, OWN
) |
192 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, OTHER
) |
193 P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES
, PREFETCH
),
194 .cntr
= { {2, -1, -1}, {3, -1, -1} },
196 [P4_EVENT_FSB_DATA_ACTIVITY
] = {
197 .opcode
= P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY
),
198 .escr_msr
= { MSR_P4_FSB_ESCR0
, MSR_P4_FSB_ESCR1
},
200 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DRDY_DRV
) |
201 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DRDY_OWN
) |
202 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DRDY_OTHER
) |
203 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DBSY_DRV
) |
204 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DBSY_OWN
) |
205 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DBSY_OTHER
),
207 .cntr
= { {0, -1, -1}, {2, -1, -1} },
209 [P4_EVENT_BSQ_ALLOCATION
] = { /* shared ESCR, broken CCCR1 */
210 .opcode
= P4_OPCODE(P4_EVENT_BSQ_ALLOCATION
),
211 .escr_msr
= { MSR_P4_BSU_ESCR0
, MSR_P4_BSU_ESCR0
},
213 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_TYPE0
) |
214 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_TYPE1
) |
215 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_LEN0
) |
216 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_LEN1
) |
217 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_IO_TYPE
) |
218 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_LOCK_TYPE
) |
219 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_CACHE_TYPE
) |
220 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_SPLIT_TYPE
) |
221 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_DEM_TYPE
) |
222 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, REQ_ORD_TYPE
) |
223 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, MEM_TYPE0
) |
224 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, MEM_TYPE1
) |
225 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION
, MEM_TYPE2
),
226 .cntr
= { {0, -1, -1}, {1, -1, -1} },
228 [P4_EVENT_BSQ_ACTIVE_ENTRIES
] = { /* shared ESCR */
229 .opcode
= P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES
),
230 .escr_msr
= { MSR_P4_BSU_ESCR1
, MSR_P4_BSU_ESCR1
},
232 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_TYPE0
) |
233 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_TYPE1
) |
234 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_LEN0
) |
235 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_LEN1
) |
236 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_IO_TYPE
) |
237 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_LOCK_TYPE
) |
238 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_CACHE_TYPE
) |
239 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_SPLIT_TYPE
) |
240 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_DEM_TYPE
) |
241 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, REQ_ORD_TYPE
) |
242 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, MEM_TYPE0
) |
243 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, MEM_TYPE1
) |
244 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES
, MEM_TYPE2
),
245 .cntr
= { {2, -1, -1}, {3, -1, -1} },
247 [P4_EVENT_SSE_INPUT_ASSIST
] = {
248 .opcode
= P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST
),
249 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
251 P4_ESCR_EMASK_BIT(P4_EVENT_SSE_INPUT_ASSIST
, ALL
),
253 .cntr
= { {8, 9, -1}, {10, 11, -1} },
255 [P4_EVENT_PACKED_SP_UOP
] = {
256 .opcode
= P4_OPCODE(P4_EVENT_PACKED_SP_UOP
),
257 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
259 P4_ESCR_EMASK_BIT(P4_EVENT_PACKED_SP_UOP
, ALL
),
261 .cntr
= { {8, 9, -1}, {10, 11, -1} },
263 [P4_EVENT_PACKED_DP_UOP
] = {
264 .opcode
= P4_OPCODE(P4_EVENT_PACKED_DP_UOP
),
265 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
267 P4_ESCR_EMASK_BIT(P4_EVENT_PACKED_DP_UOP
, ALL
),
269 .cntr
= { {8, 9, -1}, {10, 11, -1} },
271 [P4_EVENT_SCALAR_SP_UOP
] = {
272 .opcode
= P4_OPCODE(P4_EVENT_SCALAR_SP_UOP
),
273 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
275 P4_ESCR_EMASK_BIT(P4_EVENT_SCALAR_SP_UOP
, ALL
),
277 .cntr
= { {8, 9, -1}, {10, 11, -1} },
279 [P4_EVENT_SCALAR_DP_UOP
] = {
280 .opcode
= P4_OPCODE(P4_EVENT_SCALAR_DP_UOP
),
281 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
283 P4_ESCR_EMASK_BIT(P4_EVENT_SCALAR_DP_UOP
, ALL
),
285 .cntr
= { {8, 9, -1}, {10, 11, -1} },
287 [P4_EVENT_64BIT_MMX_UOP
] = {
288 .opcode
= P4_OPCODE(P4_EVENT_64BIT_MMX_UOP
),
289 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
291 P4_ESCR_EMASK_BIT(P4_EVENT_64BIT_MMX_UOP
, ALL
),
293 .cntr
= { {8, 9, -1}, {10, 11, -1} },
295 [P4_EVENT_128BIT_MMX_UOP
] = {
296 .opcode
= P4_OPCODE(P4_EVENT_128BIT_MMX_UOP
),
297 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
299 P4_ESCR_EMASK_BIT(P4_EVENT_128BIT_MMX_UOP
, ALL
),
301 .cntr
= { {8, 9, -1}, {10, 11, -1} },
303 [P4_EVENT_X87_FP_UOP
] = {
304 .opcode
= P4_OPCODE(P4_EVENT_X87_FP_UOP
),
305 .escr_msr
= { MSR_P4_FIRM_ESCR0
, MSR_P4_FIRM_ESCR1
},
307 P4_ESCR_EMASK_BIT(P4_EVENT_X87_FP_UOP
, ALL
),
309 .cntr
= { {8, 9, -1}, {10, 11, -1} },
311 [P4_EVENT_TC_MISC
] = {
312 .opcode
= P4_OPCODE(P4_EVENT_TC_MISC
),
313 .escr_msr
= { MSR_P4_TC_ESCR0
, MSR_P4_TC_ESCR1
},
315 P4_ESCR_EMASK_BIT(P4_EVENT_TC_MISC
, FLUSH
),
316 .cntr
= { {4, 5, -1}, {6, 7, -1} },
318 [P4_EVENT_GLOBAL_POWER_EVENTS
] = {
319 .opcode
= P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS
),
320 .escr_msr
= { MSR_P4_FSB_ESCR0
, MSR_P4_FSB_ESCR1
},
322 P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS
, RUNNING
),
323 .cntr
= { {0, -1, -1}, {2, -1, -1} },
325 [P4_EVENT_TC_MS_XFER
] = {
326 .opcode
= P4_OPCODE(P4_EVENT_TC_MS_XFER
),
327 .escr_msr
= { MSR_P4_MS_ESCR0
, MSR_P4_MS_ESCR1
},
329 P4_ESCR_EMASK_BIT(P4_EVENT_TC_MS_XFER
, CISC
),
330 .cntr
= { {4, 5, -1}, {6, 7, -1} },
332 [P4_EVENT_UOP_QUEUE_WRITES
] = {
333 .opcode
= P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES
),
334 .escr_msr
= { MSR_P4_MS_ESCR0
, MSR_P4_MS_ESCR1
},
336 P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES
, FROM_TC_BUILD
) |
337 P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES
, FROM_TC_DELIVER
) |
338 P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES
, FROM_ROM
),
339 .cntr
= { {4, 5, -1}, {6, 7, -1} },
341 [P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE
] = {
342 .opcode
= P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE
),
343 .escr_msr
= { MSR_P4_TBPU_ESCR0
, MSR_P4_TBPU_ESCR0
},
345 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE
, CONDITIONAL
) |
346 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE
, CALL
) |
347 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE
, RETURN
) |
348 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE
, INDIRECT
),
349 .cntr
= { {4, 5, -1}, {6, 7, -1} },
351 [P4_EVENT_RETIRED_BRANCH_TYPE
] = {
352 .opcode
= P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE
),
353 .escr_msr
= { MSR_P4_TBPU_ESCR0
, MSR_P4_TBPU_ESCR1
},
355 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, CONDITIONAL
) |
356 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, CALL
) |
357 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, RETURN
) |
358 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, INDIRECT
),
359 .cntr
= { {4, 5, -1}, {6, 7, -1} },
361 [P4_EVENT_RESOURCE_STALL
] = {
362 .opcode
= P4_OPCODE(P4_EVENT_RESOURCE_STALL
),
363 .escr_msr
= { MSR_P4_ALF_ESCR0
, MSR_P4_ALF_ESCR1
},
365 P4_ESCR_EMASK_BIT(P4_EVENT_RESOURCE_STALL
, SBFULL
),
366 .cntr
= { {12, 13, 16}, {14, 15, 17} },
368 [P4_EVENT_WC_BUFFER
] = {
369 .opcode
= P4_OPCODE(P4_EVENT_WC_BUFFER
),
370 .escr_msr
= { MSR_P4_DAC_ESCR0
, MSR_P4_DAC_ESCR1
},
372 P4_ESCR_EMASK_BIT(P4_EVENT_WC_BUFFER
, WCB_EVICTS
) |
373 P4_ESCR_EMASK_BIT(P4_EVENT_WC_BUFFER
, WCB_FULL_EVICTS
),
375 .cntr
= { {8, 9, -1}, {10, 11, -1} },
377 [P4_EVENT_B2B_CYCLES
] = {
378 .opcode
= P4_OPCODE(P4_EVENT_B2B_CYCLES
),
379 .escr_msr
= { MSR_P4_FSB_ESCR0
, MSR_P4_FSB_ESCR1
},
381 .cntr
= { {0, -1, -1}, {2, -1, -1} },
384 .opcode
= P4_OPCODE(P4_EVENT_BNR
),
385 .escr_msr
= { MSR_P4_FSB_ESCR0
, MSR_P4_FSB_ESCR1
},
387 .cntr
= { {0, -1, -1}, {2, -1, -1} },
390 .opcode
= P4_OPCODE(P4_EVENT_SNOOP
),
391 .escr_msr
= { MSR_P4_FSB_ESCR0
, MSR_P4_FSB_ESCR1
},
393 .cntr
= { {0, -1, -1}, {2, -1, -1} },
395 [P4_EVENT_RESPONSE
] = {
396 .opcode
= P4_OPCODE(P4_EVENT_RESPONSE
),
397 .escr_msr
= { MSR_P4_FSB_ESCR0
, MSR_P4_FSB_ESCR1
},
399 .cntr
= { {0, -1, -1}, {2, -1, -1} },
401 [P4_EVENT_FRONT_END_EVENT
] = {
402 .opcode
= P4_OPCODE(P4_EVENT_FRONT_END_EVENT
),
403 .escr_msr
= { MSR_P4_CRU_ESCR2
, MSR_P4_CRU_ESCR3
},
405 P4_ESCR_EMASK_BIT(P4_EVENT_FRONT_END_EVENT
, NBOGUS
) |
406 P4_ESCR_EMASK_BIT(P4_EVENT_FRONT_END_EVENT
, BOGUS
),
407 .cntr
= { {12, 13, 16}, {14, 15, 17} },
409 [P4_EVENT_EXECUTION_EVENT
] = {
410 .opcode
= P4_OPCODE(P4_EVENT_EXECUTION_EVENT
),
411 .escr_msr
= { MSR_P4_CRU_ESCR2
, MSR_P4_CRU_ESCR3
},
413 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, NBOGUS0
) |
414 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, NBOGUS1
) |
415 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, NBOGUS2
) |
416 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, NBOGUS3
) |
417 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, BOGUS0
) |
418 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, BOGUS1
) |
419 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, BOGUS2
) |
420 P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT
, BOGUS3
),
421 .cntr
= { {12, 13, 16}, {14, 15, 17} },
423 [P4_EVENT_REPLAY_EVENT
] = {
424 .opcode
= P4_OPCODE(P4_EVENT_REPLAY_EVENT
),
425 .escr_msr
= { MSR_P4_CRU_ESCR2
, MSR_P4_CRU_ESCR3
},
427 P4_ESCR_EMASK_BIT(P4_EVENT_REPLAY_EVENT
, NBOGUS
) |
428 P4_ESCR_EMASK_BIT(P4_EVENT_REPLAY_EVENT
, BOGUS
),
429 .cntr
= { {12, 13, 16}, {14, 15, 17} },
431 [P4_EVENT_INSTR_RETIRED
] = {
432 .opcode
= P4_OPCODE(P4_EVENT_INSTR_RETIRED
),
433 .escr_msr
= { MSR_P4_CRU_ESCR0
, MSR_P4_CRU_ESCR1
},
435 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED
, NBOGUSNTAG
) |
436 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED
, NBOGUSTAG
) |
437 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED
, BOGUSNTAG
) |
438 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED
, BOGUSTAG
),
439 .cntr
= { {12, 13, 16}, {14, 15, 17} },
441 [P4_EVENT_UOPS_RETIRED
] = {
442 .opcode
= P4_OPCODE(P4_EVENT_UOPS_RETIRED
),
443 .escr_msr
= { MSR_P4_CRU_ESCR0
, MSR_P4_CRU_ESCR1
},
445 P4_ESCR_EMASK_BIT(P4_EVENT_UOPS_RETIRED
, NBOGUS
) |
446 P4_ESCR_EMASK_BIT(P4_EVENT_UOPS_RETIRED
, BOGUS
),
447 .cntr
= { {12, 13, 16}, {14, 15, 17} },
449 [P4_EVENT_UOP_TYPE
] = {
450 .opcode
= P4_OPCODE(P4_EVENT_UOP_TYPE
),
451 .escr_msr
= { MSR_P4_RAT_ESCR0
, MSR_P4_RAT_ESCR1
},
453 P4_ESCR_EMASK_BIT(P4_EVENT_UOP_TYPE
, TAGLOADS
) |
454 P4_ESCR_EMASK_BIT(P4_EVENT_UOP_TYPE
, TAGSTORES
),
455 .cntr
= { {12, 13, 16}, {14, 15, 17} },
457 [P4_EVENT_BRANCH_RETIRED
] = {
458 .opcode
= P4_OPCODE(P4_EVENT_BRANCH_RETIRED
),
459 .escr_msr
= { MSR_P4_CRU_ESCR2
, MSR_P4_CRU_ESCR3
},
461 P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED
, MMNP
) |
462 P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED
, MMNM
) |
463 P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED
, MMTP
) |
464 P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED
, MMTM
),
465 .cntr
= { {12, 13, 16}, {14, 15, 17} },
467 [P4_EVENT_MISPRED_BRANCH_RETIRED
] = {
468 .opcode
= P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED
),
469 .escr_msr
= { MSR_P4_CRU_ESCR0
, MSR_P4_CRU_ESCR1
},
471 P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED
, NBOGUS
),
472 .cntr
= { {12, 13, 16}, {14, 15, 17} },
474 [P4_EVENT_X87_ASSIST
] = {
475 .opcode
= P4_OPCODE(P4_EVENT_X87_ASSIST
),
476 .escr_msr
= { MSR_P4_CRU_ESCR2
, MSR_P4_CRU_ESCR3
},
478 P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST
, FPSU
) |
479 P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST
, FPSO
) |
480 P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST
, POAO
) |
481 P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST
, POAU
) |
482 P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST
, PREA
),
483 .cntr
= { {12, 13, 16}, {14, 15, 17} },
485 [P4_EVENT_MACHINE_CLEAR
] = {
486 .opcode
= P4_OPCODE(P4_EVENT_MACHINE_CLEAR
),
487 .escr_msr
= { MSR_P4_CRU_ESCR2
, MSR_P4_CRU_ESCR3
},
489 P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR
, CLEAR
) |
490 P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR
, MOCLEAR
) |
491 P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR
, SMCLEAR
),
492 .cntr
= { {12, 13, 16}, {14, 15, 17} },
494 [P4_EVENT_INSTR_COMPLETED
] = {
495 .opcode
= P4_OPCODE(P4_EVENT_INSTR_COMPLETED
),
496 .escr_msr
= { MSR_P4_CRU_ESCR0
, MSR_P4_CRU_ESCR1
},
498 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_COMPLETED
, NBOGUS
) |
499 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_COMPLETED
, BOGUS
),
500 .cntr
= { {12, 13, 16}, {14, 15, 17} },
504 #define P4_GEN_CACHE_EVENT(event, bit, metric) \
505 p4_config_pack_escr(P4_ESCR_EVENT(event) | \
506 P4_ESCR_EMASK_BIT(event, bit)) | \
507 p4_config_pack_cccr(metric | \
508 P4_CCCR_ESEL(P4_OPCODE_ESEL(P4_OPCODE(event))))
510 static __initconst
const u64 p4_hw_cache_event_ids
511 [PERF_COUNT_HW_CACHE_MAX
]
512 [PERF_COUNT_HW_CACHE_OP_MAX
]
513 [PERF_COUNT_HW_CACHE_RESULT_MAX
] =
517 [ C(RESULT_ACCESS
) ] = 0x0,
518 [ C(RESULT_MISS
) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT
, NBOGUS
,
519 P4_PEBS_METRIC__1stl_cache_load_miss_retired
),
524 [ C(RESULT_ACCESS
) ] = 0x0,
525 [ C(RESULT_MISS
) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT
, NBOGUS
,
526 P4_PEBS_METRIC__2ndl_cache_load_miss_retired
),
531 [ C(RESULT_ACCESS
) ] = 0x0,
532 [ C(RESULT_MISS
) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT
, NBOGUS
,
533 P4_PEBS_METRIC__dtlb_load_miss_retired
),
536 [ C(RESULT_ACCESS
) ] = 0x0,
537 [ C(RESULT_MISS
) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT
, NBOGUS
,
538 P4_PEBS_METRIC__dtlb_store_miss_retired
),
543 [ C(RESULT_ACCESS
) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE
, HIT
,
544 P4_PEBS_METRIC__none
),
545 [ C(RESULT_MISS
) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE
, MISS
,
546 P4_PEBS_METRIC__none
),
549 [ C(RESULT_ACCESS
) ] = -1,
550 [ C(RESULT_MISS
) ] = -1,
552 [ C(OP_PREFETCH
) ] = {
553 [ C(RESULT_ACCESS
) ] = -1,
554 [ C(RESULT_MISS
) ] = -1,
559 static u64 p4_general_events
[PERF_COUNT_HW_MAX
] = {
560 /* non-halted CPU clocks */
561 [PERF_COUNT_HW_CPU_CYCLES
] =
562 p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS
) |
563 P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS
, RUNNING
)),
566 * retired instructions
567 * in a sake of simplicity we don't use the FSB tagging
569 [PERF_COUNT_HW_INSTRUCTIONS
] =
570 p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_INSTR_RETIRED
) |
571 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED
, NBOGUSNTAG
) |
572 P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED
, BOGUSNTAG
)),
575 [PERF_COUNT_HW_CACHE_REFERENCES
] =
576 p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE
) |
577 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_HITS
) |
578 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_HITE
) |
579 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_HITM
) |
580 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_HITS
) |
581 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_HITE
) |
582 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_HITM
)),
585 [PERF_COUNT_HW_CACHE_MISSES
] =
586 p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE
) |
587 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_2ndL_MISS
) |
588 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, RD_3rdL_MISS
) |
589 P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE
, WR_2ndL_MISS
)),
591 /* branch instructions retired */
592 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS
] =
593 p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_RETIRED_BRANCH_TYPE
) |
594 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, CONDITIONAL
) |
595 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, CALL
) |
596 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, RETURN
) |
597 P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE
, INDIRECT
)),
599 /* mispredicted branches retired */
600 [PERF_COUNT_HW_BRANCH_MISSES
] =
601 p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_MISPRED_BRANCH_RETIRED
) |
602 P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED
, NBOGUS
)),
604 /* bus ready clocks (cpu is driving #DRDY_DRV\#DRDY_OWN): */
605 [PERF_COUNT_HW_BUS_CYCLES
] =
606 p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_FSB_DATA_ACTIVITY
) |
607 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DRDY_DRV
) |
608 P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY
, DRDY_OWN
)) |
609 p4_config_pack_cccr(P4_CCCR_EDGE
| P4_CCCR_COMPARE
),
612 static struct p4_event_bind
*p4_config_get_bind(u64 config
)
614 unsigned int evnt
= p4_config_unpack_event(config
);
615 struct p4_event_bind
*bind
= NULL
;
617 if (evnt
< ARRAY_SIZE(p4_event_bind_map
))
618 bind
= &p4_event_bind_map
[evnt
];
623 static u64
p4_pmu_event_map(int hw_event
)
625 struct p4_event_bind
*bind
;
629 config
= p4_general_events
[hw_event
];
630 bind
= p4_config_get_bind(config
);
631 esel
= P4_OPCODE_ESEL(bind
->opcode
);
632 config
|= p4_config_pack_cccr(P4_CCCR_ESEL(esel
));
637 /* check cpu model specifics */
638 static bool p4_event_match_cpu_model(unsigned int event_idx
)
640 /* INSTR_COMPLETED event only exist for model 3, 4, 6 (Prescott) */
641 if (event_idx
== P4_EVENT_INSTR_COMPLETED
) {
642 if (boot_cpu_data
.x86_model
!= 3 &&
643 boot_cpu_data
.x86_model
!= 4 &&
644 boot_cpu_data
.x86_model
!= 6)
650 * - IQ_ESCR0, IQ_ESCR1 only for models 1 and 2
656 static int p4_validate_raw_event(struct perf_event
*event
)
658 unsigned int v
, emask
;
660 /* User data may have out-of-bound event index */
661 v
= p4_config_unpack_event(event
->attr
.config
);
662 if (v
>= ARRAY_SIZE(p4_event_bind_map
))
665 /* It may be unsupported: */
666 if (!p4_event_match_cpu_model(v
))
670 * NOTE: P4_CCCR_THREAD_ANY has not the same meaning as
671 * in Architectural Performance Monitoring, it means not
672 * on _which_ logical cpu to count but rather _when_, ie it
673 * depends on logical cpu state -- count event if one cpu active,
674 * none, both or any, so we just allow user to pass any value
677 * In turn we always set Tx_OS/Tx_USR bits bound to logical
678 * cpu without their propagation to another cpu
682 * if an event is shared accross the logical threads
683 * the user needs special permissions to be able to use it
685 if (p4_event_bind_map
[v
].shared
) {
686 if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN
))
690 /* ESCR EventMask bits may be invalid */
691 emask
= p4_config_unpack_escr(event
->attr
.config
) & P4_ESCR_EVENTMASK_MASK
;
692 if (emask
& ~p4_event_bind_map
[v
].escr_emask
)
696 * it may have some invalid PEBS bits
698 if (p4_config_pebs_has(event
->attr
.config
, P4_PEBS_CONFIG_ENABLE
))
701 v
= p4_config_unpack_metric(event
->attr
.config
);
702 if (v
>= ARRAY_SIZE(p4_pebs_bind_map
))
708 static int p4_hw_config(struct perf_event
*event
)
715 * the reason we use cpu that early is that: if we get scheduled
716 * first time on the same cpu -- we will not need swap thread
717 * specific flags in config (and will save some cpu cycles)
720 cccr
= p4_default_cccr_conf(cpu
);
721 escr
= p4_default_escr_conf(cpu
, event
->attr
.exclude_kernel
,
722 event
->attr
.exclude_user
);
723 event
->hw
.config
= p4_config_pack_escr(escr
) |
724 p4_config_pack_cccr(cccr
);
726 if (p4_ht_active() && p4_ht_thread(cpu
))
727 event
->hw
.config
= p4_set_ht_bit(event
->hw
.config
);
729 if (event
->attr
.type
== PERF_TYPE_RAW
) {
732 * Clear bits we reserve to be managed by kernel itself
733 * and never allowed from a user space
735 event
->attr
.config
&= P4_CONFIG_MASK
;
737 rc
= p4_validate_raw_event(event
);
742 * Note that for RAW events we allow user to use P4_CCCR_RESERVED
743 * bits since we keep additional info here (for cache events and etc)
745 event
->hw
.config
|= event
->attr
.config
;
748 rc
= x86_setup_perfctr(event
);
754 static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event
*hwc
)
759 rdmsr(hwc
->config_base
+ hwc
->idx
, low
, high
);
761 /* we need to check high bit for unflagged overflows */
762 if ((low
& P4_CCCR_OVF
) || !(high
& (1 << 31))) {
764 (void)checking_wrmsrl(hwc
->config_base
+ hwc
->idx
,
765 ((u64
)low
) & ~P4_CCCR_OVF
);
771 static void p4_pmu_disable_pebs(void)
776 * It's still allowed that two threads setup same cache
777 * events so we can't simply clear metrics until we knew
778 * noone is depending on us, so we need kind of counter
779 * for "ReplayEvent" users.
781 * What is more complex -- RAW events, if user (for some
782 * reason) will pass some cache event metric with improper
783 * event opcode -- it's fine from hardware point of view
784 * but completely nonsence from "meaning" of such action.
786 * So at moment let leave metrics turned on forever -- it's
787 * ok for now but need to be revisited!
789 * (void)checking_wrmsrl(MSR_IA32_PEBS_ENABLE, (u64)0);
790 * (void)checking_wrmsrl(MSR_P4_PEBS_MATRIX_VERT, (u64)0);
794 static inline void p4_pmu_disable_event(struct perf_event
*event
)
796 struct hw_perf_event
*hwc
= &event
->hw
;
799 * If event gets disabled while counter is in overflowed
800 * state we need to clear P4_CCCR_OVF, otherwise interrupt get
801 * asserted again and again
803 (void)checking_wrmsrl(hwc
->config_base
+ hwc
->idx
,
804 (u64
)(p4_config_unpack_cccr(hwc
->config
)) &
805 ~P4_CCCR_ENABLE
& ~P4_CCCR_OVF
& ~P4_CCCR_RESERVED
);
808 static void p4_pmu_disable_all(void)
810 struct cpu_hw_events
*cpuc
= &__get_cpu_var(cpu_hw_events
);
813 for (idx
= 0; idx
< x86_pmu
.num_counters
; idx
++) {
814 struct perf_event
*event
= cpuc
->events
[idx
];
815 if (!test_bit(idx
, cpuc
->active_mask
))
817 p4_pmu_disable_event(event
);
820 p4_pmu_disable_pebs();
823 /* configuration must be valid */
824 static void p4_pmu_enable_pebs(u64 config
)
826 struct p4_pebs_bind
*bind
;
829 BUILD_BUG_ON(P4_PEBS_METRIC__max
> P4_PEBS_CONFIG_METRIC_MASK
);
831 idx
= p4_config_unpack_metric(config
);
832 if (idx
== P4_PEBS_METRIC__none
)
835 bind
= &p4_pebs_bind_map
[idx
];
837 (void)checking_wrmsrl(MSR_IA32_PEBS_ENABLE
, (u64
)bind
->metric_pebs
);
838 (void)checking_wrmsrl(MSR_P4_PEBS_MATRIX_VERT
, (u64
)bind
->metric_vert
);
841 static void p4_pmu_enable_event(struct perf_event
*event
)
843 struct hw_perf_event
*hwc
= &event
->hw
;
844 int thread
= p4_ht_config_thread(hwc
->config
);
845 u64 escr_conf
= p4_config_unpack_escr(p4_clear_ht_bit(hwc
->config
));
846 unsigned int idx
= p4_config_unpack_event(hwc
->config
);
847 struct p4_event_bind
*bind
;
850 bind
= &p4_event_bind_map
[idx
];
851 escr_addr
= (u64
)bind
->escr_msr
[thread
];
854 * - we dont support cascaded counters yet
855 * - and counter 1 is broken (erratum)
857 WARN_ON_ONCE(p4_is_event_cascaded(hwc
->config
));
858 WARN_ON_ONCE(hwc
->idx
== 1);
860 /* we need a real Event value */
861 escr_conf
&= ~P4_ESCR_EVENT_MASK
;
862 escr_conf
|= P4_ESCR_EVENT(P4_OPCODE_EVNT(bind
->opcode
));
864 cccr
= p4_config_unpack_cccr(hwc
->config
);
867 * it could be Cache event so we need to write metrics
868 * into additional MSRs
870 p4_pmu_enable_pebs(hwc
->config
);
872 (void)checking_wrmsrl(escr_addr
, escr_conf
);
873 (void)checking_wrmsrl(hwc
->config_base
+ hwc
->idx
,
874 (cccr
& ~P4_CCCR_RESERVED
) | P4_CCCR_ENABLE
);
877 static void p4_pmu_enable_all(int added
)
879 struct cpu_hw_events
*cpuc
= &__get_cpu_var(cpu_hw_events
);
882 for (idx
= 0; idx
< x86_pmu
.num_counters
; idx
++) {
883 struct perf_event
*event
= cpuc
->events
[idx
];
884 if (!test_bit(idx
, cpuc
->active_mask
))
886 p4_pmu_enable_event(event
);
890 static int p4_pmu_handle_irq(struct pt_regs
*regs
)
892 struct perf_sample_data data
;
893 struct cpu_hw_events
*cpuc
;
894 struct perf_event
*event
;
895 struct hw_perf_event
*hwc
;
896 int idx
, handled
= 0;
902 cpuc
= &__get_cpu_var(cpu_hw_events
);
904 for (idx
= 0; idx
< x86_pmu
.num_counters
; idx
++) {
907 if (!test_bit(idx
, cpuc
->active_mask
)) {
908 /* catch in-flight IRQs */
909 if (__test_and_clear_bit(idx
, cpuc
->running
))
914 event
= cpuc
->events
[idx
];
917 WARN_ON_ONCE(hwc
->idx
!= idx
);
919 /* it might be unflagged overflow */
920 overflow
= p4_pmu_clear_cccr_ovf(hwc
);
922 val
= x86_perf_event_update(event
);
923 if (!overflow
&& (val
& (1ULL << (x86_pmu
.cntval_bits
- 1))))
928 /* event overflow for sure */
929 data
.period
= event
->hw
.last_period
;
931 if (!x86_perf_event_set_period(event
))
933 if (perf_event_overflow(event
, 1, &data
, regs
))
934 p4_pmu_disable_event(event
);
938 /* p4 quirk: unmask it again */
939 apic_write(APIC_LVTPC
, apic_read(APIC_LVTPC
) & ~APIC_LVT_MASKED
);
940 inc_irq_stat(apic_perf_irqs
);
947 * swap thread specific fields according to a thread
948 * we are going to run on
950 static void p4_pmu_swap_config_ts(struct hw_perf_event
*hwc
, int cpu
)
955 * we either lucky and continue on same cpu or no HT support
957 if (!p4_should_swap_ts(hwc
->config
, cpu
))
961 * the event is migrated from an another logical
962 * cpu, so we need to swap thread specific flags
965 escr
= p4_config_unpack_escr(hwc
->config
);
966 cccr
= p4_config_unpack_cccr(hwc
->config
);
968 if (p4_ht_thread(cpu
)) {
969 cccr
&= ~P4_CCCR_OVF_PMI_T0
;
970 cccr
|= P4_CCCR_OVF_PMI_T1
;
971 if (escr
& P4_ESCR_T0_OS
) {
972 escr
&= ~P4_ESCR_T0_OS
;
973 escr
|= P4_ESCR_T1_OS
;
975 if (escr
& P4_ESCR_T0_USR
) {
976 escr
&= ~P4_ESCR_T0_USR
;
977 escr
|= P4_ESCR_T1_USR
;
979 hwc
->config
= p4_config_pack_escr(escr
);
980 hwc
->config
|= p4_config_pack_cccr(cccr
);
981 hwc
->config
|= P4_CONFIG_HT
;
983 cccr
&= ~P4_CCCR_OVF_PMI_T1
;
984 cccr
|= P4_CCCR_OVF_PMI_T0
;
985 if (escr
& P4_ESCR_T1_OS
) {
986 escr
&= ~P4_ESCR_T1_OS
;
987 escr
|= P4_ESCR_T0_OS
;
989 if (escr
& P4_ESCR_T1_USR
) {
990 escr
&= ~P4_ESCR_T1_USR
;
991 escr
|= P4_ESCR_T0_USR
;
993 hwc
->config
= p4_config_pack_escr(escr
);
994 hwc
->config
|= p4_config_pack_cccr(cccr
);
995 hwc
->config
&= ~P4_CONFIG_HT
;
1000 * ESCR address hashing is tricky, ESCRs are not sequential
1001 * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03a0) and
1002 * the metric between any ESCRs is laid in range [0xa0,0xe1]
1004 * so we make ~70% filled hashtable
1007 #define P4_ESCR_MSR_BASE 0x000003a0
1008 #define P4_ESCR_MSR_MAX 0x000003e1
1009 #define P4_ESCR_MSR_TABLE_SIZE (P4_ESCR_MSR_MAX - P4_ESCR_MSR_BASE + 1)
1010 #define P4_ESCR_MSR_IDX(msr) (msr - P4_ESCR_MSR_BASE)
1011 #define P4_ESCR_MSR_TABLE_ENTRY(msr) [P4_ESCR_MSR_IDX(msr)] = msr
1013 static const unsigned int p4_escr_table
[P4_ESCR_MSR_TABLE_SIZE
] = {
1014 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR0
),
1015 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR1
),
1016 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR0
),
1017 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR1
),
1018 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR0
),
1019 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR1
),
1020 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR0
),
1021 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR1
),
1022 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR2
),
1023 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR3
),
1024 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR4
),
1025 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR5
),
1026 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR0
),
1027 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR1
),
1028 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR0
),
1029 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR1
),
1030 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR0
),
1031 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR1
),
1032 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR0
),
1033 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR1
),
1034 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR0
),
1035 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR1
),
1036 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR0
),
1037 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR1
),
1038 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR0
),
1039 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR1
),
1040 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR0
),
1041 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR1
),
1042 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR0
),
1043 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR1
),
1044 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR0
),
1045 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR1
),
1046 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR0
),
1047 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR1
),
1048 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR0
),
1049 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR1
),
1050 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR0
),
1051 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR1
),
1052 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR0
),
1053 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR1
),
1054 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR0
),
1055 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR1
),
1056 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR0
),
1057 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR1
),
1058 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR0
),
1059 P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR1
),
1062 static int p4_get_escr_idx(unsigned int addr
)
1064 unsigned int idx
= P4_ESCR_MSR_IDX(addr
);
1066 if (unlikely(idx
>= P4_ESCR_MSR_TABLE_SIZE
||
1067 !p4_escr_table
[idx
] ||
1068 p4_escr_table
[idx
] != addr
)) {
1069 WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr
);
1076 static int p4_next_cntr(int thread
, unsigned long *used_mask
,
1077 struct p4_event_bind
*bind
)
1081 for (i
= 0; i
< P4_CNTR_LIMIT
; i
++) {
1082 j
= bind
->cntr
[thread
][i
];
1083 if (j
!= -1 && !test_bit(j
, used_mask
))
1090 static int p4_pmu_schedule_events(struct cpu_hw_events
*cpuc
, int n
, int *assign
)
1092 unsigned long used_mask
[BITS_TO_LONGS(X86_PMC_IDX_MAX
)];
1093 unsigned long escr_mask
[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE
)];
1094 int cpu
= smp_processor_id();
1095 struct hw_perf_event
*hwc
;
1096 struct p4_event_bind
*bind
;
1097 unsigned int i
, thread
, num
;
1098 int cntr_idx
, escr_idx
;
1100 bitmap_zero(used_mask
, X86_PMC_IDX_MAX
);
1101 bitmap_zero(escr_mask
, P4_ESCR_MSR_TABLE_SIZE
);
1103 for (i
= 0, num
= n
; i
< n
; i
++, num
--) {
1105 hwc
= &cpuc
->event_list
[i
]->hw
;
1106 thread
= p4_ht_thread(cpu
);
1107 bind
= p4_config_get_bind(hwc
->config
);
1108 escr_idx
= p4_get_escr_idx(bind
->escr_msr
[thread
]);
1109 if (unlikely(escr_idx
== -1))
1112 if (hwc
->idx
!= -1 && !p4_should_swap_ts(hwc
->config
, cpu
)) {
1113 cntr_idx
= hwc
->idx
;
1115 assign
[i
] = hwc
->idx
;
1119 cntr_idx
= p4_next_cntr(thread
, used_mask
, bind
);
1120 if (cntr_idx
== -1 || test_bit(escr_idx
, escr_mask
))
1123 p4_pmu_swap_config_ts(hwc
, cpu
);
1125 assign
[i
] = cntr_idx
;
1127 set_bit(cntr_idx
, used_mask
);
1128 set_bit(escr_idx
, escr_mask
);
1132 return num
? -ENOSPC
: 0;
1135 static __initconst
const struct x86_pmu p4_pmu
= {
1136 .name
= "Netburst P4/Xeon",
1137 .handle_irq
= p4_pmu_handle_irq
,
1138 .disable_all
= p4_pmu_disable_all
,
1139 .enable_all
= p4_pmu_enable_all
,
1140 .enable
= p4_pmu_enable_event
,
1141 .disable
= p4_pmu_disable_event
,
1142 .eventsel
= MSR_P4_BPU_CCCR0
,
1143 .perfctr
= MSR_P4_BPU_PERFCTR0
,
1144 .event_map
= p4_pmu_event_map
,
1145 .max_events
= ARRAY_SIZE(p4_general_events
),
1146 .get_event_constraints
= x86_get_event_constraints
,
1148 * IF HT disabled we may need to use all
1149 * ARCH_P4_MAX_CCCR counters simulaneously
1150 * though leave it restricted at moment assuming
1153 .num_counters
= ARCH_P4_MAX_CCCR
,
1156 .cntval_mask
= (1ULL << 40) - 1,
1157 .max_period
= (1ULL << 39) - 1,
1158 .hw_config
= p4_hw_config
,
1159 .schedule_events
= p4_pmu_schedule_events
,
1161 * This handles erratum N15 in intel doc 249199-029,
1162 * the counter may not be updated correctly on write
1163 * so we need a second write operation to do the trick
1164 * (the official workaround didn't work)
1166 * the former idea is taken from OProfile code
1168 .perfctr_second_write
= 1,
1171 static __init
int p4_pmu_init(void)
1173 unsigned int low
, high
;
1175 /* If we get stripped -- indexig fails */
1176 BUILD_BUG_ON(ARCH_P4_MAX_CCCR
> X86_PMC_MAX_GENERIC
);
1178 rdmsr(MSR_IA32_MISC_ENABLE
, low
, high
);
1179 if (!(low
& (1 << 7))) {
1180 pr_cont("unsupported Netburst CPU model %d ",
1181 boot_cpu_data
.x86_model
);
1185 memcpy(hw_cache_event_ids
, p4_hw_cache_event_ids
,
1186 sizeof(hw_cache_event_ids
));
1188 pr_cont("Netburst events, ");
1195 #endif /* CONFIG_CPU_SUP_INTEL */