linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xuewen Yan <xuewen.yan@unisoc.com>
To: <dietmar.eggemann@arm.com>, <mingo@redhat.com>,
	<peterz@infradead.org>, <juri.lelli@redhat.com>,
	<vincent.guittot@linaro.org>
Cc: <rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>,
	<vschneid@redhat.com>, <vdonnefort@google.com>,
	<ke.wang@unisoc.com>, <xuewen.yan94@gmail.com>,
	<linux-kernel@vger.kernel.org>
Subject: [RFC PATCH] sched/feec: Simplify the traversal of pd'cpus
Date: Tue, 12 Aug 2025 17:33:39 +0800	[thread overview]
Message-ID: <20250812093339.8895-1-xuewen.yan@unisoc.com> (raw)

Now we use for_each_cpu() to traversal all pd's cpus,
it is in order to compute the pd_cap. This approach may
result in some unnecessary judgments.
We can simply calculate pd_cap as follows:

pd_cap = cpu_actual_cap * cpumask_weight(pd_cpus);

Then we can AND pd'scpus, sd's cpus and task's cpus_ptr
before traversing, which can save some unnecessary judgment.

Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
 kernel/sched/fair.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index b173a059315c..e47fe94d6889 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8330,18 +8330,12 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
 		cpu_actual_cap = get_actual_cpu_capacity(cpu);
 
 		eenv.cpu_cap = cpu_actual_cap;
-		eenv.pd_cap = 0;
+		eenv.pd_cap = cpu_actual_cap * cpumask_weight(cpus);
 
-		for_each_cpu(cpu, cpus) {
-			struct rq *rq = cpu_rq(cpu);
-
-			eenv.pd_cap += cpu_actual_cap;
-
-			if (!cpumask_test_cpu(cpu, sched_domain_span(sd)))
-				continue;
+		cpumask_and(cpus, cpus, sched_domain_span(sd));
 
-			if (!cpumask_test_cpu(cpu, p->cpus_ptr))
-				continue;
+		for_each_cpu_and(cpu, cpus, p->cpus_ptr) {
+			struct rq *rq = cpu_rq(cpu);
 
 			util = cpu_util(cpu, p, cpu, 0);
 			cpu_cap = capacity_of(cpu);
-- 
2.25.1


             reply	other threads:[~2025-08-12 10:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-12  9:33 Xuewen Yan [this message]
2025-08-12 21:29 ` [RFC PATCH] sched/feec: Simplify the traversal of pd'cpus Christian Loehle
2025-08-14  8:46 ` Dietmar Eggemann
2025-08-14  9:52   ` Xuewen Yan
2025-08-15 13:01     ` Dietmar Eggemann
2025-08-18 11:05       ` Xuewen Yan
2025-08-18 15:24         ` Dietmar Eggemann
2025-08-19  2:02           ` Xuewen Yan
2025-08-19 14:01             ` Dietmar Eggemann
2025-08-20 11:09               ` 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=20250812093339.8895-1-xuewen.yan@unisoc.com \
    --to=xuewen.yan@unisoc.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=ke.wang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vdonnefort@google.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=xuewen.yan94@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).