Skip to content

Commit ec618b8

Browse files
author
Peter Zijlstra
committed
sched: Fix rq->nr_iowait ordering
schedule() ttwu() deactivate_task(); if (p->on_rq && ...) // false atomic_dec(&task_rq(p)->nr_iowait); if (prev->in_iowait) atomic_inc(&rq->nr_iowait); Allows nr_iowait to be decremented before it gets incremented, resulting in more dodgy IO-wait numbers than usual. Note that because we can now do ttwu_queue_wakelist() before p->on_cpu==0, we lose the natural ordering and have to further delay the decrement. Fixes: c6e7bd7 ("sched/core: Optimize ttwu() spinning on p->on_cpu") Reported-by: Tejun Heo <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Mel Gorman <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent f97bb52 commit ec618b8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

kernel/sched/core.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,12 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags,
25012501
#ifdef CONFIG_SMP
25022502
if (wake_flags & WF_MIGRATED)
25032503
en_flags |= ENQUEUE_MIGRATED;
2504+
else
25042505
#endif
2506+
if (p->in_iowait) {
2507+
delayacct_blkio_end(p);
2508+
atomic_dec(&task_rq(p)->nr_iowait);
2509+
}
25052510

25062511
activate_task(rq, p, en_flags);
25072512
ttwu_do_wakeup(rq, p, wake_flags, rf);
@@ -2888,11 +2893,6 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
28882893
if (READ_ONCE(p->on_rq) && ttwu_runnable(p, wake_flags))
28892894
goto unlock;
28902895

2891-
if (p->in_iowait) {
2892-
delayacct_blkio_end(p);
2893-
atomic_dec(&task_rq(p)->nr_iowait);
2894-
}
2895-
28962896
#ifdef CONFIG_SMP
28972897
/*
28982898
* Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be
@@ -2963,6 +2963,11 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
29632963

29642964
cpu = select_task_rq(p, p->wake_cpu, SD_BALANCE_WAKE, wake_flags);
29652965
if (task_cpu(p) != cpu) {
2966+
if (p->in_iowait) {
2967+
delayacct_blkio_end(p);
2968+
atomic_dec(&task_rq(p)->nr_iowait);
2969+
}
2970+
29662971
wake_flags |= WF_MIGRATED;
29672972
psi_ttwu_dequeue(p);
29682973
set_task_cpu(p, cpu);

0 commit comments

Comments
 (0)