Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2014, Michael Ellerman, IBM Corp.
0004  */
0005 
0006 #include <stdio.h>
0007 #include <stdlib.h>
0008 #include <stdbool.h>
0009 
0010 #include "ebb.h"
0011 
0012 
0013 /*
0014  * Test of counting cycles while manipulating the user accessible bits in MMCR2.
0015  */
0016 
0017 /* We use two values because the first freezes PMC1 and so we would get no EBBs */
0018 #define MMCR2_EXPECTED_1 0x4020100804020000UL /* (FC1P|FC2P|FC3P|FC4P|FC5P|FC6P) */
0019 #define MMCR2_EXPECTED_2 0x0020100804020000UL /* (     FC2P|FC3P|FC4P|FC5P|FC6P) */
0020 
0021 
0022 int cycles_with_mmcr2(void)
0023 {
0024     struct event event;
0025     uint64_t val, expected[2], actual;
0026     int i;
0027     bool bad_mmcr2;
0028 
0029     SKIP_IF(!ebb_is_supported());
0030 
0031     event_init_named(&event, 0x1001e, "cycles");
0032     event_leader_ebb_init(&event);
0033 
0034     event.attr.exclude_kernel = 1;
0035     event.attr.exclude_hv = 1;
0036     event.attr.exclude_idle = 1;
0037 
0038     FAIL_IF(event_open(&event));
0039 
0040     ebb_enable_pmc_counting(1);
0041     setup_ebb_handler(standard_ebb_callee);
0042     ebb_global_enable();
0043 
0044     FAIL_IF(ebb_event_enable(&event));
0045 
0046     mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
0047 
0048     /* XXX Set of MMCR2 must be after enable */
0049     expected[0] = MMCR2_EXPECTED_1;
0050     expected[1] = MMCR2_EXPECTED_2;
0051     i = 0;
0052     bad_mmcr2 = false;
0053     actual = 0;
0054 
0055     /* Make sure we loop until we take at least one EBB */
0056     while ((ebb_state.stats.ebb_count < 20 && !bad_mmcr2) ||
0057         ebb_state.stats.ebb_count < 1)
0058     {
0059         mtspr(SPRN_MMCR2, expected[i % 2]);
0060 
0061         FAIL_IF(core_busy_loop());
0062 
0063         val = mfspr(SPRN_MMCR2);
0064         if (val != expected[i % 2]) {
0065             bad_mmcr2 = true;
0066             actual = val;
0067         }
0068 
0069         i++;
0070     }
0071 
0072     ebb_global_disable();
0073     ebb_freeze_pmcs();
0074 
0075     dump_ebb_state();
0076 
0077     event_close(&event);
0078 
0079     FAIL_IF(ebb_state.stats.ebb_count == 0);
0080 
0081     if (bad_mmcr2)
0082         printf("Bad MMCR2 value seen is 0x%lx\n", actual);
0083 
0084     FAIL_IF(bad_mmcr2);
0085 
0086     return 0;
0087 }
0088 
0089 int main(void)
0090 {
0091     return test_harness(cycles_with_mmcr2, "cycles_with_mmcr2");
0092 }