perf_event_mipsxx.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  1. /*
  2. * Linux performance counter support for MIPS.
  3. *
  4. * Copyright (C) 2010 MIPS Technologies, Inc.
  5. * Copyright (C) 2011 Cavium Networks, Inc.
  6. * Author: Deng-Cheng Zhu
  7. *
  8. * This code is based on the implementation for ARM, which is in turn
  9. * based on the sparc64 perf event code and the x86 code. Performance
  10. * counter access is based on the MIPS Oprofile code. And the callchain
  11. * support references the code of MIPS stacktrace.c.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #include <linux/cpumask.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/smp.h>
  20. #include <linux/kernel.h>
  21. #include <linux/perf_event.h>
  22. #include <linux/uaccess.h>
  23. #include <asm/irq.h>
  24. #include <asm/irq_regs.h>
  25. #include <asm/stacktrace.h>
  26. #include <asm/time.h> /* For perf_irq */
  27. #define MIPS_MAX_HWEVENTS 4
  28. struct cpu_hw_events {
  29. /* Array of events on this cpu. */
  30. struct perf_event *events[MIPS_MAX_HWEVENTS];
  31. /*
  32. * Set the bit (indexed by the counter number) when the counter
  33. * is used for an event.
  34. */
  35. unsigned long used_mask[BITS_TO_LONGS(MIPS_MAX_HWEVENTS)];
  36. /*
  37. * Software copy of the control register for each performance counter.
  38. * MIPS CPUs vary in performance counters. They use this differently,
  39. * and even may not use it.
  40. */
  41. unsigned int saved_ctrl[MIPS_MAX_HWEVENTS];
  42. };
  43. DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {
  44. .saved_ctrl = {0},
  45. };
  46. /* The description of MIPS performance events. */
  47. struct mips_perf_event {
  48. unsigned int event_id;
  49. /*
  50. * MIPS performance counters are indexed starting from 0.
  51. * CNTR_EVEN indicates the indexes of the counters to be used are
  52. * even numbers.
  53. */
  54. unsigned int cntr_mask;
  55. #define CNTR_EVEN 0x55555555
  56. #define CNTR_ODD 0xaaaaaaaa
  57. #define CNTR_ALL 0xffffffff
  58. #ifdef CONFIG_MIPS_MT_SMP
  59. enum {
  60. T = 0,
  61. V = 1,
  62. P = 2,
  63. } range;
  64. #else
  65. #define T
  66. #define V
  67. #define P
  68. #endif
  69. };
  70. static struct mips_perf_event raw_event;
  71. static DEFINE_MUTEX(raw_event_mutex);
  72. #define UNSUPPORTED_PERF_EVENT_ID 0xffffffff
  73. #define C(x) PERF_COUNT_HW_CACHE_##x
  74. struct mips_pmu {
  75. u64 max_period;
  76. u64 valid_count;
  77. u64 overflow;
  78. const char *name;
  79. int irq;
  80. u64 (*read_counter)(unsigned int idx);
  81. void (*write_counter)(unsigned int idx, u64 val);
  82. const struct mips_perf_event *(*map_raw_event)(u64 config);
  83. const struct mips_perf_event (*general_event_map)[PERF_COUNT_HW_MAX];
  84. const struct mips_perf_event (*cache_event_map)
  85. [PERF_COUNT_HW_CACHE_MAX]
  86. [PERF_COUNT_HW_CACHE_OP_MAX]
  87. [PERF_COUNT_HW_CACHE_RESULT_MAX];
  88. unsigned int num_counters;
  89. };
  90. static struct mips_pmu mipspmu;
  91. #define M_CONFIG1_PC (1 << 4)
  92. #define M_PERFCTL_EXL (1 << 0)
  93. #define M_PERFCTL_KERNEL (1 << 1)
  94. #define M_PERFCTL_SUPERVISOR (1 << 2)
  95. #define M_PERFCTL_USER (1 << 3)
  96. #define M_PERFCTL_INTERRUPT_ENABLE (1 << 4)
  97. #define M_PERFCTL_EVENT(event) (((event) & 0x3ff) << 5)
  98. #define M_PERFCTL_VPEID(vpe) ((vpe) << 16)
  99. #define M_PERFCTL_MT_EN(filter) ((filter) << 20)
  100. #define M_TC_EN_ALL M_PERFCTL_MT_EN(0)
  101. #define M_TC_EN_VPE M_PERFCTL_MT_EN(1)
  102. #define M_TC_EN_TC M_PERFCTL_MT_EN(2)
  103. #define M_PERFCTL_TCID(tcid) ((tcid) << 22)
  104. #define M_PERFCTL_WIDE (1 << 30)
  105. #define M_PERFCTL_MORE (1 << 31)
  106. #define M_PERFCTL_COUNT_EVENT_WHENEVER (M_PERFCTL_EXL | \
  107. M_PERFCTL_KERNEL | \
  108. M_PERFCTL_USER | \
  109. M_PERFCTL_SUPERVISOR | \
  110. M_PERFCTL_INTERRUPT_ENABLE)
  111. #ifdef CONFIG_MIPS_MT_SMP
  112. #define M_PERFCTL_CONFIG_MASK 0x3fff801f
  113. #else
  114. #define M_PERFCTL_CONFIG_MASK 0x1f
  115. #endif
  116. #define M_PERFCTL_EVENT_MASK 0xfe0
  117. #ifdef CONFIG_MIPS_MT_SMP
  118. static int cpu_has_mipsmt_pertccounters;
  119. static DEFINE_RWLOCK(pmuint_rwlock);
  120. /*
  121. * FIXME: For VSMP, vpe_id() is redefined for Perf-events, because
  122. * cpu_data[cpuid].vpe_id reports 0 for _both_ CPUs.
  123. */
  124. #if defined(CONFIG_HW_PERF_EVENTS)
  125. #define vpe_id() (cpu_has_mipsmt_pertccounters ? \
  126. 0 : smp_processor_id())
  127. #else
  128. #define vpe_id() (cpu_has_mipsmt_pertccounters ? \
  129. 0 : cpu_data[smp_processor_id()].vpe_id)
  130. #endif
  131. /* Copied from op_model_mipsxx.c */
  132. static unsigned int vpe_shift(void)
  133. {
  134. if (num_possible_cpus() > 1)
  135. return 1;
  136. return 0;
  137. }
  138. static unsigned int counters_total_to_per_cpu(unsigned int counters)
  139. {
  140. return counters >> vpe_shift();
  141. }
  142. static unsigned int counters_per_cpu_to_total(unsigned int counters)
  143. {
  144. return counters << vpe_shift();
  145. }
  146. #else /* !CONFIG_MIPS_MT_SMP */
  147. #define vpe_id() 0
  148. #endif /* CONFIG_MIPS_MT_SMP */
  149. static void resume_local_counters(void);
  150. static void pause_local_counters(void);
  151. static irqreturn_t mipsxx_pmu_handle_irq(int, void *);
  152. static int mipsxx_pmu_handle_shared_irq(void);
  153. static unsigned int mipsxx_pmu_swizzle_perf_idx(unsigned int idx)
  154. {
  155. if (vpe_id() == 1)
  156. idx = (idx + 2) & 3;
  157. return idx;
  158. }
  159. static u64 mipsxx_pmu_read_counter(unsigned int idx)
  160. {
  161. idx = mipsxx_pmu_swizzle_perf_idx(idx);
  162. switch (idx) {
  163. case 0:
  164. /*
  165. * The counters are unsigned, we must cast to truncate
  166. * off the high bits.
  167. */
  168. return (u32)read_c0_perfcntr0();
  169. case 1:
  170. return (u32)read_c0_perfcntr1();
  171. case 2:
  172. return (u32)read_c0_perfcntr2();
  173. case 3:
  174. return (u32)read_c0_perfcntr3();
  175. default:
  176. WARN_ONCE(1, "Invalid performance counter number (%d)\n", idx);
  177. return 0;
  178. }
  179. }
  180. static u64 mipsxx_pmu_read_counter_64(unsigned int idx)
  181. {
  182. idx = mipsxx_pmu_swizzle_perf_idx(idx);
  183. switch (idx) {
  184. case 0:
  185. return read_c0_perfcntr0_64();
  186. case 1:
  187. return read_c0_perfcntr1_64();
  188. case 2:
  189. return read_c0_perfcntr2_64();
  190. case 3:
  191. return read_c0_perfcntr3_64();
  192. default:
  193. WARN_ONCE(1, "Invalid performance counter number (%d)\n", idx);
  194. return 0;
  195. }
  196. }
  197. static void mipsxx_pmu_write_counter(unsigned int idx, u64 val)
  198. {
  199. idx = mipsxx_pmu_swizzle_perf_idx(idx);
  200. switch (idx) {
  201. case 0:
  202. write_c0_perfcntr0(val);
  203. return;
  204. case 1:
  205. write_c0_perfcntr1(val);
  206. return;
  207. case 2:
  208. write_c0_perfcntr2(val);
  209. return;
  210. case 3:
  211. write_c0_perfcntr3(val);
  212. return;
  213. }
  214. }
  215. static void mipsxx_pmu_write_counter_64(unsigned int idx, u64 val)
  216. {
  217. idx = mipsxx_pmu_swizzle_perf_idx(idx);
  218. switch (idx) {
  219. case 0:
  220. write_c0_perfcntr0_64(val);
  221. return;
  222. case 1:
  223. write_c0_perfcntr1_64(val);
  224. return;
  225. case 2:
  226. write_c0_perfcntr2_64(val);
  227. return;
  228. case 3:
  229. write_c0_perfcntr3_64(val);
  230. return;
  231. }
  232. }
  233. static unsigned int mipsxx_pmu_read_control(unsigned int idx)
  234. {
  235. idx = mipsxx_pmu_swizzle_perf_idx(idx);
  236. switch (idx) {
  237. case 0:
  238. return read_c0_perfctrl0();
  239. case 1:
  240. return read_c0_perfctrl1();
  241. case 2:
  242. return read_c0_perfctrl2();
  243. case 3:
  244. return read_c0_perfctrl3();
  245. default:
  246. WARN_ONCE(1, "Invalid performance counter number (%d)\n", idx);
  247. return 0;
  248. }
  249. }
  250. static void mipsxx_pmu_write_control(unsigned int idx, unsigned int val)
  251. {
  252. idx = mipsxx_pmu_swizzle_perf_idx(idx);
  253. switch (idx) {
  254. case 0:
  255. write_c0_perfctrl0(val);
  256. return;
  257. case 1:
  258. write_c0_perfctrl1(val);
  259. return;
  260. case 2:
  261. write_c0_perfctrl2(val);
  262. return;
  263. case 3:
  264. write_c0_perfctrl3(val);
  265. return;
  266. }
  267. }
  268. static int mipsxx_pmu_alloc_counter(struct cpu_hw_events *cpuc,
  269. struct hw_perf_event *hwc)
  270. {
  271. int i;
  272. /*
  273. * We only need to care the counter mask. The range has been
  274. * checked definitely.
  275. */
  276. unsigned long cntr_mask = (hwc->event_base >> 8) & 0xffff;
  277. for (i = mipspmu.num_counters - 1; i >= 0; i--) {
  278. /*
  279. * Note that some MIPS perf events can be counted by both
  280. * even and odd counters, wheresas many other are only by
  281. * even _or_ odd counters. This introduces an issue that
  282. * when the former kind of event takes the counter the
  283. * latter kind of event wants to use, then the "counter
  284. * allocation" for the latter event will fail. In fact if
  285. * they can be dynamically swapped, they both feel happy.
  286. * But here we leave this issue alone for now.
  287. */
  288. if (test_bit(i, &cntr_mask) &&
  289. !test_and_set_bit(i, cpuc->used_mask))
  290. return i;
  291. }
  292. return -EAGAIN;
  293. }
  294. static void mipsxx_pmu_enable_event(struct hw_perf_event *evt, int idx)
  295. {
  296. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  297. WARN_ON(idx < 0 || idx >= mipspmu.num_counters);
  298. cpuc->saved_ctrl[idx] = M_PERFCTL_EVENT(evt->event_base & 0xff) |
  299. (evt->config_base & M_PERFCTL_CONFIG_MASK) |
  300. /* Make sure interrupt enabled. */
  301. M_PERFCTL_INTERRUPT_ENABLE;
  302. /*
  303. * We do not actually let the counter run. Leave it until start().
  304. */
  305. }
  306. static void mipsxx_pmu_disable_event(int idx)
  307. {
  308. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  309. unsigned long flags;
  310. WARN_ON(idx < 0 || idx >= mipspmu.num_counters);
  311. local_irq_save(flags);
  312. cpuc->saved_ctrl[idx] = mipsxx_pmu_read_control(idx) &
  313. ~M_PERFCTL_COUNT_EVENT_WHENEVER;
  314. mipsxx_pmu_write_control(idx, cpuc->saved_ctrl[idx]);
  315. local_irq_restore(flags);
  316. }
  317. static int mipspmu_event_set_period(struct perf_event *event,
  318. struct hw_perf_event *hwc,
  319. int idx)
  320. {
  321. u64 left = local64_read(&hwc->period_left);
  322. u64 period = hwc->sample_period;
  323. int ret = 0;
  324. if (unlikely((left + period) & (1ULL << 63))) {
  325. /* left underflowed by more than period. */
  326. left = period;
  327. local64_set(&hwc->period_left, left);
  328. hwc->last_period = period;
  329. ret = 1;
  330. } else if (unlikely((left + period) <= period)) {
  331. /* left underflowed by less than period. */
  332. left += period;
  333. local64_set(&hwc->period_left, left);
  334. hwc->last_period = period;
  335. ret = 1;
  336. }
  337. if (left > mipspmu.max_period) {
  338. left = mipspmu.max_period;
  339. local64_set(&hwc->period_left, left);
  340. }
  341. local64_set(&hwc->prev_count, mipspmu.overflow - left);
  342. mipspmu.write_counter(idx, mipspmu.overflow - left);
  343. perf_event_update_userpage(event);
  344. return ret;
  345. }
  346. static void mipspmu_event_update(struct perf_event *event,
  347. struct hw_perf_event *hwc,
  348. int idx)
  349. {
  350. u64 prev_raw_count, new_raw_count;
  351. u64 delta;
  352. again:
  353. prev_raw_count = local64_read(&hwc->prev_count);
  354. new_raw_count = mipspmu.read_counter(idx);
  355. if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
  356. new_raw_count) != prev_raw_count)
  357. goto again;
  358. delta = new_raw_count - prev_raw_count;
  359. local64_add(delta, &event->count);
  360. local64_sub(delta, &hwc->period_left);
  361. }
  362. static void mipspmu_start(struct perf_event *event, int flags)
  363. {
  364. struct hw_perf_event *hwc = &event->hw;
  365. if (flags & PERF_EF_RELOAD)
  366. WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE));
  367. hwc->state = 0;
  368. /* Set the period for the event. */
  369. mipspmu_event_set_period(event, hwc, hwc->idx);
  370. /* Enable the event. */
  371. mipsxx_pmu_enable_event(hwc, hwc->idx);
  372. }
  373. static void mipspmu_stop(struct perf_event *event, int flags)
  374. {
  375. struct hw_perf_event *hwc = &event->hw;
  376. if (!(hwc->state & PERF_HES_STOPPED)) {
  377. /* We are working on a local event. */
  378. mipsxx_pmu_disable_event(hwc->idx);
  379. barrier();
  380. mipspmu_event_update(event, hwc, hwc->idx);
  381. hwc->state |= PERF_HES_STOPPED | PERF_HES_UPTODATE;
  382. }
  383. }
  384. static int mipspmu_add(struct perf_event *event, int flags)
  385. {
  386. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  387. struct hw_perf_event *hwc = &event->hw;
  388. int idx;
  389. int err = 0;
  390. perf_pmu_disable(event->pmu);
  391. /* To look for a free counter for this event. */
  392. idx = mipsxx_pmu_alloc_counter(cpuc, hwc);
  393. if (idx < 0) {
  394. err = idx;
  395. goto out;
  396. }
  397. /*
  398. * If there is an event in the counter we are going to use then
  399. * make sure it is disabled.
  400. */
  401. event->hw.idx = idx;
  402. mipsxx_pmu_disable_event(idx);
  403. cpuc->events[idx] = event;
  404. hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
  405. if (flags & PERF_EF_START)
  406. mipspmu_start(event, PERF_EF_RELOAD);
  407. /* Propagate our changes to the userspace mapping. */
  408. perf_event_update_userpage(event);
  409. out:
  410. perf_pmu_enable(event->pmu);
  411. return err;
  412. }
  413. static void mipspmu_del(struct perf_event *event, int flags)
  414. {
  415. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  416. struct hw_perf_event *hwc = &event->hw;
  417. int idx = hwc->idx;
  418. WARN_ON(idx < 0 || idx >= mipspmu.num_counters);
  419. mipspmu_stop(event, PERF_EF_UPDATE);
  420. cpuc->events[idx] = NULL;
  421. clear_bit(idx, cpuc->used_mask);
  422. perf_event_update_userpage(event);
  423. }
  424. static void mipspmu_read(struct perf_event *event)
  425. {
  426. struct hw_perf_event *hwc = &event->hw;
  427. /* Don't read disabled counters! */
  428. if (hwc->idx < 0)
  429. return;
  430. mipspmu_event_update(event, hwc, hwc->idx);
  431. }
  432. static void mipspmu_enable(struct pmu *pmu)
  433. {
  434. #ifdef CONFIG_MIPS_MT_SMP
  435. write_unlock(&pmuint_rwlock);
  436. #endif
  437. resume_local_counters();
  438. }
  439. /*
  440. * MIPS performance counters can be per-TC. The control registers can
  441. * not be directly accessed accross CPUs. Hence if we want to do global
  442. * control, we need cross CPU calls. on_each_cpu() can help us, but we
  443. * can not make sure this function is called with interrupts enabled. So
  444. * here we pause local counters and then grab a rwlock and leave the
  445. * counters on other CPUs alone. If any counter interrupt raises while
  446. * we own the write lock, simply pause local counters on that CPU and
  447. * spin in the handler. Also we know we won't be switched to another
  448. * CPU after pausing local counters and before grabbing the lock.
  449. */
  450. static void mipspmu_disable(struct pmu *pmu)
  451. {
  452. pause_local_counters();
  453. #ifdef CONFIG_MIPS_MT_SMP
  454. write_lock(&pmuint_rwlock);
  455. #endif
  456. }
  457. static atomic_t active_events = ATOMIC_INIT(0);
  458. static DEFINE_MUTEX(pmu_reserve_mutex);
  459. static int (*save_perf_irq)(void);
  460. static int mipspmu_get_irq(void)
  461. {
  462. int err;
  463. if (mipspmu.irq >= 0) {
  464. /* Request my own irq handler. */
  465. err = request_irq(mipspmu.irq, mipsxx_pmu_handle_irq,
  466. IRQF_PERCPU | IRQF_NOBALANCING,
  467. "mips_perf_pmu", NULL);
  468. if (err) {
  469. pr_warning("Unable to request IRQ%d for MIPS "
  470. "performance counters!\n", mipspmu.irq);
  471. }
  472. } else if (cp0_perfcount_irq < 0) {
  473. /*
  474. * We are sharing the irq number with the timer interrupt.
  475. */
  476. save_perf_irq = perf_irq;
  477. perf_irq = mipsxx_pmu_handle_shared_irq;
  478. err = 0;
  479. } else {
  480. pr_warning("The platform hasn't properly defined its "
  481. "interrupt controller.\n");
  482. err = -ENOENT;
  483. }
  484. return err;
  485. }
  486. static void mipspmu_free_irq(void)
  487. {
  488. if (mipspmu.irq >= 0)
  489. free_irq(mipspmu.irq, NULL);
  490. else if (cp0_perfcount_irq < 0)
  491. perf_irq = save_perf_irq;
  492. }
  493. /*
  494. * mipsxx/rm9000/loongson2 have different performance counters, they have
  495. * specific low-level init routines.
  496. */
  497. static void reset_counters(void *arg);
  498. static int __hw_perf_event_init(struct perf_event *event);
  499. static void hw_perf_event_destroy(struct perf_event *event)
  500. {
  501. if (atomic_dec_and_mutex_lock(&active_events,
  502. &pmu_reserve_mutex)) {
  503. /*
  504. * We must not call the destroy function with interrupts
  505. * disabled.
  506. */
  507. on_each_cpu(reset_counters,
  508. (void *)(long)mipspmu.num_counters, 1);
  509. mipspmu_free_irq();
  510. mutex_unlock(&pmu_reserve_mutex);
  511. }
  512. }
  513. static int mipspmu_event_init(struct perf_event *event)
  514. {
  515. int err = 0;
  516. switch (event->attr.type) {
  517. case PERF_TYPE_RAW:
  518. case PERF_TYPE_HARDWARE:
  519. case PERF_TYPE_HW_CACHE:
  520. break;
  521. default:
  522. return -ENOENT;
  523. }
  524. if (event->cpu >= nr_cpumask_bits ||
  525. (event->cpu >= 0 && !cpu_online(event->cpu)))
  526. return -ENODEV;
  527. if (!atomic_inc_not_zero(&active_events)) {
  528. if (atomic_read(&active_events) > MIPS_MAX_HWEVENTS) {
  529. atomic_dec(&active_events);
  530. return -ENOSPC;
  531. }
  532. mutex_lock(&pmu_reserve_mutex);
  533. if (atomic_read(&active_events) == 0)
  534. err = mipspmu_get_irq();
  535. if (!err)
  536. atomic_inc(&active_events);
  537. mutex_unlock(&pmu_reserve_mutex);
  538. }
  539. if (err)
  540. return err;
  541. err = __hw_perf_event_init(event);
  542. if (err)
  543. hw_perf_event_destroy(event);
  544. return err;
  545. }
  546. static struct pmu pmu = {
  547. .pmu_enable = mipspmu_enable,
  548. .pmu_disable = mipspmu_disable,
  549. .event_init = mipspmu_event_init,
  550. .add = mipspmu_add,
  551. .del = mipspmu_del,
  552. .start = mipspmu_start,
  553. .stop = mipspmu_stop,
  554. .read = mipspmu_read,
  555. };
  556. static unsigned int mipspmu_perf_event_encode(const struct mips_perf_event *pev)
  557. {
  558. /*
  559. * Top 8 bits for range, next 16 bits for cntr_mask, lowest 8 bits for
  560. * event_id.
  561. */
  562. #ifdef CONFIG_MIPS_MT_SMP
  563. return ((unsigned int)pev->range << 24) |
  564. (pev->cntr_mask & 0xffff00) |
  565. (pev->event_id & 0xff);
  566. #else
  567. return (pev->cntr_mask & 0xffff00) |
  568. (pev->event_id & 0xff);
  569. #endif
  570. }
  571. static const struct mips_perf_event *mipspmu_map_general_event(int idx)
  572. {
  573. const struct mips_perf_event *pev;
  574. pev = ((*mipspmu.general_event_map)[idx].event_id ==
  575. UNSUPPORTED_PERF_EVENT_ID ? ERR_PTR(-EOPNOTSUPP) :
  576. &(*mipspmu.general_event_map)[idx]);
  577. return pev;
  578. }
  579. static const struct mips_perf_event *mipspmu_map_cache_event(u64 config)
  580. {
  581. unsigned int cache_type, cache_op, cache_result;
  582. const struct mips_perf_event *pev;
  583. cache_type = (config >> 0) & 0xff;
  584. if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
  585. return ERR_PTR(-EINVAL);
  586. cache_op = (config >> 8) & 0xff;
  587. if (cache_op >= PERF_COUNT_HW_CACHE_OP_MAX)
  588. return ERR_PTR(-EINVAL);
  589. cache_result = (config >> 16) & 0xff;
  590. if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
  591. return ERR_PTR(-EINVAL);
  592. pev = &((*mipspmu.cache_event_map)
  593. [cache_type]
  594. [cache_op]
  595. [cache_result]);
  596. if (pev->event_id == UNSUPPORTED_PERF_EVENT_ID)
  597. return ERR_PTR(-EOPNOTSUPP);
  598. return pev;
  599. }
  600. static int validate_event(struct cpu_hw_events *cpuc,
  601. struct perf_event *event)
  602. {
  603. struct hw_perf_event fake_hwc = event->hw;
  604. /* Allow mixed event group. So return 1 to pass validation. */
  605. if (event->pmu != &pmu || event->state <= PERF_EVENT_STATE_OFF)
  606. return 1;
  607. return mipsxx_pmu_alloc_counter(cpuc, &fake_hwc) >= 0;
  608. }
  609. static int validate_group(struct perf_event *event)
  610. {
  611. struct perf_event *sibling, *leader = event->group_leader;
  612. struct cpu_hw_events fake_cpuc;
  613. memset(&fake_cpuc, 0, sizeof(fake_cpuc));
  614. if (!validate_event(&fake_cpuc, leader))
  615. return -ENOSPC;
  616. list_for_each_entry(sibling, &leader->sibling_list, group_entry) {
  617. if (!validate_event(&fake_cpuc, sibling))
  618. return -ENOSPC;
  619. }
  620. if (!validate_event(&fake_cpuc, event))
  621. return -ENOSPC;
  622. return 0;
  623. }
  624. /* This is needed by specific irq handlers in perf_event_*.c */
  625. static void handle_associated_event(struct cpu_hw_events *cpuc,
  626. int idx, struct perf_sample_data *data,
  627. struct pt_regs *regs)
  628. {
  629. struct perf_event *event = cpuc->events[idx];
  630. struct hw_perf_event *hwc = &event->hw;
  631. mipspmu_event_update(event, hwc, idx);
  632. data->period = event->hw.last_period;
  633. if (!mipspmu_event_set_period(event, hwc, idx))
  634. return;
  635. if (perf_event_overflow(event, data, regs))
  636. mipsxx_pmu_disable_event(idx);
  637. }
  638. static int __n_counters(void)
  639. {
  640. if (!(read_c0_config1() & M_CONFIG1_PC))
  641. return 0;
  642. if (!(read_c0_perfctrl0() & M_PERFCTL_MORE))
  643. return 1;
  644. if (!(read_c0_perfctrl1() & M_PERFCTL_MORE))
  645. return 2;
  646. if (!(read_c0_perfctrl2() & M_PERFCTL_MORE))
  647. return 3;
  648. return 4;
  649. }
  650. static int n_counters(void)
  651. {
  652. int counters;
  653. switch (current_cpu_type()) {
  654. case CPU_R10000:
  655. counters = 2;
  656. break;
  657. case CPU_R12000:
  658. case CPU_R14000:
  659. counters = 4;
  660. break;
  661. default:
  662. counters = __n_counters();
  663. }
  664. return counters;
  665. }
  666. static void reset_counters(void *arg)
  667. {
  668. int counters = (int)(long)arg;
  669. switch (counters) {
  670. case 4:
  671. mipsxx_pmu_write_control(3, 0);
  672. mipspmu.write_counter(3, 0);
  673. case 3:
  674. mipsxx_pmu_write_control(2, 0);
  675. mipspmu.write_counter(2, 0);
  676. case 2:
  677. mipsxx_pmu_write_control(1, 0);
  678. mipspmu.write_counter(1, 0);
  679. case 1:
  680. mipsxx_pmu_write_control(0, 0);
  681. mipspmu.write_counter(0, 0);
  682. }
  683. }
  684. /* 24K/34K/1004K cores can share the same event map. */
  685. static const struct mips_perf_event mipsxxcore_event_map
  686. [PERF_COUNT_HW_MAX] = {
  687. [PERF_COUNT_HW_CPU_CYCLES] = { 0x00, CNTR_EVEN | CNTR_ODD, P },
  688. [PERF_COUNT_HW_INSTRUCTIONS] = { 0x01, CNTR_EVEN | CNTR_ODD, T },
  689. [PERF_COUNT_HW_CACHE_REFERENCES] = { UNSUPPORTED_PERF_EVENT_ID },
  690. [PERF_COUNT_HW_CACHE_MISSES] = { UNSUPPORTED_PERF_EVENT_ID },
  691. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { 0x02, CNTR_EVEN, T },
  692. [PERF_COUNT_HW_BRANCH_MISSES] = { 0x02, CNTR_ODD, T },
  693. [PERF_COUNT_HW_BUS_CYCLES] = { UNSUPPORTED_PERF_EVENT_ID },
  694. };
  695. /* 74K core has different branch event code. */
  696. static const struct mips_perf_event mipsxx74Kcore_event_map
  697. [PERF_COUNT_HW_MAX] = {
  698. [PERF_COUNT_HW_CPU_CYCLES] = { 0x00, CNTR_EVEN | CNTR_ODD, P },
  699. [PERF_COUNT_HW_INSTRUCTIONS] = { 0x01, CNTR_EVEN | CNTR_ODD, T },
  700. [PERF_COUNT_HW_CACHE_REFERENCES] = { UNSUPPORTED_PERF_EVENT_ID },
  701. [PERF_COUNT_HW_CACHE_MISSES] = { UNSUPPORTED_PERF_EVENT_ID },
  702. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { 0x27, CNTR_EVEN, T },
  703. [PERF_COUNT_HW_BRANCH_MISSES] = { 0x27, CNTR_ODD, T },
  704. [PERF_COUNT_HW_BUS_CYCLES] = { UNSUPPORTED_PERF_EVENT_ID },
  705. };
  706. static const struct mips_perf_event octeon_event_map[PERF_COUNT_HW_MAX] = {
  707. [PERF_COUNT_HW_CPU_CYCLES] = { 0x01, CNTR_ALL },
  708. [PERF_COUNT_HW_INSTRUCTIONS] = { 0x03, CNTR_ALL },
  709. [PERF_COUNT_HW_CACHE_REFERENCES] = { 0x2b, CNTR_ALL },
  710. [PERF_COUNT_HW_CACHE_MISSES] = { 0x2e, CNTR_ALL },
  711. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { 0x08, CNTR_ALL },
  712. [PERF_COUNT_HW_BRANCH_MISSES] = { 0x09, CNTR_ALL },
  713. [PERF_COUNT_HW_BUS_CYCLES] = { 0x25, CNTR_ALL },
  714. };
  715. /* 24K/34K/1004K cores can share the same cache event map. */
  716. static const struct mips_perf_event mipsxxcore_cache_map
  717. [PERF_COUNT_HW_CACHE_MAX]
  718. [PERF_COUNT_HW_CACHE_OP_MAX]
  719. [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
  720. [C(L1D)] = {
  721. /*
  722. * Like some other architectures (e.g. ARM), the performance
  723. * counters don't differentiate between read and write
  724. * accesses/misses, so this isn't strictly correct, but it's the
  725. * best we can do. Writes and reads get combined.
  726. */
  727. [C(OP_READ)] = {
  728. [C(RESULT_ACCESS)] = { 0x0a, CNTR_EVEN, T },
  729. [C(RESULT_MISS)] = { 0x0b, CNTR_EVEN | CNTR_ODD, T },
  730. },
  731. [C(OP_WRITE)] = {
  732. [C(RESULT_ACCESS)] = { 0x0a, CNTR_EVEN, T },
  733. [C(RESULT_MISS)] = { 0x0b, CNTR_EVEN | CNTR_ODD, T },
  734. },
  735. [C(OP_PREFETCH)] = {
  736. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  737. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  738. },
  739. },
  740. [C(L1I)] = {
  741. [C(OP_READ)] = {
  742. [C(RESULT_ACCESS)] = { 0x09, CNTR_EVEN, T },
  743. [C(RESULT_MISS)] = { 0x09, CNTR_ODD, T },
  744. },
  745. [C(OP_WRITE)] = {
  746. [C(RESULT_ACCESS)] = { 0x09, CNTR_EVEN, T },
  747. [C(RESULT_MISS)] = { 0x09, CNTR_ODD, T },
  748. },
  749. [C(OP_PREFETCH)] = {
  750. [C(RESULT_ACCESS)] = { 0x14, CNTR_EVEN, T },
  751. /*
  752. * Note that MIPS has only "hit" events countable for
  753. * the prefetch operation.
  754. */
  755. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  756. },
  757. },
  758. [C(LL)] = {
  759. [C(OP_READ)] = {
  760. [C(RESULT_ACCESS)] = { 0x15, CNTR_ODD, P },
  761. [C(RESULT_MISS)] = { 0x16, CNTR_EVEN, P },
  762. },
  763. [C(OP_WRITE)] = {
  764. [C(RESULT_ACCESS)] = { 0x15, CNTR_ODD, P },
  765. [C(RESULT_MISS)] = { 0x16, CNTR_EVEN, P },
  766. },
  767. [C(OP_PREFETCH)] = {
  768. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  769. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  770. },
  771. },
  772. [C(DTLB)] = {
  773. [C(OP_READ)] = {
  774. [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
  775. [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
  776. },
  777. [C(OP_WRITE)] = {
  778. [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
  779. [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
  780. },
  781. [C(OP_PREFETCH)] = {
  782. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  783. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  784. },
  785. },
  786. [C(ITLB)] = {
  787. [C(OP_READ)] = {
  788. [C(RESULT_ACCESS)] = { 0x05, CNTR_EVEN, T },
  789. [C(RESULT_MISS)] = { 0x05, CNTR_ODD, T },
  790. },
  791. [C(OP_WRITE)] = {
  792. [C(RESULT_ACCESS)] = { 0x05, CNTR_EVEN, T },
  793. [C(RESULT_MISS)] = { 0x05, CNTR_ODD, T },
  794. },
  795. [C(OP_PREFETCH)] = {
  796. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  797. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  798. },
  799. },
  800. [C(BPU)] = {
  801. /* Using the same code for *HW_BRANCH* */
  802. [C(OP_READ)] = {
  803. [C(RESULT_ACCESS)] = { 0x02, CNTR_EVEN, T },
  804. [C(RESULT_MISS)] = { 0x02, CNTR_ODD, T },
  805. },
  806. [C(OP_WRITE)] = {
  807. [C(RESULT_ACCESS)] = { 0x02, CNTR_EVEN, T },
  808. [C(RESULT_MISS)] = { 0x02, CNTR_ODD, T },
  809. },
  810. [C(OP_PREFETCH)] = {
  811. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  812. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  813. },
  814. },
  815. [C(NODE)] = {
  816. [C(OP_READ)] = {
  817. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  818. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  819. },
  820. [C(OP_WRITE)] = {
  821. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  822. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  823. },
  824. [C(OP_PREFETCH)] = {
  825. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  826. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  827. },
  828. },
  829. };
  830. /* 74K core has completely different cache event map. */
  831. static const struct mips_perf_event mipsxx74Kcore_cache_map
  832. [PERF_COUNT_HW_CACHE_MAX]
  833. [PERF_COUNT_HW_CACHE_OP_MAX]
  834. [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
  835. [C(L1D)] = {
  836. /*
  837. * Like some other architectures (e.g. ARM), the performance
  838. * counters don't differentiate between read and write
  839. * accesses/misses, so this isn't strictly correct, but it's the
  840. * best we can do. Writes and reads get combined.
  841. */
  842. [C(OP_READ)] = {
  843. [C(RESULT_ACCESS)] = { 0x17, CNTR_ODD, T },
  844. [C(RESULT_MISS)] = { 0x18, CNTR_ODD, T },
  845. },
  846. [C(OP_WRITE)] = {
  847. [C(RESULT_ACCESS)] = { 0x17, CNTR_ODD, T },
  848. [C(RESULT_MISS)] = { 0x18, CNTR_ODD, T },
  849. },
  850. [C(OP_PREFETCH)] = {
  851. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  852. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  853. },
  854. },
  855. [C(L1I)] = {
  856. [C(OP_READ)] = {
  857. [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
  858. [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
  859. },
  860. [C(OP_WRITE)] = {
  861. [C(RESULT_ACCESS)] = { 0x06, CNTR_EVEN, T },
  862. [C(RESULT_MISS)] = { 0x06, CNTR_ODD, T },
  863. },
  864. [C(OP_PREFETCH)] = {
  865. [C(RESULT_ACCESS)] = { 0x34, CNTR_EVEN, T },
  866. /*
  867. * Note that MIPS has only "hit" events countable for
  868. * the prefetch operation.
  869. */
  870. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  871. },
  872. },
  873. [C(LL)] = {
  874. [C(OP_READ)] = {
  875. [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P },
  876. [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN | CNTR_ODD, P },
  877. },
  878. [C(OP_WRITE)] = {
  879. [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P },
  880. [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN | CNTR_ODD, P },
  881. },
  882. [C(OP_PREFETCH)] = {
  883. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  884. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  885. },
  886. },
  887. [C(DTLB)] = {
  888. /* 74K core does not have specific DTLB events. */
  889. [C(OP_READ)] = {
  890. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  891. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  892. },
  893. [C(OP_WRITE)] = {
  894. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  895. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  896. },
  897. [C(OP_PREFETCH)] = {
  898. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  899. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  900. },
  901. },
  902. [C(ITLB)] = {
  903. [C(OP_READ)] = {
  904. [C(RESULT_ACCESS)] = { 0x04, CNTR_EVEN, T },
  905. [C(RESULT_MISS)] = { 0x04, CNTR_ODD, T },
  906. },
  907. [C(OP_WRITE)] = {
  908. [C(RESULT_ACCESS)] = { 0x04, CNTR_EVEN, T },
  909. [C(RESULT_MISS)] = { 0x04, CNTR_ODD, T },
  910. },
  911. [C(OP_PREFETCH)] = {
  912. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  913. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  914. },
  915. },
  916. [C(BPU)] = {
  917. /* Using the same code for *HW_BRANCH* */
  918. [C(OP_READ)] = {
  919. [C(RESULT_ACCESS)] = { 0x27, CNTR_EVEN, T },
  920. [C(RESULT_MISS)] = { 0x27, CNTR_ODD, T },
  921. },
  922. [C(OP_WRITE)] = {
  923. [C(RESULT_ACCESS)] = { 0x27, CNTR_EVEN, T },
  924. [C(RESULT_MISS)] = { 0x27, CNTR_ODD, T },
  925. },
  926. [C(OP_PREFETCH)] = {
  927. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  928. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  929. },
  930. },
  931. [C(NODE)] = {
  932. [C(OP_READ)] = {
  933. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  934. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  935. },
  936. [C(OP_WRITE)] = {
  937. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  938. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  939. },
  940. [C(OP_PREFETCH)] = {
  941. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  942. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  943. },
  944. },
  945. };
  946. static const struct mips_perf_event octeon_cache_map
  947. [PERF_COUNT_HW_CACHE_MAX]
  948. [PERF_COUNT_HW_CACHE_OP_MAX]
  949. [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
  950. [C(L1D)] = {
  951. [C(OP_READ)] = {
  952. [C(RESULT_ACCESS)] = { 0x2b, CNTR_ALL },
  953. [C(RESULT_MISS)] = { 0x2e, CNTR_ALL },
  954. },
  955. [C(OP_WRITE)] = {
  956. [C(RESULT_ACCESS)] = { 0x30, CNTR_ALL },
  957. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  958. },
  959. [C(OP_PREFETCH)] = {
  960. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  961. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  962. },
  963. },
  964. [C(L1I)] = {
  965. [C(OP_READ)] = {
  966. [C(RESULT_ACCESS)] = { 0x18, CNTR_ALL },
  967. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  968. },
  969. [C(OP_WRITE)] = {
  970. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  971. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  972. },
  973. [C(OP_PREFETCH)] = {
  974. [C(RESULT_ACCESS)] = { 0x19, CNTR_ALL },
  975. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  976. },
  977. },
  978. [C(LL)] = {
  979. [C(OP_READ)] = {
  980. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  981. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  982. },
  983. [C(OP_WRITE)] = {
  984. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  985. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  986. },
  987. [C(OP_PREFETCH)] = {
  988. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  989. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  990. },
  991. },
  992. [C(DTLB)] = {
  993. /*
  994. * Only general DTLB misses are counted use the same event for
  995. * read and write.
  996. */
  997. [C(OP_READ)] = {
  998. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  999. [C(RESULT_MISS)] = { 0x35, CNTR_ALL },
  1000. },
  1001. [C(OP_WRITE)] = {
  1002. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1003. [C(RESULT_MISS)] = { 0x35, CNTR_ALL },
  1004. },
  1005. [C(OP_PREFETCH)] = {
  1006. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1007. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1008. },
  1009. },
  1010. [C(ITLB)] = {
  1011. [C(OP_READ)] = {
  1012. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1013. [C(RESULT_MISS)] = { 0x37, CNTR_ALL },
  1014. },
  1015. [C(OP_WRITE)] = {
  1016. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1017. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1018. },
  1019. [C(OP_PREFETCH)] = {
  1020. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1021. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1022. },
  1023. },
  1024. [C(BPU)] = {
  1025. /* Using the same code for *HW_BRANCH* */
  1026. [C(OP_READ)] = {
  1027. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1028. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1029. },
  1030. [C(OP_WRITE)] = {
  1031. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1032. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1033. },
  1034. [C(OP_PREFETCH)] = {
  1035. [C(RESULT_ACCESS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1036. [C(RESULT_MISS)] = { UNSUPPORTED_PERF_EVENT_ID },
  1037. },
  1038. },
  1039. };
  1040. #ifdef CONFIG_MIPS_MT_SMP
  1041. static void check_and_calc_range(struct perf_event *event,
  1042. const struct mips_perf_event *pev)
  1043. {
  1044. struct hw_perf_event *hwc = &event->hw;
  1045. if (event->cpu >= 0) {
  1046. if (pev->range > V) {
  1047. /*
  1048. * The user selected an event that is processor
  1049. * wide, while expecting it to be VPE wide.
  1050. */
  1051. hwc->config_base |= M_TC_EN_ALL;
  1052. } else {
  1053. /*
  1054. * FIXME: cpu_data[event->cpu].vpe_id reports 0
  1055. * for both CPUs.
  1056. */
  1057. hwc->config_base |= M_PERFCTL_VPEID(event->cpu);
  1058. hwc->config_base |= M_TC_EN_VPE;
  1059. }
  1060. } else
  1061. hwc->config_base |= M_TC_EN_ALL;
  1062. }
  1063. #else
  1064. static void check_and_calc_range(struct perf_event *event,
  1065. const struct mips_perf_event *pev)
  1066. {
  1067. }
  1068. #endif
  1069. static int __hw_perf_event_init(struct perf_event *event)
  1070. {
  1071. struct perf_event_attr *attr = &event->attr;
  1072. struct hw_perf_event *hwc = &event->hw;
  1073. const struct mips_perf_event *pev;
  1074. int err;
  1075. /* Returning MIPS event descriptor for generic perf event. */
  1076. if (PERF_TYPE_HARDWARE == event->attr.type) {
  1077. if (event->attr.config >= PERF_COUNT_HW_MAX)
  1078. return -EINVAL;
  1079. pev = mipspmu_map_general_event(event->attr.config);
  1080. } else if (PERF_TYPE_HW_CACHE == event->attr.type) {
  1081. pev = mipspmu_map_cache_event(event->attr.config);
  1082. } else if (PERF_TYPE_RAW == event->attr.type) {
  1083. /* We are working on the global raw event. */
  1084. mutex_lock(&raw_event_mutex);
  1085. pev = mipspmu.map_raw_event(event->attr.config);
  1086. } else {
  1087. /* The event type is not (yet) supported. */
  1088. return -EOPNOTSUPP;
  1089. }
  1090. if (IS_ERR(pev)) {
  1091. if (PERF_TYPE_RAW == event->attr.type)
  1092. mutex_unlock(&raw_event_mutex);
  1093. return PTR_ERR(pev);
  1094. }
  1095. /*
  1096. * We allow max flexibility on how each individual counter shared
  1097. * by the single CPU operates (the mode exclusion and the range).
  1098. */
  1099. hwc->config_base = M_PERFCTL_INTERRUPT_ENABLE;
  1100. /* Calculate range bits and validate it. */
  1101. if (num_possible_cpus() > 1)
  1102. check_and_calc_range(event, pev);
  1103. hwc->event_base = mipspmu_perf_event_encode(pev);
  1104. if (PERF_TYPE_RAW == event->attr.type)
  1105. mutex_unlock(&raw_event_mutex);
  1106. if (!attr->exclude_user)
  1107. hwc->config_base |= M_PERFCTL_USER;
  1108. if (!attr->exclude_kernel) {
  1109. hwc->config_base |= M_PERFCTL_KERNEL;
  1110. /* MIPS kernel mode: KSU == 00b || EXL == 1 || ERL == 1 */
  1111. hwc->config_base |= M_PERFCTL_EXL;
  1112. }
  1113. if (!attr->exclude_hv)
  1114. hwc->config_base |= M_PERFCTL_SUPERVISOR;
  1115. hwc->config_base &= M_PERFCTL_CONFIG_MASK;
  1116. /*
  1117. * The event can belong to another cpu. We do not assign a local
  1118. * counter for it for now.
  1119. */
  1120. hwc->idx = -1;
  1121. hwc->config = 0;
  1122. if (!hwc->sample_period) {
  1123. hwc->sample_period = mipspmu.max_period;
  1124. hwc->last_period = hwc->sample_period;
  1125. local64_set(&hwc->period_left, hwc->sample_period);
  1126. }
  1127. err = 0;
  1128. if (event->group_leader != event) {
  1129. err = validate_group(event);
  1130. if (err)
  1131. return -EINVAL;
  1132. }
  1133. event->destroy = hw_perf_event_destroy;
  1134. return err;
  1135. }
  1136. static void pause_local_counters(void)
  1137. {
  1138. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  1139. int ctr = mipspmu.num_counters;
  1140. unsigned long flags;
  1141. local_irq_save(flags);
  1142. do {
  1143. ctr--;
  1144. cpuc->saved_ctrl[ctr] = mipsxx_pmu_read_control(ctr);
  1145. mipsxx_pmu_write_control(ctr, cpuc->saved_ctrl[ctr] &
  1146. ~M_PERFCTL_COUNT_EVENT_WHENEVER);
  1147. } while (ctr > 0);
  1148. local_irq_restore(flags);
  1149. }
  1150. static void resume_local_counters(void)
  1151. {
  1152. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  1153. int ctr = mipspmu.num_counters;
  1154. do {
  1155. ctr--;
  1156. mipsxx_pmu_write_control(ctr, cpuc->saved_ctrl[ctr]);
  1157. } while (ctr > 0);
  1158. }
  1159. static int mipsxx_pmu_handle_shared_irq(void)
  1160. {
  1161. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  1162. struct perf_sample_data data;
  1163. unsigned int counters = mipspmu.num_counters;
  1164. u64 counter;
  1165. int handled = IRQ_NONE;
  1166. struct pt_regs *regs;
  1167. if (cpu_has_mips_r2 && !(read_c0_cause() & (1 << 26)))
  1168. return handled;
  1169. /*
  1170. * First we pause the local counters, so that when we are locked
  1171. * here, the counters are all paused. When it gets locked due to
  1172. * perf_disable(), the timer interrupt handler will be delayed.
  1173. *
  1174. * See also mipsxx_pmu_start().
  1175. */
  1176. pause_local_counters();
  1177. #ifdef CONFIG_MIPS_MT_SMP
  1178. read_lock(&pmuint_rwlock);
  1179. #endif
  1180. regs = get_irq_regs();
  1181. perf_sample_data_init(&data, 0);
  1182. switch (counters) {
  1183. #define HANDLE_COUNTER(n) \
  1184. case n + 1: \
  1185. if (test_bit(n, cpuc->used_mask)) { \
  1186. counter = mipspmu.read_counter(n); \
  1187. if (counter & mipspmu.overflow) { \
  1188. handle_associated_event(cpuc, n, &data, regs); \
  1189. handled = IRQ_HANDLED; \
  1190. } \
  1191. }
  1192. HANDLE_COUNTER(3)
  1193. HANDLE_COUNTER(2)
  1194. HANDLE_COUNTER(1)
  1195. HANDLE_COUNTER(0)
  1196. }
  1197. /*
  1198. * Do all the work for the pending perf events. We can do this
  1199. * in here because the performance counter interrupt is a regular
  1200. * interrupt, not NMI.
  1201. */
  1202. if (handled == IRQ_HANDLED)
  1203. irq_work_run();
  1204. #ifdef CONFIG_MIPS_MT_SMP
  1205. read_unlock(&pmuint_rwlock);
  1206. #endif
  1207. resume_local_counters();
  1208. return handled;
  1209. }
  1210. static irqreturn_t mipsxx_pmu_handle_irq(int irq, void *dev)
  1211. {
  1212. return mipsxx_pmu_handle_shared_irq();
  1213. }
  1214. /* 24K */
  1215. #define IS_UNSUPPORTED_24K_EVENT(r, b) \
  1216. ((b) == 12 || (r) == 151 || (r) == 152 || (b) == 26 || \
  1217. (b) == 27 || (r) == 28 || (r) == 158 || (b) == 31 || \
  1218. (b) == 32 || (b) == 34 || (b) == 36 || (r) == 168 || \
  1219. (r) == 172 || (b) == 47 || ((b) >= 56 && (b) <= 63) || \
  1220. ((b) >= 68 && (b) <= 127))
  1221. #define IS_BOTH_COUNTERS_24K_EVENT(b) \
  1222. ((b) == 0 || (b) == 1 || (b) == 11)
  1223. /* 34K */
  1224. #define IS_UNSUPPORTED_34K_EVENT(r, b) \
  1225. ((b) == 12 || (r) == 27 || (r) == 158 || (b) == 36 || \
  1226. (b) == 38 || (r) == 175 || ((b) >= 56 && (b) <= 63) || \
  1227. ((b) >= 68 && (b) <= 127))
  1228. #define IS_BOTH_COUNTERS_34K_EVENT(b) \
  1229. ((b) == 0 || (b) == 1 || (b) == 11)
  1230. #ifdef CONFIG_MIPS_MT_SMP
  1231. #define IS_RANGE_P_34K_EVENT(r, b) \
  1232. ((b) == 0 || (r) == 18 || (b) == 21 || (b) == 22 || \
  1233. (b) == 25 || (b) == 39 || (r) == 44 || (r) == 174 || \
  1234. (r) == 176 || ((b) >= 50 && (b) <= 55) || \
  1235. ((b) >= 64 && (b) <= 67))
  1236. #define IS_RANGE_V_34K_EVENT(r) ((r) == 47)
  1237. #endif
  1238. /* 74K */
  1239. #define IS_UNSUPPORTED_74K_EVENT(r, b) \
  1240. ((r) == 5 || ((r) >= 135 && (r) <= 137) || \
  1241. ((b) >= 10 && (b) <= 12) || (b) == 22 || (b) == 27 || \
  1242. (b) == 33 || (b) == 34 || ((b) >= 47 && (b) <= 49) || \
  1243. (r) == 178 || (b) == 55 || (b) == 57 || (b) == 60 || \
  1244. (b) == 61 || (r) == 62 || (r) == 191 || \
  1245. ((b) >= 64 && (b) <= 127))
  1246. #define IS_BOTH_COUNTERS_74K_EVENT(b) \
  1247. ((b) == 0 || (b) == 1)
  1248. /* 1004K */
  1249. #define IS_UNSUPPORTED_1004K_EVENT(r, b) \
  1250. ((b) == 12 || (r) == 27 || (r) == 158 || (b) == 38 || \
  1251. (r) == 175 || (b) == 63 || ((b) >= 68 && (b) <= 127))
  1252. #define IS_BOTH_COUNTERS_1004K_EVENT(b) \
  1253. ((b) == 0 || (b) == 1 || (b) == 11)
  1254. #ifdef CONFIG_MIPS_MT_SMP
  1255. #define IS_RANGE_P_1004K_EVENT(r, b) \
  1256. ((b) == 0 || (r) == 18 || (b) == 21 || (b) == 22 || \
  1257. (b) == 25 || (b) == 36 || (b) == 39 || (r) == 44 || \
  1258. (r) == 174 || (r) == 176 || ((b) >= 50 && (b) <= 59) || \
  1259. (r) == 188 || (b) == 61 || (b) == 62 || \
  1260. ((b) >= 64 && (b) <= 67))
  1261. #define IS_RANGE_V_1004K_EVENT(r) ((r) == 47)
  1262. #endif
  1263. /*
  1264. * User can use 0-255 raw events, where 0-127 for the events of even
  1265. * counters, and 128-255 for odd counters. Note that bit 7 is used to
  1266. * indicate the parity. So, for example, when user wants to take the
  1267. * Event Num of 15 for odd counters (by referring to the user manual),
  1268. * then 128 needs to be added to 15 as the input for the event config,
  1269. * i.e., 143 (0x8F) to be used.
  1270. */
  1271. static const struct mips_perf_event *mipsxx_pmu_map_raw_event(u64 config)
  1272. {
  1273. unsigned int raw_id = config & 0xff;
  1274. unsigned int base_id = raw_id & 0x7f;
  1275. switch (current_cpu_type()) {
  1276. case CPU_24K:
  1277. if (IS_UNSUPPORTED_24K_EVENT(raw_id, base_id))
  1278. return ERR_PTR(-EOPNOTSUPP);
  1279. raw_event.event_id = base_id;
  1280. if (IS_BOTH_COUNTERS_24K_EVENT(base_id))
  1281. raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
  1282. else
  1283. raw_event.cntr_mask =
  1284. raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
  1285. #ifdef CONFIG_MIPS_MT_SMP
  1286. /*
  1287. * This is actually doing nothing. Non-multithreading
  1288. * CPUs will not check and calculate the range.
  1289. */
  1290. raw_event.range = P;
  1291. #endif
  1292. break;
  1293. case CPU_34K:
  1294. if (IS_UNSUPPORTED_34K_EVENT(raw_id, base_id))
  1295. return ERR_PTR(-EOPNOTSUPP);
  1296. raw_event.event_id = base_id;
  1297. if (IS_BOTH_COUNTERS_34K_EVENT(base_id))
  1298. raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
  1299. else
  1300. raw_event.cntr_mask =
  1301. raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
  1302. #ifdef CONFIG_MIPS_MT_SMP
  1303. if (IS_RANGE_P_34K_EVENT(raw_id, base_id))
  1304. raw_event.range = P;
  1305. else if (unlikely(IS_RANGE_V_34K_EVENT(raw_id)))
  1306. raw_event.range = V;
  1307. else
  1308. raw_event.range = T;
  1309. #endif
  1310. break;
  1311. case CPU_74K:
  1312. if (IS_UNSUPPORTED_74K_EVENT(raw_id, base_id))
  1313. return ERR_PTR(-EOPNOTSUPP);
  1314. raw_event.event_id = base_id;
  1315. if (IS_BOTH_COUNTERS_74K_EVENT(base_id))
  1316. raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
  1317. else
  1318. raw_event.cntr_mask =
  1319. raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
  1320. #ifdef CONFIG_MIPS_MT_SMP
  1321. raw_event.range = P;
  1322. #endif
  1323. break;
  1324. case CPU_1004K:
  1325. if (IS_UNSUPPORTED_1004K_EVENT(raw_id, base_id))
  1326. return ERR_PTR(-EOPNOTSUPP);
  1327. raw_event.event_id = base_id;
  1328. if (IS_BOTH_COUNTERS_1004K_EVENT(base_id))
  1329. raw_event.cntr_mask = CNTR_EVEN | CNTR_ODD;
  1330. else
  1331. raw_event.cntr_mask =
  1332. raw_id > 127 ? CNTR_ODD : CNTR_EVEN;
  1333. #ifdef CONFIG_MIPS_MT_SMP
  1334. if (IS_RANGE_P_1004K_EVENT(raw_id, base_id))
  1335. raw_event.range = P;
  1336. else if (unlikely(IS_RANGE_V_1004K_EVENT(raw_id)))
  1337. raw_event.range = V;
  1338. else
  1339. raw_event.range = T;
  1340. #endif
  1341. break;
  1342. }
  1343. return &raw_event;
  1344. }
  1345. static const struct mips_perf_event *octeon_pmu_map_raw_event(u64 config)
  1346. {
  1347. unsigned int raw_id = config & 0xff;
  1348. unsigned int base_id = raw_id & 0x7f;
  1349. raw_event.cntr_mask = CNTR_ALL;
  1350. raw_event.event_id = base_id;
  1351. if (current_cpu_type() == CPU_CAVIUM_OCTEON2) {
  1352. if (base_id > 0x42)
  1353. return ERR_PTR(-EOPNOTSUPP);
  1354. } else {
  1355. if (base_id > 0x3a)
  1356. return ERR_PTR(-EOPNOTSUPP);
  1357. }
  1358. switch (base_id) {
  1359. case 0x00:
  1360. case 0x0f:
  1361. case 0x1e:
  1362. case 0x1f:
  1363. case 0x2f:
  1364. case 0x34:
  1365. case 0x3b ... 0x3f:
  1366. return ERR_PTR(-EOPNOTSUPP);
  1367. default:
  1368. break;
  1369. }
  1370. return &raw_event;
  1371. }
  1372. static int __init
  1373. init_hw_perf_events(void)
  1374. {
  1375. int counters, irq;
  1376. int counter_bits;
  1377. pr_info("Performance counters: ");
  1378. counters = n_counters();
  1379. if (counters == 0) {
  1380. pr_cont("No available PMU.\n");
  1381. return -ENODEV;
  1382. }
  1383. #ifdef CONFIG_MIPS_MT_SMP
  1384. cpu_has_mipsmt_pertccounters = read_c0_config7() & (1<<19);
  1385. if (!cpu_has_mipsmt_pertccounters)
  1386. counters = counters_total_to_per_cpu(counters);
  1387. #endif
  1388. #ifdef MSC01E_INT_BASE
  1389. if (cpu_has_veic) {
  1390. /*
  1391. * Using platform specific interrupt controller defines.
  1392. */
  1393. irq = MSC01E_INT_BASE + MSC01E_INT_PERFCTR;
  1394. } else {
  1395. #endif
  1396. if (cp0_perfcount_irq >= 0)
  1397. irq = MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
  1398. else
  1399. irq = -1;
  1400. #ifdef MSC01E_INT_BASE
  1401. }
  1402. #endif
  1403. mipspmu.map_raw_event = mipsxx_pmu_map_raw_event;
  1404. switch (current_cpu_type()) {
  1405. case CPU_24K:
  1406. mipspmu.name = "mips/24K";
  1407. mipspmu.general_event_map = &mipsxxcore_event_map;
  1408. mipspmu.cache_event_map = &mipsxxcore_cache_map;
  1409. break;
  1410. case CPU_34K:
  1411. mipspmu.name = "mips/34K";
  1412. mipspmu.general_event_map = &mipsxxcore_event_map;
  1413. mipspmu.cache_event_map = &mipsxxcore_cache_map;
  1414. break;
  1415. case CPU_74K:
  1416. mipspmu.name = "mips/74K";
  1417. mipspmu.general_event_map = &mipsxx74Kcore_event_map;
  1418. mipspmu.cache_event_map = &mipsxx74Kcore_cache_map;
  1419. break;
  1420. case CPU_1004K:
  1421. mipspmu.name = "mips/1004K";
  1422. mipspmu.general_event_map = &mipsxxcore_event_map;
  1423. mipspmu.cache_event_map = &mipsxxcore_cache_map;
  1424. break;
  1425. case CPU_CAVIUM_OCTEON:
  1426. case CPU_CAVIUM_OCTEON_PLUS:
  1427. case CPU_CAVIUM_OCTEON2:
  1428. mipspmu.name = "octeon";
  1429. mipspmu.general_event_map = &octeon_event_map;
  1430. mipspmu.cache_event_map = &octeon_cache_map;
  1431. mipspmu.map_raw_event = octeon_pmu_map_raw_event;
  1432. break;
  1433. default:
  1434. pr_cont("Either hardware does not support performance "
  1435. "counters, or not yet implemented.\n");
  1436. return -ENODEV;
  1437. }
  1438. mipspmu.num_counters = counters;
  1439. mipspmu.irq = irq;
  1440. if (read_c0_perfctrl0() & M_PERFCTL_WIDE) {
  1441. mipspmu.max_period = (1ULL << 63) - 1;
  1442. mipspmu.valid_count = (1ULL << 63) - 1;
  1443. mipspmu.overflow = 1ULL << 63;
  1444. mipspmu.read_counter = mipsxx_pmu_read_counter_64;
  1445. mipspmu.write_counter = mipsxx_pmu_write_counter_64;
  1446. counter_bits = 64;
  1447. } else {
  1448. mipspmu.max_period = (1ULL << 31) - 1;
  1449. mipspmu.valid_count = (1ULL << 31) - 1;
  1450. mipspmu.overflow = 1ULL << 31;
  1451. mipspmu.read_counter = mipsxx_pmu_read_counter;
  1452. mipspmu.write_counter = mipsxx_pmu_write_counter;
  1453. counter_bits = 32;
  1454. }
  1455. on_each_cpu(reset_counters, (void *)(long)counters, 1);
  1456. pr_cont("%s PMU enabled, %d %d-bit counters available to each "
  1457. "CPU, irq %d%s\n", mipspmu.name, counters, counter_bits, irq,
  1458. irq < 0 ? " (share with timer interrupt)" : "");
  1459. perf_pmu_register(&pmu, "cpu", PERF_TYPE_RAW);
  1460. return 0;
  1461. }
  1462. early_initcall(init_hw_perf_events);