perf_event_intel_cqm.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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. * Notice that we don't perform the reading of an RMID
  794. * atomically, because we can't hold a spin lock across the
  795. * IPIs.
  796. *
  797. * Speculatively perform the read, since @event might be
  798. * assigned a different (possibly invalid) RMID while we're
  799. * busying performing the IPI calls. It's therefore necessary to
  800. * check @event's RMID afterwards, and if it has changed,
  801. * discard the result of the read.
  802. */
  803. rr.rmid = ACCESS_ONCE(event->hw.cqm_rmid);
  804. if (!__rmid_valid(rr.rmid))
  805. goto out;
  806. on_each_cpu_mask(&cqm_cpumask, __intel_cqm_event_count, &rr, 1);
  807. raw_spin_lock_irqsave(&cache_lock, flags);
  808. if (event->hw.cqm_rmid == rr.rmid)
  809. local64_set(&event->count, atomic64_read(&rr.value));
  810. raw_spin_unlock_irqrestore(&cache_lock, flags);
  811. out:
  812. return __perf_event_count(event);
  813. }
  814. static void intel_cqm_event_start(struct perf_event *event, int mode)
  815. {
  816. struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
  817. u32 rmid = event->hw.cqm_rmid;
  818. if (!(event->hw.cqm_state & PERF_HES_STOPPED))
  819. return;
  820. event->hw.cqm_state &= ~PERF_HES_STOPPED;
  821. if (state->rmid_usecnt++) {
  822. if (!WARN_ON_ONCE(state->rmid != rmid))
  823. return;
  824. } else {
  825. WARN_ON_ONCE(state->rmid);
  826. }
  827. state->rmid = rmid;
  828. wrmsr(MSR_IA32_PQR_ASSOC, rmid, state->closid);
  829. }
  830. static void intel_cqm_event_stop(struct perf_event *event, int mode)
  831. {
  832. struct intel_pqr_state *state = this_cpu_ptr(&pqr_state);
  833. if (event->hw.cqm_state & PERF_HES_STOPPED)
  834. return;
  835. event->hw.cqm_state |= PERF_HES_STOPPED;
  836. intel_cqm_event_read(event);
  837. if (!--state->rmid_usecnt) {
  838. state->rmid = 0;
  839. wrmsr(MSR_IA32_PQR_ASSOC, 0, state->closid);
  840. } else {
  841. WARN_ON_ONCE(!state->rmid);
  842. }
  843. }
  844. static int intel_cqm_event_add(struct perf_event *event, int mode)
  845. {
  846. unsigned long flags;
  847. u32 rmid;
  848. raw_spin_lock_irqsave(&cache_lock, flags);
  849. event->hw.cqm_state = PERF_HES_STOPPED;
  850. rmid = event->hw.cqm_rmid;
  851. if (__rmid_valid(rmid) && (mode & PERF_EF_START))
  852. intel_cqm_event_start(event, mode);
  853. raw_spin_unlock_irqrestore(&cache_lock, flags);
  854. return 0;
  855. }
  856. static void intel_cqm_event_destroy(struct perf_event *event)
  857. {
  858. struct perf_event *group_other = NULL;
  859. mutex_lock(&cache_mutex);
  860. /*
  861. * If there's another event in this group...
  862. */
  863. if (!list_empty(&event->hw.cqm_group_entry)) {
  864. group_other = list_first_entry(&event->hw.cqm_group_entry,
  865. struct perf_event,
  866. hw.cqm_group_entry);
  867. list_del(&event->hw.cqm_group_entry);
  868. }
  869. /*
  870. * And we're the group leader..
  871. */
  872. if (cqm_group_leader(event)) {
  873. /*
  874. * If there was a group_other, make that leader, otherwise
  875. * destroy the group and return the RMID.
  876. */
  877. if (group_other) {
  878. list_replace(&event->hw.cqm_groups_entry,
  879. &group_other->hw.cqm_groups_entry);
  880. } else {
  881. u32 rmid = event->hw.cqm_rmid;
  882. if (__rmid_valid(rmid))
  883. __put_rmid(rmid);
  884. list_del(&event->hw.cqm_groups_entry);
  885. }
  886. }
  887. mutex_unlock(&cache_mutex);
  888. }
  889. static int intel_cqm_event_init(struct perf_event *event)
  890. {
  891. struct perf_event *group = NULL;
  892. bool rotate = false;
  893. if (event->attr.type != intel_cqm_pmu.type)
  894. return -ENOENT;
  895. if (event->attr.config & ~QOS_EVENT_MASK)
  896. return -EINVAL;
  897. /* unsupported modes and filters */
  898. if (event->attr.exclude_user ||
  899. event->attr.exclude_kernel ||
  900. event->attr.exclude_hv ||
  901. event->attr.exclude_idle ||
  902. event->attr.exclude_host ||
  903. event->attr.exclude_guest ||
  904. event->attr.sample_period) /* no sampling */
  905. return -EINVAL;
  906. INIT_LIST_HEAD(&event->hw.cqm_group_entry);
  907. INIT_LIST_HEAD(&event->hw.cqm_groups_entry);
  908. event->destroy = intel_cqm_event_destroy;
  909. mutex_lock(&cache_mutex);
  910. /* Will also set rmid */
  911. intel_cqm_setup_event(event, &group);
  912. if (group) {
  913. list_add_tail(&event->hw.cqm_group_entry,
  914. &group->hw.cqm_group_entry);
  915. } else {
  916. list_add_tail(&event->hw.cqm_groups_entry,
  917. &cache_groups);
  918. /*
  919. * All RMIDs are either in use or have recently been
  920. * used. Kick the rotation worker to clean/free some.
  921. *
  922. * We only do this for the group leader, rather than for
  923. * every event in a group to save on needless work.
  924. */
  925. if (!__rmid_valid(event->hw.cqm_rmid))
  926. rotate = true;
  927. }
  928. mutex_unlock(&cache_mutex);
  929. if (rotate)
  930. schedule_delayed_work(&intel_cqm_rmid_work, 0);
  931. return 0;
  932. }
  933. EVENT_ATTR_STR(llc_occupancy, intel_cqm_llc, "event=0x01");
  934. EVENT_ATTR_STR(llc_occupancy.per-pkg, intel_cqm_llc_pkg, "1");
  935. EVENT_ATTR_STR(llc_occupancy.unit, intel_cqm_llc_unit, "Bytes");
  936. EVENT_ATTR_STR(llc_occupancy.scale, intel_cqm_llc_scale, NULL);
  937. EVENT_ATTR_STR(llc_occupancy.snapshot, intel_cqm_llc_snapshot, "1");
  938. static struct attribute *intel_cqm_events_attr[] = {
  939. EVENT_PTR(intel_cqm_llc),
  940. EVENT_PTR(intel_cqm_llc_pkg),
  941. EVENT_PTR(intel_cqm_llc_unit),
  942. EVENT_PTR(intel_cqm_llc_scale),
  943. EVENT_PTR(intel_cqm_llc_snapshot),
  944. NULL,
  945. };
  946. static struct attribute_group intel_cqm_events_group = {
  947. .name = "events",
  948. .attrs = intel_cqm_events_attr,
  949. };
  950. PMU_FORMAT_ATTR(event, "config:0-7");
  951. static struct attribute *intel_cqm_formats_attr[] = {
  952. &format_attr_event.attr,
  953. NULL,
  954. };
  955. static struct attribute_group intel_cqm_format_group = {
  956. .name = "format",
  957. .attrs = intel_cqm_formats_attr,
  958. };
  959. static ssize_t
  960. max_recycle_threshold_show(struct device *dev, struct device_attribute *attr,
  961. char *page)
  962. {
  963. ssize_t rv;
  964. mutex_lock(&cache_mutex);
  965. rv = snprintf(page, PAGE_SIZE-1, "%u\n", __intel_cqm_max_threshold);
  966. mutex_unlock(&cache_mutex);
  967. return rv;
  968. }
  969. static ssize_t
  970. max_recycle_threshold_store(struct device *dev,
  971. struct device_attribute *attr,
  972. const char *buf, size_t count)
  973. {
  974. unsigned int bytes, cachelines;
  975. int ret;
  976. ret = kstrtouint(buf, 0, &bytes);
  977. if (ret)
  978. return ret;
  979. mutex_lock(&cache_mutex);
  980. __intel_cqm_max_threshold = bytes;
  981. cachelines = bytes / cqm_l3_scale;
  982. /*
  983. * The new maximum takes effect immediately.
  984. */
  985. if (__intel_cqm_threshold > cachelines)
  986. __intel_cqm_threshold = cachelines;
  987. mutex_unlock(&cache_mutex);
  988. return count;
  989. }
  990. static DEVICE_ATTR_RW(max_recycle_threshold);
  991. static struct attribute *intel_cqm_attrs[] = {
  992. &dev_attr_max_recycle_threshold.attr,
  993. NULL,
  994. };
  995. static const struct attribute_group intel_cqm_group = {
  996. .attrs = intel_cqm_attrs,
  997. };
  998. static const struct attribute_group *intel_cqm_attr_groups[] = {
  999. &intel_cqm_events_group,
  1000. &intel_cqm_format_group,
  1001. &intel_cqm_group,
  1002. NULL,
  1003. };
  1004. static struct pmu intel_cqm_pmu = {
  1005. .hrtimer_interval_ms = RMID_DEFAULT_QUEUE_TIME,
  1006. .attr_groups = intel_cqm_attr_groups,
  1007. .task_ctx_nr = perf_sw_context,
  1008. .event_init = intel_cqm_event_init,
  1009. .add = intel_cqm_event_add,
  1010. .del = intel_cqm_event_stop,
  1011. .start = intel_cqm_event_start,
  1012. .stop = intel_cqm_event_stop,
  1013. .read = intel_cqm_event_read,
  1014. .count = intel_cqm_event_count,
  1015. };
  1016. static inline void cqm_pick_event_reader(int cpu)
  1017. {
  1018. int phys_id = topology_physical_package_id(cpu);
  1019. int i;
  1020. for_each_cpu(i, &cqm_cpumask) {
  1021. if (phys_id == topology_physical_package_id(i))
  1022. return; /* already got reader for this socket */
  1023. }
  1024. cpumask_set_cpu(cpu, &cqm_cpumask);
  1025. }
  1026. static void intel_cqm_cpu_prepare(unsigned int cpu)
  1027. {
  1028. struct intel_pqr_state *state = &per_cpu(pqr_state, cpu);
  1029. struct cpuinfo_x86 *c = &cpu_data(cpu);
  1030. state->rmid = 0;
  1031. state->closid = 0;
  1032. state->rmid_usecnt = 0;
  1033. WARN_ON(c->x86_cache_max_rmid != cqm_max_rmid);
  1034. WARN_ON(c->x86_cache_occ_scale != cqm_l3_scale);
  1035. }
  1036. static void intel_cqm_cpu_exit(unsigned int cpu)
  1037. {
  1038. int phys_id = topology_physical_package_id(cpu);
  1039. int i;
  1040. /*
  1041. * Is @cpu a designated cqm reader?
  1042. */
  1043. if (!cpumask_test_and_clear_cpu(cpu, &cqm_cpumask))
  1044. return;
  1045. for_each_online_cpu(i) {
  1046. if (i == cpu)
  1047. continue;
  1048. if (phys_id == topology_physical_package_id(i)) {
  1049. cpumask_set_cpu(i, &cqm_cpumask);
  1050. break;
  1051. }
  1052. }
  1053. }
  1054. static int intel_cqm_cpu_notifier(struct notifier_block *nb,
  1055. unsigned long action, void *hcpu)
  1056. {
  1057. unsigned int cpu = (unsigned long)hcpu;
  1058. switch (action & ~CPU_TASKS_FROZEN) {
  1059. case CPU_UP_PREPARE:
  1060. intel_cqm_cpu_prepare(cpu);
  1061. break;
  1062. case CPU_DOWN_PREPARE:
  1063. intel_cqm_cpu_exit(cpu);
  1064. break;
  1065. case CPU_STARTING:
  1066. cqm_pick_event_reader(cpu);
  1067. break;
  1068. }
  1069. return NOTIFY_OK;
  1070. }
  1071. static const struct x86_cpu_id intel_cqm_match[] = {
  1072. { .vendor = X86_VENDOR_INTEL, .feature = X86_FEATURE_CQM_OCCUP_LLC },
  1073. {}
  1074. };
  1075. static int __init intel_cqm_init(void)
  1076. {
  1077. char *str, scale[20];
  1078. int i, cpu, ret;
  1079. if (!x86_match_cpu(intel_cqm_match))
  1080. return -ENODEV;
  1081. cqm_l3_scale = boot_cpu_data.x86_cache_occ_scale;
  1082. /*
  1083. * It's possible that not all resources support the same number
  1084. * of RMIDs. Instead of making scheduling much more complicated
  1085. * (where we have to match a task's RMID to a cpu that supports
  1086. * that many RMIDs) just find the minimum RMIDs supported across
  1087. * all cpus.
  1088. *
  1089. * Also, check that the scales match on all cpus.
  1090. */
  1091. cpu_notifier_register_begin();
  1092. for_each_online_cpu(cpu) {
  1093. struct cpuinfo_x86 *c = &cpu_data(cpu);
  1094. if (c->x86_cache_max_rmid < cqm_max_rmid)
  1095. cqm_max_rmid = c->x86_cache_max_rmid;
  1096. if (c->x86_cache_occ_scale != cqm_l3_scale) {
  1097. pr_err("Multiple LLC scale values, disabling\n");
  1098. ret = -EINVAL;
  1099. goto out;
  1100. }
  1101. }
  1102. /*
  1103. * A reasonable upper limit on the max threshold is the number
  1104. * of lines tagged per RMID if all RMIDs have the same number of
  1105. * lines tagged in the LLC.
  1106. *
  1107. * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
  1108. */
  1109. __intel_cqm_max_threshold =
  1110. boot_cpu_data.x86_cache_size * 1024 / (cqm_max_rmid + 1);
  1111. snprintf(scale, sizeof(scale), "%u", cqm_l3_scale);
  1112. str = kstrdup(scale, GFP_KERNEL);
  1113. if (!str) {
  1114. ret = -ENOMEM;
  1115. goto out;
  1116. }
  1117. event_attr_intel_cqm_llc_scale.event_str = str;
  1118. ret = intel_cqm_setup_rmid_cache();
  1119. if (ret)
  1120. goto out;
  1121. for_each_online_cpu(i) {
  1122. intel_cqm_cpu_prepare(i);
  1123. cqm_pick_event_reader(i);
  1124. }
  1125. __perf_cpu_notifier(intel_cqm_cpu_notifier);
  1126. ret = perf_pmu_register(&intel_cqm_pmu, "intel_cqm", -1);
  1127. if (ret)
  1128. pr_err("Intel CQM perf registration failed: %d\n", ret);
  1129. else
  1130. pr_info("Intel CQM monitoring enabled\n");
  1131. out:
  1132. cpu_notifier_register_done();
  1133. return ret;
  1134. }
  1135. device_initcall(intel_cqm_init);