On Fri, Nov 03, 2017 at 02:45:45PM +0000, James Morse wrote:
> Hi Thomas, Peter,
> 
> I'm trying to work out what stops a thread being pre-empted and migrated 
> between
> calling get_online_cpus() and put_online_cpus().
> 
> According to __percpu_down_read(), its the pre-empt count:
> >  * Due to having preemption disabled the decrement happens on
> >  * the same CPU as the increment, avoiding the
> >  * increment-on-one-CPU-and-decrement-on-another problem.
> 
> 
> So this:
> > void cpus_read_lock(void)
> > {
> >        percpu_down_read(&cpu_hotplug_lock);
> > +
> > +       /* Can we migrated before we release this per-cpu lock? */
> > +       WARN_ON(preemptible());
> >  }
> 
> should never fire?

It should.. You're reading a comment on __percpu_down_read() and using
percpu_down_read(), _not_ the same function ;-)

If you look at percpu_down_read(), you'll note it'll disable preemption
before calling __percpu_down_read().

And yes, that whole percpu-rwsem code is fairly magical :-)

Reply via email to