2 * Copyright 2014, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
14 * Test of counting cycles while manipulating the user accessible bits in MMCR2.
17 /* We use two values because the first freezes PMC1 and so we would get no EBBs */
18 #define MMCR2_EXPECTED_1 0x4020100804020000UL /* (FC1P|FC2P|FC3P|FC4P|FC5P|FC6P) */
19 #define MMCR2_EXPECTED_2 0x0020100804020000UL /* ( FC2P|FC3P|FC4P|FC5P|FC6P) */
22 int cycles_with_mmcr2(void)
25 uint64_t val, expected[2], actual;
29 event_init_named(&event, 0x1001e, "cycles");
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(1);
39 setup_ebb_handler(standard_ebb_callee);
42 FAIL_IF(ebb_event_enable(&event));
44 mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
46 /* XXX Set of MMCR2 must be after enable */
47 expected[0] = MMCR2_EXPECTED_1;
48 expected[1] = MMCR2_EXPECTED_2;
52 /* Make sure we loop until we take at least one EBB */
53 while ((ebb_state.stats.ebb_count < 20 && !bad_mmcr2) ||
54 ebb_state.stats.ebb_count < 1)
56 mtspr(SPRN_MMCR2, expected[i % 2]);
58 FAIL_IF(core_busy_loop());
60 val = mfspr(SPRN_MMCR2);
61 if (val != expected[i % 2]) {
72 count_pmc(1, sample_period);
78 FAIL_IF(ebb_state.stats.ebb_count == 0);
81 printf("Bad MMCR2 value seen is 0x%lx\n", actual);
90 return test_harness(cycles_with_mmcr2, "cycles_with_mmcr2");