Message ID | 20230129161444.1674958-2-qyousef@layalina.io |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1801711wrn; Sun, 29 Jan 2023 08:17:10 -0800 (PST) X-Google-Smtp-Source: AK7set+X9lp0nENKgmaNcM4rOYM7vSS9pQlIcajjuW52jNhKjqikr+yF97mwZ9ypZpMqC31l842q X-Received: by 2002:a17:903:2291:b0:196:704e:2c9c with SMTP id b17-20020a170903229100b00196704e2c9cmr5571959plh.23.1675009029784; Sun, 29 Jan 2023 08:17:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675009029; cv=none; d=google.com; s=arc-20160816; b=fkHJwpDEn1GUC8nsTgl+53stRqedyLjt30d7Trz2NjsRT7Bp29LBQNexw2UscmeNHp pwMsqE4diN25Dqq0gOf0gKG0Kfi0F4fkM66aJsHILMX+GdJa9QFvhuW4XxtJFj/E0ozh 8ExB52Cl+ub4Uv7LWtj+VQIlVLFhlcyw+Ty/1+NOIll5QK9zXv1LQXEerieEQ72n6eql 023YnAb+eO3vVR7wmMVsf+aAxRf1BD3rp3yTUNk0ciTu3642z88f7cwtkaRX0qUdTqyL udEq0egQOe3bVl3nikGrwJpyzRTBguOEaLiYEVKju/9EcFo+o6LBAieLJntlwb+iGd+B PgbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/kxYlHG5oFypkr3pUxTSgVEs+bHMQxU7f8JXM84b6kU=; b=vBPE+V8OlWSZSWMQP2D3qVCUl2nWQ7hsiWCkgN9N93J2nsA4O8QsnIqmRz59Fso8LE bi5NUA6oNNLt3D29cyGcc78yydrAUWE91gwy/ppzglJpgCvzTap38WAvrbQp5Tk6pHDK skYgwJC+UpLQ1hdDDnzaeBoyIae1bj6KBxI5TSQRcXMejZ5XxHudQF3GLSpI6fZK1WfY gA8S2v2dtgPjalsu2rJ/hXKSwTJlIm6L/LQcnkVIFB2ILr7MR9XG3SNIw6Ugyxk5WIwL K1s5SLBhvMOotSQbjvlO/wjzp8MStAD2uTfj4ATib5QTGA/AVXY/JM89Rt4vmVm6eTmg iviw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@layalina-io.20210112.gappssmtp.com header.s=20210112 header.b=xWPLpgWG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020a17090311c700b00194c4985c98si11655513plh.248.2023.01.29.08.16.57; Sun, 29 Jan 2023 08:17:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@layalina-io.20210112.gappssmtp.com header.s=20210112 header.b=xWPLpgWG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231429AbjA2QPC (ORCPT <rfc822;n2h9z4@gmail.com> + 99 others); Sun, 29 Jan 2023 11:15:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230076AbjA2QO7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 29 Jan 2023 11:14:59 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 443E71E2B6 for <linux-kernel@vger.kernel.org>; Sun, 29 Jan 2023 08:14:58 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id k16so6524954wms.2 for <linux-kernel@vger.kernel.org>; Sun, 29 Jan 2023 08:14:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=layalina-io.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/kxYlHG5oFypkr3pUxTSgVEs+bHMQxU7f8JXM84b6kU=; b=xWPLpgWGnvTZ6YPIRhflVxRly7YPZXXxsbkCDMr1V9tgl3OcDFvX1jB8BCsQvhfWAE AKWiXP2zsYbejjJQZSCvgb76nD6oXvrJdJUNFD1+zhtpUEx6jncBjHvxh94Vvh/1IA7y tOLpgLsOGJPNcEus+SGg9Q7unk+lS1UGdD07UX3+KaQWUa8rZUUHc72tF0OGK29SUu0d qOgfc/TkSl0VJcRH2qdxfdQqZ+hNNaFVz4lVXlgpi6/yvBNf+6dnxnRHGmB5XP5KUQKm hG56PLnLpDBtTY102dJAN8jg5h+dER0yigjHVjxr2nrBey9AlwVGpTlTDBuo2ogYp1/0 1Y3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/kxYlHG5oFypkr3pUxTSgVEs+bHMQxU7f8JXM84b6kU=; b=HUTaJZwPxAWTfjvWfHEwqPG8SZxygP8l9kuR4K0N/g1Tz5UgAHq3bhqQqPFhrjgnST Tq2RslgZY7/7tWSFE8AmF0ufJt5Gwv1ML4iJMINbf70tczqZYx0yDFyfquPIYdccGKZO gdmt2GBX1uMX4Ez4dsMO1cBkNxahhGFrzu7S67mdlNDm/to7NAKJxeb7SPbf6Fbg/Y+w T1oTvPLdEivDV2iLpBhF+atB0thlOQn84xNliHFv+4CoZuCyrkJyFr1mTRhO3LFYTlMh OOLx8nyO3AIEJxkDwXTMZoVzdHddHXlI2D2LlPPmKDhdfPAiw8erd1aN4T8ffzh6SZix lD9g== X-Gm-Message-State: AFqh2krv74zcNXMWhw+4jUQp6mkakzHRTS3rUdhSU5QOxBF+PzhrunpS 3ZCi/HZjdpbGeOPjCWvrvLWyz9Z/A1WP3ZSe X-Received: by 2002:a05:600c:3d16:b0:3cf:8b22:76b3 with SMTP id bh22-20020a05600c3d1600b003cf8b2276b3mr44438418wmb.0.1675008896912; Sun, 29 Jan 2023 08:14:56 -0800 (PST) Received: from localhost.localdomain (host86-163-35-10.range86-163.btcentralplus.com. [86.163.35.10]) by smtp.gmail.com with ESMTPSA id e5-20020a05600c254500b003dc47fb33dasm5324783wma.18.2023.01.29.08.14.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 08:14:56 -0800 (PST) From: Qais Yousef <qyousef@layalina.io> To: Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Vincent Guittot <vincent.guittot@linaro.org>, Dietmar Eggemann <dietmar.eggemann@arm.com> Cc: linux-kernel@vger.kernel.org, Lukasz Luba <lukasz.luba@arm.com>, Wei Wang <wvw@google.com>, Xuewen Yan <xuewen.yan94@gmail.com>, Hank <han.lin@mediatek.com>, Jonathan JMChen <Jonathan.JMChen@mediatek.com>, Qais Yousef <qyousef@layalina.io> Subject: [PATCH 1/3] sched/uclamp: Set max_spare_cap_cpu even if max_spare_cap is 0 Date: Sun, 29 Jan 2023 16:14:42 +0000 Message-Id: <20230129161444.1674958-2-qyousef@layalina.io> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230129161444.1674958-1-qyousef@layalina.io> References: <20230129161444.1674958-1-qyousef@layalina.io> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756374268751244561?= X-GMAIL-MSGID: =?utf-8?q?1756374268751244561?= |
Series |
Fix a couple of corner cases in feec() when using uclamp_max
|
|
Commit Message
Qais Yousef
Jan. 29, 2023, 4:14 p.m. UTC
When uclamp_max is being used, the util of the task could be higher than
the spare capacity of the CPU, but due to uclamp_max value we force fit
it there.
The way the condition for checking for max_spare_cap in
find_energy_efficient_cpu() was constructed; it ignored any CPU that has
its spare_cap less than or _equal_ to max_spare_cap. Since we initialize
max_spare_cap to 0; this lead to never setting max_spare_cap_cpu and
hence ending up never performing compute_energy() for this cluster and
missing an opportunity for a better energy efficient placement to honour
uclamp_max setting.
max_spare_cap = 0;
cpu_cap = capacity_of(cpu) - task_util(p); // 0 if task_util(p) is high
...
util_fits_cpu(...); // will return true if uclamp_max forces it to fit
...
// this logic will fail to update max_spare_cap_cpu if cpu_cap is 0
if (cpu_cap > max_spare_cap) {
max_spare_cap = cpu_cap;
max_spare_cap_cpu = cpu;
}
prev_spare_cap suffers from a similar problem.
Fix the logic by treating -1UL value as 'not populated' instead of
0 which is a viable and correct spare capacity value.
Fixes: 1d42509e475c ("sched/fair: Make EAS wakeup placement consider uclamp restrictions")
Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io>
---
kernel/sched/fair.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
Comments
On 01/29/23 16:14, Qais Yousef wrote: > When uclamp_max is being used, the util of the task could be higher than > the spare capacity of the CPU, but due to uclamp_max value we force fit > it there. > > The way the condition for checking for max_spare_cap in > find_energy_efficient_cpu() was constructed; it ignored any CPU that has > its spare_cap less than or _equal_ to max_spare_cap. Since we initialize > max_spare_cap to 0; this lead to never setting max_spare_cap_cpu and > hence ending up never performing compute_energy() for this cluster and > missing an opportunity for a better energy efficient placement to honour > uclamp_max setting. > > max_spare_cap = 0; > cpu_cap = capacity_of(cpu) - task_util(p); // 0 if task_util(p) is high > > ... > > util_fits_cpu(...); // will return true if uclamp_max forces it to fit > > ... > > // this logic will fail to update max_spare_cap_cpu if cpu_cap is 0 > if (cpu_cap > max_spare_cap) { > max_spare_cap = cpu_cap; > max_spare_cap_cpu = cpu; > } > > prev_spare_cap suffers from a similar problem. > > Fix the logic by treating -1UL value as 'not populated' instead of > 0 which is a viable and correct spare capacity value. > > Fixes: 1d42509e475c ("sched/fair: Make EAS wakeup placement consider uclamp restrictions") > Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io> > --- > kernel/sched/fair.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index e29e9ea4cde8..ca2c389d3180 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7390,9 +7390,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > for (; pd; pd = pd->next) { > unsigned long util_min = p_util_min, util_max = p_util_max; > unsigned long cpu_cap, cpu_thermal_cap, util; > - unsigned long cur_delta, max_spare_cap = 0; > + unsigned long cur_delta, max_spare_cap = -1UL; > unsigned long rq_util_min, rq_util_max; > - unsigned long prev_spare_cap = 0; > + unsigned long prev_spare_cap = -1UL; > int max_spare_cap_cpu = -1; > unsigned long base_energy; > int fits, max_fits = -1; > @@ -7457,7 +7457,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > prev_spare_cap = cpu_cap; > prev_fits = fits; > } else if ((fits > max_fits) || > - ((fits == max_fits) && (cpu_cap > max_spare_cap))) { > + ((fits == max_fits) && > + (cpu_cap > max_spare_cap || max_spare_cap == -1UL) { Oops. Sorry I just realized I bodged this while rebasing and preparing the patches for posting. There are missing termination parenthesis that will cause compilation errors. Apologies.. -- Qais Yousef > /* > * Find the CPU with the maximum spare capacity > * among the remaining CPUs in the performance > @@ -7469,7 +7470,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > } > } > > - if (max_spare_cap_cpu < 0 && prev_spare_cap == 0) > + if (max_spare_cap_cpu < 0 && prev_spare_cap == -1UL) > continue; > > eenv_pd_busy_time(&eenv, cpus, p); > @@ -7477,7 +7478,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > base_energy = compute_energy(&eenv, pd, cpus, p, -1); > > /* Evaluate the energy impact of using prev_cpu. */ > - if (prev_spare_cap > 0) { > + if (prev_spare_cap != -1UL) { > prev_delta = compute_energy(&eenv, pd, cpus, p, > prev_cpu); > /* CPU utilization has changed */ > @@ -7489,7 +7490,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > } > > /* Evaluate the energy impact of using max_spare_cap_cpu. */ > - if (max_spare_cap_cpu >= 0 && max_spare_cap > prev_spare_cap) { > + if (max_spare_cap_cpu >= 0 && > + (max_spare_cap > prev_spare_cap || prev_spare_cap == -1UL)) { > /* Current best energy cpu fits better */ > if (max_fits < best_fits) > continue; > -- > 2.25.1 >
On Sun, 29 Jan 2023 at 17:14, Qais Yousef <qyousef@layalina.io> wrote: > > When uclamp_max is being used, the util of the task could be higher than > the spare capacity of the CPU, but due to uclamp_max value we force fit > it there. > > The way the condition for checking for max_spare_cap in > find_energy_efficient_cpu() was constructed; it ignored any CPU that has > its spare_cap less than or _equal_ to max_spare_cap. Since we initialize > max_spare_cap to 0; this lead to never setting max_spare_cap_cpu and > hence ending up never performing compute_energy() for this cluster and > missing an opportunity for a better energy efficient placement to honour > uclamp_max setting. > > max_spare_cap = 0; > cpu_cap = capacity_of(cpu) - task_util(p); // 0 if task_util(p) is high > > ... > > util_fits_cpu(...); // will return true if uclamp_max forces it to fit > > ... > > // this logic will fail to update max_spare_cap_cpu if cpu_cap is 0 > if (cpu_cap > max_spare_cap) { > max_spare_cap = cpu_cap; > max_spare_cap_cpu = cpu; > } > > prev_spare_cap suffers from a similar problem. > > Fix the logic by treating -1UL value as 'not populated' instead of > 0 which is a viable and correct spare capacity value. > > Fixes: 1d42509e475c ("sched/fair: Make EAS wakeup placement consider uclamp restrictions") > Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io> > --- > kernel/sched/fair.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index e29e9ea4cde8..ca2c389d3180 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7390,9 +7390,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > for (; pd; pd = pd->next) { > unsigned long util_min = p_util_min, util_max = p_util_max; > unsigned long cpu_cap, cpu_thermal_cap, util; > - unsigned long cur_delta, max_spare_cap = 0; > + unsigned long cur_delta, max_spare_cap = -1UL; > unsigned long rq_util_min, rq_util_max; > - unsigned long prev_spare_cap = 0; > + unsigned long prev_spare_cap = -1UL; > int max_spare_cap_cpu = -1; > unsigned long base_energy; > int fits, max_fits = -1; > @@ -7457,7 +7457,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > prev_spare_cap = cpu_cap; > prev_fits = fits; > } else if ((fits > max_fits) || > - ((fits == max_fits) && (cpu_cap > max_spare_cap))) { > + ((fits == max_fits) && > + (cpu_cap > max_spare_cap || max_spare_cap == -1UL) { Can't we use a signed comparison to include the case of max_spare_cap == -1 in cpu_cap > max_spare_cap ? > /* > * Find the CPU with the maximum spare capacity > * among the remaining CPUs in the performance > @@ -7469,7 +7470,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > } > } > > - if (max_spare_cap_cpu < 0 && prev_spare_cap == 0) > + if (max_spare_cap_cpu < 0 && prev_spare_cap == -1UL) > continue; > > eenv_pd_busy_time(&eenv, cpus, p); > @@ -7477,7 +7478,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > base_energy = compute_energy(&eenv, pd, cpus, p, -1); > > /* Evaluate the energy impact of using prev_cpu. */ > - if (prev_spare_cap > 0) { > + if (prev_spare_cap != -1UL) { > prev_delta = compute_energy(&eenv, pd, cpus, p, > prev_cpu); > /* CPU utilization has changed */ > @@ -7489,7 +7490,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > } > > /* Evaluate the energy impact of using max_spare_cap_cpu. */ > - if (max_spare_cap_cpu >= 0 && max_spare_cap > prev_spare_cap) { > + if (max_spare_cap_cpu >= 0 && > + (max_spare_cap > prev_spare_cap || prev_spare_cap == -1UL)) { > /* Current best energy cpu fits better */ > if (max_fits < best_fits) > continue; > -- > 2.25.1 >
On 01/30/23 15:44, Vincent Guittot wrote: > On Sun, 29 Jan 2023 at 17:14, Qais Yousef <qyousef@layalina.io> wrote: > > > > When uclamp_max is being used, the util of the task could be higher than > > the spare capacity of the CPU, but due to uclamp_max value we force fit > > it there. > > > > The way the condition for checking for max_spare_cap in > > find_energy_efficient_cpu() was constructed; it ignored any CPU that has > > its spare_cap less than or _equal_ to max_spare_cap. Since we initialize > > max_spare_cap to 0; this lead to never setting max_spare_cap_cpu and > > hence ending up never performing compute_energy() for this cluster and > > missing an opportunity for a better energy efficient placement to honour > > uclamp_max setting. > > > > max_spare_cap = 0; > > cpu_cap = capacity_of(cpu) - task_util(p); // 0 if task_util(p) is high > > > > ... > > > > util_fits_cpu(...); // will return true if uclamp_max forces it to fit > > > > ... > > > > // this logic will fail to update max_spare_cap_cpu if cpu_cap is 0 > > if (cpu_cap > max_spare_cap) { > > max_spare_cap = cpu_cap; > > max_spare_cap_cpu = cpu; > > } > > > > prev_spare_cap suffers from a similar problem. > > > > Fix the logic by treating -1UL value as 'not populated' instead of > > 0 which is a viable and correct spare capacity value. > > > > Fixes: 1d42509e475c ("sched/fair: Make EAS wakeup placement consider uclamp restrictions") > > Signed-off-by: Qais Yousef (Google) <qyousef@layalina.io> > > --- > > kernel/sched/fair.c | 14 ++++++++------ > > 1 file changed, 8 insertions(+), 6 deletions(-) > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index e29e9ea4cde8..ca2c389d3180 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -7390,9 +7390,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > > for (; pd; pd = pd->next) { > > unsigned long util_min = p_util_min, util_max = p_util_max; > > unsigned long cpu_cap, cpu_thermal_cap, util; > > - unsigned long cur_delta, max_spare_cap = 0; > > + unsigned long cur_delta, max_spare_cap = -1UL; > > unsigned long rq_util_min, rq_util_max; > > - unsigned long prev_spare_cap = 0; > > + unsigned long prev_spare_cap = -1UL; > > int max_spare_cap_cpu = -1; > > unsigned long base_energy; > > int fits, max_fits = -1; > > @@ -7457,7 +7457,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > > prev_spare_cap = cpu_cap; > > prev_fits = fits; > > } else if ((fits > max_fits) || > > - ((fits == max_fits) && (cpu_cap > max_spare_cap))) { > > + ((fits == max_fits) && > > + (cpu_cap > max_spare_cap || max_spare_cap == -1UL) { > > Can't we use a signed comparison to include the case of max_spare_cap > == -1 in cpu_cap > max_spare_cap ? By converting max_spare_cap to long, right? My memory could be failing me, but I seem to remember we had mixed usage and consolidated into unsigned long. That's why I didn't want to break the trend. Anyway. If no one shouts against that, I don't mind going for that. Thanks -- Qais Yousef > > > /* > > * Find the CPU with the maximum spare capacity > > * among the remaining CPUs in the performance > > @@ -7469,7 +7470,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > > } > > } > > > > - if (max_spare_cap_cpu < 0 && prev_spare_cap == 0) > > + if (max_spare_cap_cpu < 0 && prev_spare_cap == -1UL) > > continue; > > > > eenv_pd_busy_time(&eenv, cpus, p); > > @@ -7477,7 +7478,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > > base_energy = compute_energy(&eenv, pd, cpus, p, -1); > > > > /* Evaluate the energy impact of using prev_cpu. */ > > - if (prev_spare_cap > 0) { > > + if (prev_spare_cap != -1UL) { > > prev_delta = compute_energy(&eenv, pd, cpus, p, > > prev_cpu); > > /* CPU utilization has changed */ > > @@ -7489,7 +7490,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > > } > > > > /* Evaluate the energy impact of using max_spare_cap_cpu. */ > > - if (max_spare_cap_cpu >= 0 && max_spare_cap > prev_spare_cap) { > > + if (max_spare_cap_cpu >= 0 && > > + (max_spare_cap > prev_spare_cap || prev_spare_cap == -1UL)) { > > /* Current best energy cpu fits better */ > > if (max_fits < best_fits) > > continue; > > -- > > 2.25.1 > >
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e29e9ea4cde8..ca2c389d3180 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7390,9 +7390,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) for (; pd; pd = pd->next) { unsigned long util_min = p_util_min, util_max = p_util_max; unsigned long cpu_cap, cpu_thermal_cap, util; - unsigned long cur_delta, max_spare_cap = 0; + unsigned long cur_delta, max_spare_cap = -1UL; unsigned long rq_util_min, rq_util_max; - unsigned long prev_spare_cap = 0; + unsigned long prev_spare_cap = -1UL; int max_spare_cap_cpu = -1; unsigned long base_energy; int fits, max_fits = -1; @@ -7457,7 +7457,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) prev_spare_cap = cpu_cap; prev_fits = fits; } else if ((fits > max_fits) || - ((fits == max_fits) && (cpu_cap > max_spare_cap))) { + ((fits == max_fits) && + (cpu_cap > max_spare_cap || max_spare_cap == -1UL) { /* * Find the CPU with the maximum spare capacity * among the remaining CPUs in the performance @@ -7469,7 +7470,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) } } - if (max_spare_cap_cpu < 0 && prev_spare_cap == 0) + if (max_spare_cap_cpu < 0 && prev_spare_cap == -1UL) continue; eenv_pd_busy_time(&eenv, cpus, p); @@ -7477,7 +7478,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) base_energy = compute_energy(&eenv, pd, cpus, p, -1); /* Evaluate the energy impact of using prev_cpu. */ - if (prev_spare_cap > 0) { + if (prev_spare_cap != -1UL) { prev_delta = compute_energy(&eenv, pd, cpus, p, prev_cpu); /* CPU utilization has changed */ @@ -7489,7 +7490,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) } /* Evaluate the energy impact of using max_spare_cap_cpu. */ - if (max_spare_cap_cpu >= 0 && max_spare_cap > prev_spare_cap) { + if (max_spare_cap_cpu >= 0 && + (max_spare_cap > prev_spare_cap || prev_spare_cap == -1UL)) { /* Current best energy cpu fits better */ if (max_fits < best_fits) continue;