Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2022, Madhavan Srinivasan, 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 /* All successful D-side store dispatches for this thread */
0014 #define EventCode 0x010000046080
0015 
0016 #define MALLOC_SIZE     (0x10000 * 10)  /* Ought to be enough .. */
0017 
0018 /*
0019  * A perf sampling test for mmcr2
0020  * fields : l2l3
0021  */
0022 static int mmcr2_l2l3(void)
0023 {
0024     struct event event;
0025     u64 *intr_regs;
0026     char *p;
0027     int i;
0028 
0029     /* Check for platform support for the test */
0030     SKIP_IF(check_pvr_for_sampling_tests());
0031     SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1));
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     FAIL_IF(event_open(&event));
0037     event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
0038 
0039     FAIL_IF(event_enable(&event));
0040 
0041     /* workload to make the event overflow */
0042     p = malloc(MALLOC_SIZE);
0043     FAIL_IF(!p);
0044 
0045     for (i = 0; i < MALLOC_SIZE; i += 0x10000)
0046         p[i] = i;
0047 
0048     FAIL_IF(event_disable(&event));
0049 
0050     /* Check for sample count */
0051     FAIL_IF(!collect_samples(event.mmap_buffer));
0052 
0053     intr_regs = get_intr_regs(&event, event.mmap_buffer);
0054 
0055     /* Check for intr_regs */
0056     FAIL_IF(!intr_regs);
0057 
0058     /*
0059      * Verify that l2l3 field of MMCR2 match with
0060      * corresponding event code field
0061      */
0062     FAIL_IF(EV_CODE_EXTRACT(event.attr.config, l2l3) !=
0063         get_mmcr2_l2l3(get_reg_value(intr_regs, "MMCR2"), 4));
0064 
0065     event_close(&event);
0066     free(p);
0067 
0068     return 0;
0069 }
0070 
0071 int main(void)
0072 {
0073     return test_harness(mmcr2_l2l3, "mmcr2_l2l3");
0074 }