cycles_with_mmcr2_test.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2014, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdbool.h>
  8. #include "ebb.h"
  9. /*
  10. * Test of counting cycles while manipulating the user accessible bits in MMCR2.
  11. */
  12. /* We use two values because the first freezes PMC1 and so we would get no EBBs */
  13. #define MMCR2_EXPECTED_1 0x4020100804020000UL /* (FC1P|FC2P|FC3P|FC4P|FC5P|FC6P) */
  14. #define MMCR2_EXPECTED_2 0x0020100804020000UL /* ( FC2P|FC3P|FC4P|FC5P|FC6P) */
  15. int cycles_with_mmcr2(void)
  16. {
  17. struct event event;
  18. uint64_t val, expected[2], actual;
  19. int i;
  20. bool bad_mmcr2;
  21. event_init_named(&event, 0x1001e, "cycles");
  22. event_leader_ebb_init(&event);
  23. event.attr.exclude_kernel = 1;
  24. event.attr.exclude_hv = 1;
  25. event.attr.exclude_idle = 1;
  26. FAIL_IF(event_open(&event));
  27. ebb_enable_pmc_counting(1);
  28. setup_ebb_handler(standard_ebb_callee);
  29. ebb_global_enable();
  30. FAIL_IF(ebb_event_enable(&event));
  31. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  32. /* XXX Set of MMCR2 must be after enable */
  33. expected[0] = MMCR2_EXPECTED_1;
  34. expected[1] = MMCR2_EXPECTED_2;
  35. i = 0;
  36. bad_mmcr2 = false;
  37. /* Make sure we loop until we take at least one EBB */
  38. while ((ebb_state.stats.ebb_count < 20 && !bad_mmcr2) ||
  39. ebb_state.stats.ebb_count < 1)
  40. {
  41. mtspr(SPRN_MMCR2, expected[i % 2]);
  42. FAIL_IF(core_busy_loop());
  43. val = mfspr(SPRN_MMCR2);
  44. if (val != expected[i % 2]) {
  45. bad_mmcr2 = true;
  46. actual = val;
  47. }
  48. i++;
  49. }
  50. ebb_global_disable();
  51. ebb_freeze_pmcs();
  52. count_pmc(1, sample_period);
  53. dump_ebb_state();
  54. event_close(&event);
  55. FAIL_IF(ebb_state.stats.ebb_count == 0);
  56. if (bad_mmcr2)
  57. printf("Bad MMCR2 value seen is 0x%lx\n", actual);
  58. FAIL_IF(bad_mmcr2);
  59. return 0;
  60. }
  61. int main(void)
  62. {
  63. return test_harness(cycles_with_mmcr2, "cycles_with_mmcr2");
  64. }