linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Viresh Kumar <viresh.kumar@linaro.org>,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH AUTOSEL 5.2 190/249] cpufreq: Avoid calling cpufreq_verify_current_freq() from handle_update()
Date: Sun, 21 Jul 2019 20:40:16 -0400	[thread overview]
Message-ID: <20190722004016.GD1607@sasha-vm> (raw)
In-Reply-To: <b43e57ea-c5b8-b4c4-f58f-405e649aada1@intel.com>

On Tue, Jul 16, 2019 at 11:25:00AM +0200, Rafael J. Wysocki wrote:
>On 7/15/2019 3:45 PM, Sasha Levin wrote:
>>From: Viresh Kumar <viresh.kumar@linaro.org>
>>
>>[ Upstream commit 70a59fde6e69d1d8579f84bf4555bfffb3ce452d ]
>>
>>On some occasions cpufreq_verify_current_freq() schedules a work whose
>>callback is handle_update(), which further calls cpufreq_update_policy()
>>which may end up calling cpufreq_verify_current_freq() again.
>>
>>On the other hand, when cpufreq_update_policy() is called from
>>handle_update(), the pointer to the cpufreq policy is already
>>available, but cpufreq_cpu_acquire() is still called to get it in
>>cpufreq_update_policy(), which should be avoided as well.
>>
>>To fix these issues, create a new helper, refresh_frequency_limits(),
>>and make both handle_update() call it cpufreq_update_policy().
>>
>>Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>>[ rjw: Rename reeval_frequency_limits() as refresh_frequency_limits() ]
>>[ rjw: Changelog ]
>>Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>Signed-off-by: Sasha Levin <sashal@kernel.org>
>>---
>>  drivers/cpufreq/cpufreq.c | 26 ++++++++++++++++----------
>>  1 file changed, 16 insertions(+), 10 deletions(-)
>>
>>diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>>index e84bf0eb7239..876a4cb09de3 100644
>>--- a/drivers/cpufreq/cpufreq.c
>>+++ b/drivers/cpufreq/cpufreq.c
>>@@ -1114,13 +1114,25 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp
>>  	return ret;
>>  }
>>+static void refresh_frequency_limits(struct cpufreq_policy *policy)
>>+{
>>+	struct cpufreq_policy new_policy = *policy;
>>+
>>+	pr_debug("updating policy for CPU %u\n", policy->cpu);
>>+
>>+	new_policy.min = policy->user_policy.min;
>>+	new_policy.max = policy->user_policy.max;
>>+
>>+	cpufreq_set_policy(policy, &new_policy);
>>+}
>>+
>>  static void handle_update(struct work_struct *work)
>>  {
>>  	struct cpufreq_policy *policy =
>>  		container_of(work, struct cpufreq_policy, update);
>>-	unsigned int cpu = policy->cpu;
>>-	pr_debug("handle_update for cpu %u called\n", cpu);
>>-	cpufreq_update_policy(cpu);
>>+
>>+	pr_debug("handle_update for cpu %u called\n", policy->cpu);
>>+	refresh_frequency_limits(policy);
>>  }
>>  static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
>>@@ -2392,7 +2404,6 @@ int cpufreq_set_policy(struct cpufreq_policy *policy,
>>  void cpufreq_update_policy(unsigned int cpu)
>>  {
>>  	struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
>>-	struct cpufreq_policy new_policy;
>>  	if (!policy)
>>  		return;
>>@@ -2405,12 +2416,7 @@ void cpufreq_update_policy(unsigned int cpu)
>>  	    (cpufreq_suspended || WARN_ON(!cpufreq_update_current_freq(policy))))
>>  		goto unlock;
>>-	pr_debug("updating policy for CPU %u\n", cpu);
>>-	memcpy(&new_policy, policy, sizeof(*policy));
>>-	new_policy.min = policy->user_policy.min;
>>-	new_policy.max = policy->user_policy.max;
>>-
>>-	cpufreq_set_policy(policy, &new_policy);
>>+	refresh_frequency_limits(policy);
>>  unlock:
>>  	cpufreq_cpu_release(policy);
>
>I don't think this is suitable for -stable.

I've dropped it, thanks!

--
Thanks,
Sasha

  reply	other threads:[~2019-07-22  0:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190715134655.4076-1-sashal@kernel.org>
2019-07-15 13:43 ` [PATCH AUTOSEL 5.2 066/249] cpupower : frequency-set -r option misses the last cpu in related cpu list Sasha Levin
2019-07-15 13:44 ` [PATCH AUTOSEL 5.2 099/249] x86/cpu: Add Ice Lake NNPI to Intel family Sasha Levin
2019-07-15 13:44 ` [PATCH AUTOSEL 5.2 102/249] perf/x86: Add Intel Ice Lake NNPI uncore support Sasha Levin
2019-07-15 13:45 ` [PATCH AUTOSEL 5.2 190/249] cpufreq: Avoid calling cpufreq_verify_current_freq() from handle_update() Sasha Levin
2019-07-16  9:25   ` Rafael J. Wysocki
2019-07-22  0:40     ` Sasha Levin [this message]
2019-07-15 13:45 ` [PATCH AUTOSEL 5.2 191/249] cpufreq: Don't skip frequency validation for has_target() drivers Sasha Levin

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=20190722004016.GD1607@sasha-vm \
    --to=sashal@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=stable@vger.kernel.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).