runtime: add mp parameter for getMCache

Since all callers of getMCache appear to have mp available,
we pass the mp to getMCache, and reduce one call to getg.
And after modification, getMCache is also inlined.

Change-Id: Ib7880c118336acc026ecd7c60c5a88722c3ddfc7
Reviewed-on: https://go-review.googlesource.com/c/go/+/349329
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Trust: Carlos Amedee <carlos@golang.org>
This commit is contained in:
Leonard Wang 2021-09-11 20:53:24 +08:00 committed by Ian Lance Taylor
parent 8cf0a087c0
commit 84ba117fd7
2 changed files with 4 additions and 4 deletions

View file

@ -972,7 +972,7 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
shouldhelpgc := false
dataSize := size
c := getMCache()
c := getMCache(mp)
if c == nil {
throw("mallocgc called without a P or outside bootstrapping")
}
@ -1247,7 +1247,7 @@ func reflect_unsafe_NewArray(typ *_type, n int) unsafe.Pointer {
}
func profilealloc(mp *m, x unsafe.Pointer, size uintptr) {
c := getMCache()
c := getMCache(mp)
if c == nil {
throw("profilealloc called without a P or outside bootstrapping")
}

View file

@ -122,9 +122,9 @@ func freemcache(c *mcache) {
//
// Returns nil if we're not bootstrapping or we don't have a P. The caller's
// P must not change, so we must be in a non-preemptible state.
func getMCache() *mcache {
func getMCache(mp *m) *mcache {
// Grab the mcache, since that's where stats live.
pp := getg().m.p.ptr()
pp := mp.p.ptr()
var c *mcache
if pp == nil {
// We will be called without a P while bootstrapping,