From: tip-bot for Patrick Bellasi <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: vincent.guittot@linaro.org, joelaf@google.com,
rafael.j.wysocki@intel.com, tglx@linutronix.de,
juri.lelli@redhat.com, mingo@kernel.org, balsini@android.com,
tj@kernel.org, linux-kernel@vger.kernel.org, smuckle@google.com,
hpa@zytor.com, morten.rasmussen@arm.com, surenb@google.com,
quentin.perret@arm.com, pjt@google.com, dietmar.eggemann@arm.com,
patrick.bellasi@arm.com, tkjos@google.com,
torvalds@linux-foundation.org, peterz@infradead.org,
viresh.kumar@linaro.org
Subject: [tip:sched/core] sched/uclamp: Add uclamp support to energy_compute()
Date: Tue, 25 Jun 2019 01:37:11 -0700 [thread overview]
Message-ID: <tip-af24bde8df2029f067dc46aff0393c8f18ff6e2f@git.kernel.org> (raw)
In-Reply-To: <20190621084217.8167-12-patrick.bellasi@arm.com>
Commit-ID: af24bde8df2029f067dc46aff0393c8f18ff6e2f
Gitweb: https://git.kernel.org/tip/af24bde8df2029f067dc46aff0393c8f18ff6e2f
Author: Patrick Bellasi <patrick.bellasi@arm.com>
AuthorDate: Fri, 21 Jun 2019 09:42:12 +0100
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 24 Jun 2019 19:23:49 +0200
sched/uclamp: Add uclamp support to energy_compute()
The Energy Aware Scheduler (EAS) estimates the energy impact of waking
up a task on a given CPU. This estimation is based on:
a) an (active) power consumption defined for each CPU frequency
b) an estimation of which frequency will be used on each CPU
c) an estimation of the busy time (utilization) of each CPU
Utilization clamping can affect both b) and c).
A CPU is expected to run:
- on an higher than required frequency, but for a shorter time, in case
its estimated utilization will be smaller than the minimum utilization
enforced by uclamp
- on a smaller than required frequency, but for a longer time, in case
its estimated utilization is bigger than the maximum utilization
enforced by uclamp
While compute_energy() already accounts clamping effects on busy time,
the clamping effects on frequency selection are currently ignored.
Fix it by considering how CPU clamp values will be affected by a
task waking up and being RUNNABLE on that CPU.
Do that by refactoring schedutil_freq_util() to take an additional
task_struct* which allows EAS to evaluate the impact on clamp values of
a task being eventually queued in a CPU. Clamp values are applied to the
RT+CFS utilization only when a FREQUENCY_UTIL is required by
compute_energy().
Do note that switching from ENERGY_UTIL to FREQUENCY_UTIL in the
computation of the cpu_util signal implies that we are more likely to
estimate the highest OPP when a RT task is running in another CPU of
the same performance domain. This can have an impact on energy
estimation but:
- it's not easy to say which approach is better, since it depends on
the use case
- the original approach could still be obtained by setting a smaller
task-specific util_min whenever required
Since we are at that:
- rename schedutil_freq_util() into schedutil_cpu_util(),
since it's not only used for frequency selection.
Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alessio Balsini <balsini@android.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Joel Fernandes <joelaf@google.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Morten Rasmussen <morten.rasmussen@arm.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Perret <quentin.perret@arm.com>
Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com>
Cc: Steve Muckle <smuckle@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Todd Kjos <tkjos@google.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Link: https://lkml.kernel.org/r/20190621084217.8167-12-patrick.bellasi@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/cpufreq_schedutil.c | 9 +++++----
kernel/sched/fair.c | 40 ++++++++++++++++++++++++++++++++++------
kernel/sched/sched.h | 21 +++++++++------------
3 files changed, 48 insertions(+), 22 deletions(-)
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index d84e036a7536..636ca6f88c8e 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -196,8 +196,9 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy,
* based on the task model parameters and gives the minimal utilization
* required to meet deadlines.
*/
-unsigned long schedutil_freq_util(int cpu, unsigned long util_cfs,
- unsigned long max, enum schedutil_type type)
+unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs,
+ unsigned long max, enum schedutil_type type,
+ struct task_struct *p)
{
unsigned long dl_util, util, irq;
struct rq *rq = cpu_rq(cpu);
@@ -230,7 +231,7 @@ unsigned long schedutil_freq_util(int cpu, unsigned long util_cfs,
*/
util = util_cfs + cpu_util_rt(rq);
if (type == FREQUENCY_UTIL)
- util = uclamp_util(rq, util);
+ util = uclamp_util_with(rq, util, p);
dl_util = cpu_util_dl(rq);
@@ -290,7 +291,7 @@ static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu)
sg_cpu->max = max;
sg_cpu->bw_dl = cpu_bw_dl(rq);
- return schedutil_freq_util(sg_cpu->cpu, util, max, FREQUENCY_UTIL);
+ return schedutil_cpu_util(sg_cpu->cpu, util, max, FREQUENCY_UTIL, NULL);
}
/**
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 28db7ce5c3a6..b798fe7ff7cd 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6231,11 +6231,21 @@ static unsigned long cpu_util_next(int cpu, struct task_struct *p, int dst_cpu)
static long
compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd)
{
- long util, max_util, sum_util, energy = 0;
+ unsigned int max_util, util_cfs, cpu_util, cpu_cap;
+ unsigned long sum_util, energy = 0;
+ struct task_struct *tsk;
int cpu;
for (; pd; pd = pd->next) {
+ struct cpumask *pd_mask = perf_domain_span(pd);
+
+ /*
+ * The energy model mandates all the CPUs of a performance
+ * domain have the same capacity.
+ */
+ cpu_cap = arch_scale_cpu_capacity(cpumask_first(pd_mask));
max_util = sum_util = 0;
+
/*
* The capacity state of CPUs of the current rd can be driven by
* CPUs of another rd if they belong to the same performance
@@ -6246,11 +6256,29 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd)
* it will not appear in its pd list and will not be accounted
* by compute_energy().
*/
- for_each_cpu_and(cpu, perf_domain_span(pd), cpu_online_mask) {
- util = cpu_util_next(cpu, p, dst_cpu);
- util = schedutil_energy_util(cpu, util);
- max_util = max(util, max_util);
- sum_util += util;
+ for_each_cpu_and(cpu, pd_mask, cpu_online_mask) {
+ util_cfs = cpu_util_next(cpu, p, dst_cpu);
+
+ /*
+ * Busy time computation: utilization clamping is not
+ * required since the ratio (sum_util / cpu_capacity)
+ * is already enough to scale the EM reported power
+ * consumption at the (eventually clamped) cpu_capacity.
+ */
+ sum_util += schedutil_cpu_util(cpu, util_cfs, cpu_cap,
+ ENERGY_UTIL, NULL);
+
+ /*
+ * Performance domain frequency: utilization clamping
+ * must be considered since it affects the selection
+ * of the performance domain frequency.
+ * NOTE: in case RT tasks are running, by default the
+ * FREQUENCY_UTIL's utilization can be max OPP.
+ */
+ tsk = cpu == dst_cpu ? p : NULL;
+ cpu_util = schedutil_cpu_util(cpu, util_cfs, cpu_cap,
+ FREQUENCY_UTIL, tsk);
+ max_util = max(max_util, cpu_util);
}
energy += em_pd_energy(pd->em_pd, max_util, sum_util);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 1783f6b4c2e0..802b1f3405f2 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2322,7 +2322,6 @@ static inline unsigned long capacity_orig_of(int cpu)
}
#endif
-#ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL
/**
* enum schedutil_type - CPU utilization type
* @FREQUENCY_UTIL: Utilization used to select frequency
@@ -2338,15 +2337,11 @@ enum schedutil_type {
ENERGY_UTIL,
};
-unsigned long schedutil_freq_util(int cpu, unsigned long util_cfs,
- unsigned long max, enum schedutil_type type);
+#ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL
-static inline unsigned long schedutil_energy_util(int cpu, unsigned long cfs)
-{
- unsigned long max = arch_scale_cpu_capacity(cpu);
-
- return schedutil_freq_util(cpu, cfs, max, ENERGY_UTIL);
-}
+unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs,
+ unsigned long max, enum schedutil_type type,
+ struct task_struct *p);
static inline unsigned long cpu_bw_dl(struct rq *rq)
{
@@ -2375,11 +2370,13 @@ static inline unsigned long cpu_util_rt(struct rq *rq)
return READ_ONCE(rq->avg_rt.util_avg);
}
#else /* CONFIG_CPU_FREQ_GOV_SCHEDUTIL */
-static inline unsigned long schedutil_energy_util(int cpu, unsigned long cfs)
+static inline unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs,
+ unsigned long max, enum schedutil_type type,
+ struct task_struct *p)
{
- return cfs;
+ return 0;
}
-#endif
+#endif /* CONFIG_CPU_FREQ_GOV_SCHEDUTIL */
#ifdef CONFIG_HAVE_SCHED_AVG_IRQ
static inline unsigned long cpu_util_irq(struct rq *rq)
next prev parent reply other threads:[~2019-06-25 8:37 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-21 8:42 [PATCH v10 00/16] Add utilization clamping support Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 01/16] sched/core: uclamp: Add CPU's clamp buckets refcounting Patrick Bellasi
2019-06-25 8:30 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 02/16] sched/core: uclamp: Add bucket local max tracking Patrick Bellasi
2019-06-25 8:30 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 03/16] sched/core: uclamp: Enforce last task's UCLAMP_MAX Patrick Bellasi
2019-06-25 8:31 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 04/16] sched/core: uclamp: Add system default clamps Patrick Bellasi
2019-06-25 8:32 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 05/16] sched/core: Allow sched_setattr() to use the current policy Patrick Bellasi
2019-06-25 8:32 ` [tip:sched/core] " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 06/16] sched/core: uclamp: Extend sched_setattr() to support utilization clamping Patrick Bellasi
2019-06-25 8:33 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 07/16] sched/core: uclamp: Reset uclamp values on RESET_ON_FORK Patrick Bellasi
2019-06-25 8:34 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 08/16] sched/core: uclamp: Set default clamps for RT tasks Patrick Bellasi
2019-06-25 8:35 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 09/16] sched/cpufreq: uclamp: Add clamps for FAIR and " Patrick Bellasi
2019-06-25 8:35 ` [tip:sched/core] sched/cpufreq, sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 10/16] sched/core: uclamp: Add uclamp_util_with() Patrick Bellasi
2019-06-25 8:36 ` [tip:sched/core] sched/uclamp: " tip-bot for Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 11/16] sched/fair: uclamp: Add uclamp support to energy_compute() Patrick Bellasi
2019-06-21 14:01 ` Peter Zijlstra
2019-06-21 14:47 ` Patrick Bellasi
2019-06-25 8:37 ` tip-bot for Patrick Bellasi [this message]
2019-06-21 8:42 ` [PATCH v10 12/16] sched/core: uclamp: Extend CPU's cgroup controller Patrick Bellasi
2019-06-22 15:03 ` Tejun Heo
2019-06-24 17:29 ` Patrick Bellasi
2019-06-24 17:52 ` Tejun Heo
2019-06-25 9:31 ` Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 13/16] sched/core: uclamp: Propagate parent clamps Patrick Bellasi
2019-06-22 15:07 ` Tejun Heo
2019-06-24 17:34 ` Patrick Bellasi
2019-06-24 17:46 ` Tejun Heo
2019-06-21 8:42 ` [PATCH v10 14/16] sched/core: uclamp: Propagate system defaults to root group Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 15/16] sched/core: uclamp: Use TG's clamps to restrict TASK's clamps Patrick Bellasi
2019-06-21 8:42 ` [PATCH v10 16/16] sched/core: uclamp: Update CPU's refcount on TG's clamp changes Patrick Bellasi
2019-06-21 14:55 ` [PATCH v10 00/16] Add utilization clamping support Patrick Bellasi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-af24bde8df2029f067dc46aff0393c8f18ff6e2f@git.kernel.org \
--to=tipbot@zytor.com \
--cc=balsini@android.com \
--cc=dietmar.eggemann@arm.com \
--cc=hpa@zytor.com \
--cc=joelaf@google.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=morten.rasmussen@arm.com \
--cc=patrick.bellasi@arm.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=quentin.perret@arm.com \
--cc=rafael.j.wysocki@intel.com \
--cc=smuckle@google.com \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=tkjos@google.com \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox