perf_event_v6.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * ARMv6 Performance counter handling code.
  3. *
  4. * Copyright (C) 2009 picoChip Designs, Ltd., Jamie Iles
  5. *
  6. * ARMv6 has 2 configurable performance counters and a single cycle counter.
  7. * They all share a single reset bit but can be written to zero so we can use
  8. * that for a reset.
  9. *
  10. * The counters can't be individually enabled or disabled so when we remove
  11. * one event and replace it with another we could get spurious counts from the
  12. * wrong event. However, we can take advantage of the fact that the
  13. * performance counters can export events to the event bus, and the event bus
  14. * itself can be monitored. This requires that we *don't* export the events to
  15. * the event bus. The procedure for disabling a configurable counter is:
  16. * - change the counter to count the ETMEXTOUT[0] signal (0x20). This
  17. * effectively stops the counter from counting.
  18. * - disable the counter's interrupt generation (each counter has it's
  19. * own interrupt enable bit).
  20. * Once stopped, the counter value can be written as 0 to reset.
  21. *
  22. * To enable a counter:
  23. * - enable the counter's interrupt generation.
  24. * - set the new event type.
  25. *
  26. * Note: the dedicated cycle counter only counts cycles and can't be
  27. * enabled/disabled independently of the others. When we want to disable the
  28. * cycle counter, we have to just disable the interrupt reporting and start
  29. * ignoring that counter. When re-enabling, we have to reset the value and
  30. * enable the interrupt.
  31. */
  32. #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K)
  33. enum armv6_perf_types {
  34. ARMV6_PERFCTR_ICACHE_MISS = 0x0,
  35. ARMV6_PERFCTR_IBUF_STALL = 0x1,
  36. ARMV6_PERFCTR_DDEP_STALL = 0x2,
  37. ARMV6_PERFCTR_ITLB_MISS = 0x3,
  38. ARMV6_PERFCTR_DTLB_MISS = 0x4,
  39. ARMV6_PERFCTR_BR_EXEC = 0x5,
  40. ARMV6_PERFCTR_BR_MISPREDICT = 0x6,
  41. ARMV6_PERFCTR_INSTR_EXEC = 0x7,
  42. ARMV6_PERFCTR_DCACHE_HIT = 0x9,
  43. ARMV6_PERFCTR_DCACHE_ACCESS = 0xA,
  44. ARMV6_PERFCTR_DCACHE_MISS = 0xB,
  45. ARMV6_PERFCTR_DCACHE_WBACK = 0xC,
  46. ARMV6_PERFCTR_SW_PC_CHANGE = 0xD,
  47. ARMV6_PERFCTR_MAIN_TLB_MISS = 0xF,
  48. ARMV6_PERFCTR_EXPL_D_ACCESS = 0x10,
  49. ARMV6_PERFCTR_LSU_FULL_STALL = 0x11,
  50. ARMV6_PERFCTR_WBUF_DRAINED = 0x12,
  51. ARMV6_PERFCTR_CPU_CYCLES = 0xFF,
  52. ARMV6_PERFCTR_NOP = 0x20,
  53. };
  54. enum armv6_counters {
  55. ARMV6_CYCLE_COUNTER = 0,
  56. ARMV6_COUNTER0,
  57. ARMV6_COUNTER1,
  58. };
  59. /*
  60. * The hardware events that we support. We do support cache operations but
  61. * we have harvard caches and no way to combine instruction and data
  62. * accesses/misses in hardware.
  63. */
  64. static const unsigned armv6_perf_map[PERF_COUNT_HW_MAX] = {
  65. PERF_MAP_ALL_UNSUPPORTED,
  66. [PERF_COUNT_HW_CPU_CYCLES] = ARMV6_PERFCTR_CPU_CYCLES,
  67. [PERF_COUNT_HW_INSTRUCTIONS] = ARMV6_PERFCTR_INSTR_EXEC,
  68. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV6_PERFCTR_BR_EXEC,
  69. [PERF_COUNT_HW_BRANCH_MISSES] = ARMV6_PERFCTR_BR_MISPREDICT,
  70. [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = ARMV6_PERFCTR_IBUF_STALL,
  71. [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = ARMV6_PERFCTR_LSU_FULL_STALL,
  72. };
  73. static const unsigned armv6_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
  74. [PERF_COUNT_HW_CACHE_OP_MAX]
  75. [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
  76. PERF_CACHE_MAP_ALL_UNSUPPORTED,
  77. /*
  78. * The performance counters don't differentiate between read and write
  79. * accesses/misses so this isn't strictly correct, but it's the best we
  80. * can do. Writes and reads get combined.
  81. */
  82. [C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV6_PERFCTR_DCACHE_ACCESS,
  83. [C(L1D)][C(OP_READ)][C(RESULT_MISS)] = ARMV6_PERFCTR_DCACHE_MISS,
  84. [C(L1D)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV6_PERFCTR_DCACHE_ACCESS,
  85. [C(L1D)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV6_PERFCTR_DCACHE_MISS,
  86. [C(L1I)][C(OP_READ)][C(RESULT_MISS)] = ARMV6_PERFCTR_ICACHE_MISS,
  87. /*
  88. * The ARM performance counters can count micro DTLB misses, micro ITLB
  89. * misses and main TLB misses. There isn't an event for TLB misses, so
  90. * use the micro misses here and if users want the main TLB misses they
  91. * can use a raw counter.
  92. */
  93. [C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV6_PERFCTR_DTLB_MISS,
  94. [C(DTLB)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV6_PERFCTR_DTLB_MISS,
  95. [C(ITLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV6_PERFCTR_ITLB_MISS,
  96. [C(ITLB)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV6_PERFCTR_ITLB_MISS,
  97. };
  98. enum armv6mpcore_perf_types {
  99. ARMV6MPCORE_PERFCTR_ICACHE_MISS = 0x0,
  100. ARMV6MPCORE_PERFCTR_IBUF_STALL = 0x1,
  101. ARMV6MPCORE_PERFCTR_DDEP_STALL = 0x2,
  102. ARMV6MPCORE_PERFCTR_ITLB_MISS = 0x3,
  103. ARMV6MPCORE_PERFCTR_DTLB_MISS = 0x4,
  104. ARMV6MPCORE_PERFCTR_BR_EXEC = 0x5,
  105. ARMV6MPCORE_PERFCTR_BR_NOTPREDICT = 0x6,
  106. ARMV6MPCORE_PERFCTR_BR_MISPREDICT = 0x7,
  107. ARMV6MPCORE_PERFCTR_INSTR_EXEC = 0x8,
  108. ARMV6MPCORE_PERFCTR_DCACHE_RDACCESS = 0xA,
  109. ARMV6MPCORE_PERFCTR_DCACHE_RDMISS = 0xB,
  110. ARMV6MPCORE_PERFCTR_DCACHE_WRACCESS = 0xC,
  111. ARMV6MPCORE_PERFCTR_DCACHE_WRMISS = 0xD,
  112. ARMV6MPCORE_PERFCTR_DCACHE_EVICTION = 0xE,
  113. ARMV6MPCORE_PERFCTR_SW_PC_CHANGE = 0xF,
  114. ARMV6MPCORE_PERFCTR_MAIN_TLB_MISS = 0x10,
  115. ARMV6MPCORE_PERFCTR_EXPL_MEM_ACCESS = 0x11,
  116. ARMV6MPCORE_PERFCTR_LSU_FULL_STALL = 0x12,
  117. ARMV6MPCORE_PERFCTR_WBUF_DRAINED = 0x13,
  118. ARMV6MPCORE_PERFCTR_CPU_CYCLES = 0xFF,
  119. };
  120. /*
  121. * The hardware events that we support. We do support cache operations but
  122. * we have harvard caches and no way to combine instruction and data
  123. * accesses/misses in hardware.
  124. */
  125. static const unsigned armv6mpcore_perf_map[PERF_COUNT_HW_MAX] = {
  126. PERF_MAP_ALL_UNSUPPORTED,
  127. [PERF_COUNT_HW_CPU_CYCLES] = ARMV6MPCORE_PERFCTR_CPU_CYCLES,
  128. [PERF_COUNT_HW_INSTRUCTIONS] = ARMV6MPCORE_PERFCTR_INSTR_EXEC,
  129. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV6MPCORE_PERFCTR_BR_EXEC,
  130. [PERF_COUNT_HW_BRANCH_MISSES] = ARMV6MPCORE_PERFCTR_BR_MISPREDICT,
  131. [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = ARMV6MPCORE_PERFCTR_IBUF_STALL,
  132. [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = ARMV6MPCORE_PERFCTR_LSU_FULL_STALL,
  133. };
  134. static const unsigned armv6mpcore_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
  135. [PERF_COUNT_HW_CACHE_OP_MAX]
  136. [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
  137. PERF_CACHE_MAP_ALL_UNSUPPORTED,
  138. [C(L1D)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV6MPCORE_PERFCTR_DCACHE_RDACCESS,
  139. [C(L1D)][C(OP_READ)][C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DCACHE_RDMISS,
  140. [C(L1D)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV6MPCORE_PERFCTR_DCACHE_WRACCESS,
  141. [C(L1D)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DCACHE_WRMISS,
  142. [C(L1I)][C(OP_READ)][C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ICACHE_MISS,
  143. /*
  144. * The ARM performance counters can count micro DTLB misses, micro ITLB
  145. * misses and main TLB misses. There isn't an event for TLB misses, so
  146. * use the micro misses here and if users want the main TLB misses they
  147. * can use a raw counter.
  148. */
  149. [C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DTLB_MISS,
  150. [C(DTLB)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_DTLB_MISS,
  151. [C(ITLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ITLB_MISS,
  152. [C(ITLB)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV6MPCORE_PERFCTR_ITLB_MISS,
  153. };
  154. static inline unsigned long
  155. armv6_pmcr_read(void)
  156. {
  157. u32 val;
  158. asm volatile("mrc p15, 0, %0, c15, c12, 0" : "=r"(val));
  159. return val;
  160. }
  161. static inline void
  162. armv6_pmcr_write(unsigned long val)
  163. {
  164. asm volatile("mcr p15, 0, %0, c15, c12, 0" : : "r"(val));
  165. }
  166. #define ARMV6_PMCR_ENABLE (1 << 0)
  167. #define ARMV6_PMCR_CTR01_RESET (1 << 1)
  168. #define ARMV6_PMCR_CCOUNT_RESET (1 << 2)
  169. #define ARMV6_PMCR_CCOUNT_DIV (1 << 3)
  170. #define ARMV6_PMCR_COUNT0_IEN (1 << 4)
  171. #define ARMV6_PMCR_COUNT1_IEN (1 << 5)
  172. #define ARMV6_PMCR_CCOUNT_IEN (1 << 6)
  173. #define ARMV6_PMCR_COUNT0_OVERFLOW (1 << 8)
  174. #define ARMV6_PMCR_COUNT1_OVERFLOW (1 << 9)
  175. #define ARMV6_PMCR_CCOUNT_OVERFLOW (1 << 10)
  176. #define ARMV6_PMCR_EVT_COUNT0_SHIFT 20
  177. #define ARMV6_PMCR_EVT_COUNT0_MASK (0xFF << ARMV6_PMCR_EVT_COUNT0_SHIFT)
  178. #define ARMV6_PMCR_EVT_COUNT1_SHIFT 12
  179. #define ARMV6_PMCR_EVT_COUNT1_MASK (0xFF << ARMV6_PMCR_EVT_COUNT1_SHIFT)
  180. #define ARMV6_PMCR_OVERFLOWED_MASK \
  181. (ARMV6_PMCR_COUNT0_OVERFLOW | ARMV6_PMCR_COUNT1_OVERFLOW | \
  182. ARMV6_PMCR_CCOUNT_OVERFLOW)
  183. static inline int
  184. armv6_pmcr_has_overflowed(unsigned long pmcr)
  185. {
  186. return pmcr & ARMV6_PMCR_OVERFLOWED_MASK;
  187. }
  188. static inline int
  189. armv6_pmcr_counter_has_overflowed(unsigned long pmcr,
  190. enum armv6_counters counter)
  191. {
  192. int ret = 0;
  193. if (ARMV6_CYCLE_COUNTER == counter)
  194. ret = pmcr & ARMV6_PMCR_CCOUNT_OVERFLOW;
  195. else if (ARMV6_COUNTER0 == counter)
  196. ret = pmcr & ARMV6_PMCR_COUNT0_OVERFLOW;
  197. else if (ARMV6_COUNTER1 == counter)
  198. ret = pmcr & ARMV6_PMCR_COUNT1_OVERFLOW;
  199. else
  200. WARN_ONCE(1, "invalid counter number (%d)\n", counter);
  201. return ret;
  202. }
  203. static inline u32 armv6pmu_read_counter(struct perf_event *event)
  204. {
  205. struct hw_perf_event *hwc = &event->hw;
  206. int counter = hwc->idx;
  207. unsigned long value = 0;
  208. if (ARMV6_CYCLE_COUNTER == counter)
  209. asm volatile("mrc p15, 0, %0, c15, c12, 1" : "=r"(value));
  210. else if (ARMV6_COUNTER0 == counter)
  211. asm volatile("mrc p15, 0, %0, c15, c12, 2" : "=r"(value));
  212. else if (ARMV6_COUNTER1 == counter)
  213. asm volatile("mrc p15, 0, %0, c15, c12, 3" : "=r"(value));
  214. else
  215. WARN_ONCE(1, "invalid counter number (%d)\n", counter);
  216. return value;
  217. }
  218. static inline void armv6pmu_write_counter(struct perf_event *event, u32 value)
  219. {
  220. struct hw_perf_event *hwc = &event->hw;
  221. int counter = hwc->idx;
  222. if (ARMV6_CYCLE_COUNTER == counter)
  223. asm volatile("mcr p15, 0, %0, c15, c12, 1" : : "r"(value));
  224. else if (ARMV6_COUNTER0 == counter)
  225. asm volatile("mcr p15, 0, %0, c15, c12, 2" : : "r"(value));
  226. else if (ARMV6_COUNTER1 == counter)
  227. asm volatile("mcr p15, 0, %0, c15, c12, 3" : : "r"(value));
  228. else
  229. WARN_ONCE(1, "invalid counter number (%d)\n", counter);
  230. }
  231. static void armv6pmu_enable_event(struct perf_event *event)
  232. {
  233. unsigned long val, mask, evt, flags;
  234. struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
  235. struct hw_perf_event *hwc = &event->hw;
  236. struct pmu_hw_events *events = cpu_pmu->get_hw_events();
  237. int idx = hwc->idx;
  238. if (ARMV6_CYCLE_COUNTER == idx) {
  239. mask = 0;
  240. evt = ARMV6_PMCR_CCOUNT_IEN;
  241. } else if (ARMV6_COUNTER0 == idx) {
  242. mask = ARMV6_PMCR_EVT_COUNT0_MASK;
  243. evt = (hwc->config_base << ARMV6_PMCR_EVT_COUNT0_SHIFT) |
  244. ARMV6_PMCR_COUNT0_IEN;
  245. } else if (ARMV6_COUNTER1 == idx) {
  246. mask = ARMV6_PMCR_EVT_COUNT1_MASK;
  247. evt = (hwc->config_base << ARMV6_PMCR_EVT_COUNT1_SHIFT) |
  248. ARMV6_PMCR_COUNT1_IEN;
  249. } else {
  250. WARN_ONCE(1, "invalid counter number (%d)\n", idx);
  251. return;
  252. }
  253. /*
  254. * Mask out the current event and set the counter to count the event
  255. * that we're interested in.
  256. */
  257. raw_spin_lock_irqsave(&events->pmu_lock, flags);
  258. val = armv6_pmcr_read();
  259. val &= ~mask;
  260. val |= evt;
  261. armv6_pmcr_write(val);
  262. raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
  263. }
  264. static irqreturn_t
  265. armv6pmu_handle_irq(int irq_num,
  266. void *dev)
  267. {
  268. unsigned long pmcr = armv6_pmcr_read();
  269. struct perf_sample_data data;
  270. struct arm_pmu *cpu_pmu = (struct arm_pmu *)dev;
  271. struct pmu_hw_events *cpuc = cpu_pmu->get_hw_events();
  272. struct pt_regs *regs;
  273. int idx;
  274. if (!armv6_pmcr_has_overflowed(pmcr))
  275. return IRQ_NONE;
  276. regs = get_irq_regs();
  277. /*
  278. * The interrupts are cleared by writing the overflow flags back to
  279. * the control register. All of the other bits don't have any effect
  280. * if they are rewritten, so write the whole value back.
  281. */
  282. armv6_pmcr_write(pmcr);
  283. for (idx = 0; idx < cpu_pmu->num_events; ++idx) {
  284. struct perf_event *event = cpuc->events[idx];
  285. struct hw_perf_event *hwc;
  286. /* Ignore if we don't have an event. */
  287. if (!event)
  288. continue;
  289. /*
  290. * We have a single interrupt for all counters. Check that
  291. * each counter has overflowed before we process it.
  292. */
  293. if (!armv6_pmcr_counter_has_overflowed(pmcr, idx))
  294. continue;
  295. hwc = &event->hw;
  296. armpmu_event_update(event);
  297. perf_sample_data_init(&data, 0, hwc->last_period);
  298. if (!armpmu_event_set_period(event))
  299. continue;
  300. if (perf_event_overflow(event, &data, regs))
  301. cpu_pmu->disable(event);
  302. }
  303. /*
  304. * Handle the pending perf events.
  305. *
  306. * Note: this call *must* be run with interrupts disabled. For
  307. * platforms that can have the PMU interrupts raised as an NMI, this
  308. * will not work.
  309. */
  310. irq_work_run();
  311. return IRQ_HANDLED;
  312. }
  313. static void armv6pmu_start(struct arm_pmu *cpu_pmu)
  314. {
  315. unsigned long flags, val;
  316. struct pmu_hw_events *events = cpu_pmu->get_hw_events();
  317. raw_spin_lock_irqsave(&events->pmu_lock, flags);
  318. val = armv6_pmcr_read();
  319. val |= ARMV6_PMCR_ENABLE;
  320. armv6_pmcr_write(val);
  321. raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
  322. }
  323. static void armv6pmu_stop(struct arm_pmu *cpu_pmu)
  324. {
  325. unsigned long flags, val;
  326. struct pmu_hw_events *events = cpu_pmu->get_hw_events();
  327. raw_spin_lock_irqsave(&events->pmu_lock, flags);
  328. val = armv6_pmcr_read();
  329. val &= ~ARMV6_PMCR_ENABLE;
  330. armv6_pmcr_write(val);
  331. raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
  332. }
  333. static int
  334. armv6pmu_get_event_idx(struct pmu_hw_events *cpuc,
  335. struct perf_event *event)
  336. {
  337. struct hw_perf_event *hwc = &event->hw;
  338. /* Always place a cycle counter into the cycle counter. */
  339. if (ARMV6_PERFCTR_CPU_CYCLES == hwc->config_base) {
  340. if (test_and_set_bit(ARMV6_CYCLE_COUNTER, cpuc->used_mask))
  341. return -EAGAIN;
  342. return ARMV6_CYCLE_COUNTER;
  343. } else {
  344. /*
  345. * For anything other than a cycle counter, try and use
  346. * counter0 and counter1.
  347. */
  348. if (!test_and_set_bit(ARMV6_COUNTER1, cpuc->used_mask))
  349. return ARMV6_COUNTER1;
  350. if (!test_and_set_bit(ARMV6_COUNTER0, cpuc->used_mask))
  351. return ARMV6_COUNTER0;
  352. /* The counters are all in use. */
  353. return -EAGAIN;
  354. }
  355. }
  356. static void armv6pmu_disable_event(struct perf_event *event)
  357. {
  358. unsigned long val, mask, evt, flags;
  359. struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
  360. struct hw_perf_event *hwc = &event->hw;
  361. struct pmu_hw_events *events = cpu_pmu->get_hw_events();
  362. int idx = hwc->idx;
  363. if (ARMV6_CYCLE_COUNTER == idx) {
  364. mask = ARMV6_PMCR_CCOUNT_IEN;
  365. evt = 0;
  366. } else if (ARMV6_COUNTER0 == idx) {
  367. mask = ARMV6_PMCR_COUNT0_IEN | ARMV6_PMCR_EVT_COUNT0_MASK;
  368. evt = ARMV6_PERFCTR_NOP << ARMV6_PMCR_EVT_COUNT0_SHIFT;
  369. } else if (ARMV6_COUNTER1 == idx) {
  370. mask = ARMV6_PMCR_COUNT1_IEN | ARMV6_PMCR_EVT_COUNT1_MASK;
  371. evt = ARMV6_PERFCTR_NOP << ARMV6_PMCR_EVT_COUNT1_SHIFT;
  372. } else {
  373. WARN_ONCE(1, "invalid counter number (%d)\n", idx);
  374. return;
  375. }
  376. /*
  377. * Mask out the current event and set the counter to count the number
  378. * of ETM bus signal assertion cycles. The external reporting should
  379. * be disabled and so this should never increment.
  380. */
  381. raw_spin_lock_irqsave(&events->pmu_lock, flags);
  382. val = armv6_pmcr_read();
  383. val &= ~mask;
  384. val |= evt;
  385. armv6_pmcr_write(val);
  386. raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
  387. }
  388. static void armv6mpcore_pmu_disable_event(struct perf_event *event)
  389. {
  390. unsigned long val, mask, flags, evt = 0;
  391. struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu);
  392. struct hw_perf_event *hwc = &event->hw;
  393. struct pmu_hw_events *events = cpu_pmu->get_hw_events();
  394. int idx = hwc->idx;
  395. if (ARMV6_CYCLE_COUNTER == idx) {
  396. mask = ARMV6_PMCR_CCOUNT_IEN;
  397. } else if (ARMV6_COUNTER0 == idx) {
  398. mask = ARMV6_PMCR_COUNT0_IEN;
  399. } else if (ARMV6_COUNTER1 == idx) {
  400. mask = ARMV6_PMCR_COUNT1_IEN;
  401. } else {
  402. WARN_ONCE(1, "invalid counter number (%d)\n", idx);
  403. return;
  404. }
  405. /*
  406. * Unlike UP ARMv6, we don't have a way of stopping the counters. We
  407. * simply disable the interrupt reporting.
  408. */
  409. raw_spin_lock_irqsave(&events->pmu_lock, flags);
  410. val = armv6_pmcr_read();
  411. val &= ~mask;
  412. val |= evt;
  413. armv6_pmcr_write(val);
  414. raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
  415. }
  416. static int armv6_map_event(struct perf_event *event)
  417. {
  418. return armpmu_map_event(event, &armv6_perf_map,
  419. &armv6_perf_cache_map, 0xFF);
  420. }
  421. static void armv6pmu_init(struct arm_pmu *cpu_pmu)
  422. {
  423. cpu_pmu->handle_irq = armv6pmu_handle_irq;
  424. cpu_pmu->enable = armv6pmu_enable_event;
  425. cpu_pmu->disable = armv6pmu_disable_event;
  426. cpu_pmu->read_counter = armv6pmu_read_counter;
  427. cpu_pmu->write_counter = armv6pmu_write_counter;
  428. cpu_pmu->get_event_idx = armv6pmu_get_event_idx;
  429. cpu_pmu->start = armv6pmu_start;
  430. cpu_pmu->stop = armv6pmu_stop;
  431. cpu_pmu->map_event = armv6_map_event;
  432. cpu_pmu->num_events = 3;
  433. cpu_pmu->max_period = (1LLU << 32) - 1;
  434. }
  435. static int armv6_1136_pmu_init(struct arm_pmu *cpu_pmu)
  436. {
  437. armv6pmu_init(cpu_pmu);
  438. cpu_pmu->name = "armv6_1136";
  439. return 0;
  440. }
  441. static int armv6_1156_pmu_init(struct arm_pmu *cpu_pmu)
  442. {
  443. armv6pmu_init(cpu_pmu);
  444. cpu_pmu->name = "armv6_1156";
  445. return 0;
  446. }
  447. static int armv6_1176_pmu_init(struct arm_pmu *cpu_pmu)
  448. {
  449. armv6pmu_init(cpu_pmu);
  450. cpu_pmu->name = "armv6_1176";
  451. return 0;
  452. }
  453. /*
  454. * ARMv6mpcore is almost identical to single core ARMv6 with the exception
  455. * that some of the events have different enumerations and that there is no
  456. * *hack* to stop the programmable counters. To stop the counters we simply
  457. * disable the interrupt reporting and update the event. When unthrottling we
  458. * reset the period and enable the interrupt reporting.
  459. */
  460. static int armv6mpcore_map_event(struct perf_event *event)
  461. {
  462. return armpmu_map_event(event, &armv6mpcore_perf_map,
  463. &armv6mpcore_perf_cache_map, 0xFF);
  464. }
  465. static int armv6mpcore_pmu_init(struct arm_pmu *cpu_pmu)
  466. {
  467. cpu_pmu->name = "armv6_11mpcore";
  468. cpu_pmu->handle_irq = armv6pmu_handle_irq;
  469. cpu_pmu->enable = armv6pmu_enable_event;
  470. cpu_pmu->disable = armv6mpcore_pmu_disable_event;
  471. cpu_pmu->read_counter = armv6pmu_read_counter;
  472. cpu_pmu->write_counter = armv6pmu_write_counter;
  473. cpu_pmu->get_event_idx = armv6pmu_get_event_idx;
  474. cpu_pmu->start = armv6pmu_start;
  475. cpu_pmu->stop = armv6pmu_stop;
  476. cpu_pmu->map_event = armv6mpcore_map_event;
  477. cpu_pmu->num_events = 3;
  478. cpu_pmu->max_period = (1LLU << 32) - 1;
  479. return 0;
  480. }
  481. #else
  482. static int armv6_1136_pmu_init(struct arm_pmu *cpu_pmu)
  483. {
  484. return -ENODEV;
  485. }
  486. static int armv6_1156_pmu_init(struct arm_pmu *cpu_pmu)
  487. {
  488. return -ENODEV;
  489. }
  490. static int armv6_1176_pmu_init(struct arm_pmu *cpu_pmu)
  491. {
  492. return -ENODEV;
  493. }
  494. static int armv6mpcore_pmu_init(struct arm_pmu *cpu_pmu)
  495. {
  496. return -ENODEV;
  497. }
  498. #endif /* CONFIG_CPU_V6 || CONFIG_CPU_V6K */