pub struct Counter { /* private fields */ }Available on AArch64 or x86-64 only.
Expand description
The CPU’s free-running counter: cntvct_el0 on aarch64, the time-stamp counter on x86_64.
A reading is one instruction that touches no memory. Every core and process on a machine reads
the same counter, so a Tickstamp one process took, another may subtract from. Only the
difference of two readings means anything, and the counter’s rate turns it into
a span.
The read is not ordered against the instructions around it: right for stamping, and for timing anything much longer than the read itself.
§Examples
use t2t_clock::{Clock, Counter};
use t2t_core::Timedelta;
let counter = Counter::discover()?;
let start = counter.now();
let took = (counter.now() - start).to_timedelta(counter.rate());
assert!(took < Timedelta::from_millis(1), "two reads back to back");Implementations§
Source§impl Counter
impl Counter
Sourcepub fn discover() -> Result<Self, CounterError>
pub fn discover() -> Result<Self, CounterError>
The counter, at the rate the CPU reports for it; where it reports none, on x86_64 with
std on 64-bit Linux or macOS, one measured against the OS clocks over 10 ms.
§Errors
CounterError::NotInvariant, the time-stamp counter’s rate follows the core’s.CounterError::NoRate, the CPU reports no rate, and none could be measured.CounterError::ImplausibleRate, the rate is outside 1 MHz to 10 GHz.
Trait Implementations§
impl Copy for Counter
impl Eq for Counter
impl StructuralPartialEq for Counter
Auto Trait Implementations§
impl Freeze for Counter
impl RefUnwindSafe for Counter
impl Send for Counter
impl Sync for Counter
impl Unpin for Counter
impl UnsafeUnpin for Counter
impl UnwindSafe for Counter
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
Mutably borrows from an owned value. Read more