]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add debug mode to extend _Grunning-without-P windows
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 30 Oct 2025 17:24:47 +0000 (17:24 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 14 Nov 2025 19:15:39 +0000 (11:15 -0800)
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>

src/runtime/proc.go

index 44b64913a56ae3550f303e85f995a39c74df4c8d..44dbb2fd44b7a642a01c9ec2f6fd9cd6542b3328 100644 (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()