From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Steve Muckle <steve.muckle@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Morten Rasmussen <morten.rasmussen@arm.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Juri Lelli <Juri.Lelli@arm.com>,
Patrick Bellasi <patrick.bellasi@arm.com>,
Michael Turquette <mturquette@baylibre.com>
Subject: Re: [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to driver frequency
Date: Mon, 30 May 2016 16:25:25 +0200 [thread overview]
Message-ID: <CAJZ5v0hwohZh_Pubt5pc2NoiMWrSDkcfjkbcFuugPkRTwKhejQ@mail.gmail.com> (raw)
In-Reply-To: <20160530101830.GE30066@vireshk-i7>
On Mon, May 30, 2016 at 12:18 PM, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 29-05-16, 02:40, Rafael J. Wysocki wrote:
>> I can't really parse the above question, so I'm not going to try to
>> answer it. :-)
>
> Sorry about that :(
>
> IOW, I think that we should make this change into the sched-governor (I will
> send a patch separately if you agree to this):
I don't.
> diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> index 14c4aa25cc45..5934b14aa21c 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -66,11 +66,6 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
>
> if (unlikely(sg_policy->need_freq_update)) {
> sg_policy->need_freq_update = false;
> - /*
> - * This happens when limits change, so forget the previous
> - * next_freq value and force an update.
> - */
> - sg_policy->next_freq = UINT_MAX;
> return true;
> }
>
> And here is my reasoning behind this.
>
> Can you show me any case, where the above code (as present in mainline
> today) leads to a freq-change? I couldn't find any.
>
> Let me demonstrate.
>
> Following only talks about the fast-switch path, the other path is
> same as well.
>
> Suppose this is the current range of frequencies supported by a
> driver: 200, 400, 600, 800, 1000 (in MHz).
>
> And policy->cur = next_freq = 400 MHz.
>
> A.) Suppose that we change policy->min to 400 MHz from userspace.
> -> sugov_limits()
> This will find everything in order and simply set
> need_freq_update, without updating the frequency.
>
> On next util-callback, we will forcefully return true from
> sugov_should_update_freq() and reach sugov_update_commit().
>
> We calculate next_freq and that comes to 400 MHz again (that's the
> case we are trying to target with the above code).
>
> With the current code, we will forcefully end up calling
> cpufreq_driver_fast_switch().
>
> Because the new and current frequencies are same,
> cpufreq_driver->fast_switch() will simply return.
>
> NOTE: I also think that cpufreq_driver_fast_switch() should have a
> check like (policy->cur == target_freq). I will add that too, in
> case you agree.
>
> So, forcefully updating next_freq to UINT_MAX will end up wasting
> some cycles, but wouldn't do any useful stuff.
It will, but there's no way to distinguish this case from B in the
governor with the current min/max synchronization mechanism. That is,
it only knows that something has changed, but checking what exactly
has changed would be racy.
> B.) Suppose that we change policy->min to 600 MHz from userspace.
> -> sugov_limits()
> This will find that policy->cur is less than 600 and will set
> that to 600 MHz by calling __cpufreq_driver_target(). We will
> also set need_freq_update.
>
> Note that next_freq and policy->cur are not in sync anymore and
> perhaps this is the most important case for the above code.
It is.
Moreover, please note that __cpufreq_driver_target() is only called in
sugov_limits() when policy->fast_switch_enabled is unset.
> On next util-callback, we will forcefully return true from
> sugov_should_update_freq() and reach sugov_update_commit().
>
> We calculate next_freq and lets say that comes to 400 MHz again
> (as that's the case we are trying to target with the above code).
>
> With the current code, we will forcefully end up calling
> cpufreq_driver_fast_switch().
>
> Because next_freq() is not part of the new range, we will clamp it
> and set it to 600 MHz eventually. Again, next and current
> frequencies are same, cpufreq_driver->fast_switch() will simply
> return.
Not really (as per the above).
And even in the !fast_switch_enabled case, if next_freq stays at 400
MHz (which is different from policy->cur), it may lead to suboptimal
decisions going forward (eg. if it goes to 600 MHz next time and the
governor will think that the frequency has changed, although in fact
it hasn't).
I guess the !fast_switch_enabled case might be optimized by comparing
next_freq with policy->cur at one point, but next_freq should be
updated regardless IMO.
next prev parent reply other threads:[~2016-05-30 14:25 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-26 2:52 [PATCH v2 0/3] cpufreq: avoid redundant driver calls in schedutil Steve Muckle
2016-05-26 2:52 ` [PATCH v2 1/3] cpufreq: add resolve_freq driver callback Steve Muckle
2016-05-26 6:25 ` Viresh Kumar
2016-05-30 15:31 ` Steve Muckle
2016-05-31 5:30 ` Viresh Kumar
2016-05-31 18:48 ` Steve Muckle
2016-05-31 11:14 ` Viresh Kumar
2016-05-31 18:12 ` Steve Muckle
2016-05-26 2:53 ` [PATCH v2 2/3] cpufreq: acpi-cpufreq: add resolve_freq callback Steve Muckle
2016-05-26 6:43 ` Viresh Kumar
2016-05-30 16:20 ` Steve Muckle
2016-05-31 11:38 ` Viresh Kumar
2016-05-26 2:53 ` [PATCH v2 3/3] cpufreq: schedutil: map raw required frequency to driver frequency Steve Muckle
2016-05-26 7:16 ` Viresh Kumar
2016-05-29 0:40 ` Rafael J. Wysocki
2016-05-30 10:18 ` Viresh Kumar
2016-05-30 14:25 ` Rafael J. Wysocki [this message]
2016-05-30 15:32 ` Viresh Kumar
2016-05-30 19:08 ` Rafael J. Wysocki
2016-05-31 9:02 ` Peter Zijlstra
2016-05-31 1:49 ` Wanpeng Li
2016-05-30 16:35 ` Steve Muckle
2016-06-01 10:50 ` Viresh Kumar
2016-05-27 5:41 ` Wanpeng Li
2016-05-30 16:48 ` Steve Muckle
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=CAJZ5v0hwohZh_Pubt5pc2NoiMWrSDkcfjkbcFuugPkRTwKhejQ@mail.gmail.com \
--to=rafael@kernel.org \
--cc=Juri.Lelli@arm.com \
--cc=dietmar.eggemann@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=morten.rasmussen@arm.com \
--cc=mturquette@baylibre.com \
--cc=patrick.bellasi@arm.com \
--cc=peterz@infradead.org \
--cc=steve.muckle@linaro.org \
--cc=vincent.guittot@linaro.org \
--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).