phc

package
v0.0.0-...-a34aaee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

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

SupportedMethods is a list of supported TimeMethods

Functions

func Time

func Time(iface string, method TimeMethod) (time.Time, error)

Time returns time we got from network card

func TimeFromDevice

func TimeFromDevice(device string) (time.Time, error)

TimeFromDevice returns time we got from PTP device

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

func IfacesInfo() ([]IfaceData, error)

IfacesInfo is like net.Interfaces() but with added EthtoolTSinfo

type Ifreq

type Ifreq struct {
	Name [unix.IFNAMSIZ]byte
	Data uintptr
}

Ifreq is the request we send with SIOCETHTOOL IOCTL as per Linux kernel's include/uapi/linux/if.h

type PTPClockTime

type PTPClockTime struct {
	Sec      int64  /* seconds */
	NSec     uint32 /* nanoseconds */
	Reserved uint32
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL