runtime: split up ticks to get correct alignment
On 32-bit x86 a uint64 variable by itself is aligned to an 8-byte boundary.
A uint64 field in a struct is aligned to a 4-byte boundary.
The runtime.ticks variable has a uint64 field that must be aligned
to an 8-byte boundary. Rather than rely on luck, split up the struct
into separate vars so that the required alignment happens reliably.
It would be much nicer if issue golang/go#19057 were fixed somehow,
but that is for another day.
Change-Id: If609ed165fb9cb1ea89fd351268c9984aa5df20d
Reviewed-on: https://go-review.googlesource.com/41143
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/libgo/go/runtime/runtime.go b/libgo/go/runtime/runtime.go
index e63130b..58710de 100644
--- a/libgo/go/runtime/runtime.go
+++ b/libgo/go/runtime/runtime.go
@@ -19,20 +19,17 @@
//
//go:linkname tickspersecond runtime.tickspersecond
-var ticks struct {
- lock mutex
- pad uint32 // ensure 8-byte alignment of val on 386
- val uint64
-}
+var ticksLock mutex
+var ticksVal uint64
// Note: Called by runtime/pprof in addition to runtime code.
func tickspersecond() int64 {
- r := int64(atomic.Load64(&ticks.val))
+ r := int64(atomic.Load64(&ticksVal))
if r != 0 {
return r
}
- lock(&ticks.lock)
- r = int64(ticks.val)
+ lock(&ticksLock)
+ r = int64(ticksVal)
if r == 0 {
t0 := nanotime()
c0 := cputicks()
@@ -46,9 +43,9 @@
if r == 0 {
r++
}
- atomic.Store64(&ticks.val, uint64(r))
+ atomic.Store64(&ticksVal, uint64(r))
}
- unlock(&ticks.lock)
+ unlock(&ticksLock)
return r
}