smp: simplify smp_call_function_any()
PATCH 1/1 smp: simplify smp_call_function_any()
The functions calls get_cpu()/put_cpu() meaningless because the actual CPU that would execute the caller's function is not necessarily the current one.
The smp_call_function_single() which is called by smp_call_function_any() does the right get/put protection.
--- kernel/smp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
kernel/smp.c +2 -6
@@ -754,17 +754,13 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async);int smp_call_function_any (const struct cpumask *mask,smp_call_func_t func,void *info,int wait) { -unsigned int cpu; -int ret; +unsigned int cpu =smp_processor_id ();/* Try for same CPU (cheapest) */ - cpu =get_cpu ();if (!cpumask_test_cpu (cpu, mask)) cpu =sched_numa_find_nth_cpu (mask,0 ,cpu_to_node (cpu)); - ret =smp_call_function_single (cpu, func, info, wait); -put_cpu (); -return ret; +return smp_call_function_single (cpu, func, info, wait); }EXPORT_SYMBOL_GPL (smp_call_function_any);
Signature · 1 line
2.43.0
Quoted 17 lines · Yury Norov (NVIDIA)
The functions calls get_cpu()/put_cpu() meaningless because the actual CPU that would execute the caller's function is not necessarily the current one.
The
smp_call_function_single()which is called bysmp_call_function_any()does the right get/put protection.Signed-off-by Yury Norov (NVIDIA) <[email protected]>--- kernel/smp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)kernel/smp.c +0
-0
kernel/smp.c EXPORT_SYMBOL_GPL(smp_call_function_single_async); · line 757
Quoted 6 lines
kernel/smp.c +1
-2@@ -754,17 +754,13 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async);int smp_call_function_any (const struct cpumask *mask,smp_call_func_t func,void *info,int wait) { -unsigned int cpu; -int ret; +unsigned int cpu =smp_processor_id ();
I wonder whether this passes any moderate testing with kernel debug options enabled. I would at the very least expect a raw_smp_processor_id() call here not to trip debug warnings.
AFAIU smp_call_function_any call be called from preemptible context, right ?
Thanks,
Mathieu
Quoted 13 lines
kernel/smp.c +1
-4/* Try for same CPU (cheapest) */ - cpu =get_cpu ();if (!cpumask_test_cpu (cpu, mask)) cpu =sched_numa_find_nth_cpu (mask,0 ,cpu_to_node (cpu)); - ret =smp_call_function_single (cpu, func, info, wait); -put_cpu (); -return ret; +return smp_call_function_single (cpu, func, info, wait); }EXPORT_SYMBOL_GPL (smp_call_function_any);
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Quoted 29 lines · Mathieu Desnoyers
Quoted 17 lines · Yury Norov (NVIDIA)
The functions calls get_cpu()/put_cpu() meaningless because the actual CPU that would execute the caller's function is not necessarily the current one.
The
smp_call_function_single()which is called bysmp_call_function_any()does the right get/put protection.Signed-off-by Yury Norov (NVIDIA) <[email protected]>--- kernel/smp.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)kernel/smp.c +0
-0kernel/smp.c EXPORT_SYMBOL_GPL(smp_call_function_single_async); · line 757
Quoted 6 lines
kernel/smp.c +1
-2@@ -754,17 +754,13 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async);int smp_call_function_any (const struct cpumask *mask,smp_call_func_t func,void *info,int wait) { -unsigned int cpu; -int ret; +unsigned int cpu =smp_processor_id ();I wonder whether this passes any moderate testing with kernel debug options enabled. I would at the very least expect a
raw_smp_processor_id()call here not to trip debug warnings.
Quoted 2 lines
AFAIU
smp_call_function_anycall be called from preemptible context, right ?
You're right, we need to retain current CPU unless the work is scheduled. I need to test better. Sorry for the noise.