e6500-pmu.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Performance counter support for e6500 family processors.
  3. *
  4. * Author: Priyanka Jain, Priyanka.Jain@freescale.com
  5. * Based on e500-pmu.c
  6. * Copyright 2013 Freescale Semiconductor, Inc.
  7. * Copyright 2008-2009 Paul Mackerras, IBM Corporation.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/string.h>
  15. #include <linux/perf_event.h>
  16. #include <asm/reg.h>
  17. #include <asm/cputable.h>
  18. /*
  19. * Map of generic hardware event types to hardware events
  20. * Zero if unsupported
  21. */
  22. static int e6500_generic_events[] = {
  23. [PERF_COUNT_HW_CPU_CYCLES] = 1,
  24. [PERF_COUNT_HW_INSTRUCTIONS] = 2,
  25. [PERF_COUNT_HW_CACHE_MISSES] = 221,
  26. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 12,
  27. [PERF_COUNT_HW_BRANCH_MISSES] = 15,
  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 e6500_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
  36. [C(L1D)] = {
  37. /*RESULT_ACCESS RESULT_MISS */
  38. [C(OP_READ)] = { 27, 222 },
  39. [C(OP_WRITE)] = { 28, 223 },
  40. [C(OP_PREFETCH)] = { 29, 0 },
  41. },
  42. [C(L1I)] = {
  43. /*RESULT_ACCESS RESULT_MISS */
  44. [C(OP_READ)] = { 2, 254 },
  45. [C(OP_WRITE)] = { -1, -1 },
  46. [C(OP_PREFETCH)] = { 37, 0 },
  47. },
  48. /*
  49. * Assuming LL means L2, it's not a good match for this model.
  50. * It does not have separate read/write events (but it does have
  51. * separate instruction/data events).
  52. */
  53. [C(LL)] = {
  54. /*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)] = {
  66. /*RESULT_ACCESS RESULT_MISS */
  67. [C(OP_READ)] = { 26, 66 },
  68. [C(OP_WRITE)] = { -1, -1 },
  69. [C(OP_PREFETCH)] = { -1, -1 },
  70. },
  71. [C(BPU)] = {
  72. /*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)] = {
  78. /* RESULT_ACCESS RESULT_MISS */
  79. [C(OP_READ)] = { -1, -1 },
  80. [C(OP_WRITE)] = { -1, -1 },
  81. [C(OP_PREFETCH)] = { -1, -1 },
  82. },
  83. };
  84. static int num_events = 512;
  85. /* Upper half of event id is PMLCb, for threshold events */
  86. static u64 e6500_xlate_event(u64 event_id)
  87. {
  88. u32 event_low = (u32)event_id;
  89. if (event_low >= num_events ||
  90. (event_id & (FSL_EMB_EVENT_THRESHMUL | FSL_EMB_EVENT_THRESH)))
  91. return 0;
  92. return FSL_EMB_EVENT_VALID;
  93. }
  94. static struct fsl_emb_pmu e6500_pmu = {
  95. .name = "e6500 family",
  96. .n_counter = 6,
  97. .n_restricted = 0,
  98. .xlate_event = e6500_xlate_event,
  99. .n_generic = ARRAY_SIZE(e6500_generic_events),
  100. .generic_events = e6500_generic_events,
  101. .cache_events = &e6500_cache_events,
  102. };
  103. static int init_e6500_pmu(void)
  104. {
  105. if (!cur_cpu_spec->oprofile_cpu_type ||
  106. strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e6500"))
  107. return -ENODEV;
  108. return register_fsl_emb_pmu(&e6500_pmu);
  109. }
  110. early_initcall(init_e6500_pmu);