2 * Copyright 2014, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
14 * Test of counting cycles while using MMCR0_FC (freeze counters) to only count
15 * parts of the code. This is complicated by the fact that FC is set by the
16 * hardware when the event overflows. We may take the EBB after we have set FC,
17 * so we have to be careful about whether we clear FC at the end of the EBB
21 static bool counters_frozen
= false;
22 static int ebbs_while_frozen
= 0;
24 static void ebb_callee(void)
28 mask
= MMCR0_PMAO
| MMCR0_FC
;
30 val
= mfspr(SPRN_BESCR
);
31 if (!(val
& BESCR_PMEO
)) {
32 ebb_state
.stats
.spurious
++;
36 ebb_state
.stats
.ebb_count
++;
37 trace_log_counter(ebb_state
.trace
, ebb_state
.stats
.ebb_count
);
39 val
= mfspr(SPRN_MMCR0
);
40 trace_log_reg(ebb_state
.trace
, SPRN_MMCR0
, val
);
42 if (counters_frozen
) {
43 trace_log_string(ebb_state
.trace
, "frozen");
48 count_pmc(1, sample_period
);
50 reset_ebb_with_clear_mask(mask
);
53 int cycles_with_freeze(void)
59 SKIP_IF(!ebb_is_supported());
61 event_init_named(&event
, 0x1001e, "cycles");
62 event_leader_ebb_init(&event
);
64 event
.attr
.exclude_kernel
= 1;
65 event
.attr
.exclude_hv
= 1;
66 event
.attr
.exclude_idle
= 1;
68 FAIL_IF(event_open(&event
));
70 setup_ebb_handler(ebb_callee
);
72 FAIL_IF(ebb_event_enable(&event
));
74 mtspr(SPRN_PMC1
, pmc_sample_period(sample_period
));
78 /* Make sure we loop until we take at least one EBB */
79 while ((ebb_state
.stats
.ebb_count
< 20 && !fc_cleared
) ||
80 ebb_state
.stats
.ebb_count
< 1)
82 counters_frozen
= false;
84 mtspr(SPRN_MMCR0
, mfspr(SPRN_MMCR0
) & ~MMCR0_FC
);
86 FAIL_IF(core_busy_loop());
88 counters_frozen
= true;
90 mtspr(SPRN_MMCR0
, mfspr(SPRN_MMCR0
) | MMCR0_FC
);
92 val
= mfspr(SPRN_MMCR0
);
93 if (! (val
& MMCR0_FC
)) {
94 printf("Outside of loop, FC NOT set MMCR0 0x%lx\n", val
);
102 count_pmc(1, sample_period
);
106 printf("EBBs while frozen %d\n", ebbs_while_frozen
);
110 FAIL_IF(ebb_state
.stats
.ebb_count
== 0);
118 return test_harness(cycles_with_freeze
, "cycles_with_freeze");
This page took 0.05808 seconds and 5 git commands to generate.