Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/hfi1: Create common functions for affinity CPU mask operations

CPU masks are used to keep track of affinity assignments for IRQs
and processes. Operations performed on these affinity CPU masks are
duplicated throughout the code.

Create common functions for affinity CPU mask operations to remove
duplicate code.

Reviewed-by: Michael J. Ruhl <michael.j.ruhl@intel.com>
Signed-off-by: Sebastian Sanchez <sebastian.sanchez@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>

authored by

Sebastian Sanchez and committed by
Doug Ledford
cf38ea10 af8aab71

+60 -23
+60 -23
drivers/infiniband/hw/hfi1/affinity.c
··· 77 77 set->gen = 0; 78 78 } 79 79 80 + /* Increment generation of CPU set if needed */ 81 + static void _cpu_mask_set_gen_inc(struct cpu_mask_set *set) 82 + { 83 + if (cpumask_equal(&set->mask, &set->used)) { 84 + /* 85 + * We've used up all the CPUs, bump up the generation 86 + * and reset the 'used' map 87 + */ 88 + set->gen++; 89 + cpumask_clear(&set->used); 90 + } 91 + } 92 + 93 + static void _cpu_mask_set_gen_dec(struct cpu_mask_set *set) 94 + { 95 + if (cpumask_empty(&set->used) && set->gen) { 96 + set->gen--; 97 + cpumask_copy(&set->used, &set->mask); 98 + } 99 + } 100 + 101 + /* Get the first CPU from the list of unused CPUs in a CPU set data structure */ 102 + static int cpu_mask_set_get_first(struct cpu_mask_set *set, cpumask_var_t diff) 103 + { 104 + int cpu; 105 + 106 + if (!diff || !set) 107 + return -EINVAL; 108 + 109 + _cpu_mask_set_gen_inc(set); 110 + 111 + /* Find out CPUs left in CPU mask */ 112 + cpumask_andnot(diff, &set->mask, &set->used); 113 + 114 + cpu = cpumask_first(diff); 115 + if (cpu >= nr_cpu_ids) /* empty */ 116 + cpu = -EINVAL; 117 + else 118 + cpumask_set_cpu(cpu, &set->used); 119 + 120 + return cpu; 121 + } 122 + 123 + static void cpu_mask_set_put(struct cpu_mask_set *set, int cpu) 124 + { 125 + if (!set) 126 + return; 127 + 128 + cpumask_clear_cpu(cpu, &set->used); 129 + _cpu_mask_set_gen_dec(set); 130 + } 131 + 80 132 /* Initialize non-HT cpu cores mask */ 81 133 void init_real_cpu_mask(void) 82 134 { ··· 508 456 if (!zalloc_cpumask_var(&diff, GFP_KERNEL)) 509 457 return -ENOMEM; 510 458 511 - if (cpumask_equal(&set->mask, &set->used)) { 512 - /* 513 - * We've used up all the CPUs, bump up the generation 514 - * and reset the 'used' map 515 - */ 516 - set->gen++; 517 - cpumask_clear(&set->used); 459 + cpu = cpu_mask_set_get_first(set, diff); 460 + if (cpu < 0) { 461 + free_cpumask_var(diff); 462 + dd_dev_err(dd, "Failure to obtain CPU for IRQ\n"); 463 + return cpu; 518 464 } 519 - cpumask_andnot(diff, &set->mask, &set->used); 520 - cpu = cpumask_first(diff); 521 - cpumask_set_cpu(cpu, &set->used); 522 465 523 466 free_cpumask_var(diff); 524 467 } ··· 573 526 574 527 if (set) { 575 528 cpumask_andnot(&set->used, &set->used, &msix->mask); 576 - if (cpumask_empty(&set->used) && set->gen) { 577 - set->gen--; 578 - cpumask_copy(&set->used, &set->mask); 579 - } 529 + _cpu_mask_set_gen_dec(set); 580 530 } 581 531 582 532 irq_set_affinity_hint(msix->irq, NULL); ··· 684 640 * If we've used all available HW threads, clear the mask and start 685 641 * overloading. 686 642 */ 687 - if (cpumask_equal(&set->mask, &set->used)) { 688 - set->gen++; 689 - cpumask_clear(&set->used); 690 - } 643 + _cpu_mask_set_gen_inc(set); 691 644 692 645 /* 693 646 * If NUMA node has CPUs used by interrupt handlers, include them in the ··· 808 767 return; 809 768 810 769 mutex_lock(&affinity->lock); 811 - cpumask_clear_cpu(cpu, &set->used); 770 + cpu_mask_set_put(set, cpu); 812 771 hfi1_cdbg(PROC, "Returning CPU %d for future process assignment", cpu); 813 - if (cpumask_empty(&set->used) && set->gen) { 814 - set->gen--; 815 - cpumask_copy(&set->used, &set->mask); 816 - } 817 772 mutex_unlock(&affinity->lock); 818 773 }