]> Cypherpunks repositories - gostls13.git/commit
[dev.simd] runtime: save scalar registers off stack in amd64 async preemption
authorAustin Clements <austin@google.com>
Wed, 30 Apr 2025 02:55:40 +0000 (22:55 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 30 Jun 2025 18:50:33 +0000 (11:50 -0700)
commit426cf36b4d0c672dc88fc5cef9b0d5db0d2f4fe5
tree1ed5d81491cef46cc97b6de82490ed9c8be1961d
parentead249a2e2989c6775235058d38f0e33afdf752a
[dev.simd] 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.

Change-Id: I123a95e21c11d5c10942d70e27f84d2d99bbf735
Reviewed-on: https://go-review.googlesource.com/c/go/+/680898
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Austin Clements <austin@google.com>
13 files changed:
src/runtime/export_test.go
src/runtime/lockrank.go
src/runtime/mheap.go
src/runtime/mklockrank.go
src/runtime/mkpreempt.go
src/runtime/preempt.go
src/runtime/preempt_amd64.go [new file with mode: 0644]
src/runtime/preempt_amd64.s
src/runtime/preempt_noxreg.go [new file with mode: 0644]
src/runtime/preempt_xreg.go [new file with mode: 0644]
src/runtime/proc.go
src/runtime/runtime2.go
src/runtime/sizeof_test.go