multi_counter_test.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2014, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <sys/ioctl.h>
  8. #include "ebb.h"
  9. /*
  10. * Test counting multiple events using EBBs.
  11. */
  12. int multi_counter(void)
  13. {
  14. struct event events[6];
  15. int i, group_fd;
  16. event_init_named(&events[0], 0x1001C, "PM_CMPLU_STALL_THRD");
  17. event_init_named(&events[1], 0x2D016, "PM_CMPLU_STALL_FXU");
  18. event_init_named(&events[2], 0x30006, "PM_CMPLU_STALL_OTHER_CMPL");
  19. event_init_named(&events[3], 0x4000A, "PM_CMPLU_STALL");
  20. event_init_named(&events[4], 0x600f4, "PM_RUN_CYC");
  21. event_init_named(&events[5], 0x500fa, "PM_RUN_INST_CMPL");
  22. event_leader_ebb_init(&events[0]);
  23. for (i = 1; i < 6; i++)
  24. event_ebb_init(&events[i]);
  25. group_fd = -1;
  26. for (i = 0; i < 6; i++) {
  27. events[i].attr.exclude_kernel = 1;
  28. events[i].attr.exclude_hv = 1;
  29. events[i].attr.exclude_idle = 1;
  30. FAIL_IF(event_open_with_group(&events[i], group_fd));
  31. if (group_fd == -1)
  32. group_fd = events[0].fd;
  33. }
  34. ebb_enable_pmc_counting(1);
  35. ebb_enable_pmc_counting(2);
  36. ebb_enable_pmc_counting(3);
  37. ebb_enable_pmc_counting(4);
  38. ebb_enable_pmc_counting(5);
  39. ebb_enable_pmc_counting(6);
  40. setup_ebb_handler(standard_ebb_callee);
  41. FAIL_IF(ioctl(events[0].fd, PERF_EVENT_IOC_ENABLE, PERF_IOC_FLAG_GROUP));
  42. FAIL_IF(event_read(&events[0]));
  43. ebb_global_enable();
  44. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  45. mtspr(SPRN_PMC2, pmc_sample_period(sample_period));
  46. mtspr(SPRN_PMC3, pmc_sample_period(sample_period));
  47. mtspr(SPRN_PMC4, pmc_sample_period(sample_period));
  48. mtspr(SPRN_PMC5, pmc_sample_period(sample_period));
  49. mtspr(SPRN_PMC6, pmc_sample_period(sample_period));
  50. while (ebb_state.stats.ebb_count < 50) {
  51. FAIL_IF(core_busy_loop());
  52. FAIL_IF(ebb_check_mmcr0());
  53. }
  54. ebb_global_disable();
  55. ebb_freeze_pmcs();
  56. count_pmc(1, sample_period);
  57. count_pmc(2, sample_period);
  58. count_pmc(3, sample_period);
  59. count_pmc(4, sample_period);
  60. count_pmc(5, sample_period);
  61. count_pmc(6, sample_period);
  62. dump_ebb_state();
  63. for (i = 0; i < 6; i++)
  64. event_close(&events[i]);
  65. FAIL_IF(ebb_state.stats.ebb_count == 0);
  66. return 0;
  67. }
  68. int main(void)
  69. {
  70. return test_harness(multi_counter, "multi_counter");
  71. }