runtime: store goroutine state behind pthread-key getg#2090
Open
cpunion wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
2 times, most recently
from
July 15, 2026 00:48
b543675 to
57ae899
Compare
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
from
July 15, 2026 08:54
57ae899 to
b651488
Compare
cpunion
marked this pull request as ready for review
July 15, 2026 10:22
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
2 times, most recently
from
July 15, 2026 20:52
63fe488 to
56564e7
Compare
This was referenced Jul 16, 2026
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
3 times, most recently
from
July 18, 2026 23:20
353c562 to
e363bbe
Compare
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
2 times, most recently
from
July 20, 2026 04:24
a309b55 to
34387d1
Compare
This was referenced Jul 20, 2026
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
from
July 23, 2026 09:31
34387d1 to
3434b3c
Compare
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
from
July 23, 2026 10:42
3434b3c to
59a616e
Compare
cpunion
force-pushed
the
codex/runtime-g-state-gls
branch
from
July 24, 2026 03:29
59a616e to
87ba303
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LLGo keeps goroutine-owned runtime state in several pthread-backed locations:
That splits one goroutine's state across unrelated lifetime mechanisms and makes each new field add more key management.
Change
Introduce one runtime
gand onegetgpath:Hosted LLGo targets store
*gbehind one pthread key.getglazily allocates a zeroed GC root, installs it withpthread_setspecific, and reuses it for defer, panic/recover, Goexit, and main state. The pthread-key destructor releases an outstanding panic value and the GC root.Host builds and currently single-context bare-metal targets use the same
gAPI with an ordinary global fallback.This PR does not add compiler directives, locality metadata, package-block storage, or C-library constructor changes. It changes eight files and has an independent diff of
+369/-73.Relation to #2079
This PR and #2079 are independent and can merge in either order.
getg.The current head deliberately uses pthread keys so it can be reviewed and merged without the larger TLS/GLS compiler change.
Runtime cost
Apple M4 Max, macOS arm64, Go 1.26.5, LLVM 19.1.7, real LLGo, five adjacent benchmark runs:
getgthrough one pthread keyThe benchmark reports
0 B/op, 0 allocs/opon the hot path. Allocation occurs once when a pthread first acquires itsg.Validation
Tests were serialized with
GOMAXPROCS=2,GOMEMLIMIT=8GiB, and-p=1.test/llgoextpass.getgwithin one goroutine, distinct state across concurrently live goroutines, defer-head isolation, and Set/Get/Clear transitions.