cpumask: introduce new API, without changing anything, v3

Impact: cleanup

Clean up based on feedback from Andrew Morton and others:

- change to inline functions instead of macros
- add __init to bootmem method
- add a missing debug check

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by Rusty Russell and committed by Ingo Molnar 984f2f37 cd83e42c

+54 -7
+52 -6
include/linux/cpumask.h
··· 564 564 } 565 565 566 566 #if NR_CPUS == 1 567 - /* Uniprocesor. */ 568 - #define cpumask_first(src) ({ (void)(src); 0; }) 569 - #define cpumask_next(n, src) ({ (void)(src); 1; }) 570 - #define cpumask_next_zero(n, src) ({ (void)(src); 1; }) 571 - #define cpumask_next_and(n, srcp, andp) ({ (void)(srcp), (void)(andp); 1; }) 572 - #define cpumask_any_but(mask, cpu) ({ (void)(mask); (void)(cpu); 0; }) 567 + /* Uniprocessor. Assume all masks are "1". */ 568 + static inline unsigned int cpumask_first(const struct cpumask *srcp) 569 + { 570 + return 0; 571 + } 572 + 573 + /* Valid inputs for n are -1 and 0. */ 574 + static inline unsigned int cpumask_next(int n, const struct cpumask *srcp) 575 + { 576 + return n+1; 577 + } 578 + 579 + static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp) 580 + { 581 + return n+1; 582 + } 583 + 584 + static inline unsigned int cpumask_next_and(int n, 585 + const struct cpumask *srcp, 586 + const struct cpumask *andp) 587 + { 588 + return n+1; 589 + } 590 + 591 + /* cpu must be a valid cpu, ie 0, so there's no other choice. */ 592 + static inline unsigned int cpumask_any_but(const struct cpumask *mask, 593 + unsigned int cpu) 594 + { 595 + return 1; 596 + } 573 597 574 598 #define for_each_cpu(cpu, mask) \ 575 599 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) ··· 644 620 int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *); 645 621 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu); 646 622 623 + /** 624 + * for_each_cpu - iterate over every cpu in a mask 625 + * @cpu: the (optionally unsigned) integer iterator 626 + * @mask: the cpumask pointer 627 + * 628 + * After the loop, cpu is >= nr_cpu_ids. 629 + */ 647 630 #define for_each_cpu(cpu, mask) \ 648 631 for ((cpu) = -1; \ 649 632 (cpu) = cpumask_next((cpu), (mask)), \ 650 633 (cpu) < nr_cpu_ids;) 634 + 635 + /** 636 + * for_each_cpu_and - iterate over every cpu in both masks 637 + * @cpu: the (optionally unsigned) integer iterator 638 + * @mask: the first cpumask pointer 639 + * @and: the second cpumask pointer 640 + * 641 + * This saves a temporary CPU mask in many places. It is equivalent to: 642 + * struct cpumask tmp; 643 + * cpumask_and(&tmp, &mask, &and); 644 + * for_each_cpu(cpu, &tmp) 645 + * ... 646 + * 647 + * After the loop, cpu is >= nr_cpu_ids. 648 + */ 651 649 #define for_each_cpu_and(cpu, mask, and) \ 652 650 for ((cpu) = -1; \ 653 651 (cpu) = cpumask_next_and((cpu), (mask), (and)), \
+2 -1
lib/cpumask.c
··· 67 67 { 68 68 unsigned int i; 69 69 70 + cpumask_check(cpu); 70 71 for_each_cpu(i, mask) 71 72 if (i != cpu) 72 73 break; ··· 109 108 } 110 109 EXPORT_SYMBOL(free_cpumask_var); 111 110 112 - void free_bootmem_cpumask_var(cpumask_var_t mask) 111 + void __init free_bootmem_cpumask_var(cpumask_var_t mask) 113 112 { 114 113 free_bootmem((unsigned long)mask, cpumask_size()); 115 114 }