From ee92daae25029882979eb694bd7246491e364d3c Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Mon, 20 Sep 2021 20:44:50 +0800 Subject: [PATCH] runtime: ensure at least 1 tick between events ticks might be same after tick division, although the real cputicks is linear growth Fixes #46737 Change-Id: I1d98866fbf21b426c6c1c96cc9cf802d7f440f18 Reviewed-on: https://go-review.googlesource.com/c/go/+/330849 Trust: Meng Zhuo Trust: Bryan C. Mills Run-TryBot: Meng Zhuo Reviewed-by: Michael Knyszek TryBot-Result: Go Bot --- src/runtime/trace.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/runtime/trace.go b/src/runtime/trace.go index 00544e4283c..5b14a5f5539 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -551,8 +551,15 @@ func traceEventLocked(extraBytes int, mp *m, pid int32, bufp *traceBufPtr, ev by bufp.set(buf) } + // NOTE: ticks might be same after tick division, although the real cputicks is + // linear growth. ticks := uint64(cputicks()) / traceTickDiv tickDiff := ticks - buf.lastTicks + if tickDiff == 0 { + ticks = buf.lastTicks + 1 + tickDiff = 1 + } + buf.lastTicks = ticks narg := byte(len(args)) if skip >= 0 { @@ -653,6 +660,9 @@ func traceFlush(buf traceBufPtr, pid int32) traceBufPtr { // initialize the buffer for a new batch ticks := uint64(cputicks()) / traceTickDiv + if ticks == bufp.lastTicks { + ticks = bufp.lastTicks + 1 + } bufp.lastTicks = ticks bufp.byte(traceEvBatch | 1<