perf_event_intel_cqm.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. /*
  2. * Intel Cache Quality-of-Service Monitoring (CQM) support.
  3. *
  4. * Based very, very heavily on work by Peter Zijlstra.
  5. */
  6. #include <linux/perf_event.h>
  7. #include <linux/slab.h>
  8. #include <asm/cpu_device_id.h>
  9. #include "perf_event.h"
  10. #define MSR_IA32_PQR_ASSOC 0x0c8f
  11. #define MSR_IA32_QM_CTR 0x0c8e
  12. #define MSR_IA32_QM_EVTSEL 0x0c8d
  13. static u32 cqm_max_rmid = -1;
  14. static unsigned int cqm_l3_scale; /* supposedly cacheline size */
  15. /**
  16. * struct intel_pqr_state - State cache for the PQR MSR
  17. * @rmid: The cached Resource Monitoring ID
  18. * @closid: The cached Class Of Service ID
  19. * @rmid_usecnt: The usage counter for rmid
  20. *
  21. * The upper 32 bits of MSR_IA32_PQR_ASSOC contain closid and the
  22. * lower 10 bits rmid. The update to MSR_IA32_PQR_ASSOC always
  23. * contains both parts, so we need to cache them.
  24. *
  25. * The cache also helps to avoid pointless updates if the value does
  26. * not change.
  27. */
  28. struct intel_pqr_state {
  29. u32 rmid;
  30. u32 closid;
  31. int rmid_usecnt;
  32. };
  33. /*
  34. * The cached intel_pqr_state is strictly per CPU and can never be
  35. * updated from a remote CPU. Both functions which modify the state
  36. * (intel_cqm_event_start and intel_cqm_event_stop) are called with
  37. * interrupts disabled, which is sufficient for the protection.
  38. */
  39. static DEFINE_PER_CPU(struct intel_pqr_state, pqr_state);
  40. /*
  41. * Protects cache_cgroups and cqm_rmid_free_lru and cqm_rmid_limbo_lru.
  42. * Also protects event->hw.cqm_rmid
  43. *
  44. * Hold either for stability, both for modification of ->hw.cqm_rmid.
  45. */
  46. static DEFINE_MUTEX(cache_mutex);
  47. static DEFINE_RAW_SPINLOCK(cache_lock);
  48. /*
  49. * Groups of events that have the same target(s), one RMID per group.
  50. */
  51. static LIST_HEAD(cache_groups);
  52. /*
  53. * Mask of CPUs for reading CQM values. We only need one per-socket.
  54. */
  55. static cpumask_t cqm_cpumask;
  56. #define RMID_VAL_ERROR (1ULL << 63)
  57. #define RMID_VAL_UNAVAIL (1ULL << 62)
  58. #define QOS_L3_OCCUP_EVENT_ID (1 << 0)
  59. #define QOS_EVENT_MASK QOS_L3_OCCUP_EVENT_ID
  60. /*
  61. * This is central to the rotation algorithm in __intel_cqm_rmid_rotate().
  62. *
  63. * This rmid is always free and is guaranteed to have an associated
  64. * near-zero occupancy value, i.e. no cachelines are tagged with this
  65. * RMID, once __intel_cqm_rmid_rotate() returns.
  66. */
  67. static u32 intel_cqm_rotation_rmid;
  68. #define INVALID_RMID (-1)
  69. /*
  70. * Is @rmid valid for programming the hardware?
  71. *
  72. * rmid 0 is reserved by the hardware for all non-monitored tasks, which
  73. * means that we should never come across an rmid with that value.
  74. * Likewise, an rmid value of -1 is used to indicate "no rmid currently
  75. * assigned" and is used as part of the rotation code.
  76. */
  77. static inline bool __rmid_valid(u32 rmid)
  78. {
  79. if (!rmid || rmid == INVALID_RMID)
  80. return false;
  81. return true;
  82. }
  83. static u64 __rmid_read(u32 rmid)
  84. {
  85. u64 val;
  86. /*
  87. * Ignore the SDM, this thing is _NOTHING_ like a regular perfcnt,
  88. * it just says that to increase confusion.
  89. */
  90. wrmsr(MSR_IA32_QM_EVTSEL, QOS_L3_OCCUP_EVENT_ID, rmid);
  91. rdmsrl(MSR_IA32_QM_CTR, val);
  92. /*
  93. * Aside from the ERROR and UNAVAIL bits, assume this thing returns
  94. * the number of cachelines tagged with @rmid.
  95. */
  96. return val;
  97. }
  98. enum rmid_recycle_state {
  99. RMID_YOUNG = 0,
  100. RMID_AVAILABLE,
  101. RMID_DIRTY,
  102. };
  103. struct cqm_rmid_entry {
  104. u32 rmid;
  105. enum rmid_recycle_state state;
  106. struct list_head list;
  107. unsigned long queue_time;
  108. };
  109. /*
  110. * cqm_rmid_free_lru - A least recently used list of RMIDs.
  111. *
  112. * Oldest entry at the head, newest (most recently used) entry at the
  113. * tail. This list is never traversed, it's only used to keep track of
  114. * the lru order. That is, we only pick entries of the head or insert
  115. * them on the tail.
  116. *
  117. * All entries on the list are 'free', and their RMIDs are not currently
  118. * in use. To mark an RMID as in use, remove its entry from the lru
  119. * list.
  120. *
  121. *
  122. * cqm_rmid_limbo_lru - list of currently unused but (potentially) dirty RMIDs.
  123. *
  124. * This list is contains RMIDs that no one is currently using but that
  125. * may have a non-zero occupancy value associated with them. The
  126. * rotation worker moves RMIDs from the limbo list to the free list once
  127. * the occupancy value drops below __intel_cqm_threshold.
  128. *
  129. * Both lists are protected by cache_mutex.
  130. */
  131. static LIST_HEAD(cqm_rmid_free_lru);
  132. static LIST_HEAD(cqm_rmid_limbo_lru);
  133. /*
  134. * We use a simple array of pointers so that we can lookup a struct
  135. * cqm_rmid_entry in O(1). This alleviates the callers of __get_rmid()
  136. * and __put_rmid() from having to worry about dealing with struct
  137. * cqm_rmid_entry - they just deal with rmids, i.e. integers.
  138. *
  139. * Once this array is initialized it is read-only. No locks are required
  140. * to access it.
  141. *
  142. * All entries for all RMIDs can be looked up in the this array at all
  143. * times.
  144. */
  145. static struct cqm_rmid_entry **cqm_rmid_ptrs;
  146. static inline struct cqm_rmid_entry *__rmid_entry(u32 rmid)
  147. {
  148. struct cqm_rmid_entry *entry;
  149. entry = cqm_rmid_ptrs[rmid];
  150. WARN_ON(entry->rmid != rmid);
  151. return entry;
  152. }
  153. /*
  154. * Returns < 0 on fail.
  155. *
  156. * We expect to be called with cache_mutex held.
  157. */
  158. static u32 __get_rmid(void)
  159. {
  160. struct cqm_rmid_entry *entry;
  161. lockdep_assert_held(&cache_mutex);
  162. if (list_empty(&cqm_rmid_free_lru))
  163. return INVALID_RMID;
  164. entry = list_first_entry(&cqm_rmid_free_lru, struct cqm_rmid_entry, list);
  165. list_del(&entry->list);
  166. return entry->rmid;
  167. }
  168. static void __put_rmid(u32 rmid)
  169. {
  170. struct cqm_rmid_entry *entry;
  171. lockdep_assert_held(&cache_mutex);
  172. WARN_ON(!__rmid_valid(rmid));
  173. entry = __rmid_entry(rmid);
  174. entry->queue_time = jiffies;
  175. entry->state = RMID_YOUNG;
  176. list_add_tail(&entry->list, &cqm_rmid_limbo_lru);
  177. }
  178. static int intel_cqm_setup_rmid_cache(void)
  179. {
  180. struct cqm_rmid_entry *entry;
  181. unsigned int nr_rmids;
  182. int r = 0;
  183. nr_rmids = cqm_max_rmid + 1;
  184. cqm_rmid_ptrs = kmalloc(sizeof(struct cqm_rmid_entry *) *
  185. nr_rmids, GFP_KERNEL);
  186. if (!cqm_rmid_ptrs)
  187. return -ENOMEM;
  188. for (; r <= cqm_max_rmid; r++) {
  189. struct cqm_rmid_entry *entry;
  190. entry = kmalloc(sizeof(*entry), GFP_KERNEL);
  191. if (!entry)
  192. goto fail;
  193. INIT_LIST_HEAD(&entry->list);
  194. entry->rmid = r;
  195. cqm_rmid_ptrs[r] = entry;
  196. list_add_tail(&entry->list, &cqm_rmid_free_lru);
  197. }
  198. /*
  199. * RMID 0 is special and is always allocated. It's used for all
  200. * tasks that are not monitored.
  201. */
  202. entry = __rmid_entry(0);
  203. list_del(&entry->list);
  204. mutex_lock(&cache_mutex);
  205. intel_cqm_rotation_rmid = __get_rmid();
  206. mutex_unlock(&cache_mutex);
  207. return 0;
  208. fail:
  209. while (r--)
  210. kfree(cqm_rmid_ptrs[r]);
  211. kfree(cqm_rmid_ptrs);
  212. return -ENOMEM;
  213. }
  214. /*
  215. * Determine if @a and @b measure the same set of tasks.
  216. *
  217. * If @a and @b measure the same set of tasks then we want to share a
  218. * single RMID.
  219. */
  220. static bool __match_event(struct perf_event *a, struct perf_event *b)
  221. {
  222. /* Per-cpu and task events don't mix */
  223. if ((a->attach_state & PERF_ATTACH_TASK) !=
  224. (b->attach_state & PERF_ATTACH_TASK))
  225. return false;
  226. #ifdef CONFIG_CGROUP_PERF
  227. if (a->cgrp != b->cgrp)
  228. return false;
  229. #endif
  230. /* If not task event, we're machine wide */
  231. if (!(b->attach_state & PERF_ATTACH_TASK))
  232. return true;
  233. /*
  234. * Events that target same task are placed into the same cache group.
  235. */
  236. if (a->hw.target == b->hw.target)
  237. return true;
  238. /*
  239. * Are we an inherited event?
  240. */
  241. if (b->parent == a)
  242. return true;
  243. return false;
  244. }
  245. #ifdef CONFIG_CGROUP_PERF
  246. static inline struct perf_cgroup *event_to_cgroup(struct perf_event *event)
  247. {
  248. if (event->attach_state & PERF_ATTACH_TASK)
  249. return perf_cgroup_from_task(event->hw.target);
  250. return event->cgrp;
  251. }
  252. #endif
  253. /*
  254. * Determine if @a's tasks intersect with @b's tasks
  255. *
  256. * There are combinations of events that we explicitly prohibit,
  257. *
  258. * PROHIBITS
  259. * system-wide -> cgroup and task
  260. * cgroup -> system-wide
  261. * -> task in cgroup
  262. * task -> system-wide
  263. * -> task in cgroup
  264. *
  265. * Call this function before allocating an RMID.
  266. */
  267. static bool __conflict_event(struct perf_event *a, struct perf_event *b)
  268. {
  269. #ifdef CONFIG_CGROUP_PERF
  270. /*
  271. * We can have any number of cgroups but only one system-wide
  272. * event at a time.
  273. */
  274. if (a->cgrp && b->cgrp) {
  275. struct perf_cgroup *ac = a->cgrp;
  276. struct perf_cgroup *bc = b->cgrp;
  277. /*
  278. * This condition should have been caught in
  279. * __match_event() and we should be sharing an RMID.
  280. */
  281. WARN_ON_ONCE(ac == bc);
  282. if (cgroup_is_descendant(ac->css.cgroup, bc->css.cgroup) ||
  283. cgroup_is_descendant(bc->css.cgroup, ac->css.cgroup))
  284. return true;
  285. return false;
  286. }
  287. if (a->cgrp || b->cgrp) {
  288. struct perf_cgroup *ac, *bc;
  289. /*
  290. * cgroup and system-wide events are mutually exclusive
  291. */
  292. if ((a->cgrp && !(b->attach_state & PERF_ATTACH_TASK)) ||
  293. (b->cgrp && !(a->attach_state & PERF_ATTACH_TASK)))
  294. return true;
  295. /*
  296. * Ensure neither event is part of the other's cgroup
  297. */
  298. ac = event_to_cgroup(a);
  299. bc = event_to_cgroup(b);
  300. if (ac == bc)
  301. return true;
  302. /*
  303. * Must have cgroup and non-intersecting task events.
  304. */
  305. if (!ac || !bc)
  306. return false;
  307. /*
  308. * We have cgroup and task events, and the task belongs
  309. * to a cgroup. Check for for overlap.
  310. */
  311. if (cgroup_is_descendant(ac->css.cgroup, bc->css.cgroup) ||
  312. cgroup_is_descendant(bc->css.cgroup, ac->css.cgroup))
  313. return true;
  314. return false;
  315. }
  316. #endif
  317. /*
  318. * If one of them is not a task, same story as above with cgroups.
  319. */
  320. if (!(a->attach_state & PERF_ATTACH_TASK) ||
  321. !(b->attach_state & PERF_ATTACH_TASK))
  322. return true;
  323. /*
  324. * Must be non-overlapping.
  325. */
  326. return false;
  327. }
  328. struct rmid_read {
  329. u32 rmid;
  330. atomic64_t value;
  331. };
  332. static void __intel_cqm_event_count(void *info);
  333. /*
  334. * Exchange the RMID of a group of events.
  335. */
  336. static u32 intel_cqm_xchg_rmid(struct perf_event *group, u32 rmid)
  337. {
  338. struct perf_event *event;
  339. struct list_head *head = &group->hw.cqm_group_entry;
  340. u32 old_rmid = group->hw.cqm_rmid;
  341. lockdep_assert_held(&cache_mutex);
  342. /*
  343. * If our RMID is being deallocated, perform a read now.
  344. */
  345. if (__rmid_valid(old_rmid) && !__rmid_valid(rmid)) {
  346. struct rmid_read rr = {
  347. .value = ATOMIC64_INIT(0),
  348. .rmid = old_rmid,
  349. };
  350. on_each_cpu_mask(&cqm_cpumask, __intel_cqm_event_count,
  351. &rr, 1);
  352. local64_set(&group->count, atomic64_read(&rr.value));
  353. }
  354. raw_spin_lock_irq(&cache_lock);
  355. group->hw.cqm_rmid = rmid;
  356. list_for_each_entry(event, head, hw.cqm_group_entry)
  357. event->hw.cqm_rmid = rmid;
  358. raw_spin_unlock_irq(&cache_lock);
  359. return old_rmid;
  360. }
  361. /*
  362. * If we fail to assign a new RMID for intel_cqm_rotation_rmid because
  363. * cachelines are still tagged with RMIDs in limbo, we progressively
  364. * increment the threshold until we find an RMID in limbo with <=
  365. * __intel_cqm_threshold lines tagged. This is designed to mitigate the
  366. * problem where cachelines tagged with an RMID are not steadily being
  367. * evicted.
  368. *
  369. * On successful rotations we decrease the threshold back towards zero.
  370. *
  371. * __intel_cqm_max_threshold provides an upper bound on the threshold,
  372. * and is measured in bytes because it's exposed to userland.
  373. */
  374. static unsigned int __intel_cqm_threshold;
  375. static unsigned int __intel_cqm_max_threshold;
  376. /*
  377. * Test whether an RMID has a zero occupancy value on this cpu.
  378. */
  379. static void intel_cqm_stable(void *arg)
  380. {
  381. struct cqm_rmid_entry *entry;
  382. list_for_each_entry(entry, &cqm_rmid_limbo_lru, list) {
  383. if (entry->state != RMID_AVAILABLE)
  384. break;
  385. if (__rmid_read(entry->rmid) > __intel_cqm_threshold)
  386. entry->state = RMID_DIRTY;
  387. }
  388. }
  389. /*
  390. * If we have group events waiting for an RMID that don't conflict with
  391. * events already running, assign @rmid.
  392. */
  393. static bool intel_cqm_sched_in_event(u32 rmid)
  394. {
  395. struct perf_event *leader, *event;
  396. lockdep_assert_held(&cache_mutex);
  397. leader = list_first_entry(&cache_groups, struct perf_event,
  398. hw.cqm_groups_entry);
  399. event = leader;
  400. list_for_each_entry_continue(event, &cache_groups,
  401. hw.cqm_groups_entry) {
  402. if (__rmid_valid(event->hw.cqm_rmid))
  403. continue;
  404. if (__conflict_event(event, leader))
  405. continue;
  406. intel_cqm_xchg_rmid(event, rmid);
  407. return true;
  408. }
  409. return false;
  410. }
  411. /*
  412. * Initially use this constant for both the limbo queue time and the
  413. * rotation timer interval, pmu::hrtimer_interval_ms.
  414. *
  415. * They don't need to be the same, but the two are related since if you
  416. * rotate faster than you recycle RMIDs, you may run out of available
  417. * RMIDs.
  418. */
  419. #define RMID_DEFAULT_QUEUE_TIME 250 /* ms */
  420. static unsigned int __rmid_queue_time_ms = RMID_DEFAULT_QUEUE_TIME;
  421. /*
  422. * intel_cqm_rmid_stabilize - move RMIDs from limbo to free list
  423. * @nr_available: number of freeable RMIDs on the limbo list
  424. *
  425. * Quiescent state; wait for all 'freed' RMIDs to become unused, i.e. no
  426. * cachelines are tagged with those RMIDs. After this we can reuse them
  427. * and know that the current set of active RMIDs is stable.
  428. *
  429. * Return %true or %false depending on whether stabilization needs to be
  430. * reattempted.
  431. *
  432. * If we return %true then @nr_available is updated to indicate the
  433. * number of RMIDs on the limbo list that have been queued for the
  434. * minimum queue time (RMID_AVAILABLE), but whose data occupancy values
  435. * are above __intel_cqm_threshold.
  436. */
  437. static bool intel_cqm_rmid_stabilize(unsigned int *available)
  438. {
  439. struct cqm_rmid_entry *entry, *tmp;
  440. lockdep_assert_held(&cache_mutex);
  441. *available = 0;
  442. list_for_each_entry(entry, &cqm_rmid_limbo_lru, list) {
  443. unsigned long min_queue_time;
  444. unsigned long now = jiffies;
  445. /*
  446. * We hold RMIDs placed into limbo for a minimum queue
  447. * time. Before the minimum queue time has elapsed we do
  448. * not recycle RMIDs.
  449. *
  450. * The reasoning is that until a sufficient time has
  451. * passed since we stopped using an RMID, any RMID
  452. * placed onto the limbo list will likely still have
  453. * data tagged in the cache, which means we'll probably
  454. * fail to recycle it anyway.
  455. *
  456. * We can save ourselves an expensive IPI by skipping
  457. * any RMIDs that have not been queued for the minimum
  458. * time.
  459. */
  460. min_queue_time = entry->queue_time +
  461. msecs_to_jiffies(__rmid_queue_time_ms);
  462. if (time_after(min_queue_time, now))
  463. break;
  464. entry->state = RMID_AVAILABLE;
  465. (*available)++;
  466. }
  467. /*
  468. * Fast return if none of the RMIDs on the limbo list have been
  469. * sitting on the queue for the minimum queue time.
  470. */
  471. if (!*available)
  472. return false;
  473. /*
  474. * Test whether an RMID is free for each package.
  475. */
  476. on_each_cpu_mask(&cqm_cpumask, intel_cqm_stable, NULL, true);
  477. list_for_each_entry_safe(entry, tmp, &cqm_rmid_limbo_lru, list) {
  478. /*
  479. * Exhausted all RMIDs that have waited min queue time.
  480. */
  481. if (entry->state == RMID_YOUNG)
  482. break;
  483. if (entry->state == RMID_DIRTY)
  484. continue;
  485. list_del(&entry->list); /* remove from limbo */
  486. /*
  487. * The rotation RMID gets priority if it's
  488. * currently invalid. In which case, skip adding
  489. * the RMID to the the free lru.
  490. */
  491. if (!__rmid_valid(intel_cqm_rotation_rmid)) {
  492. intel_cqm_rotation_rmid = entry->rmid;
  493. continue;
  494. }
  495. /*
  496. * If we have groups waiting for RMIDs, hand
  497. * them one now provided they don't conflict.
  498. */
  499. if (intel_cqm_sched_in_event(entry->rmid))
  500. continue;
  501. /*
  502. * Otherwise place it onto the free list.
  503. */
  504. list_add_tail(&entry->list, &cqm_rmid_free_lru);
  505. }
  506. return __rmid_valid(intel_cqm_rotation_rmid);
  507. }
  508. /*
  509. * Pick a victim group and move it to the tail of the group list.
  510. * @next: The first group without an RMID
  511. */
  512. static void __intel_cqm_pick_and_rotate(struct perf_event *next)
  513. {
  514. struct perf_event *rotor;
  515. u32 rmid;
  516. lockdep_assert_held(&cache_mutex);
  517. rotor = list_first_entry(&cache_groups, struct perf_event,
  518. hw.cqm_groups_entry);
  519. /*
  520. * The group at the front of the list should always have a valid
  521. * RMID. If it doesn't then no groups have RMIDs assigned and we
  522. * don't need to rotate the list.
  523. */
  524. if (next == rotor)
  525. return;
  526. rmid = intel_cqm_xchg_rmid(rotor, INVALID_RMID);
  527. __put_rmid(rmid);
  528. list_rotate_left(&cache_groups);
  529. }
  530. /*
  531. * Deallocate the RMIDs from any events that conflict with @event, and
  532. * place them on the back of the group list.
  533. */
  534. static void intel_cqm_sched_out_conflicting_events(struct perf_event *event)
  535. {
  536. struct perf_event *group, *g;
  537. u32 rmid;
  538. lockdep_assert_held(&cache_mutex);
  539. list_for_each_entry_safe(group, g, &cache_groups, hw.cqm_groups_entry) {
  540. if (group == event)
  541. continue;
  542. rmid = group->hw.cqm_rmid;
  543. /*
  544. * Skip events that don't have a valid RMID.
  545. */
  546. if (!__rmid_valid(rmid))
  547. continue;
  548. /*
  549. * No conflict? No problem! Leave the event alone.
  550. */
  551. if (!__conflict_event(group, event))
  552. continue;
  553. intel_cqm_xchg_rmid(group, INVALID_RMID);
  554. __put_rmid(rmid);
  555. }
  556. }
  557. /*
  558. * Attempt to rotate the groups and assign new RMIDs.
  559. *
  560. * We rotate for two reasons,
  561. * 1. To handle the scheduling of conflicting events
  562. * 2. To recycle RMIDs
  563. *
  564. * Rotating RMIDs is complicated because the hardware doesn't give us
  565. * any clues.
  566. *
  567. * There's problems with the hardware interface; when you change the
  568. * task:RMID map cachelines retain their 'old' tags, giving a skewed
  569. * picture. In order to work around this, we must always keep one free
  570. * RMID - intel_cqm_rotation_rmid.
  571. *
  572. * Rotation works by taking away an RMID from a group (the old RMID),
  573. * and assigning the free RMID to another group (the new RMID). We must
  574. * then wait for the old RMID to not be used (no cachelines tagged).
  575. * This ensure that all cachelines are tagged with 'active' RMIDs. At
  576. * this point we can start reading values for the new RMID and treat the
  577. * old RMID as the free RMID for the next rotation.
  578. *
  579. * Return %true or %false depending on whether we did any rotating.
  580. */
  581. static bool __intel_cqm_rmid_rotate(void)
  582. {
  583. struct perf_event *group, *start = NULL;
  584. unsigned int threshold_limit;
  585. unsigned int nr_needed = 0;
  586. unsigned int nr_available;
  587. bool rotated = false;
  588. mutex_lock(&cache_mutex);
  589. again:
  590. /*
  591. * Fast path through this function if there are no groups and no
  592. * RMIDs that need cleaning.
  593. */
  594. if (list_empty(&cache_groups) && list_empty(&cqm_rmid_limbo_lru))
  595. goto out;
  596. list_for_each_entry(group, &cache_groups, hw.cqm_groups_entry) {
  597. if (!__rmid_valid(group->hw.cqm_rmid)) {
  598. if (!start)
  599. start = group;
  600. nr_needed++;
  601. }
  602. }
  603. /*
  604. * We have some event groups, but they all have RMIDs assigned
  605. * and no RMIDs need cleaning.
  606. */
  607. if (!nr_needed && list_empty(&cqm_rmid_limbo_lru))
  608. goto out;
  609. if (!nr_needed)
  610. goto stabilize;
  611. /*
  612. * We have more event groups without RMIDs than available RMIDs,
  613. * or we have event groups that conflict with the ones currently
  614. * scheduled.
  615. *
  616. * We force deallocate the rmid of the group at the head of
  617. * cache_groups. The first event group without an RMID then gets
  618. * assigned intel_cqm_rotation_rmid. This ensures we always make
  619. * forward progress.
  620. *
  621. * Rotate the cache_groups list so the previous head is now the
  622. * tail.
  623. */
  624. __intel_cqm_pick_and_rotate(start);
  625. /*
  626. * If the rotation is going to succeed, reduce the threshold so
  627. * that we don't needlessly reuse dirty RMIDs.
  628. */
  629. if (__rmid_valid(intel_cqm_rotation_rmid)) {
  630. intel_cqm_xchg_rmid(start, intel_cqm_rotation_rmid);
  631. intel_cqm_rotation_rmid = __get_rmid();
  632. intel_cqm_sched_out_conflicting_events(start);
  633. if (__intel_cqm_threshold)
  634. __intel_cqm_threshold--;
  635. }
  636. rotated = true;
  637. stabilize:
  638. /*
  639. * We now need to stablize the RMID we freed above (if any) to
  640. * ensure that the next time we rotate we have an RMID with zero
  641. * occupancy value.
  642. *
  643. * Alternatively, if we didn't need to perform any rotation,
  644. * we'll have a bunch of RMIDs in limbo that need stabilizing.
  645. */
  646. threshold_limit = __intel_cqm_max_threshold / cqm_l3_scale;
  647. while (intel_cqm_rmid_stabilize(&nr_available) &&
  648. __intel_cqm_threshold < threshold_limit) {
  649. unsigned int steal_limit;
  650. /*
  651. * Don't spin if nobody is actively waiting for an RMID,
  652. * the rotation worker will be kicked as soon as an
  653. * event needs an RMID anyway.
  654. */
  655. if (!nr_needed)
  656. break;
  657. /* Allow max 25% of RMIDs to be in limbo. */
  658. steal_limit = (cqm_max_rmid + 1) / 4;
  659. /*
  660. * We failed to stabilize any RMIDs so our rotation
  661. * logic is now stuck. In order to make forward progress
  662. * we have a few options:
  663. *
  664. * 1. rotate ("steal") another RMID
  665. * 2. increase the threshold
  666. * 3. do nothing
  667. *
  668. * We do both of 1. and 2. until we hit the steal limit.
  669. *
  670. * The steal limit prevents all RMIDs ending up on the
  671. * limbo list. This can happen if every RMID has a
  672. * non-zero occupancy above threshold_limit, and the
  673. * occupancy values aren't dropping fast enough.
  674. *
  675. * Note that there is prioritisation at work here - we'd
  676. * rather increase the number of RMIDs on the limbo list
  677. * than increase the threshold, because increasing the
  678. * threshold skews the event data (because we reuse
  679. * dirty RMIDs) - threshold bumps are a last resort.
  680. */
  681. if (nr_available < steal_limit)
  682. goto again;
  683. __intel_cqm_threshold++;
  684. }
  685. out:
  686. mutex_unlock(&cache_mutex);
  687. return rotated;
  688. }
  689. static void intel_cqm_rmid_rotate(struct work_struct *work);
  690. static DECLARE_DELAYED_WORK(intel_cqm_rmid_work, intel_cqm_rmid_rotate);
  691. static struct pmu intel_cqm_pmu;
  692. static void intel_cqm_rmid_rotate(struct work_struct *work)
  693. {
  694. unsigned long delay;
  695. __intel_cqm_rmid_rotate();
  696. delay = msecs_to_jiffies(intel_cqm_pmu.hrtimer_interval_ms);
  697. schedule_delayed_work(&intel_cqm_rmid_work, delay);
  698. }
  699. /*
  700. * Find a group and setup RMID.
  701. *
  702. * If we're part of a group, we use the group's RMID.
  703. */
  704. static void intel_cqm_setup_event(struct perf_event *event,
  705. struct perf_event **group)
  706. {
  707. struct perf_event *iter;
  708. bool conflict = false;
  709. u32 rmid;
  710. list_for_each_entry(iter, &cache_groups, hw.cqm_groups_entry) {
  711. rmid = iter->hw.cqm_rmid;
  712. if (__match_event(iter, event)) {
  713. /* All tasks in a group share an RMID */
  714. event->hw.cqm_rmid = rmid;
  715. *group = iter;
  716. return;
  717. }
  718. /*
  719. * We only care about conflicts for events that are
  720. * actually scheduled in (and hence have a valid RMID).
  721. */
  722. if (__conflict_event(iter, event) && __rmid_valid(rmid))
  723. conflict = true;
  724. }
  725. if (conflict)
  726. rmid = INVALID_RMID;
  727. else
  728. rmid = __get_rmid();
  729. event->hw.cqm_rmid = rmid;
  730. }
  731. static void intel_cqm_event_read(struct perf_event *event)
  732. {
  733. unsigned long flags;
  734. u32 rmid;
  735. u64 val;
  736. /*
  737. * Task events are handled by intel_cqm_event_count().
  738. */
  739. if (event->cpu == -1)
  740. return;
  741. raw_spin_lock_irqsave(&cache_lock, flags);
  742. rmid = event->hw.cqm_rmid;
  743. if (!__rmid_valid(rmid))
  744. goto out;
  745. val = __rmid_read(rmid);
  746. /*
  747. * Ignore this reading on error states and do not update the value.
  748. */
  749. if (val & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL))
  750. goto out;
  751. local64_set(&event->count, val);
  752. out:
  753. raw_spin_unlock_irqrestore(&cache_lock, flags);
  754. }
  755. static void __intel_cqm_event_count(void *info)
  756. {
  757. struct rmid_read *rr = info;
  758. u64 val;
  759. val = __rmid_read(rr->rmid);
  760. if (val & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL))
  761. return;
  762. atomic64_add(val, &rr->value);
  763. }
  764. static inline bool cqm_group_leader(struct perf_event *event)
  765. {
  766. return !list_empty(&event->hw.cqm_groups_entry);
  767. }
  768. static u64 intel_cqm_event_count(struct perf_event *event)
  769. {
  770. unsigned long flags;
  771. struct rmid_read rr = {
  772. .value = ATOMIC64_INIT(0),
  773. };
  774. /*
  775. * We only need to worry about task events. System-wide events
  776. * are handled like usual, i.e. entirely with
  777. * intel_cqm_event_read().
  778. */
  779. if (event->cpu != -1)
  780. return __perf_event_count(event);
  781. /*
  782. * Only the group leader gets to report values. This stops us
  783. * reporting duplicate values to userspace, and gives us a clear
  784. * rule for which task gets to report the values.
  785. *
  786. * Note that it is impossible to attribute these values to
  787. * specific packages - we forfeit that ability when we create
  788. * task events.
  789. */
  790. if (!cqm_group_leader(event))
  791. return 0;
  792. /*
  793. * Getting up-to-date values requires an SMP IPI which is not
  794. * possible if we're being called in interrupt context. Return
  795. * the cached values instead.
  796. */
  797. if (unlikely(in_interrupt()))
  798. goto out;
  799. /*
  800. * Notice that we don't perform the reading of an RMID
  801. * atomically, because we can't hold a spin lock across the
  802. * IPIs.
  803. *
  804. * Speculatively perform the read, since @event might be
  805. * assigned a different (possibly invalid) RMID while we're
  806. * busying performing the IPI calls. It's therefore necessary to
  807. * check @event's RMID afterwards, and if it has changed,
  808. * discard the result of the read.
  809. */
  810. rr.rmid = ACCESS_ONCE(event->hw.cqm_rmid);
  811. if (!__rmid_valid(rr.rmid))
  812. goto out;
  813. on_each_cpu_mask(&cqm_cpumask, __intel_cqm_event_count, &rr, 1);
  814. raw_spin_lock_irqsave(&cache_lock, flags);
  815. if (event->hw.cqm_rmid == rr.rmid)
  816. local64_set(&event->count, atomic64_read(&rr.value));
  817. raw_spin_unlock_irqrestore(&cache_lock, flags);
  818. out:
  819. return __perf_event_count(event);
  820. }
  821. static void intel_cqm_event_start(struct perf_event *event, int mode)
  822. {
  823. struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
  824. u32 rmid = event->hw.cqm_rmid;
  825. if (!(event->hw.cqm_state & PERF_HES_STOPPED))
  826. return;
  827. event->hw.cqm_state &= ~PERF_HES_STOPPED;
  828. if (state->rmid_usecnt++) {
  829. if (!WARN_ON_ONCE(state->rmid != rmid))
  830. return;
  831. } else {
  832. WARN_ON_ONCE(state->rmid);
  833. }
  834. state->rmid = rmid;
  835. wrmsr(MSR_IA32_PQR_ASSOC, rmid, state->closid);
  836. }
  837. static void intel_cqm_event_stop(struct perf_event *event, int mode)
  838. {
  839. struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
  840. if (event->hw.cqm_state & PERF_HES_STOPPED)
  841. return;
  842. event->hw.cqm_state |= PERF_HES_STOPPED;
  843. intel_cqm_event_read(event);
  844. if (!--state->rmid_usecnt) {
  845. state->rmid = 0;
  846. wrmsr(MSR_IA32_PQR_ASSOC, 0, state->closid);
  847. } else {
  848. WARN_ON_ONCE(!state->rmid);
  849. }
  850. }
  851. static int intel_cqm_event_add(struct perf_event *event, int mode)
  852. {
  853. unsigned long flags;
  854. u32 rmid;
  855. raw_spin_lock_irqsave(&cache_lock, flags);
  856. event->hw.cqm_state = PERF_HES_STOPPED;
  857. rmid = event->hw.cqm_rmid;
  858. if (__rmid_valid(rmid) && (mode & PERF_EF_START))
  859. intel_cqm_event_start(event, mode);
  860. raw_spin_unlock_irqrestore(&cache_lock, flags);
  861. return 0;
  862. }
  863. static void intel_cqm_event_destroy(struct perf_event *event)
  864. {
  865. struct perf_event *group_other = NULL;
  866. mutex_lock(&cache_mutex);
  867. /*
  868. * If there's another event in this group...
  869. */
  870. if (!list_empty(&event->hw.cqm_group_entry)) {
  871. group_other = list_first_entry(&event->hw.cqm_group_entry,
  872. struct perf_event,
  873. hw.cqm_group_entry);
  874. list_del(&event->hw.cqm_group_entry);
  875. }
  876. /*
  877. * And we're the group leader..
  878. */
  879. if (cqm_group_leader(event)) {
  880. /*
  881. * If there was a group_other, make that leader, otherwise
  882. * destroy the group and return the RMID.
  883. */
  884. if (group_other) {
  885. list_replace(&event->hw.cqm_groups_entry,
  886. &group_other->hw.cqm_groups_entry);
  887. } else {
  888. u32 rmid = event->hw.cqm_rmid;
  889. if (__rmid_valid(rmid))
  890. __put_rmid(rmid);
  891. list_del(&event->hw.cqm_groups_entry);
  892. }
  893. }
  894. mutex_unlock(&cache_mutex);
  895. }
  896. static int intel_cqm_event_init(struct perf_event *event)
  897. {
  898. struct perf_event *group = NULL;
  899. bool rotate = false;
  900. if (event->attr.type != intel_cqm_pmu.type)
  901. return -ENOENT;
  902. if (event->attr.config & ~QOS_EVENT_MASK)
  903. return -EINVAL;
  904. /* unsupported modes and filters */
  905. if (event->attr.exclude_user ||
  906. event->attr.exclude_kernel ||
  907. event->attr.exclude_hv ||
  908. event->attr.exclude_idle ||
  909. event->attr.exclude_host ||
  910. event->attr.exclude_guest ||
  911. event->attr.sample_period) /* no sampling */
  912. return -EINVAL;
  913. INIT_LIST_HEAD(&event->hw.cqm_group_entry);
  914. INIT_LIST_HEAD(&event->hw.cqm_groups_entry);
  915. event->destroy = intel_cqm_event_destroy;
  916. mutex_lock(&cache_mutex);
  917. /* Will also set rmid */
  918. intel_cqm_setup_event(event, &group);
  919. if (group) {
  920. list_add_tail(&event->hw.cqm_group_entry,
  921. &group->hw.cqm_group_entry);
  922. } else {
  923. list_add_tail(&event->hw.cqm_groups_entry,
  924. &cache_groups);
  925. /*
  926. * All RMIDs are either in use or have recently been
  927. * used. Kick the rotation worker to clean/free some.
  928. *
  929. * We only do this for the group leader, rather than for
  930. * every event in a group to save on needless work.
  931. */
  932. if (!__rmid_valid(event->hw.cqm_rmid))
  933. rotate = true;
  934. }
  935. mutex_unlock(&cache_mutex);
  936. if (rotate)
  937. schedule_delayed_work(&intel_cqm_rmid_work, 0);
  938. return 0;
  939. }
  940. EVENT_ATTR_STR(llc_occupancy, intel_cqm_llc, "event=0x01");
  941. EVENT_ATTR_STR(llc_occupancy.per-pkg, intel_cqm_llc_pkg, "1");
  942. EVENT_ATTR_STR(llc_occupancy.unit, intel_cqm_llc_unit, "Bytes");
  943. EVENT_ATTR_STR(llc_occupancy.scale, intel_cqm_llc_scale, NULL);
  944. EVENT_ATTR_STR(llc_occupancy.snapshot, intel_cqm_llc_snapshot, "1");
  945. static struct attribute *intel_cqm_events_attr[] = {
  946. EVENT_PTR(intel_cqm_llc),
  947. EVENT_PTR(intel_cqm_llc_pkg),
  948. EVENT_PTR(intel_cqm_llc_unit),
  949. EVENT_PTR(intel_cqm_llc_scale),
  950. EVENT_PTR(intel_cqm_llc_snapshot),
  951. NULL,
  952. };
  953. static struct attribute_group intel_cqm_events_group = {
  954. .name = "events",
  955. .attrs = intel_cqm_events_attr,
  956. };
  957. PMU_FORMAT_ATTR(event, "config:0-7");
  958. static struct attribute *intel_cqm_formats_attr[] = {
  959. &format_attr_event.attr,
  960. NULL,
  961. };
  962. static struct attribute_group intel_cqm_format_group = {
  963. .name = "format",
  964. .attrs = intel_cqm_formats_attr,
  965. };
  966. static ssize_t
  967. max_recycle_threshold_show(struct device *dev, struct device_attribute *attr,
  968. char *page)
  969. {
  970. ssize_t rv;
  971. mutex_lock(&cache_mutex);
  972. rv = snprintf(page, PAGE_SIZE-1, "%u\n", __intel_cqm_max_threshold);
  973. mutex_unlock(&cache_mutex);
  974. return rv;
  975. }
  976. static ssize_t
  977. max_recycle_threshold_store(struct device *dev,
  978. struct device_attribute *attr,
  979. const char *buf, size_t count)
  980. {
  981. unsigned int bytes, cachelines;
  982. int ret;
  983. ret = kstrtouint(buf, 0, &bytes);
  984. if (ret)
  985. return ret;
  986. mutex_lock(&cache_mutex);
  987. __intel_cqm_max_threshold = bytes;
  988. cachelines = bytes / cqm_l3_scale;
  989. /*
  990. * The new maximum takes effect immediately.
  991. */
  992. if (__intel_cqm_threshold > cachelines)
  993. __intel_cqm_threshold = cachelines;
  994. mutex_unlock(&cache_mutex);
  995. return count;
  996. }
  997. static DEVICE_ATTR_RW(max_recycle_threshold);
  998. static struct attribute *intel_cqm_attrs[] = {
  999. &dev_attr_max_recycle_threshold.attr,
  1000. NULL,
  1001. };
  1002. static const struct attribute_group intel_cqm_group = {
  1003. .attrs = intel_cqm_attrs,
  1004. };
  1005. static const struct attribute_group *intel_cqm_attr_groups[] = {
  1006. &intel_cqm_events_group,
  1007. &intel_cqm_format_group,
  1008. &intel_cqm_group,
  1009. NULL,
  1010. };
  1011. static struct pmu intel_cqm_pmu = {
  1012. .hrtimer_interval_ms = RMID_DEFAULT_QUEUE_TIME,
  1013. .attr_groups = intel_cqm_attr_groups,
  1014. .task_ctx_nr = perf_sw_context,
  1015. .event_init = intel_cqm_event_init,
  1016. .add = intel_cqm_event_add,
  1017. .del = intel_cqm_event_stop,
  1018. .start = intel_cqm_event_start,
  1019. .stop = intel_cqm_event_stop,
  1020. .read = intel_cqm_event_read,
  1021. .count = intel_cqm_event_count,
  1022. };
  1023. static inline void cqm_pick_event_reader(int cpu)
  1024. {
  1025. int phys_id = topology_physical_package_id(cpu);
  1026. int i;
  1027. for_each_cpu(i, &cqm_cpumask) {
  1028. if (phys_id == topology_physical_package_id(i))
  1029. return; /* already got reader for this socket */
  1030. }
  1031. cpumask_set_cpu(cpu, &cqm_cpumask);
  1032. }
  1033. static void intel_cqm_cpu_starting(unsigned int cpu)
  1034. {
  1035. struct intel_pqr_state *state = &per_cpu(pqr_state, cpu);
  1036. struct cpuinfo_x86 *c = &cpu_data(cpu);
  1037. state->rmid = 0;
  1038. state->closid = 0;
  1039. state->rmid_usecnt = 0;
  1040. WARN_ON(c->x86_cache_max_rmid != cqm_max_rmid);
  1041. WARN_ON(c->x86_cache_occ_scale != cqm_l3_scale);
  1042. }
  1043. static void intel_cqm_cpu_exit(unsigned int cpu)
  1044. {
  1045. int phys_id = topology_physical_package_id(cpu);
  1046. int i;
  1047. /*
  1048. * Is @cpu a designated cqm reader?
  1049. */
  1050. if (!cpumask_test_and_clear_cpu(cpu, &cqm_cpumask))
  1051. return;
  1052. for_each_online_cpu(i) {
  1053. if (i == cpu)
  1054. continue;
  1055. if (phys_id == topology_physical_package_id(i)) {
  1056. cpumask_set_cpu(i, &cqm_cpumask);
  1057. break;
  1058. }
  1059. }
  1060. }
  1061. static int intel_cqm_cpu_notifier(struct notifier_block *nb,
  1062. unsigned long action, void *hcpu)
  1063. {
  1064. unsigned int cpu = (unsigned long)hcpu;
  1065. switch (action & ~CPU_TASKS_FROZEN) {
  1066. case CPU_DOWN_PREPARE:
  1067. intel_cqm_cpu_exit(cpu);
  1068. break;
  1069. case CPU_STARTING:
  1070. intel_cqm_cpu_starting(cpu);
  1071. cqm_pick_event_reader(cpu);
  1072. break;
  1073. }
  1074. return NOTIFY_OK;
  1075. }
  1076. static const struct x86_cpu_id intel_cqm_match[] = {
  1077. { .vendor = X86_VENDOR_INTEL, .feature = X86_FEATURE_CQM_OCCUP_LLC },
  1078. {}
  1079. };
  1080. static int __init intel_cqm_init(void)
  1081. {
  1082. char *str, scale[20];
  1083. int i, cpu, ret;
  1084. if (!x86_match_cpu(intel_cqm_match))
  1085. return -ENODEV;
  1086. cqm_l3_scale = boot_cpu_data.x86_cache_occ_scale;
  1087. /*
  1088. * It's possible that not all resources support the same number
  1089. * of RMIDs. Instead of making scheduling much more complicated
  1090. * (where we have to match a task's RMID to a cpu that supports
  1091. * that many RMIDs) just find the minimum RMIDs supported across
  1092. * all cpus.
  1093. *
  1094. * Also, check that the scales match on all cpus.
  1095. */
  1096. cpu_notifier_register_begin();
  1097. for_each_online_cpu(cpu) {
  1098. struct cpuinfo_x86 *c = &cpu_data(cpu);
  1099. if (c->x86_cache_max_rmid < cqm_max_rmid)
  1100. cqm_max_rmid = c->x86_cache_max_rmid;
  1101. if (c->x86_cache_occ_scale != cqm_l3_scale) {
  1102. pr_err("Multiple LLC scale values, disabling\n");
  1103. ret = -EINVAL;
  1104. goto out;
  1105. }
  1106. }
  1107. /*
  1108. * A reasonable upper limit on the max threshold is the number
  1109. * of lines tagged per RMID if all RMIDs have the same number of
  1110. * lines tagged in the LLC.
  1111. *
  1112. * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
  1113. */
  1114. __intel_cqm_max_threshold =
  1115. boot_cpu_data.x86_cache_size * 1024 / (cqm_max_rmid + 1);
  1116. snprintf(scale, sizeof(scale), "%u", cqm_l3_scale);
  1117. str = kstrdup(scale, GFP_KERNEL);
  1118. if (!str) {
  1119. ret = -ENOMEM;
  1120. goto out;
  1121. }
  1122. event_attr_intel_cqm_llc_scale.event_str = str;
  1123. ret = intel_cqm_setup_rmid_cache();
  1124. if (ret)
  1125. goto out;
  1126. for_each_online_cpu(i) {
  1127. intel_cqm_cpu_starting(i);
  1128. cqm_pick_event_reader(i);
  1129. }
  1130. __perf_cpu_notifier(intel_cqm_cpu_notifier);
  1131. ret = perf_pmu_register(&intel_cqm_pmu, "intel_cqm", -1);
  1132. if (ret)
  1133. pr_err("Intel CQM perf registration failed: %d\n", ret);
  1134. else
  1135. pr_info("Intel CQM monitoring enabled\n");
  1136. out:
  1137. cpu_notifier_register_done();
  1138. return ret;
  1139. }
  1140. device_initcall(intel_cqm_init);