lkml.org 
[lkml]   [2010]   [May]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 1/4] cpu_stop: implement stop_cpu[s]()
From
Date
On Thu, 2010-04-22 at 18:09 +0200, Tejun Heo wrote:

> +struct cpu_stop_done {
> + atomic_t nr_todo; /* nr left to execute */
> + bool executed; /* actually executed? */
> + int ret; /* collected return value */
> + struct completion completion; /* fired if nr_todo reaches 0 */
> +};
> +

> +/* signal completion unless @done is NULL */
> +static void cpu_stop_signal_done(struct cpu_stop_done *done, bool executed)
> +{
> + if (done) {
> + if (executed)
> + done->executed = true;
> + if (atomic_dec_and_test(&done->nr_todo))
> + complete(&done->completion);
> + }
> +}
> +
> +/* queue @work to @stopper. if offline, @work is completed immediately */
> +static void cpu_stop_queue_work(struct cpu_stopper *stopper,
> + struct cpu_stop_work *work)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&stopper->lock, flags);
> +
> + if (stopper->enabled) {
> + list_add_tail(&work->list, &stopper->works);
> + wake_up_process(stopper->thread);
> + } else
> + cpu_stop_signal_done(work->done, false);
> +
> + spin_unlock_irqrestore(&stopper->lock, flags);
> +}
> +

> +int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
> +{
> + struct cpu_stop_done done;
> + struct cpu_stop_work work = { .fn = fn, .arg = arg, .done = &done };
> +
> + cpu_stop_init_done(&done, 1);
> + cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), &work);
> + wait_for_completion(&done.completion);
> + return done.executed ? done.ret : -ENOENT;
> +}

If you do:

done = { .ret = -ENOENT, };
And remove that if()
> + ret = work->fn(work->arg);
> + if (ret)
> + done->ret = ret;
> +

You can do away with all the ->executed bits.


\
 
 \ /
  Last update: 2010-05-03 15:29    [from the cache]
©2003-2011 Jasper Spaans