New creates new fbclock-daemon
(cfg *Config, stats stats.Server, l Logger)
| 198 | r[target] = linearizability.SPTPHTTPTestResult{Error: errNoTestResults} |
| 199 | } |
| 200 | return r |
| 201 | } |
| 202 | |
| 203 | // New creates new fbclock-daemon |
| 204 | func New(cfg *Config, stats stats.Server, l Logger) (*Daemon, error) { |
| 205 | // we need at least 1m of samples for aggregate values |
| 206 | effectiveRingSize := minRingSize(cfg.RingSize, cfg.Interval) |
| 207 | s := &Daemon{ |
| 208 | stats: stats, |
| 209 | state: newDaemonState(effectiveRingSize), |
| 210 | cfg: cfg, |
| 211 | l: l, |
| 212 | } |
| 213 | if cfg.SPTP { |
| 214 | s.DataFetcher = &HTTPFetcher{} |
| 215 | } else { |
| 216 | s.DataFetcher = &SockFetcher{} |
| 217 | } |
| 218 | |
| 219 | phcDevice, err := phc.IfaceToPHCDevice(cfg.Iface) |
| 220 | if err != nil { |
| 221 | return nil, fmt.Errorf("finding PHC device for %q: %w", cfg.Iface, err) |
| 222 | } |
| 223 | |
| 224 | // Keep file open for the lifetime of the fbclock |
| 225 | f, err := os.OpenFile(phcDevice, os.O_RDWR, 0) |
| 226 | if err != nil { |
| 227 | return nil, err |
| 228 | } |
| 229 | dev := phc.FromFile(f) |
| 230 | |
| 231 | // function to get time from phc |
| 232 | s.getPHCTime = func() (time.Time, error) { return dev.Time() } |
| 233 | s.getPHCAndSysTime = func() (time.Time, time.Time, uint32, time.Duration, error) { |
| 234 | // Primary anchor: uses the existing MONOTONIC_RAW-preferred path so that |
| 235 | // fbclock_gettime behavior is unchanged. Falls back to REALTIME if the |
| 236 | // kernel doesn't accept MONO_RAW in the ioctl. |
| 237 | data, err := dev.ReadSysoffExtended() |
| 238 | if err != nil { |
| 239 | return time.Time{}, time.Time{}, 0, 0, err |
| 240 | } |
| 241 | best := data.BestSample() |
| 242 | return best.PHCTime, best.SysTime, uint32(best.SysClockID), best.Delay, nil //nolint:gosec |
| 243 | } |
| 244 | s.getPHCAndSysTimeRealtime = func() (time.Time, time.Time, time.Duration, error) { |
| 245 | // Realtime anchor in CLOCK_REALTIME, only for fbclock_gettime_past. |
| 246 | data, err := dev.ReadSysoffExtendedRealTimeClock() |
| 247 | if err != nil { |
| 248 | return time.Time{}, time.Time{}, 0, err |
| 249 | } |
| 250 | best := data.BestSample() |
| 251 | return best.PHCTime, best.SysTime, best.Delay, nil |
| 252 | } |
| 253 | s.getPHCFreqPPB = func() (float64, error) { return dev.FreqPPB() } |
| 254 | // calculated values |
| 255 | s.stats.SetCounter("m_ns", 0) |
| 256 | s.stats.SetCounter("w_ns", 0) |
| 257 | s.stats.SetCounter("drift_ppb", 0) |
no test coverage detected