Sorry I've taken so long to reply. Thanks Konstantin and Dave.
In the implementation and usage of distributed lock leases, it is
always essential to use the monotonic time API to measure the
time interval.
But in the implementation of the time package (go 1.9), there is
fallback and the go application itself couldn't know whether it is
actually using a monotonic time syscall or just the fallback
`gettimeofday` which is unsafe for the strict lease measuring:
TEXT runtime·nanotime(SB),NOSPLIT,$16
// Duplicate time.now here to avoid using up precious stack space.
// See comment above in time.now.
MOVQ runtime·__vdso_clock_gettime_sym(SB), AX
CMPQ AX, $0
JEQ fallback
MOVL $1, DI // CLOCK_MONOTONIC
LEAQ 0(SP), SI
CALL AX
MOVQ 0(SP), AX // sec
MOVQ 8(SP), DX // nsec
// sec is in AX, nsec in DX
// return nsec in AX
IMULQ $1000000000, AX
ADDQ DX, AX
MOVQ AX, ret+0(FP)
RET
fallback:
LEAQ 0(SP), DI
MOVQ $0, SI
MOVQ runtime·__vdso_gettimeofday_sym(SB), AX
CALL AX
MOVQ 0(SP), AX // sec
MOVL 8(SP), DX // usec
IMULQ $1000, DX
// sec is in AX, nsec in DX
// return nsec in AX
IMULQ $1000000000, AX
ADDQ DX, AX
MOVQ AX, ret+0(FP)
RET
(I think maybe it's better to add one api like 'time.IsMono' to tell the go app
whether the monotonic clock is really & actually been used unmistakenly.)
Ps:
Although there is a in time.Now().String() for time has a monotonic
clock reading:
1. Doesn't have monotonic clock reading:
"2006-01-02 15:04:05.999999999 -0700 MST"
2. Have monotonic clock reading:
"2006-01-02 15:04:05.999999999 -0700 MST m=+2.006332106"
But it is a little strange and not straight forward to use RE to match the
final field "m=±<value>", and most importantly, there isn't any guarantee
about how this format will be modified in the future.