e500-pmu.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. };
  76. static int num_events = 128;
  77. /* Upper half of event id is PMLCb, for threshold events */
  78. static u64 e500_xlate_event(u64 event_id)
  79. {
  80. u32 event_low = (u32)event_id;
  81. u64 ret;
  82. if (event_low >= num_events)
  83. return 0;
  84. ret = FSL_EMB_EVENT_VALID;
  85. if (event_low >= 76 && event_low <= 81) {
  86. ret |= FSL_EMB_EVENT_RESTRICTED;
  87. ret |= event_id &
  88. (FSL_EMB_EVENT_THRESHMUL | FSL_EMB_EVENT_THRESH);
  89. } else if (event_id &
  90. (FSL_EMB_EVENT_THRESHMUL | FSL_EMB_EVENT_THRESH)) {
  91. /* Threshold requested on non-threshold event */
  92. return 0;
  93. }
  94. return ret;
  95. }
  96. static struct fsl_emb_pmu e500_pmu = {
  97. .name = "e500 family",
  98. .n_counter = 4,
  99. .n_restricted = 2,
  100. .xlate_event = e500_xlate_event,
  101. .n_generic = ARRAY_SIZE(e500_generic_events),
  102. .generic_events = e500_generic_events,
  103. .cache_events = &e500_cache_events,
  104. };
  105. static int init_e500_pmu(void)
  106. {
  107. if (!cur_cpu_spec->oprofile_cpu_type)
  108. return -ENODEV;
  109. if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500mc"))
  110. num_events = 256;
  111. else if (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500"))
  112. return -ENODEV;
  113. return register_fsl_emb_pmu(&e500_pmu);
  114. }
  115. arch_initcall(init_e500_pmu);