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_with_ll_sc(u64 loops, u64 *ll_sc_target);
0014 
0015 /* The data cache was reloaded from local core's L3 due to a demand load */
0016 #define EventCode 0x1340000001c040
0017 
0018 /*
0019  * A perf sampling test for mmcr3
0020  * fields.
0021  */
0022 static int mmcr3_src(void)
0023 {
0024     struct event event;
0025     u64 *intr_regs;
0026     u64 dummy;
0027 
0028     /* Check for platform support for the test */
0029     SKIP_IF(check_pvr_for_sampling_tests());
0030     SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1));
0031 
0032     /* Init the event for the sampling test */
0033     event_init_sampling(&event, EventCode);
0034     event.attr.sample_regs_intr = platform_extended_mask;
0035     FAIL_IF(event_open(&event));
0036     event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
0037 
0038     FAIL_IF(event_enable(&event));
0039 
0040     /* workload to make event overflow */
0041     thirty_two_instruction_loop_with_ll_sc(1000000, &dummy);
0042 
0043     FAIL_IF(event_disable(&event));
0044 
0045     /* Check for sample count */
0046     FAIL_IF(!collect_samples(event.mmap_buffer));
0047 
0048     intr_regs = get_intr_regs(&event, event.mmap_buffer);
0049 
0050     /* Check for intr_regs */
0051     FAIL_IF(!intr_regs);
0052 
0053     /*
0054      * Verify that src field of MMCR3 match with
0055      * corresponding event code field
0056      */
0057     FAIL_IF(EV_CODE_EXTRACT(event.attr.config, mmcr3_src) !=
0058         get_mmcr3_src(get_reg_value(intr_regs, "MMCR3"), 1));
0059 
0060     event_close(&event);
0061     return 0;
0062 }
0063 
0064 int main(void)
0065 {
0066     return test_harness(mmcr3_src, "mmcr3_src");
0067 }