Skip to content

Commit

Permalink
handle ts2phc holdover state
Browse files Browse the repository at this point in the history
Signed-off-by: Aneesh Puttur <aputtur@redhat.com>
  • Loading branch information
aneeshkp committed Sep 23, 2024
1 parent 7fec29e commit 6b8b54d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
15 changes: 11 additions & 4 deletions plugins/ptp_operator/metrics/logparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ func extractRegularMetrics(processName, output string) (interfaceName string, pt
// ts2phc[82674.465]: [ts2phc.0.config] ens2f1 extts index 0 at 1673031129.000000000 corr 0 src 1673031129.911642976 diff 0
// ts2phc[82674.465]: [ts2phc.0.config] ens2f1 master offset 0 s2 freq -0
// ts2phc[521734.693]: [ts2phc.0.config:6] /dev/ptp6 offset 0 s2 freq -0
// s2phc[82674.465]: ts2phc.0.config] ens7f0 offset 1 s3 freq +1 holdover

// 0 1 2 3 4 5 6 7 8 9 10 11
// 1 2 3 4 5 6 7 8 9
// ptp4l 5196819.100 ptp4l.0.config master offset -2162130 s2 freq +22451884 path delay 374976
//
// ts2phc 522946.693 ts2phc.0.config ens7f0 offset 0 s2 freq -0
// ts2phc 82674.465 ts2phc.0.config ens7f0 offset 1 s3 freq +1 holdover
index := FindInLogForCfgFileIndex(output)
if index == -1 {
log.Errorf("config name is not found in log output %s", output)
Expand All @@ -127,8 +129,9 @@ func extractRegularMetrics(processName, output string) (interfaceName string, pt
// 0 1 2 3 4 5 6 7 8
// ptp4l.0.config master offset -2162130 s2 freq +22451884 delay 374976
// ts2phc.0.config ens2f1 master offset 0 s2 freq -0
// 0 1 2 3 4 5 6
// 0 1 2 3 4 5 6 7
// ts2phc.0.config ens7f0 offset 0 s2 freq -0
// ts2phc.0.config ens7f0 offset 1 s3 freq +1 holdover
// 0 1 2 3 4 5 6 7
// ptp4l.0.config CLOCK_REALTIME offset -62 s0 freq -78368 delay 1100
if len(fields) < 7 {
Expand Down Expand Up @@ -169,13 +172,17 @@ func extractRegularMetrics(processName, output string) (interfaceName string, pt
clockState = ptp.FREERUN
case clockStep:
clockState = ptp.FREERUN
case locked:
case locked, lockedStable:
clockState = ptp.LOCKED
default:
log.Errorf("%s - failed to parse clock state output `%s` ", processName, fields[4])
}

if len(fields) >= 8 {
// 0 1 2 3 4 5 6 7
// ts2phc.0.config ens7f0 offset 1 s3 freq +1 holdover
if len(fields) >= 8 && processName == ts2phcProcessName && fields[7] == "holdover" {
clockState = ptp.HOLDOVER
} else if len(fields) >= 8 { // anything new we ignor
delay, err = strconv.ParseFloat(fields[8], 64)
if err != nil {
log.Errorf("%s failed to parse delay from master output %s error %v", processName, fields[8], err)
Expand Down Expand Up @@ -226,7 +233,7 @@ func extractNmeaMetrics(processName, output string) (interfaceName string, statu
clockState = ptp.FREERUN
case clockStep:
clockState = ptp.FREERUN
case locked:
case locked, lockedStable:
clockState = ptp.LOCKED
default:
log.Errorf("%s - failed to parse clock state output `%s` ", processName, fields[6])
Expand Down
2 changes: 2 additions & 0 deletions plugins/ptp_operator/metrics/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ func (p *PTPEventManager) GenPTPEvent(ptpProfileName string, oStats *stats.Stats
oStats.SetLastSyncState(clockState)
oStats.SetLastOffset(ptpOffset)
}
case ptp.HOLDOVER:
return // do nothing for holdover
case ptp.FREERUN:
if lastClockState != ptp.HOLDOVER {
// within range
Expand Down
10 changes: 6 additions & 4 deletions plugins/ptp_operator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ const (
gmProcessName = "GM"
syncE4lProcessName = "synce4l"

unLocked = "s0"
clockStep = "s1"
locked = "s2"
unLocked = "s0"
clockStep = "s1"
locked = "s2"
lockedStable = "s3"

// FreeRunOffsetValue when sync state is FREERUN
FreeRunOffsetValue = -9999999999999999
Expand Down Expand Up @@ -187,6 +188,7 @@ func (p *PTPEventManager) ExtractMetrics(msg string) {
// ts2phc[82674.465]: [ts2phc.0.cfg] nmea delay: 88403525 ns
// ts2phc[82674.465]: [ts2phc.0.cfg] ens2f1 extts index 0 at 1673031129.000000000 corr 0 src 1673031129.911642976 diff 0
// ts2phc[82674.465]: [ts2phc.0.cfg] ens2f1 master offset 0 s2 freq -0
// ts2phc[82674.465]: ts2phc.0.config] ens7f0 offset 1 s3 freq +1 holdover
// Use threshold to CLOCK_REALTIME==SLAVE, rest send clock state to metrics no events
// db | oc/bc/dual | ts2phc wo/GNSS | ts2phc w/GNSS | two card
// --------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -296,7 +298,7 @@ func (p *PTPEventManager) ExtractMetrics(msg string) {
p.GenPTPEvent(profileName, ptpStats[types.IFace(interfaceName)], masterResource, int64(ptpOffset), syncState, ptp.PtpStateChange)
} else {
threshold := p.PtpThreshold(profileName, false)
if !isOffsetInRange(int64(ptpOffset), threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
if syncState != ptp.HOLDOVER && !isOffsetInRange(int64(ptpOffset), threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
syncState = ptp.FREERUN
}
ptpStats[types.IFace(interfaceName)].SetLastSyncState(syncState)
Expand Down

0 comments on commit 6b8b54d

Please sign in to comment.