pub struct TscFrequency {
hz: u64,
}Expand description
Fields§
§hz: u64Implementations§
Source§impl TscFrequency
impl TscFrequency
Sourcepub const fn from_hz(hz: u64) -> Option<Self>
pub const fn from_hz(hz: u64) -> Option<Self>
Builds a frequency from a hertz value, rejecting implausible values.
Sourcepub fn from_cpuid(leaf15: [u32; 4], leaf16: [u32; 4]) -> Option<Self>
pub fn from_cpuid(leaf15: [u32; 4], leaf16: [u32; 4]) -> Option<Self>
Detects the frequency from CPUID leaves 0x15 and 0x16.
The arguments are the four u32 registers of each leaf in
[EAX, EBX, ECX, EDX] order, so this function stays pure and testable
on the host. Priority and validation are described at module level.
Returns None when neither leaf yields a plausible frequency; it never
panics, whatever the inputs.
Sourcepub const fn mhz(self) -> u64
pub const fn mhz(self) -> u64
Frequency in megahertz, truncated towards zero.
The truncation is documented because the value is only used for
human-readable diagnostics; the exact value is Self::hz.
Sourcepub fn nanoseconds(self, cycles: u64) -> u64
pub fn nanoseconds(self, cycles: u64) -> u64
Converts a cycle count to nanoseconds, rounded to the nearest integer.
Rounds half up (+ hz/2 before the division). Saturates at
u64::MAX instead of overflowing; never divides by zero (the
constructor guarantees a non-zero frequency).
Source§impl TscFrequency
impl TscFrequency
Sourcepub fn cpuid_leaves(self) -> CpuidTscLeaves
pub fn cpuid_leaves(self) -> CpuidTscLeaves
Derives the CPUID leaves that publish this frequency to a guest.
The representation is exact whenever hz / gcd(hz, 1 GHz) fits in 32
bits, which covers every frequency up to about 4.29 GHz and many higher
ones (for example 10 GHz reduces to 10/1). Otherwise the frequency is
published with a 1 MHz crystal and a numerator truncated to the lower
megahertz: the guest then computes a frequency off by less than 1 MHz,
that is less than 0.001 % at 3 GHz.
base_mhz is always the truncated megahertz value, as leaf 0x16
specifies an integer number of megahertz. A guest that has both leaves
can cross-check them.
Trait Implementations§
Source§impl Clone for TscFrequency
impl Clone for TscFrequency
impl Copy for TscFrequency
Source§impl Debug for TscFrequency
impl Debug for TscFrequency
impl Eq for TscFrequency
Source§impl Ord for TscFrequency
impl Ord for TscFrequency
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TscFrequency
impl PartialEq for TscFrequency
Source§impl PartialOrd for TscFrequency
impl PartialOrd for TscFrequency
impl StructuralPartialEq for TscFrequency
Auto Trait Implementations§
impl Forget for TscFrequency
impl Freeze for TscFrequency
impl Move for TscFrequency
impl RefUnwindSafe for TscFrequency
impl Send for TscFrequency
impl Sync for TscFrequency
impl Unpin for TscFrequency
impl UnsafeUnpin for TscFrequency
impl UnwindSafe for TscFrequency
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more