mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: use signals to preempt Gs for suspendG
This adds support for pausing a running G by sending a signal to its M. The main complication is that we want to target a G, but can only send a signal to an M. Hence, the protocol we use is to simply mark the G for preemption (which we already do) and send the M a "wake up and look around" signal. The signal checks if it's running a G with a preemption request and stops it if so in the same way that stack check preemptions stop Gs. Since the preemption may fail (the G could be moved or the signal could arrive at an unsafe point), we keep a count of the number of received preemption signals. This lets stopG detect if its request failed and should be retried without an explicit channel back to suspendG. For #10958, #24543. Change-Id: I3e1538d5ea5200aeb434374abb5d5fdc56107e53 Reviewed-on: https://go-review.googlesource.com/c/go/+/201760 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
d16ec13756
commit
62e53b7922
10 changed files with 294 additions and 8 deletions
|
|
@ -423,6 +423,11 @@ type g struct {
|
|||
preemptStop bool // transition to _Gpreempted on preemption; otherwise, just deschedule
|
||||
preemptShrink bool // shrink stack at synchronous safe point
|
||||
|
||||
// asyncSafePoint is set if g is stopped at an asynchronous
|
||||
// safe point. This means there are frames on the stack
|
||||
// without precise pointer information.
|
||||
asyncSafePoint bool
|
||||
|
||||
paniconfault bool // panic (instead of crash) on unexpected fault address
|
||||
gcscandone bool // g has scanned stack; protected by _Gscan bit in status
|
||||
throwsplit bool // must not split stack
|
||||
|
|
@ -531,6 +536,11 @@ type m struct {
|
|||
vdsoSP uintptr // SP for traceback while in VDSO call (0 if not in call)
|
||||
vdsoPC uintptr // PC for traceback while in VDSO call
|
||||
|
||||
// preemptGen counts the number of completed preemption
|
||||
// signals. This is used to detect when a preemption is
|
||||
// requested, but fails. Accessed atomically.
|
||||
preemptGen uint32
|
||||
|
||||
dlogPerM
|
||||
|
||||
mOS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue