perf_event.h 6.7 KB

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