e500-pmu.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. };
  27. #define C(x) PERF_COUNT_HW_CACHE_##x
  28. /*
  29. * Table of generalized cache-related events.
  30. * 0 means not supported, -1 means nonsensical, other values
  31. * are event codes.
  32. */
  33. static int e500_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
  34. /*
  35. * D-cache misses are not split into read/write/prefetch;
  36. * use raw event 41.
  37. */
  38. [C(L1D)] = { /* RESULT_ACCESS RESULT_MISS */
  39. [C(OP_READ)] = { 27, 0 },
  40. [C(OP_WRITE)] = { 28, 0 },
  41. [C(OP_PREFETCH)] = { 29, 0 },
  42. },
  43. [C(L1I)] = { /* RESULT_ACCESS RESULT_MISS */
  44. [C(OP_READ)] = { 2, 60 },
  45. [C(OP_WRITE)] = { -1, -1 },
  46. [C(OP_PREFETCH)] = { 0, 0 },
  47. },
  48. /*
  49. * Assuming LL means L2, it's not a good match for this model.
  50. * It allocates only on L1 castout or explicit prefetch, and
  51. * does not have separate read/write events (but it does have
  52. * separate instruction/data events).
  53. */
  54. [C(LL)] = { /* RESULT_ACCESS RESULT_MISS */
  55. [C(OP_READ)] = { 0, 0 },
  56. [C(OP_WRITE)] = { 0, 0 },
  57. [C(OP_PREFETCH)] = { 0, 0 },
  58. },
  59. /*
  60. * There are data/instruction MMU misses, but that's a miss on
  61. * the chip's internal level-one TLB which is probably not
  62. * what the user wants. Instead, unified level-two TLB misses
  63. * are reported here.
  64. */
  65. [C(DTLB)] = { /* RESULT_ACCESS RESULT_MISS */
  66. [C(OP_READ)] = { 26, 66 },
  67. [C(OP_WRITE)] = { -1, -1 },
  68. [C(OP_PREFETCH)] = { -1, -1 },
  69. },
  70. [C(BPU)] = { /* RESULT_ACCESS RESULT_MISS */
  71. [C(OP_READ)] = { 12, 15 },
  72. [C(OP_WRITE)] = { -1, -1 },
  73. [C(OP_PREFETCH)] = { -1, -1 },
  74. },
  75. [C(NODE)] = { /* RESULT_ACCESS RESULT_MISS */
  76. [C(OP_READ)] = { -1, -1 },
  77. [C(OP_WRITE)] = { -1, -1 },
  78. [C(OP_PREFETCH)] = { -1, -1 },
  79. },
  80. };
  81. static int num_events = 128;
  82. /* Upper half of event id is PMLCb, for threshold events */
  83. static u64 e500_xlate_event(u64 event_id)
  84. {
  85. u32 event_low = (u32)event_id;
  86. u64 ret;
  87. if (event_low >= num_events)
  88. return 0;
  89. ret = FSL_EMB_EVENT_VALID;
  90. if (event_low >= 76 && event_low <= 81) {
  91. ret |= FSL_EMB_EVENT_RESTRICTED;
  92. ret |= event_id &
  93. (FSL_EMB_EVENT_THRESHMUL | FSL_EMB_EVENT_THRESH);
  94. } else if (event_id &
  95. (FSL_EMB_EVENT_THRESHMUL | FSL_EMB_EVENT_THRESH)) {
  96. /* Threshold requested on non-threshold event */
  97. return 0;
  98. }
  99. return ret;
  100. }
  101. static struct fsl_emb_pmu e500_pmu = {
  102. .name = "e500 family",
  103. .n_counter = 4,
  104. .n_restricted = 2,
  105. .xlate_event = e500_xlate_event,
  106. .n_generic = ARRAY_SIZE(e500_generic_events),
  107. .generic_events = e500_generic_events,
  108. .cache_events = &e500_cache_events,
  109. };
  110. static int init_e500_pmu(void)
  111. {
  112. if (!cur_cpu_spec->oprofile_cpu_type)
  113. return -ENODEV;
  114. if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500mc"))
  115. num_events = 256;
  116. else if (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500"))
  117. return -ENODEV;
  118. return register_fsl_emb_pmu(&e500_pmu);
  119. }
  120. early_initcall(init_e500_pmu);