Documentation ¶
Index ¶
Constants ¶
const ( // Path of the lock file. DefaultLockPath string = "clockd.client.lock" // Key used for shared memory communication with clockd. DefaultShmKey int = 55356 ClientInfoSharedMemoryBufferSize int = 48 )
const ( // MaxClockDrift is the absolute value of the max clock drift in ppb. 1e3ppm // or 1e6ppb is picked based on Microsoft's FarmV2 survey, which found that // most oscillators would drift significantly less than 200ppm. This leaves // us a 5x error budget. // // Note that it is highly unlikely to see such a large drift on a working // clock as the underlying digital system require the drift to be bounded // at a much smaller range, e.g. Intel NIC typically require a 30ppm max // drift for its SerDes and a 300ppm max drift for PCI-E, see Intel 82599 // datasheet for more details. On the software side, kernel accepts 500ppm // maximum adjustment, meaning anything higher than that reflects a hardware // fault. MaxClockDrift int64 = 1000000 )
Variables ¶
var ( // ErrNotReady indicates that clockd is not ready yet. ErrNotReady = errors.New("bounded time service not ready") // ErrStopped indicates that clockd unexpectedly stopped, e.g. crashed. ErrStopped = errors.New("bounded time service stopped") )
var ( // Encoder used for content stored in the shared memory region. Encoder = binary.BigEndian )
Functions ¶
func FirstError ¶
func GetClockUncertainty ¶
GetClockUncertainty returns the dispersion introduced by the clock itself when we can not confirm whether it is broken or not. When there is a nanosecond worth of uncertain period, we multiply it with the MaxClockDrift to get the dispersion.
func UnmarshalClientInfo ¶
func UnmarshalClientInfo(data []byte, c *ClientInfo) error
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client used to get current bounded time. It is not thread safe meaning you shouldn't be using the same client concurrently from multiple threads.
func (*Client) GetUnixTime ¶
GetUnixTime returns the UnixTime instance that represents the current time with reported uncertainty.
type ClientInfo ¶
type ClientInfo struct { Valid bool Locked bool Count uint16 Dispersion uint64 Sec uint64 NSec uint32 }
ClientInfo contains details exposed by clockd. Applications shouldn't be accessing any fields. All fields are in Unix time.
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
func NewSemaphore ¶
Open creates a new POSIX semaphore or opens an existing semaphore. The semaphore is identified by name. The mode argument specifies the permissions to be placed on the new semaphore. The value argument specifies the initial value for the new semaphore. If the named semaphore already exist, mode and value are ignored. For details see sem_overview(7).
func (*Semaphore) Close ¶
Close closes the named semaphore, allowing any resources that the system has allocated to the calling process for this semaphore to be freed.
func (*Semaphore) Unlink ¶
Unlink removes the named semaphore. The semaphore name is removed immediately. The semaphore is destroyed once all other processes that have the semaphore open close it.
func (*Semaphore) Wait ¶
Wait decrements the semaphore. If the semaphore's value is greater than zero, then the decrement proceeds, and the function returns, immediately. If the semaphore currently has the value zero, then the call blocks until either it becomes possible to perform the decrement, or a signal interrupts the call.
type UnixTime ¶
UnixTime is the native time provided by clockd. It is used to represent current and future time with specified time uncertainties. Use time types from the stdlib or other 3rd libraries for generic time values. The Dispersion member is the uncertainty of the specified time meaning that for time t, the actual time is between [t-Dispersion, t+Dispersion] both inclusive.
func (*UnixTime) Bounds ¶
Bounds returns the lower and upper limit of the time represented by the UnixTime instance.