Re: [PATCH] cpuhotplug: introduce try_get_online_cpus() take 2

From: Oleg Nesterov
Date: Thu Jun 04 2009 - 22:19:28 EST


On 06/05, Lai Jiangshan wrote:
>
> Oleg Nesterov wrote:
> > On 06/04, Lai Jiangshan wrote:
> >>
> >> + if (unlikely(!atomic_inc_not_zero(&cpu_hotplug.refcount))) {
> >> + DEFINE_WAIT(wait);
> >> +
> >> + for (;;) {
> >> + prepare_to_wait(&cpu_hotplug.sleeping_readers, &wait,
> >> + TASK_UNINTERRUPTIBLE);
> >> + if (atomic_inc_not_zero(&cpu_hotplug.refcount))
> >> + break;
> >> + schedule();
> >> + }
> >> +
> >> + finish_wait(&cpu_hotplug.sleeping_readers, &wait);
> >> + }
> >> }
> >
> > Looks like the code above can be replaced with
> >
> > wait_event(atomic_inc_not_zero(&cpu_hotplug.refcount));
>
> You are right, but with the atomic_inc_not_zero() has side-effect,
> I'm afraid that wait_event() will be changed in future, and it may
> increases the cpu_hotplug.refcount twice.

We already have side-effects in wait_event(), see use_module().
And wait_event(atomic_inc_not_zero()) is much easier to understand.

Personally, I think wait_event() must work correctly if "condition"
has side-effects.

But this is subjective. So, of course, please do what you like more.

> > Hmm. It seems to me that cpu_hotplug_done() needs mb__before_atomic_inc()
> > before atomic_inc. Otherwise, "active_writer = NULL" can be re-ordered with
> > atomic_inc(). If the new reader does get_online_cpus() + put_online_cpus()
> > quicky, it can see active_writer != NULL.
> >
>
> The lines "active_writer = NULL" and "atomic_inc()" can exchange,
> there is no code need to synchronize to them.
> get_online_cpus()/put_online_cpus() will see "active_writer != current",
> it just what get_online_cpus()/put_online_cpus() needs.

I meant another problem, but I misread the patch. When I actually applied
it I don't see any problems with re-ordering.

This means I should find something else ;) put_online_cpus() does not
need smp_mb__after_atomic_dec(). atomic_dec_and_test() implies mb() on
both sides, this is even documented.

Oleg.

--
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/