Commit 8044b77a authored by Austin Clements's avatar Austin Clements

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/31570Reviewed-by: default avatarRick Hudson <rlh@golang.org>
parent 85c22bc3
...@@ -2175,8 +2175,8 @@ top: ...@@ -2175,8 +2175,8 @@ top:
func dropg() { func dropg() {
_g_ := getg() _g_ := getg()
_g_.m.curg.m = nil setMNoWB(&_g_.m.curg.m, nil)
_g_.m.curg = nil setGNoWB(&_g_.m.curg, nil)
} }
func parkunlock_c(gp *g, lock unsafe.Pointer) bool { func parkunlock_c(gp *g, lock unsafe.Pointer) bool {
......
...@@ -205,6 +205,14 @@ func (gp *guintptr) cas(old, new guintptr) bool { ...@@ -205,6 +205,14 @@ func (gp *guintptr) cas(old, new guintptr) bool {
return atomic.Casuintptr((*uintptr)(unsafe.Pointer(gp)), uintptr(old), uintptr(new)) 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 type puintptr uintptr
//go:nosplit //go:nosplit
...@@ -221,6 +229,14 @@ func (mp muintptr) ptr() *m { return (*m)(unsafe.Pointer(mp)) } ...@@ -221,6 +229,14 @@ func (mp muintptr) ptr() *m { return (*m)(unsafe.Pointer(mp)) }
//go:nosplit //go:nosplit
func (mp *muintptr) set(m *m) { *mp = muintptr(unsafe.Pointer(m)) } 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 { type gobuf struct {
// The offsets of sp, pc, and g are known to (hard-coded in) libmach. // The offsets of sp, pc, and g are known to (hard-coded in) libmach.
sp uintptr sp uintptr
......
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