mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
tstime/mono: remove unsafe
This removes the unsafe/linkname and only uses the standard library. It's a bit slower, for now, but https://go.dev/cl/518336 should get us back. On darwin/arm64, without https://go.dev/cl/518336 pkg: tailscale.com/tstime/mono │ before │ after │ │ sec/op │ sec/op vs base │ MonoNow-8 16.20n ± 0% 19.75n ± 0% +21.92% (p=0.000 n=10) TimeNow-8 39.46n ± 0% 39.40n ± 0% -0.16% (p=0.002 n=10) geomean 25.28n 27.89n +10.33% And with it, MonoNow-8 16.34n ± 1% 16.93n ± 0% +3.67% (p=0.001 n=10) TimeNow-8 39.55n ± 15% 38.46n ± 1% -2.76% (p=0.000 n=10) geomean 25.42n 25.52n +0.41% Updates #8839 Updates tailscale/go#70 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
cc3caa4b2a
commit
a1b8d703d6
@@ -16,7 +16,6 @@ import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
_ "unsafe" // for go:linkname
|
||||
)
|
||||
|
||||
// Time is the number of nanoseconds elapsed since an unspecified reference start time.
|
||||
@@ -29,7 +28,7 @@ func Now() Time {
|
||||
// The corresponding package time expression never does, if the wall clock is correct.
|
||||
// Preserve this correspondence by increasing the "base" monotonic clock by a fair amount.
|
||||
const baseOffset int64 = 1 << 55 // approximately 10,000 hours in nanoseconds
|
||||
return Time(now() + baseOffset)
|
||||
return Time(int64(time.Since(baseWall)) + baseOffset)
|
||||
}
|
||||
|
||||
// Since returns the time elapsed since t.
|
||||
@@ -72,9 +71,6 @@ func (t *Time) LoadAtomic() Time {
|
||||
return Time(atomic.LoadInt64((*int64)(t)))
|
||||
}
|
||||
|
||||
//go:linkname now runtime.nanotime1
|
||||
func now() int64
|
||||
|
||||
// baseWall and baseMono are a pair of almost-identical times used to correlate a Time with a wall time.
|
||||
var (
|
||||
baseWall time.Time
|
||||
|
Reference in New Issue
Block a user