]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: ensure at least 1 tick between events
authorMeng Zhuo <mzh@golangcn.org>
Mon, 20 Sep 2021 12:44:50 +0000 (20:44 +0800)
committerMeng Zhuo <mzh@golangcn.org>
Tue, 19 Oct 2021 07:45:46 +0000 (07:45 +0000)
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 <mzh@golangcn.org>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/runtime/trace.go

index 00544e4283c620310c1ee3b53664750d34787713..5b14a5f553922526b1667c71e067cddec43dbbfc 100644 (file)
@@ -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<<traceArgCountShift)
        bufp.varint(uint64(pid))