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 /*
0014  * Primary PMU event used here is PM_MRK_INST_CMPL (0x401e0)
0015  * Threshold event selection used is issue to complete for cycles
0016  * Sampling criteria is Load only sampling
0017  */
0018 #define p9_EventCode 0x13E35340401e0
0019 #define p10_EventCode 0x35340401e0
0020 
0021 extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target);
0022 
0023 /* A perf sampling test to test mmcra fields */
0024 static int mmcra_thresh_cmp(void)
0025 {
0026     struct event event;
0027     u64 *intr_regs;
0028     u64 dummy;
0029 
0030     /* Check for platform support for the test */
0031     SKIP_IF(check_pvr_for_sampling_tests());
0032 
0033     /* Skip for comapt mode */
0034     SKIP_IF(check_for_compat_mode());
0035 
0036     /* Init the event for the sampling test */
0037     if (!have_hwcap2(PPC_FEATURE2_ARCH_3_1)) {
0038         event_init_sampling(&event, p9_EventCode);
0039     } else {
0040         event_init_sampling(&event, p10_EventCode);
0041         event.attr.config1 = 1000;
0042     }
0043 
0044     event.attr.sample_regs_intr = platform_extended_mask;
0045     FAIL_IF(event_open(&event));
0046     event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
0047 
0048     FAIL_IF(event_enable(&event));
0049 
0050     /* workload to make the event overflow */
0051     thirty_two_instruction_loop_with_ll_sc(1000000, &dummy);
0052 
0053     FAIL_IF(event_disable(&event));
0054 
0055     /* Check for sample count */
0056     FAIL_IF(!collect_samples(event.mmap_buffer));
0057 
0058     intr_regs = get_intr_regs(&event, event.mmap_buffer);
0059 
0060     /* Check for intr_regs */
0061     FAIL_IF(!intr_regs);
0062 
0063     /* Verify that thresh cmp match with the corresponding event code fields */
0064     FAIL_IF(get_thresh_cmp_val(event) !=
0065             get_mmcra_thd_cmp(get_reg_value(intr_regs, "MMCRA"), 4));
0066 
0067     event_close(&event);
0068     return 0;
0069 }
0070 
0071 int main(void)
0072 {
0073     FAIL_IF(test_harness(mmcra_thresh_cmp, "mmcra_thresh_cmp"));
0074 }