All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shivnandan Kumar <quic_kshivnan@quicinc.com>
To: <rafael@kernel.org>, Viresh Kumar <viresh.kumar@linaro.org>,
	"Vincent Donnefort" <vincent.donnefort@arm.com>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<quic_pkondeti@quicinc.com>, <quic_namajain@quicinc.com>,
	<quic_rgottimu@quicinc.com>, kernel <kernel@quicinc.com>,
	Shivnandan Kumar <quic_kshivnan@quicinc.com>,
	<stable@vger.kernel.org>
Subject: [PATCH v2] cpufreq: Limit resolving a frequency to policy min/max
Date: Tue, 27 Feb 2024 14:43:51 +0530	[thread overview]
Message-ID: <20240227091351.1144757-1-quic_kshivnan@quicinc.com> (raw)

Resolving a frequency to an efficient one should not transgress policy->max
(which can be set for thermal reason) and policy->min. Currently there is
possibility where scaling_cur_freq can exceed scaling_max_freq when
scaling_max_freq is inefficient frequency. Add additional check to ensure
that resolving a frequency will respect policy->min/max.

Cc: <stable@vger.kernel.org>
Fixes: 1f39fa0dccff ("cpufreq: Introducing CPUFREQ_RELATION_E")
Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>
--

Changes in v2:
-rename function name from cpufreq_table_index_is_in_limits to cpufreq_is_in_limits
-remove redundant outer parenthesis in return statement
-Make comment single line

--
---
 include/linux/cpufreq.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index afda5f24d3dd..7741244dee6e 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -1021,6 +1021,19 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
 						   efficiencies);
 }
 
+static inline bool cpufreq_is_in_limits(struct cpufreq_policy *policy,
+						    int idx)
+{
+	unsigned int freq;
+
+	if (idx < 0)
+		return false;
+
+	freq = policy->freq_table[idx].frequency;
+
+	return freq == clamp_val(freq, policy->min, policy->max);
+}
+
 static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
 						 unsigned int target_freq,
 						 unsigned int relation)
@@ -1054,7 +1067,8 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
 		return 0;
 	}
 
-	if (idx < 0 && efficiencies) {
+	/* Limit frequency index to honor policy->min/max */
+	if (!cpufreq_is_in_limits(policy, idx) && efficiencies) {
 		efficiencies = false;
 		goto retry;
 	}
-- 
2.25.1


             reply	other threads:[~2024-02-27  9:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27  9:13 Shivnandan Kumar [this message]
2024-02-29 19:23 ` [PATCH v2] cpufreq: Limit resolving a frequency to policy min/max Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2024-02-24 15:13 Shivnandan 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=20240227091351.1144757-1-quic_kshivnan@quicinc.com \
    --to=quic_kshivnan@quicinc.com \
    --cc=kernel@quicinc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=quic_namajain@quicinc.com \
    --cc=quic_pkondeti@quicinc.com \
    --cc=quic_rgottimu@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vincent.donnefort@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.