On Tue, 24 Sep 2013 14:38:21 +0200
Peter Zijlstra <[email protected]> wrote:

> +#define cpuhp_writer_wait(cond)                                              
> \
> +do {                                                                 \
> +     for (;;) {                                                      \
> +             set_current_state(TASK_UNINTERRUPTIBLE);                \
> +             if (cond)                                               \
> +                     break;                                          \
> +             schedule();                                             \
> +     }                                                               \
> +     __set_current_state(TASK_RUNNING);                              \
> +} while (0)
> +
> +void __get_online_cpus(void)

The above really needs a comment about how it is used. Otherwise, I can
envision someone calling this as "oh I can use this when I'm in a
preempt disable section", and the comment below for the
preempt_enable_no_resched() will no longer be true.

-- Steve


>  {
> -     if (cpu_hotplug.active_writer == current)
> +     if (cpuhp_writer_task == current)
>               return;
> -     mutex_lock(&cpu_hotplug.lock);
>  
> -     if (WARN_ON(!cpu_hotplug.refcount))
> -             cpu_hotplug.refcount++; /* try to fix things up */
> +     atomic_inc(&cpuhp_waitcount);
> +
> +     /*
> +      * We either call schedule() in the wait, or we'll fall through
> +      * and reschedule on the preempt_enable() in get_online_cpus().
> +      */
> +     preempt_enable_no_resched();
> +     wait_event(cpuhp_wq, !__cpuhp_writer);
> +     preempt_disable();
> +
> +     /*
> +      * It would be possible for cpu_hotplug_done() to complete before
> +      * the atomic_inc() above; in which case there is no writer waiting
> +      * and doing a wakeup would be BAD (tm).
> +      *
> +      * If however we still observe cpuhp_writer_task here we know
> +      * cpu_hotplug_done() is currently stuck waiting for cpuhp_waitcount.
> +      */
> +     if (atomic_dec_and_test(&cpuhp_waitcount) && cpuhp_writer_task)
> +             cpuhp_writer_wake();
> +}
> +EXPORT_SYMBOL_GPL(__get_online_cpus);
>  
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to