aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2017-04-12 16:07:28 -0400
committerThomas Gleixner <tglx@linutronix.de>2017-04-15 06:20:53 -0400
commit0e8d6a9336b487a1dd6f1991ff376e669d4c87c6 (patch)
tree11bf45da14998976aeb13623f52673b64af35177 /kernel/workqueue.c
parent048c9b954e20396e0c45ee778466994d1be2e612 (diff)
workqueue: Provide work_on_cpu_safe()
work_on_cpu() is not protected against CPU hotplug. For code which requires to be either executed on an online CPU or to fail if the CPU is not available the callsite would have to protect against CPU hotplug. Provide a function which does get/put_online_cpus() around the call to work_on_cpu() and fails the call with -ENODEV if the target CPU is not online. Preparatory patch to convert several racy task affinity manipulations. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Tejun Heo <tj@kernel.org> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Sebastian Siewior <bigeasy@linutronix.de> Cc: Lai Jiangshan <jiangshanlai@gmail.com> Cc: Viresh Kumar <viresh.kumar@linaro.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: "David S. Miller" <davem@davemloft.net> Cc: Len Brown <lenb@kernel.org> Link: http://lkml.kernel.org/r/20170412201042.262610721@linutronix.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index c0168b7da1ea..5bf1be018628 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4735,6 +4735,29 @@ long work_on_cpu(int cpu, long (*fn)(void *), void *arg)
4735 return wfc.ret; 4735 return wfc.ret;
4736} 4736}
4737EXPORT_SYMBOL_GPL(work_on_cpu); 4737EXPORT_SYMBOL_GPL(work_on_cpu);
4738
4739/**
4740 * work_on_cpu_safe - run a function in thread context on a particular cpu
4741 * @cpu: the cpu to run on
4742 * @fn: the function to run
4743 * @arg: the function argument
4744 *
4745 * Disables CPU hotplug and calls work_on_cpu(). The caller must not hold
4746 * any locks which would prevent @fn from completing.
4747 *
4748 * Return: The value @fn returns.
4749 */
4750long work_on_cpu_safe(int cpu, long (*fn)(void *), void *arg)
4751{
4752 long ret = -ENODEV;
4753
4754 get_online_cpus();
4755 if (cpu_online(cpu))
4756 ret = work_on_cpu(cpu, fn, arg);
4757 put_online_cpus();
4758 return ret;
4759}
4760EXPORT_SYMBOL_GPL(work_on_cpu_safe);
4738#endif /* CONFIG_SMP */ 4761#endif /* CONFIG_SMP */
4739 4762
4740#ifdef CONFIG_FREEZER 4763#ifdef CONFIG_FREEZER