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
- Variables
- func ClockAdjFreq(phcDevice string, freqPPB float64) error
- func ClockStep(phcDevice string, step time.Duration) error
- func DeviceFromIface(iface string) (string, error)
- func FDToClockID(fd uintptr) int32
- func FrequencyPPB(iface string) (float64, error)
- func FrequencyPPBFromDevice(phcDevice string) (freqPPB float64, err error)
- func IfaceToPHCDevice(iface string) (string, error)
- func MaxFreqAdjPPBFromDevice(phcDevice string) (maxFreq float64, err error)
- func OffsetBetweenDevices(deviceA, deviceB string) (time.Duration, error)
- func OffsetBetweenExtendedReadings(extendedA, extendedB *PTPSysOffsetExtended) time.Duration
- func Time(iface string, method TimeMethod) (time.Time, error)
- func TimeFromDevice(device string) (time.Time, error)
- type EthtoolTSinfo
- type IfaceData
- type Ifreq
- type PTPClockCaps
- type PTPClockTime
- type PTPSysOffsetExtended
- type SysoffResult
- type TimeMethod
Constants ¶
const DefaultMaxClockFreqPPB = 500000.0
DefaultMaxClockFreqPPB value came from linuxptp project (clockadj.c)
const (
// ExtendedNumProbes is the number of samples we request for IOCTL SYS_OFFSET_EXTENDED
ExtendedNumProbes = 9
)
Variables ¶
var SupportedMethods = []TimeMethod{MethodSyscallClockGettime, MethodIoctlSysOffsetExtended}
SupportedMethods is a list of supported TimeMethods
Functions ¶
func ClockAdjFreq ¶
ClockAdjFreq adjusts PHC clock frequency in PPB
func DeviceFromIface ¶
DeviceFromIface returns a path to a PHC device from a network interface
func FDToClockID ¶
FDToClockID converts file descriptor number to clockID. see man(3) clock_gettime, FD_TO_CLOCKID macros
func FrequencyPPB ¶
FrequencyPPB reads network card PHC device frequency in PPB
func FrequencyPPBFromDevice ¶
FrequencyPPBFromDevice reads PHC device frequency in PPB
func IfaceToPHCDevice ¶
IfaceToPHCDevice returns path to PHC device associated with given network card iface
func MaxFreqAdjPPBFromDevice ¶
MaxFreqAdjPPBFromDevice reads max value for frequency adjustments (in PPB) from ptp device
func OffsetBetweenDevices ¶
OffsetBetweenDevices returns estimated difference between two PHC devices
func OffsetBetweenExtendedReadings ¶
func OffsetBetweenExtendedReadings(extendedA, extendedB *PTPSysOffsetExtended) time.Duration
OffsetBetweenExtendedReadings returns estimated difference between two PHC SYS_OFFSET_EXTENDED readings
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 PTPClockCaps ¶
type PTPClockCaps struct { MaxAdj int32 /* Maximum frequency adjustment in parts per billon. */ NAalarm int32 /* Number of programmable alarms. */ NExtTs int32 /* Number of external time stamp channels. */ NPerOut int32 /* Number of programmable periodic signals. */ PPS int32 /* Whether the clock supports a PPS callback. */ NPins int32 /* Number of input/output pins. */ /* Whether the clock supports precise system-device cross timestamps */ CrossTimestamping int32 /* Whether the clock supports adjust phase */ AdjustPhase int32 Rsv [12]int32 /* Reserved for future use. */ }
PTPClockCaps as defined in linux/ptp_clock.h
func ReadPTPClockCapsFromDevice ¶
func ReadPTPClockCapsFromDevice(phcDevice string) (*PTPClockCaps, error)
ReadPTPClockCapsFromDevice reads ptp capabilities using ioctl
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 SysoffEstimateBasic ¶
func SysoffEstimateBasic(ts1, rt, ts2 time.Time) SysoffResult
SysoffEstimateBasic logic based on calculate_offset from ptp4l phc_ctl.c
func SysoffEstimateExtended ¶
func SysoffEstimateExtended(extended *PTPSysOffsetExtended) SysoffResult
SysoffEstimateExtended finds sample which took least time to be read, logic loosely based on sysoff_estimate from ptp4l sysoff.c
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