From: Austin Clements Date: Wed, 19 Oct 2016 20:00:07 +0000 (-0400) Subject: runtime: eliminate write barriers from dropg X-Git-Tag: go1.8beta1~489 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8044b77a57f9d22e0815ed1476ffa8156b622862;p=gostls13.git runtime: eliminate write barriers from dropg Currently this contains no write barriers because it's writing nil pointers, but with the hybrid barrier, even these will produce write barriers. However, since these are *gs and *ms, they don't need write barriers, so we can simply eliminate them. Updates #17503. Change-Id: Ib188a60492c5cfb352814bf9b2bcb2941fb7d6c0 Reviewed-on: https://go-review.googlesource.com/31570 Reviewed-by: Rick Hudson --- diff --git a/src/runtime/proc.go b/src/runtime/proc.go index c77229b925..eb2532f3c3 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -2175,8 +2175,8 @@ top: func dropg() { _g_ := getg() - _g_.m.curg.m = nil - _g_.m.curg = nil + setMNoWB(&_g_.m.curg.m, nil) + setGNoWB(&_g_.m.curg, nil) } func parkunlock_c(gp *g, lock unsafe.Pointer) bool { diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 683156daf1..49f6e6f649 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -205,6 +205,14 @@ func (gp *guintptr) cas(old, new guintptr) bool { return atomic.Casuintptr((*uintptr)(unsafe.Pointer(gp)), uintptr(old), uintptr(new)) } +// setGNoWB performs *gp = new without a write barrier. +// For times when it's impractical to use a guintptr. +//go:nosplit +//go:nowritebarrier +func setGNoWB(gp **g, new *g) { + (*guintptr)(unsafe.Pointer(gp)).set(new) +} + type puintptr uintptr //go:nosplit @@ -221,6 +229,14 @@ func (mp muintptr) ptr() *m { return (*m)(unsafe.Pointer(mp)) } //go:nosplit func (mp *muintptr) set(m *m) { *mp = muintptr(unsafe.Pointer(m)) } +// setMNoWB performs *mp = new without a write barrier. +// For times when it's impractical to use an muintptr. +//go:nosplit +//go:nowritebarrier +func setMNoWB(mp **m, new *m) { + (*muintptr)(unsafe.Pointer(mp)).set(new) +} + type gobuf struct { // The offsets of sp, pc, and g are known to (hard-coded in) libmach. sp uintptr