cpufreq: transition-latency cleanups
Subsystems (3)
Viresh Kumar
maintainercover cpufreq: transition-latency cleanups
Hi,
This series tries to cleanup the code around transition-latency and its users. Some of the old legacy code, which may not make much sense now, is being dropped as.
Some code consolidation also happens across governors.
Based of: pm/linux-next
Tested on: ARM64 Hikey board.
--
viresh
Viresh Kumar (6):
cpufreq: Don't check for max_transition_latency
cpufreq: Remove (now) unused code related to max_transition_latency
cpufreq: governor: Drop min_sampling_rate
cpufreq: Use transition_delay_us for legacy governors as well
cpufreq: Cap the default transition delay value to 10 ms
cpufreq: arm_big_little: Make ->get_transition_latency() mandatory
Documentation/admin-guide/pm/cpufreq.rst | 8 -------- drivers/cpufreq/arm_big_little.c | 10 ++++----- drivers/cpufreq/cpufreq.c | 19 ----------------- drivers/cpufreq/cpufreq_conservative.c | 6 ------ drivers/cpufreq/cpufreq_governor.c | 17 ++-------------- drivers/cpufreq/cpufreq_governor.h | 2 -- drivers/cpufreq/cpufreq_ondemand.c | 12 ----------- drivers/cpufreq/cpufreq_performance.c | 6 ------ include/linux/cpufreq.h | 35 +++++++++++++++++++++++--------- kernel/sched/cpufreq_schedutil.c | 11 +--------- 10 files changed, 32 insertions(+), 94 deletions(-)
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Viresh Kumar
maintainerPATCH 1/6 cpufreq: Don't check for max_transition_latency
This check is there only for drivers that set transition_latency to CPUFREQ_ETERNAL. And the "max_transition_latency" field is only set for ondemand and conservative governors (i.e. This code doesn't run for schedutil governor).
With CPUFREQ_ETERNAL, transition latency becomes around 4 seconds (yeah its practically impossible). But even then there is nothing particular in the governor's code that will not function if the latency is over 10ms (TRANSITION_LATENCY_LIMIT). Why disable use of the governor completely ?
And if its about falling back to the performance governor for such platforms, then we aren't doing the same for schedutil governor.
This patch get rids of this particular check and let platforms decide if they want to use legacy governors or not.
--- drivers/cpufreq/cpufreq.c | 14 -------------- include/linux/cpufreq.h | 3 --- 2 files changed, 17 deletions(-)
drivers/cpufreq/cpufreq.c +0 -14
@@ -1988,20 +1988,6 @@ static int cpufreq_init_governor(struct cpufreq_policy *policy)if (!policy->governor)return -EINVAL ; -if (policy->governor->max_transition_latency && - policy->cpuinfo.transition_latency > - policy->governor->max_transition_latency) { -struct cpufreq_governor *gov =cpufreq_fallback_governor (); - -if (gov) { -pr_warn ("%s governor failed, too long transition latency of HW, fallback to %s governor\n" , - policy->governor->name, gov->name); - policy->governor = gov; - }else { -return -EINVAL ; - } - } -if (!try_module_get (policy->governor->owner))return -EINVAL ;
include/linux/cpufreq.h +0 -3
@@ -487,9 +487,6 @@ static inline unsigned long cpufreq_scale(unsigned long old, u_int div,* polling frequency is 1000 times the transition latency of the processor. The * ondemand governor will work on any processor with transition latency <= 10ms, * using appropriate sampling rate. -* -* For CPUs with transition latency > 10ms (mostly drivers with CPUFREQ_ETERNAL) -* the ondemand governor will not work. All times here are in us (microseconds). */ #define MIN_SAMPLING_RATE_RATIO (2)#define LATENCY_MULTIPLIER (1000)
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Viresh Kumar
maintainerPATCH 2/6 cpufreq: Remove (now) unused code related to max_transition_latency
In reply to Viresh KumarGet rid of the now unused code after the only user of max_transition_latency is gone.
--- drivers/cpufreq/cpufreq.c | 5 ----- drivers/cpufreq/cpufreq_governor.h | 1 - drivers/cpufreq/cpufreq_performance.c | 6 ------ include/linux/cpufreq.h | 5 ----- 4 files changed, 17 deletions(-)
drivers/cpufreq/cpufreq.c +0 -5
@@ -1969,11 +1969,6 @@ int cpufreq_driver_target(struct cpufreq_policy *policy, }EXPORT_SYMBOL_GPL (cpufreq_driver_target); -__weak struct cpufreq_governor *cpufreq_fallback_governor (void ) -{ -return NULL ; -} -static int cpufreq_init_governor (struct cpufreq_policy *policy) {int ret;
drivers/cpufreq/cpufreq_governor.h +0 -1
@@ -160,7 +160,6 @@ void cpufreq_dbs_governor_limits(struct cpufreq_policy *policy);#define CPUFREQ_DBS_GOVERNOR_INITIALIZER (_name_) \ { \ .name = _name_, \ - .max_transition_latency = TRANSITION_LATENCY_LIMIT, \ .owner = THIS_MODULE, \ .init = cpufreq_dbs_governor_init, \ .exit = cpufreq_dbs_governor_exit, \
drivers/cpufreq/cpufreq_performance.c +0 -6
@@ -44,12 +44,6 @@ struct cpufreq_governor *cpufreq_default_governor(void) return &cpufreq_gov_performance; }#endif -#ifndef CONFIG_CPU_FREQ_GOV_PERFORMANCE_MODULE -struct cpufreq_governor *cpufreq_fallback_governor (void ) -{ -return &cpufreq_gov_performance; -} -#endif MODULE_AUTHOR ("Dominik Brodowski <[email protected]>" );MODULE_DESCRIPTION ("CPUfreq policy governor 'performance'" );
include/linux/cpufreq.h +0 -5
@@ -491,7 +491,6 @@ static inline unsigned long cpufreq_scale(unsigned long old, u_int div,#define MIN_SAMPLING_RATE_RATIO (2)#define LATENCY_MULTIPLIER (1000)#define MIN_LATENCY_MULTIPLIER (20) -#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)struct cpufreq_governor {char name[CPUFREQ_NAME_LEN ];
@@ -504,9 +503,6 @@ struct cpufreq_governor { char *buf);int (*store_setspeed) (struct cpufreq_policy *policy,unsigned int freq); -unsigned int max_transition_latency;/* HW must be able to switch to -next freq faster than this value in nano secs or we -will fallback to performance governor */ struct list_head governor_list;struct module *owner; };
@@ -526,7 +522,6 @@ int cpufreq_register_governor(struct cpufreq_governor *governor);void cpufreq_unregister_governor (struct cpufreq_governor *governor);struct cpufreq_governor *cpufreq_default_governor (void ); -struct cpufreq_governor *cpufreq_fallback_governor (void );static inline void cpufreq_policy_apply_limits (struct cpufreq_policy *policy) {
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Viresh Kumar
maintainerPATCH 3/6 cpufreq: governor: Drop min_sampling_rate
In reply to Viresh KumarThe cpufreq core and governors aren't supposed to set a limit on how fast we want to try changing the frequency. This is currently done for the legacy governors with help of min_sampling_rate.
At worst, we may end up setting the sampling rate to a value lower than the rate at which frequency can be changed and then one of the CPUs in the policy will be only changing frequency for ever.
But that is something for the user to decide and there is no need to have special handling for such cases in the core. Leave it for the user to figure out.
--- Documentation/admin-guide/pm/cpufreq.rst | 8 -------- drivers/cpufreq/cpufreq_conservative.c | 6 ------ drivers/cpufreq/cpufreq_governor.c | 10 ++-------- drivers/cpufreq/cpufreq_governor.h | 1 - drivers/cpufreq/cpufreq_ondemand.c | 12 ------------ include/linux/cpufreq.h | 2 -- 6 files changed, 2 insertions(+), 37 deletions(-)
Documentation/admin-guide/pm/cpufreq.rst +0 -8
@@ -471,14 +471,6 @@ it is allowed to use (the ``scaling_max_freq`` policy limit). # echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) > ondemand/sampling_rate - -``min_sampling_rate`` - The minimum value of ``sampling_rate``. - - Equal to 10000 (10 ms) if :c:macro:`CONFIG_NO_HZ_COMMON` and - :c:data:`tick_nohz_active` are both set or to 20 times the value of - :c:data:`jiffies` in microseconds otherwise. - ``up_threshold`` If the estimated CPU load is above this value (in percent), the governor will set the frequency to the maximum value allowed for the policy.
drivers/cpufreq/cpufreq_conservative.c +0 -6
@@ -246,7 +246,6 @@ gov_show_one_common(sampling_rate);gov_show_one_common (sampling_down_factor);gov_show_one_common (up_threshold);gov_show_one_common (ignore_nice_load); -gov_show_one_common (min_sampling_rate);gov_show_one (cs, down_threshold);gov_show_one (cs, freq_step);
@@ -254,12 +253,10 @@ gov_attr_rw(sampling_rate);gov_attr_rw (sampling_down_factor);gov_attr_rw (up_threshold);gov_attr_rw (ignore_nice_load); -gov_attr_ro (min_sampling_rate);gov_attr_rw (down_threshold);gov_attr_rw (freq_step);static struct attribute *cs_attributes[] = { - &min_sampling_rate.attr, &sampling_rate.attr, &sampling_down_factor.attr, &up_threshold.attr,
@@ -297,10 +294,7 @@ static int cs_init(struct dbs_data *dbs_data) dbs_data->up_threshold =DEF_FREQUENCY_UP_THRESHOLD ; dbs_data->sampling_down_factor =DEF_SAMPLING_DOWN_FACTOR ; dbs_data->ignore_nice_load =0 ; - dbs_data->tuners = tuners; - dbs_data->min_sampling_rate =MIN_SAMPLING_RATE_RATIO * -jiffies_to_usecs (10 );return 0 ; }
drivers/cpufreq/cpufreq_governor.c +2 -8
@@ -47,14 +47,11 @@ ssize_t store_sampling_rate(struct gov_attr_set *attr_set, const char *buf, {struct dbs_data *dbs_data =to_dbs_data (attr_set);struct policy_dbs_info *policy_dbs; -unsigned int rate;int ret; - ret =sscanf (buf,"%u" , &rate); + ret =sscanf (buf,"%u" , &dbs_data->sampling_rate);if (ret !=1 )return -EINVAL ; - dbs_data->sampling_rate =max (rate, dbs_data->min_sampling_rate); -/* * We are operating under dbs_data->mutex and so the list and its * entries can't be freed concurrently.
@@ -437,10 +434,7 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy) latency =1 ;/* Bring kernel and HW constraints together */ - dbs_data->min_sampling_rate =max (dbs_data->min_sampling_rate, -MIN_LATENCY_MULTIPLIER * latency); - dbs_data->sampling_rate =max (dbs_data->min_sampling_rate, -LATENCY_MULTIPLIER * latency); + dbs_data->sampling_rate =LATENCY_MULTIPLIER * latency;if (!have_governor_per_policy ()) gov->gdbs_data = dbs_data;
drivers/cpufreq/cpufreq_governor.h +0 -1
@@ -41,7 +41,6 @@ enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE};struct dbs_data {struct gov_attr_set attr_set;void *tuners; -unsigned int min_sampling_rate;unsigned int ignore_nice_load;unsigned int sampling_rate;unsigned int sampling_down_factor;
drivers/cpufreq/cpufreq_ondemand.c +0 -12
@@ -319,7 +319,6 @@ gov_show_one_common(sampling_rate);gov_show_one_common (up_threshold);gov_show_one_common (sampling_down_factor);gov_show_one_common (ignore_nice_load); -gov_show_one_common (min_sampling_rate);gov_show_one_common (io_is_busy);gov_show_one (od, powersave_bias);
@@ -329,10 +328,8 @@ gov_attr_rw(up_threshold);gov_attr_rw (sampling_down_factor);gov_attr_rw (ignore_nice_load);gov_attr_rw (powersave_bias); -gov_attr_ro (min_sampling_rate);static struct attribute *od_attributes[] = { - &min_sampling_rate.attr, &sampling_rate.attr, &up_threshold.attr, &sampling_down_factor.attr,
@@ -373,17 +370,8 @@ static int od_init(struct dbs_data *dbs_data)if (idle_time !=-1ULL ) {/* Idle micro accounting is supported. Use finer thresholds */ dbs_data->up_threshold =MICRO_FREQUENCY_UP_THRESHOLD ; -/* -* In nohz/micro accounting case we set the minimum frequency -* not depending on HZ, but fixed (very low). -*/ - dbs_data->min_sampling_rate =MICRO_FREQUENCY_MIN_SAMPLE_RATE ; }else { dbs_data->up_threshold =DEF_FREQUENCY_UP_THRESHOLD ; - -/* For correct statistics, we need 10 ticks for each measure */ - dbs_data->min_sampling_rate =MIN_SAMPLING_RATE_RATIO * -jiffies_to_usecs (10 ); } dbs_data->sampling_down_factor =DEF_SAMPLING_DOWN_FACTOR ;
include/linux/cpufreq.h +0 -2
@@ -488,9 +488,7 @@ static inline unsigned long cpufreq_scale(unsigned long old, u_int div,* ondemand governor will work on any processor with transition latency <= 10ms, * using appropriate sampling rate. */ -#define MIN_SAMPLING_RATE_RATIO (2)#define LATENCY_MULTIPLIER (1000) -#define MIN_LATENCY_MULTIPLIER (20)struct cpufreq_governor {char name[CPUFREQ_NAME_LEN ];
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Re: [PATCH 3/6] cpufreq: governor: Drop min_sampling_rate
Quoted 7 lines · Viresh Kumar
The cpufreq core and governors aren't supposed to set a limit on how fast we want to try changing the frequency. This is currently done for the legacy governors with help of
min_sampling_rate.At worst, we may end up setting the sampling rate to a value lower than the rate at which frequency can be changed and then one of the CPUs in the policy will be only changing frequency for ever.
Is it safe to issue requests to change the CPU frequency so frequently, even on historic hardware such as speedstep-{ich,smi,centrino}? In the past, these checks more or less disallowed the running of dynamic frequency scaling at least on speedstep-smi[*], but maybe on a few other platforms as well. That's why I am curious on whether this may break systems potentially on a hardware level if the hardware was not designed to do dynamic frequency scaling (and not just frequency switches on battery/AC).
Best,
Dominik
Viresh Kumar
maintainerRe: [PATCH 3/6] cpufreq: governor: Drop min_sampling_rate
Quoted 10 lines · Dominik Brodowski
Quoted 7 lines · Viresh Kumar
The cpufreq core and governors aren't supposed to set a limit on how fast we want to try changing the frequency. This is currently done for the legacy governors with help of
min_sampling_rate.At worst, we may end up setting the sampling rate to a value lower than the rate at which frequency can be changed and then one of the CPUs in the policy will be only changing frequency for ever.
Is it safe to issue requests to change the CPU frequency so frequently,
Well, I assumed so. I am not sure the hardware would break though. Overheating ?
Quoted 4 lines
even
on historic hardware such as speedstep-{ich,smi,centrino}? In the past, these checks more or less disallowed the running of dynamic frequency scaling at least on speedstep-smi[*],
We must by doing dynamic freq scaling even without this patch. I don't see why you say the above then.
All we do here is that we get rid of the limit on how soon we can change the freq again.
Quoted 4 lines
but maybe on a few other platforms as
well. That's why I am curious on whether this may break systems potentially on a hardware level if the hardware was not designed to do dynamic frequency scaling (and not just frequency switches on battery/AC).
Honestly I am not sure if any hardware can break or not, just because of this commit.
Signature · 1 line
viresh
Re: [PATCH 3/6] cpufreq: governor: Drop min_sampling_rate
Quoted 20 lines · Viresh Kumar
Quoted 10 lines · Dominik Brodowski
Quoted 7 lines · Viresh Kumar
The cpufreq core and governors aren't supposed to set a limit on how fast we want to try changing the frequency. This is currently done for the legacy governors with help of
min_sampling_rate.At worst, we may end up setting the sampling rate to a value lower than the rate at which frequency can be changed and then one of the CPUs in the policy will be only changing frequency for ever.
Is it safe to issue requests to change the CPU frequency so frequently,
Well, I assumed so. I am not sure the hardware would break though. Overheating ?
Quoted 4 lines
even
on historic hardware such as speedstep-{ich,smi,centrino}? In the past, these checks more or less disallowed the running of dynamic frequency scaling at least on speedstep-smi[*],
Quoted 5 lines
We must by doing dynamic freq scaling even without this patch. I don't see why you say the above then.
All we do here is that we get rid of the limit on how soon we can change the freq again.
Well, as I understand it, first generation "speedstep" was designed more or less to switch frequencies only when AC power was lost or restored.
The Linux implementation merely said: "no on-the-fly changes", but switch frequencies whenever a user explicitly requested such a change (presumably only every once in an unspecified while).
This same reasoning may be present in other drivers using CPUFREQ_ETERNAL.
Quoted 7 lines
Quoted 4 lines
but maybe on a few other platforms as
well. That's why I am curious on whether this may break systems potentially on a hardware level if the hardware was not designed to do dynamic frequency scaling (and not just frequency switches on battery/AC).Honestly I am not sure if any hardware can break or not, just because of this commit.
I am not *sure* either, I am just worried of the consequences of doing things out-of-spec...
Best
Dominik
Viresh Kumar
maintainerRe: [PATCH 3/6] cpufreq: governor: Drop min_sampling_rate
Quoted 11 lines · Dominik Brodowski
Quoted 10 lines · Viresh Kumar
Quoted 9 lines · Dominik Brodowski
Quoted 7 lines · Viresh Kumar
The cpufreq core and governors aren't supposed to set a limit on how fast we want to try changing the frequency. This is currently done for the legacy governors with help of
min_sampling_rate.At worst, we may end up setting the sampling rate to a value lower than the rate at which frequency can be changed and then one of the CPUs in the policy will be only changing frequency for ever.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Is it safe to issue requests to change the CPU frequency so frequently,
Well, I assumed so. I am not sure the hardware would break though. Overheating ?
Quoted 2 lines
even
on historic hardware such as speedstep-{ich,smi,centrino}? In the past,
speedstep-smi is the only one which sets transition_latency to CPUFREQ_ETERNAL and the others are putting some meaningful values. So yes, they should be doing DVFS dynamically.
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
these checks more or less disallowed the running of dynamic frequency scaling at least on speedstep-smi[*],
We must by doing dynamic freq scaling even without this patch. I don't see why you say the above then.
All we do here is that we get rid of the limit on how soon we can change the freq again.
Quoted 8 lines
Well, as I understand it, first generation "speedstep" was designed more or less to switch frequencies only when AC power was lost or restored.
The Linux implementation merely said: "no on-the-fly changes", but switch frequencies whenever a user explicitly requested such a change (presumably only every once in an unspecified while).
This same reasoning may be present in other drivers using
CPUFREQ_ETERNAL.
Thanks for the explanation here and I am convinced that this series has at least done one thing wrong. And that is removal of max_transition_latency from governors and allowing ondemand to run on such platforms (which may end up breaking them).
So I will actually modify that patch and set max_transition_latency to CPUFREQ_ETERNAL for ondemand/conservative instead of 10ms. Also we should do the same for schedutil as well, so that will also use the max_transition_latency field.
But I hope, this patch will still be fine. Right ?
Quoted 2 lines
I am not *sure* either, I am just worried of the consequences of doing things out-of-spec...
Thanks for your inputs Dominik.
Signature · 1 line
viresh
Re: [PATCH 3/6] cpufreq: governor: Drop min_sampling_rate
Quoted 47 lines · Viresh Kumar
Quoted 11 lines · Dominik Brodowski
Quoted 10 lines · Viresh Kumar
Quoted 9 lines · Dominik Brodowski
Quoted 7 lines · Viresh Kumar
The cpufreq core and governors aren't supposed to set a limit on how fast we want to try changing the frequency. This is currently done for the legacy governors with help of
min_sampling_rate.At worst, we may end up setting the sampling rate to a value lower than the rate at which frequency can be changed and then one of the CPUs in the policy will be only changing frequency for ever.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Is it safe to issue requests to change the CPU frequency so frequently,
Well, I assumed so. I am not sure the hardware would break though. Overheating ?
Quoted 2 lines
even
on historic hardware such as speedstep-{ich,smi,centrino}? In the past,speedstep-smi is the only one which sets
transition_latencytoCPUFREQ_ETERNALand the others are putting some meaningful values. So yes, they should be doing DVFS dynamically.Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
these checks more or less disallowed the running of dynamic frequency scaling at least on speedstep-smi[*],
We must by doing dynamic freq scaling even without this patch. I don't see why you say the above then.
All we do here is that we get rid of the limit on how soon we can change the freq again.
Quoted 8 lines
Well, as I understand it, first generation "speedstep" was designed more or less to switch frequencies only when AC power was lost or restored.
The Linux implementation merely said: "no on-the-fly changes", but switch frequencies whenever a user explicitly requested such a change (presumably only every once in an unspecified while).
This same reasoning may be present in other drivers using
CPUFREQ_ETERNAL.Thanks for the explanation here and I am convinced that this series has at least done one thing wrong. And that is removal of
max_transition_latencyfrom governors and allowing ondemand to run on such platforms (which may end up breaking them).
Quoted 6 lines
So I will actually modify that patch and set
max_transition_latencytoCPUFREQ_ETERNALfor ondemand/conservative instead of 10ms. Also we should do the same for schedutil as well, so that will also use themax_transition_latencyfield.But I hope, this patch will still be fine. Right ?
Indeed, I have no comments otherwise. Thanks!
Best
Dominik
Viresh Kumar
maintainerPATCH 4/6 cpufreq: Use transition_delay_us for legacy governors as well
In reply to Viresh KumarThe policy->transition_delay_us field is used only by the schedutil governor currently, but it should rather be a common thing across all governors.
Create a new helper cpufreq_policy_transition_delay_us() to get the transition delay across all governors.
--- drivers/cpufreq/cpufreq_governor.c | 9 +-------- include/linux/cpufreq.h | 15 +++++++++++++++ kernel/sched/cpufreq_schedutil.c | 11 +---------- 3 files changed, 17 insertions(+), 18 deletions(-)
drivers/cpufreq/cpufreq_governor.c +1 -8
@@ -389,7 +389,6 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)struct dbs_governor *gov =dbs_governor_of (policy);struct dbs_data *dbs_data;struct policy_dbs_info *policy_dbs; -unsigned int latency;int ret =0 ;/* State should be equivalent to EXIT */
@@ -428,13 +427,7 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)if (ret) goto free_policy_dbs_info; -/* policy latency is in ns. Convert it to us first */ - latency = policy->cpuinfo.transition_latency /1000 ; -if (latency ==0 ) - latency =1 ; - -/* Bring kernel and HW constraints together */ - dbs_data->sampling_rate =LATENCY_MULTIPLIER * latency; + dbs_data->sampling_rate =cpufreq_policy_transition_delay_us (policy);if (!have_governor_per_policy ()) gov->gdbs_data = dbs_data;
include/linux/cpufreq.h +15 -0
@@ -529,6 +529,21 @@ static inline void cpufreq_policy_apply_limits(struct cpufreq_policy *policy)__cpufreq_driver_target (policy, policy->min,CPUFREQ_RELATION_L ); } +static inline unsigned int +cpufreq_policy_transition_delay_us (struct cpufreq_policy *policy) +{ +unsigned int delay_us =LATENCY_MULTIPLIER , latency; + +if (policy->transition_delay_us) +return policy->transition_delay_us; + + latency = policy->cpuinfo.transition_latency /NSEC_PER_USEC ; +if (latency) + delay_us *= latency; + +return delay_us; +} +/* Governor attribute set */ struct gov_attr_set {struct kobject kobj;
kernel/sched/cpufreq_schedutil.c +1 -10
@@ -528,16 +528,7 @@ static int sugov_init(struct cpufreq_policy *policy) goto stop_kthread; } -if (policy->transition_delay_us) { - tunables->rate_limit_us = policy->transition_delay_us; - }else { -unsigned int lat; - - tunables->rate_limit_us =LATENCY_MULTIPLIER ; - lat = policy->cpuinfo.transition_latency /NSEC_PER_USEC ; -if (lat) - tunables->rate_limit_us *= lat; - } + tunables->rate_limit_us =cpufreq_policy_transition_delay_us (policy); policy->governor_data = sg_policy; sg_policy->tunables = tunables;
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Viresh Kumar
maintainerPATCH 5/6 cpufreq: Cap the default transition delay value to 10 ms
In reply to Viresh KumarIf transition_delay_us isn't defined by the cpufreq driver, the default value of transition delay (time after which the cpufreq governor will try updating the frequency again) is currently calculated by multiplying transition_latency (nsec) with LATENCY_MULTIPLIER (1000) and then converting this time to usec. That gives the exact same value as transition_latency, just that the time unit is usec instead of nsec.
With acpi-cpufreq for example, transition_latency is set to around 10 usec and we get transition delay as 10 ms. Which seems to be a reasonable amount of time to reevaluate the frequency again.
But for platforms where frequency switching isn't that fast (like ARM), the transition_latency varies from 500 usec to 3 ms, and the transition delay becomes 500 ms to 3 seconds. Of course, that is a pretty bad default value to start with.
We can try to come across a better formula (instead of multiplying with LATENCY_MULTIPLIER) to solve this problem, but will that be worth it ?
This patch tries a simple approach and caps the maximum value of default transition delay to 10 ms. Of course, userspace can still come in and change this value anytime or individual drivers can rather provide transition_delay_us instead.
--- include/linux/cpufreq.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
include/linux/cpufreq.h +11 -1
@@ -541,7 +541,17 @@ cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy)if (latency) delay_us *= latency; -return delay_us; +/* +* For platforms that can change the frequency very fast (< 10 us), +* the above formula gives a decent transition delay. But for platforms +* where transition_latency is in milliseconds, it ends up giving +* unrealistic values. +* +* Cap the default transition delay to 10 ms, which seems to be a +* reasonable amount of time after which we should reevaluate the +* frequency. +*/ +return min (delay_us, (unsigned int )10000 ); }/* Governor attribute set */
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Viresh Kumar
maintainerPATCH 6/6 cpufreq: arm_big_little: Make ->get_transition_latency() mandatory
In reply to Viresh KumarAll users of arm_big_little driver are defining it and there is no need to keep it optional. Make it mandatory.
--- drivers/cpufreq/arm_big_little.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/cpufreq/arm_big_little.c +4 -6
@@ -483,11 +483,8 @@ static int bL_cpufreq_init(struct cpufreq_policy *policy)return ret; } -if (arm_bL_ops->get_transition_latency) - policy->cpuinfo.transition_latency = - arm_bL_ops->get_transition_latency (cpu_dev); -else - policy->cpuinfo.transition_latency =CPUFREQ_ETERNAL ; + policy->cpuinfo.transition_latency = + arm_bL_ops->get_transition_latency (cpu_dev);if (is_bL_switching_enabled ())per_cpu (cpu_last_req_freq, policy->cpu) =clk_get_cpu_rate (policy->cpu);
@@ -622,7 +619,8 @@ int bL_cpufreq_register(struct cpufreq_arm_bL_ops *ops)return -EBUSY ; } -if (!ops || !strlen (ops->name) || !ops->init_opp_table) { +if (!ops || !strlen (ops->name) || !ops->init_opp_table || + !ops->get_transition_latency) {pr_err ("%s: Invalid arm_bL_ops, exiting\n" , __func__);return -ENODEV ; }
Signature · 1 line
2.13.0.71.gd7076ec9c9cb
Rafael J. Wysocki
maintainerHi,
Quoted 7 lines · Viresh Kumar
Hi,
This series tries to cleanup the code around transition-latency and its users. Some of the old legacy code, which may not make much sense now, is being dropped as.
Some code consolidation also happens across governors.
Please mark RFC patches as RFC.
This is not going to be considered for 4.13, so the timing is not the best one I could think about.
Thanks,
Rafael