Re: [PATCH 2/8] Add interface for queuing work on a specific CPU

Oleg Nesterov
2008-02-11T10:52:31Z

Sorry for delay,

On 02/07, Andrew Morton wrote:
>
> On Thu, 7 Feb 2008 10:18:59 +0100 Jens Axboe <jens.axboe@oracle.com> wrote:
>
> > --- a/kernel/workqueue.c
> > +++ b/kernel/workqueue.c
> > @@ -175,6 +175,21 @@ int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
> > }
> > EXPORT_SYMBOL_GPL(queue_work);
> >
> > +int fastcall queue_work_on_cpu(struct workqueue_struct *wq,
> > + struct work_struct *work, int cpu)
> > +{
> > + int ret = 0;
> > +
> > + if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
> > + BUG_ON(!list_empty(&work->entry));
> > + __queue_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
> > + ret = 1;
> > + }
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(queue_work_on_cpu);
>
> Might as well change queue_work() to call this?

This is possible, but in that case queue_work_on_cpu() should use wq_per_cpu(),
not per_cpu_ptr(). (otherwise queue_work(single_threaded_wq) won't work).

A bit off-topic, the comment near queue_work() says

* We queue the work to the CPU it was submitted, but there is no
* guarantee that it will be processed by that CPU.

This is wrong. Unless cpu_down() happens, we do guarantee it will be processed
by that CPU. Perhaps it makes sense to fix the comment as well?

Oleg.