aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorMeng Zhuo <mzh@golangcn.org>2021-12-17 14:15:42 +0800
committerZhuo Meng <mzh@golangcn.org>2021-12-29 01:44:55 +0000
commita78532a4121d26c33ee3ce69b3dda3a608f5a077 (patch)
tree047376ea52fb4ac706016f48714c3de333067f29 /src/runtime
parentb357b05b70d2b8c4988ac2a27f2af176e7a09e1b (diff)
downloadgo-a78532a4121d26c33ee3ce69b3dda3a608f5a077.tar.gz
go-a78532a4121d26c33ee3ce69b3dda3a608f5a077.zip
runtime: invalid negative frequency while tracing
The riscv64 Hifive Unmatched is the only platform that failed on testcase TestAnalyzeAnnotations occasionally after CL 332954 had merged. The failure happens when ticks per second (freq) is over 1e12 which causing the timestamps of two events are same. There are 2 reasons causing big frequency: 1. RDCYCLE is HART based according to the riscv manual which makes negative ticks delta 2. negative float64 -> uint64 is undefined and "lucky" negative float is too big to handle for trace For #46737 Change-Id: I1f3c1ac31aae249969000c719c32aaf5a66d29a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/373034 Trust: Zhuo Meng <mzh@golangcn.org> Run-TryBot: Zhuo Meng <mzh@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/asm_riscv64.s5
-rw-r--r--src/runtime/trace.go3
2 files changed, 7 insertions, 1 deletions
diff --git a/src/runtime/asm_riscv64.s b/src/runtime/asm_riscv64.s
index 0e813189d4..2a4837b399 100644
--- a/src/runtime/asm_riscv64.s
+++ b/src/runtime/asm_riscv64.s
@@ -81,7 +81,10 @@ TEXT setg_gcc<>(SB),NOSPLIT,$0-0
// func cputicks() int64
TEXT runtime·cputicks(SB),NOSPLIT,$0-8
- RDCYCLE A0
+ // RDTIME to emulate cpu ticks
+ // RDCYCLE reads counter that is per HART(core) based
+ // according to the riscv manual, see issue 46737
+ RDTIME A0
MOV A0, ret+0(FP)
RET
diff --git a/src/runtime/trace.go b/src/runtime/trace.go
index 5b14a5f553..71a29d4316 100644
--- a/src/runtime/trace.go
+++ b/src/runtime/trace.go
@@ -426,6 +426,9 @@ func ReadTrace() []byte {
trace.footerWritten = true
// Use float64 because (trace.ticksEnd - trace.ticksStart) * 1e9 can overflow int64.
freq := float64(trace.ticksEnd-trace.ticksStart) * 1e9 / float64(trace.timeEnd-trace.timeStart) / traceTickDiv
+ if freq <= 0 {
+ throw("trace: ReadTrace got invalid frequency")
+ }
trace.lockOwner = nil
unlock(&trace.lock)
var data []byte