e500-pmu.c 3.7 KB

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