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 <sys/ioctl.h>
0009 
0010 #include "ebb.h"
0011 
0012 
0013 /*
0014  * Test counting multiple events using EBBs.
0015  */
0016 int multi_counter(void)
0017 {
0018     struct event events[6];
0019     int i, group_fd;
0020 
0021     SKIP_IF(!ebb_is_supported());
0022 
0023     event_init_named(&events[0], 0x1001C, "PM_CMPLU_STALL_THRD");
0024     event_init_named(&events[1], 0x2D016, "PM_CMPLU_STALL_FXU");
0025     event_init_named(&events[2], 0x30006, "PM_CMPLU_STALL_OTHER_CMPL");
0026     event_init_named(&events[3], 0x4000A, "PM_CMPLU_STALL");
0027     event_init_named(&events[4], 0x600f4, "PM_RUN_CYC");
0028     event_init_named(&events[5], 0x500fa, "PM_RUN_INST_CMPL");
0029 
0030     event_leader_ebb_init(&events[0]);
0031     for (i = 1; i < 6; i++)
0032         event_ebb_init(&events[i]);
0033 
0034     group_fd = -1;
0035     for (i = 0; i < 6; i++) {
0036         events[i].attr.exclude_kernel = 1;
0037         events[i].attr.exclude_hv = 1;
0038         events[i].attr.exclude_idle = 1;
0039 
0040         FAIL_IF(event_open_with_group(&events[i], group_fd));
0041         if (group_fd == -1)
0042             group_fd = events[0].fd;
0043     }
0044 
0045     ebb_enable_pmc_counting(1);
0046     ebb_enable_pmc_counting(2);
0047     ebb_enable_pmc_counting(3);
0048     ebb_enable_pmc_counting(4);
0049     ebb_enable_pmc_counting(5);
0050     ebb_enable_pmc_counting(6);
0051     setup_ebb_handler(standard_ebb_callee);
0052 
0053     FAIL_IF(ioctl(events[0].fd, PERF_EVENT_IOC_ENABLE, PERF_IOC_FLAG_GROUP));
0054     FAIL_IF(event_read(&events[0]));
0055 
0056     ebb_global_enable();
0057 
0058     mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
0059     mtspr(SPRN_PMC2, pmc_sample_period(sample_period));
0060     mtspr(SPRN_PMC3, pmc_sample_period(sample_period));
0061     mtspr(SPRN_PMC4, pmc_sample_period(sample_period));
0062     mtspr(SPRN_PMC5, pmc_sample_period(sample_period));
0063     mtspr(SPRN_PMC6, pmc_sample_period(sample_period));
0064 
0065     while (ebb_state.stats.ebb_count < 50) {
0066         FAIL_IF(core_busy_loop());
0067         FAIL_IF(ebb_check_mmcr0());
0068     }
0069 
0070     ebb_global_disable();
0071     ebb_freeze_pmcs();
0072 
0073     dump_ebb_state();
0074 
0075     for (i = 0; i < 6; i++)
0076         event_close(&events[i]);
0077 
0078     FAIL_IF(ebb_state.stats.ebb_count == 0);
0079 
0080     return 0;
0081 }
0082 
0083 int main(void)
0084 {
0085     return test_harness(multi_counter, "multi_counter");
0086 }