From: "Jon Medhurst (Tixy)" <tixy@linaro.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>,
Lists linaro-kernel <linaro-kernel@lists.linaro.org>,
Patch Tracking <patches@linaro.org>,
"cpufreq@vger.kernel.org" <cpufreq@vger.kernel.org>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
Subject: Re: [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu
Date: Mon, 16 Sep 2013 19:42:10 +0100 [thread overview]
Message-ID: <1379356930.3422.71.camel@linaro1.home> (raw)
In-Reply-To: <CAKohpomEQsS-WHQpa=_07NQ1FXDB711inrmMgUguD529BA7g1A@mail.gmail.com>
On Mon, 2013-09-16 at 22:38 +0530, Viresh Kumar wrote:
> On 16 September 2013 21:57, Jon Medhurst (Tixy) <tixy@linaro.org> wrote:
> > If I take mainline code and just change the line above to:
>
> You meant this line by above line?
>
> unlock_policy_rwsem_write(cpu);
Yes.
> > up_write(&per_cpu(cpu_policy_rwsem, (per_cpu(cpufreq_cpu_data,
> > cpu))->last_cpu));
> > then the big_little cpufreq driver works for me.
>
> That would be same as: up_write(&per_cpu(cpu_policy_rwsem, policy->last_cpu));
Yes. (I had cut'n'pasted from the unlock_policy_rwsem_ macro)
> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> >> index 43c24aa..c18bf7b 100644
> >> --- a/drivers/cpufreq/cpufreq.c
> >> +++ b/drivers/cpufreq/cpufreq.c
> >> @@ -952,9 +952,16 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
> >> if (cpu == policy->cpu)
> >> return;
> >>
> >> + /* take direct locks as lock_policy_rwsem_write wouldn't work here */
> >> + down_write(&per_cpu(cpu_policy_rwsem, policy->cpu));
> >> + down_write(&per_cpu(cpu_policy_rwsem, cpu));
> >> +
> >> policy->last_cpu = policy->cpu;
> >> policy->cpu = cpu;
> >>
> >> + up_write(&per_cpu(cpu_policy_rwsem, cpu));
> >> + up_write(&per_cpu(cpu_policy_rwsem, policy->cpu));
> >
> > You've just overwritten policy->cpu with cpu.
>
> Stupid enough :)
>
> > I tried using
> > policy->last_cpu to fix that, but it still doesn't work for me (giving
> > the lockdep warning I mentioned.) If I change the code to just lock the
> > original policy->cpu lock only, then all is fine.
>
> Fixed my patch now.. find attached..
The commit log to that patch still mentions taking both locks.
The code itself fixes the lockdep errors I had, so
Tested-by: Jon Medhurst <tixy@linaro.org>
however, I still have concerns about the locking (below)...
> It mentions why lock for last cpu is
> enough here. Copied that here too..
>
> + /*
> + * Take direct locks as lock_policy_rwsem_write wouldn't work here.
> + * Also lock for last cpu is enough here as contention will happen only
> + * after policy->cpu is changed and after it is changed, other threads
> + * will try to acquire lock for new cpu. And policy is already updated
> + * by then.
> + */
>
> > Also, this locking is now just happening around policy->cpu update,
> > whereas before this change, it was locked for the whole of
> > update_policy_cpu, i.e. cpufreq_frequency_table_update_policy_cpu and
> > the notifier callbacks. Is that change of lock coverage OK?
>
> Yeah, the rwsem is only required for updating policy's fields and so that
> should be okay.
But what about reads, like in cpufreq_frequency_table_update_policy_cpu
which is called immediately after the unlocking writes? Should that not
be covered by a reader lock?
And after that call, policy is passed into blocking_notifier_call_chain,
do those callbacks not want to look at policy fields? Or are they going
to do there own locking?
Or is update_policy_cpu itself meant to be called with a read lock held?
(It doesn't appear to be as the semaphore 'activiy' field of the lock is
zero).
Or is there some other non-obvious synchronisation method which means
the policy object can't change?
This is the first time I've looked at this code, so feel free just to
say 'it's complicated, just trust me, I'm the expert, I know what I'm
doing'...
--
Tixy
next prev parent reply other threads:[~2013-09-16 18:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-16 15:10 [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu Viresh Kumar
2013-09-16 15:10 ` [PATCH 2/2] cpufreq: make return type of lock_policy_rwsem_{read|write}() as void Viresh Kumar
2013-09-17 8:28 ` Jon Medhurst (Tixy)
2013-09-30 18:28 ` Rafael J. Wysocki
2013-10-02 8:43 ` Viresh Kumar
2013-10-02 16:38 ` Rafael J. Wysocki
2013-10-02 16:49 ` Viresh Kumar
2013-09-16 16:27 ` [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu Jon Medhurst (Tixy)
2013-09-16 17:08 ` Viresh Kumar
2013-09-16 18:34 ` Rafael J. Wysocki
2013-09-17 4:38 ` Viresh Kumar
2013-09-16 18:42 ` Jon Medhurst (Tixy) [this message]
2013-09-17 4:46 ` Viresh Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1379356930.3422.71.camel@linaro1.home \
--to=tixy@linaro.org \
--cc=cpufreq@vger.kernel.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=patches@linaro.org \
--cc=rjw@sisk.pl \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).