* [PATCH v2] sched/stats: Fix run_delay over-count for migrated sched_delayed tasks
@ 2026-09-20 4:31 albin_yang
2026-09-20 11:15 ` Kayra Cizmeci
2026-09-21 5:32 ` K Prateek Nayak
0 siblings, 2 replies; 3+ messages in thread
From: albin_yang @ 2026-09-20 4:31 UTC (permalink / raw)
To: peterz, mingo, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
kprateek.nayak, chen.yu, kayracizmeci, mintaohuang, linux-kernel,
albin_yang, albinwyang, Chen Yu
From: Wei Yang <albinwyang@tencent.com>
With DELAY_DEQUEUE, a blocked task stays on the runqueue with
se.sched_delayed set and its sched_info.last_queued is cleared, so the sleep
is not counted into run_delay.
When such a delayed (sleeping) task is migrated across CPUs via the plain
migration paths (move_queued_task / move_queued_task_locked, the latter used
by __migrate_swap_task), activate_task(dst, 0) calls enqueue_task() without
ENQUEUE_RESTORE, re-arming last_queued to the migration timestamp while the
task is still sleeping. The later real wakeup (ENQUEUE_DELAYED) tries to
re-arm last_queued at wakeup time but is suppressed because last_queued is
already non-zero, so sched_info_arrive() folds the whole sleep duration
between migration and wakeup into run_delay.
Load balance is affected too: the sched_delayed check in can_migrate_task()
bails out only when env->migration_type != migrate_load, so it does not
block migration when the type is migrate_load - which active load balance
always uses (its lb_env leaves migration_type at 0 == migrate_load), and
which regular load balance can also use via calculate_imbalance(). Either
way the re-attach goes through attach_task() -> activate_task(rq, p,
ENQUEUE_NOCLOCK), without ENQUEUE_RESTORE.
Fix by not re-arming last_queued for a sched_delayed task in
sched_info_enqueue(). The wakeup path clears sched_delayed before reaching
sched_info_enqueue(), so it still re-arms at the real wakeup time. Plain
runnable tasks are unaffected.
Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue")
Reported-by: MingTao Huang <mintaohuang@tencent.com>
Signed-off-by: Wei Yang <albinwyang@tencent.com>
Reviewed-by: Chen Yu <yu.c.chen@intel.com>
---
v1 -> v2:
- Correct the claim that load-balance migrations are unaffected:
can_migrate_task() only skips a delayed task when migration_type !=
migrate_load, so active load balance (whose lb_env leaves
migration_type at 0 == migrate_load) can migrate a sched_delayed task,
as can regular load balance via the migrate_load branches of
calculate_imbalance(). The fix covers those paths too; only the
description was wrong. Pointed out by Kayra Cizmeci.
- Add Chen Yu's Reviewed-by.
v1: https://lore.kernel.org/all/20260909133345.1572954-1-albin_yang@163.com/
kernel/sched/stats.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
index ebe0a7765f98..dc626f99ffd9 100644
--- a/kernel/sched/stats.h
+++ b/kernel/sched/stats.h
@@ -290,7 +290,7 @@ static void sched_info_arrive(struct rq *rq, struct task_struct *t)
*/
static inline void sched_info_enqueue(struct rq *rq, struct task_struct *t)
{
- if (!t->sched_info.last_queued)
+ if (!t->sched_info.last_queued && !t->se.sched_delayed)
t->sched_info.last_queued = rq_clock(rq);
}
--
2.43.7
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] sched/stats: Fix run_delay over-count for migrated sched_delayed tasks
2026-09-20 4:31 [PATCH v2] sched/stats: Fix run_delay over-count for migrated sched_delayed tasks albin_yang
@ 2026-09-20 11:15 ` Kayra Cizmeci
2026-09-21 5:32 ` K Prateek Nayak
1 sibling, 0 replies; 3+ messages in thread
From: Kayra Cizmeci @ 2026-09-20 11:15 UTC (permalink / raw)
To: albin_yang
Cc: albinwyang, bsegall, chen.yu, dietmar.eggemann, juri.lelli,
kayracizmeci, kprateek.nayak, linux-kernel, mgorman, mingo,
mintaohuang, peterz, rostedt, vincent.guittot, vschneid,
yu.c.chen
Hi Wei,
> Load balance is affected too: the sched_delayed check in can_migrate_task()
> bails out only when env->migration_type != migrate_load, so it does not
> block migration when the type is migrate_load - which active load balance
> always uses (its lb_env leaves migration_type at 0 == migrate_load), and
> which regular load balance can also use via calculate_imbalance(). Either
> way the re-attach goes through attach_task() -> activate_task(rq, p,
> ENQUEUE_NOCLOCK), without ENQUEUE_RESTORE.
> @@ -290,7 +290,7 @@ static void sched_info_arrive(struct rq *rq, struct task_struct *t)
> */
> static inline void sched_info_enqueue(struct rq *rq, struct task_struct *t)
> {
> - if (!t->sched_info.last_queued)
> + if (!t->sched_info.last_queued && !t->se.sched_delayed)
> t->sched_info.last_queued = rq_clock(rq);
> }
Well sched_info_enqueue() gets called from 2 places. The comment above says
otherwise but it's wrong. It gets called from sched_info_depart() and
enqueue_task().
I'll send a patch about that comment later.
Anyway,
Let's say detach_one_task() found the p to detach on active_load_balance_cpu_stop(),
from there, p goes to attach_task() from there. And then
activate_task(), therefore enqueue_task() and
sched_info_enqueue().
If p is delayed then, correctly the sched_info_enqueue() will not start the clock.
If not, it will.
On the second call chain tho, there are task_is_running protection before entering sched_info_enqueue(),
therefore a task cannot run if it is delayed. So the patch's case never runs on that path.
Here:
Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>
Thanks,
Kayra :>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] sched/stats: Fix run_delay over-count for migrated sched_delayed tasks
2026-09-20 4:31 [PATCH v2] sched/stats: Fix run_delay over-count for migrated sched_delayed tasks albin_yang
2026-09-20 11:15 ` Kayra Cizmeci
@ 2026-09-21 5:32 ` K Prateek Nayak
1 sibling, 0 replies; 3+ messages in thread
From: K Prateek Nayak @ 2026-09-21 5:32 UTC (permalink / raw)
To: albin_yang, peterz, mingo, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid, chen.yu,
kayracizmeci, mintaohuang, linux-kernel, albinwyang, Chen Yu
Hello Wei,
On 9/20/2026 10:01 AM, albin_yang@163.com wrote:
> From: Wei Yang <albinwyang@tencent.com>
>
> With DELAY_DEQUEUE, a blocked task stays on the runqueue with
> se.sched_delayed set and its sched_info.last_queued is cleared, so the sleep
> is not counted into run_delay.
>
> When such a delayed (sleeping) task is migrated across CPUs via the plain
> migration paths (move_queued_task / move_queued_task_locked, the latter used
> by __migrate_swap_task), activate_task(dst, 0) calls enqueue_task() without
> ENQUEUE_RESTORE, re-arming last_queued to the migration timestamp while the
> task is still sleeping. The later real wakeup (ENQUEUE_DELAYED) tries to
> re-arm last_queued at wakeup time but is suppressed because last_queued is
> already non-zero, so sched_info_arrive() folds the whole sleep duration
> between migration and wakeup into run_delay.
>
> Load balance is affected too: the sched_delayed check in can_migrate_task()
> bails out only when env->migration_type != migrate_load, so it does not
> block migration when the type is migrate_load - which active load balance
> always uses (its lb_env leaves migration_type at 0 == migrate_load), and
> which regular load balance can also use via calculate_imbalance(). Either
> way the re-attach goes through attach_task() -> activate_task(rq, p,
> ENQUEUE_NOCLOCK), without ENQUEUE_RESTORE.
>
> Fix by not re-arming last_queued for a sched_delayed task in
> sched_info_enqueue(). The wakeup path clears sched_delayed before reaching
> sched_info_enqueue(), so it still re-arms at the real wakeup time. Plain
> runnable tasks are unaffected.
>
> Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue")
> Reported-by: MingTao Huang <mintaohuang@tencent.com>
> Signed-off-by: Wei Yang <albinwyang@tencent.com>
> Reviewed-by: Chen Yu <yu.c.chen@intel.com>
Feel free to include:
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
--
Thanks and Regards,
Prateek
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-21 5:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20 4:31 [PATCH v2] sched/stats: Fix run_delay over-count for migrated sched_delayed tasks albin_yang
2026-09-20 11:15 ` Kayra Cizmeci
2026-09-21 5:32 ` K Prateek Nayak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®