mirror of
https://github.com/golang/go.git
synced 2025-05-18 13:54:40 +00:00
runtime: simplify nobarrierWakeTime
Also use the simplified nobarrierWakeTime in findrunnable, as it no longer needs the current time. Change-Id: I77b125d6a184dde0aeb517fc068164c274f0a046 Reviewed-on: https://go-review.googlesource.com/c/go/+/266304 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
a313eec386
commit
e02ab89eb8
@ -2659,18 +2659,9 @@ stop:
|
|||||||
// checkTimers here because it calls adjusttimers which may need to allocate
|
// checkTimers here because it calls adjusttimers which may need to allocate
|
||||||
// memory, and that isn't allowed when we don't have an active P.
|
// memory, and that isn't allowed when we don't have an active P.
|
||||||
for _, _p_ := range allpSnapshot {
|
for _, _p_ := range allpSnapshot {
|
||||||
// This is similar to nobarrierWakeTime, but minimizes calls to
|
w := nobarrierWakeTime(_p_)
|
||||||
// nanotime.
|
if w != 0 && (pollUntil == 0 || w < pollUntil) {
|
||||||
if atomic.Load(&_p_.adjustTimers) > 0 {
|
pollUntil = w
|
||||||
if now == 0 {
|
|
||||||
now = nanotime()
|
|
||||||
}
|
|
||||||
pollUntil = now
|
|
||||||
} else {
|
|
||||||
w := int64(atomic.Load64(&_p_.timer0When))
|
|
||||||
if w != 0 && (pollUntil == 0 || w < pollUntil) {
|
|
||||||
pollUntil = w
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pollUntil != 0 {
|
if pollUntil != 0 {
|
||||||
|
@ -742,16 +742,15 @@ func addAdjustedTimers(pp *p, moved []*timer) {
|
|||||||
// nobarrierWakeTime looks at P's timers and returns the time when we
|
// nobarrierWakeTime looks at P's timers and returns the time when we
|
||||||
// should wake up the netpoller. It returns 0 if there are no timers.
|
// should wake up the netpoller. It returns 0 if there are no timers.
|
||||||
// This function is invoked when dropping a P, and must run without
|
// This function is invoked when dropping a P, and must run without
|
||||||
// any write barriers. Therefore, if there are any timers that needs
|
// any write barriers.
|
||||||
// to be moved earlier, it conservatively returns the current time.
|
|
||||||
// The netpoller M will wake up and adjust timers before sleeping again.
|
|
||||||
//go:nowritebarrierrec
|
//go:nowritebarrierrec
|
||||||
func nobarrierWakeTime(pp *p) int64 {
|
func nobarrierWakeTime(pp *p) int64 {
|
||||||
if atomic.Load(&pp.adjustTimers) > 0 {
|
next := int64(atomic.Load64(&pp.timer0When))
|
||||||
return nanotime()
|
nextAdj := int64(atomic.Load64(&pp.timerModifiedEarliest))
|
||||||
} else {
|
if next == 0 || (nextAdj != 0 && nextAdj < next) {
|
||||||
return int64(atomic.Load64(&pp.timer0When))
|
next = nextAdj
|
||||||
}
|
}
|
||||||
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
// runtimer examines the first timer in timers. If it is ready based on now,
|
// runtimer examines the first timer in timers. If it is ready based on now,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user