Comments (4)
Of course, if it's possible for quanta
to ever generate Instant
s with the u64
value 0, this won't work, so we'd need to know for sure that this is the case. Otherwise, we'll need to find an alternative solution for my use case.
from quanta.
Thinking through this one a little bit, and putting my thoughts down in this issue...
I think, practically speaking, there is an infinitesimally small chance of generating an Instant
whose raw value is 0
. While our reference time anchor may initially be zero -- unlikely, very unlikely, but technically possible -- and our TSC scaling factor could end up scaling a raw TSC read to zero... it's just... super unlikely. That said, it's technically possible: timespec
in libc uses signed integers for both the second and nanosecond components. We might end up somewhere before zero, with the TSC addition bringing it up to zero.
There's also the technically-possible-but-highly-unlikely issue of integer overflow/wraparound as we scale up the raw TSC value and then add it to the reference time anchor, bringing it inline with the output you'd get from clock_gettime(CLOCK_MONOTONIC)
directly.
While we could always construct an Instant
such that we bitwise-AND the value with one, to ensure it's non-zero, that's an extra instruction for every single time we build an Instant
, which is annoying. Maybe not practically meaningful, performance-wise, certainly compared to the other heavy-handed stuff that std::time
is doing... but still not great.
from quanta.
The other thing is that doing so would introduce a 1ns forward jump about half of the time, which isn't terrible in terms of accuracy, but it might make monotonicity invariants harder to achieve. Gotta think through that one...
from quanta.
Just to close the mental loop around the bitwise-AND idea for my own sake: I think this would work.
Since we're only ever adding to the value, we won't be changing the numbers such that they warp backwards in time, which upholds the monotonicity invariant between two values of Instant
. At worst, we may end up with two measurements -- T0 and T1 -- that, when uncorrected, are 1 nanosecond apart. If T0 was even, we would increment it by 1ns, which would make it equal to T1.
I'll whip up a simple PR to benchmark the change.
from quanta.
Related Issues (20)
- Attempting to start Upkeep always returns an UpkeepRunning error HOT 2
- Fix benchmark GH action.
- Unify global recent / global clock usage.
- Always gives the time since last boot HOT 2
- Clean up our wild use of conditional compilation.
- Testing for all supported platforms. HOT 2
- Failed to build version 0.9.1 HOT 1
- Does not build on MIPS and ARMv5 HOT 7
- Check for RDTSCP support doesn't work HOT 2
- Switch to CLOCK_BOOTTIME and friends to improve accuracy. HOT 2
- Intermittent panic due to overflowing our source calibration denominator. HOT 5
- Comparing to `minstant` HOT 9
- Adding support for TSC on ARM. HOT 4
- Fails to build on x86 without SSE2 HOT 2
- Allow Instant to be used atomically HOT 3
- Quanta Clock is off by a factor of 1000 in web browsers
- RUSTSEC-2020-0168: mach is unmaintained HOT 2
- Much slower than std version in case of high contention HOT 2
- Can Clock provide `delta_as_nanos`? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quanta.