2017-11-30 11:50:01

by Patrick Bellasi

[permalink] [raw]
Subject: [PATCH v3 0/6] cpufreq: schedutil: fixes for flags updates

This is a re-spin of a previous posting [1], rebased on v4.15-rc1.

A detailed description of the series, as well as experimental results,
is available in the cover letter of the previous posting.
Here is a resume of the main results:

- reduces energy consumption by ~50% by ensuring that a small task is always
running at the minimum OPP even when the sugov's RT kthread is used to change
frequencies in the same cluster

- increase from 4% to 98% the chances for a RT task to complete its activations
while running at the max OPP.

- The sequence of tracing events reported in a trace is much more deterministic
and matching the expected system behaviors. For example, as soon as a RT
task wakes up we ask for an OPP switch to max frequency.

A detailed report for these results is available here [2].

According to the discussion in the previous posting, one patch:

cpufreq: schedutil: ignore the sugov kthread for frequencies selections

was considered the more controversial.
That's why in this posting I'm still proposing that patch, since it
still makes sense to me, but I've moved it at the end of the series,
after the less controversial ones.

Cheers Patrick

.:: References
==============

[1] https://lkml.org/lkml/2017/7/4/495
[2] https://gist.github.com/derkling/0cd7210e4fa6f2ec3558073006e5ad70

Patrick Bellasi (6):
cpufreq: schedutil: reset sg_cpus's flags at IDLE enter
cpufreq: schedutil: ensure max frequency while running RT/DL tasks
cpufreq: schedutil: update CFS util only if used
sched/rt: fast switch to maximum frequency when RT tasks are scheduled
cpufreq: schedutil: relax rate-limiting while running RT/DL tasks
cpufreq: schedutil: ignore sugov kthreads

include/linux/sched/cpufreq.h | 1 +
kernel/sched/cpufreq_schedutil.c | 61 ++++++++++++++++++++++++++++++++--------
kernel/sched/idle_task.c | 4 +++
kernel/sched/rt.c | 15 ++++++++--
4 files changed, 67 insertions(+), 14 deletions(-)

--
2.14.1


From 1585361627284005541@xxx Wed Nov 29 01:24:26 +0000 2017
X-GM-THRID: 1584865790453913324
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread


2017-11-30 11:48:41

by Patrick Bellasi

[permalink] [raw]
Subject: [PATCH v3 5/6] cpufreq: schedutil: relax rate-limiting while running RT/DL tasks

The policy in use for RT/DL tasks sets the maximum frequency when a task
in these classes calls for a cpufreq_update_util(). However, the
current implementation is still enforcing a frequency switch rate
limiting when these tasks are running.
This is potentially working against the goal to switch to the maximum OPP
when RT tasks are running. In certain unfortunate cases it can also happen
that a RT task almost completes its activation at a lower OPP.

This patch overrides on purpose the rate limiting configuration
to better serve RT/DL tasks. As long as a frequency scaling operation
is not in progress, a frequency switch is always authorized when
running in "rt_mode", i.e. the current task in a CPU belongs to the
RT/DL class.

Signed-off-by: Patrick Bellasi <[email protected]>
Reviewed-by: Dietmar Eggemann <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
Changes from v2:
- rebased on v4.15-rc1

Change-Id: I733d47b9e265cebb2e3e5e71a3cd468e9be002d1
---
kernel/sched/cpufreq_schedutil.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 40521d59630b..3eea8884e61b 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -74,7 +74,8 @@ static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);

/************************ Governor internals ***********************/

-static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
+static bool sugov_should_update_freq(struct sugov_policy *sg_policy,
+ u64 time, bool rt_mode)
{
s64 delta_ns;

@@ -111,6 +112,10 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
return true;
}

+ /* Always update if a RT/DL task is running */
+ if (rt_mode)
+ return true;
+
delta_ns = time - sg_policy->last_freq_update_time;
return delta_ns >= sg_policy->freq_update_delay_ns;
}
@@ -268,11 +273,6 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
sugov_set_iowait_boost(sg_cpu, time, flags);
sg_cpu->last_update = time;

- if (!sugov_should_update_freq(sg_policy, time))
- return;
-
- busy = sugov_cpu_is_busy(sg_cpu);
-
/*
* While RT/DL tasks are running we do not want FAIR tasks to
* overvrite this CPU's flags, still we can update utilization and
@@ -281,6 +281,11 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
rt_mode = task_has_dl_policy(current) ||
task_has_rt_policy(current) ||
(flags & SCHED_CPUFREQ_RT_DL);
+ if (!sugov_should_update_freq(sg_policy, time, rt_mode))
+ return;
+
+ busy = sugov_cpu_is_busy(sg_cpu);
+
if (rt_mode) {
next_f = policy->cpuinfo.max_freq;
} else {
@@ -379,7 +384,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
sugov_set_iowait_boost(sg_cpu, time, flags);
sg_cpu->last_update = time;

- if (sugov_should_update_freq(sg_policy, time)) {
+ if (sugov_should_update_freq(sg_policy, time, rt_mode)) {
next_f = rt_mode
? sg_policy->policy->cpuinfo.max_freq
: sugov_next_freq_shared(sg_cpu, time);
--
2.14.1


From 1585239959516852443@xxx Mon Nov 27 17:10:34 +0000 2017
X-GM-THRID: 1585239959516852443
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread

2017-11-30 11:49:29

by Patrick Bellasi

[permalink] [raw]
Subject: [PATCH v3 3/6] cpufreq: schedutil: update CFS util only if used

Currently the utilization of the FAIR class is collected before locking
the policy. Although that should not be a big issue for most cases, we
also don't really know how much latency there can be between the
utilization reading and its usage.

Let's get the FAIR utilization right before its usage to be better in
sync with the current status of a CPU.

Signed-off-by: Patrick Bellasi <[email protected]>
Reviewed-by: Dietmar Eggemann <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
Changes from v2:
- rebased on v4.15-rc1

Change-Id: I9291a560bcad7db76894e3f0fcdb917511d0479e
---
kernel/sched/cpufreq_schedutil.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 448f49de5335..40521d59630b 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -351,10 +351,9 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
unsigned int next_f;
bool rt_mode;

- sugov_get_util(&util, &max, sg_cpu->cpu);
-
raw_spin_lock(&sg_policy->update_lock);

+ sugov_get_util(&util, &max, sg_cpu->cpu);
sg_cpu->util = util;
sg_cpu->max = max;

--
2.14.1


From 1584099902383533857@xxx Wed Nov 15 03:09:51 +0000 2017
X-GM-THRID: 1584099902383533857
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread