Skip to content

Commit

Permalink
fail measurement if oscillatord is unavailable (#321)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #321

When `oscillatord` is stopped (crashed for example) `c4u` will not refresh the `ptp4u` config and we may end up serving bad time as a result.
This diff fixes this situation by assuming `nil` measurement means "uncalibrated"

Reviewed By: abulimov

Differential Revision: D52834697

fbshipit-source-id: 62d76f92d9593960d65c9b8150da1f423035ea90
  • Loading branch information
leoleovich authored and facebook-github-bot committed Jan 17, 2024
1 parent 506a539 commit c467f80
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
19 changes: 10 additions & 9 deletions ptp/c4u/c4u.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,18 @@ func Run(config *Config, rb *clock.RingBuffer, st stats.Stats) error {
log.Errorf("Failed to collect clock data: %v", err)
dataError = true
}
// To avoid stale data always continue to fill the ring buffer
// even with nil values

// If DP is missing - assume the worst
if dp == nil {
dp = &clock.DataPoint{
OscillatorClockClass: clock.ClockClassUncalibrated,
}
}

rb.Write(dp)
// stats
if dp != nil {
st.SetPHCOffsetNS(int64(dp.PHCOffset))
st.SetOscillatorOffsetNS(int64(dp.OscillatorOffset))
} else {
st.SetPHCOffsetNS(0)
st.SetOscillatorOffsetNS(0)
}
st.SetPHCOffsetNS(int64(dp.PHCOffset))
st.SetOscillatorOffsetNS(int64(dp.OscillatorOffset))

w, err := clock.Worst(rb.Data(), config.AccuracyExpr, config.ClassExpr)
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions ptp/c4u/c4u_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,49 @@ func TestRun(t *testing.T) {
require.Equal(t, expected, dc)
}

func TestRunNilDatapoint(t *testing.T) {
// We don't really care about UTCOffset here - just to be the same result as in c4u.Run()
utcoffset, _ := utcoffset.Run()

expected := &server.DynamicConfig{
ClockClass: ptp.ClockClass52,
ClockAccuracy: 254,
DrainInterval: 30 * time.Second,
MaxSubDuration: 1 * time.Hour,
MetricInterval: 1 * time.Minute,
MinSubInterval: 1 * time.Second,
UTCOffset: utcoffset,
}

cfg, err := os.CreateTemp("", "c4u")
require.NoError(t, err)
defer os.Remove(cfg.Name())

c := &Config{
Path: cfg.Name(),
Sample: 3,
Apply: true,
AccuracyExpr: "1",
ClassExpr: "p99(oscillatorclass)",
}

st := stats.NewJSONStats()
rb := clock.NewRingBuffer(2)
dp := &clock.DataPoint{
PHCOffset: time.Microsecond,
OscillatorOffset: time.Microsecond,
OscillatorClockClass: clock.ClockClassHoldover,
}
rb.Write(dp)
err = Run(c, rb, st)
require.NoError(t, err)

dc, err := server.ReadDynamicConfig(c.Path)
require.NoError(t, err)
// must make sure nil entry results in ClockClass = 52
require.Equal(t, expected, dc)
}

func TestEvaluateClockQuality(t *testing.T) {
c := &Config{
LockBaseLine: ptp.ClockAccuracyMicrosecond1,
Expand Down
2 changes: 1 addition & 1 deletion ptp/c4u/clock/oscillatord.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func oscillatord() (*oscillatorState, error) {
}
defer conn.Close()
deadline := time.Now().Add(timeout)
if err := conn.SetDeadline(deadline); err != nil {
if err = conn.SetDeadline(deadline); err != nil {
return nil, err
}

Expand Down

0 comments on commit c467f80

Please sign in to comment.