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 a per-task event vs an EBB - in that order. The EBB should push the
0019  * per-task event off the PMU.
0020  */
0021 
0022 static int setup_child_event(struct event *event, pid_t child_pid)
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     FAIL_IF(event_open_with_pid(event, child_pid));
0031     FAIL_IF(event_enable(event));
0032 
0033     return 0;
0034 }
0035 
0036 int task_event_vs_ebb(void)
0037 {
0038     union pipe read_pipe, write_pipe;
0039     struct event event;
0040     pid_t pid;
0041     int rc;
0042 
0043     SKIP_IF(!ebb_is_supported());
0044 
0045     FAIL_IF(pipe(read_pipe.fds) == -1);
0046     FAIL_IF(pipe(write_pipe.fds) == -1);
0047 
0048     pid = fork();
0049     if (pid == 0) {
0050         /* NB order of pipes looks reversed */
0051         exit(ebb_child(write_pipe, read_pipe));
0052     }
0053 
0054     /* We setup the task event first */
0055     rc = setup_child_event(&event, pid);
0056     if (rc) {
0057         kill_child_and_wait(pid);
0058         return rc;
0059     }
0060 
0061     /* Signal the child to install its EBB event and wait */
0062     if (sync_with_child(read_pipe, write_pipe))
0063         /* If it fails, wait for it to exit */
0064         goto wait;
0065 
0066     /* Signal the child to run */
0067     FAIL_IF(sync_with_child(read_pipe, write_pipe));
0068 
0069 wait:
0070     /* The EBB event should push the task event off so the child should succeed */
0071     FAIL_IF(wait_for_child(pid));
0072     FAIL_IF(event_disable(&event));
0073     FAIL_IF(event_read(&event));
0074 
0075     event_report(&event);
0076 
0077     /* The task event may have run, or not so we can't assert anything about it */
0078 
0079     return 0;
0080 }
0081 
0082 int main(void)
0083 {
0084     return test_harness(task_event_vs_ebb, "task_event_vs_ebb");
0085 }