⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

Module ntp

Module ntp 

Source
Expand description

NTP client for VeridianOS time synchronization

Implements NTPv4 (RFC 5905) client mode with:

  • 48-byte NTP packet serialization/deserialization
  • Clock offset and round-trip delay calculation (integer-only)
  • Marzullo’s algorithm for multi-source time selection
  • Clock filter (best-of-8 by minimum delay)
  • Drift compensation via integer linear regression
  • RTC integration for system clock adjustment

Structs§

ClockFilter
Clock filter: keeps the last CLOCK_FILTER_SIZE samples and selects the one with the smallest round-trip delay as the best estimate.
DriftEstimator
Drift estimator using integer linear regression over recent measurements.
NtpClient
NTP client managing time synchronization with one or more servers.
NtpMeasurement
Result of processing an NTP response.
NtpPacket
NTPv4 packet (48 bytes, RFC 5905).
NtpTimestamp
NTP timestamp: 32-bit seconds since 1900-01-01 + 32-bit fraction.
TimeInterval
An interval from a time source for Marzullo’s algorithm.

Enums§

LeapIndicator
Leap indicator values (2-bit field)

Constants§

CLOCK_FILTER_SIZE
Number of samples in the clock filter
MAX_POLL_INTERVAL
Maximum poll interval in seconds (2^10 = 1024s)
MIN_POLL_INTERVAL
Minimum poll interval in seconds (2^6 = 64s)
NTP_PACKET_SIZE
NTP packet size in bytes
NTP_PORT
NTP UDP port
NTP_UNIX_OFFSET
Seconds between NTP epoch (1900-01-01) and Unix epoch (1970-01-01) 70 years including 17 leap years: (70*365 + 17) * 86400

Functions§

boot_sync
Trigger a boot-time NTP synchronization.
calculate_offset_delay
Calculate clock offset and round-trip delay from NTP timestamps.
get_last_sync_epoch
Get the last NTP sync time as Unix epoch seconds (0 = never synced).
get_ntp_offset_ms
Get the last NTP-computed offset in milliseconds.
get_poll_interval
Get the current poll interval in seconds.
marzullo_select
Run Marzullo’s algorithm on a set of time intervals to find the tightest intersection supported by a majority of sources.
record_sync
Record that a successful NTP sync occurred at the given Unix epoch time.