runtime: add debug mode to extend _Grunning-without-P windows

This was suggested in CL 646198, and I tested with it, I forgot to push
it so it wasn't merged. I think it might be worth keeping.

Change-Id: Ibf97d969fe7d0eeb365f5f7b1fbeadea3a1076ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/716580
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Anthony Knyszek 2025-10-30 17:24:47 +00:00 committed by Gopher Robot
parent 710abf74da
commit 7a8d0b5d53

View file

@ -4658,6 +4658,11 @@ func reentersyscall(pc, sp, bp uintptr) {
gp.m.locks--
}
// debugExtendGrunningNoP is a debug mode that extends the windows in which
// we're _Grunning without a P in order to try to shake out bugs with code
// assuming this state is impossible.
const debugExtendGrunningNoP = false
// Standard syscall entry used by the go syscall library and normal cgo calls.
//
// This is exported via linkname to assembly in the syscall package and x/sys.
@ -4770,6 +4775,9 @@ func entersyscallblock() {
// <--
// Caution: we're in a small window where we are in _Grunning without a P.
// -->
if debugExtendGrunningNoP {
usleep(10)
}
casgstatus(gp, _Grunning, _Gsyscall)
if gp.syscallsp < gp.stack.lo || gp.stack.hi < gp.syscallsp {
systemstack(func() {
@ -4852,6 +4860,9 @@ func exitsyscall() {
// Caution: we're in a window where we may be in _Grunning without a P.
// Either we will grab a P or call exitsyscall0, where we'll switch to
// _Grunnable.
if debugExtendGrunningNoP {
usleep(10)
}
// Grab and clear our old P.
oldp := gp.m.oldp.ptr()