Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2022, Kajol Jain, IBM Corp.
0004  */
0005 
0006 #include <stdio.h>
0007 #include <stdlib.h>
0008 
0009 #include "../event.h"
0010 #include "misc.h"
0011 #include "utils.h"
0012 
0013 extern void thirty_two_instruction_loop(int loops);
0014 
0015 /* Instructions */
0016 #define EventCode 0x500fa
0017 
0018 /* ifm field for conditional branch mode */
0019 #define IFM_COND_BRANCH 0x3
0020 
0021 /*
0022  * A perf sampling test for mmcra
0023  * field: ifm for bhrb cond call.
0024  */
0025 static int mmcra_bhrb_cond_test(void)
0026 {
0027     struct event event;
0028     u64 *intr_regs;
0029 
0030     /*
0031      * Check for platform support for the test.
0032      * This test is only aplicable on power10
0033      */
0034     SKIP_IF(check_pvr_for_sampling_tests());
0035     SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1));
0036 
0037      /* Init the event for the sampling test */
0038     event_init_sampling(&event, EventCode);
0039     event.attr.sample_regs_intr = platform_extended_mask;
0040     event.attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
0041     event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_COND;
0042     event.attr.exclude_kernel = 1;
0043 
0044     FAIL_IF(event_open(&event));
0045     event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
0046 
0047     FAIL_IF(event_enable(&event));
0048 
0049     /* workload to make the event overflow */
0050     thirty_two_instruction_loop(10000);
0051 
0052     FAIL_IF(event_disable(&event));
0053 
0054     intr_regs = get_intr_regs(&event, event.mmap_buffer);
0055 
0056     /* Check for intr_regs */
0057     FAIL_IF(!intr_regs);
0058 
0059     /* Verify that ifm bit is set properly in MMCRA */
0060     FAIL_IF(get_mmcra_ifm(get_reg_value(intr_regs, "MMCRA"), 5) != IFM_COND_BRANCH);
0061 
0062     event_close(&event);
0063     return 0;
0064 }
0065 
0066 int main(void)
0067 {
0068     return test_harness(mmcra_bhrb_cond_test, "mmcra_bhrb_cond_test");
0069 }