pmc56_overflow_test.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. SKIP_IF(!ebb_is_supported());
  38. /* Use PMC2 so we set PMCjCE, which enables PMC5/6 */
  39. event_init(&event, 0x2001e);
  40. event_leader_ebb_init(&event);
  41. event.attr.exclude_kernel = 1;
  42. event.attr.exclude_hv = 1;
  43. event.attr.exclude_idle = 1;
  44. FAIL_IF(event_open(&event));
  45. setup_ebb_handler(ebb_callee);
  46. ebb_global_enable();
  47. FAIL_IF(ebb_event_enable(&event));
  48. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  49. mtspr(SPRN_PMC5, 0);
  50. mtspr(SPRN_PMC6, 0);
  51. while (ebb_state.stats.ebb_count < 10)
  52. FAIL_IF(core_busy_loop());
  53. ebb_global_disable();
  54. ebb_freeze_pmcs();
  55. count_pmc(2, sample_period);
  56. dump_ebb_state();
  57. printf("PMC5/6 overflow %d\n", pmc56_overflowed);
  58. event_close(&event);
  59. FAIL_IF(ebb_state.stats.ebb_count == 0 || pmc56_overflowed != 0);
  60. return 0;
  61. }
  62. int main(void)
  63. {
  64. return test_harness(pmc56_overflow, "pmc56_overflow");
  65. }