Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2014, Michael Ellerman, IBM Corp.
0004  */
0005 
0006 #include <signal.h>
0007 #include <stdio.h>
0008 #include <stdlib.h>
0009 #include <stdbool.h>
0010 #include <sys/types.h>
0011 #include <sys/wait.h>
0012 #include <unistd.h>
0013 
0014 #include "ebb.h"
0015 
0016 
0017 /*
0018  * Tests an EBB vs a cpu event - in that order. The EBB should force the cpu
0019  * event off the PMU.
0020  */
0021 
0022 static int setup_cpu_event(struct event *event, int cpu)
0023 {
0024     event_init_named(event, 0x400FA, "PM_RUN_INST_CMPL");
0025 
0026     event->attr.exclude_kernel = 1;
0027     event->attr.exclude_hv = 1;
0028     event->attr.exclude_idle = 1;
0029 
0030     SKIP_IF(require_paranoia_below(1));
0031     FAIL_IF(event_open_with_cpu(event, cpu));
0032     FAIL_IF(event_enable(event));
0033 
0034     return 0;
0035 }
0036 
0037 int ebb_vs_cpu_event(void)
0038 {
0039     union pipe read_pipe, write_pipe;
0040     struct event event;
0041     int cpu, rc;
0042     pid_t pid;
0043 
0044     SKIP_IF(!ebb_is_supported());
0045 
0046     cpu = pick_online_cpu();
0047     FAIL_IF(cpu < 0);
0048     FAIL_IF(bind_to_cpu(cpu));
0049 
0050     FAIL_IF(pipe(read_pipe.fds) == -1);
0051     FAIL_IF(pipe(write_pipe.fds) == -1);
0052 
0053     pid = fork();
0054     if (pid == 0) {
0055         /* NB order of pipes looks reversed */
0056         exit(ebb_child(write_pipe, read_pipe));
0057     }
0058 
0059     /* Signal the child to install its EBB event and wait */
0060     FAIL_IF(sync_with_child(read_pipe, write_pipe));
0061 
0062     /* Now try to install our CPU event */
0063     rc = setup_cpu_event(&event, cpu);
0064     if (rc) {
0065         kill_child_and_wait(pid);
0066         return rc;
0067     }
0068 
0069     /* Signal the child to run */
0070     FAIL_IF(sync_with_child(read_pipe, write_pipe));
0071 
0072     /* .. and wait for it to complete */
0073     FAIL_IF(wait_for_child(pid));
0074     FAIL_IF(event_disable(&event));
0075     FAIL_IF(event_read(&event));
0076 
0077     event_report(&event);
0078 
0079     /* The cpu event may have run, but we don't expect 100% */
0080     FAIL_IF(event.result.enabled >= event.result.running);
0081 
0082     return 0;
0083 }
0084 
0085 int main(void)
0086 {
0087     return test_harness(ebb_vs_cpu_event, "ebb_vs_cpu_event");
0088 }