aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2022-08-17 14:59:57 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2022-08-18 01:46:15 +0000
commitbb5d656a3ac78575d9e2c9bed026cc1756fab179 (patch)
treec8aeb18704bf0d9ae4c242137d224819094cda5d /src
parentb30ba3df9ff8969f934bec5016cfce4b91f6ea5b (diff)
downloadgo-bb5d656a3ac78575d9e2c9bed026cc1756fab179.tar.xz
runtime: convert p.timerModifiedEarliest to atomic type
Updates #53821 Change-Id: Iac0d7a3871d9e3ee0ba38ee7ab989faca9c89666 Reviewed-on: https://go-review.googlesource.com/c/go/+/424397 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/proc.go2
-rw-r--r--src/runtime/runtime2.go3
-rw-r--r--src/runtime/time.go19
3 files changed, 12 insertions, 12 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index f100e321d4..01f9ed5f57 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -3330,7 +3330,7 @@ func checkTimers(pp *p, now int64) (rnow, pollUntil int64, ran bool) {
// If it's not yet time for the first timer, or the first adjusted
// timer, then there is nothing to do.
next := int64(pp.timer0When.Load())
- nextAdj := int64(atomic.Load64(&pp.timerModifiedEarliest))
+ nextAdj := int64(pp.timerModifiedEarliest.Load())
if next == 0 || (nextAdj != 0 && nextAdj < next) {
next = nextAdj
}
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index 34638d9fb3..79c8ccb6ec 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -676,9 +676,8 @@ type p struct {
// The earliest known nextwhen field of a timer with
// timerModifiedEarlier status. Because the timer may have been
// modified again, there need not be any timer with this value.
- // This is updated using atomic functions.
// This is 0 if there are no timerModifiedEarlier timers.
- timerModifiedEarliest uint64
+ timerModifiedEarliest atomic.Uint64
// Per-P GC state
gcAssistTime int64 // Nanoseconds in assistAlloc
diff --git a/src/runtime/time.go b/src/runtime/time.go
index 0ab2c9c21d..7ce3caf113 100644
--- a/src/runtime/time.go
+++ b/src/runtime/time.go
@@ -400,7 +400,7 @@ func dodeltimer(pp *p, i int) int {
n := atomic.Xadd(&pp.numTimers, -1)
if n == 0 {
// If there are no timers, then clearly none are modified.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
}
return smallestChanged
}
@@ -428,7 +428,7 @@ func dodeltimer0(pp *p) {
n := atomic.Xadd(&pp.numTimers, -1)
if n == 0 {
// If there are no timers, then clearly none are modified.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
}
}
@@ -671,7 +671,7 @@ func adjusttimers(pp *p, now int64) {
// a lot of timers back and forth if the timers rarely expire.
// We'll postpone looking through all the adjusted timers until
// one would actually expire.
- first := atomic.Load64(&pp.timerModifiedEarliest)
+ first := pp.timerModifiedEarliest.Load()
if first == 0 || int64(first) > now {
if verifyTimers {
verifyTimerHeap(pp)
@@ -680,7 +680,7 @@ func adjusttimers(pp *p, now int64) {
}
// We are going to clear all timerModifiedEarlier timers.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
var moved []*timer
for i := 0; i < len(pp.timers); i++ {
@@ -755,7 +755,7 @@ func addAdjustedTimers(pp *p, moved []*timer) {
//go:nowritebarrierrec
func nobarrierWakeTime(pp *p) int64 {
next := int64(pp.timer0When.Load())
- nextAdj := int64(atomic.Load64(&pp.timerModifiedEarliest))
+ nextAdj := int64(pp.timerModifiedEarliest.Load())
if next == 0 || (nextAdj != 0 && nextAdj < next) {
next = nextAdj
}
@@ -903,7 +903,7 @@ func runOneTimer(pp *p, t *timer, now int64) {
func clearDeletedTimers(pp *p) {
// We are going to clear all timerModifiedEarlier timers.
// Do this now in case new ones show up while we are looping.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
cdel := int32(0)
to := 0
@@ -1014,11 +1014,12 @@ func updateTimer0When(pp *p) {
// The timers for pp will not be locked.
func updateTimerModifiedEarliest(pp *p, nextwhen int64) {
for {
- old := atomic.Load64(&pp.timerModifiedEarliest)
+ old := pp.timerModifiedEarliest.Load()
if old != 0 && int64(old) < nextwhen {
return
}
- if atomic.Cas64(&pp.timerModifiedEarliest, old, uint64(nextwhen)) {
+
+ if pp.timerModifiedEarliest.CompareAndSwap(old, uint64(nextwhen)) {
return
}
}
@@ -1044,7 +1045,7 @@ func timeSleepUntil() int64 {
next = w
}
- w = int64(atomic.Load64(&pp.timerModifiedEarliest))
+ w = int64(pp.timerModifiedEarliest.Load())
if w != 0 && w < next {
next = w
}