Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // OffsetCoeff is offset & coefficient pair. // Coefficient is in [0,64) bits. // Offset is in [64, 128) bits. // Using false sharing range as aligned size & total size for avoiding cache pollution. OffsetCoeff = xbytes.MakeAlignedBlock(cpu.X86FalseSharingRange, cpu.X86FalseSharingRange) OffsetCoeffAddr = &OffsetCoeff[0] )
unix_nano_timestamp = tsc_register_value * Coeff + Offset. Coeff = 1 / (tsc_frequency / 1e9). We could regard coeff as the inverse of TSCFrequency(GHz) (actually it just has mathematics property) for avoiding future dividing. MUL gets much better performance than DIV.
var ( // OffsetCoeffF using float64 as offset. OffsetCoeffF = xbytes.MakeAlignedBlock(cpu.X86FalseSharingRange, cpu.X86FalseSharingRange) OffsetCoeffFAddr = &OffsetCoeffF[0] )
var UnixNano = sysClock
UnixNano returns time as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC.
Warn: DO NOT use it for measuring single function performance unless ForbidOutOfOrder has been invoked.
e.g. ```
start := tsc.UnixNano() foo() end := tsc.UnixNano() cost := end - start
``` The value of cost is unpredictable, because all instructions for getting tsc are not serializing, we need to be careful to deal with the order (use barrier).
See GetInOrder in tsc_amd64.s for more details.
Functions ¶
func AllowOutOfOrder ¶ added in v1.0.1
func AllowOutOfOrder()
AllowOutOfOrder sets allowOutOfOrder true.
Not threads safe.
func Calibrate ¶
func Calibrate()
Calibrate calibrates tsc clock.
It's a good practice that runs Calibrate periodically (e.g., 5 min is a good start).
func CalibrateWithCoeff ¶ added in v1.0.1
func CalibrateWithCoeff(c float64)
CalibrateWithCoeff calibrates coefficient to wall_clock by variables.
Not thread safe, only for testing.
func ForbidOutOfOrder ¶ added in v1.0.1
func ForbidOutOfOrder()
ForbidOutOfOrder sets allowOutOfOrder false.
Not threads safe.
func GetCurrentClockSource ¶ added in v1.2.1
func GetCurrentClockSource() string
GetCurrentClockSource gets clock source on Linux.
func GetInOrder ¶ added in v0.0.3
func GetInOrder() int64
GetInOrder gets tsc value in strict order. It's used to help calibrating to avoid out-of-order issues.
func IsOutOfOrder ¶ added in v1.0.1
func IsOutOfOrder() bool
IsOutOfOrder returns allow out-of-order or not.
Not threads safe.
func LoadOffsetCoeff ¶ added in v1.1.1
Same logic as unixNanoTSC16B for checking getting offset & coeff correctly.
Types ¶
This section is empty.