aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorTejun Heo2012-09-18 14:48:43 -0500
committerGreg Kroah-Hartman2012-10-02 11:47:22 -0500
commit3d45db6b5158a7f09f8be651577416ef6a4dcbd4 (patch)
tree04082fd9bf0d0a955752cc485a0d7f2b48464ff6 /kernel
parent896b6af471f67fc60cbab5a503cb8a764a8c47a4 (diff)
downloadkernel-common-3d45db6b5158a7f09f8be651577416ef6a4dcbd4.tar.gz
kernel-common-3d45db6b5158a7f09f8be651577416ef6a4dcbd4.tar.xz
kernel-common-3d45db6b5158a7f09f8be651577416ef6a4dcbd4.zip
workqueue: reimplement work_on_cpu() using system_wq
commit ed48ece27cd3d5ee0354c32bbaec0f3e1d4715c3 upstream. The existing work_on_cpu() implementation is hugely inefficient. It creates a new kthread, execute that single function and then let the kthread die on each invocation. Now that system_wq can handle concurrent executions, there's no advantage of doing this. Reimplement work_on_cpu() using system_wq which makes it simpler and way more efficient. stable: While this isn't a fix in itself, it's needed to fix a workqueue related bug in cpufreq/powernow-k8. AFAICS, this shouldn't break other existing users. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Jiri Kosina <jkosina@suse.cz> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Len Brown <lenb@kernel.org> Cc: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/workqueue.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index e88c924fc6b..ebd96393ae5 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3599,18 +3599,17 @@ static int __devinit workqueue_cpu_down_callback(struct notifier_block *nfb,
3599#ifdef CONFIG_SMP 3599#ifdef CONFIG_SMP
3600 3600
3601struct work_for_cpu { 3601struct work_for_cpu {
3602 struct completion completion; 3602 struct work_struct work;
3603 long (*fn)(void *); 3603 long (*fn)(void *);
3604 void *arg; 3604 void *arg;
3605 long ret; 3605 long ret;
3606}; 3606};
3607 3607
3608static int do_work_for_cpu(void *_wfc) 3608static void work_for_cpu_fn(struct work_struct *work)
3609{ 3609{
3610 struct work_for_cpu *wfc = _wfc; 3610 struct work_for_cpu *wfc = container_of(work, struct work_for_cpu, work);
3611
3611 wfc->ret = wfc->fn(wfc->arg); 3612 wfc->ret = wfc->fn(wfc->arg);
3612 complete(&wfc->completion);
3613 return 0;
3614} 3613}
3615 3614
3616/** 3615/**
@@ -3625,19 +3624,11 @@ static int do_work_for_cpu(void *_wfc)
3625 */ 3624 */
3626long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) 3625long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg)
3627{ 3626{
3628 struct task_struct *sub_thread; 3627 struct work_for_cpu wfc = { .fn = fn, .arg = arg };
3629 struct work_for_cpu wfc = {
3630 .completion = COMPLETION_INITIALIZER_ONSTACK(wfc.completion),
3631 .fn = fn,
3632 .arg = arg,
3633 };
3634 3628
3635 sub_thread = kthread_create(do_work_for_cpu, &wfc, "work_for_cpu"); 3629 INIT_WORK_ONSTACK(&wfc.work, work_for_cpu_fn);
3636 if (IS_ERR(sub_thread)) 3630 schedule_work_on(cpu, &wfc.work);
3637 return PTR_ERR(sub_thread); 3631 flush_work(&wfc.work);
3638 kthread_bind(sub_thread, cpu);
3639 wake_up_process(sub_thread);
3640 wait_for_completion(&wfc.completion);
3641 return wfc.ret; 3632 return wfc.ret;
3642} 3633}
3643EXPORT_SYMBOL_GPL(work_on_cpu); 3634EXPORT_SYMBOL_GPL(work_on_cpu);