Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 142885
b: refs/heads/master
c: 6b44003
h: refs/heads/master
i:
  142883: ac1b6a7
v: v3
  • Loading branch information
Andrew Morton authored and Rusty Russell committed Apr 9, 2009
1 parent 999868b commit 6fe29f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1c99315bb36b5d776210546d438ca928dc9b1f22
refs/heads/master: 6b44003e5ca66a3fffeb5bc90f40ada2c4340896
36 changes: 19 additions & 17 deletions trunk/kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,20 +966,20 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb,
}

#ifdef CONFIG_SMP
static struct workqueue_struct *work_on_cpu_wq __read_mostly;

struct work_for_cpu {
struct work_struct work;
struct completion completion;
long (*fn)(void *);
void *arg;
long ret;
};

static void do_work_for_cpu(struct work_struct *w)
static int do_work_for_cpu(void *_wfc)
{
struct work_for_cpu *wfc = container_of(w, struct work_for_cpu, work);

struct work_for_cpu *wfc = _wfc;
wfc->ret = wfc->fn(wfc->arg);
complete(&wfc->completion);
return 0;
}

/**
Expand All @@ -990,17 +990,23 @@ static void do_work_for_cpu(struct work_struct *w)
*
* This will return the value @fn returns.
* It is up to the caller to ensure that the cpu doesn't go offline.
* The caller must not hold any locks which would prevent @fn from completing.
*/
long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg)
{
struct work_for_cpu wfc;

INIT_WORK(&wfc.work, do_work_for_cpu);
wfc.fn = fn;
wfc.arg = arg;
queue_work_on(cpu, work_on_cpu_wq, &wfc.work);
flush_work(&wfc.work);

struct task_struct *sub_thread;
struct work_for_cpu wfc = {
.completion = COMPLETION_INITIALIZER_ONSTACK(wfc.completion),
.fn = fn,
.arg = arg,
};

sub_thread = kthread_create(do_work_for_cpu, &wfc, "work_for_cpu");
if (IS_ERR(sub_thread))
return PTR_ERR(sub_thread);
kthread_bind(sub_thread, cpu);
wake_up_process(sub_thread);
wait_for_completion(&wfc.completion);
return wfc.ret;
}
EXPORT_SYMBOL_GPL(work_on_cpu);
Expand All @@ -1016,8 +1022,4 @@ void __init init_workqueues(void)
hotcpu_notifier(workqueue_cpu_callback, 0);
keventd_wq = create_workqueue("events");
BUG_ON(!keventd_wq);
#ifdef CONFIG_SMP
work_on_cpu_wq = create_workqueue("work_on_cpu");
BUG_ON(!work_on_cpu_wq);
#endif
}

0 comments on commit 6fe29f2

Please sign in to comment.