cpufreq: simplify boost handling
Subsystems (8)
Viresh Kumar
maintainercover cpufreq: simplify boost handling
Hello,
The boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently most of the drivers enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Also it is possible to have a scenario where not all cpufreq policies support boost frequencies. And letting sysfs (or other parts of the kernel) enable boost feature for that policy isn't correct.
Simplify and cleanup handling of boost to solve these issues.
Pushed here:
git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git cpufreq/boost
Rebased over few dependencies from PM tree, will push to the arm-cpufreq tree after merge window is closed.
Viresh Kumar (15):
cpufreq: staticize cpufreq_boost_trigger_state()
cpufreq: Export cpufreq_boost_set_sw()
cpufreq: Introduce policy->boost_supported flag
cpufreq: acpi: Set policy->boost_supported
cpufreq: amd: Set policy->boost_supported
cpufreq: cppc: Set policy->boost_supported
cpufreq: Restrict enabling boost on policies with no boost frequencies
cpufreq: apple: Set .set_boost directly
cpufreq: loongson: Set .set_boost directly
cpufreq: powernv: Set .set_boost directly
cpufreq: scmi: Set .set_boost directly
cpufreq: dt: Set .set_boost directly
cpufreq: qcom: Set .set_boost directly
cpufreq: staticize policy_has_boost_freq()
cpufreq: Remove cpufreq_enable_boost_support()
drivers/cpufreq/acpi-cpufreq.c | 3 +++ drivers/cpufreq/amd-pstate.c | 4 ++-- drivers/cpufreq/apple-soc-cpufreq.c | 10 +--------- drivers/cpufreq/cppc_cpufreq.c | 9 +-------- drivers/cpufreq/cpufreq-dt.c | 14 +------------- drivers/cpufreq/cpufreq.c | 30 ++++++++++++----------------- drivers/cpufreq/freq_table.c | 7 +++++-- drivers/cpufreq/loongson3_cpufreq.c | 10 +--------- drivers/cpufreq/powernv-cpufreq.c | 5 +---- drivers/cpufreq/qcom-cpufreq-hw.c | 7 +------ drivers/cpufreq/scmi-cpufreq.c | 11 +---------- include/linux/cpufreq.h | 20 ++++++------------- 12 files changed, 35 insertions(+), 95 deletions(-)
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 1/15 cpufreq: staticize cpufreq_boost_trigger_state()
cpufreq_boost_trigger_state() is only used by cpufreq core, mark it static.
--- drivers/cpufreq/cpufreq.c | 3 ++- include/linux/cpufreq.h | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-)
drivers/cpufreq/cpufreq.c +2 -1
@@ -87,6 +87,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,struct cpufreq_governor *new_gov, unsigned int new_pol);static bool cpufreq_boost_supported (void ); +static int cpufreq_boost_trigger_state (int state);/* * Two notifier lists: the "policy" list is involved in the
@@ -2805,7 +2806,7 @@ static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)return 0 ; } -int cpufreq_boost_trigger_state (int state) +static int cpufreq_boost_trigger_state (int state) {struct cpufreq_policy *policy;unsigned long flags;
include/linux/cpufreq.h +0 -5
@@ -778,7 +778,6 @@ int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,ssize_t cpufreq_show_cpus (const struct cpumask *mask,char *buf);#ifdef CONFIG_CPU_FREQ -int cpufreq_boost_trigger_state (int state);bool cpufreq_boost_enabled (void );int cpufreq_enable_boost_support (void );bool policy_has_boost_freq (struct cpufreq_policy *policy);
@@ -1150,10 +1149,6 @@ static inline int of_perf_domain_get_sharing_cpumask(int pcpu, const char *list_ return 0; }#else -static inline int cpufreq_boost_trigger_state (int state) -{ -return 0 ; -}static inline bool cpufreq_boost_enabled (void ) {return false;
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 2/15 cpufreq: Export cpufreq_boost_set_sw()
In reply to Viresh KumarThis will be used directly by cpufreq driver going forward, export it.
--- drivers/cpufreq/cpufreq.c | 3 ++- include/linux/cpufreq.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +2 -1
@@ -2786,7 +2786,7 @@ EXPORT_SYMBOL_GPL(cpufreq_update_limits);/********************************************************************* * BOOST * *********************************************************************/ -static int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state) +int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state) {int ret;
@@ -2805,6 +2805,7 @@ static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)return 0 ; } +EXPORT_SYMBOL_GPL (cpufreq_boost_set_sw);static int cpufreq_boost_trigger_state (int state) {
include/linux/cpufreq.h +6 -0
@@ -781,6 +781,7 @@ ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);bool cpufreq_boost_enabled (void );int cpufreq_enable_boost_support (void );bool policy_has_boost_freq (struct cpufreq_policy *policy); +int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state);/* Find lowest freq at or above target in a table in ascending order */ static inline int cpufreq_table_find_index_al(struct cpufreq_policy *policy,
@@ -1164,6 +1165,11 @@ static inline bool policy_has_boost_freq(struct cpufreq_policy *policy)return false; } +static inline int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state) +{ +return -EOPNOTSUPP ; +} +static inline int cpufreq_table_set_inefficient (struct cpufreq_policy *policy,unsigned int frequency)
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 3/15 cpufreq: Introduce policy->boost_supported flag
In reply to Viresh KumarIt is possible to have a scenario where not all cpufreq policies support boost frequencies. And letting sysfs (or other parts of the kernel) enable boost feature for that policy isn't correct.
Add a new flag, boost_supported, which will be set to true by the cpufreq core only if the freq table contains valid boost frequencies.
Some cpufreq drivers though don't have boost frequencies in the freq-table, they can set this flag from their ->init() callbacks.
Once all the drivers are updated to set the flag correctly, we can check it before enabling boost feature for a policy.
--- drivers/cpufreq/freq_table.c | 4 ++++ include/linux/cpufreq.h | 3 +++ 2 files changed, 7 insertions(+)
drivers/cpufreq/freq_table.c +4 -0
@@ -359,6 +359,10 @@ int cpufreq_table_validate_and_sort(struct cpufreq_policy *policy)if (ret)return ret; +/* Driver's may have set this field already */ +if (policy_has_boost_freq (policy)) + policy->boost_supported = true; +return set_freq_table_sorted (policy); }
include/linux/cpufreq.h +3 -0
@@ -144,6 +144,9 @@ struct cpufreq_policy {/* Per policy boost enabled flag. */ bool boost_enabled; +/* Per policy boost supported flag. */ +bool boost_supported; +/* Cached frequency lookup from cpufreq_driver_resolve_freq. */ unsigned int cached_target_freq;unsigned int cached_resolved_idx;
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 4/15 cpufreq: acpi: Set policy->boost_supported
In reply to Viresh KumarWith a later commit, the cpufreq core will call the ->set_boost() callback only if the policy supports boost frequency. The boost_supported flag is set by the cpufreq core if policy->freq_table is set and one or more boost frequencies are present.
For other drivers, the flag must be set explicitly.
--- drivers/cpufreq/acpi-cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/cpufreq/acpi-cpufreq.c +3 -0
@@ -891,6 +891,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)if (perf->states[0 ].core_frequency *1000 != freq_table[0 ].frequency)pr_warn (FW_WARN "P-state 0 is not max freq\n" ); +if (acpi_cpufreq_driver.set_boost) + policy->boost_supported = true; +return result; err_unreg:
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 5/15 cpufreq: amd: Set policy->boost_supported
In reply to Viresh KumarWith a later commit, the cpufreq core will call the ->set_boost() callback only if the policy supports boost frequency. The boost_supported flag is set by the cpufreq core if policy->freq_table is set and one or more boost frequencies are present.
For other drivers, the flag must be set explicitly.
The policy->boost_enabled flag is set by the cpufreq core once the policy is initialized, don't set it anymore.
--- drivers/cpufreq/amd-pstate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +2 -2
@@ -995,7 +995,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy) policy->cpuinfo.min_freq = min_freq; policy->cpuinfo.max_freq = max_freq; - policy->boost_enabled =READ_ONCE (cpudata->boost_supported); + policy->boost_supported =READ_ONCE (cpudata->boost_supported);/* It will be updated by governor */ policy->cur = policy->cpuinfo.min_freq;
@@ -1480,7 +1480,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) policy->min = policy->cpuinfo.min_freq; policy->max = policy->cpuinfo.max_freq; - policy->boost_enabled =READ_ONCE (cpudata->boost_supported); + policy->boost_supported =READ_ONCE (cpudata->boost_supported);/* * Set the policy to provide a valid fallback value in case
Signature · 1 line
2.31.1.272.g89b43f80a514
Re: [PATCH 05/15] cpufreq: amd: Set policy->boost_supported
Hello Viresh,
Quoted 9 lines · Viresh Kumar
With a later commit, the cpufreq core will call the ->set_boost() callback only if the policy supports boost frequency. The
boost_supportedflag is set by the cpufreq core ifpolicy->freq_tableis set and one or more boost frequencies are present.For other drivers, the flag must be set explicitly.
The
policy->boost_enabledflag is set by the cpufreq core once the policy is initialized, don't set it anymore.
This patch uncovers a bug in the amd_pstate mode switch path (e.g when we do "echo passive > /sys/devices/system/cpu/amd_pstate/status"). I have posted a fix for it at
https://lore.kernel.org/all/[email protected]/T/#u
Can we try to merge this fix before your patch?, so we fix the bug before it is uncovered. Currently, the fix is based on top of superm1/bleeding-edge (amd-pstate maintainer's dev tree). It wont apply cleanly on your tree i.e. vireshk/pm/cpufreq/boost. I can rebase it on your tree and repost, if needed.
Thanks,
Dhananjay
Quoted 28 lines
Signed-off-by Viresh Kumar <[email protected]>--- drivers/cpufreq/amd-pstate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/cpufreq/amd-pstate.c +2
-2@@ -995,7 +995,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy) policy->cpuinfo.min_freq = min_freq; policy->cpuinfo.max_freq = max_freq; - policy->boost_enabled =READ_ONCE (cpudata->boost_supported); + policy->boost_supported =READ_ONCE (cpudata->boost_supported);/* It will be updated by governor */ policy->cur = policy->cpuinfo.min_freq;@@ -1480,7 +1480,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) policy->min = policy->cpuinfo.min_freq; policy->max = policy->cpuinfo.max_freq; - policy->boost_enabled =READ_ONCE (cpudata->boost_supported); + policy->boost_supported =READ_ONCE (cpudata->boost_supported);/* * Set the policy to provide a valid fallback value in case
Viresh Kumar
maintainerPATCH 6/15 cpufreq: cppc: Set policy->boost_supported
In reply to Viresh KumarWith a later commit, the cpufreq core will call the ->set_boost() callback only if the policy supports boost frequency. The boost_supported flag is set by the cpufreq core if policy->freq_table is set and one or more boost frequencies are present.
For other drivers, the flag must be set explicitly.
With this, the local variable boost_supported isn't required anymore.
--- drivers/cpufreq/cppc_cpufreq.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/cpufreq/cppc_cpufreq.c +1 -8
@@ -34,8 +34,6 @@*/ static LIST_HEAD (cpu_data_list); -static bool boost_supported; -static struct cpufreq_driver cppc_cpufreq_driver;#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE
@@ -653,7 +651,7 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)* is supported. */ if (caps->highest_perf > caps->nominal_perf) - boost_supported = true; + policy->boost_supported = true;/* Set policy->cur to max now. The governors will adjust later. */ policy->cur =cppc_perf_to_khz (caps, caps->highest_perf);
@@ -791,11 +789,6 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)struct cppc_perf_caps *caps = &cpu_data->perf_caps;int ret; -if (!boost_supported) { -pr_err ("BOOST not supported by CPU or firmware\n" ); -return -EINVAL ; - } -if (state) policy->max =cppc_perf_to_khz (caps, caps->highest_perf);else
Signature · 1 line
2.31.1.272.g89b43f80a514
zhenglifeng (A)
reviewerRe: [PATCH 06/15] cpufreq: cppc: Set policy->boost_supported
Quoted 38 lines · Viresh Kumar
With a later commit, the cpufreq core will call the ->set_boost() callback only if the policy supports boost frequency. The
boost_supportedflag is set by the cpufreq core ifpolicy->freq_tableis set and one or more boost frequencies are present.For other drivers, the flag must be set explicitly.
With this, the local variable
boost_supportedisn't required anymore.Signed-off-by Viresh Kumar <[email protected]>--- drivers/cpufreq/cppc_cpufreq.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/cpufreq/cppc_cpufreq.c +1
-3@@ -34,8 +34,6 @@*/ static LIST_HEAD (cpu_data_list); -static bool boost_supported; -static struct cpufreq_driver cppc_cpufreq_driver;#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE @@ -653,7 +651,7 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)* is supported. */ if (caps->highest_perf > caps->nominal_perf) - boost_supported = true; + policy->boost_supported = true;/* Set policy->cur to max now. The governors will adjust later. */ policy->cur =cppc_perf_to_khz (caps, caps->highest_perf);@@ -791,11 +789,6 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)struct cppc_perf_caps *caps = &cpu_data->perf_caps;
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 794
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +0
-5int ret; -if (!boost_supported) { -pr_err ("BOOST not supported by CPU or firmware\n" ); -return -EINVAL ; - } -if (state) policy->max =cppc_perf_to_khz (caps, caps->highest_perf);else
I have a little question. With the old boost_supported flag as false, it will fail when you operate the global boost flag. But if you replace it with the per-policy boost_supported flag, the global boost_enabled flag can be set to true without any error, even no policy's boost_enabled flag changed. Is this interface behavior change OK?
Viresh Kumar
maintainerRe: [PATCH 06/15] cpufreq: cppc: Set policy->boost_supported
Quoted 27 lines · zhenglifeng (A)
Quoted 26 lines · Viresh Kumar
drivers/cpufreq/cppc_cpufreq.c +1
-3@@ -34,8 +34,6 @@*/ static LIST_HEAD (cpu_data_list); -static bool boost_supported; -static struct cpufreq_driver cppc_cpufreq_driver;#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE @@ -653,7 +651,7 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)* is supported. */ if (caps->highest_perf > caps->nominal_perf) - boost_supported = true; + policy->boost_supported = true;/* Set policy->cur to max now. The governors will adjust later. */ policy->cur =cppc_perf_to_khz (caps, caps->highest_perf);@@ -791,11 +789,6 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)struct cppc_perf_caps *caps = &cpu_data->perf_caps;int ret;
Quoted 14 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 794
Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c +0
-5-if (!boost_supported) { -pr_err ("BOOST not supported by CPU or firmware\n" ); -return -EINVAL ; - } -if (state) policy->max =cppc_perf_to_khz (caps, caps->highest_perf);else I have a little question. With the old
boost_supportedflag as false, it will fail when you operate the global boost flag. But if you replace it with the per-policyboost_supportedflag, the globalboost_enabledflag can be set to true without any error, even no policy'sboost_enabledflag changed. Is this interface behavior change OK?
Right, so earlier even if a single policy didn't support boost, the code disabled boost for all of them. Or it was rather racy, as the last policy to be initialized will decide if boost will be supported or not. This is surely incorrect.
The global boost flag can be enabled disabled without worrying about any individual policy. If the policy supports boost, it will follow the global boost here, else it shouldn't take part in the change.
So yes, the new interface does the right thing here.
Signature · 1 line
viresh
Re: [PATCH 06/15] cpufreq: cppc: Set policy->boost_supported
In reply to Viresh KumarQuoted 38 lines · Viresh Kumar
With a later commit, the cpufreq core will call the ->set_boost() callback only if the policy supports boost frequency. The
boost_supportedflag is set by the cpufreq core ifpolicy->freq_tableis set and one or more boost frequencies are present.For other drivers, the flag must be set explicitly.
With this, the local variable
boost_supportedisn't required anymore.Signed-off-by Viresh Kumar <[email protected]>--- drivers/cpufreq/cppc_cpufreq.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)drivers/cpufreq/cppc_cpufreq.c +1
-3@@ -34,8 +34,6 @@*/ static LIST_HEAD (cpu_data_list); -static bool boost_supported; -static struct cpufreq_driver cppc_cpufreq_driver;#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE @@ -653,7 +651,7 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)* is supported. */ if (caps->highest_perf > caps->nominal_perf) - boost_supported = true; + policy->boost_supported = true;/* Set policy->cur to max now. The governors will adjust later. */ policy->cur =cppc_perf_to_khz (caps, caps->highest_perf);@@ -791,11 +789,6 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)struct cppc_perf_caps *caps = &cpu_data->perf_caps;
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 794
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +0
-5int ret; -if (!boost_supported) { -pr_err ("BOOST not supported by CPU or firmware\n" ); -return -EINVAL ; - } -if (state) policy->max =cppc_perf_to_khz (caps, caps->highest_perf);else
Viresh Kumar
maintainerPATCH 7/15 cpufreq: Restrict enabling boost on policies with no boost frequencies
In reply to Viresh KumarIt is possible to have a scenario where not all cpufreq policies support boost frequencies. And letting sysfs (or other parts of the kernel) enable boost feature for that policy isn't correct.
Now that all drivers (that required a change) are updated to set the policy->boost_supported properly, check this flag before enabling boost feature for a policy.
--- drivers/cpufreq/cpufreq.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +8 -1
@@ -631,6 +631,9 @@ static ssize_t store_local_boost(struct cpufreq_policy *policy,if (!cpufreq_driver->boost_enabled)return -EINVAL ; +if (!policy->boost_supported) +return -EINVAL ; +if (policy->boost_enabled == enable)return count;
@@ -1586,7 +1589,8 @@ static int cpufreq_online(unsigned int cpu) policy->cdev =of_cpufreq_cooling_register (policy);/* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ -if (policy->boost_enabled !=cpufreq_boost_enabled ()) { +if (policy->boost_supported && + policy->boost_enabled !=cpufreq_boost_enabled ()) { policy->boost_enabled =cpufreq_boost_enabled (); ret = cpufreq_driver->set_boost (policy, policy->boost_enabled);if (ret) {
@@ -2822,6 +2826,9 @@ static int cpufreq_boost_trigger_state(int state)cpus_read_lock ();for_each_active_policy (policy) { +if (!policy->boost_supported) +continue ; + policy->boost_enabled = state; ret = cpufreq_driver->set_boost (policy, state);if (ret) {
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 8/15 cpufreq: apple: Set .set_boost directly
In reply to Viresh KumarThe boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently the driver enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Instead set the .set_boost field directly and always enable the boost support. If a policy doesn't support boost feature, the core will not enable it for that policy.
Keep the initial state of driver level boost to disabled and let the user enable it if required as ideally the boost frequencies must be used only when really required.
--- drivers/cpufreq/apple-soc-cpufreq.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/cpufreq/apple-soc-cpufreq.c +1 -9
@@ -310,15 +310,6 @@ static int apple_soc_cpufreq_init(struct cpufreq_policy *policy) policy->fast_switch_possible = true; policy->suspend_freq = freq_table[0 ].frequency; -if (policy_has_boost_freq (policy)) { - ret =cpufreq_enable_boost_support (); -if (ret) { -dev_warn (cpu_dev,"failed to enable boost: %d\n" , ret); - }else { - apple_soc_cpufreq_driver.boost_enabled = true; - } - } -return 0 ; out_free_cpufreq_table:
@@ -353,6 +344,7 @@ static struct cpufreq_driver apple_soc_cpufreq_driver = { .target_index = apple_soc_cpufreq_set_target, .fast_switch = apple_soc_cpufreq_fast_switch, .register_em = cpufreq_register_em_with_opp, + .set_boost = cpufreq_boost_set_sw, .suspend = cpufreq_generic_suspend, };
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 9/15 cpufreq: loongson: Set .set_boost directly
In reply to Viresh KumarThe boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently the driver enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Instead set the .set_boost field directly and always enable the boost support. If a policy doesn't support boost feature, the core will not enable it for that policy.
Keep the initial state of driver level boost to disabled and let the user enable it if required as ideally the boost frequencies must be used only when really required.
--- drivers/cpufreq/loongson3_cpufreq.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/cpufreq/loongson3_cpufreq.c +1 -9
@@ -299,15 +299,6 @@ static int loongson3_cpufreq_cpu_init(struct cpufreq_policy *policy)per_cpu (freq_data, i) =per_cpu (freq_data, cpu); } -if (policy_has_boost_freq (policy)) { - ret =cpufreq_enable_boost_support (); -if (ret <0 ) { -pr_warn ("cpufreq: Failed to enable boost: %d\n" , ret); -return ret; - } - loongson3_cpufreq_driver.boost_enabled = true; - } -return 0 ; }
@@ -338,6 +329,7 @@ static struct cpufreq_driver loongson3_cpufreq_driver = { .get = loongson3_cpufreq_get, .target_index = loongson3_cpufreq_target, .verify = cpufreq_generic_frequency_table_verify, + .set_boost = cpufreq_boost_set_sw, .suspend = cpufreq_generic_suspend, };
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 10/15 cpufreq: powernv: Set .set_boost directly
In reply to Viresh KumarThe boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently the driver enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Instead set the .set_boost field directly and always enable the boost support. If a policy doesn't support boost feature, the core will not enable it for that policy.
Keep the initial state of driver level boost to disabled and let the user enable it if required as ideally the boost frequencies must be used only when really required.
--- drivers/cpufreq/powernv-cpufreq.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +1 -4
@@ -1125,7 +1125,7 @@ static int __init powernv_cpufreq_init(void) goto out;if (powernv_pstate_info.wof_enabled) - powernv_cpufreq_driver.boost_enabled = true; + powernv_cpufreq_driver.set_boost = cpufreq_boost_set_sw;else powernv_cpu_freq_attr[SCALING_BOOST_FREQS_ATTR_INDEX ] =NULL ;
@@ -1135,9 +1135,6 @@ static int __init powernv_cpufreq_init(void) goto cleanup; } -if (powernv_pstate_info.wof_enabled) -cpufreq_enable_boost_support (); -register_reboot_notifier (&powernv_cpufreq_reboot_nb);opal_message_notifier_register (OPAL_MSG_OCC , &powernv_cpufreq_opal_nb);
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 11/15 cpufreq: scmi: Set .set_boost directly
In reply to Viresh KumarThe boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently the driver enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Instead set the .set_boost field directly and always enable the boost support. If a policy doesn't support boost feature, the core will not enable it for that policy.
Keep the initial state of driver level boost to disabled and let the user enable it if required as ideally the boost frequencies must be used only when really required.
--- drivers/cpufreq/scmi-cpufreq.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/cpufreq/scmi-cpufreq.c +1 -10
@@ -297,16 +297,6 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy) policy->transition_delay_us =scmi_get_rate_limit (domain, policy->fast_switch_possible); -if (policy_has_boost_freq (policy)) { - ret =cpufreq_enable_boost_support (); -if (ret) { -dev_warn (cpu_dev,"failed to enable boost: %d\n" , ret); - goto out_free_table; - }else { - scmi_cpufreq_driver.boost_enabled = true; - } - } - ret =freq_qos_add_request (&policy->constraints, &priv->limits_freq_req,FREQ_QOS_MAX ,FREQ_QOS_MAX_DEFAULT_VALUE );if (ret <0 ) {
@@ -394,6 +384,7 @@ static struct cpufreq_driver scmi_cpufreq_driver = { .init = scmi_cpufreq_init, .exit = scmi_cpufreq_exit, .register_em = scmi_cpufreq_register_em, + .set_boost = cpufreq_boost_set_sw, };static int scmi_cpufreq_probe (struct scmi_device *sdev)
Signature · 1 line
2.31.1.272.g89b43f80a514
Re: [PATCH 11/15] cpufreq: scmi: Set .set_boost directly
Quoted 8 lines · Viresh Kumar
The boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently the driver enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Quoted 8 lines
Instead set the .set_boost field directly and always enable the boost support. If a policy doesn't support boost feature, the core will not enable it for that policy.
Keep the initial state of driver level boost to disabled and let the user enable it if required as ideally the boost frequencies must be used only when really required.
Signature · 2 lines
Regards, Sudeep
Viresh Kumar
maintainerPATCH 12/15 cpufreq: dt: Set .set_boost directly
In reply to Viresh KumarThe boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently the driver enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Instead set the .set_boost field directly and always enable the boost support. If a policy doesn't support boost feature, the core will not enable it for that policy.
Keep the initial state of driver level boost to disabled and let the user enable it if required as ideally the boost frequencies must be used only when really required.
--- drivers/cpufreq/cpufreq-dt.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/cpufreq/cpufreq-dt.c +1 -13
@@ -114,20 +114,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) policy->cpuinfo.transition_latency = transition_latency; policy->dvfs_possible_from_any_cpu = true; -/* Support turbo/boost mode */ -if (policy_has_boost_freq (policy)) { -/* This gets disabled by core on driver unregister */ - ret =cpufreq_enable_boost_support (); -if (ret) - goto out_clk_put; - } -return 0 ; - -out_clk_put: -clk_put (cpu_clk); - -return ret; }static int cpufreq_online (struct cpufreq_policy *policy)
@@ -162,6 +149,7 @@ static struct cpufreq_driver dt_cpufreq_driver = { .offline = cpufreq_offline, .register_em = cpufreq_register_em_with_opp, .name = "cpufreq-dt", + .set_boost = cpufreq_boost_set_sw, .suspend = cpufreq_generic_suspend, };
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 13/15 cpufreq: qcom: Set .set_boost directly
In reply to Viresh KumarThe boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently the driver enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Instead set the .set_boost field directly and always enable the boost support. If a policy doesn't support boost feature, the core will not enable it for that policy.
Keep the initial state of driver level boost to disabled and let the user enable it if required as ideally the boost frequencies must be used only when really required.
--- drivers/cpufreq/qcom-cpufreq-hw.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/cpufreq/qcom-cpufreq-hw.c +1 -6
@@ -566,12 +566,6 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)return -ENODEV ; } -if (policy_has_boost_freq (policy)) { - ret =cpufreq_enable_boost_support (); -if (ret) -dev_warn (cpu_dev,"failed to enable boost: %d\n" , ret); - } -return qcom_cpufreq_hw_lmh_init (policy, index); }
@@ -610,6 +604,7 @@ static struct cpufreq_driver cpufreq_qcom_hw_driver = { .fast_switch = qcom_cpufreq_hw_fast_switch, .name = "qcom-cpufreq-hw", .ready = qcom_cpufreq_ready, + .set_boost = cpufreq_boost_set_sw, };static unsigned long qcom_cpufreq_hw_recalc_rate (struct clk_hw *hw,unsigned long parent_rate)
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 14/15 cpufreq: staticize policy_has_boost_freq()
In reply to Viresh Kumarpolicy_has_boost_freq() isn't used outside of freq_table.c now, mark it static.
--- drivers/cpufreq/freq_table.c | 3 +-- include/linux/cpufreq.h | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-)
drivers/cpufreq/freq_table.c +1 -2
@@ -14,7 +14,7 @@* FREQUENCY TABLE HELPERS * *********************************************************************/ -bool policy_has_boost_freq (struct cpufreq_policy *policy) +static bool policy_has_boost_freq (struct cpufreq_policy *policy) {struct cpufreq_frequency_table *pos, *table = policy->freq_table;
@@ -27,7 +27,6 @@ bool policy_has_boost_freq(struct cpufreq_policy *policy)return false; } -EXPORT_SYMBOL_GPL (policy_has_boost_freq);int cpufreq_frequency_table_cpuinfo (struct cpufreq_policy *policy,struct cpufreq_frequency_table *table)
include/linux/cpufreq.h +0 -6
@@ -783,7 +783,6 @@ ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);#ifdef CONFIG_CPU_FREQ bool cpufreq_boost_enabled (void );int cpufreq_enable_boost_support (void ); -bool policy_has_boost_freq (struct cpufreq_policy *policy);int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state);/* Find lowest freq at or above target in a table in ascending order */
@@ -1163,11 +1162,6 @@ static inline int cpufreq_enable_boost_support(void)return -EINVAL ; } -static inline bool policy_has_boost_freq (struct cpufreq_policy *policy) -{ -return false; -} -static inline int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state) {return -EOPNOTSUPP ;
Signature · 1 line
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerPATCH 15/15 cpufreq: Remove cpufreq_enable_boost_support()
In reply to Viresh KumarRemove the now unused helper, cpufreq_enable_boost_support().
--- drivers/cpufreq/cpufreq.c | 15 --------------- include/linux/cpufreq.h | 6 ------ 2 files changed, 21 deletions(-)
drivers/cpufreq/cpufreq.c +0 -15
@@ -2876,21 +2876,6 @@ static void remove_boost_sysfs_file(void)sysfs_remove_file (cpufreq_global_kobject, &boost.attr); } -int cpufreq_enable_boost_support (void ) -{ -if (!cpufreq_driver) -return -EINVAL ; - -if (cpufreq_boost_supported ()) -return 0 ; - - cpufreq_driver->set_boost = cpufreq_boost_set_sw; - -/* This will get removed on driver unregister */ -return create_boost_sysfs_file (); -} -EXPORT_SYMBOL_GPL (cpufreq_enable_boost_support); -bool cpufreq_boost_enabled (void ) {return cpufreq_driver->boost_enabled;
include/linux/cpufreq.h +0 -6
@@ -782,7 +782,6 @@ ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);#ifdef CONFIG_CPU_FREQ bool cpufreq_boost_enabled (void ); -int cpufreq_enable_boost_support (void );int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state);/* Find lowest freq at or above target in a table in ascending order */
@@ -1157,11 +1156,6 @@ static inline bool cpufreq_boost_enabled(void)return false; } -static inline int cpufreq_enable_boost_support (void ) -{ -return -EINVAL ; -} -static inline int cpufreq_boost_set_sw (struct cpufreq_policy *policy,int state) {return -EOPNOTSUPP ;
Signature · 1 line
2.31.1.272.g89b43f80a514
Rafael J. Wysocki
maintainerQuoted 11 lines · Viresh Kumar
Hello,
The boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently most of the drivers enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Quoted 5 lines
Also it is possible to have a scenario where not all cpufreq policies support boost frequencies. And letting sysfs (or other parts of the kernel) enable boost feature for that policy isn't correct.
Simplify and cleanup handling of boost to solve these issues.
I guess this depends on the previous series?
Quoted 41 lines
Pushed here:
git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.gitcpufreq/boostRebased over few dependencies from PM tree, will push to the arm-cpufreq tree after merge window is closed.
Viresh Kumar (15):
cpufreq: staticizecpufreq_boost_trigger_state()
cpufreq: Exportcpufreq_boost_set_sw()
cpufreq: Introducepolicy->boost_supportedflag
cpufreq: acpi: Setpolicy->boost_supported
cpufreq: amd: Setpolicy->boost_supported
cpufreq: cppc: Setpolicy->boost_supported
cpufreq: Restrict enabling boost on policies with no boost frequencies
cpufreq: apple: Set .set_boost directly
cpufreq: loongson: Set .set_boost directly
cpufreq: powernv: Set .set_boost directly
cpufreq: scmi: Set .set_boost directly
cpufreq: dt: Set .set_boost directly
cpufreq: qcom: Set .set_boost directly
cpufreq: staticizepolicy_has_boost_freq()
cpufreq: Removecpufreq_enable_boost_support()drivers/cpufreq/acpi-cpufreq.c | 3 +++ drivers/cpufreq/amd-pstate.c | 4 ++-- drivers/cpufreq/apple-soc-cpufreq.c | 10 +--------- drivers/cpufreq/cppc_cpufreq.c | 9 +-------- drivers/cpufreq/cpufreq-dt.c | 14 +------------- drivers/cpufreq/cpufreq.c | 30 ++++++++++++----------------- drivers/cpufreq/freq_table.c | 7 +++++-- drivers/cpufreq/loongson3_cpufreq.c | 10 +--------- drivers/cpufreq/powernv-cpufreq.c | 5 +---- drivers/cpufreq/qcom-cpufreq-hw.c | 7 +------ drivers/cpufreq/scmi-cpufreq.c | 11 +---------- include/linux/cpufreq.h | 20 ++++++------------- 12 files changed, 35 insertions(+), 95 deletions(-)--
2.31.1.272.g89b43f80a514
Viresh Kumar
maintainerQuoted 12 lines · Rafael J. Wysocki
Quoted 11 lines · Viresh Kumar
Hello,
The boost feature can be controlled at two levels currently, driver level (applies to all policies) and per-policy.
Currently most of the drivers enables driver level boost support from the per-policy ->init() callback, which isn't really efficient as that gets called for each policy and then there is online/offline path too where this gets done unnecessarily.
Quoted 7 lines
Quoted 5 lines
Also it is possible to have a scenario where not all cpufreq policies support boost frequencies. And letting sysfs (or other parts of the kernel) enable boost feature for that policy isn't correct.
Simplify and cleanup handling of boost to solve these issues.
I guess this depends on the previous series?
Yes my series and the boost related patches in your tree.
Signature · 1 line
viresh