Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quanta overhaul: calibration speed, accuracy, and more #19

Merged
merged 5 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ harness = false
metrics = ["metrics-core"]

[dependencies]
once_cell = "^1.4"
metrics-core = { version = "^0.5", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions benches/timing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn time_clocksource_counter_scaled(b: &mut Bencher) {
}

fn time_quanta_now(b: &mut Bencher) {
let clock = Clock::new();
let mut clock = Clock::new();
b.iter(|| clock.now())
}

Expand Down Expand Up @@ -93,7 +93,7 @@ fn time_quanta_raw_delta(b: &mut Bencher) {
}

fn time_quanta_now_delta(b: &mut Bencher) {
let clock = Clock::new();
let mut clock = Clock::new();
b.iter(|| {
let start = clock.now();
let end = clock.now();
Expand Down
12 changes: 2 additions & 10 deletions src/counter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::ClockSource;

#[cfg(all(target_arch = "x86", target_feature = "sse2"))]
use std::arch::x86::{__rdtscp, _mm_lfence, _rdtsc};
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))]
use std::arch::x86_64::{__rdtscp, _mm_lfence, _rdtsc};

Expand All @@ -15,10 +13,7 @@ impl Counter {
}
}

#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
target_feature = "sse2"
))]
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))]
impl ClockSource for Counter {
fn now(&self) -> u64 {
unsafe {
Expand Down Expand Up @@ -46,10 +41,7 @@ impl ClockSource for Counter {
}
}

#[cfg(not(all(
any(target_arch = "x86", target_arch = "x86_64"),
target_feature = "sse2"
)))]
#[cfg(not(all(target_arch = "x86_64", target_feature = "sse2")))]
impl ClockSource for Counter {
fn now(&self) -> u64 {
panic!("can't use counter without TSC support");
Expand Down
22 changes: 7 additions & 15 deletions src/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@ use std::time::Duration;

/// A point-in-time wall-clock measurement.
///
/// Represents a time measurement that has been taken by [`Clock`](crate::Clock) and scaled to wall-clock time.
/// Represents a time measurement that has been taken by [`Clock`](crate::Clock) and scaled to reference time.
///
/// Unlike the stdlib `Instant`, this type has two meaningful differences:
/// - It provides no guarantees around monotonicity whatsoever, beyond any guarantees provided by
/// `Clock` itself.
/// - It is intended to be opaque, but the internal value can be accessed. There are no guarantees
/// on the internal value timebase, or other factors, remaining stable over time and this
/// convenience is only intended for comparisons of `Instant`s provided by the same exact `Clock`
/// instance.
/// Unlike the stdlib `Instant`, this type has a meaningful difference: it is intended to be opaque, but the
/// internal value _can_ be accessed. There are no guarantees here and depending on this value directly is
/// proceeding at your own risk. ⚠️
///
/// An `Instant` is 8 bytes.
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Instant(pub(crate) u64);

impl Instant {
pub(crate) fn new(inner: u64) -> Self {
Instant(inner)
}

/// Returns the amount of time elapsed from another instant to this one.
///
/// # Panics
Expand All @@ -40,7 +32,7 @@ impl Instant {
/// use std::time::Duration;
/// use std::thread::sleep;
///
/// let clock = Clock::new();
/// let mut clock = Clock::new();
/// let now = clock.now();
/// sleep(Duration::new(1, 0));
/// let new_now = clock.now();
Expand All @@ -63,7 +55,7 @@ impl Instant {
/// use std::time::Duration;
/// use std::thread::sleep;
///
/// let clock = Clock::new();
/// let mut clock = Clock::new();
/// let now = clock.now();
/// sleep(Duration::new(1, 0));
/// let new_now = clock.now();
Expand All @@ -84,7 +76,7 @@ impl Instant {
/// use std::time::Duration;
/// use std::thread::sleep;
///
/// let clock = Clock::new();
/// let mut clock = Clock::new();
/// let now = clock.now();
/// sleep(Duration::new(1, 0));
/// let new_now = clock.now();
Expand Down
Loading