Documentation ¶
Overview ¶
Package phc contains code to work with PTP Hardware Clock (PHC). It allows getting PHC time via different APIs (syscall, ioctl).
It also provides means to calculate offset between sys clock and PHC.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SupportedMethods = []TimeMethod{MethodSyscallClockGettime, MethodIoctlSysOffsetExtended}
SupportedMethods is a list of supported TimeMethods
Functions ¶
Types ¶
type EthtoolTSinfo ¶
type EthtoolTSinfo struct { Cmd uint32 SOtimestamping uint32 PHCIndex int32 TXTypes uint32 TXReserved [3]uint32 RXFilters uint32 RXReserved [3]uint32 }
EthtoolTSinfo holds a device's timestamping and PHC association as per Linux kernel's include/uapi/linux/ethtool.h
func IfaceInfo ¶
func IfaceInfo(iface string) (*EthtoolTSinfo, error)
IfaceInfo uses SIOCETHTOOL ioctl to get information for the give nic, i.e. eth0.
type IfaceData ¶
type IfaceData struct { Iface net.Interface TSInfo EthtoolTSinfo }
IfaceData has both net.Interface and EthtoolTSinfo
func IfacesInfo ¶
IfacesInfo is like net.Interfaces() but with added EthtoolTSinfo
type Ifreq ¶
Ifreq is the request we send with SIOCETHTOOL IOCTL as per Linux kernel's include/uapi/linux/if.h
type PTPClockTime ¶
PTPClockTime as defined in linux/ptp_clock.h
func (PTPClockTime) Time ¶
func (t PTPClockTime) Time() time.Time
Time returns PTPClockTime as time.Time
type PTPSysOffsetExtended ¶
type PTPSysOffsetExtended struct { NSamples uint32 /* Desired number of measurements. */ Reserved [3]uint32 /* Reserved for future use. */ /* * Array of [system, phc, system] time stamps. The kernel will provide * 3*n_samples time stamps. * - system time right before reading the lowest bits of the PHC timestamp * - PHC time * - system time immediately after reading the lowest bits of the PHC timestamp */ TS [ptpMaxSamples][3]PTPClockTime }
PTPSysOffsetExtended as defined in linux/ptp_clock.h
func ReadPTPSysOffsetExtended ¶
func ReadPTPSysOffsetExtended(device string, nsamples int) (*PTPSysOffsetExtended, error)
ReadPTPSysOffsetExtended gets precise time from PHC along with SYS time to measure the call delay.
type SysoffResult ¶
type SysoffResult struct { Offset time.Duration Delay time.Duration SysTime time.Time PHCTime time.Time }
SysoffResult is a result of PHC time measurement with related data
func TimeAndOffset ¶
func TimeAndOffset(iface string, method TimeMethod) (SysoffResult, error)
TimeAndOffset returns time we got from network card + offset
func TimeAndOffsetFromDevice ¶
func TimeAndOffsetFromDevice(device string, method TimeMethod) (SysoffResult, error)
TimeAndOffsetFromDevice returns time we got from phc device + offset
type TimeMethod ¶
type TimeMethod string
TimeMethod is method we use to get time
const ( MethodSyscallClockGettime TimeMethod = "syscall_clock_gettime" MethodIoctlSysOffsetExtended TimeMethod = "ioctl_PTP_SYS_OFFSET_EXTENDED" )
Methods we support to get time