Skip to content

Commit

Permalink
drop PtpClockTime.Time() (#418)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #418

Avoid the non-upstreamed unix.PtpClockTime.Time().

The related [golang/go#70032](golang/go#70032) is still pending decision. In case of positive outcome we can unland this.

Reviewed By: leoleovich

Differential Revision: D64901381

fbshipit-source-id: b06c389dff7f0720391bc8dac81e6a346a111a58
  • Loading branch information
yarikk authored and facebook-github-bot committed Nov 18, 2024
1 parent a92d130 commit ccc405e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
17 changes: 9 additions & 8 deletions phc/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type SysoffResult struct {

// based on sysoff_estimate from ptp4l sysoff.c
func sysoffFromExtendedTS(extendedTS [3]PtpClockTime) SysoffResult {
t1 := extendedTS[0].Time()
tp := extendedTS[1].Time()
t2 := extendedTS[2].Time()
t1 := time.Unix(extendedTS[0].Sec, int64(extendedTS[0].Nsec))
tp := time.Unix(extendedTS[1].Sec, int64(extendedTS[1].Nsec))
t2 := time.Unix(extendedTS[2].Sec, int64(extendedTS[2].Nsec))
interval := t2.Sub(t1)
timestamp := t1.Add(interval / 2)
offset := timestamp.Sub(tp)
Expand All @@ -60,13 +60,14 @@ func sysoffFromExtendedTS(extendedTS [3]PtpClockTime) SysoffResult {
}

// SysoffFromPrecise returns SysoffResult from *PTPSysOffsetPrecise . Code based on sysoff_precise from ptp4l sysoff.c
func SysoffFromPrecise(precise *PTPSysOffsetPrecise) SysoffResult {
offset := precise.Realtime.Time().Sub(precise.Device.Time())
func SysoffFromPrecise(pre *PTPSysOffsetPrecise) SysoffResult {
tp := time.Unix(pre.Device.Sec, int64(pre.Device.Nsec))
tr := time.Unix(pre.Realtime.Sec, int64(pre.Realtime.Nsec))
return SysoffResult{
SysTime: precise.Realtime.Time(),
PHCTime: precise.Device.Time(),
SysTime: tr,
PHCTime: tp,
Delay: 0, // They are measured at the same time
Offset: offset,
Offset: tr.Sub(tp),
}
}

Expand Down
6 changes: 4 additions & 2 deletions phc/phc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ func Time(iface string, method TimeMethod) (time.Time, error) {
return time.Time{}, err
}
latest := extended.Ts[extended.Samples-1]
return latest[1].Time(), nil
tp := latest[1]
return time.Unix(tp.Sec, int64(tp.Nsec)), nil
case MethodIoctlSysOffsetPrecise:
precise, err := dev.ReadSysoffPrecise()
if err != nil {
return time.Time{}, err
}
return precise.Device.Time(), nil
tp := precise.Device
return time.Unix(tp.Sec, int64(tp.Nsec)), nil
default:
return time.Time{}, fmt.Errorf("unknown method to get PHC time %q", method)
}
Expand Down
3 changes: 2 additions & 1 deletion phc/pps_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ func (ppsSink *PPSSink) getPPSEventTimestamp() (time.Time, error) {
return time.Time{}, fmt.Errorf("extts on unexpected pin index %d, expected %d", event.Index, ppsSink.InputPin)
}

eventTime := event.T.Time()
t := event.T
eventTime := time.Unix(t.Sec, int64(t.Nsec))

return eventTime, nil
}
Expand Down
19 changes: 0 additions & 19 deletions phc/unix/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,6 @@ const (
PTP_PF_PHYSYNC //nolint:revive
)

// https://go-review.googlesource.com/c/sys/+/621498

// TimeToPtpClockTime returns t as PtpClockTime
func TimeToPtpClockTime(t time.Time) PtpClockTime {
sec := t.Unix()
nsec := uint32(t.Nanosecond())
return PtpClockTime{Sec: sec, Nsec: nsec}
}

// Time returns PTPClockTime as time.Time
func (t *PtpClockTime) Time() time.Time {
return time.Unix(t.Sec, int64(t.Nsec))
}

// Unix returns the time stored in t as seconds plus nanoseconds.
func (t *PtpClockTime) Unix() (sec int64, nsec int64) {
return t.Sec, int64(t.Nsec)
}

// bridging to upstream

type Cmsghdr = unix.Cmsghdr
Expand Down

0 comments on commit ccc405e

Please sign in to comment.