Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2022, Athira Rajeev, 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 /*
0016  * A perf sampling test for mmcr0
0017  * field: pmccext
0018  */
0019 static int mmcr0_pmccext(void)
0020 {
0021     struct event event;
0022     u64 *intr_regs;
0023 
0024     /* Check for platform support for the test */
0025     SKIP_IF(check_pvr_for_sampling_tests());
0026     SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1));
0027 
0028     /* Init the event for the sampling test */
0029     event_init_sampling(&event, 0x4001e);
0030     event.attr.sample_regs_intr = platform_extended_mask;
0031     FAIL_IF(event_open(&event));
0032     event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
0033 
0034     FAIL_IF(event_enable(&event));
0035 
0036     /* workload to make the event overflow */
0037     thirty_two_instruction_loop(10000);
0038 
0039     FAIL_IF(event_disable(&event));
0040 
0041     /* Check for sample count */
0042     FAIL_IF(!collect_samples(event.mmap_buffer));
0043 
0044     intr_regs = get_intr_regs(&event, event.mmap_buffer);
0045 
0046     /* Check for intr_regs */
0047     FAIL_IF(!intr_regs);
0048 
0049     /* Verify that pmccext field is set in MMCR0 */
0050     FAIL_IF(!get_mmcr0_pmccext(get_reg_value(intr_regs, "MMCR0"), 4));
0051 
0052     event_close(&event);
0053     return 0;
0054 }
0055 
0056 int main(void)
0057 {
0058     return test_harness(mmcr0_pmccext, "mmcr0_pmccext");
0059 }