aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2025-02-03 16:53:47 +0000
committerGopher Robot <gobot@golang.org>2025-10-30 10:46:51 -0700
commit5b8e85034028906ab0a243399e18fd8b72fe2f76 (patch)
tree1da9d7c2ff0ac1917f43f8e882d405c0bfdf1d82 /src/runtime
parent251814e5804886923dd1bb07d06c94563a4e1d9b (diff)
downloadgo-5b8e85034028906ab0a243399e18fd8b72fe2f76.tar.xz
runtime: don't track scheduling latency for _Grunning <-> _Gsyscall
The current logic causes much more tracking than necessary, when really _Grunning and _Gsyscall are both sort of "running" from the perspective of tracking scheduling latency. This makes cgo calls and syscalls a little faster in the single-threaded case, and shows much larger improvement in the multi-threaded case by removing updates of shared variables (though this parallel microbenchmark is a little unrealistic, so don't ascribe too much weight to it). goos: linux goarch: amd64 pkg: internal/runtime/cgobench cpu: AMD EPYC 7B13 │ after.out │ after-2.out │ │ sec/op │ sec/op vs base │ CgoCall-64 35.83n ± 1% 34.69n ± 1% -3.20% (p=0.002 n=6) CgoCallParallel-64 5.338n ± 1% 1.352n ± 4% -74.67% (p=0.002 n=6) Change-Id: I2ea494dd5ebbbfb457373549986fbe2fbe318d45 Reviewed-on: https://go-review.googlesource.com/c/go/+/646275 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/proc.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 2ec2f8cfca..53f64e8032 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -1316,8 +1316,9 @@ func casgstatus(gp *g, oldval, newval uint32) {
})
}
- if oldval == _Grunning {
- // Track every gTrackingPeriod time a goroutine transitions out of running.
+ if (oldval == _Grunning || oldval == _Gsyscall) && (newval != _Grunning && newval != _Gsyscall) {
+ // Track every gTrackingPeriod time a goroutine transitions out of _Grunning or _Gsyscall.
+ // Do not track _Grunning <-> _Gsyscall transitions, since they're two very similar states.
if casgstatusAlwaysTrack || gp.trackingSeq%gTrackingPeriod == 0 {
gp.tracking = true
}