perfmon.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /*
  2. * Copyright (c) 2014-2018 Remy Noel.
  3. * Copyright (c) 2014-2018 Richard Braun.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. *
  19. * Locking order :
  20. *
  21. * thread_runq -+
  22. * |
  23. * event -+-> interrupts -+-> td
  24. * |
  25. * +-> pmu
  26. *
  27. * TODO Kernel/user mode seggregation.
  28. */
  29. #include <assert.h>
  30. #include <errno.h>
  31. #include <stddef.h>
  32. #include <stdint.h>
  33. #include <stdio.h>
  34. #include <kern/clock.h>
  35. #include <kern/init.h>
  36. #include <kern/list.h>
  37. #include <kern/log.h>
  38. #include <kern/macros.h>
  39. #include <kern/percpu.h>
  40. #include <kern/perfmon.h>
  41. #include <kern/perfmon_types.h>
  42. #include <kern/spinlock.h>
  43. #include <kern/syscnt.h>
  44. #include <kern/thread.h>
  45. #include <kern/timer.h>
  46. #include <kern/xcall.h>
  47. #include <machine/boot.h>
  48. #include <machine/cpu.h>
  49. /*
  50. * Minimum hardware counter poll interval, in milliseconds.
  51. *
  52. * The main purpose of polling hardware counters is to detect overflows
  53. * when the driver is unable to reliably use overflow interrupts.
  54. */
  55. #define PERFMON_MIN_POLL_INTERVAL 50
  56. // Internal event flags.
  57. #define PERFMON_EF_TYPE_CPU 0x100
  58. #define PERFMON_EF_ATTACHED 0x200
  59. #define PERFMON_EF_PUBLIC_MASK \
  60. (PERFMON_EF_KERN | PERFMON_EF_USER | PERFMON_EF_RAW)
  61. /*
  62. * Per-CPU performance monitoring counter.
  63. *
  64. * When an event is attached to a processor, the matching per-CPU PMC get
  65. * referenced. When a per-CPU PMC is referenced, its underlying hardware
  66. * counter is active.
  67. *
  68. * Interrupts and preemption must be disabled on access.
  69. */
  70. struct perfmon_cpu_pmc
  71. {
  72. unsigned int nr_refs;
  73. unsigned int pmc_id;
  74. unsigned int raw_event_id;
  75. uint64_t raw_value;
  76. uint64_t value;
  77. };
  78. /*
  79. * Per-CPU performance monitoring unit.
  80. *
  81. * Per-CPU PMCs are indexed the same way as global PMCs.
  82. *
  83. * Interrupts and preemption must be disabled on access.
  84. */
  85. struct perfmon_cpu_pmu
  86. {
  87. struct perfmon_dev *dev;
  88. unsigned int cpu;
  89. struct perfmon_cpu_pmc pmcs[PERFMON_MAX_PMCS];
  90. struct timer poll_timer;
  91. struct syscnt sc_nr_overflows;
  92. };
  93. /*
  94. * Performance monitoring counter.
  95. *
  96. * When a PMC is used, it maps a raw event to a hardware counter.
  97. * A PMC is used if and only if its reference counter isn't zero.
  98. */
  99. struct perfmon_pmc
  100. {
  101. unsigned int nr_refs;
  102. unsigned int pmc_id;
  103. unsigned int raw_event_id;
  104. };
  105. /*
  106. * Performance monitoring unit.
  107. *
  108. * There is a single system-wide logical PMU, used to globally allocate
  109. * PMCs. Reserving a counter across the entire system ensures thread
  110. * migration isn't hindered by performance monitoring.
  111. *
  112. * Locking the global PMU is only required when allocating or releasing
  113. * a PMC. Once allocated, the PMC may safely be accessed without hodling
  114. * the lock.
  115. */
  116. struct perfmon_pmu
  117. {
  118. struct perfmon_dev *dev;
  119. struct spinlock lock;
  120. struct perfmon_pmc pmcs[PERFMON_MAX_PMCS];
  121. };
  122. static struct perfmon_pmu perfmon_pmu;
  123. static struct perfmon_cpu_pmu perfmon_cpu_pmu __percpu;
  124. static struct perfmon_pmu*
  125. perfmon_get_pmu (void)
  126. {
  127. return (&perfmon_pmu);
  128. }
  129. static struct perfmon_cpu_pmu*
  130. perfmon_get_local_cpu_pmu (void)
  131. {
  132. assert (!thread_preempt_enabled ());
  133. return (cpu_local_ptr (perfmon_cpu_pmu));
  134. }
  135. static struct perfmon_cpu_pmu*
  136. perfmon_get_cpu_pmu (unsigned int cpu)
  137. {
  138. return (percpu_ptr (perfmon_cpu_pmu, cpu));
  139. }
  140. static void __init
  141. perfmon_pmc_init (struct perfmon_pmc *pmc)
  142. {
  143. pmc->nr_refs = 0;
  144. }
  145. static bool
  146. perfmon_pmc_used (const struct perfmon_pmc *pmc)
  147. {
  148. return (pmc->nr_refs != 0);
  149. }
  150. static unsigned int
  151. perfmon_pmc_id (const struct perfmon_pmc *pmc)
  152. {
  153. return (pmc->pmc_id);
  154. }
  155. static unsigned int
  156. perfmon_pmc_raw_event_id (const struct perfmon_pmc *pmc)
  157. {
  158. return (pmc->raw_event_id);
  159. }
  160. static void
  161. perfmon_pmc_use (struct perfmon_pmc *pmc, unsigned int pmc_id,
  162. unsigned int raw_event_id)
  163. {
  164. assert (!perfmon_pmc_used (pmc));
  165. pmc->nr_refs = 1;
  166. pmc->pmc_id = pmc_id;
  167. pmc->raw_event_id = raw_event_id;
  168. }
  169. static void
  170. perfmon_pmc_ref (struct perfmon_pmc *pmc)
  171. {
  172. assert (perfmon_pmc_used (pmc));
  173. ++pmc->nr_refs;
  174. }
  175. static void
  176. perfmon_pmc_unref (struct perfmon_pmc *pmc)
  177. {
  178. assert (perfmon_pmc_used (pmc));
  179. --pmc->nr_refs;
  180. }
  181. static unsigned int
  182. perfmon_pmu_get_pmc_index (const struct perfmon_pmu *pmu,
  183. const struct perfmon_pmc *pmc)
  184. {
  185. size_t pmc_index = pmc - pmu->pmcs;
  186. assert (pmc_index < ARRAY_SIZE (pmu->pmcs));
  187. return (pmc_index);
  188. }
  189. static struct perfmon_pmc*
  190. perfmon_pmu_get_pmc (struct perfmon_pmu *pmu, unsigned int index)
  191. {
  192. assert (index < ARRAY_SIZE (pmu->pmcs));
  193. return (&pmu->pmcs[index]);
  194. }
  195. static void __init
  196. perfmon_pmu_init (struct perfmon_pmu *pmu)
  197. {
  198. pmu->dev = NULL;
  199. spinlock_init (&pmu->lock);
  200. for (size_t i = 0; i < ARRAY_SIZE (pmu->pmcs); i++)
  201. perfmon_pmc_init (perfmon_pmu_get_pmc (pmu, i));
  202. }
  203. static void __init
  204. perfmon_pmu_set_dev (struct perfmon_pmu *pmu, struct perfmon_dev *dev)
  205. {
  206. assert (dev);
  207. assert (!pmu->dev);
  208. pmu->dev = dev;
  209. }
  210. static struct perfmon_dev*
  211. perfmon_pmu_get_dev (const struct perfmon_pmu *pmu)
  212. {
  213. return (pmu->dev);
  214. }
  215. static void
  216. perfmon_pmu_handle_overflow_intr (const struct perfmon_pmu *pmu)
  217. {
  218. pmu->dev->ops->handle_overflow_intr ();
  219. }
  220. static int
  221. perfmon_pmu_translate (const struct perfmon_pmu *pmu,
  222. unsigned int *raw_event_id,
  223. unsigned int event_id)
  224. {
  225. return (pmu->dev ?
  226. pmu->dev->ops->translate (raw_event_id, event_id) : ENODEV);
  227. }
  228. static int
  229. perfmon_pmu_alloc_pmc_id (const struct perfmon_pmu *pmu,
  230. unsigned int *pmc_idp,
  231. unsigned int pmc_index,
  232. unsigned int raw_event_id)
  233. {
  234. if (!pmu->dev)
  235. return (ENODEV);
  236. unsigned int pmc_id;
  237. int error = pmu->dev->ops->alloc (&pmc_id, pmc_index, raw_event_id);
  238. if (error)
  239. return (error);
  240. *pmc_idp = pmc_id;
  241. return (0);
  242. }
  243. static void
  244. perfmon_pmu_free_pmc_id (const struct perfmon_pmu *pmu, unsigned int pmc_id)
  245. {
  246. assert (pmu->dev);
  247. pmu->dev->ops->free (pmc_id);
  248. }
  249. static struct perfmon_pmc *
  250. perfmon_pmu_find_unused_pmc (struct perfmon_pmu *pmu)
  251. {
  252. for (size_t i = 0; i < ARRAY_SIZE (pmu->pmcs); i++)
  253. {
  254. _Auto pmc = perfmon_pmu_get_pmc (pmu, i);
  255. if (!perfmon_pmc_used (pmc))
  256. return (pmc);
  257. }
  258. return (NULL);
  259. }
  260. static int
  261. perfmon_pmu_alloc_pmc (struct perfmon_pmu *pmu, struct perfmon_pmc **pmcp,
  262. unsigned int raw_event_id)
  263. {
  264. _Auto pmc = perfmon_pmu_find_unused_pmc (pmu);
  265. if (! pmc)
  266. return (EAGAIN);
  267. unsigned int pmc_index = perfmon_pmu_get_pmc_index (pmu, pmc),
  268. pmc_id = 0;
  269. int error = perfmon_pmu_alloc_pmc_id (pmu, &pmc_id, pmc_index, raw_event_id);
  270. if (error)
  271. return (error);
  272. perfmon_pmc_use (pmc, pmc_id, raw_event_id);
  273. *pmcp = pmc;
  274. return (0);
  275. }
  276. static void
  277. perfmon_pmu_free_pmc (struct perfmon_pmu *pmu, struct perfmon_pmc *pmc)
  278. {
  279. assert (!perfmon_pmc_used (pmc));
  280. unsigned int pmc_id = perfmon_pmc_id (pmc);
  281. perfmon_pmu_free_pmc_id (pmu, pmc_id);
  282. }
  283. static struct perfmon_pmc *
  284. perfmon_pmu_get_pmc_by_raw_event_id (struct perfmon_pmu *pmu,
  285. unsigned int raw_event_id)
  286. {
  287. for (size_t i = 0; i < ARRAY_SIZE (pmu->pmcs); i++)
  288. {
  289. _Auto pmc = perfmon_pmu_get_pmc (pmu, i);
  290. if (!perfmon_pmc_used (pmc))
  291. continue;
  292. else if (perfmon_pmc_raw_event_id (pmc) == raw_event_id)
  293. return (pmc);
  294. }
  295. return (NULL);
  296. }
  297. static int
  298. perfmon_pmu_take_pmc (struct perfmon_pmu *pmu, struct perfmon_pmc **pmcp,
  299. unsigned int raw_event_id)
  300. {
  301. spinlock_lock (&pmu->lock);
  302. int error;
  303. _Auto pmc = perfmon_pmu_get_pmc_by_raw_event_id (pmu, raw_event_id);
  304. if (pmc)
  305. {
  306. perfmon_pmc_ref (pmc);
  307. error = 0;
  308. }
  309. else
  310. {
  311. error = perfmon_pmu_alloc_pmc (pmu, &pmc, raw_event_id);
  312. if (error)
  313. pmc = NULL;
  314. }
  315. spinlock_unlock (&pmu->lock);
  316. if (! error)
  317. *pmcp = pmc;
  318. return (error);
  319. }
  320. static void
  321. perfmon_pmu_put_pmc (struct perfmon_pmu *pmu, struct perfmon_pmc *pmc)
  322. {
  323. spinlock_lock (&pmu->lock);
  324. perfmon_pmc_unref (pmc);
  325. if (!perfmon_pmc_used (pmc))
  326. perfmon_pmu_free_pmc (pmu, pmc);
  327. spinlock_unlock (&pmu->lock);
  328. }
  329. static int
  330. perfmon_check_event_args (unsigned int id, unsigned int flags)
  331. {
  332. if (!((flags & PERFMON_EF_PUBLIC_MASK) == flags) ||
  333. !(flags & PERFMON_EF_RAW) || id < PERFMON_NR_GENERIC_EVENTS ||
  334. !((flags & (PERFMON_EF_KERN | PERFMON_EF_USER))))
  335. return (EINVAL);
  336. return (0);
  337. }
  338. int
  339. perfmon_event_init (struct perfmon_event *event, unsigned int id,
  340. unsigned int flags)
  341. {
  342. int error = perfmon_check_event_args (id, flags);
  343. if (error)
  344. return (error);
  345. spinlock_init (&event->lock);
  346. event->flags = flags;
  347. event->id = id;
  348. event->value = 0;
  349. return (0);
  350. }
  351. static bool
  352. perfmon_event_type_cpu (const struct perfmon_event *event)
  353. {
  354. return (event->flags & PERFMON_EF_TYPE_CPU);
  355. }
  356. static void
  357. perfmon_event_set_type_cpu (struct perfmon_event *event)
  358. {
  359. event->flags |= PERFMON_EF_TYPE_CPU;
  360. }
  361. static void
  362. perfmon_event_clear_type_cpu (struct perfmon_event *event)
  363. {
  364. event->flags &= ~PERFMON_EF_TYPE_CPU;
  365. }
  366. static bool
  367. perfmon_event_attached (const struct perfmon_event *event)
  368. {
  369. return (event->flags & PERFMON_EF_ATTACHED);
  370. }
  371. static unsigned int
  372. perfmon_event_pmc_index (const struct perfmon_event *event)
  373. {
  374. assert (perfmon_event_attached (event));
  375. return (event->pmc_index);
  376. }
  377. static void __init
  378. perfmon_cpu_pmc_init (struct perfmon_cpu_pmc *cpu_pmc)
  379. {
  380. cpu_pmc->nr_refs = 0;
  381. }
  382. static bool
  383. perfmon_cpu_pmc_used (const struct perfmon_cpu_pmc *cpu_pmc)
  384. {
  385. return (cpu_pmc->nr_refs != 0);
  386. }
  387. static void
  388. perfmon_cpu_pmc_use (struct perfmon_cpu_pmc *cpu_pmc, unsigned int pmc_id,
  389. unsigned int raw_event_id, uint64_t raw_value)
  390. {
  391. assert (!perfmon_cpu_pmc_used (cpu_pmc));
  392. cpu_pmc->nr_refs = 1;
  393. cpu_pmc->pmc_id = pmc_id;
  394. cpu_pmc->raw_event_id = raw_event_id;
  395. cpu_pmc->raw_value = raw_value;
  396. cpu_pmc->value = 0;
  397. }
  398. static void
  399. perfmon_cpu_pmc_ref (struct perfmon_cpu_pmc *cpu_pmc)
  400. {
  401. assert (perfmon_cpu_pmc_used (cpu_pmc));
  402. ++cpu_pmc->nr_refs;
  403. }
  404. static void
  405. perfmon_cpu_pmc_unref (struct perfmon_cpu_pmc *cpu_pmc)
  406. {
  407. assert (perfmon_cpu_pmc_used (cpu_pmc));
  408. --cpu_pmc->nr_refs;
  409. }
  410. static unsigned int
  411. perfmon_cpu_pmc_id (const struct perfmon_cpu_pmc *cpu_pmc)
  412. {
  413. return (cpu_pmc->pmc_id);
  414. }
  415. static bool
  416. perfmon_cpu_pmc_update (struct perfmon_cpu_pmc *cpu_pmc, uint64_t raw_value,
  417. unsigned int pmc_width)
  418. {
  419. uint64_t delta = raw_value - cpu_pmc->raw_value;
  420. bool overflowed;
  421. if (pmc_width == 64)
  422. overflowed = false;
  423. else if (raw_value >= cpu_pmc->raw_value)
  424. overflowed = false;
  425. else
  426. {
  427. overflowed = true;
  428. delta += (uint64_t)1 << pmc_width;
  429. }
  430. cpu_pmc->value += delta;
  431. cpu_pmc->raw_value = raw_value;
  432. return (overflowed);
  433. }
  434. static uint64_t
  435. perfmon_cpu_pmc_get_value (const struct perfmon_cpu_pmc *cpu_pmc)
  436. {
  437. return (cpu_pmc->value);
  438. }
  439. static struct perfmon_cpu_pmc*
  440. perfmon_cpu_pmu_get_pmc (struct perfmon_cpu_pmu *cpu_pmu, unsigned int index)
  441. {
  442. assert (index < ARRAY_SIZE (cpu_pmu->pmcs));
  443. return (&cpu_pmu->pmcs[index]);
  444. }
  445. static void
  446. perfmon_cpu_pmu_start (struct perfmon_cpu_pmu *cpu_pmu, unsigned int pmc_id,
  447. unsigned int raw_event_id)
  448. {
  449. cpu_pmu->dev->ops->start (pmc_id, raw_event_id);
  450. }
  451. static void
  452. perfmon_cpu_pmu_stop (struct perfmon_cpu_pmu *cpu_pmu, unsigned int pmc_id)
  453. {
  454. cpu_pmu->dev->ops->stop (pmc_id);
  455. }
  456. static uint64_t
  457. perfmon_cpu_pmu_read (const struct perfmon_cpu_pmu *cpu_pmu, unsigned int pmc_id)
  458. {
  459. return (cpu_pmu->dev->ops->read (pmc_id));
  460. }
  461. static void
  462. perfmon_cpu_pmu_use_pmc (struct perfmon_cpu_pmu *cpu_pmu,
  463. struct perfmon_cpu_pmc *cpu_pmc,
  464. unsigned int pmc_id,
  465. unsigned int raw_event_id)
  466. {
  467. perfmon_cpu_pmu_start (cpu_pmu, pmc_id, raw_event_id);
  468. uint64_t raw_value = perfmon_cpu_pmu_read (cpu_pmu, pmc_id);
  469. perfmon_cpu_pmc_use (cpu_pmc, pmc_id, raw_event_id, raw_value);
  470. }
  471. static void
  472. perfmon_cpu_pmu_update_pmc (struct perfmon_cpu_pmu *cpu_pmu,
  473. struct perfmon_cpu_pmc *cpu_pmc)
  474. {
  475. uint64_t raw_value = perfmon_cpu_pmu_read (cpu_pmu,
  476. perfmon_cpu_pmc_id (cpu_pmc));
  477. bool overflowed = perfmon_cpu_pmc_update (cpu_pmc, raw_value,
  478. cpu_pmu->dev->pmc_width);
  479. if (overflowed)
  480. syscnt_inc (&cpu_pmu->sc_nr_overflows);
  481. }
  482. static void
  483. perfmon_cpu_pmu_check_overflow (void *arg)
  484. {
  485. assert (!cpu_intr_enabled ());
  486. struct perfmon_cpu_pmu *cpu_pmu = arg;
  487. assert (cpu_pmu->cpu == cpu_id ());
  488. for (size_t i = 0; i < ARRAY_SIZE (cpu_pmu->pmcs); i++)
  489. {
  490. _Auto cpu_pmc = perfmon_cpu_pmu_get_pmc (cpu_pmu, i);
  491. if (!perfmon_cpu_pmc_used (cpu_pmc))
  492. continue;
  493. perfmon_cpu_pmu_update_pmc (cpu_pmu, cpu_pmc);
  494. }
  495. }
  496. static void
  497. perfmon_cpu_pmu_poll (struct timer *timer)
  498. {
  499. _Auto cpu_pmu = structof (timer, struct perfmon_cpu_pmu, poll_timer);
  500. xcall_call (perfmon_cpu_pmu_check_overflow, cpu_pmu, cpu_pmu->cpu);
  501. timer_schedule (timer, timer_get_time (timer) + cpu_pmu->dev->poll_interval);
  502. }
  503. static void __init
  504. perfmon_cpu_pmu_init (struct perfmon_cpu_pmu *cpu_pmu, unsigned int cpu,
  505. struct perfmon_dev *dev)
  506. {
  507. cpu_pmu->dev = dev;
  508. cpu_pmu->cpu = cpu;
  509. for (size_t i = 0; i < ARRAY_SIZE (cpu_pmu->pmcs); i++)
  510. perfmon_cpu_pmc_init (perfmon_cpu_pmu_get_pmc (cpu_pmu, i));
  511. if (dev->ops->handle_overflow_intr == NULL)
  512. {
  513. assert (dev->poll_interval != 0);
  514. /*
  515. * XXX Ideally, this would be an interrupt timer instead of a high
  516. * priority one, but it can't be because the handler performs
  517. * cross-calls to remote processors, which requires that interrupts
  518. * be enabled. This is one potential user of CPU-bound timers.
  519. */
  520. timer_init (&cpu_pmu->poll_timer, perfmon_cpu_pmu_poll, TIMER_HIGH_PRIO);
  521. timer_schedule (&cpu_pmu->poll_timer, dev->poll_interval);
  522. }
  523. char name[SYSCNT_NAME_SIZE];
  524. snprintf (name, sizeof (name), "perfmon_nr_overflows/%u", cpu);
  525. syscnt_register (&cpu_pmu->sc_nr_overflows, name);
  526. }
  527. static uint64_t
  528. perfmon_cpu_pmu_load (struct perfmon_cpu_pmu *cpu_pmu, unsigned int pmc_index,
  529. unsigned int pmc_id, unsigned int raw_event_id)
  530. {
  531. assert (!cpu_intr_enabled ());
  532. _Auto cpu_pmc = perfmon_cpu_pmu_get_pmc (cpu_pmu, pmc_index);
  533. if (perfmon_cpu_pmc_used (cpu_pmc))
  534. {
  535. perfmon_cpu_pmc_ref (cpu_pmc);
  536. perfmon_cpu_pmu_update_pmc (cpu_pmu, cpu_pmc);
  537. }
  538. else
  539. perfmon_cpu_pmu_use_pmc (cpu_pmu, cpu_pmc, pmc_id, raw_event_id);
  540. return (perfmon_cpu_pmc_get_value (cpu_pmc));
  541. }
  542. static uint64_t
  543. perfmon_cpu_pmu_unload (struct perfmon_cpu_pmu *cpu_pmu, unsigned int pmc_index)
  544. {
  545. assert (!cpu_intr_enabled ());
  546. _Auto cpu_pmc = perfmon_cpu_pmu_get_pmc (cpu_pmu, pmc_index);
  547. unsigned int pmc_id = perfmon_cpu_pmc_id (cpu_pmc);
  548. perfmon_cpu_pmu_update_pmc (cpu_pmu, cpu_pmc);
  549. uint64_t value = perfmon_cpu_pmc_get_value (cpu_pmc);
  550. perfmon_cpu_pmc_unref (cpu_pmc);
  551. if (!perfmon_cpu_pmc_used (cpu_pmc))
  552. perfmon_cpu_pmu_stop (cpu_pmu, pmc_id);
  553. return (value);
  554. }
  555. static uint64_t
  556. perfmon_cpu_pmu_sync (struct perfmon_cpu_pmu *cpu_pmu, unsigned int pmc_index)
  557. {
  558. assert (!cpu_intr_enabled ());
  559. _Auto cpu_pmc = perfmon_cpu_pmu_get_pmc (cpu_pmu, pmc_index);
  560. perfmon_cpu_pmu_update_pmc (cpu_pmu, cpu_pmc);
  561. return (perfmon_cpu_pmc_get_value (cpu_pmc));
  562. }
  563. static void
  564. perfmon_td_pmc_init (struct perfmon_td_pmc *td_pmc)
  565. {
  566. td_pmc->nr_refs = 0;
  567. td_pmc->loaded = false;
  568. td_pmc->value = 0;
  569. }
  570. static bool
  571. perfmon_td_pmc_used (const struct perfmon_td_pmc *td_pmc)
  572. {
  573. return (td_pmc->nr_refs != 0);
  574. }
  575. static void
  576. perfmon_td_pmc_use (struct perfmon_td_pmc *td_pmc, unsigned int pmc_id,
  577. unsigned int raw_event_id)
  578. {
  579. assert (!perfmon_td_pmc_used (td_pmc));
  580. td_pmc->nr_refs = 1;
  581. td_pmc->loaded = false;
  582. td_pmc->pmc_id = pmc_id;
  583. td_pmc->raw_event_id = raw_event_id;
  584. td_pmc->value = 0;
  585. }
  586. static unsigned int
  587. perfmon_td_pmc_id (const struct perfmon_td_pmc *td_pmc)
  588. {
  589. return (td_pmc->pmc_id);
  590. }
  591. static unsigned int
  592. perfmon_td_pmc_raw_event_id (const struct perfmon_td_pmc *td_pmc)
  593. {
  594. return (td_pmc->raw_event_id);
  595. }
  596. static void
  597. perfmon_td_pmc_ref (struct perfmon_td_pmc *td_pmc)
  598. {
  599. assert (perfmon_td_pmc_used (td_pmc));
  600. ++td_pmc->nr_refs;
  601. }
  602. static void
  603. perfmon_td_pmc_unref (struct perfmon_td_pmc *td_pmc)
  604. {
  605. assert (perfmon_td_pmc_used (td_pmc));
  606. --td_pmc->nr_refs;
  607. }
  608. static bool
  609. perfmon_td_pmc_loaded (const struct perfmon_td_pmc *td_pmc)
  610. {
  611. return (td_pmc->loaded);
  612. }
  613. static void
  614. perfmon_td_pmc_load (struct perfmon_td_pmc *td_pmc, uint64_t cpu_pmc_value)
  615. {
  616. assert (!perfmon_td_pmc_loaded (td_pmc));
  617. td_pmc->cpu_pmc_value = cpu_pmc_value;
  618. td_pmc->loaded = true;
  619. }
  620. static void
  621. perfmon_td_pmc_update (struct perfmon_td_pmc *td_pmc, uint64_t cpu_pmc_value)
  622. {
  623. assert (perfmon_td_pmc_loaded (td_pmc));
  624. uint64_t delta = cpu_pmc_value - td_pmc->cpu_pmc_value;
  625. td_pmc->cpu_pmc_value = cpu_pmc_value;
  626. td_pmc->value += delta;
  627. }
  628. static void
  629. perfmon_td_pmc_unload (struct perfmon_td_pmc *td_pmc, uint64_t cpu_pmc_value)
  630. {
  631. perfmon_td_pmc_update (td_pmc, cpu_pmc_value);
  632. td_pmc->loaded = false;
  633. }
  634. static uint64_t
  635. perfmon_td_pmc_read (const struct perfmon_td_pmc *td_pmc)
  636. {
  637. return (td_pmc->value);
  638. }
  639. static unsigned int
  640. perfmon_td_get_pmc_index (const struct perfmon_td *td,
  641. const struct perfmon_td_pmc *td_pmc)
  642. {
  643. size_t pmc_index = td_pmc - td->pmcs;
  644. assert (pmc_index < ARRAY_SIZE (td->pmcs));
  645. return (pmc_index);
  646. }
  647. static struct perfmon_td_pmc*
  648. perfmon_td_get_pmc (struct perfmon_td *td, unsigned int index)
  649. {
  650. assert (index < ARRAY_SIZE (td->pmcs));
  651. return (&td->pmcs[index]);
  652. }
  653. void
  654. perfmon_td_init (struct perfmon_td *td)
  655. {
  656. spinlock_init (&td->lock);
  657. for (size_t i = 0; i < ARRAY_SIZE (td->pmcs); i++)
  658. perfmon_td_pmc_init (perfmon_td_get_pmc (td, i));
  659. }
  660. static void
  661. perfmon_td_load_pmc (struct perfmon_td *td, struct perfmon_td_pmc *td_pmc)
  662. {
  663. _Auto cpu_pmu = perfmon_get_local_cpu_pmu ();
  664. unsigned int pmc_index = perfmon_td_get_pmc_index (td, td_pmc),
  665. pmc_id = perfmon_td_pmc_id (td_pmc),
  666. raw_event_id = perfmon_td_pmc_raw_event_id (td_pmc);
  667. uint64_t cpu_pmc_value = perfmon_cpu_pmu_load (cpu_pmu, pmc_index,
  668. pmc_id, raw_event_id);
  669. perfmon_td_pmc_load (td_pmc, cpu_pmc_value);
  670. }
  671. static void
  672. perfmon_td_unload_pmc (struct perfmon_td *td, struct perfmon_td_pmc *td_pmc)
  673. {
  674. _Auto cpu_pmu = perfmon_get_local_cpu_pmu ();
  675. unsigned int pmc_index = perfmon_td_get_pmc_index (td, td_pmc);
  676. uint64_t cpu_pmc_value = perfmon_cpu_pmu_unload (cpu_pmu, pmc_index);
  677. perfmon_td_pmc_unload (td_pmc, cpu_pmc_value);
  678. }
  679. static void
  680. perfmon_td_update_pmc (struct perfmon_td *td, struct perfmon_td_pmc *td_pmc)
  681. {
  682. _Auto cpu_pmu = perfmon_get_local_cpu_pmu ();
  683. unsigned int pmc_index = perfmon_td_get_pmc_index (td, td_pmc);
  684. uint64_t cpu_pmc_value = perfmon_cpu_pmu_sync (cpu_pmu, pmc_index);
  685. perfmon_td_pmc_update (td_pmc, cpu_pmc_value);
  686. }
  687. void
  688. perfmon_td_load (struct perfmon_td *td)
  689. {
  690. unsigned int pmc_index, pmc_id, raw_event_id;
  691. struct perfmon_td_pmc *td_pmc;
  692. uint64_t cpu_pmc_value;
  693. assert (!cpu_intr_enabled ());
  694. assert (!thread_preempt_enabled ());
  695. _Auto cpu_pmu = perfmon_get_local_cpu_pmu ();
  696. spinlock_lock (&td->lock);
  697. for (size_t i = 0; i < ARRAY_SIZE (td->pmcs); i++)
  698. {
  699. _Auto td_pmc = perfmon_td_get_pmc (td, i);
  700. if (!perfmon_td_pmc_used (td_pmc) || perfmon_td_pmc_loaded (td_pmc))
  701. continue;
  702. unsigned int pmc_index = perfmon_td_get_pmc_index (td, td_pmc),
  703. pmc_id = perfmon_td_pmc_id (td_pmc),
  704. raw_event_id = perfmon_td_pmc_raw_event_id (td_pmc);
  705. cpu_pmc_value = perfmon_cpu_pmu_load (cpu_pmu, pmc_index,
  706. pmc_id, raw_event_id);
  707. perfmon_td_pmc_load (td_pmc, cpu_pmc_value);
  708. }
  709. spinlock_unlock (&td->lock);
  710. }
  711. void
  712. perfmon_td_unload (struct perfmon_td *td)
  713. {
  714. assert (!cpu_intr_enabled ());
  715. assert (!thread_preempt_enabled ());
  716. _Auto cpu_pmu = perfmon_get_local_cpu_pmu ();
  717. spinlock_lock (&td->lock);
  718. for (size_t i = 0; i < ARRAY_SIZE (td->pmcs); i++)
  719. {
  720. _Auto td_pmc = perfmon_td_get_pmc (td, i);
  721. if (!perfmon_td_pmc_loaded (td_pmc))
  722. continue;
  723. unsigned int pmc_index = perfmon_td_get_pmc_index (td, td_pmc);
  724. uint64_t cpu_pmc_value = perfmon_cpu_pmu_unload (cpu_pmu, pmc_index);
  725. perfmon_td_pmc_unload (td_pmc, cpu_pmc_value);
  726. }
  727. spinlock_unlock (&td->lock);
  728. }
  729. static void
  730. perfmon_event_load (struct perfmon_event *event, uint64_t pmc_value)
  731. {
  732. event->pmc_value = pmc_value;
  733. }
  734. static void
  735. perfmon_event_update (struct perfmon_event *event, uint64_t pmc_value)
  736. {
  737. uint64_t delta = pmc_value - event->pmc_value;
  738. event->value += delta;
  739. event->pmc_value = pmc_value;
  740. }
  741. static void
  742. perfmon_event_load_cpu_remote (void *arg)
  743. {
  744. uint64_t cpu_pmc_value;
  745. struct perfmon_event *event = arg;
  746. _Auto cpu_pmu = perfmon_get_local_cpu_pmu ();
  747. _Auto pmu = perfmon_get_pmu();
  748. unsigned int pmc_index = perfmon_event_pmc_index (event);
  749. _Auto pmc = perfmon_pmu_get_pmc (pmu, pmc_index);
  750. cpu_pmc_value = perfmon_cpu_pmu_load (cpu_pmu, pmc_index,
  751. perfmon_pmc_id (pmc),
  752. perfmon_pmc_raw_event_id (pmc));
  753. perfmon_event_load (event, cpu_pmc_value);
  754. }
  755. static void
  756. perfmon_event_load_cpu (struct perfmon_event *event, unsigned int cpu)
  757. {
  758. perfmon_event_set_type_cpu (event);
  759. event->cpu = cpu;
  760. xcall_call (perfmon_event_load_cpu_remote, event, cpu);
  761. }
  762. static void
  763. perfmon_event_load_thread_remote (void *arg)
  764. {
  765. struct perfmon_event *event = arg;
  766. unsigned int pmc_index = perfmon_event_pmc_index (event);
  767. _Auto td = thread_get_perfmon_td (event->thread);
  768. _Auto td_pmc = perfmon_td_get_pmc (td, pmc_index);
  769. spinlock_lock (&td->lock);
  770. if (thread_self () != event->thread)
  771. ;
  772. else if (perfmon_td_pmc_loaded (td_pmc))
  773. perfmon_td_update_pmc (td, td_pmc);
  774. else
  775. perfmon_td_load_pmc (td, td_pmc);
  776. uint64_t td_pmc_value = perfmon_td_pmc_read (td_pmc);
  777. spinlock_unlock (&td->lock);
  778. perfmon_event_load (event, td_pmc_value);
  779. }
  780. static void
  781. perfmon_event_load_thread (struct perfmon_event *event, struct thread *thread)
  782. {
  783. _Auto pmu = perfmon_get_pmu ();
  784. thread_ref (thread);
  785. event->thread = thread;
  786. unsigned int pmc_index = perfmon_event_pmc_index (event);
  787. _Auto pmc = perfmon_pmu_get_pmc (pmu, pmc_index);
  788. _Auto td = thread_get_perfmon_td (thread);
  789. _Auto td_pmc = perfmon_td_get_pmc (td, pmc_index);
  790. cpu_flags_t flags;
  791. spinlock_lock_intr_save (&td->lock, &flags);
  792. if (perfmon_td_pmc_used (td_pmc))
  793. perfmon_td_pmc_ref (td_pmc);
  794. else
  795. perfmon_td_pmc_use (td_pmc, perfmon_pmc_id (pmc),
  796. perfmon_pmc_raw_event_id (pmc));
  797. spinlock_unlock_intr_restore (&td->lock, flags);
  798. xcall_call (perfmon_event_load_thread_remote, event, thread_cpu (thread));
  799. }
  800. static void
  801. perfmon_event_unload_cpu_remote (void *arg)
  802. {
  803. struct perfmon_event *event = arg;
  804. _Auto cpu_pmu = perfmon_get_local_cpu_pmu ();
  805. unsigned int pmc_index = perfmon_event_pmc_index (event);
  806. uint64_t cpu_pmc_value = perfmon_cpu_pmu_unload (cpu_pmu, pmc_index);
  807. perfmon_event_update (event, cpu_pmc_value);
  808. }
  809. static void
  810. perfmon_event_unload_cpu (struct perfmon_event *event)
  811. {
  812. xcall_call (perfmon_event_unload_cpu_remote, event, event->cpu);
  813. perfmon_event_clear_type_cpu (event);
  814. }
  815. static void
  816. perfmon_event_unload_thread_remote (void *arg)
  817. {
  818. struct perfmon_event *event = arg;
  819. unsigned int pmc_index = perfmon_event_pmc_index (event);
  820. _Auto td = thread_get_perfmon_td (event->thread);
  821. _Auto td_pmc = perfmon_td_get_pmc (td, pmc_index);
  822. spinlock_lock (&td->lock);
  823. if (dthread_self () == event->thread && perfmon_td_pmc_loaded (td_pmc))
  824. {
  825. if (perfmon_td_pmc_used (td_pmc))
  826. perfmon_td_update_pmc (td, td_pmc);
  827. else
  828. perfmon_td_unload_pmc (td, td_pmc);
  829. }
  830. uint64_t td_pmc_value = perfmon_td_pmc_read (td_pmc);
  831. spinlock_unlock (&td->lock);
  832. perfmon_event_update (event, td_pmc_value);
  833. }
  834. static void
  835. perfmon_event_unload_thread (struct perfmon_event *event)
  836. {
  837. unsigned int pmc_index = perfmon_event_pmc_index (event);
  838. _Auto td = thread_get_perfmon_td (event->thread);
  839. _Auto td_pmc = perfmon_td_get_pmc (td, pmc_index);
  840. cpu_flags_t flags;
  841. spinlock_lock_intr_save (&td->lock, &flags);
  842. perfmon_td_pmc_unref (td_pmc);
  843. spinlock_unlock_intr_restore (&td->lock, flags);
  844. xcall_call (perfmon_event_unload_thread_remote, event,
  845. thread_cpu (event->thread));
  846. thread_unref (event->thread);
  847. event->thread = NULL;
  848. }
  849. static void
  850. perfmon_event_sync_cpu_remote (void *arg)
  851. {
  852. struct perfmon_event *event = arg;
  853. _Auto cpu_pmu = perfmon_get_local_cpu_pmu();
  854. unsigned int pmc_index = perfmon_event_pmc_index (event);
  855. uint64_t cpu_pmc_value = perfmon_cpu_pmu_sync (cpu_pmu, pmc_index);
  856. perfmon_event_update (event, cpu_pmc_value);
  857. }
  858. static void
  859. perfmon_event_sync_cpu (struct perfmon_event *event)
  860. {
  861. xcall_call (perfmon_event_sync_cpu_remote, event, event->cpu);
  862. }
  863. static void
  864. perfmon_event_sync_thread_remote (void *arg)
  865. {
  866. struct perfmon_event *event = arg;
  867. unsigned int pmc_index = perfmon_event_pmc_index (event);
  868. _Auto td = thread_get_perfmon_td (event->thread);
  869. _Auto td_pmc = perfmon_td_get_pmc (td, pmc_index);
  870. spinlock_lock (&td->lock);
  871. if (thread_self () == event->thread)
  872. perfmon_td_update_pmc (td, td_pmc);
  873. uint64_t td_pmc_value = perfmon_td_pmc_read (td_pmc);
  874. spinlock_unlock (&td->lock);
  875. perfmon_event_update (event, td_pmc_value);
  876. }
  877. static void
  878. perfmon_event_sync_thread (struct perfmon_event *event)
  879. {
  880. xcall_call (perfmon_event_sync_thread_remote, event,
  881. thread_cpu (event->thread));
  882. }
  883. static int
  884. perfmon_event_attach_pmu (struct perfmon_event *event)
  885. {
  886. unsigned int raw_event_id = 0;
  887. _Auto pmu = perfmon_get_pmu ();
  888. if (! (event->flags & PERFMON_EF_RAW))
  889. {
  890. int error = perfmon_pmu_translate (pmu, &raw_event_id, event->id);
  891. if (error)
  892. return (error);
  893. }
  894. struct perfmon_pmc *pmc;
  895. int error = perfmon_pmu_take_pmc (pmu, &pmc, raw_event_id);
  896. if (error)
  897. return (error);
  898. event->pmc_index = perfmon_pmu_get_pmc_index (pmu, pmc);
  899. event->flags |= PERFMON_EF_ATTACHED;
  900. event->value = 0;
  901. return (0);
  902. }
  903. static void
  904. perfmon_event_detach_pmu (struct perfmon_event *event)
  905. {
  906. _Auto pmu = perfmon_get_pmu();
  907. _Auto pmc = perfmon_pmu_get_pmc (pmu, perfmon_event_pmc_index (event));
  908. perfmon_pmu_put_pmc (pmu, pmc);
  909. event->flags &= ~PERFMON_EF_ATTACHED;
  910. }
  911. int
  912. perfmon_event_attach (struct perfmon_event *event, struct thread *thread)
  913. {
  914. int error;
  915. spinlock_lock (&event->lock);
  916. if (perfmon_event_attached (event))
  917. {
  918. error = EINVAL;
  919. goto error;
  920. }
  921. error = perfmon_event_attach_pmu (event);
  922. if (! error)
  923. perfmon_event_load_thread (event, thread);
  924. error:
  925. spinlock_unlock (&event->lock);
  926. return (error);
  927. }
  928. int
  929. perfmon_event_attach_cpu (struct perfmon_event *event, unsigned int cpu)
  930. {
  931. int error;
  932. if (cpu >= cpu_count ())
  933. return (EINVAL);
  934. spinlock_lock (&event->lock);
  935. if (perfmon_event_attached (event))
  936. {
  937. error = EINVAL;
  938. goto out;
  939. }
  940. error = perfmon_event_attach_pmu (event);
  941. if (! error)
  942. perfmon_event_load_cpu (event, cpu);
  943. out:
  944. spinlock_unlock (&event->lock);
  945. return (error);
  946. }
  947. int
  948. perfmon_event_detach (struct perfmon_event *event)
  949. {
  950. int error;
  951. spinlock_lock (&event->lock);
  952. if (!perfmon_event_attached (event))
  953. {
  954. error = EINVAL;
  955. goto out;
  956. }
  957. if (perfmon_event_type_cpu (event))
  958. perfmon_event_unload_cpu (event);
  959. else
  960. perfmon_event_unload_thread (event);
  961. perfmon_event_detach_pmu (event);
  962. error = 0;
  963. out:
  964. spinlock_unlock (&event->lock);
  965. return (error);
  966. }
  967. uint64_t
  968. perfmon_event_read (struct perfmon_event *event)
  969. {
  970. spinlock_lock (&event->lock);
  971. if (perfmon_event_attached (event))
  972. {
  973. if (perfmon_event_type_cpu (event))
  974. perfmon_event_sync_cpu (event);
  975. else
  976. perfmon_event_sync_thread (event);
  977. }
  978. uint64_t value = event->value;
  979. spinlock_unlock (&event->lock);
  980. return (value);
  981. }
  982. static uint64_t __init
  983. perfmon_compute_poll_interval (uint64_t pmc_width)
  984. {
  985. uint64_t cycles;
  986. if (pmc_width == 64)
  987. cycles = (uint64_t)-1;
  988. else
  989. cycles = (uint64_t)1 << pmc_width;
  990. /*
  991. * Assume an unrealistically high upper bound on the number of
  992. * events per cycle to otbain a comfortable margin of safety.
  993. */
  994. cycles /= 100;
  995. uint64_t time = cycles / (cpu_get_freq () / 1000);
  996. if (time < PERFMON_MIN_POLL_INTERVAL)
  997. {
  998. log_warning ("perfmon: invalid poll interval %llu, forced to %llu",
  999. time, PERFMON_MIN_POLL_INTERVAL);
  1000. time = PERFMON_MIN_POLL_INTERVAL;
  1001. }
  1002. return (clock_ticks_from_ms (time));
  1003. }
  1004. void __init
  1005. perfmon_register (struct perfmon_dev *dev)
  1006. {
  1007. const struct perfmon_dev_ops *ops = dev->ops;
  1008. assert (ops->translate && ops->alloc && ops->free
  1009. && ops->start && ops->stop && ops->read);
  1010. assert (dev->pmc_width <= 64);
  1011. if (!dev->ops->handle_overflow_intr && !dev->poll_interval)
  1012. dev->poll_interval = perfmon_compute_poll_interval (dev->pmc_width);
  1013. perfmon_pmu_set_dev (perfmon_get_pmu (), dev);
  1014. }
  1015. void
  1016. perfmon_overflow_intr (void)
  1017. {
  1018. perfmon_pmu_handle_overflow_intr (perfmon_get_pmu ());
  1019. }
  1020. void
  1021. perfmon_report_overflow (unsigned int pmc_index)
  1022. {
  1023. assert (!cpu_intr_enabled ());
  1024. assert (!thread_preempt_enabled ());
  1025. _Auto cpu_pmu = perfmon_get_local_cpu_pmu();
  1026. _Auto cpu_pmc = perfmon_cpu_pmu_get_pmc (cpu_pmu, pmc_index);
  1027. perfmon_cpu_pmu_update_pmc (cpu_pmu, cpu_pmc);
  1028. }
  1029. static int __init
  1030. perfmon_bootstrap (void)
  1031. {
  1032. perfmon_pmu_init (perfmon_get_pmu ());
  1033. return (0);
  1034. }
  1035. INIT_OP_DEFINE (perfmon_bootstrap,
  1036. INIT_OP_DEP (log_setup, true),
  1037. INIT_OP_DEP (spinlock_setup, true));
  1038. static int __init
  1039. perfmon_setup (void)
  1040. {
  1041. struct perfmon_dev *dev = perfmon_pmu_get_dev (perfmon_get_pmu ());
  1042. if (!dev)
  1043. return (ENODEV);
  1044. for (uint32_t cpu = 0; cpu < cpu_count (); ++cpu)
  1045. perfmon_cpu_pmu_init (perfmon_get_cpu_pmu (cpu), cpu, dev);
  1046. return (0);
  1047. }
  1048. INIT_OP_DEFINE (perfmon_setup,
  1049. INIT_OP_DEP (boot_setup_pmu, true),
  1050. INIT_OP_DEP (cpu_mp_probe, true),
  1051. INIT_OP_DEP (cpu_setup, true),
  1052. INIT_OP_DEP (percpu_setup, true),
  1053. INIT_OP_DEP (perfmon_bootstrap, true),
  1054. INIT_OP_DEP (spinlock_setup, true),
  1055. INIT_OP_DEP (syscnt_setup, true));