[PATCH 1/2] sched/core: Allow newidle for core-sched
From: Peter Zijlstra
Date: Wed Jun 24 2026 - 08:30:55 EST
As reported [1], it is possible for newidle, as called from pick_task_fair(),
to migrate a task that was already selected for the SMT sibling.
That is, in case of core scheduling (pick_next_task()'s restart_multi label),
pick_task() is called for each SMT sibling. Suppose SMT0 picks task A, and SMT1
has no tasks and does newidle, it must not be possible (but currently is) to
migrate A to SMT1 and also select A.
This re-enables newidle balancing for core scheduling.
[1] https://patch.msgid.link/20260603095108.GA1684319@xxxxxxxxxxxxx
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
kernel/sched/fair.c | 6 ++----
kernel/sched/sched.h | 15 ++++++++++++++-
2 files changed, 16 insertions(+), 5 deletions(-)
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9942,9 +9942,6 @@ struct task_struct *pick_task_fair(struc
return p;
idle:
- if (sched_core_enabled(rq))
- return NULL;
-
new_tasks = sched_balance_newidle(rq, rf);
if (new_tasks < 0)
return RETRY_TASK;
@@ -10783,7 +10780,8 @@ int can_migrate_task(struct task_struct
env->flags &= ~LBF_ALL_PINNED;
if (task_on_cpu(env->src_rq, p) ||
- task_current_donor(env->src_rq, p)) {
+ task_current_donor(env->src_rq, p) ||
+ task_on_core(env->src_rq, p)) {
schedstat_inc(p->stats.nr_failed_migrations_running);
return 0;
}
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1570,6 +1570,14 @@ static inline bool task_has_sched_core(s
return !!p->core_cookie;
}
+static inline bool task_on_core(struct rq *rq, struct task_struct *p)
+{
+ if (sched_core_disabled())
+ return false;
+
+ return rq->core_pick == p;
+}
+
#else /* !CONFIG_SCHED_CORE: */
static inline bool sched_core_enabled(struct rq *rq)
@@ -1615,6 +1623,11 @@ static inline bool task_has_sched_core(s
return false;
}
+static inline bool task_on_core(struct rq *rq, struct task_struct *p)
+{
+ return false;
+}
+
#endif /* !CONFIG_SCHED_CORE */
#ifdef CONFIG_RT_GROUP_SCHED
@@ -4131,7 +4144,7 @@ void move_queued_task_locked(struct rq *
static inline
bool task_is_pushable(struct rq *rq, struct task_struct *p, int cpu)
{
- if (!task_on_cpu(rq, p) &&
+ if (!task_on_cpu(rq, p) && !task_on_core(rq, p) &&
cpumask_test_cpu(cpu, &p->cpus_mask))
return true;