]> Cypherpunks repositories - gostls13.git/commit
runtime: use signals to preempt Gs for suspendG
authorAustin Clements <austin@google.com>
Tue, 8 Oct 2019 17:23:51 +0000 (13:23 -0400)
committerAustin Clements <austin@google.com>
Sat, 2 Nov 2019 21:51:18 +0000 (21:51 +0000)
commit62e53b79227dafc6afcd92240c89acb8c0e1dd56
tree40e85fda03128d81c0146857f0456d9ea55c32f0
parentd16ec137568fb20e674a99c265e7c340c065dd69
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>
src/os/signal/signal_test.go
src/runtime/mgcmark.go
src/runtime/os_js.go
src/runtime/os_plan9.go
src/runtime/os_windows.go
src/runtime/preempt.go
src/runtime/runtime2.go
src/runtime/signal_unix.go
src/runtime/stack.go
src/runtime/symtab.go