]> git.baikalelectronics.ru Git - kernel.git/commit
sched: Fix the check of nr_running at queue wakelist
authorTianchen Ding <dtcccc@linux.alibaba.com>
Wed, 8 Jun 2022 23:34:11 +0000 (07:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:24:15 +0000 (14:24 +0200)
commitf1b7fc1cddb2b7f2afdfc4ce4bba323040b4b6a5
treed3c4178f28d87c1ac5c93ae302225a8300d1b3bd
parent5fd61d293347a0e226798a9f09691f3089dc9223
sched: Fix the check of nr_running at queue wakelist

[ Upstream commit 1fa405bf1eca0dd4a91511d7cbd6021c8f6fc0d7 ]

The commit 5378097a078d ("sched/core: Offload wakee task activation if it
the wakee is descheduling") checked rq->nr_running <= 1 to avoid task
stacking when WF_ON_CPU.

Per the ordering of writes to p->on_rq and p->on_cpu, observing p->on_cpu
(WF_ON_CPU) in ttwu_queue_cond() implies !p->on_rq, IOW p has gone through
the deactivate_task() in __schedule(), thus p has been accounted out of
rq->nr_running. As such, the task being the only runnable task on the rq
implies reading rq->nr_running == 0 at that point.

The benchmark result is in [1].

[1] https://lore.kernel.org/all/e34de686-4e85-bde1-9f3c-9bbc86b38627@linux.alibaba.com/

Suggested-by: Valentin Schneider <vschneid@redhat.com>
Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Link: https://lore.kernel.org/r/20220608233412.327341-2-dtcccc@linux.alibaba.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/sched/core.c