Commit fc8eb264 authored by Austin Clements's avatar Austin Clements

runtime: ensure _Grunning Gs have a valid g.m and g.m.p

We already claim on the documentation for _Grunning that this is case,
but execute transitions to _Grunning before assigning g.m. Fix this
and make the documentation even more explicit.

For #10958, #24543, but also a good cleanup.

Change-Id: I1eb0108e7762f55cfb0282aca624af1c0a15fe56
Reviewed-on: https://go-review.googlesource.com/c/go/+/201440
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent f82956b8
...@@ -2177,6 +2177,10 @@ func gcstopm() { ...@@ -2177,6 +2177,10 @@ func gcstopm() {
func execute(gp *g, inheritTime bool) { func execute(gp *g, inheritTime bool) {
_g_ := getg() _g_ := getg()
// Assign gp.m before entering _Grunning so running Gs have an
// M.
_g_.m.curg = gp
gp.m = _g_.m
casgstatus(gp, _Grunnable, _Grunning) casgstatus(gp, _Grunnable, _Grunning)
gp.waitsince = 0 gp.waitsince = 0
gp.preempt = false gp.preempt = false
...@@ -2184,8 +2188,6 @@ func execute(gp *g, inheritTime bool) { ...@@ -2184,8 +2188,6 @@ func execute(gp *g, inheritTime bool) {
if !inheritTime { if !inheritTime {
_g_.m.p.ptr().schedtick++ _g_.m.p.ptr().schedtick++
} }
_g_.m.curg = gp
gp.m = _g_.m
// Check whether the profiler needs to be turned on or off. // Check whether the profiler needs to be turned on or off.
hz := sched.profilehz hz := sched.profilehz
......
...@@ -40,7 +40,7 @@ const ( ...@@ -40,7 +40,7 @@ const (
// _Grunning means this goroutine may execute user code. The // _Grunning means this goroutine may execute user code. The
// stack is owned by this goroutine. It is not on a run queue. // stack is owned by this goroutine. It is not on a run queue.
// It is assigned an M and a P. // It is assigned an M and a P (g.m and g.m.p are valid).
_Grunning // 2 _Grunning // 2
// _Gsyscall means this goroutine is executing a system call. // _Gsyscall means this goroutine is executing a system call.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment