multi_ebb_procs_test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright 2014, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <stdbool.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <signal.h>
  9. #include "ebb.h"
  10. /*
  11. * Test running multiple EBB using processes at once on a single CPU. They
  12. * should all run happily without interfering with each other.
  13. */
  14. static bool child_should_exit;
  15. static void sigint_handler(int signal)
  16. {
  17. child_should_exit = true;
  18. }
  19. struct sigaction sigint_action = {
  20. .sa_handler = sigint_handler,
  21. };
  22. static int cycles_child(void)
  23. {
  24. struct event event;
  25. if (sigaction(SIGINT, &sigint_action, NULL)) {
  26. perror("sigaction");
  27. return 1;
  28. }
  29. event_init_named(&event, 0x1001e, "cycles");
  30. event_leader_ebb_init(&event);
  31. event.attr.exclude_kernel = 1;
  32. event.attr.exclude_hv = 1;
  33. event.attr.exclude_idle = 1;
  34. FAIL_IF(event_open(&event));
  35. ebb_enable_pmc_counting(1);
  36. setup_ebb_handler(standard_ebb_callee);
  37. ebb_global_enable();
  38. FAIL_IF(ebb_event_enable(&event));
  39. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  40. while (!child_should_exit) {
  41. FAIL_IF(core_busy_loop());
  42. FAIL_IF(ebb_check_mmcr0());
  43. }
  44. ebb_global_disable();
  45. ebb_freeze_pmcs();
  46. count_pmc(1, sample_period);
  47. dump_summary_ebb_state();
  48. event_close(&event);
  49. FAIL_IF(ebb_state.stats.ebb_count == 0);
  50. return 0;
  51. }
  52. #define NR_CHILDREN 4
  53. int multi_ebb_procs(void)
  54. {
  55. pid_t pids[NR_CHILDREN];
  56. int cpu, rc, i;
  57. cpu = pick_online_cpu();
  58. FAIL_IF(cpu < 0);
  59. FAIL_IF(bind_to_cpu(cpu));
  60. for (i = 0; i < NR_CHILDREN; i++) {
  61. pids[i] = fork();
  62. if (pids[i] == 0)
  63. exit(cycles_child());
  64. }
  65. /* Have them all run for "a while" */
  66. sleep(10);
  67. rc = 0;
  68. for (i = 0; i < NR_CHILDREN; i++) {
  69. /* Tell them to stop */
  70. kill(pids[i], SIGINT);
  71. /* And wait */
  72. rc |= wait_for_child(pids[i]);
  73. }
  74. return rc;
  75. }
  76. int main(void)
  77. {
  78. return test_harness(multi_ebb_procs, "multi_ebb_procs");
  79. }