Skip to content

Commit

Permalink
runtime: convert ticksType.val to atomic type
Browse files Browse the repository at this point in the history
Updates #53821

Change-Id: Ia0c58d7e7e11a1b52bbb7c19ebbb131e3eea5314
Reviewed-on: https://go-review.googlesource.com/c/go/+/424926
Reviewed-by: Michael Knyszek <[email protected]>
Run-TryBot: Cuong Manh Le <[email protected]>
Auto-Submit: Cuong Manh Le <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
  • Loading branch information
cuonglm authored and gopherbot committed Aug 23, 2022
1 parent 332a598 commit e1114fd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/runtime/align_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var AtomicFields = []uintptr{
unsafe.Offsetof(lfnode{}.next),
unsafe.Offsetof(mstats{}.last_gc_nanotime),
unsafe.Offsetof(mstats{}.last_gc_unix),
unsafe.Offsetof(ticksType{}.val),
unsafe.Offsetof(workType{}.bytesMarked),
}

Expand Down
9 changes: 4 additions & 5 deletions src/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ var ticks ticksType

type ticksType struct {
lock mutex
pad uint32 // ensure 8-byte alignment of val on 386
val uint64
val atomic.Int64
}

// Note: Called by runtime/pprof in addition to runtime code.
func tickspersecond() int64 {
r := int64(atomic.Load64(&ticks.val))
r := ticks.val.Load()
if r != 0 {
return r
}
lock(&ticks.lock)
r = int64(ticks.val)
r = ticks.val.Load()
if r == 0 {
t0 := nanotime()
c0 := cputicks()
Expand All @@ -43,7 +42,7 @@ func tickspersecond() int64 {
if r == 0 {
r++
}
atomic.Store64(&ticks.val, uint64(r))
ticks.val.Store(r)
}
unlock(&ticks.lock)
return r
Expand Down

0 comments on commit e1114fd

Please sign in to comment.