Skip to content

Commit 7d49b28

Browse files
rikvanrielPeter Zijlstra
authored andcommitted
smp,cpumask: introduce on_each_cpu_cond_mask
Introduce a variant of on_each_cpu_cond that iterates only over the CPUs in a cpumask, in order to avoid making callbacks for every single CPU in the system when we only need to test a subset. Cc: npiggin@gmail.com Cc: mingo@kernel.org Cc: will.deacon@arm.com Cc: songliubraving@fb.com Cc: kernel-team@fb.com Cc: hpa@zytor.com Cc: luto@kernel.org Signed-off-by: Rik van Riel <riel@surriel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180926035844.1420-5-riel@surriel.com
1 parent c3f7f2c commit 7d49b28

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎include/linux/smp.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
5353
smp_call_func_t func, void *info, bool wait,
5454
gfp_t gfp_flags);
5555

56+
void on_each_cpu_cond_mask(bool (*cond_func)(int cpu, void *info),
57+
smp_call_func_t func, void *info, bool wait,
58+
gfp_t gfp_flags, const struct cpumask *mask);
59+
5660
int smp_call_function_single_async(int cpu, call_single_data_t *csd);
5761

5862
#ifdef CONFIG_SMP

‎kernel/smp.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,9 @@ EXPORT_SYMBOL(on_each_cpu_mask);
669669
* You must not call this function with disabled interrupts or
670670
* from a hardware interrupt handler or from a bottom half handler.
671671
*/
672-
void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
672+
void on_each_cpu_cond_mask(bool (*cond_func)(int cpu, void *info),
673673
smp_call_func_t func, void *info, bool wait,
674-
gfp_t gfp_flags)
674+
gfp_t gfp_flags, const struct cpumask *mask)
675675
{
676676
cpumask_var_t cpus;
677677
int cpu, ret;
@@ -680,7 +680,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
680680

681681
if (likely(zalloc_cpumask_var(&cpus, (gfp_flags|__GFP_NOWARN)))) {
682682
preempt_disable();
683-
for_each_online_cpu(cpu)
683+
for_each_cpu(cpu, mask)
684684
if (cond_func(cpu, info))
685685
__cpumask_set_cpu(cpu, cpus);
686686
on_each_cpu_mask(cpus, func, info, wait);
@@ -692,7 +692,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
692692
* just have to IPI them one by one.
693693
*/
694694
preempt_disable();
695-
for_each_online_cpu(cpu)
695+
for_each_cpu(cpu, mask)
696696
if (cond_func(cpu, info)) {
697697
ret = smp_call_function_single(cpu, func,
698698
info, wait);
@@ -701,6 +701,15 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
701701
preempt_enable();
702702
}
703703
}
704+
EXPORT_SYMBOL(on_each_cpu_cond_mask);
705+
706+
void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
707+
smp_call_func_t func, void *info, bool wait,
708+
gfp_t gfp_flags)
709+
{
710+
on_each_cpu_cond_mask(cond_func, func, info, wait, gfp_flags,
711+
cpu_online_mask);
712+
}
704713
EXPORT_SYMBOL(on_each_cpu_cond);
705714

706715
static void do_nothing(void *unused)

‎kernel/up.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ EXPORT_SYMBOL(on_each_cpu_mask);
6868
* Preemption is disabled here to make sure the cond_func is called under the
6969
* same condtions in UP and SMP.
7070
*/
71-
void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
72-
smp_call_func_t func, void *info, bool wait,
73-
gfp_t gfp_flags)
71+
void on_each_cpu_cond_mask(bool (*cond_func)(int cpu, void *info),
72+
smp_call_func_t func, void *info, bool wait,
73+
gfp_t gfp_flags, const struct cpumask *mask)
7474
{
7575
unsigned long flags;
7676

@@ -82,6 +82,14 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
8282
}
8383
preempt_enable();
8484
}
85+
EXPORT_SYMBOL(on_each_cpu_cond_mask);
86+
87+
void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
88+
smp_call_func_t func, void *info, bool wait,
89+
gfp_t gfp_flags)
90+
{
91+
on_each_cpu_cond_mask(cond_func, func, info, wait, gfp_flags, NULL);
92+
}
8593
EXPORT_SYMBOL(on_each_cpu_cond);
8694

8795
int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys)

0 commit comments

Comments
 (0)