From: Xuewen Yan <xuewen.yan94@gmail.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com
Cc: rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
bristot@redhat.com, linux-kernel@vger.kernel.org,
quentin.perret@arm.com, zhang.lyra@gmail.com,
xuewyan@foxmail.com
Subject: [PATCH] sched/fair: use signed long when compute energy delta in eas
Date: Tue, 30 Mar 2021 13:21:54 +0800 [thread overview]
Message-ID: <20210330052154.26861-1-xuewen.yan94@gmail.com> (raw)
From: Xuewen Yan <xuewen.yan@unisoc.com>
now the energy delta compute as follow:
base_energy_pd = compute_energy(p, -1, pd);
--->Traverse all CPUs in pd
--->em_pd_energy()
----------------------------------------------------- \
search for the max_sapre_cap_cpu \
--------------------------------- search time
cur_delta = compute_energy(p, max_spare_cap_cpu, pd); /
--->Traverse all CPUs in pd /
---------------------------------------------------- /
--->em_pd_energy()
cur_delta -= base_energy_pd;
During the search_time, or when calculate the cpu_util in
compute_energy(), there may occurred task dequeue or cpu_util change,
it may cause the cur_energy < base_energy_pd, so the cur_delta
would be negative. But the cur_delta is unsigned long, at this time,
the cur_delta would always bigger than best_delta of last pd.
Change the vars to signed long.
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
kernel/sched/fair.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 794c2cb945f8..310d9d215cd7 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6586,7 +6586,7 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd)
*/
static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
{
- unsigned long prev_delta = ULONG_MAX, best_delta = ULONG_MAX;
+ long prev_delta = LONG_MAX, best_delta = LONG_MAX;
struct root_domain *rd = cpu_rq(smp_processor_id())->rd;
unsigned long cpu_cap, util, base_energy = 0;
int cpu, best_energy_cpu = prev_cpu;
@@ -6613,13 +6613,11 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
goto unlock;
for (; pd; pd = pd->next) {
- unsigned long cur_delta, spare_cap, max_spare_cap = 0;
+ long cur_delta;
+ unsigned long spare_cap, max_spare_cap = 0;
unsigned long base_energy_pd;
int max_spare_cap_cpu = -1;
-
- /* Compute the 'base' energy of the pd, without @p */
- base_energy_pd = compute_energy(p, -1, pd);
- base_energy += base_energy_pd;
+ bool prev_in_pd = false;
for_each_cpu_and(cpu, perf_domain_span(pd), sched_domain_span(sd)) {
if (!cpumask_test_cpu(cpu, p->cpus_ptr))
@@ -6641,13 +6639,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
if (!fits_capacity(util, cpu_cap))
continue;
- /* Always use prev_cpu as a candidate. */
- if (cpu == prev_cpu) {
- prev_delta = compute_energy(p, prev_cpu, pd);
- prev_delta -= base_energy_pd;
- best_delta = min(best_delta, prev_delta);
- }
-
+ if (cpu == prev_cpu)
+ prev_in_pd = true;
/*
* Find the CPU with the maximum spare capacity in
* the performance domain
@@ -6658,6 +6651,16 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
}
}
+ /* Compute the 'base' energy of the pd, without @p */
+ base_energy_pd = compute_energy(p, -1, pd);
+ base_energy += base_energy_pd;
+
+ /* Always use prev_cpu as a candidate. */
+ if (prev_in_pd) {
+ prev_delta = compute_energy(p, prev_cpu, pd);
+ prev_delta -= base_energy_pd;
+ best_delta = min(best_delta, prev_delta);
+ }
/* Evaluate the energy impact of using this CPU. */
if (max_spare_cap_cpu >= 0 && max_spare_cap_cpu != prev_cpu) {
cur_delta = compute_energy(p, max_spare_cap_cpu, pd);
@@ -6675,7 +6678,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
* Pick the best CPU if prev_cpu cannot be used, or if it saves at
* least 6% of the energy used by prev_cpu.
*/
- if (prev_delta == ULONG_MAX)
+ if (prev_delta == LONG_MAX)
return best_energy_cpu;
if ((prev_delta - best_delta) > ((prev_delta + base_energy) >> 4))
--
2.29.0
next reply other threads:[~2021-03-30 5:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 5:21 Xuewen Yan [this message]
2021-03-30 9:45 ` [PATCH] sched/fair: use signed long when compute energy delta in eas Quentin Perret
2021-04-01 18:07 ` Dietmar Eggemann
2021-04-06 10:59 ` Xuewen Yan
2021-04-07 14:11 ` Pierre
2021-04-08 5:41 ` Xuewen Yan
2021-04-08 9:33 ` Pierre
2021-04-09 2:20 ` Xuewen Yan
2021-04-12 10:26 ` Pierre Gondois
2021-04-12 10:52 ` Xuewen Yan
2021-04-12 17:14 ` Pierre Gondois
2021-04-13 1:50 ` Xuewen Yan
2021-04-13 10:58 ` Pierre Gondois
2021-04-13 11:59 ` Xuewen Yan
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=20210330052154.26861-1-xuewen.yan94@gmail.com \
--to=xuewen.yan94@gmail.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=quentin.perret@arm.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=xuewyan@foxmail.com \
--cc=zhang.lyra@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).