aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/export_test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2025-04-29 22:55:40 -0400
committerGopher Robot <gobot@golang.org>2025-08-05 13:58:52 -0700
commitaf0c4fe2ca51918bd82231ac48a28a0d0ef15c98 (patch)
treed895c4802fb8aeb94d8c6d1d634bc74f152fb134 /src/runtime/export_test.go
parente73afaae69bb6f098e3c1dbd98cfe134843910a1 (diff)
downloadgo-af0c4fe2ca51918bd82231ac48a28a0d0ef15c98.tar.xz
runtime: save scalar registers off stack in amd64 async preemption
Asynchronous preemption must save all registers that could be in use by Go code. Currently, it saves all of these to the goroutine stack. As a result, the stack frame requirements of asynchronous preemption can be rather high. On amd64, this requires 368 bytes of stack space, most of which is the XMM registers. Several RISC architectures are around 0.5 KiB. As we add support for SIMD instructions, this is going to become a problem. The AVX-512 register state is 2.5 KiB. This well exceeds the nosplit limit, and even if it didn't, could constrain when we can asynchronously preempt goroutines on small stacks. This CL fixes this by moving pure scalar state stored in non-GP registers off the stack and into an allocated "extended register state" object. To reduce space overhead, we only allocate these objects as needed. While in the theoretical limit, every G could need this register state, in practice very few do at a time. However, we can't allocate when we're in the middle of saving the register state during an asynchronous preemption, so we reserve scratch space on every P to temporarily store the register state, which can then be copied out to an allocated state object later by Go code. This commit only implements this for amd64, since that's where we're about to add much more vector state, but it lays the groundwork for doing this on any architecture that could benefit. This is a cherry-pick of CL 680898 plus bug fix CL 684836 from the dev.simd branch. Change-Id: I123a95e21c11d5c10942d70e27f84d2d99bbf735 Reviewed-on: https://go-review.googlesource.com/c/go/+/669195 Auto-Submit: Austin Clements <austin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime/export_test.go')
-rw-r--r--src/runtime/export_test.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go
index fa30efccb1..1f55717f0a 100644
--- a/src/runtime/export_test.go
+++ b/src/runtime/export_test.go
@@ -554,6 +554,8 @@ type G = g
type Sudog = sudog
+type XRegPerG = xRegPerG
+
func Getg() *G {
return getg()
}