MCPcopy Create free account
hub / github.com/facebook/time / ioctlHWTimestampCaps

Function ioctlHWTimestampCaps

timestamp/timestamp_linux.go:98–122  ·  view source on GitHub ↗
(fd int, ifname string)

Source from the content-addressed store, hash-verified

96 var rxFilter int32
97
98 hw, err := unix.IoctlGetEthtoolTsInfo(fd, ifname)
99 if err != nil {
100 return 0, fmt.Errorf("failed to run ioctl SIOCETHTOOL to see what is supported: (%w)", err)
101 }
102
103 if hw.Tx_types&(1<<unix.HWTSTAMP_TX_ON) == 0 {
104 return 0, fmt.Errorf("hardware TX timestamping is not supported for the interface %s", ifname)
105 }
106
107 if hw.Rx_filters&(1<<unix.HWTSTAMP_FILTER_PTP_V2_L4_EVENT) > 0 {
108 rxFilter = unix.HWTSTAMP_FILTER_PTP_V2_L4_EVENT
109 } else if hw.Rx_filters&(1<<unix.HWTSTAMP_FILTER_PTP_V2_EVENT) > 0 {
110 rxFilter = unix.HWTSTAMP_FILTER_PTP_V2_EVENT
111 } else if hw.Rx_filters&(1<<unix.HWTSTAMP_FILTER_ALL) > 0 {
112 rxFilter = unix.HWTSTAMP_FILTER_ALL
113 }
114
115 if rxFilter == 0 {
116 return 0, fmt.Errorf("hardware RX timestamping is not supported for the interface %s", ifname)
117 }
118 return rxFilter, nil
119}
120
121func ioctlTimestamp(fd int, ifname string, filter int32) error {
122 hw, err := unix.IoctlGetHwTstamp(fd, ifname)
123 if errors.Is(err, unix.ENOTSUP) {
124 // for the loopback interface
125 hw = &unix.HwTstampConfig{}

Callers 3

EnableHWTimestampsFunction · 0.85
EnableHWTimestampsRxFunction · 0.85
TestReadHWTimestampCapsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestReadHWTimestampCapsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…