cycles_test.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2014, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "ebb.h"
  8. /*
  9. * Basic test that counts user cycles and takes EBBs.
  10. */
  11. int cycles(void)
  12. {
  13. struct event event;
  14. SKIP_IF(!ebb_is_supported());
  15. event_init_named(&event, 0x1001e, "cycles");
  16. event_leader_ebb_init(&event);
  17. event.attr.exclude_kernel = 1;
  18. event.attr.exclude_hv = 1;
  19. event.attr.exclude_idle = 1;
  20. FAIL_IF(event_open(&event));
  21. ebb_enable_pmc_counting(1);
  22. setup_ebb_handler(standard_ebb_callee);
  23. ebb_global_enable();
  24. FAIL_IF(ebb_event_enable(&event));
  25. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  26. while (ebb_state.stats.ebb_count < 10) {
  27. FAIL_IF(core_busy_loop());
  28. FAIL_IF(ebb_check_mmcr0());
  29. }
  30. ebb_global_disable();
  31. ebb_freeze_pmcs();
  32. count_pmc(1, sample_period);
  33. dump_ebb_state();
  34. event_close(&event);
  35. FAIL_IF(ebb_state.stats.ebb_count == 0);
  36. FAIL_IF(!ebb_check_count(1, sample_period, 100));
  37. return 0;
  38. }
  39. int main(void)
  40. {
  41. return test_harness(cycles, "cycles");
  42. }