affinity.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. /*
  2. * Copyright(c) 2015 - 2018 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #include <linux/topology.h>
  48. #include <linux/cpumask.h>
  49. #include <linux/module.h>
  50. #include <linux/interrupt.h>
  51. #include "hfi.h"
  52. #include "affinity.h"
  53. #include "sdma.h"
  54. #include "trace.h"
  55. struct hfi1_affinity_node_list node_affinity = {
  56. .list = LIST_HEAD_INIT(node_affinity.list),
  57. .lock = __MUTEX_INITIALIZER(node_affinity.lock)
  58. };
  59. /* Name of IRQ types, indexed by enum irq_type */
  60. static const char * const irq_type_names[] = {
  61. "SDMA",
  62. "RCVCTXT",
  63. "GENERAL",
  64. "OTHER",
  65. };
  66. /* Per NUMA node count of HFI devices */
  67. static unsigned int *hfi1_per_node_cntr;
  68. static inline void init_cpu_mask_set(struct cpu_mask_set *set)
  69. {
  70. cpumask_clear(&set->mask);
  71. cpumask_clear(&set->used);
  72. set->gen = 0;
  73. }
  74. /* Increment generation of CPU set if needed */
  75. static void _cpu_mask_set_gen_inc(struct cpu_mask_set *set)
  76. {
  77. if (cpumask_equal(&set->mask, &set->used)) {
  78. /*
  79. * We've used up all the CPUs, bump up the generation
  80. * and reset the 'used' map
  81. */
  82. set->gen++;
  83. cpumask_clear(&set->used);
  84. }
  85. }
  86. static void _cpu_mask_set_gen_dec(struct cpu_mask_set *set)
  87. {
  88. if (cpumask_empty(&set->used) && set->gen) {
  89. set->gen--;
  90. cpumask_copy(&set->used, &set->mask);
  91. }
  92. }
  93. /* Get the first CPU from the list of unused CPUs in a CPU set data structure */
  94. static int cpu_mask_set_get_first(struct cpu_mask_set *set, cpumask_var_t diff)
  95. {
  96. int cpu;
  97. if (!diff || !set)
  98. return -EINVAL;
  99. _cpu_mask_set_gen_inc(set);
  100. /* Find out CPUs left in CPU mask */
  101. cpumask_andnot(diff, &set->mask, &set->used);
  102. cpu = cpumask_first(diff);
  103. if (cpu >= nr_cpu_ids) /* empty */
  104. cpu = -EINVAL;
  105. else
  106. cpumask_set_cpu(cpu, &set->used);
  107. return cpu;
  108. }
  109. static void cpu_mask_set_put(struct cpu_mask_set *set, int cpu)
  110. {
  111. if (!set)
  112. return;
  113. cpumask_clear_cpu(cpu, &set->used);
  114. _cpu_mask_set_gen_dec(set);
  115. }
  116. /* Initialize non-HT cpu cores mask */
  117. void init_real_cpu_mask(void)
  118. {
  119. int possible, curr_cpu, i, ht;
  120. cpumask_clear(&node_affinity.real_cpu_mask);
  121. /* Start with cpu online mask as the real cpu mask */
  122. cpumask_copy(&node_affinity.real_cpu_mask, cpu_online_mask);
  123. /*
  124. * Remove HT cores from the real cpu mask. Do this in two steps below.
  125. */
  126. possible = cpumask_weight(&node_affinity.real_cpu_mask);
  127. ht = cpumask_weight(topology_sibling_cpumask(
  128. cpumask_first(&node_affinity.real_cpu_mask)));
  129. /*
  130. * Step 1. Skip over the first N HT siblings and use them as the
  131. * "real" cores. Assumes that HT cores are not enumerated in
  132. * succession (except in the single core case).
  133. */
  134. curr_cpu = cpumask_first(&node_affinity.real_cpu_mask);
  135. for (i = 0; i < possible / ht; i++)
  136. curr_cpu = cpumask_next(curr_cpu, &node_affinity.real_cpu_mask);
  137. /*
  138. * Step 2. Remove the remaining HT siblings. Use cpumask_next() to
  139. * skip any gaps.
  140. */
  141. for (; i < possible; i++) {
  142. cpumask_clear_cpu(curr_cpu, &node_affinity.real_cpu_mask);
  143. curr_cpu = cpumask_next(curr_cpu, &node_affinity.real_cpu_mask);
  144. }
  145. }
  146. int node_affinity_init(void)
  147. {
  148. int node;
  149. struct pci_dev *dev = NULL;
  150. const struct pci_device_id *ids = hfi1_pci_tbl;
  151. cpumask_clear(&node_affinity.proc.used);
  152. cpumask_copy(&node_affinity.proc.mask, cpu_online_mask);
  153. node_affinity.proc.gen = 0;
  154. node_affinity.num_core_siblings =
  155. cpumask_weight(topology_sibling_cpumask(
  156. cpumask_first(&node_affinity.proc.mask)
  157. ));
  158. node_affinity.num_possible_nodes = num_possible_nodes();
  159. node_affinity.num_online_nodes = num_online_nodes();
  160. node_affinity.num_online_cpus = num_online_cpus();
  161. /*
  162. * The real cpu mask is part of the affinity struct but it has to be
  163. * initialized early. It is needed to calculate the number of user
  164. * contexts in set_up_context_variables().
  165. */
  166. init_real_cpu_mask();
  167. hfi1_per_node_cntr = kcalloc(node_affinity.num_possible_nodes,
  168. sizeof(*hfi1_per_node_cntr), GFP_KERNEL);
  169. if (!hfi1_per_node_cntr)
  170. return -ENOMEM;
  171. while (ids->vendor) {
  172. dev = NULL;
  173. while ((dev = pci_get_device(ids->vendor, ids->device, dev))) {
  174. node = pcibus_to_node(dev->bus);
  175. if (node < 0)
  176. goto out;
  177. hfi1_per_node_cntr[node]++;
  178. }
  179. ids++;
  180. }
  181. return 0;
  182. out:
  183. /*
  184. * Invalid PCI NUMA node information found, note it, and populate
  185. * our database 1:1.
  186. */
  187. pr_err("HFI: Invalid PCI NUMA node. Performance may be affected\n");
  188. pr_err("HFI: System BIOS may need to be upgraded\n");
  189. for (node = 0; node < node_affinity.num_possible_nodes; node++)
  190. hfi1_per_node_cntr[node] = 1;
  191. return 0;
  192. }
  193. static void node_affinity_destroy(struct hfi1_affinity_node *entry)
  194. {
  195. free_percpu(entry->comp_vect_affinity);
  196. kfree(entry);
  197. }
  198. void node_affinity_destroy_all(void)
  199. {
  200. struct list_head *pos, *q;
  201. struct hfi1_affinity_node *entry;
  202. mutex_lock(&node_affinity.lock);
  203. list_for_each_safe(pos, q, &node_affinity.list) {
  204. entry = list_entry(pos, struct hfi1_affinity_node,
  205. list);
  206. list_del(pos);
  207. node_affinity_destroy(entry);
  208. }
  209. mutex_unlock(&node_affinity.lock);
  210. kfree(hfi1_per_node_cntr);
  211. }
  212. static struct hfi1_affinity_node *node_affinity_allocate(int node)
  213. {
  214. struct hfi1_affinity_node *entry;
  215. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  216. if (!entry)
  217. return NULL;
  218. entry->node = node;
  219. entry->comp_vect_affinity = alloc_percpu(u16);
  220. INIT_LIST_HEAD(&entry->list);
  221. return entry;
  222. }
  223. /*
  224. * It appends an entry to the list.
  225. * It *must* be called with node_affinity.lock held.
  226. */
  227. static void node_affinity_add_tail(struct hfi1_affinity_node *entry)
  228. {
  229. list_add_tail(&entry->list, &node_affinity.list);
  230. }
  231. /* It must be called with node_affinity.lock held */
  232. static struct hfi1_affinity_node *node_affinity_lookup(int node)
  233. {
  234. struct list_head *pos;
  235. struct hfi1_affinity_node *entry;
  236. list_for_each(pos, &node_affinity.list) {
  237. entry = list_entry(pos, struct hfi1_affinity_node, list);
  238. if (entry->node == node)
  239. return entry;
  240. }
  241. return NULL;
  242. }
  243. static int per_cpu_affinity_get(cpumask_var_t possible_cpumask,
  244. u16 __percpu *comp_vect_affinity)
  245. {
  246. int curr_cpu;
  247. u16 cntr;
  248. u16 prev_cntr;
  249. int ret_cpu;
  250. if (!possible_cpumask) {
  251. ret_cpu = -EINVAL;
  252. goto fail;
  253. }
  254. if (!comp_vect_affinity) {
  255. ret_cpu = -EINVAL;
  256. goto fail;
  257. }
  258. ret_cpu = cpumask_first(possible_cpumask);
  259. if (ret_cpu >= nr_cpu_ids) {
  260. ret_cpu = -EINVAL;
  261. goto fail;
  262. }
  263. prev_cntr = *per_cpu_ptr(comp_vect_affinity, ret_cpu);
  264. for_each_cpu(curr_cpu, possible_cpumask) {
  265. cntr = *per_cpu_ptr(comp_vect_affinity, curr_cpu);
  266. if (cntr < prev_cntr) {
  267. ret_cpu = curr_cpu;
  268. prev_cntr = cntr;
  269. }
  270. }
  271. *per_cpu_ptr(comp_vect_affinity, ret_cpu) += 1;
  272. fail:
  273. return ret_cpu;
  274. }
  275. static int per_cpu_affinity_put_max(cpumask_var_t possible_cpumask,
  276. u16 __percpu *comp_vect_affinity)
  277. {
  278. int curr_cpu;
  279. int max_cpu;
  280. u16 cntr;
  281. u16 prev_cntr;
  282. if (!possible_cpumask)
  283. return -EINVAL;
  284. if (!comp_vect_affinity)
  285. return -EINVAL;
  286. max_cpu = cpumask_first(possible_cpumask);
  287. if (max_cpu >= nr_cpu_ids)
  288. return -EINVAL;
  289. prev_cntr = *per_cpu_ptr(comp_vect_affinity, max_cpu);
  290. for_each_cpu(curr_cpu, possible_cpumask) {
  291. cntr = *per_cpu_ptr(comp_vect_affinity, curr_cpu);
  292. if (cntr > prev_cntr) {
  293. max_cpu = curr_cpu;
  294. prev_cntr = cntr;
  295. }
  296. }
  297. *per_cpu_ptr(comp_vect_affinity, max_cpu) -= 1;
  298. return max_cpu;
  299. }
  300. /*
  301. * Non-interrupt CPUs are used first, then interrupt CPUs.
  302. * Two already allocated cpu masks must be passed.
  303. */
  304. static int _dev_comp_vect_cpu_get(struct hfi1_devdata *dd,
  305. struct hfi1_affinity_node *entry,
  306. cpumask_var_t non_intr_cpus,
  307. cpumask_var_t available_cpus)
  308. __must_hold(&node_affinity.lock)
  309. {
  310. int cpu;
  311. struct cpu_mask_set *set = dd->comp_vect;
  312. lockdep_assert_held(&node_affinity.lock);
  313. if (!non_intr_cpus) {
  314. cpu = -1;
  315. goto fail;
  316. }
  317. if (!available_cpus) {
  318. cpu = -1;
  319. goto fail;
  320. }
  321. /* Available CPUs for pinning completion vectors */
  322. _cpu_mask_set_gen_inc(set);
  323. cpumask_andnot(available_cpus, &set->mask, &set->used);
  324. /* Available CPUs without SDMA engine interrupts */
  325. cpumask_andnot(non_intr_cpus, available_cpus,
  326. &entry->def_intr.used);
  327. /* If there are non-interrupt CPUs available, use them first */
  328. if (!cpumask_empty(non_intr_cpus))
  329. cpu = cpumask_first(non_intr_cpus);
  330. else /* Otherwise, use interrupt CPUs */
  331. cpu = cpumask_first(available_cpus);
  332. if (cpu >= nr_cpu_ids) { /* empty */
  333. cpu = -1;
  334. goto fail;
  335. }
  336. cpumask_set_cpu(cpu, &set->used);
  337. fail:
  338. return cpu;
  339. }
  340. static void _dev_comp_vect_cpu_put(struct hfi1_devdata *dd, int cpu)
  341. {
  342. struct cpu_mask_set *set = dd->comp_vect;
  343. if (cpu < 0)
  344. return;
  345. cpu_mask_set_put(set, cpu);
  346. }
  347. /* _dev_comp_vect_mappings_destroy() is reentrant */
  348. static void _dev_comp_vect_mappings_destroy(struct hfi1_devdata *dd)
  349. {
  350. int i, cpu;
  351. if (!dd->comp_vect_mappings)
  352. return;
  353. for (i = 0; i < dd->comp_vect_possible_cpus; i++) {
  354. cpu = dd->comp_vect_mappings[i];
  355. _dev_comp_vect_cpu_put(dd, cpu);
  356. dd->comp_vect_mappings[i] = -1;
  357. hfi1_cdbg(AFFINITY,
  358. "[%s] Release CPU %d from completion vector %d",
  359. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), cpu, i);
  360. }
  361. kfree(dd->comp_vect_mappings);
  362. dd->comp_vect_mappings = NULL;
  363. }
  364. /*
  365. * This function creates the table for looking up CPUs for completion vectors.
  366. * num_comp_vectors needs to have been initilized before calling this function.
  367. */
  368. static int _dev_comp_vect_mappings_create(struct hfi1_devdata *dd,
  369. struct hfi1_affinity_node *entry)
  370. __must_hold(&node_affinity.lock)
  371. {
  372. int i, cpu, ret;
  373. cpumask_var_t non_intr_cpus;
  374. cpumask_var_t available_cpus;
  375. lockdep_assert_held(&node_affinity.lock);
  376. if (!zalloc_cpumask_var(&non_intr_cpus, GFP_KERNEL))
  377. return -ENOMEM;
  378. if (!zalloc_cpumask_var(&available_cpus, GFP_KERNEL)) {
  379. free_cpumask_var(non_intr_cpus);
  380. return -ENOMEM;
  381. }
  382. dd->comp_vect_mappings = kcalloc(dd->comp_vect_possible_cpus,
  383. sizeof(*dd->comp_vect_mappings),
  384. GFP_KERNEL);
  385. if (!dd->comp_vect_mappings) {
  386. ret = -ENOMEM;
  387. goto fail;
  388. }
  389. for (i = 0; i < dd->comp_vect_possible_cpus; i++)
  390. dd->comp_vect_mappings[i] = -1;
  391. for (i = 0; i < dd->comp_vect_possible_cpus; i++) {
  392. cpu = _dev_comp_vect_cpu_get(dd, entry, non_intr_cpus,
  393. available_cpus);
  394. if (cpu < 0) {
  395. ret = -EINVAL;
  396. goto fail;
  397. }
  398. dd->comp_vect_mappings[i] = cpu;
  399. hfi1_cdbg(AFFINITY,
  400. "[%s] Completion Vector %d -> CPU %d",
  401. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), i, cpu);
  402. }
  403. free_cpumask_var(available_cpus);
  404. free_cpumask_var(non_intr_cpus);
  405. return 0;
  406. fail:
  407. free_cpumask_var(available_cpus);
  408. free_cpumask_var(non_intr_cpus);
  409. _dev_comp_vect_mappings_destroy(dd);
  410. return ret;
  411. }
  412. int hfi1_comp_vectors_set_up(struct hfi1_devdata *dd)
  413. {
  414. int ret;
  415. struct hfi1_affinity_node *entry;
  416. mutex_lock(&node_affinity.lock);
  417. entry = node_affinity_lookup(dd->node);
  418. if (!entry) {
  419. ret = -EINVAL;
  420. goto unlock;
  421. }
  422. ret = _dev_comp_vect_mappings_create(dd, entry);
  423. unlock:
  424. mutex_unlock(&node_affinity.lock);
  425. return ret;
  426. }
  427. void hfi1_comp_vectors_clean_up(struct hfi1_devdata *dd)
  428. {
  429. _dev_comp_vect_mappings_destroy(dd);
  430. }
  431. int hfi1_comp_vect_mappings_lookup(struct rvt_dev_info *rdi, int comp_vect)
  432. {
  433. struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
  434. struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
  435. if (!dd->comp_vect_mappings)
  436. return -EINVAL;
  437. if (comp_vect >= dd->comp_vect_possible_cpus)
  438. return -EINVAL;
  439. return dd->comp_vect_mappings[comp_vect];
  440. }
  441. /*
  442. * It assumes dd->comp_vect_possible_cpus is available.
  443. */
  444. static int _dev_comp_vect_cpu_mask_init(struct hfi1_devdata *dd,
  445. struct hfi1_affinity_node *entry,
  446. bool first_dev_init)
  447. __must_hold(&node_affinity.lock)
  448. {
  449. int i, j, curr_cpu;
  450. int possible_cpus_comp_vect = 0;
  451. struct cpumask *dev_comp_vect_mask = &dd->comp_vect->mask;
  452. lockdep_assert_held(&node_affinity.lock);
  453. /*
  454. * If there's only one CPU available for completion vectors, then
  455. * there will only be one completion vector available. Othewise,
  456. * the number of completion vector available will be the number of
  457. * available CPUs divide it by the number of devices in the
  458. * local NUMA node.
  459. */
  460. if (cpumask_weight(&entry->comp_vect_mask) == 1) {
  461. possible_cpus_comp_vect = 1;
  462. dd_dev_warn(dd,
  463. "Number of kernel receive queues is too large for completion vector affinity to be effective\n");
  464. } else {
  465. possible_cpus_comp_vect +=
  466. cpumask_weight(&entry->comp_vect_mask) /
  467. hfi1_per_node_cntr[dd->node];
  468. /*
  469. * If the completion vector CPUs available doesn't divide
  470. * evenly among devices, then the first device device to be
  471. * initialized gets an extra CPU.
  472. */
  473. if (first_dev_init &&
  474. cpumask_weight(&entry->comp_vect_mask) %
  475. hfi1_per_node_cntr[dd->node] != 0)
  476. possible_cpus_comp_vect++;
  477. }
  478. dd->comp_vect_possible_cpus = possible_cpus_comp_vect;
  479. /* Reserving CPUs for device completion vector */
  480. for (i = 0; i < dd->comp_vect_possible_cpus; i++) {
  481. curr_cpu = per_cpu_affinity_get(&entry->comp_vect_mask,
  482. entry->comp_vect_affinity);
  483. if (curr_cpu < 0)
  484. goto fail;
  485. cpumask_set_cpu(curr_cpu, dev_comp_vect_mask);
  486. }
  487. hfi1_cdbg(AFFINITY,
  488. "[%s] Completion vector affinity CPU set(s) %*pbl",
  489. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi),
  490. cpumask_pr_args(dev_comp_vect_mask));
  491. return 0;
  492. fail:
  493. for (j = 0; j < i; j++)
  494. per_cpu_affinity_put_max(&entry->comp_vect_mask,
  495. entry->comp_vect_affinity);
  496. return curr_cpu;
  497. }
  498. /*
  499. * It assumes dd->comp_vect_possible_cpus is available.
  500. */
  501. static void _dev_comp_vect_cpu_mask_clean_up(struct hfi1_devdata *dd,
  502. struct hfi1_affinity_node *entry)
  503. __must_hold(&node_affinity.lock)
  504. {
  505. int i, cpu;
  506. lockdep_assert_held(&node_affinity.lock);
  507. if (!dd->comp_vect_possible_cpus)
  508. return;
  509. for (i = 0; i < dd->comp_vect_possible_cpus; i++) {
  510. cpu = per_cpu_affinity_put_max(&dd->comp_vect->mask,
  511. entry->comp_vect_affinity);
  512. /* Clearing CPU in device completion vector cpu mask */
  513. if (cpu >= 0)
  514. cpumask_clear_cpu(cpu, &dd->comp_vect->mask);
  515. }
  516. dd->comp_vect_possible_cpus = 0;
  517. }
  518. /*
  519. * Interrupt affinity.
  520. *
  521. * non-rcv avail gets a default mask that
  522. * starts as possible cpus with threads reset
  523. * and each rcv avail reset.
  524. *
  525. * rcv avail gets node relative 1 wrapping back
  526. * to the node relative 1 as necessary.
  527. *
  528. */
  529. int hfi1_dev_affinity_init(struct hfi1_devdata *dd)
  530. {
  531. int node = pcibus_to_node(dd->pcidev->bus);
  532. struct hfi1_affinity_node *entry;
  533. const struct cpumask *local_mask;
  534. int curr_cpu, possible, i, ret;
  535. bool new_entry = false;
  536. /*
  537. * If the BIOS does not have the NUMA node information set, select
  538. * NUMA 0 so we get consistent performance.
  539. */
  540. if (node < 0) {
  541. dd_dev_err(dd, "Invalid PCI NUMA node. Performance may be affected\n");
  542. node = 0;
  543. }
  544. dd->node = node;
  545. local_mask = cpumask_of_node(dd->node);
  546. if (cpumask_first(local_mask) >= nr_cpu_ids)
  547. local_mask = topology_core_cpumask(0);
  548. mutex_lock(&node_affinity.lock);
  549. entry = node_affinity_lookup(dd->node);
  550. /*
  551. * If this is the first time this NUMA node's affinity is used,
  552. * create an entry in the global affinity structure and initialize it.
  553. */
  554. if (!entry) {
  555. entry = node_affinity_allocate(node);
  556. if (!entry) {
  557. dd_dev_err(dd,
  558. "Unable to allocate global affinity node\n");
  559. ret = -ENOMEM;
  560. goto fail;
  561. }
  562. new_entry = true;
  563. init_cpu_mask_set(&entry->def_intr);
  564. init_cpu_mask_set(&entry->rcv_intr);
  565. cpumask_clear(&entry->comp_vect_mask);
  566. cpumask_clear(&entry->general_intr_mask);
  567. /* Use the "real" cpu mask of this node as the default */
  568. cpumask_and(&entry->def_intr.mask, &node_affinity.real_cpu_mask,
  569. local_mask);
  570. /* fill in the receive list */
  571. possible = cpumask_weight(&entry->def_intr.mask);
  572. curr_cpu = cpumask_first(&entry->def_intr.mask);
  573. if (possible == 1) {
  574. /* only one CPU, everyone will use it */
  575. cpumask_set_cpu(curr_cpu, &entry->rcv_intr.mask);
  576. cpumask_set_cpu(curr_cpu, &entry->general_intr_mask);
  577. } else {
  578. /*
  579. * The general/control context will be the first CPU in
  580. * the default list, so it is removed from the default
  581. * list and added to the general interrupt list.
  582. */
  583. cpumask_clear_cpu(curr_cpu, &entry->def_intr.mask);
  584. cpumask_set_cpu(curr_cpu, &entry->general_intr_mask);
  585. curr_cpu = cpumask_next(curr_cpu,
  586. &entry->def_intr.mask);
  587. /*
  588. * Remove the remaining kernel receive queues from
  589. * the default list and add them to the receive list.
  590. */
  591. for (i = 0;
  592. i < (dd->n_krcv_queues - 1) *
  593. hfi1_per_node_cntr[dd->node];
  594. i++) {
  595. cpumask_clear_cpu(curr_cpu,
  596. &entry->def_intr.mask);
  597. cpumask_set_cpu(curr_cpu,
  598. &entry->rcv_intr.mask);
  599. curr_cpu = cpumask_next(curr_cpu,
  600. &entry->def_intr.mask);
  601. if (curr_cpu >= nr_cpu_ids)
  602. break;
  603. }
  604. /*
  605. * If there ends up being 0 CPU cores leftover for SDMA
  606. * engines, use the same CPU cores as general/control
  607. * context.
  608. */
  609. if (cpumask_weight(&entry->def_intr.mask) == 0)
  610. cpumask_copy(&entry->def_intr.mask,
  611. &entry->general_intr_mask);
  612. }
  613. /* Determine completion vector CPUs for the entire node */
  614. cpumask_and(&entry->comp_vect_mask,
  615. &node_affinity.real_cpu_mask, local_mask);
  616. cpumask_andnot(&entry->comp_vect_mask,
  617. &entry->comp_vect_mask,
  618. &entry->rcv_intr.mask);
  619. cpumask_andnot(&entry->comp_vect_mask,
  620. &entry->comp_vect_mask,
  621. &entry->general_intr_mask);
  622. /*
  623. * If there ends up being 0 CPU cores leftover for completion
  624. * vectors, use the same CPU core as the general/control
  625. * context.
  626. */
  627. if (cpumask_weight(&entry->comp_vect_mask) == 0)
  628. cpumask_copy(&entry->comp_vect_mask,
  629. &entry->general_intr_mask);
  630. }
  631. ret = _dev_comp_vect_cpu_mask_init(dd, entry, new_entry);
  632. if (ret < 0)
  633. goto fail;
  634. if (new_entry)
  635. node_affinity_add_tail(entry);
  636. mutex_unlock(&node_affinity.lock);
  637. return 0;
  638. fail:
  639. if (new_entry)
  640. node_affinity_destroy(entry);
  641. mutex_unlock(&node_affinity.lock);
  642. return ret;
  643. }
  644. void hfi1_dev_affinity_clean_up(struct hfi1_devdata *dd)
  645. {
  646. struct hfi1_affinity_node *entry;
  647. if (dd->node < 0)
  648. return;
  649. mutex_lock(&node_affinity.lock);
  650. entry = node_affinity_lookup(dd->node);
  651. if (!entry)
  652. goto unlock;
  653. /*
  654. * Free device completion vector CPUs to be used by future
  655. * completion vectors
  656. */
  657. _dev_comp_vect_cpu_mask_clean_up(dd, entry);
  658. unlock:
  659. mutex_unlock(&node_affinity.lock);
  660. dd->node = -1;
  661. }
  662. /*
  663. * Function updates the irq affinity hint for msix after it has been changed
  664. * by the user using the /proc/irq interface. This function only accepts
  665. * one cpu in the mask.
  666. */
  667. static void hfi1_update_sdma_affinity(struct hfi1_msix_entry *msix, int cpu)
  668. {
  669. struct sdma_engine *sde = msix->arg;
  670. struct hfi1_devdata *dd = sde->dd;
  671. struct hfi1_affinity_node *entry;
  672. struct cpu_mask_set *set;
  673. int i, old_cpu;
  674. if (cpu > num_online_cpus() || cpu == sde->cpu)
  675. return;
  676. mutex_lock(&node_affinity.lock);
  677. entry = node_affinity_lookup(dd->node);
  678. if (!entry)
  679. goto unlock;
  680. old_cpu = sde->cpu;
  681. sde->cpu = cpu;
  682. cpumask_clear(&msix->mask);
  683. cpumask_set_cpu(cpu, &msix->mask);
  684. dd_dev_dbg(dd, "IRQ: %u, type %s engine %u -> cpu: %d\n",
  685. msix->irq, irq_type_names[msix->type],
  686. sde->this_idx, cpu);
  687. irq_set_affinity_hint(msix->irq, &msix->mask);
  688. /*
  689. * Set the new cpu in the hfi1_affinity_node and clean
  690. * the old cpu if it is not used by any other IRQ
  691. */
  692. set = &entry->def_intr;
  693. cpumask_set_cpu(cpu, &set->mask);
  694. cpumask_set_cpu(cpu, &set->used);
  695. for (i = 0; i < dd->num_msix_entries; i++) {
  696. struct hfi1_msix_entry *other_msix;
  697. other_msix = &dd->msix_entries[i];
  698. if (other_msix->type != IRQ_SDMA || other_msix == msix)
  699. continue;
  700. if (cpumask_test_cpu(old_cpu, &other_msix->mask))
  701. goto unlock;
  702. }
  703. cpumask_clear_cpu(old_cpu, &set->mask);
  704. cpumask_clear_cpu(old_cpu, &set->used);
  705. unlock:
  706. mutex_unlock(&node_affinity.lock);
  707. }
  708. static void hfi1_irq_notifier_notify(struct irq_affinity_notify *notify,
  709. const cpumask_t *mask)
  710. {
  711. int cpu = cpumask_first(mask);
  712. struct hfi1_msix_entry *msix = container_of(notify,
  713. struct hfi1_msix_entry,
  714. notify);
  715. /* Only one CPU configuration supported currently */
  716. hfi1_update_sdma_affinity(msix, cpu);
  717. }
  718. static void hfi1_irq_notifier_release(struct kref *ref)
  719. {
  720. /*
  721. * This is required by affinity notifier. We don't have anything to
  722. * free here.
  723. */
  724. }
  725. static void hfi1_setup_sdma_notifier(struct hfi1_msix_entry *msix)
  726. {
  727. struct irq_affinity_notify *notify = &msix->notify;
  728. notify->irq = msix->irq;
  729. notify->notify = hfi1_irq_notifier_notify;
  730. notify->release = hfi1_irq_notifier_release;
  731. if (irq_set_affinity_notifier(notify->irq, notify))
  732. pr_err("Failed to register sdma irq affinity notifier for irq %d\n",
  733. notify->irq);
  734. }
  735. static void hfi1_cleanup_sdma_notifier(struct hfi1_msix_entry *msix)
  736. {
  737. struct irq_affinity_notify *notify = &msix->notify;
  738. if (irq_set_affinity_notifier(notify->irq, NULL))
  739. pr_err("Failed to cleanup sdma irq affinity notifier for irq %d\n",
  740. notify->irq);
  741. }
  742. /*
  743. * Function sets the irq affinity for msix.
  744. * It *must* be called with node_affinity.lock held.
  745. */
  746. static int get_irq_affinity(struct hfi1_devdata *dd,
  747. struct hfi1_msix_entry *msix)
  748. {
  749. cpumask_var_t diff;
  750. struct hfi1_affinity_node *entry;
  751. struct cpu_mask_set *set = NULL;
  752. struct sdma_engine *sde = NULL;
  753. struct hfi1_ctxtdata *rcd = NULL;
  754. char extra[64];
  755. int cpu = -1;
  756. extra[0] = '\0';
  757. cpumask_clear(&msix->mask);
  758. entry = node_affinity_lookup(dd->node);
  759. switch (msix->type) {
  760. case IRQ_SDMA:
  761. sde = (struct sdma_engine *)msix->arg;
  762. scnprintf(extra, 64, "engine %u", sde->this_idx);
  763. set = &entry->def_intr;
  764. break;
  765. case IRQ_GENERAL:
  766. cpu = cpumask_first(&entry->general_intr_mask);
  767. break;
  768. case IRQ_RCVCTXT:
  769. rcd = (struct hfi1_ctxtdata *)msix->arg;
  770. if (rcd->ctxt == HFI1_CTRL_CTXT)
  771. cpu = cpumask_first(&entry->general_intr_mask);
  772. else
  773. set = &entry->rcv_intr;
  774. scnprintf(extra, 64, "ctxt %u", rcd->ctxt);
  775. break;
  776. default:
  777. dd_dev_err(dd, "Invalid IRQ type %d\n", msix->type);
  778. return -EINVAL;
  779. }
  780. /*
  781. * The general and control contexts are placed on a particular
  782. * CPU, which is set above. Skip accounting for it. Everything else
  783. * finds its CPU here.
  784. */
  785. if (cpu == -1 && set) {
  786. if (!zalloc_cpumask_var(&diff, GFP_KERNEL))
  787. return -ENOMEM;
  788. cpu = cpu_mask_set_get_first(set, diff);
  789. if (cpu < 0) {
  790. free_cpumask_var(diff);
  791. dd_dev_err(dd, "Failure to obtain CPU for IRQ\n");
  792. return cpu;
  793. }
  794. free_cpumask_var(diff);
  795. }
  796. cpumask_set_cpu(cpu, &msix->mask);
  797. dd_dev_info(dd, "IRQ: %u, type %s %s -> cpu: %d\n",
  798. msix->irq, irq_type_names[msix->type],
  799. extra, cpu);
  800. irq_set_affinity_hint(msix->irq, &msix->mask);
  801. if (msix->type == IRQ_SDMA) {
  802. sde->cpu = cpu;
  803. hfi1_setup_sdma_notifier(msix);
  804. }
  805. return 0;
  806. }
  807. int hfi1_get_irq_affinity(struct hfi1_devdata *dd, struct hfi1_msix_entry *msix)
  808. {
  809. int ret;
  810. mutex_lock(&node_affinity.lock);
  811. ret = get_irq_affinity(dd, msix);
  812. mutex_unlock(&node_affinity.lock);
  813. return ret;
  814. }
  815. void hfi1_put_irq_affinity(struct hfi1_devdata *dd,
  816. struct hfi1_msix_entry *msix)
  817. {
  818. struct cpu_mask_set *set = NULL;
  819. struct hfi1_ctxtdata *rcd;
  820. struct hfi1_affinity_node *entry;
  821. mutex_lock(&node_affinity.lock);
  822. entry = node_affinity_lookup(dd->node);
  823. switch (msix->type) {
  824. case IRQ_SDMA:
  825. set = &entry->def_intr;
  826. hfi1_cleanup_sdma_notifier(msix);
  827. break;
  828. case IRQ_GENERAL:
  829. /* Don't do accounting for general contexts */
  830. break;
  831. case IRQ_RCVCTXT:
  832. rcd = (struct hfi1_ctxtdata *)msix->arg;
  833. /* Don't do accounting for control contexts */
  834. if (rcd->ctxt != HFI1_CTRL_CTXT)
  835. set = &entry->rcv_intr;
  836. break;
  837. default:
  838. mutex_unlock(&node_affinity.lock);
  839. return;
  840. }
  841. if (set) {
  842. cpumask_andnot(&set->used, &set->used, &msix->mask);
  843. _cpu_mask_set_gen_dec(set);
  844. }
  845. irq_set_affinity_hint(msix->irq, NULL);
  846. cpumask_clear(&msix->mask);
  847. mutex_unlock(&node_affinity.lock);
  848. }
  849. /* This should be called with node_affinity.lock held */
  850. static void find_hw_thread_mask(uint hw_thread_no, cpumask_var_t hw_thread_mask,
  851. struct hfi1_affinity_node_list *affinity)
  852. {
  853. int possible, curr_cpu, i;
  854. uint num_cores_per_socket = node_affinity.num_online_cpus /
  855. affinity->num_core_siblings /
  856. node_affinity.num_online_nodes;
  857. cpumask_copy(hw_thread_mask, &affinity->proc.mask);
  858. if (affinity->num_core_siblings > 0) {
  859. /* Removing other siblings not needed for now */
  860. possible = cpumask_weight(hw_thread_mask);
  861. curr_cpu = cpumask_first(hw_thread_mask);
  862. for (i = 0;
  863. i < num_cores_per_socket * node_affinity.num_online_nodes;
  864. i++)
  865. curr_cpu = cpumask_next(curr_cpu, hw_thread_mask);
  866. for (; i < possible; i++) {
  867. cpumask_clear_cpu(curr_cpu, hw_thread_mask);
  868. curr_cpu = cpumask_next(curr_cpu, hw_thread_mask);
  869. }
  870. /* Identifying correct HW threads within physical cores */
  871. cpumask_shift_left(hw_thread_mask, hw_thread_mask,
  872. num_cores_per_socket *
  873. node_affinity.num_online_nodes *
  874. hw_thread_no);
  875. }
  876. }
  877. int hfi1_get_proc_affinity(int node)
  878. {
  879. int cpu = -1, ret, i;
  880. struct hfi1_affinity_node *entry;
  881. cpumask_var_t diff, hw_thread_mask, available_mask, intrs_mask;
  882. const struct cpumask *node_mask,
  883. *proc_mask = &current->cpus_allowed;
  884. struct hfi1_affinity_node_list *affinity = &node_affinity;
  885. struct cpu_mask_set *set = &affinity->proc;
  886. /*
  887. * check whether process/context affinity has already
  888. * been set
  889. */
  890. if (cpumask_weight(proc_mask) == 1) {
  891. hfi1_cdbg(PROC, "PID %u %s affinity set to CPU %*pbl",
  892. current->pid, current->comm,
  893. cpumask_pr_args(proc_mask));
  894. /*
  895. * Mark the pre-set CPU as used. This is atomic so we don't
  896. * need the lock
  897. */
  898. cpu = cpumask_first(proc_mask);
  899. cpumask_set_cpu(cpu, &set->used);
  900. goto done;
  901. } else if (cpumask_weight(proc_mask) < cpumask_weight(&set->mask)) {
  902. hfi1_cdbg(PROC, "PID %u %s affinity set to CPU set(s) %*pbl",
  903. current->pid, current->comm,
  904. cpumask_pr_args(proc_mask));
  905. goto done;
  906. }
  907. /*
  908. * The process does not have a preset CPU affinity so find one to
  909. * recommend using the following algorithm:
  910. *
  911. * For each user process that is opening a context on HFI Y:
  912. * a) If all cores are filled, reinitialize the bitmask
  913. * b) Fill real cores first, then HT cores (First set of HT
  914. * cores on all physical cores, then second set of HT core,
  915. * and, so on) in the following order:
  916. *
  917. * 1. Same NUMA node as HFI Y and not running an IRQ
  918. * handler
  919. * 2. Same NUMA node as HFI Y and running an IRQ handler
  920. * 3. Different NUMA node to HFI Y and not running an IRQ
  921. * handler
  922. * 4. Different NUMA node to HFI Y and running an IRQ
  923. * handler
  924. * c) Mark core as filled in the bitmask. As user processes are
  925. * done, clear cores from the bitmask.
  926. */
  927. ret = zalloc_cpumask_var(&diff, GFP_KERNEL);
  928. if (!ret)
  929. goto done;
  930. ret = zalloc_cpumask_var(&hw_thread_mask, GFP_KERNEL);
  931. if (!ret)
  932. goto free_diff;
  933. ret = zalloc_cpumask_var(&available_mask, GFP_KERNEL);
  934. if (!ret)
  935. goto free_hw_thread_mask;
  936. ret = zalloc_cpumask_var(&intrs_mask, GFP_KERNEL);
  937. if (!ret)
  938. goto free_available_mask;
  939. mutex_lock(&affinity->lock);
  940. /*
  941. * If we've used all available HW threads, clear the mask and start
  942. * overloading.
  943. */
  944. _cpu_mask_set_gen_inc(set);
  945. /*
  946. * If NUMA node has CPUs used by interrupt handlers, include them in the
  947. * interrupt handler mask.
  948. */
  949. entry = node_affinity_lookup(node);
  950. if (entry) {
  951. cpumask_copy(intrs_mask, (entry->def_intr.gen ?
  952. &entry->def_intr.mask :
  953. &entry->def_intr.used));
  954. cpumask_or(intrs_mask, intrs_mask, (entry->rcv_intr.gen ?
  955. &entry->rcv_intr.mask :
  956. &entry->rcv_intr.used));
  957. cpumask_or(intrs_mask, intrs_mask, &entry->general_intr_mask);
  958. }
  959. hfi1_cdbg(PROC, "CPUs used by interrupts: %*pbl",
  960. cpumask_pr_args(intrs_mask));
  961. cpumask_copy(hw_thread_mask, &set->mask);
  962. /*
  963. * If HT cores are enabled, identify which HW threads within the
  964. * physical cores should be used.
  965. */
  966. if (affinity->num_core_siblings > 0) {
  967. for (i = 0; i < affinity->num_core_siblings; i++) {
  968. find_hw_thread_mask(i, hw_thread_mask, affinity);
  969. /*
  970. * If there's at least one available core for this HW
  971. * thread number, stop looking for a core.
  972. *
  973. * diff will always be not empty at least once in this
  974. * loop as the used mask gets reset when
  975. * (set->mask == set->used) before this loop.
  976. */
  977. cpumask_andnot(diff, hw_thread_mask, &set->used);
  978. if (!cpumask_empty(diff))
  979. break;
  980. }
  981. }
  982. hfi1_cdbg(PROC, "Same available HW thread on all physical CPUs: %*pbl",
  983. cpumask_pr_args(hw_thread_mask));
  984. node_mask = cpumask_of_node(node);
  985. hfi1_cdbg(PROC, "Device on NUMA %u, CPUs %*pbl", node,
  986. cpumask_pr_args(node_mask));
  987. /* Get cpumask of available CPUs on preferred NUMA */
  988. cpumask_and(available_mask, hw_thread_mask, node_mask);
  989. cpumask_andnot(available_mask, available_mask, &set->used);
  990. hfi1_cdbg(PROC, "Available CPUs on NUMA %u: %*pbl", node,
  991. cpumask_pr_args(available_mask));
  992. /*
  993. * At first, we don't want to place processes on the same
  994. * CPUs as interrupt handlers. Then, CPUs running interrupt
  995. * handlers are used.
  996. *
  997. * 1) If diff is not empty, then there are CPUs not running
  998. * non-interrupt handlers available, so diff gets copied
  999. * over to available_mask.
  1000. * 2) If diff is empty, then all CPUs not running interrupt
  1001. * handlers are taken, so available_mask contains all
  1002. * available CPUs running interrupt handlers.
  1003. * 3) If available_mask is empty, then all CPUs on the
  1004. * preferred NUMA node are taken, so other NUMA nodes are
  1005. * used for process assignments using the same method as
  1006. * the preferred NUMA node.
  1007. */
  1008. cpumask_andnot(diff, available_mask, intrs_mask);
  1009. if (!cpumask_empty(diff))
  1010. cpumask_copy(available_mask, diff);
  1011. /* If we don't have CPUs on the preferred node, use other NUMA nodes */
  1012. if (cpumask_empty(available_mask)) {
  1013. cpumask_andnot(available_mask, hw_thread_mask, &set->used);
  1014. /* Excluding preferred NUMA cores */
  1015. cpumask_andnot(available_mask, available_mask, node_mask);
  1016. hfi1_cdbg(PROC,
  1017. "Preferred NUMA node cores are taken, cores available in other NUMA nodes: %*pbl",
  1018. cpumask_pr_args(available_mask));
  1019. /*
  1020. * At first, we don't want to place processes on the same
  1021. * CPUs as interrupt handlers.
  1022. */
  1023. cpumask_andnot(diff, available_mask, intrs_mask);
  1024. if (!cpumask_empty(diff))
  1025. cpumask_copy(available_mask, diff);
  1026. }
  1027. hfi1_cdbg(PROC, "Possible CPUs for process: %*pbl",
  1028. cpumask_pr_args(available_mask));
  1029. cpu = cpumask_first(available_mask);
  1030. if (cpu >= nr_cpu_ids) /* empty */
  1031. cpu = -1;
  1032. else
  1033. cpumask_set_cpu(cpu, &set->used);
  1034. mutex_unlock(&affinity->lock);
  1035. hfi1_cdbg(PROC, "Process assigned to CPU %d", cpu);
  1036. free_cpumask_var(intrs_mask);
  1037. free_available_mask:
  1038. free_cpumask_var(available_mask);
  1039. free_hw_thread_mask:
  1040. free_cpumask_var(hw_thread_mask);
  1041. free_diff:
  1042. free_cpumask_var(diff);
  1043. done:
  1044. return cpu;
  1045. }
  1046. void hfi1_put_proc_affinity(int cpu)
  1047. {
  1048. struct hfi1_affinity_node_list *affinity = &node_affinity;
  1049. struct cpu_mask_set *set = &affinity->proc;
  1050. if (cpu < 0)
  1051. return;
  1052. mutex_lock(&affinity->lock);
  1053. cpu_mask_set_put(set, cpu);
  1054. hfi1_cdbg(PROC, "Returning CPU %d for future process assignment", cpu);
  1055. mutex_unlock(&affinity->lock);
  1056. }