linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] sched/feec: Simplify the traversal of pd'cpus
@ 2025-08-12  9:33 Xuewen Yan
  2025-08-12 21:29 ` Christian Loehle
  2025-08-14  8:46 ` Dietmar Eggemann
  0 siblings, 2 replies; 10+ messages in thread
From: Xuewen Yan @ 2025-08-12  9:33 UTC (permalink / raw)
  To: dietmar.eggemann, mingo, peterz, juri.lelli, vincent.guittot
  Cc: rostedt, bsegall, mgorman, vschneid, vdonnefort, ke.wang,
	xuewen.yan94, linux-kernel

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-08-20 11:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12  9:33 [RFC PATCH] sched/feec: Simplify the traversal of pd'cpus Xuewen Yan
2025-08-12 21:29 ` 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

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).