pmc56_overflow_test.c 1.6 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 "ebb.h"
  8. /*
  9. * Test that PMC5 & 6 are frozen (ie. don't overflow) when they are not being
  10. * used. Tests the MMCR0_FC56 logic in the kernel.
  11. */
  12. static int pmc56_overflowed;
  13. static void ebb_callee(void)
  14. {
  15. uint64_t val;
  16. val = mfspr(SPRN_BESCR);
  17. if (!(val & BESCR_PMEO)) {
  18. ebb_state.stats.spurious++;
  19. goto out;
  20. }
  21. ebb_state.stats.ebb_count++;
  22. count_pmc(2, sample_period);
  23. val = mfspr(SPRN_PMC5);
  24. if (val >= COUNTER_OVERFLOW)
  25. pmc56_overflowed++;
  26. count_pmc(5, COUNTER_OVERFLOW);
  27. val = mfspr(SPRN_PMC6);
  28. if (val >= COUNTER_OVERFLOW)
  29. pmc56_overflowed++;
  30. count_pmc(6, COUNTER_OVERFLOW);
  31. out:
  32. reset_ebb();
  33. }
  34. int pmc56_overflow(void)
  35. {
  36. struct event event;
  37. /* Use PMC2 so we set PMCjCE, which enables PMC5/6 */
  38. event_init(&event, 0x2001e);
  39. event_leader_ebb_init(&event);
  40. event.attr.exclude_kernel = 1;
  41. event.attr.exclude_hv = 1;
  42. event.attr.exclude_idle = 1;
  43. FAIL_IF(event_open(&event));
  44. setup_ebb_handler(ebb_callee);
  45. ebb_global_enable();
  46. FAIL_IF(ebb_event_enable(&event));
  47. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  48. mtspr(SPRN_PMC5, 0);
  49. mtspr(SPRN_PMC6, 0);
  50. while (ebb_state.stats.ebb_count < 10)
  51. FAIL_IF(core_busy_loop());
  52. ebb_global_disable();
  53. ebb_freeze_pmcs();
  54. count_pmc(2, sample_period);
  55. dump_ebb_state();
  56. printf("PMC5/6 overflow %d\n", pmc56_overflowed);
  57. event_close(&event);
  58. FAIL_IF(ebb_state.stats.ebb_count == 0 || pmc56_overflowed != 0);
  59. return 0;
  60. }
  61. int main(void)
  62. {
  63. return test_harness(pmc56_overflow, "pmc56_overflow");
  64. }