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 <signal.h>
0007 #include <stdio.h>
0008 #include <stdlib.h>
0009 #include <sys/types.h>
0010 
0011 #include "../event.h"
0012 #include "misc.h"
0013 #include "utils.h"
0014 
0015 extern void thirty_two_instruction_loop(int loops);
0016 
0017 static bool is_hv;
0018 
0019 static void sig_usr2_handler(int signum, siginfo_t *info, void *data)
0020 {
0021     ucontext_t *uctx = data;
0022 
0023     is_hv = !!(uctx->uc_mcontext.gp_regs[PT_MSR] & MSR_HV);
0024 }
0025 
0026 /*
0027  * A perf sampling test for mmcr2
0028  * fields : fcs, fch.
0029  */
0030 static int mmcr2_fcs_fch(void)
0031 {
0032     struct sigaction sigact = {
0033         .sa_sigaction = sig_usr2_handler,
0034         .sa_flags = SA_SIGINFO
0035     };
0036     struct event event;
0037     u64 *intr_regs;
0038 
0039     FAIL_IF(sigaction(SIGUSR2, &sigact, NULL));
0040     FAIL_IF(kill(getpid(), SIGUSR2));
0041 
0042     /* Check for platform support for the test */
0043     SKIP_IF(check_pvr_for_sampling_tests());
0044 
0045     /* Init the event for the sampling test */
0046     event_init_sampling(&event, 0x1001e);
0047     event.attr.sample_regs_intr = platform_extended_mask;
0048     event.attr.exclude_kernel = 1;
0049     FAIL_IF(event_open(&event));
0050     event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
0051 
0052     FAIL_IF(event_enable(&event));
0053 
0054     /* workload to make the event overflow */
0055     thirty_two_instruction_loop(10000);
0056 
0057     FAIL_IF(event_disable(&event));
0058 
0059     /* Check for sample count */
0060     FAIL_IF(!collect_samples(event.mmap_buffer));
0061 
0062     intr_regs = get_intr_regs(&event, event.mmap_buffer);
0063 
0064     /* Check for intr_regs */
0065     FAIL_IF(!intr_regs);
0066 
0067     /*
0068      * Verify that fcs and fch field of MMCR2 match
0069      * with corresponding modifier fields.
0070      */
0071     if (is_hv)
0072         FAIL_IF(event.attr.exclude_kernel !=
0073             get_mmcr2_fch(get_reg_value(intr_regs, "MMCR2"), 1));
0074     else
0075         FAIL_IF(event.attr.exclude_kernel !=
0076             get_mmcr2_fcs(get_reg_value(intr_regs, "MMCR2"), 1));
0077 
0078     event_close(&event);
0079     return 0;
0080 }
0081 
0082 int main(void)
0083 {
0084     return test_harness(mmcr2_fcs_fch, "mmcr2_fcs_fch");
0085 }