perf_event.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Linux performance counter support for ARC
  3. *
  4. * Copyright (C) 2011-2013 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #ifndef __ASM_PERF_EVENT_H
  12. #define __ASM_PERF_EVENT_H
  13. /* real maximum varies per CPU, this is the maximum supported by the driver */
  14. #define ARC_PMU_MAX_HWEVENTS 64
  15. #define ARC_REG_CC_BUILD 0xF6
  16. #define ARC_REG_CC_INDEX 0x240
  17. #define ARC_REG_CC_NAME0 0x241
  18. #define ARC_REG_CC_NAME1 0x242
  19. #define ARC_REG_PCT_BUILD 0xF5
  20. #define ARC_REG_PCT_COUNTL 0x250
  21. #define ARC_REG_PCT_COUNTH 0x251
  22. #define ARC_REG_PCT_SNAPL 0x252
  23. #define ARC_REG_PCT_SNAPH 0x253
  24. #define ARC_REG_PCT_CONFIG 0x254
  25. #define ARC_REG_PCT_CONTROL 0x255
  26. #define ARC_REG_PCT_INDEX 0x256
  27. #define ARC_REG_PCT_CONTROL_CC (1 << 16) /* clear counts */
  28. #define ARC_REG_PCT_CONTROL_SN (1 << 17) /* snapshot */
  29. struct arc_reg_pct_build {
  30. #ifdef CONFIG_CPU_BIG_ENDIAN
  31. unsigned int m:8, c:8, r:6, s:2, v:8;
  32. #else
  33. unsigned int v:8, s:2, r:6, c:8, m:8;
  34. #endif
  35. };
  36. struct arc_reg_cc_build {
  37. #ifdef CONFIG_CPU_BIG_ENDIAN
  38. unsigned int c:16, r:8, v:8;
  39. #else
  40. unsigned int v:8, r:8, c:16;
  41. #endif
  42. };
  43. #define PERF_COUNT_ARC_DCLM (PERF_COUNT_HW_MAX + 0)
  44. #define PERF_COUNT_ARC_DCSM (PERF_COUNT_HW_MAX + 1)
  45. #define PERF_COUNT_ARC_ICM (PERF_COUNT_HW_MAX + 2)
  46. #define PERF_COUNT_ARC_BPOK (PERF_COUNT_HW_MAX + 3)
  47. #define PERF_COUNT_ARC_EDTLB (PERF_COUNT_HW_MAX + 4)
  48. #define PERF_COUNT_ARC_EITLB (PERF_COUNT_HW_MAX + 5)
  49. #define PERF_COUNT_ARC_LDC (PERF_COUNT_HW_MAX + 6)
  50. #define PERF_COUNT_ARC_STC (PERF_COUNT_HW_MAX + 7)
  51. #define PERF_COUNT_ARC_HW_MAX (PERF_COUNT_HW_MAX + 8)
  52. /*
  53. * Some ARC pct quirks:
  54. *
  55. * PERF_COUNT_HW_STALLED_CYCLES_BACKEND
  56. * PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
  57. * The ARC 700 can either measure stalls per pipeline stage, or all stalls
  58. * combined; for now we assign all stalls to STALLED_CYCLES_BACKEND
  59. * and all pipeline flushes (e.g. caused by mispredicts, etc.) to
  60. * STALLED_CYCLES_FRONTEND.
  61. *
  62. * We could start multiple performance counters and combine everything
  63. * afterwards, but that makes it complicated.
  64. *
  65. * Note that I$ cache misses aren't counted by either of the two!
  66. */
  67. /*
  68. * ARC PCT has hardware conditions with fixed "names" but variable "indexes"
  69. * (based on a specific RTL build)
  70. * Below is the static map between perf generic/arc specific event_id and
  71. * h/w condition names.
  72. * At the time of probe, we loop thru each index and find it's name to
  73. * complete the mapping of perf event_id to h/w index as latter is needed
  74. * to program the counter really
  75. */
  76. static const char * const arc_pmu_ev_hw_map[] = {
  77. /* count cycles */
  78. [PERF_COUNT_HW_CPU_CYCLES] = "crun",
  79. [PERF_COUNT_HW_REF_CPU_CYCLES] = "crun",
  80. [PERF_COUNT_HW_BUS_CYCLES] = "crun",
  81. [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = "bflush",
  82. [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = "bstall",
  83. /* counts condition */
  84. [PERF_COUNT_HW_INSTRUCTIONS] = "iall",
  85. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmp",
  86. [PERF_COUNT_ARC_BPOK] = "bpok", /* NP-NT, PT-T, PNT-NT */
  87. [PERF_COUNT_HW_BRANCH_MISSES] = "bpfail", /* NP-T, PT-NT, PNT-T */
  88. [PERF_COUNT_ARC_LDC] = "imemrdc", /* Instr: mem read cached */
  89. [PERF_COUNT_ARC_STC] = "imemwrc", /* Instr: mem write cached */
  90. [PERF_COUNT_ARC_DCLM] = "dclm", /* D-cache Load Miss */
  91. [PERF_COUNT_ARC_DCSM] = "dcsm", /* D-cache Store Miss */
  92. [PERF_COUNT_ARC_ICM] = "icm", /* I-cache Miss */
  93. [PERF_COUNT_ARC_EDTLB] = "edtlb", /* D-TLB Miss */
  94. [PERF_COUNT_ARC_EITLB] = "eitlb", /* I-TLB Miss */
  95. };
  96. #define C(_x) PERF_COUNT_HW_CACHE_##_x
  97. #define CACHE_OP_UNSUPPORTED 0xffff
  98. static const unsigned arc_pmu_cache_map[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
  99. [C(L1D)] = {
  100. [C(OP_READ)] = {
  101. [C(RESULT_ACCESS)] = PERF_COUNT_ARC_LDC,
  102. [C(RESULT_MISS)] = PERF_COUNT_ARC_DCLM,
  103. },
  104. [C(OP_WRITE)] = {
  105. [C(RESULT_ACCESS)] = PERF_COUNT_ARC_STC,
  106. [C(RESULT_MISS)] = PERF_COUNT_ARC_DCSM,
  107. },
  108. [C(OP_PREFETCH)] = {
  109. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  110. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  111. },
  112. },
  113. [C(L1I)] = {
  114. [C(OP_READ)] = {
  115. [C(RESULT_ACCESS)] = PERF_COUNT_HW_INSTRUCTIONS,
  116. [C(RESULT_MISS)] = PERF_COUNT_ARC_ICM,
  117. },
  118. [C(OP_WRITE)] = {
  119. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  120. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  121. },
  122. [C(OP_PREFETCH)] = {
  123. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  124. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  125. },
  126. },
  127. [C(LL)] = {
  128. [C(OP_READ)] = {
  129. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  130. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  131. },
  132. [C(OP_WRITE)] = {
  133. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  134. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  135. },
  136. [C(OP_PREFETCH)] = {
  137. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  138. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  139. },
  140. },
  141. [C(DTLB)] = {
  142. [C(OP_READ)] = {
  143. [C(RESULT_ACCESS)] = PERF_COUNT_ARC_LDC,
  144. [C(RESULT_MISS)] = PERF_COUNT_ARC_EDTLB,
  145. },
  146. /* DTLB LD/ST Miss not segregated by h/w*/
  147. [C(OP_WRITE)] = {
  148. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  149. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  150. },
  151. [C(OP_PREFETCH)] = {
  152. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  153. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  154. },
  155. },
  156. [C(ITLB)] = {
  157. [C(OP_READ)] = {
  158. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  159. [C(RESULT_MISS)] = PERF_COUNT_ARC_EITLB,
  160. },
  161. [C(OP_WRITE)] = {
  162. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  163. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  164. },
  165. [C(OP_PREFETCH)] = {
  166. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  167. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  168. },
  169. },
  170. [C(BPU)] = {
  171. [C(OP_READ)] = {
  172. [C(RESULT_ACCESS)] = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
  173. [C(RESULT_MISS)] = PERF_COUNT_HW_BRANCH_MISSES,
  174. },
  175. [C(OP_WRITE)] = {
  176. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  177. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  178. },
  179. [C(OP_PREFETCH)] = {
  180. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  181. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  182. },
  183. },
  184. [C(NODE)] = {
  185. [C(OP_READ)] = {
  186. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  187. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  188. },
  189. [C(OP_WRITE)] = {
  190. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  191. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  192. },
  193. [C(OP_PREFETCH)] = {
  194. [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
  195. [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
  196. },
  197. },
  198. };
  199. #endif /* __ASM_PERF_EVENT_H */