]> Cypherpunks repositories - gostls13.git/commit
runtime: check global runq during "delicate dance"
authorMichael Pratt <mpratt@google.com>
Wed, 7 Jun 2023 15:38:26 +0000 (11:38 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 20 Jul 2023 21:39:53 +0000 (21:39 +0000)
commitdd5db4df560341cb2f9f15b98de596bfcb3ed7b2
treeee8ca4708f0b8cb94353c28551bc4cd564a48862
parent884aa71f5126d10f7fa4cbf2dd643b3595763908
runtime: check global runq during "delicate dance"

When a thread transitions to spinning to non-spinning it must recheck
all sources of work because other threads may submit new work but skip
wakep because they see a spinning thread.

However, since the beginning of time (CL 7314062) we do not check the
global run queue, only the local per-P run queues.

The global run queue is checked just above the spinning checks while
dropping the P. I am unsure what the purpose of this check is. It
appears to simply be opportunistic since sched.lock is already held
there in order to drop the P. It is not sufficient to synchronize with
threads adding work because it occurs before decrementing
sched.nmspinning, which is what threads us to decide to wake a thread.

Resolve this by adding an explicit global run queue check alongside the
local per-P run queue checks.

Almost nothing happens between dropped sched.lock after dropping the P
and relocking sched.lock: just clearing mp.spinning and decrementing
sched.nmspinning. Thus it may be better to just hold sched.lock for this
entire period, but this is a larger change that I would prefer to avoid
in the freeze and backports.

For #55160.

Change-Id: Ifd88b5a4c561c063cedcfcfe1dd8ae04202d9666
Reviewed-on: https://go-review.googlesource.com/c/go/+/501975
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/runtime/proc.go