Re: [PATCH 1/4] cpu_stop: implement stop_cpu[s]()

From: Peter Zijlstra
Date: Mon May 03 2010 - 09:27:57 EST


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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/