]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: eliminate write barriers from dropg
authorAustin Clements <austin@google.com>
Wed, 19 Oct 2016 20:00:07 +0000 (16:00 -0400)
committerAustin Clements <austin@google.com>
Fri, 28 Oct 2016 20:05:39 +0000 (20:05 +0000)
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 <rlh@golang.org>
src/runtime/proc.go
src/runtime/runtime2.go

index c77229b925ab6ba86bc446e9865e7766ad1524be..eb2532f3c3eade70d40df9b98ec6629da2a5a3fa 100644 (file)
@@ -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 {
index 683156daf1f841d9b5941afb6dc867539b4a5f01..49f6e6f64983277abaa2927ef44bfc38884c21b7 100644 (file)
@@ -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