2 * Copyright 2014, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
16 * Test that tries to trigger CPU_FTR_PMAO_BUG. Which is a hardware defect
17 * where an exception triggers but we context switch before it is delivered and
21 static int test_body(void)
23 int i
, orig_period
, max_period
;
26 SKIP_IF(!ebb_is_supported());
28 /* We use PMC4 to make sure the kernel switches all counters correctly */
29 event_init_named(&event
, 0x40002, "instructions");
30 event_leader_ebb_init(&event
);
32 event
.attr
.exclude_kernel
= 1;
33 event
.attr
.exclude_hv
= 1;
34 event
.attr
.exclude_idle
= 1;
36 FAIL_IF(event_open(&event
));
38 ebb_enable_pmc_counting(4);
39 setup_ebb_handler(standard_ebb_callee
);
41 FAIL_IF(ebb_event_enable(&event
));
44 * We want a low sample period, but we also want to get out of the EBB
45 * handler without tripping up again.
47 * This value picked after much experimentation.
49 orig_period
= max_period
= sample_period
= 400;
51 mtspr(SPRN_PMC4
, pmc_sample_period(sample_period
));
53 while (ebb_state
.stats
.ebb_count
< 1000000) {
55 * We are trying to get the EBB exception to race exactly with
56 * us entering the kernel to do the syscall. We then need the
57 * kernel to decide our timeslice is up and context switch to
58 * the other thread. When we come back our EBB will have been
59 * lost and we'll spin in this while loop forever.
62 for (i
= 0; i
< 100000; i
++)
65 /* Change the sample period slightly to try and hit the race */
66 if (sample_period
>= (orig_period
+ 200))
67 sample_period
= orig_period
;
71 if (sample_period
> max_period
)
72 max_period
= sample_period
;
78 count_pmc(4, sample_period
);
79 mtspr(SPRN_PMC4
, 0xdead);
81 dump_summary_ebb_state();
86 FAIL_IF(ebb_state
.stats
.ebb_count
== 0);
88 /* We vary our sample period so we need extra fudge here */
89 FAIL_IF(!ebb_check_count(4, orig_period
, 2 * (max_period
- orig_period
)));
94 static int lost_exception(void)
96 return eat_cpu(test_body
);
101 return test_harness(lost_exception
, "lost_exception");