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 /*
0019  * A perf sampling test for mmcra
0020  * field: bhrb_disable.
0021  */
0022 static int mmcra_bhrb_disable_test(void)
0023 {
0024     struct event event;
0025     u64 *intr_regs;
0026 
0027     /*
0028      * Check for platform support for the test.
0029      * This test is only aplicable on power10
0030      */
0031     SKIP_IF(check_pvr_for_sampling_tests());
0032     SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1));
0033 
0034      /* Init the event for the sampling test */
0035     event_init_sampling(&event, EventCode);
0036     event.attr.sample_regs_intr = platform_extended_mask;
0037     event.attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
0038     event.attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY;
0039     event.attr.exclude_kernel = 1;
0040 
0041     FAIL_IF(event_open(&event));
0042     event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
0043 
0044     FAIL_IF(event_enable(&event));
0045 
0046     /* workload to make the event overflow */
0047     thirty_two_instruction_loop(10000);
0048 
0049     FAIL_IF(event_disable(&event));
0050 
0051     intr_regs = get_intr_regs(&event, event.mmap_buffer);
0052 
0053     /* Check for intr_regs */
0054     FAIL_IF(!intr_regs);
0055 
0056     /* Verify that bhrb_disable bit is set in MMCRA */
0057     FAIL_IF(get_mmcra_bhrb_disable(get_reg_value(intr_regs, "MMCRA"), 5));
0058 
0059     event_close(&event);
0060     return 0;
0061 }
0062 
0063 int main(void)
0064 {
0065     return test_harness(mmcra_bhrb_disable_test, "mmcra_bhrb_disable_test");
0066 }