[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251126090401.59698-1-wujianyong@hygon.cn>
Date: Wed, 26 Nov 2025 17:04:01 +0800
From: Jianyong Wu <wujianyong@...on.cn>
To: <peterz@...radead.org>, <mingo@...hat.com>, <juri.lelli@...hat.com>,
<vincent.guittot@...aro.org>
CC: <dietmar.eggemann@....com>, <rostedt@...dmis.org>, <bsegall@...gle.com>,
<mgorman@...e.de>, <vschneid@...hat.com>, <linux-kernel@...r.kernel.org>,
<jianyong.wu@...look.com>, <wujianyong@...on.cn>, <liuyibin@...on.cn>
Subject: [PATCH] sched/core: avoid calling select_task_rq if bound to one CPU for exec
In the current implementation, even if the task calling execl is bound
to a single CPU (or not allowed to be migrated), it still invokes the
select_task_rq() callback to select a CPU. This is unnecessary and
wastes cycles.
Add a check: if the task is restricted to running on exactly one CPU
(cpus_ptr has only one online CPU) or is not allowed to be migrated,
skip select_task_rq() and directly use the task's bound CPU.
Test environment: 256-CPU X86 server
Test method: Run unixbench's execl test with task bound to a single CPU:
$ numactl -C 10 ./Run execl -c 1
Test results: Average of 5 runs
baseline patched improvement
430.38 437.52 +1.66%
Co-developed-by: Yibin Liu <liuyibin@...on.cn>
Signed-off-by: Yibin Liu <liuyibin@...on.cn>
Signed-off-by: Jianyong Wu <wujianyong@...on.cn>
---
kernel/sched/core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f754a60de848..c1e9f633cfb0 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5442,7 +5442,11 @@ void sched_exec(void)
int dest_cpu;
scoped_guard (raw_spinlock_irqsave, &p->pi_lock) {
- dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC);
+ if (p->nr_cpus_allowed > 1 && !is_migration_disabled(p))
+ dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC);
+ else
+ dest_cpu = cpumask_any(p->cpus_ptr);
+
if (dest_cpu == smp_processor_id())
return;
--
2.43.0
Powered by blists - more mailing lists