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 <stdbool.h>
0007 #include <stdio.h>
0008 #include <stdlib.h>
0009 #include <signal.h>
0010 
0011 #include "ebb.h"
0012 
0013 
0014 /*
0015  * Test running multiple EBB using processes at once on a single CPU. They
0016  * should all run happily without interfering with each other.
0017  */
0018 
0019 static bool child_should_exit;
0020 
0021 static void sigint_handler(int signal)
0022 {
0023     child_should_exit = true;
0024 }
0025 
0026 struct sigaction sigint_action = {
0027     .sa_handler = sigint_handler,
0028 };
0029 
0030 static int cycles_child(void)
0031 {
0032     struct event event;
0033 
0034     if (sigaction(SIGINT, &sigint_action, NULL)) {
0035         perror("sigaction");
0036         return 1;
0037     }
0038 
0039     event_init_named(&event, 0x1001e, "cycles");
0040     event_leader_ebb_init(&event);
0041 
0042     event.attr.exclude_kernel = 1;
0043     event.attr.exclude_hv = 1;
0044     event.attr.exclude_idle = 1;
0045 
0046     FAIL_IF(event_open(&event));
0047 
0048     ebb_enable_pmc_counting(1);
0049     setup_ebb_handler(standard_ebb_callee);
0050     ebb_global_enable();
0051 
0052     FAIL_IF(ebb_event_enable(&event));
0053 
0054     mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
0055 
0056     while (!child_should_exit) {
0057         FAIL_IF(core_busy_loop());
0058         FAIL_IF(ebb_check_mmcr0());
0059     }
0060 
0061     ebb_global_disable();
0062     ebb_freeze_pmcs();
0063 
0064     dump_summary_ebb_state();
0065 
0066     event_close(&event);
0067 
0068     FAIL_IF(ebb_state.stats.ebb_count == 0);
0069 
0070     return 0;
0071 }
0072 
0073 #define NR_CHILDREN 4
0074 
0075 int multi_ebb_procs(void)
0076 {
0077     pid_t pids[NR_CHILDREN];
0078     int cpu, rc, i;
0079 
0080     SKIP_IF(!ebb_is_supported());
0081 
0082     cpu = pick_online_cpu();
0083     FAIL_IF(cpu < 0);
0084     FAIL_IF(bind_to_cpu(cpu));
0085 
0086     for (i = 0; i < NR_CHILDREN; i++) {
0087         pids[i] = fork();
0088         if (pids[i] == 0)
0089             exit(cycles_child());
0090     }
0091 
0092     /* Have them all run for "a while" */
0093     sleep(10);
0094 
0095     rc = 0;
0096     for (i = 0; i < NR_CHILDREN; i++) {
0097         /* Tell them to stop */
0098         kill(pids[i], SIGINT);
0099         /* And wait */
0100         rc |= wait_for_child(pids[i]);
0101     }
0102 
0103     return rc;
0104 }
0105 
0106 int main(void)
0107 {
0108     return test_harness(multi_ebb_procs, "multi_ebb_procs");
0109 }