cpufreq: Fix per-policy boost behavior after CPU hotplug
PATCH v2 1/1 cpufreq: Fix per-policy boost behavior after CPU hotplug
This patch fixes the behavior of the cpufreq boost when the global boost flag is toggled during CPU hotplug offline. This action previously led to incorrect scaling_max_freq values when the CPU was brought back online. The issue also manifested as incorrect scaling_cur_freq under the performance governor.
For example, after the following operations, even if the global boost is disabled, the resulting scaling_max_freq and scaling_cur_freq will still reflect the settings of an enabled boost.
$ echo performance > /sys/devices/system/cpu/cpufreq/policy7/scaling_governor $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_cur_freq 3200000 $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_max_freq 3200000
$ echo 1 > /sys/devices/system/cpu/cpufreq/boost $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_cur_freq 3250000 $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_max_freq 3250000
$ echo 0 > /sys/devices/system/cpu/cpu7/online $ echo 0 > /sys/devices/system/cpu/cpufreq/boost $ echo 1 > /sys/devices/system/cpu/cpu7/online $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_cur_freq 3250000 $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_max_freq 3250000
---
V1 -> V2: Adjusted log messages and fixed build error.
Link:
https://lore.kernel.org/all/[email protected]/
--- drivers/cpufreq/cpufreq.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/cpufreq/cpufreq.c +29 -0
@@ -1495,6 +1495,35 @@ static int cpufreq_online(unsigned int cpu)blocking_notifier_call_chain (&cpufreq_policy_notifier_list,CPUFREQ_CREATE_POLICY , policy); + }else { +/* +* Call freq_qos_update_request() for the per-policy boost flag mirror +* the cpufreq_driver boost during hotplug online. +* Register an online callback if the default mirroring of the global +* boost setting is not intended. +*/ +if (!cpufreq_driver->online) { + ret =freq_qos_update_request (policy->max_freq_req, policy->max); +if (ret) +pr_err ("%s: freq qos update failed\n" , __func__); + }else { +/* +* Let the per-policy boost flag mirror the cpufreq_driver +* boost if an illegal state occurs after hotplug +*/ +if (policy->boost_enabled && !cpufreq_driver->boost_enabled) { +pr_info ("%s: local boost flag mirror the global boost\n" , + __func__); + policy->boost_enabled = cpufreq_driver->boost_enabled; + ret = cpufreq_driver->set_boost (policy, + cpufreq_driver->boost_enabled); +if (ret) { + policy->boost_enabled = !policy->boost_enabled; +pr_err ("%s: Failed to mirror the global boost flag\n" , + __func__); + } + } + } }if (cpufreq_driver->get &&has_target ()) {
Signature · 1 line
2.18.0
Viresh Kumar
maintainerQuoted 22 lines · PoShao Chen
This patch fixes the behavior of the cpufreq boost when the global boost flag is toggled during CPU hotplug offline. This action previously led to incorrect
scaling_max_freqvalues when the CPU was brought back online. The issue also manifested as incorrectscaling_cur_frequnder the performance governor.For example, after the following operations, even if the global boost is disabled, the resulting
scaling_max_freqandscaling_cur_freqwill still reflect the settings of an enabled boost.$ echo performance > /sys/devices/system/cpu/cpufreq/policy7/scaling_governor $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_cur_freq 3200000 $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_max_freq 3200000$ echo 1 > /sys/devices/system/cpu/cpufreq/boost $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_cur_freq 3250000 $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_max_freq 3250000
Quoted 7 lines
$ echo 0 > /sys/devices/system/cpu/cpu7/online $ echo 0 > /sys/devices/system/cpu/cpufreq/boost $ echo 1 > /sys/devices/system/cpu/cpu7/online $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_cur_freq 3250000 $ cat /sys/devices/system/cpu/cpufreq/policy7/scaling_max_freq 3250000
Please try this instead:
drivers/cpufreq/cpufreq.c +4 -1
@@ -43,6 +43,9 @@ static LIST_HEAD(cpufreq_policy_list);#define for_each_inactive_policy (__policy) \ for_each_suitable_policy(__policy, false) +#define for_each_policy (__policy) \ + list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) +/* Iterate over governors */ static LIST_HEAD (cpufreq_governor_list);#define for_each_governor (__governor) \
@@ -2815,7 +2818,7 @@ int cpufreq_boost_trigger_state(int state)write_unlock_irqrestore (&cpufreq_driver_lock, flags);cpus_read_lock (); -for_each_active_policy (policy) { +for_each_policy (policy) { policy->boost_enabled = state; ret = cpufreq_driver->set_boost (policy, state);if (ret) {
Signature · 1 line
viresh
Quoted 29 lines · Viresh Kumar
Please try this instead:
drivers/cpufreq/cpufreq.c +3
-0@@ -43,6 +43,9 @@ static LIST_HEAD(cpufreq_policy_list);#define for_each_inactive_policy (__policy) \ for_each_suitable_policy(__policy, false) +#define for_each_policy (__policy) \ + list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) +/* Iterate over governors */ static LIST_HEAD (cpufreq_governor_list );#define
for_each_governor(__governor)\drivers/cpufreq/cpufreq.c +1
-1@@ -2815,7 +2818,7 @@ int cpufreq_boost_trigger_state(int state)write_unlock_irqrestore (&cpufreq_driver_lock, flags);cpus_read_lock (); -for_each_active_policy (policy) { +for_each_policy (policy) { policy->boost_enabled = state; ret = cpufreq_driver->set_boost (policy, state);if (ret) {Signature · 2 lines
-- viresh
Thank you for the suggestion. However, calling ->set_boost when the policy is inactive will fail in two ways:
1. policy->freq_table will be NULL.
2. freq_qos_update_request will fail to refresh the frequency limit.
Signature · 1 line
poshao
Viresh Kumar
maintainerQuoted 31 lines · PoShao Chen
Quoted 18 lines · Viresh Kumar
Please try this instead:
drivers/cpufreq/cpufreq.c +3
-0@@ -43,6 +43,9 @@ static LIST_HEAD(cpufreq_policy_list);#define for_each_inactive_policy (__policy) \ for_each_suitable_policy(__policy, false) +#define for_each_policy (__policy) \ + list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) +/* Iterate over governors */ static LIST_HEAD (cpufreq_governor_list );#define
for_each_governor(__governor)\drivers/cpufreq/cpufreq.c int cpufreq_boost_trigger_state(int state) · line 2824
Quoted 8 lines
drivers/cpufreq/cpufreq.c +1
-1@@ -2815,7 +2818,7 @@ int cpufreq_boost_trigger_state(int state)write_unlock_irqrestore (&cpufreq_driver_lock, flags);cpus_read_lock (); -for_each_active_policy (policy) { +for_each_policy (policy) { policy->boost_enabled = state; ret = cpufreq_driver->set_boost (policy, state);if (ret) {Thank you for the suggestion. However, calling ->set_boost when the policy is inactive will fail in two ways:
Quoted 2 lines
1.
policy->freq_tablewill be NULL.
2.freq_qos_update_requestwill fail to refresh the frequency limit.
What about just this then ?
drivers/cpufreq/cpufreq.c +3 -3
@@ -1430,9 +1430,6 @@ static int cpufreq_online(unsigned int cpu) goto out_free_policy; } -/* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ - policy->boost_enabled =cpufreq_boost_enabled () &&policy_has_boost_freq (policy); -/* * The initialization has succeeded and the policy is online. * If there is a problem with its frequency table, take it
@@ -1446,6 +1443,9 @@ static int cpufreq_online(unsigned int cpu)cpumask_copy (policy->related_cpus, policy->cpus); } +/* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ + policy->boost_enabled =cpufreq_boost_enabled () &&policy_has_boost_freq (policy); +/* * affected cpus must always be the one, which are online. We aren't * managing offline cpus here.
So the cpufreq core sets the policy boost to whatever the global boost is at the time CPU comes online.
This won't call cppc_cpufreq_set_boost() (I think that's the driver you are using ?) though. The freq_qos_update_request() thing we do there is driver specific and the driver itself needs to take care of this, perhaps in the online() callback.
Signature · 1 line
viresh