@@ -89,11 +89,11 @@ static u64 counter_start_values[] = {
89
89
0xffffffffffff ,
90
90
};
91
91
92
- static unsigned int get_adaptive_pebs_record_size (u64 pebs_data_cfg )
92
+ static unsigned int get_pebs_record_size (u64 pebs_data_cfg , bool use_adaptive )
93
93
{
94
94
unsigned int sz = sizeof (struct pebs_basic );
95
95
96
- if (!has_baseline )
96
+ if (!use_adaptive )
97
97
return sz ;
98
98
99
99
if (pebs_data_cfg & PEBS_DATACFG_MEMINFO )
@@ -199,10 +199,10 @@ static void free_buffers(void)
199
199
free_page (pebs_buffer );
200
200
}
201
201
202
- static void pebs_enable (u64 bitmask , u64 pebs_data_cfg )
202
+ static void pebs_enable (u64 bitmask , u64 pebs_data_cfg , bool use_adaptive )
203
203
{
204
204
static struct debug_store * ds ;
205
- u64 baseline_extra_ctrl = 0 , fixed_ctr_ctrl = 0 ;
205
+ u64 adaptive_ctrl = 0 , fixed_ctr_ctrl = 0 ;
206
206
unsigned int idx ;
207
207
208
208
if (has_baseline )
@@ -212,26 +212,26 @@ static void pebs_enable(u64 bitmask, u64 pebs_data_cfg)
212
212
ds -> pebs_index = ds -> pebs_buffer_base = (unsigned long )pebs_buffer ;
213
213
ds -> pebs_absolute_maximum = (unsigned long )pebs_buffer + PAGE_SIZE ;
214
214
ds -> pebs_interrupt_threshold = ds -> pebs_buffer_base +
215
- get_adaptive_pebs_record_size (pebs_data_cfg );
215
+ get_pebs_record_size (pebs_data_cfg , use_adaptive );
216
216
217
217
for (idx = 0 ; idx < pmu .nr_fixed_counters ; idx ++ ) {
218
218
if (!(BIT_ULL (FIXED_CNT_INDEX + idx ) & bitmask ))
219
219
continue ;
220
- if (has_baseline )
221
- baseline_extra_ctrl = BIT (FIXED_CNT_INDEX + idx * 4 );
220
+ if (use_adaptive )
221
+ adaptive_ctrl = BIT (FIXED_CNT_INDEX + idx * 4 );
222
222
wrmsr (MSR_PERF_FIXED_CTRx (idx ), ctr_start_val );
223
- fixed_ctr_ctrl |= (0xbULL << (idx * 4 ) | baseline_extra_ctrl );
223
+ fixed_ctr_ctrl |= (0xbULL << (idx * 4 ) | adaptive_ctrl );
224
224
}
225
225
if (fixed_ctr_ctrl )
226
226
wrmsr (MSR_CORE_PERF_FIXED_CTR_CTRL , fixed_ctr_ctrl );
227
227
228
228
for (idx = 0 ; idx < max_nr_gp_events ; idx ++ ) {
229
229
if (!(BIT_ULL (idx ) & bitmask ))
230
230
continue ;
231
- if (has_baseline )
232
- baseline_extra_ctrl = ICL_EVENTSEL_ADAPTIVE ;
231
+ if (use_adaptive )
232
+ adaptive_ctrl = ICL_EVENTSEL_ADAPTIVE ;
233
233
wrmsr (MSR_GP_EVENT_SELECTx (idx ), EVNTSEL_EN | EVNTSEL_OS | EVNTSEL_USR |
234
- intel_arch_events [idx ] | baseline_extra_ctrl );
234
+ intel_arch_events [idx ] | adaptive_ctrl );
235
235
wrmsr (MSR_GP_COUNTERx (idx ), ctr_start_val );
236
236
}
237
237
@@ -268,11 +268,11 @@ static void pebs_disable(unsigned int idx)
268
268
wrmsr (MSR_CORE_PERF_GLOBAL_CTRL , 0 );
269
269
}
270
270
271
- static void check_pebs_records (u64 bitmask , u64 pebs_data_cfg )
271
+ static void check_pebs_records (u64 bitmask , u64 pebs_data_cfg , bool use_adaptive )
272
272
{
273
273
struct pebs_basic * pebs_rec = (struct pebs_basic * )pebs_buffer ;
274
274
struct debug_store * ds = (struct debug_store * )ds_bufer ;
275
- unsigned int pebs_record_size = get_adaptive_pebs_record_size ( pebs_data_cfg ) ;
275
+ unsigned int pebs_record_size ;
276
276
unsigned int count = 0 ;
277
277
bool expected , pebs_idx_match , pebs_size_match , data_cfg_match ;
278
278
void * cur_record ;
@@ -293,12 +293,9 @@ static void check_pebs_records(u64 bitmask, u64 pebs_data_cfg)
293
293
do {
294
294
pebs_rec = (struct pebs_basic * )cur_record ;
295
295
pebs_record_size = pebs_rec -> format_size >> RECORD_SIZE_OFFSET ;
296
- pebs_idx_match =
297
- pebs_rec -> applicable_counters & bitmask ;
298
- pebs_size_match =
299
- pebs_record_size == get_adaptive_pebs_record_size (pebs_data_cfg );
300
- data_cfg_match =
301
- (pebs_rec -> format_size & GENMASK_ULL (47 , 0 )) == pebs_data_cfg ;
296
+ pebs_idx_match = pebs_rec -> applicable_counters & bitmask ;
297
+ pebs_size_match = pebs_record_size == get_pebs_record_size (pebs_data_cfg , use_adaptive );
298
+ data_cfg_match = (pebs_rec -> format_size & GENMASK_ULL (47 , 0 )) == pebs_data_cfg ;
302
299
expected = pebs_idx_match && pebs_size_match && data_cfg_match ;
303
300
report (expected ,
304
301
"PEBS record (written seq %d) is verified (including size, counters and cfg)." , count );
@@ -311,56 +308,57 @@ static void check_pebs_records(u64 bitmask, u64 pebs_data_cfg)
311
308
printf ("FAIL: The applicable_counters (0x%lx) doesn't match with pmc_bitmask (0x%lx).\n" ,
312
309
pebs_rec -> applicable_counters , bitmask );
313
310
if (!pebs_size_match )
314
- printf ("FAIL: The pebs_record_size (%d) doesn't match with MSR_PEBS_DATA_CFG (%d).\n" ,
315
- pebs_record_size , get_adaptive_pebs_record_size (pebs_data_cfg ));
311
+ printf ("FAIL: The pebs_record_size (%d) doesn't match with expected record size (%d).\n" ,
312
+ pebs_record_size , get_pebs_record_size (pebs_data_cfg , use_adaptive ));
316
313
if (!data_cfg_match )
317
- printf ("FAIL: The pebs_data_cfg (0x%lx) doesn't match with MSR_PEBS_DATA_CFG (0x%lx).\n" ,
318
- pebs_rec -> format_size & 0xffffffffffff , pebs_data_cfg );
314
+ printf ("FAIL: The pebs_data_cfg (0x%lx) doesn't match with the effective MSR_PEBS_DATA_CFG (0x%lx).\n" ,
315
+ pebs_rec -> format_size & 0xffffffffffff , use_adaptive ? pebs_data_cfg : 0 );
319
316
}
320
317
}
321
318
322
- static void check_one_counter (enum pmc_type type ,
323
- unsigned int idx , u64 pebs_data_cfg )
319
+ static void check_one_counter (enum pmc_type type , unsigned int idx ,
320
+ u64 pebs_data_cfg , bool use_adaptive )
324
321
{
325
322
int pebs_bit = BIT_ULL (type == FIXED ? FIXED_CNT_INDEX + idx : idx );
326
323
327
324
report_prefix_pushf ("%s counter %d (0x%lx)" ,
328
325
type == FIXED ? "Extended Fixed" : "GP" , idx , ctr_start_val );
329
326
reset_pebs ();
330
- pebs_enable (pebs_bit , pebs_data_cfg );
327
+ pebs_enable (pebs_bit , pebs_data_cfg , use_adaptive );
331
328
workload ();
332
329
pebs_disable (idx );
333
- check_pebs_records (pebs_bit , pebs_data_cfg );
330
+ check_pebs_records (pebs_bit , pebs_data_cfg , use_adaptive );
334
331
report_prefix_pop ();
335
332
}
336
333
337
334
/* more than one PEBS records will be generated. */
338
- static void check_multiple_counters (u64 bitmask , u64 pebs_data_cfg )
335
+ static void check_multiple_counters (u64 bitmask , u64 pebs_data_cfg ,
336
+ bool use_adaptive )
339
337
{
340
338
reset_pebs ();
341
- pebs_enable (bitmask , pebs_data_cfg );
339
+ pebs_enable (bitmask , pebs_data_cfg , use_adaptive );
342
340
workload2 ();
343
341
pebs_disable (0 );
344
- check_pebs_records (bitmask , pebs_data_cfg );
342
+ check_pebs_records (bitmask , pebs_data_cfg , use_adaptive );
345
343
}
346
344
347
- static void check_pebs_counters (u64 pebs_data_cfg )
345
+ static void check_pebs_counters (u64 pebs_data_cfg , bool use_adaptive )
348
346
{
349
347
unsigned int idx ;
350
348
u64 bitmask = 0 ;
351
349
352
350
for (idx = 0 ; has_baseline && idx < pmu .nr_fixed_counters ; idx ++ )
353
- check_one_counter (FIXED , idx , pebs_data_cfg );
351
+ check_one_counter (FIXED , idx , pebs_data_cfg , use_adaptive );
354
352
355
353
for (idx = 0 ; idx < max_nr_gp_events ; idx ++ )
356
- check_one_counter (GP , idx , pebs_data_cfg );
354
+ check_one_counter (GP , idx , pebs_data_cfg , use_adaptive );
357
355
358
356
for (idx = 0 ; has_baseline && idx < pmu .nr_fixed_counters ; idx ++ )
359
357
bitmask |= BIT_ULL (FIXED_CNT_INDEX + idx );
360
358
for (idx = 0 ; idx < max_nr_gp_events ; idx += 2 )
361
359
bitmask |= BIT_ULL (idx );
362
360
report_prefix_pushf ("Multiple (0x%lx)" , bitmask );
363
- check_multiple_counters (bitmask , pebs_data_cfg );
361
+ check_multiple_counters (bitmask , pebs_data_cfg , use_adaptive );
364
362
report_prefix_pop ();
365
363
}
366
364
@@ -408,7 +406,7 @@ int main(int ac, char **av)
408
406
409
407
for (i = 0 ; i < ARRAY_SIZE (counter_start_values ); i ++ ) {
410
408
ctr_start_val = counter_start_values [i ];
411
- check_pebs_counters (0 );
409
+ check_pebs_counters (0 , false );
412
410
if (!has_baseline )
413
411
continue ;
414
412
@@ -419,7 +417,11 @@ int main(int ac, char **av)
419
417
pebs_data_cfg |= ((MAX_NUM_LBR_ENTRY - 1 ) << PEBS_DATACFG_LBR_SHIFT );
420
418
421
419
report_prefix_pushf ("Adaptive (0x%lx)" , pebs_data_cfg );
422
- check_pebs_counters (pebs_data_cfg );
420
+ check_pebs_counters (pebs_data_cfg , true);
421
+ report_prefix_pop ();
422
+
423
+ report_prefix_pushf ("Ignored Adaptive (0x%lx)" , pebs_data_cfg );
424
+ check_pebs_counters (pebs_data_cfg , false);
423
425
report_prefix_pop ();
424
426
}
425
427
}
0 commit comments