daemon

package
v0.0.0-...-2bb883b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MathDefaultHistory is a default number of samples to keep
	MathDefaultHistory = 100
	// MathDefaultM is a default formula to calculate M
	MathDefaultM = "mean(clockaccuracy, 100) + abs(mean(offset, 100)) + 1.0 * stddev(offset, 100)"
	// MathDefaultW is a default formula to calculate W
	MathDefaultW = "mean(m, 100) + 4.0 * stddev(m, 100)"
	// MathDefaultDrift is a default formula to calculate default drift
	MathDefaultDrift = "1.5 * mean(freqchangeabs, 99)"
)
View Source
const ManagedPTPDevicePath = string(fbclock.PTPPath)

ManagedPTPDevicePath is the path we will set up a copy of iface's PHC device, so that fbclock clients can access it without explicit configuration.

View Source
const MathHelp = `` /* 1161-byte string literal not displayed */

MathHelp is a help message used by flags in main

Variables

This section is empty.

Functions

func SetupDeviceDir

func SetupDeviceDir(iface string) error

SetupDeviceDir creates a PHC device path from the interface name

func TimeMonotonicRaw

func TimeMonotonicRaw() (time.Time, error)

TimeMonotonicRaw returns the current time from CLOCK_MONOTONIC_RAW

Types

type CSVLogger

type CSVLogger struct {
	// contains filtered or unexported fields
}

CSVLogger logs Sample as CSV into given writer

func NewCSVLogger

func NewCSVLogger(w io.Writer, sampleRate int) *CSVLogger

NewCSVLogger returns new CSVLogger

func (*CSVLogger) Log

func (l *CSVLogger) Log(s *LogSample) error

Log implements Logger interface

type Config

type Config struct {
	PTPClientAddress               string        // where should fbclock connect to
	RingSize                       int           // must be at least the size of N samples we use in expressions
	Math                           Math          // configuration for calculation we'll be doing
	Interval                       time.Duration // how often do we poll ptp4l and update data in shm
	Iface                          string        // network interface to use
	LinearizabilityTestInterval    time.Duration // perform the linearizability test every so often
	SPTP                           bool          // denotes whether we are running in sptp or ptp4l mode
	LinearizabilityTestMaxGMOffset time.Duration // max offset between GMs before linearizability test considered failed
	BootDelay                      time.Duration // postpone startup by this time after boot
	EnableDataV2                   bool          // enable fbclock data v2
}

Config represents configuration we expect to read from file

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig reads config and unmarshals it from yaml into Config

func (*Config) EvalAndValidate

func (c *Config) EvalAndValidate() error

EvalAndValidate makes sure config is valid and evaluates expressions for further use.

func (*Config) PostponeStart

func (c *Config) PostponeStart() error

PostponeStart postpones startup by BootDelay

type Daemon

type Daemon struct {
	DataFetcher
	// contains filtered or unexported fields
}

Daemon is a component of fbclock that runs continuously, talks to ptp4l, does the math and populates shared memory for client library to read from.

func New

func New(cfg *Config, stats stats.Server, l Logger) (*Daemon, error)

New creates new fbclock-daemon

func (*Daemon) Run

func (s *Daemon) Run(ctx context.Context) error

Run a daemon

type DataFetcher

type DataFetcher interface {
	//function to gm data
	FetchGMs(cfg *Config) (targest []string, err error)
	//function to fetch stats
	FetchStats(cfg *Config) (*DataPoint, error)
}

DataFetcher is the data fetcher interface

type DataPoint

type DataPoint struct {
	// IngressTimeNS represents ingress time in NanoSeconds
	IngressTimeNS int64
	// MasterOffsetNS represents master offset in NanoSeconds
	MasterOffsetNS float64
	// PathDelayNS represents path delay in NanoSeconds
	PathDelayNS float64
	// FreqAdjustmentPPB represents freq adjustment in parts per billion
	FreqAdjustmentPPB float64
	// ClockAccuracyNS represents clock accurary in nanoseconds
	ClockAccuracyNS float64
}

DataPoint is what we store in DataPoint ring buffer

func (*DataPoint) SanityCheck

func (d *DataPoint) SanityCheck() error

SanityCheck checks datapoint for correctness

type DummyLogger

type DummyLogger struct {
	// contains filtered or unexported fields
}

DummyLogger logs M and W to given writer

func NewDummyLogger

func NewDummyLogger(w io.Writer, sampleRate int) *DummyLogger

NewDummyLogger returns new DummyLogger

func (*DummyLogger) Log

func (l *DummyLogger) Log(s *LogSample) error

Log implements Logger interface

type HTTPFetcher

type HTTPFetcher struct {
	DataFetcher
}

HTTPFetcher provides data fetcher implementation using http

func (*HTTPFetcher) FetchGMs

func (hf *HTTPFetcher) FetchGMs(cfg *Config) (targets []string, err error)

FetchGMs fetches GMs via http

func (*HTTPFetcher) FetchStats

func (hf *HTTPFetcher) FetchStats(cfg *Config) (*DataPoint, error)

FetchStats fetches GMs via http

type LogSample

type LogSample struct {
	MasterOffsetNS          float64
	MasterOffsetMeanNS      float64
	MasterOffsetStddevNS    float64
	PathDelayNS             float64
	PathDelayMeanNS         float64
	PathDelayStddevNS       float64
	FreqAdjustmentPPB       float64
	FreqAdjustmentMeanPPB   float64
	FreqAdjustmentStddevPPB float64
	MeasurementNS           float64
	MeasurementMeanNS       float64
	MeasurementStddevNS     float64
	WindowNS                float64
	ClockAccuracyMean       float64
}

LogSample has all the measurements we may want to log

func (*LogSample) CSVRecords

func (s *LogSample) CSVRecords() []string

CSVRecords returns all data from this sample as CSV. Must by synced with `header` variable.

type Logger

type Logger interface {
	Log(*LogSample) error
}

Logger is something that can store LogSample somewhere

type Math

type Math struct {
	M string // Measurement, our value for clock quality

	W string // window of uncertainty, without adjustment for potential holdover

	Drift string // drift in PPB, for holdover multiplier calculations
	// contains filtered or unexported fields
}

Math stores our math expressions for M ans W values in two forms: string and parsed

func (*Math) Prepare

func (m *Math) Prepare() error

Prepare will prepare all math expressions

type SockFetcher

type SockFetcher struct {
	DataFetcher
}

SockFetcher provides data fetcher implementation using ptp4l Sock

func (*SockFetcher) FetchGMs

func (sf *SockFetcher) FetchGMs(cfg *Config) (targets []string, err error)

FetchGMs fetches gm data from ptp4l socket

func (*SockFetcher) FetchStats

func (sf *SockFetcher) FetchStats(cfg *Config) (*DataPoint, error)

FetchStats fetches stats from ptp4l socket

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL