e500-pmu.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Performance counter support for e500 family processors.
  4. *
  5. * Copyright 2008-2009 Paul Mackerras, IBM Corporation.
  6. * Copyright 2010 Freescale Semiconductor, Inc.
  7. */
  8. #include <linux/string.h>
  9. #include <linux/perf_event.h>
  10. #include <asm/reg.h>
  11. #include <asm/cputable.h>
  12. /*
  13. * Map of generic hardware event types to hardware events
  14. * Zero if unsupported
  15. */
  16. static int e500_generic_events[] = {
  17. [PERF_COUNT_HW_CPU_CYCLES] = 1,
  18. [PERF_COUNT_HW_INSTRUCTIONS] = 2,
  19. [PERF_COUNT_HW_CACHE_MISSES] = 41, /* Data L1 cache reloads */
  20. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 12,
  21. [PERF_COUNT_HW_BRANCH_MISSES] = 15,
  22. [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 18,
  23. [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 19,
  24. };
  25. #define C(x) PERF_COUNT_HW_CACHE_##x
  26. /*
  27. * Table of generalized cache-related events.
  28. * 0 means not supported, -1 means nonsensical, other values
  29. * are event codes.
  30. */
  31. static int e500_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
  32. /*
  33. * D-cache misses are not split into read/write/prefetch;
  34. * use raw event 41.
  35. */
  36. [C(L1D)] = { /* RESULT_ACCESS RESULT_MISS */
  37. [C(OP_READ)] = { 27, 0 },
  38. [C(OP_WRITE)] = { 28, 0 },
  39. [C(OP_PREFETCH)] = { 29, 0 },
  40. },
  41. [C(L1I)] = { /* RESULT_ACCESS RESULT_MISS */
  42. [C(OP_READ)] = { 2, 60 },
  43. [C(OP_WRITE)] = { -1, -1 },
  44. [C(OP_PREFETCH)] = { 0, 0 },
  45. },
  46. /*
  47. * Assuming LL means L2, it's not a good match for this model.
  48. * It allocates only on L1 castout or explicit prefetch, and
  49. * does not have separate read/write events (but it does have
  50. * separate instruction/data events).
  51. */
  52. [C(LL)] = { /* RESULT_ACCESS RESULT_MISS */
  53. [C(OP_READ)] = { 0, 0 },
  54. [C(OP_WRITE)] = { 0, 0 },
  55. [C(OP_PREFETCH)] = { 0, 0 },
  56. },
  57. /*
  58. * There are data/instruction MMU misses, but that's a miss on
  59. * the chip's internal level-one TLB which is probably not
  60. * what the user wants. Instead, unified level-two TLB misses
  61. * are reported here.
  62. */
  63. [C(DTLB)] = { /* RESULT_ACCESS RESULT_MISS */
  64. [C(OP_READ)] = { 26, 66 },
  65. [C(OP_WRITE)] = { -1, -1 },
  66. [C(OP_PREFETCH)] = { -1, -1 },
  67. },
  68. [C(BPU)] = { /* RESULT_ACCESS RESULT_MISS */
  69. [C(OP_READ)] = { 12, 15 },
  70. [C(OP_WRITE)] = { -1, -1 },
  71. [C(OP_PREFETCH)] = { -1, -1 },
  72. },
  73. [C(NODE)] = { /* RESULT_ACCESS RESULT_MISS */
  74. [C(OP_READ)] = { -1, -1 },
  75. [C(OP_WRITE)] = { -1, -1 },
  76. [C(OP_PREFETCH)] = { -1, -1 },
  77. },
  78. };
  79. static int num_events = 128;
  80. /* Upper half of event id is PMLCb, for threshold events */
  81. static u64 e500_xlate_event(u64 event_id)
  82. {
  83. u32 event_low = (u32)event_id;
  84. u64 ret;
  85. if (event_low >= num_events)
  86. return 0;
  87. ret = FSL_EMB_EVENT_VALID;
  88. if (event_low >= 76 && event_low <= 81) {
  89. ret |= FSL_EMB_EVENT_RESTRICTED;
  90. ret |= event_id &
  91. (FSL_EMB_EVENT_THRESHMUL | FSL_EMB_EVENT_THRESH);
  92. } else if (event_id &
  93. (FSL_EMB_EVENT_THRESHMUL | FSL_EMB_EVENT_THRESH)) {
  94. /* Threshold requested on non-threshold event */
  95. return 0;
  96. }
  97. return ret;
  98. }
  99. static struct fsl_emb_pmu e500_pmu = {
  100. .name = "e500 family",
  101. .n_counter = 4,
  102. .n_restricted = 2,
  103. .xlate_event = e500_xlate_event,
  104. .n_generic = ARRAY_SIZE(e500_generic_events),
  105. .generic_events = e500_generic_events,
  106. .cache_events = &e500_cache_events,
  107. };
  108. static int init_e500_pmu(void)
  109. {
  110. unsigned int pvr = mfspr(SPRN_PVR);
  111. /* ec500mc */
  112. if (PVR_VER(pvr) == PVR_VER_E500MC || PVR_VER(pvr) == PVR_VER_E5500)
  113. num_events = 256;
  114. /* e500 */
  115. else if (PVR_VER(pvr) != PVR_VER_E500V1 && PVR_VER(pvr) != PVR_VER_E500V2)
  116. return -ENODEV;
  117. return register_fsl_emb_pmu(&e500_pmu);
  118. }
  119. early_initcall(init_e500_pmu);