mod ntp;
pub use ntp::{Ntp, NtpData, Stratum, TryFromU8Error, ValidStratumLevel};
mod phc;
pub use phc::{Phc, PhcData};
use crate::daemon::time::{TscCount, TscDiff};
#[cfg(feature = "daemon")]
use {
crate::daemon::io::tsc::{read_timestamp_counter_begin, read_timestamp_counter_end},
crate::daemon::time::{Clock, clocks::RealTime},
};
pub enum Event {
Ntp(Ntp),
Phc(Phc),
}
pub trait TscRtt {
fn counter_pre(&self) -> TscCount;
fn counter_post(&self) -> TscCount;
fn rtt(&self) -> TscDiff {
self.counter_post() - self.counter_pre()
}
fn tsc_midpoint(&self) -> TscCount {
self.counter_pre().midpoint(self.counter_post())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SystemClockMeasurement {
pub system_time: crate::daemon::time::Instant,
pub tsc: TscCount,
}
impl SystemClockMeasurement {
#[cfg(feature = "daemon")]
#[allow(clippy::cast_possible_wrap)]
pub fn now() -> Self {
let pre = read_timestamp_counter_begin();
let system_time = RealTime.get_time();
let post = read_timestamp_counter_end();
let tsc = pre.midpoint(post);
Self {
system_time,
tsc: TscCount::new(tsc as i64),
}
}
}