cpufreq: intel_pstate: Handle _PPC updates on global turbo disable/enable
Subsystems (4)
v3 cover cpufreq: intel_pstate: Handle _PPC updates on global turbo disable/enable
Hi All,
This is a new version of the following with one patch added:
Quoted 10 lines
This is a follow-up to the RFT patch set posted previously:
https://lore.kernel.org/lkml/[email protected]/Patch [1/3] causes
intel_pstateto update all policies if it gets a_PPCchange notification and sees a global turbo disable/enable change.Patch [2/3] adds
cpufreq_cpu_acquire()andcpufreq_cpu_release()to reduce code duplication after the next patch a bit (and Srinivas wanted the rwsem manipulation to not be done directly by the driver).
Quoted 5 lines
Patch [3/3] makes
intel_pstateupdate cpuinfo.max_freq for all policies in those cases.I've atted Tested-by tags to patches [1/3] and [3/3], because there are only cosmetic differences between them and what has been tested.
The new patch goes (as the new [3/4]) before the old [3/3] (which becomes the new [4/4] obviously) and it modifies the schedutil governor to prevent it from caching values that depend on cpuinfo.max_freq.
The other patches are the same as before.
Thanks,
Rafael
PATCH v3 1/4 cpufreq: intel_pstate: Driver-specific handling of _PPC updates
From: Rafael J. Wysocki <[email protected]>
In some cases, the platform firmware disables or enables turbo frequencies for all CPUs globally before triggering a _PPC change notification for one of them. Obviously, that global change affects all CPUs, not just the notified one, and it needs to be acted upon by cpufreq.
The intel_pstate driver is able to detect such global changes of the settings, but it also needs to update policy limits for all CPUs if that happens, in particular if turbo frequencies are enabled globally - to allow them to be used.
For this reason, introduce a new cpufreq driver callback to be invoked on _PPC notifications, if present, instead of simply calling cpufreq_update_policy() for the notified CPU and make intel_pstate use it to trigger policy updates for all CPUs in the system if global settings change.
---
v2 -> v3:
* Added Acked-by from Viresh.
--- drivers/acpi/processor_perflib.c | 2 +- drivers/cpufreq/cpufreq.c | 16 ++++++++++++++++ drivers/cpufreq/intel_pstate.c | 24 ++++++++++++++++++++++++ include/linux/cpufreq.h | 4 ++++ 4 files changed, 45 insertions(+), 1 deletion(-)
drivers/acpi/processor_perflib.c +1 -1
@@ -181,7 +181,7 @@ void acpi_processor_ppc_has_changed(struacpi_processor_ppc_ost (pr->handle,0 ); }if (ret >=0 ) -cpufreq_update_policy (pr->id); +cpufreq_update_limits (pr->id); }int acpi_processor_get_bios_limit (int cpu,unsigned int *limit)
drivers/cpufreq/cpufreq.c +16 -0
@@ -2370,6 +2370,22 @@ unlock: }EXPORT_SYMBOL (cpufreq_update_policy); +/** +* cpufreq_update_limits - Update policy limits for a given CPU. +* @cpu: CPU to update the policy limits for. +* +* Invoke the driver's ->update_limits callback if present or call +* cpufreq_update_policy() for @cpu. +*/ +void cpufreq_update_limits (unsigned int cpu) +{ +if (cpufreq_driver->update_limits) + cpufreq_driver->update_limits (cpu); +else +cpufreq_update_policy (cpu); +} +EXPORT_SYMBOL_GPL (cpufreq_update_limits); +/********************************************************************* * BOOST * *********************************************************************/
drivers/cpufreq/intel_pstate.c +24 -0
@@ -179,6 +179,7 @@ struct vid_data {* based on the MSR_IA32_MISC_ENABLE value and whether or * not the maximum reported turbo P-state is different from * the maximum reported non-turbo one. +* @turbo_disabled_s: Saved @turbo_disabled value. * @min_perf_pct: Minimum capacity limit in percent of the maximum turbo * P-state capacity. * @max_perf_pct: Maximum capacity limit in percent of the maximum turbo
@@ -187,6 +188,7 @@ struct vid_data {struct global_params {bool no_turbo;bool turbo_disabled; +bool turbo_disabled_s;int max_perf_pct;int min_perf_pct; };
@@ -894,6 +896,25 @@ static void intel_pstate_update_policiescpufreq_update_policy (cpu); } +static void intel_pstate_update_limits (unsigned int cpu) +{ +mutex_lock (&intel_pstate_driver_lock); + +update_turbo_state (); +/* +* If turbo has been turned on or off globally, policy limits for +* all CPUs need to be updated to reflect that. +*/ +if (global.turbo_disabled_s != global.turbo_disabled) { + global.turbo_disabled_s = global.turbo_disabled; +intel_pstate_update_policies (); + }else { +cpufreq_update_policy (cpu); + } + +mutex_unlock (&intel_pstate_driver_lock); +} +/************************** sysfs begin ************************/ #define show_one (file_name, object) \ static ssize_t show_##file_name \
@@ -2135,6 +2156,7 @@ static int __intel_pstate_cpu_init(struc/* cpuinfo and default policy values */ policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling;update_turbo_state (); + global.turbo_disabled_s = global.turbo_disabled; policy->cpuinfo.max_freq = global.turbo_disabled ? cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; policy->cpuinfo.max_freq *= cpu->pstate.scaling;
@@ -2179,6 +2201,7 @@ static struct cpufreq_driver intel_pstat .init = intel_pstate_cpu_init, .exit = intel_pstate_cpu_exit, .stop_cpu = intel_pstate_stop_cpu, + .update_limits = intel_pstate_update_limits, .name = "intel_pstate", };
@@ -2313,6 +2336,7 @@ static struct cpufreq_driver intel_cpufr .init = intel_cpufreq_cpu_init, .exit = intel_pstate_cpu_exit, .stop_cpu = intel_cpufreq_stop_cpu, + .update_limits = intel_pstate_update_limits, .name = "intel_cpufreq", };
include/linux/cpufreq.h +4 -0
@@ -195,6 +195,7 @@ void disable_cpufreq(void);u64 get_cpu_idle_time (unsigned int cpu,u64 *wall,int io_busy);int cpufreq_get_policy (struct cpufreq_policy *policy,unsigned int cpu);void cpufreq_update_policy (unsigned int cpu); +void cpufreq_update_limits (unsigned int cpu);bool have_governor_per_policy (void );struct kobject *get_governor_parent_kobj (struct cpufreq_policy *policy);void cpufreq_enable_fast_switch (struct cpufreq_policy *policy);
@@ -322,6 +323,9 @@ struct cpufreq_driver {/* should be defined, if possible */ unsigned int (*get)(unsigned int cpu); +/* Called to update policy limits on firmware notifications. */ +void (*update_limits)(unsigned int cpu); +/* optional */ int (*bios_limit)(int cpu,unsigned int *limit);
PATCH v3 2/4 cpufreq: Add cpufreq_cpu_acquire() and cpufreq_cpu_release()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
It sometimes is necessary to find a cpufreq policy for a given CPU and acquire its rwsem (for writing) immediately after that, so introduce cpufreq_cpu_acquire() as a helper for that and the complementary cpufreq_cpu_release().
Make cpufreq_update_policy() use the new functions.
---
v2 -> v3:
* Added Acked-by from Viresh.
--- drivers/cpufreq/cpufreq.c | 56 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-)
drivers/cpufreq/cpufreq.c +47 -9
@@ -250,6 +250,51 @@ void cpufreq_cpu_put(struct cpufreq_poli }EXPORT_SYMBOL_GPL (cpufreq_cpu_put); +/** +* cpufreq_cpu_release - Unlock a policy and decrement its usage counter. +* @policy: cpufreq policy returned by cpufreq_cpu_acquire(). +*/ +static void cpufreq_cpu_release (struct cpufreq_policy *policy) +{ +if (WARN_ON (!policy)) +return ; + +lockdep_assert_held (&policy->rwsem); + +up_write (&policy->rwsem); + +cpufreq_cpu_put (policy); +} + +/** +* cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it. +* @cpu: CPU to find the policy for. +* +* Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and +* if the policy returned by it is not NULL, acquire its rwsem for writing. +* Return the policy if it is active or release it and return NULL otherwise. +* +* The policy returned by this function has to be released with the help of +* cpufreq_cpu_release() in order to release its rwsem and balance its usage +* counter properly. +*/ +static struct cpufreq_policy *cpufreq_cpu_acquire (unsigned int cpu) +{ +struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); + +if (!policy) +return NULL ; + +down_write (&policy->rwsem); + +if (policy_is_inactive (policy)) { +cpufreq_cpu_release (policy); +return NULL ; + } + +return policy; +} +/********************************************************************* * EXTERNALLY AFFECTING FREQUENCY CHANGES * *********************************************************************/
@@ -2337,17 +2382,12 @@ static int cpufreq_set_policy(struct cpu*/ void cpufreq_update_policy (unsigned int cpu) { -struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); +struct cpufreq_policy *policy =cpufreq_cpu_acquire (cpu);struct cpufreq_policy new_policy;if (!policy)return ; -down_write (&policy->rwsem); - -if (policy_is_inactive (policy)) - goto unlock; -/* * BIOS might change freq behind our back * -> ask driver for current freq and notify governors about a change
@@ -2364,9 +2404,7 @@ void cpufreq_update_policy(unsigned intcpufreq_set_policy (policy, &new_policy); unlock: -up_write (&policy->rwsem); - -cpufreq_cpu_put (policy); +cpufreq_cpu_release (policy); }EXPORT_SYMBOL (cpufreq_update_policy);
PATCH v3 3/4 cpufreq: schedutil: Simplify iowait boosting
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
There is not reason for the minimum iowait boost value in the schedutil cpufreq governor to depend on the available range of CPU frequencies. In fact, that dependency is generally confusing, because it causes the iowait boost to behave somewhat differently on CPUs with the same maximum frequency and different minimum frequencies, for example.
For this reason, replace the min field in struct sugov_cpu with a constant and choose its values to be 1/8 of SCHED_CAPACITY_SCALE (for consistency with the intel_pstate driver's internal governor).
[Note that policy->cpuinfo.max_freq will not be a constant any more
after a subsequent change, so this change is depended on by it.]
--- kernel/sched/cpufreq_schedutil.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
kernel/sched/cpufreq_schedutil.c +5 -7
@@ -13,6 +13,8 @@#include <linux/sched/cpufreq.h> #include <trace/events/power.h> +#define IOWAIT_BOOST_MIN (SCHED_CAPACITY_SCALE / 8) +struct sugov_tunables {struct gov_attr_set attr_set;unsigned int rate_limit_us;
@@ -51,7 +53,6 @@ struct sugov_cpu {u64 last_update;unsigned long bw_dl; -unsigned long min;unsigned long max;/* The field below is for single-CPU policies only: */
@@ -303,7 +304,7 @@ static bool sugov_iowait_reset(struct suif (delta_ns <=TICK_NSEC )return false; - sg_cpu->iowait_boost = set_iowait_boost ? sg_cpu->min :0 ; + sg_cpu->iowait_boost = set_iowait_boost ?IOWAIT_BOOST_MIN :0 ; sg_cpu->iowait_boost_pending = set_iowait_boost;return true;
@@ -349,7 +350,7 @@ static void sugov_iowait_boost(struct su }/* First wakeup after IO: start with minimum boost */ - sg_cpu->iowait_boost = sg_cpu->min; + sg_cpu->iowait_boost =IOWAIT_BOOST_MIN ; }/**
@@ -389,7 +390,7 @@ static unsigned long sugov_iowait_apply(* No boost pending; reduce the boost value. */ sg_cpu->iowait_boost >>=1 ; -if (sg_cpu->iowait_boost < sg_cpu->min) { +if (sg_cpu->iowait_boost <IOWAIT_BOOST_MIN ) { sg_cpu->iowait_boost =0 ;return util; }
@@ -826,9 +827,6 @@ static int sugov_start(struct cpufreq_pomemset (sg_cpu,0 ,sizeof (*sg_cpu)); sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; - sg_cpu->min = - (SCHED_CAPACITY_SCALE * policy->cpuinfo.min_freq) / - policy->cpuinfo.max_freq; }for_each_cpu (cpu, policy->cpus) {
Re: [PATCH v3 3/4] cpufreq: schedutil: Simplify iowait boosting
Hi Rafael,
kernel/sched/cpufreq_schedutil.c static bool sugov_iowait_reset(struct sua
Quoted 18 lines · Rafael J. Wysocki
kernel/sched/cpufreq_schedutil.c +2
-1@@ -13,6 +13,8 @@#include <linux/sched/cpufreq.h> #include <trace/events/power.h> +#define IOWAIT_BOOST_MIN (SCHED_CAPACITY_SCALE / 8) +struct sugov_tunables {struct gov_attr_set attr_set;unsigned int rate_limit_us;@@ -51,7 +53,6 @@ struct sugov_cpu {u64 last_update;unsigned long bw_dl; -unsigned long min;unsigned long max;/* The field below is for single-CPU policies only: */ @@ -303,7 +304,7 @@ static bool sugov_iowait_reset(struct sua
The comment above this function needs updating I think.
kernel/sched/cpufreq_schedutil.c static void sugov_iowait_boost(struct su
Quoted 9 lines
kernel/sched/cpufreq_schedutil.c +1
-1if (delta_ns <=TICK_NSEC )return false; - sg_cpu->iowait_boost = set_iowait_boost ? sg_cpu->min :0 ; + sg_cpu->iowait_boost = set_iowait_boost ?IOWAIT_BOOST_MIN :0 ; sg_cpu->iowait_boost_pending = set_iowait_boost;return true;@@ -349,7 +350,7 @@ static void sugov_iowait_boost(struct su
Ditto.
Quoted 19 lines
kernel/sched/cpufreq_schedutil.c +2
-2}/* First wakeup after IO: start with minimum boost */ - sg_cpu->iowait_boost = sg_cpu->min; + sg_cpu->iowait_boost =IOWAIT_BOOST_MIN ; }/** @@ -389,7 +390,7 @@ static unsigned long sugov_iowait_apply(* No boost pending; reduce the boost value. */ sg_cpu->iowait_boost >>=1 ; -if (sg_cpu->iowait_boost < sg_cpu->min) { +if (sg_cpu->iowait_boost <IOWAIT_BOOST_MIN ) { sg_cpu->iowait_boost =0 ;return util; }
kernel/sched/cpufreq_schedutil.c static int sugov_start(struct cpufreq_po · line 832
Quoted 9 lines
kernel/sched/cpufreq_schedutil.c +0
-3@@ -826,9 +827,6 @@ static int sugov_start(struct cpufreq_pomemset (sg_cpu,0 ,sizeof (*sg_cpu)); sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; - sg_cpu->min = - (SCHED_CAPACITY_SCALE * policy->cpuinfo.min_freq) / - policy->cpuinfo.max_freq; }for_each_cpu (cpu, policy->cpus) {
Other than that, I tried a backport of this on a Pixel 3 with Snapdragon 845 (which is relevant because it has tons of OPPs, so starting at 128 makes it ramp up faster) to check the impact on power, but the only differences appeared to be in the noise margin, so it's all good :)
Full test results available at [1]. Note that I did enable the iowait boost feature for these tests -- it is disabled by default on P3 ...
Thanks,
Quentin
---
[1] https://nbviewer.jupyter.org/gist/qperret/69c9bde13aad2d783689e78c9ba2d9bc
Rafael J. Wysocki
maintainerRe: [PATCH v3 3/4] cpufreq: schedutil: Simplify iowait boosting
Quoted 28 lines · Quentin Perret
Hi Rafael,
kernel/sched/cpufreq_schedutil.c static bool sugov_iowait_reset(struct sua
Quoted 18 lines · Rafael J. Wysocki
kernel/sched/cpufreq_schedutil.c +2
-1@@ -13,6 +13,8 @@#include <linux/sched/cpufreq.h> #include <trace/events/power.h> +#define IOWAIT_BOOST_MIN (SCHED_CAPACITY_SCALE / 8) +struct sugov_tunables {struct gov_attr_set attr_set;unsigned int rate_limit_us;@@ -51,7 +53,6 @@ struct sugov_cpu {u64 last_update;unsigned long bw_dl; -unsigned long min;unsigned long max;/* The field below is for single-CPU policies only: */ @@ -303,7 +304,7 @@ static bool sugov_iowait_reset(struct suaThe comment above this function needs updating I think.
Quoted 3 lines
kernel/sched/cpufreq_schedutil.c +0
-0if (delta_ns <=TICK_NSEC )return false;
Quoted 8 lines
kernel/sched/cpufreq_schedutil.c static void sugov_iowait_boost(struct su
Quoted 6 lines
kernel/sched/cpufreq_schedutil.c +1
-1- sg_cpu->iowait_boost = set_iowait_boost ? sg_cpu->min :0 ; + sg_cpu->iowait_boost = set_iowait_boost ?IOWAIT_BOOST_MIN :0 ; sg_cpu->iowait_boost_pending = set_iowait_boost;return true;@@ -349,7 +350,7 @@ static void sugov_iowait_boost(struct suDitto.
I overlooked these two, thanks for pointing that out!
Will send an update momentarily.
Quoted 26 lines
Quoted 26 lines
kernel/sched/cpufreq_schedutil.c +2
-5}/* First wakeup after IO: start with minimum boost */ - sg_cpu->iowait_boost = sg_cpu->min; + sg_cpu->iowait_boost =IOWAIT_BOOST_MIN ; }/** @@ -389,7 +390,7 @@ static unsigned long sugov_iowait_apply(* No boost pending; reduce the boost value. */ sg_cpu->iowait_boost >>=1 ; -if (sg_cpu->iowait_boost < sg_cpu->min) { +if (sg_cpu->iowait_boost <IOWAIT_BOOST_MIN ) { sg_cpu->iowait_boost =0 ;return util; }@@ -826,9 +827,6 @@ static int sugov_start(struct cpufreq_pomemset (sg_cpu,0 ,sizeof (*sg_cpu)); sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; - sg_cpu->min = - (SCHED_CAPACITY_SCALE * policy->cpuinfo.min_freq) / - policy->cpuinfo.max_freq; }
Quoted 7 lines
kernel/sched/cpufreq_schedutil.c static int sugov_start(struct cpufreq_po · line 832
Quoted 2 lines
kernel/sched/cpufreq_schedutil.c +0
-0for_each_cpu (cpu, policy->cpus) {Other than that, I tried a backport of this on a Pixel 3 with Snapdragon 845 (which is relevant because it has tons of OPPs, so starting at 128 makes it ramp up faster) to check the impact on power, but the only differences appeared to be in the noise margin, so it's all good :)
Cool. :-)
Quoted 2 lines
Full test results available at [1]. Note that I did enable the iowait boost feature for these tests -- it is disabled by default on P3 ...
Thanks!
Quoted 2 lines
---
[1] https://nbviewer.jupyter.org/gist/qperret/69c9bde13aad2d783689e78c9ba2d9bc
PATCH v3 3/4 cpufreq: schedutil: Simplify iowait boosting
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
There is not reason for the minimum iowait boost value in the schedutil cpufreq governor to depend on the available range of CPU frequencies. In fact, that dependency is generally confusing, because it causes the iowait boost to behave somewhat differently on CPUs with the same maximum frequency and different minimum frequencies, for example.
For this reason, replace the min field in struct sugov_cpu with a constant and choose its values to be 1/8 of SCHED_CAPACITY_SCALE (for consistency with the intel_pstate driver's internal governor).
[Note that policy->cpuinfo.max_freq will not be a constant any more
after a subsequent change, so this change is depended on by it.]
---
As pointed out by Quentin, the original patch overlooked two kerneldoc comments that needed to be updated along with the code, so do that here.
No other changes with respect to the original.
--- kernel/sched/cpufreq_schedutil.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
kernel/sched/cpufreq_schedutil.c +10 -11
@@ -13,6 +13,8 @@#include <linux/sched/cpufreq.h> #include <trace/events/power.h> +#define IOWAIT_BOOST_MIN (SCHED_CAPACITY_SCALE / 8) +struct sugov_tunables {struct gov_attr_set attr_set;unsigned int rate_limit_us;
@@ -51,7 +53,6 @@ struct sugov_cpu {u64 last_update;unsigned long bw_dl; -unsigned long min;unsigned long max;/* The field below is for single-CPU policies only: */
@@ -291,8 +292,8 @@ static unsigned long sugov_get_util(stru* * The IO wait boost of a task is disabled after a tick since the last update * of a CPU. If a new IO wait boost is requested after more then a tick, then -* we enable the boost starting from the minimum frequency, which improves -* energy efficiency by ignoring sporadic wakeups from IO. +* we enable the boost starting from IOWAIT_BOOST_MIN, which improves energy +* efficiency by ignoring sporadic wakeups from IO. */ static bool sugov_iowait_reset (struct sugov_cpu *sg_cpu,u64 time,bool set_iowait_boost)
@@ -303,7 +304,7 @@ static bool sugov_iowait_reset(struct suif (delta_ns <=TICK_NSEC )return false; - sg_cpu->iowait_boost = set_iowait_boost ? sg_cpu->min :0 ; + sg_cpu->iowait_boost = set_iowait_boost ?IOWAIT_BOOST_MIN :0 ; sg_cpu->iowait_boost_pending = set_iowait_boost;return true;
@@ -317,8 +318,9 @@ static bool sugov_iowait_reset(struct su* * Each time a task wakes up after an IO operation, the CPU utilization can be * boosted to a certain utilization which doubles at each "frequent and -* successive" wakeup from IO, ranging from the utilization of the minimum -* OPP to the utilization of the maximum OPP. +* successive" wakeup from IO, ranging from IOWAIT_BOOST_MIN to the utilization +* of the maximum OPP. +* * To keep doubling, an IO boost has to be requested at least once per tick, * otherwise we restart from the utilization of the minimum OPP. */
@@ -349,7 +351,7 @@ static void sugov_iowait_boost(struct su }/* First wakeup after IO: start with minimum boost */ - sg_cpu->iowait_boost = sg_cpu->min; + sg_cpu->iowait_boost =IOWAIT_BOOST_MIN ; }/**
@@ -389,7 +391,7 @@ static unsigned long sugov_iowait_apply(* No boost pending; reduce the boost value. */ sg_cpu->iowait_boost >>=1 ; -if (sg_cpu->iowait_boost < sg_cpu->min) { +if (sg_cpu->iowait_boost <IOWAIT_BOOST_MIN ) { sg_cpu->iowait_boost =0 ;return util; }
@@ -826,9 +828,6 @@ static int sugov_start(struct cpufreq_pomemset (sg_cpu,0 ,sizeof (*sg_cpu)); sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; - sg_cpu->min = - (SCHED_CAPACITY_SCALE * policy->cpuinfo.min_freq) / - policy->cpuinfo.max_freq; }for_each_cpu (cpu, policy->cpus) {
Re: [Update][PATCH v3 3/4] cpufreq: schedutil: Simplify iowait boosting
Quoted 105 lines · CEST Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
There is not reason for the minimum iowait boost value in the schedutil cpufreq governor to depend on the available range of CPU frequencies. In fact, that dependency is generally confusing, because it causes the iowait boost to behave somewhat differently on CPUs with the same maximum frequency and different minimum frequencies, for example.
For this reason, replace the min field in struct
sugov_cpuwith a constant and choose its values to be 1/8 ofSCHED_CAPACITY_SCALE(for consistency with theintel_pstatedriver's internal governor).[Note that
policy->cpuinfo.max_freqwill not be a constant any more
after a subsequent change, so this change is depended on by it.]Link https://lore.kernel.org/lkml/[email protected]/T/#ee20bdc98b7d89f6110c0d00e5c3ee8c2ced93c3d open hereSuggested-by Peter Zijlstra <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>---
As pointed out by Quentin, the original patch overlooked two kerneldoc comments that needed to be updated along with the code, so do that here.
No other changes with respect to the original.
--- kernel/sched/cpufreq_schedutil.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)Index:
linux-pm/kernel/sched/cpufreq_schedutil.c
===================================================================kernel/sched/cpufreq_schedutil.c +10
-8@@ -13,6 +13,8 @@#include <linux/sched/cpufreq.h> #include <trace/events/power.h> +#define IOWAIT_BOOST_MIN (SCHED_CAPACITY_SCALE / 8) +struct sugov_tunables {struct gov_attr_set attr_set;unsigned int rate_limit_us;@@ -51,7 +53,6 @@ struct sugov_cpu {u64 last_update;unsigned long bw_dl; -unsigned long min;unsigned long max;/* The field below is for single-CPU policies only: */ @@ -291,8 +292,8 @@ static unsigned long sugov_get_util(stru* * The IO wait boost of a task is disabled after a tick since the last update * of a CPU. If a new IO wait boost is requested after more then a tick, then -* we enable the boost starting from the minimum frequency, which improves -* energy efficiency by ignoring sporadic wakeups from IO. +* we enable the boost starting from IOWAIT_BOOST_MIN, which improves energy +* efficiency by ignoring sporadic wakeups from IO. */ static bool sugov_iowait_reset (struct sugov_cpu *sg_cpu,u64 time,bool set_iowait_boost)@@ -303,7 +304,7 @@ static bool sugov_iowait_reset(struct suif (delta_ns <=TICK_NSEC )return false; - sg_cpu->iowait_boost = set_iowait_boost ? sg_cpu->min :0 ; + sg_cpu->iowait_boost = set_iowait_boost ?IOWAIT_BOOST_MIN :0 ; sg_cpu->iowait_boost_pending = set_iowait_boost;return true;@@ -317,8 +318,9 @@ static bool sugov_iowait_reset(struct su* * Each time a task wakes up after an IO operation, the CPU utilization can be * boosted to a certain utilization which doubles at each "frequent and -* successive" wakeup from IO, ranging from the utilization of the minimum -* OPP to the utilization of the maximum OPP. +* successive" wakeup from IO, ranging from IOWAIT_BOOST_MIN to the utilization +* of the maximum OPP. +* * To keep doubling, an IO boost has to be requested at least once per tick, * otherwise we restart from the utilization of the minimum OPP. */ @@ -349,7 +351,7 @@ static void sugov_iowait_boost(struct su }/* First wakeup after IO: start with minimum boost */ - sg_cpu->iowait_boost = sg_cpu->min; + sg_cpu->iowait_boost =IOWAIT_BOOST_MIN ; }/** @@ -389,7 +391,7 @@ static unsigned long sugov_iowait_apply(* No boost pending; reduce the boost value. */ sg_cpu->iowait_boost >>=1 ; -if (sg_cpu->iowait_boost < sg_cpu->min) { +if (sg_cpu->iowait_boost <IOWAIT_BOOST_MIN ) { sg_cpu->iowait_boost =0 ;return util; }
kernel/sched/cpufreq_schedutil.c static int sugov_start(struct cpufreq_po · line 833
Quoted 9 lines
kernel/sched/cpufreq_schedutil.c +0
-3@@ -826,9 +828,6 @@ static int sugov_start(struct cpufreq_pomemset (sg_cpu,0 ,sizeof (*sg_cpu)); sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; - sg_cpu->min = - (SCHED_CAPACITY_SCALE * policy->cpuinfo.min_freq) / - policy->cpuinfo.max_freq; }for_each_cpu (cpu, policy->cpus) {
Any more comments on this patch?
If not, I'll queue it up along with the rest of the series.
Thanks!
Re: [Update][PATCH v3 3/4] cpufreq: schedutil: Simplify iowait boosting
Quoted 15 lines · Rafael J. Wysocki
Quoted 14 lines · CEST Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
There is not reason for the minimum iowait boost value in the schedutil cpufreq governor to depend on the available range of CPU frequencies. In fact, that dependency is generally confusing, because it causes the iowait boost to behave somewhat differently on CPUs with the same maximum frequency and different minimum frequencies, for example.
For this reason, replace the min field in struct
sugov_cpuwith a constant and choose its values to be 1/8 ofSCHED_CAPACITY_SCALE(for consistency with theintel_pstatedriver's internal governor).
Quoted 8 lines
Quoted 6 lines
[Note that
policy->cpuinfo.max_freqwill not be a constant any more
after a subsequent change, so this change is depended on by it.]Any more comments on this patch?
I obviously like it :-)
Quoted 1 line
If not, I'll queue it up along with the rest of the series.
Thanks!
Re: [Update][PATCH v3 3/4] cpufreq: schedutil: Simplify iowait boosting
In reply to Rafael J. WysockiQuoted 22 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
There is not reason for the minimum iowait boost value in the schedutil cpufreq governor to depend on the available range of CPU frequencies. In fact, that dependency is generally confusing, because it causes the iowait boost to behave somewhat differently on CPUs with the same maximum frequency and different minimum frequencies, for example.
For this reason, replace the min field in struct
sugov_cpuwith a constant and choose its values to be 1/8 ofSCHED_CAPACITY_SCALE(for consistency with theintel_pstatedriver's internal governor).[Note that
policy->cpuinfo.max_freqwill not be a constant any more
after a subsequent change, so this change is depended on by it.]Link https://lore.kernel.org/lkml/[email protected]/T/#ee20bdc98b7d89f6110c0d00e5c3ee8c2ced93c3d open hereSuggested-by Peter Zijlstra <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>---
Quoted 8 lines
As pointed out by Quentin, the original patch overlooked two kerneldoc comments that needed to be updated along with the code, so do that here.
No other changes with respect to the original.
--- kernel/sched/cpufreq_schedutil.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
viresh
PATCH v3 4/4 cpufreq: intel_pstate: Update max frequency on global turbo changes
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
While the cpuinfo.max_freq value doesn't really matter for intel_pstate in the active mode, in the passive mode it is used by governors as the maximum physical frequency of the CPU and the results of governor computations generally depend on it. Also it is made available to user space via sysfs and it should match the current HW configuration.
For this reason, make intel_pstate update cpuinfo.max_freq for all CPUs if it detects a global change of turbo frequency settings from "disable" to "enable" or the other way associated with a _PPC change notification from the platform firmware.
Note that policy_is_inactive(), cpufreq_cpu_acquire(), cpufreq_cpu_release(), and cpufreq_set_policy() need to be made available to it for this purpose.
---
v2 -> v3:
* Added Acked-by from Viresh.
--- drivers/cpufreq/cpufreq.c | 16 ++++------------ drivers/cpufreq/intel_pstate.c | 35 +++++++++++++++++++++++++++++------ include/linux/cpufreq.h | 10 ++++++++++ 3 files changed, 43 insertions(+), 18 deletions(-)
drivers/cpufreq/intel_pstate.c +29 -6
@@ -179,7 +179,7 @@ struct vid_data {* based on the MSR_IA32_MISC_ENABLE value and whether or * not the maximum reported turbo P-state is different from * the maximum reported non-turbo one. -* @turbo_disabled_s: Saved @turbo_disabled value. +* @turbo_disabled_mf: The @turbo_disabled value reflected by cpuinfo.max_freq. * @min_perf_pct: Minimum capacity limit in percent of the maximum turbo * P-state capacity. * @max_perf_pct: Maximum capacity limit in percent of the maximum turbo
@@ -188,7 +188,7 @@ struct vid_data {struct global_params {bool no_turbo;bool turbo_disabled; -bool turbo_disabled_s; +bool turbo_disabled_mf;int max_perf_pct;int min_perf_pct; };
@@ -896,6 +896,28 @@ static void intel_pstate_update_policiescpufreq_update_policy (cpu); } +static void intel_pstate_update_max_freq (unsigned int cpu) +{ +struct cpufreq_policy *policy =cpufreq_cpu_acquire (cpu); +struct cpufreq_policy new_policy; +struct cpudata *cpudata; + +if (!policy) +return ; + + cpudata = all_cpu_data[cpu]; + policy->cpuinfo.max_freq = global.turbo_disabled_mf ? + cpudata->pstate.max_freq : cpudata->pstate.turbo_freq; + +memcpy (&new_policy, policy,sizeof (*policy)); + new_policy.max =min (policy->user_policy.max, policy->cpuinfo.max_freq); + new_policy.min =min (policy->user_policy.min, new_policy.max); + +cpufreq_set_policy (policy, &new_policy); + +cpufreq_cpu_release (policy); +} +static void intel_pstate_update_limits (unsigned int cpu) {mutex_lock (&intel_pstate_driver_lock);
@@ -905,9 +927,10 @@ static void intel_pstate_update_limits(u* If turbo has been turned on or off globally, policy limits for * all CPUs need to be updated to reflect that. */ -if (global.turbo_disabled_s != global.turbo_disabled) { - global.turbo_disabled_s = global.turbo_disabled; -intel_pstate_update_policies (); +if (global.turbo_disabled_mf != global.turbo_disabled) { + global.turbo_disabled_mf = global.turbo_disabled; +for_each_possible_cpu (cpu) +intel_pstate_update_max_freq (cpu); }else {cpufreq_update_policy (cpu); }
@@ -2156,7 +2179,7 @@ static int __intel_pstate_cpu_init(struc/* cpuinfo and default policy values */ policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling;update_turbo_state (); - global.turbo_disabled_s = global.turbo_disabled; + global.turbo_disabled_mf = global.turbo_disabled; policy->cpuinfo.max_freq = global.turbo_disabled ? cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; policy->cpuinfo.max_freq *= cpu->pstate.scaling;
drivers/cpufreq/cpufreq.c +4 -12
@@ -34,11 +34,6 @@static LIST_HEAD (cpufreq_policy_list); -static inline bool policy_is_inactive (struct cpufreq_policy *policy) -{ -return cpumask_empty (policy->cpus); -} -/* Macros to iterate over CPU policies */ #define for_each_suitable_policy (__policy, __active) \ list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
@@ -254,7 +249,7 @@ EXPORT_SYMBOL_GPL(cpufreq_cpu_put);* cpufreq_cpu_release - Unlock a policy and decrement its usage counter. * @policy: cpufreq policy returned by cpufreq_cpu_acquire(). */ -static void cpufreq_cpu_release (struct cpufreq_policy *policy) +void cpufreq_cpu_release (struct cpufreq_policy *policy) {if (WARN_ON (!policy))return ;
@@ -278,7 +273,7 @@ static void cpufreq_cpu_release(struct c* cpufreq_cpu_release() in order to release its rwsem and balance its usage * counter properly. */ -static struct cpufreq_policy *cpufreq_cpu_acquire (unsigned int cpu) +struct cpufreq_policy *cpufreq_cpu_acquire (unsigned int cpu) {struct cpufreq_policy *policy =cpufreq_cpu_get (cpu);
@@ -714,9 +709,6 @@ static ssize_t show_scaling_cur_freq(strreturn ret; } -static int cpufreq_set_policy (struct cpufreq_policy *policy, -struct cpufreq_policy *new_policy); -/** * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access */
@@ -2274,8 +2266,8 @@ EXPORT_SYMBOL(cpufreq_get_policy);* * The cpuinfo part of @policy is not updated by this function. */ -static int cpufreq_set_policy (struct cpufreq_policy *policy, -struct cpufreq_policy *new_policy) +int cpufreq_set_policy (struct cpufreq_policy *policy, +struct cpufreq_policy *new_policy) {struct cpufreq_governor *old_gov;int ret;
include/linux/cpufreq.h +10 -0
@@ -178,6 +178,11 @@ static inline struct cpufreq_policy *cpustatic inline void cpufreq_cpu_put (struct cpufreq_policy *policy) { }#endif +static inline bool policy_is_inactive (struct cpufreq_policy *policy) +{ +return cpumask_empty (policy->cpus); +} +static inline bool policy_is_shared (struct cpufreq_policy *policy) {return cpumask_weight (policy->cpus) >1 ;
@@ -193,7 +198,12 @@ unsigned int cpufreq_quick_get_max(unsigvoid disable_cpufreq (void );u64 get_cpu_idle_time (unsigned int cpu,u64 *wall,int io_busy); + +struct cpufreq_policy *cpufreq_cpu_acquire (unsigned int cpu); +void cpufreq_cpu_release (struct cpufreq_policy *policy);int cpufreq_get_policy (struct cpufreq_policy *policy,unsigned int cpu); +int cpufreq_set_policy (struct cpufreq_policy *policy, +struct cpufreq_policy *new_policy);void cpufreq_update_policy (unsigned int cpu);void cpufreq_update_limits (unsigned int cpu);bool have_governor_per_policy (void );