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