Skip to content

Commit

Permalink
remove clockclass 140 T-GM
Browse files Browse the repository at this point in the history
Signed-off-by: Aneesh Puttur <[email protected]>
  • Loading branch information
aneeshkp committed Oct 18, 2024
1 parent e9ec62a commit a7ae479
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion addons/intel/e810.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ func AfterRunPTPCommandE810(data *interface{}, nodeProfile *ptpv1.PtpProfile, co
glog.Infof("Running /usr/bin/ubxtool with args %s", strings.Join(ublxArgs, ", "))
stdout, err = exec.Command("/usr/local/bin/ubxtool", ublxArgs...).CombinedOutput()
//stdout, err = exec.Command("/usr/local/bin/ubxtool", "-p", "STATUS").CombinedOutput()
_data := *data
if data != nil && ublxOpt.ReportOutput {
_data := *data
glog.Infof("Saving status to hwconfig: %s", string(stdout))
var pluginData *E810PluginData = _data.(*E810PluginData)
_pluginData := *pluginData
Expand Down
75 changes: 40 additions & 35 deletions pkg/dpll/dpll.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,16 @@ func (d *DpllConfig) monitorNtf(c *genetlink.Conn) {
glog.Error(err)
return
}

case nl.DPLL_CMD_PIN_CHANGE_NTF:
pins, err = nl.ParsePinReplies([]genetlink.Message{msg})
if err != nil {
glog.Error(err)
return
}

default:
glog.Info("unhandled dpll message", msg.Header.Command, msg.Data)

}

}
if d.nlUpdateState(devices, pins) {
d.stateDecision()
Expand Down Expand Up @@ -621,77 +618,81 @@ func (d *DpllConfig) MonitorDpll() {
// stateDecision
func (d *DpllConfig) stateDecision() {
dpllStatus := d.getWorseState(d.phaseStatus, d.frequencyStatus)
glog.Infof("%s-dpll decision: Status %d, Offset %d, In spec %v, Source lost %v, On holdover %v",
d.iface, dpllStatus, d.phaseOffset, d.inSpec, d.sourceLost, d.onHoldover)
if d.hasPPSAsSource() {
d.sourceLost = false //TODO: do not have a handler to catch pps source , so we will set to false
// and to true if state changes to holdover for source PPS based DPLL
}
switch dpllStatus {
case DPLL_FREERUN, DPLL_INVALID, DPLL_UNKNOWN:
d.inSpec = true
d.inSpec = false
d.sourceLost = true
if d.hasGNSSAsSource() && d.onHoldover {
d.holdoverCloseCh <- true
} else if d.hasPPSAsSource() {
d.sourceLost = true
}
d.state = event.PTP_FREERUN
d.phaseOffset = FaultyPhaseOffset
glog.Infof("dpll is in FREERUN, state is FREERUN (%s)", d.iface)
d.sendDpllEvent()
case DPLL_LOCKED:
if !d.sourceLost && d.isOffsetInRange() { // right now pps always source not lost
if !d.sourceLost && d.isOffsetInRange() {
if d.hasGNSSAsSource() && d.onHoldover {
d.holdoverCloseCh <- true
}
glog.Infof("dpll is locked, offset is in range, state is LOCKED(%s)", d.iface)
d.state = event.PTP_LOCKED
} else { // what happens if source is lost and DPLL is locked? goto holdover?
d.inSpec = true
} else {
glog.Infof("dpll is locked, offset is out of range, state is FREERUN(%s)", d.iface)
d.state = event.PTP_FREERUN
d.inSpec = true
}
d.inSpec = true
d.sendDpllEvent()
case DPLL_LOCKED_HO_ACQ, DPLL_HOLDOVER:
if d.hasPPSAsSource() {
switch {
case d.hasPPSAsSource():
if dpllStatus == DPLL_HOLDOVER {
d.state = event.PTP_FREERUN // pps when moved to HOLDOVER we declare freerun
d.state = event.PTP_FREERUN
d.phaseOffset = FaultyPhaseOffset
d.sourceLost = true
} else if dpllStatus == DPLL_LOCKED_HO_ACQ && d.isOffsetInRange() {
} else if d.isOffsetInRange() {
d.state = event.PTP_LOCKED
d.sourceLost = false
} else {
d.state = event.PTP_FREERUN
d.sourceLost = false
d.phaseOffset = FaultyPhaseOffset
}
} else if !d.sourceLost && d.isOffsetInRange() {
case !d.sourceLost && d.isOffsetInRange():
glog.Infof("dpll is locked, source is not lost, offset is in range, state is DPLL_LOCKED_HO_ACQ or DPLL_HOLDOVER(%s)", d.iface)
if d.hasGNSSAsSource() {
if d.onHoldover {
d.holdoverCloseCh <- true
glog.Infof("closing holdover for %s", d.iface)
}
d.inSpec = true
if d.hasGNSSAsSource() && d.onHoldover {
d.holdoverCloseCh <- true
glog.Infof("closing holdover for %s", d.iface)
}
d.inSpec = true
d.state = event.PTP_LOCKED
} else if d.sourceLost && d.inSpec {
glog.Infof("dpll state is DPLL_LOCKED_HO_ACQ or DPLL_HOLDOVER, source is lost, state is HOLDOVER(%s)", d.iface)
case d.sourceLost && d.inSpec:
glog.Infof("dpll state is DPLL_LOCKED_HO_ACQ or DPLL_HOLDOVER, source is lost, state is HOLDOVER(%s)", d.iface)
if !d.onHoldover {
d.holdoverCloseCh = make(chan bool)
d.onHoldover = true
d.state = event.PTP_HOLDOVER
go d.holdover()
}
return // sending events are handled by holdover return here
} else if !d.inSpec {
glog.Infof("dpll is not in spec ,state is DPLL_LOCKED_HO_ACQ or DPLL_HOLDOVER, offset is out of range, state is FREERUN(%s)", d.iface)
return // do not send event holdover will handle it
case !d.inSpec:
glog.Infof("dpll is not in spec, state is DPLL_LOCKED_HO_ACQ or DPLL_HOLDOVER, offset is out of range, state is FREERUN(%s)", d.iface)
d.state = event.PTP_FREERUN
d.phaseOffset = FaultyPhaseOffset
}
d.sendDpllEvent()
}
// log the decision
if d.hasPPSAsSource() {
glog.Infof("%s-dpll decision: Status %d, Offset %d, In spec %v, Source %v lost %v",
d.iface, dpllStatus, d.phaseOffset, d.inSpec, "pps", d.sourceLost)
d.sourceLost = false
//TODO: do not have a handler to catch pps source , so we will set to false
// and to true if state changes to holdover for source PPS based DPLL
} else if d.hasGNSSAsSource() {
glog.Infof("%s-dpll decision: Status %d, Offset %d, In spec %v, Source %v lost %v, On holdover %v",
d.iface, dpllStatus, d.phaseOffset, d.inSpec, "GNSS", d.sourceLost, d.onHoldover)
}
}

// sendDpllEvent sends DPLL event to the event channel
Expand Down Expand Up @@ -820,18 +821,22 @@ func (d *DpllConfig) holdover() {
//calculate offset
// TODO: should we stop calculation if source is returned during holdover but not in spec (meaning offset are not within threshold and state is not locked)
// Ans : continue to calculate offset here and if source is returned and actual offset is within threshold then go to locked state and cancel this timer
d.phaseOffset = int64(math.Round((d.slope / 1000) * float64(time.Since(start).Seconds())))
glog.Infof("(%s) time since holdover start %f, offset %d nanosecond holdover %s", d.iface, float64(time.Since(start).Seconds()), d.phaseOffset, strconv.FormatBool(d.onHoldover))
d.phaseOffset = int64(math.Round((d.slope / 1000) * time.Since(start).Seconds()))
glog.Infof("(%s) time since holdover start %f, offset %d nanosecond holdover %s", d.iface, time.Since(start).Seconds(), d.phaseOffset, strconv.FormatBool(d.onHoldover))
d.sendDpllEvent()
if !d.isLocalOffsetInRange() { // when holdover verify with local max holdover not with regular threshold
// once not in range, it will not go back to in range until holdover is closed
glog.Infof("offset is out of range: %v, max %v",
d.phaseOffset, d.LocalMaxHoldoverOffSet)
//TODO: Vitaly what should be the state here? should we go to freerun or stay in holdover
// I think this is outof spec so we should go to freerun
d.inSpec = false // in HO, Out of spec only if frequency is traceable
d.state = event.PTP_FREERUN
// TODO: implement frequency traceable check here
// if frequency traceable then Stay in HOLDOVER state resulting in CLOCK CLASS 140 (ITU-T G.781)
d.sendDpllEvent()
return
}
case <-timeout:
d.inSpec = false // in HO, Out of spec
d.inSpec = false // not in HO, Out of spec
d.state = event.PTP_FREERUN
d.phaseOffset = FaultyPhaseOffset
glog.Infof("holdover timer %d expired", d.timer)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dpll/dpll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getTestData(source event.EventSource, pinType uint32) []DpllTestCase {
expectedPhaseStatus: 0, //no phase status event for eec
expectedPhaseOffset: dpll.FaultyPhaseOffset * 1000000,
expectedFrequencyStatus: 2, // locked
expectedInSpecState: true,
expectedInSpecState: false,
desc: "1.locked frequency status, unknonw Phase status ",
}, {
reply: &nl.DoDeviceGetReply{
Expand Down
33 changes: 16 additions & 17 deletions pkg/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,8 @@ func (e *EventHandler) updateGMState(cfgName string) grandMasterSyncState {
switch dpllState {
case PTP_FREERUN:
e.gmSyncState[cfgName].state = dpllState
if e.outOfSpec {
// T-GM in holdover, out of holdover specification
e.gmSyncState[cfgName].clockClass = protocol.ClockClassOutOfSpec
} else { // from holdover it goes to out of spec to free run
// T-GM or T-BC in free-run mode
e.gmSyncState[cfgName].clockClass = protocol.ClockClassFreerun
}
// T-GM or T-BC in free-run mode
e.gmSyncState[cfgName].clockClass = protocol.ClockClassFreerun
case PTP_HOLDOVER:
e.gmSyncState[cfgName].state = dpllState
// T-GM in holdover, within holdover specification
Expand Down Expand Up @@ -694,13 +689,18 @@ connect:
}
}
sendUpdate := false
offset, found := event.Values["offset"]
if found {
clockAccuracy := fbprotocol.ClockAccuracyFromOffset(time.Duration(offset.(int)) * time.Nanosecond)
if clockAccuracy != gmState.clockAccuracy {
sendUpdate = true
// on phase offset changes update clock accuracy
if event.ProcessName == DPLL {
if offset, found := event.Values[OFFSET]; found {
offsetValue, ok := offset.(int64)
if ok {
clockAccuracy := fbprotocol.ClockAccuracyFromOffset(time.Duration(offsetValue) * time.Nanosecond)
if clockAccuracy != gmState.clockAccuracy {
sendUpdate = true
}
gmState.clockAccuracy = clockAccuracy
}
}
gmState.clockAccuracy = clockAccuracy
}

if e.clockClass != protocol.ClockClassUninitialized &&
Expand All @@ -721,7 +721,7 @@ connect:
}
}()
}
} // end of GM congition
} // end of GM condition
if len(logOut) > 0 {
if e.stdoutToSocket {
for _, l := range logOut {
Expand Down Expand Up @@ -825,8 +825,7 @@ func (e *EventHandler) GetPTPState(source EventSource, cfgName string) PTPState

// UpdateClockStateMetrics ...
func (e *EventHandler) UpdateClockStateMetrics(state PTPState, process, iFace string) {
labels := prometheus.Labels{}
labels = prometheus.Labels{
labels := prometheus.Labels{
"process": process, "node": e.nodeName, "iface": iFace}
if state == PTP_LOCKED {
e.clockMetric.With(labels).Set(1)
Expand Down Expand Up @@ -908,7 +907,7 @@ func (e *EventHandler) updateMetrics(cfgName string, process EventSource, proces
s.Labels = map[string]string{"from": pName, "node": e.nodeName,
"process": string(process), "iface": iface}
s.Value = dataValue
d.Metrics[dataType].GaugeMetric.With(s.Labels).Set(dataValue)
d.Metrics[dataType].GaugeMetric.With(s.Labels).Set(s.Value)
}
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var (
func monkeyPatch() {

event.PMCGMGetter = func(cfgName string) (protocol.GrandmasterSettings, error) {
cfgName = strings.Replace(cfgName, event.TS2PHCProcessName, event.PTP4lProcessName, 1)
return protocol.GrandmasterSettings{
ClockQuality: fbprotocol.ClockQuality{
ClockClass: 0,
Expand All @@ -47,7 +46,6 @@ func monkeyPatch() {
}, nil
}
event.PMCGMSetter = func(cfgName string, g protocol.GrandmasterSettings) error {
cfgName = strings.Replace(cfgName, event.TS2PHCProcessName, event.PTP4lProcessName, 1)
return nil
}
}
Expand Down

0 comments on commit a7ae479

Please sign in to comment.