mirror of
https://github.com/golang/go.git
synced 2025-10-19 11:03:18 +00:00
runtime: deduplicate pMask resize code
Change-Id: I04a9a69904710a488c685cb9eee9c3313ed8e97b Reviewed-on: https://go-review.googlesource.com/c/go/+/701896 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
fde10c4ce7
commit
69e74b0aac
1 changed files with 20 additions and 17 deletions
|
@ -5873,8 +5873,6 @@ func procresize(nprocs int32) *p {
|
|||
}
|
||||
sched.procresizetime = now
|
||||
|
||||
maskWords := (nprocs + 31) / 32
|
||||
|
||||
// Grow allp if necessary.
|
||||
if nprocs > int32(len(allp)) {
|
||||
// Synchronize with retake, which could be running
|
||||
|
@ -5890,19 +5888,8 @@ func procresize(nprocs int32) *p {
|
|||
allp = nallp
|
||||
}
|
||||
|
||||
if maskWords <= int32(cap(idlepMask)) {
|
||||
idlepMask = idlepMask[:maskWords]
|
||||
timerpMask = timerpMask[:maskWords]
|
||||
} else {
|
||||
nidlepMask := make([]uint32, maskWords)
|
||||
// No need to copy beyond len, old Ps are irrelevant.
|
||||
copy(nidlepMask, idlepMask)
|
||||
idlepMask = nidlepMask
|
||||
|
||||
ntimerpMask := make([]uint32, maskWords)
|
||||
copy(ntimerpMask, timerpMask)
|
||||
timerpMask = ntimerpMask
|
||||
}
|
||||
idlepMask = idlepMask.resize(nprocs)
|
||||
timerpMask = timerpMask.resize(nprocs)
|
||||
unlock(&allpLock)
|
||||
}
|
||||
|
||||
|
@ -5965,8 +5952,8 @@ func procresize(nprocs int32) *p {
|
|||
if int32(len(allp)) != nprocs {
|
||||
lock(&allpLock)
|
||||
allp = allp[:nprocs]
|
||||
idlepMask = idlepMask[:maskWords]
|
||||
timerpMask = timerpMask[:maskWords]
|
||||
idlepMask = idlepMask.resize(nprocs)
|
||||
timerpMask = timerpMask.resize(nprocs)
|
||||
unlock(&allpLock)
|
||||
}
|
||||
|
||||
|
@ -6905,6 +6892,22 @@ func (p pMask) clear(id int32) {
|
|||
atomic.And(&p[word], ^mask)
|
||||
}
|
||||
|
||||
// resize resizes the pMask and returns a new one.
|
||||
//
|
||||
// The result may alias p, so callers are encouraged to
|
||||
// discard p. Not safe for concurrent use.
|
||||
func (p pMask) resize(nprocs int32) pMask {
|
||||
maskWords := (nprocs + 31) / 32
|
||||
|
||||
if maskWords <= int32(cap(p)) {
|
||||
return p[:maskWords]
|
||||
}
|
||||
newMask := make([]uint32, maskWords)
|
||||
// No need to copy beyond len, old Ps are irrelevant.
|
||||
copy(newMask, p)
|
||||
return newMask
|
||||
}
|
||||
|
||||
// pidleput puts p on the _Pidle list. now must be a relatively recent call
|
||||
// to nanotime or zero. Returns now or the current time if now was zero.
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue