[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180619133844.GB17720@e108498-lin.cambridge.arm.com>
Date: Tue, 19 Jun 2018 14:38:45 +0100
From: Quentin Perret <quentin.perret@....com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: rjw@...ysocki.net, gregkh@...uxfoundation.org,
linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
mingo@...hat.com, dietmar.eggemann@....com,
morten.rasmussen@....com, chris.redpath@....com,
patrick.bellasi@....com, valentin.schneider@....com,
vincent.guittot@...aro.org, thara.gopinath@...aro.org,
viresh.kumar@...aro.org, tkjos@...gle.com, joelaf@...gle.com,
smuckle@...gle.com, adharmap@...cinc.com, skannan@...cinc.com,
pkondeti@...eaurora.org, juri.lelli@...hat.com,
edubezval@...il.com, srinivas.pandruvada@...ux.intel.com,
currojerez@...eup.net, javi.merino@...nel.org
Subject: Re: [RFC PATCH v3 03/10] PM: Introduce an Energy Model management
framework
On Tuesday 19 Jun 2018 at 15:23:38 (+0200), Peter Zijlstra wrote:
> On Tue, Jun 19, 2018 at 01:58:58PM +0100, Quentin Perret wrote:
> > On Tuesday 19 Jun 2018 at 13:34:08 (+0200), Peter Zijlstra wrote:
> > > On Mon, May 21, 2018 at 03:24:58PM +0100, Quentin Perret wrote:
> > > > +struct em_freq_domain *em_cpu_get(int cpu)
> > > > +{
> > > > + struct em_freq_domain *fd;
> > > > + unsigned long flags;
> > > > +
> > > > + read_lock_irqsave(&em_data_lock, flags);
> > > > + fd = per_cpu(em_data, cpu);
> > > > + read_unlock_irqrestore(&em_data_lock, flags);
> > >
> > > Why can't this use RCU? This is the exact thing read_locks are terrible
> > > at and RCU excells at.
> >
> > So the idea was that clients (the scheduler for ex) can get a reference
> > to a frequency domain object once, and they're guaranteed it always
> > exists without asking for it again.
> >
> > For example, my proposal was to have the scheduler (patch 05) build its
> > own private list of frequency domains on which it can iterate efficiently
> > in the wake-up path. If we protect this per_cpu variable with RCU, then
> > this isn't possible any-more. The scheduler will have to re-ask
> > em_cpu_get() at every wake-up, and that makes iterating over frequency
> > domains a whole lot more complex.
> >
> > Does that make any sense ?
>
> None what so ever... The lock doesn't guarantee stability any more than
> RCU does.
>
> If you hand out the pointer and then drop the read-lock, the write-lock
> can proceed and change the pointer right after you.
>
> The very easiest solution is to never change the data, as I think was
> suggested elsewhere in the thread. Construct the thing once and then
> never mutate.
This is what is done actually. We will never write twice in the per_cpu
array itself. One of the fields (the table) in the structure pointed from
the per_cpu array can change, but not the pointer on the structure
itself.
The only reason this lock is here is to ensure the atomicity of the
write happening in em_register_freq_domain. But that write can happen
only once, the first time the frequency domain is registered.
But maybe I could use something simpler than a lock in this case ?
Would WRITE_ONCE/READ_ONCE be enough to ensure that atomicity for
example ?
Thanks,
Quentin
Powered by blists - more mailing lists