From nobody Mon Feb 9 18:18:07 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7DE1330640; Mon, 26 Jan 2026 10:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769422756; cv=none; b=cld0+kyv2Pr5uHN0GWPGK2e0DHUcHp+S/GqBf01vVkhJh3qyOKVe8gKZLdOlFvf0S8OOo3bThdJgjD2YnoFrjzh9yP7E6W1NhaVR6V+fD+6GELXIkqqSVn8VYgp2PUV+FrUzk6QhRTN6QBx76C91VMGTsQy5b9HF566CQofSm+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769422756; c=relaxed/simple; bh=c1eWi+UqnTIEqEHycUHgp/VD+sNLi0VbrxP4lpcjTEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j+KgOVYm1zmrXW1Rbw2QdAPzH+zpVKW44HoppQ3qdJ9l964IjhdG+cmwziOdkDLf6bfaWvyfHLvs1w5b3c4pTuAJNO1el0nJzbSAPpKBthbDVpFOzYAo7uWCkJ49QjyqCkjNIpqloFBObJ0ehUhiIv3Gth+BoF7YjTr+NxcTzlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 762AF497; Mon, 26 Jan 2026 02:19:07 -0800 (PST) Received: from e135073.nice.arm.com (e135073.arm.com [10.34.125.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 796D53F632; Mon, 26 Jan 2026 02:19:10 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Jie Zhan , zhenglifeng1@huawei.com, Ionela Voinescu , Christian Loehle , sumitg@nvidia.com, Pierre Gondois , "Rafael J. Wysocki" , Viresh Kumar , Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , Perry Yuan , Srinivas Pandruvada , Len Brown , Saravana Kannan , linux-pm@vger.kernel.org Subject: [PATCH 5/6] cpufreq: Set policy->min and max as real QoS constraints Date: Mon, 26 Jan 2026 11:18:14 +0100 Message-ID: <20260126101826.94030-6-pierre.gondois@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260126101826.94030-1-pierre.gondois@arm.com> References: <20260126101826.94030-1-pierre.gondois@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cpufreq_set_policy() will ultimately override the policy min/max values written in the .init() callback through: cpufreq_policy_online() \-cpufreq_init_policy() \-cpufreq_set_policy() \-/* Set policy->min/max */ Thus the policy min/max values provided are only temporary. There is an exception if CPUFREQ_NEED_INITIAL_FREQ_CHECK is set and: cpufreq_policy_online() \-cpufreq_init_policy() \-__cpufreq_driver_target() \-cpufreq_driver->target() is called. In this case, some drivers use the policy min/max values in their .target() callback before they are overridden. Check cpufreq drivers: - if their .target() callback doesn't use policy->min or max, remove the initialization - assuming policy->min or max values were populated as constraints, set them as QoS real constraints in cpufreq_policy_online() Signed-off-by: Pierre Gondois --- drivers/cpufreq/amd-pstate.c | 24 ++++++++++++------------ drivers/cpufreq/cpufreq-nforce2.c | 4 ++-- drivers/cpufreq/cpufreq.c | 16 ++++++++++++++-- drivers/cpufreq/gx-suspmod.c | 9 ++++----- drivers/cpufreq/intel_pstate.c | 3 --- drivers/cpufreq/pcc-cpufreq.c | 8 ++++---- drivers/cpufreq/pxa3xx-cpufreq.c | 4 ++-- drivers/cpufreq/virtual-cpufreq.c | 6 +++--- 8 files changed, 41 insertions(+), 33 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 310d5938cbdf6..aaafbe9b26cae 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -1003,12 +1003,12 @@ static int amd_pstate_cpu_init(struct cpufreq_polic= y *policy) =20 perf =3D READ_ONCE(cpudata->perf); =20 - policy->cpuinfo.min_freq =3D policy->min =3D perf_to_freq(perf, - cpudata->nominal_freq, - perf.lowest_perf); - policy->cpuinfo.max_freq =3D policy->max =3D perf_to_freq(perf, - cpudata->nominal_freq, - perf.highest_perf); + policy->cpuinfo.min_freq =3D perf_to_freq(perf, + cpudata->nominal_freq, + perf.lowest_perf); + policy->cpuinfo.max_freq =3D perf_to_freq(perf, + cpudata->nominal_freq, + perf.highest_perf); =20 ret =3D amd_pstate_cppc_enable(policy); if (ret) @@ -1485,12 +1485,12 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_p= olicy *policy) =20 perf =3D READ_ONCE(cpudata->perf); =20 - policy->cpuinfo.min_freq =3D policy->min =3D perf_to_freq(perf, - cpudata->nominal_freq, - perf.lowest_perf); - policy->cpuinfo.max_freq =3D policy->max =3D perf_to_freq(perf, - cpudata->nominal_freq, - perf.highest_perf); + policy->cpuinfo.min_freq =3D perf_to_freq(perf, + cpudata->nominal_freq, + perf.lowest_perf); + policy->cpuinfo.max_freq =3D perf_to_freq(perf, + cpudata->nominal_freq, + perf.highest_perf); policy->driver_data =3D cpudata; =20 ret =3D amd_pstate_cppc_enable(policy); diff --git a/drivers/cpufreq/cpufreq-nforce2.c b/drivers/cpufreq/cpufreq-nf= orce2.c index fbbbe501cf2dc..831102522ad64 100644 --- a/drivers/cpufreq/cpufreq-nforce2.c +++ b/drivers/cpufreq/cpufreq-nforce2.c @@ -355,8 +355,8 @@ static int nforce2_cpu_init(struct cpufreq_policy *poli= cy) min_fsb =3D NFORCE2_MIN_FSB; =20 /* cpuinfo and default policy values */ - policy->min =3D policy->cpuinfo.min_freq =3D min_fsb * fid * 100; - policy->max =3D policy->cpuinfo.max_freq =3D max_fsb * fid * 100; + policy->cpuinfo.min_freq =3D min_fsb * fid * 100; + policy->cpuinfo.max_freq =3D max_fsb * fid * 100; =20 return 0; } diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 43bf6aed90e49..209e2673ca50b 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1455,6 +1455,18 @@ static int cpufreq_policy_online(struct cpufreq_poli= cy *policy, cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); =20 if (new_policy) { + unsigned int min, max; + + /* + * If the driver has set policy->min or max, + * use the value as a QoS request. + */ + min =3D max(FREQ_QOS_MIN_DEFAULT_VALUE, policy->min); + if (policy->max) + max =3D min(FREQ_QOS_MAX_DEFAULT_VALUE, policy->max); + else + max =3D FREQ_QOS_MAX_DEFAULT_VALUE; + for_each_cpu(j, policy->related_cpus) { per_cpu(cpufreq_cpu_data, j) =3D policy; add_cpu_dev_symlink(policy, j, get_cpu_device(j)); @@ -1469,7 +1481,7 @@ static int cpufreq_policy_online(struct cpufreq_polic= y *policy, =20 ret =3D freq_qos_add_request(&policy->constraints, policy->min_freq_req, FREQ_QOS_MIN, - FREQ_QOS_MIN_DEFAULT_VALUE); + min); if (ret < 0) { /* * So we don't call freq_qos_remove_request() for an @@ -1489,7 +1501,7 @@ static int cpufreq_policy_online(struct cpufreq_polic= y *policy, =20 ret =3D freq_qos_add_request(&policy->constraints, policy->max_freq_req, FREQ_QOS_MAX, - FREQ_QOS_MAX_DEFAULT_VALUE); + max); if (ret < 0) { policy->max_freq_req =3D NULL; goto out_destroy_policy; diff --git a/drivers/cpufreq/gx-suspmod.c b/drivers/cpufreq/gx-suspmod.c index 75b3ef7ec6796..57999b8d51fa2 100644 --- a/drivers/cpufreq/gx-suspmod.c +++ b/drivers/cpufreq/gx-suspmod.c @@ -397,7 +397,7 @@ static int cpufreq_gx_target(struct cpufreq_policy *pol= icy, =20 static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy) { - unsigned int maxfreq; + unsigned int minfreq, maxfreq; =20 if (!policy || policy->cpu !=3D 0) return -ENODEV; @@ -418,11 +418,10 @@ static int cpufreq_gx_cpu_init(struct cpufreq_policy = *policy) policy->cpu =3D 0; =20 if (max_duration < POLICY_MIN_DIV) - policy->min =3D maxfreq / max_duration; + minfreq =3D maxfreq / max_duration; else - policy->min =3D maxfreq / POLICY_MIN_DIV; - policy->max =3D maxfreq; - policy->cpuinfo.min_freq =3D maxfreq / max_duration; + minfreq =3D maxfreq / POLICY_MIN_DIV; + policy->cpuinfo.min_freq =3D minfreq; policy->cpuinfo.max_freq =3D maxfreq; =20 return 0; diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index ec4abe3745736..bf2f7524d04a9 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -3047,9 +3047,6 @@ static int __intel_pstate_cpu_init(struct cpufreq_pol= icy *policy) policy->cpuinfo.max_freq =3D READ_ONCE(global.no_turbo) ? cpu->pstate.max_freq : cpu->pstate.turbo_freq; =20 - policy->min =3D policy->cpuinfo.min_freq; - policy->max =3D policy->cpuinfo.max_freq; - intel_pstate_init_acpi_perf_limits(policy); =20 policy->fast_switch_possible =3D true; diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c index ac2e90a65f0c4..231edfe8cabaa 100644 --- a/drivers/cpufreq/pcc-cpufreq.c +++ b/drivers/cpufreq/pcc-cpufreq.c @@ -551,13 +551,13 @@ static int pcc_cpufreq_cpu_init(struct cpufreq_policy= *policy) goto out; } =20 - policy->max =3D policy->cpuinfo.max_freq =3D + policy->cpuinfo.max_freq =3D ioread32(&pcch_hdr->nominal) * 1000; - policy->min =3D policy->cpuinfo.min_freq =3D + policy->cpuinfo.min_freq =3D ioread32(&pcch_hdr->minimum_frequency) * 1000; =20 - pr_debug("init: policy->max is %d, policy->min is %d\n", - policy->max, policy->min); + pr_debug("init: max_freq is %d, min_freq is %d\n", + policy->cpuinfo.max_freq, policy->cpuinfo.min_freq); out: return result; } diff --git a/drivers/cpufreq/pxa3xx-cpufreq.c b/drivers/cpufreq/pxa3xx-cpuf= req.c index 4afa48d172dbe..f53b9d7edc76a 100644 --- a/drivers/cpufreq/pxa3xx-cpufreq.c +++ b/drivers/cpufreq/pxa3xx-cpufreq.c @@ -185,8 +185,8 @@ static int pxa3xx_cpufreq_init(struct cpufreq_policy *p= olicy) int ret =3D -EINVAL; =20 /* set default policy and cpuinfo */ - policy->min =3D policy->cpuinfo.min_freq =3D 104000; - policy->max =3D policy->cpuinfo.max_freq =3D + policy->cpuinfo.min_freq =3D 104000; + policy->cpuinfo.max_freq =3D (cpu_is_pxa320()) ? 806000 : 624000; policy->cpuinfo.transition_latency =3D 1000; /* FIXME: 1 ms, assumed */ =20 diff --git a/drivers/cpufreq/virtual-cpufreq.c b/drivers/cpufreq/virtual-cp= ufreq.c index 6ffa16d239b2b..6f7dbef7fda96 100644 --- a/drivers/cpufreq/virtual-cpufreq.c +++ b/drivers/cpufreq/virtual-cpufreq.c @@ -164,10 +164,10 @@ static int virt_cpufreq_get_freq_info(struct cpufreq_= policy *policy) policy->cpuinfo.min_freq =3D 1; policy->cpuinfo.max_freq =3D virt_cpufreq_get_perftbl_entry(policy->cpu,= 0); =20 - policy->min =3D policy->cpuinfo.min_freq; - policy->max =3D policy->cpuinfo.max_freq; + policy->cpuinfo.min_freq; + policy->cpuinfo.max_freq; =20 - policy->cur =3D policy->max; + policy->cur =3D policy->cpuinfo.max_freq; return 0; } =20 --=20 2.43.0