multi_counter_test.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. SKIP_IF(!ebb_is_supported());
  17. event_init_named(&events[0], 0x1001C, "PM_CMPLU_STALL_THRD");
  18. event_init_named(&events[1], 0x2D016, "PM_CMPLU_STALL_FXU");
  19. event_init_named(&events[2], 0x30006, "PM_CMPLU_STALL_OTHER_CMPL");
  20. event_init_named(&events[3], 0x4000A, "PM_CMPLU_STALL");
  21. event_init_named(&events[4], 0x600f4, "PM_RUN_CYC");
  22. event_init_named(&events[5], 0x500fa, "PM_RUN_INST_CMPL");
  23. event_leader_ebb_init(&events[0]);
  24. for (i = 1; i < 6; i++)
  25. event_ebb_init(&events[i]);
  26. group_fd = -1;
  27. for (i = 0; i < 6; i++) {
  28. events[i].attr.exclude_kernel = 1;
  29. events[i].attr.exclude_hv = 1;
  30. events[i].attr.exclude_idle = 1;
  31. FAIL_IF(event_open_with_group(&events[i], group_fd));
  32. if (group_fd == -1)
  33. group_fd = events[0].fd;
  34. }
  35. ebb_enable_pmc_counting(1);
  36. ebb_enable_pmc_counting(2);
  37. ebb_enable_pmc_counting(3);
  38. ebb_enable_pmc_counting(4);
  39. ebb_enable_pmc_counting(5);
  40. ebb_enable_pmc_counting(6);
  41. setup_ebb_handler(standard_ebb_callee);
  42. FAIL_IF(ioctl(events[0].fd, PERF_EVENT_IOC_ENABLE, PERF_IOC_FLAG_GROUP));
  43. FAIL_IF(event_read(&events[0]));
  44. ebb_global_enable();
  45. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  46. mtspr(SPRN_PMC2, pmc_sample_period(sample_period));
  47. mtspr(SPRN_PMC3, pmc_sample_period(sample_period));
  48. mtspr(SPRN_PMC4, pmc_sample_period(sample_period));
  49. mtspr(SPRN_PMC5, pmc_sample_period(sample_period));
  50. mtspr(SPRN_PMC6, pmc_sample_period(sample_period));
  51. while (ebb_state.stats.ebb_count < 50) {
  52. FAIL_IF(core_busy_loop());
  53. FAIL_IF(ebb_check_mmcr0());
  54. }
  55. ebb_global_disable();
  56. ebb_freeze_pmcs();
  57. count_pmc(1, sample_period);
  58. count_pmc(2, sample_period);
  59. count_pmc(3, sample_period);
  60. count_pmc(4, sample_period);
  61. count_pmc(5, sample_period);
  62. count_pmc(6, sample_period);
  63. dump_ebb_state();
  64. for (i = 0; i < 6; i++)
  65. event_close(&events[i]);
  66. FAIL_IF(ebb_state.stats.ebb_count == 0);
  67. return 0;
  68. }
  69. int main(void)
  70. {
  71. return test_harness(multi_counter, "multi_counter");
  72. }