14 static constexpr
unsigned fp_floor(u32 t, u64 k)
15 {
return unsigned((u64(t) * k) >> 32); }
16 static constexpr u32 fp_round(
unsigned t, u64 k)
17 {
return u32((u64(t) * k + (1u << 31)) >> 32); }
19 unsigned TimeVal::elapsed_tick()
const {
35 tval += fp_round(usec,
clk->m_tick_per_usec);
41 tval += fp_round(msec,
clk->m_tick_per_msec);
47 if (elapsed >= ticks) {
56 u32 ticks = fp_round(usec,
clk->m_tick_per_usec);
61 u32 ticks = fp_round(msec,
clk->m_tick_per_msec);
70 return TimeVal {
this,
raw() + fp_round(usec, m_tick_per_usec)};
74 return TimeVal {
this,
raw() + fp_round(msec, m_tick_per_msec)};
79 if (!
tval)
return false;
84 static const u32 THRESHOLD = UINT32_MAX / 8;
85 if (elapsed < THRESHOLD) {
96 u32 interval = fp_round(usec, m_tick_per_usec);
97 while (
raw() - tstart < interval) {}
The TimeRef API provides access to a monotonic time-counter.
TimeVal checkpoint_msec(unsigned msec)
Create an oven-timer, set N milliseconds from now.
virtual u32 raw()=0
Read current time in arbitrary "ticks".
TimeVal now()
Create a TimeVal object using the tick-count from raw().
TimeVal checkpoint_usec(unsigned usec)
Create an oven-timer, set N microseconds from now.
void busywait_usec(unsigned usec)
If timer resolution allows, busywait for X microseconds.
Implement TimeRef API using a memory-mapped performance counter.
u32 raw() override
Read current time in arbitrary "ticks".
Timestamp for measuring elapsed time.
unsigned elapsed_usec() const
Elapsed time in microseconds.
bool interval_usec(unsigned usec)
Test an interval measured in microseconds.
TimeRef * clk
Pointer to the parent time reference.
bool checkpoint_elapsed()
Test if an oven-timer checkpoint has elapsed.
u32 tval
The value of this timestamp, measured in ticks.
bool interval_tick(u32 ticks)
Test an interval measured in ticks.
unsigned increment_msec()
Measure elapsed time in milliseconds, then increment by the returned quantized value.
unsigned elapsed_msec() const
Elapsed time in milliseconds.
bool interval_msec(unsigned msec)
Test an interval measured in milliseconds.
unsigned increment_usec()
Measure elapsed time in microseconds, then increment by the returned quantized value.
TimeRef and TimeVal define the API for monotonic timers.
Miscellaneous mathematical utility functions.