mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:17:36 +00:00
Everywhere: Use MonotonicTime instead of Duration
This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
This commit is contained in:
parent
b2e7b8cdff
commit
fc5cab5c21
29 changed files with 79 additions and 80 deletions
|
@ -328,12 +328,12 @@ ErrorOr<u32> Controller::get_pcm_output_sample_rate(size_t channel_index)
|
|||
|
||||
ErrorOr<void> wait_until(size_t delay_in_microseconds, size_t timeout_in_microseconds, Function<ErrorOr<bool>()> condition)
|
||||
{
|
||||
auto const timeout = Duration::from_microseconds(static_cast<i64>(timeout_in_microseconds));
|
||||
auto const& time_management = TimeManagement::the();
|
||||
// FIXME: Use monotonic time instead.
|
||||
u64 start_microseconds = time_management.now().offset_to_epoch().to_microseconds();
|
||||
auto start = time_management.monotonic_time(TimePrecision::Precise);
|
||||
while (!TRY(condition())) {
|
||||
microseconds_delay(delay_in_microseconds);
|
||||
if ((time_management.now().offset_to_epoch().to_microseconds() - start_microseconds) >= timeout_in_microseconds)
|
||||
if (time_management.monotonic_time(TimePrecision::Precise) - start >= timeout)
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
return {};
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace Kernel {
|
|||
|
||||
static void delay(i64 nanoseconds)
|
||||
{
|
||||
auto start = TimeManagement::the().monotonic_time().to_nanoseconds();
|
||||
auto end = start + nanoseconds;
|
||||
while (TimeManagement::the().monotonic_time().to_nanoseconds() < end)
|
||||
auto start = TimeManagement::the().monotonic_time();
|
||||
auto end = start + Duration::from_nanoseconds(nanoseconds);
|
||||
while (TimeManagement::the().monotonic_time() < end)
|
||||
Processor::pause();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ static u64 (*s_scheduler_current_time)();
|
|||
static u64 current_time_monotonic()
|
||||
{
|
||||
// We always need a precise timestamp here, we cannot rely on a coarse timestamp
|
||||
return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).to_nanoseconds();
|
||||
return (u64)TimeManagement::the().monotonic_time(TimePrecision::Precise).nanoseconds();
|
||||
}
|
||||
|
||||
u64 TimeManagement::scheduler_current_time()
|
||||
|
@ -81,11 +81,11 @@ Duration TimeManagement::current_time(clockid_t clock_id) const
|
|||
{
|
||||
switch (clock_id) {
|
||||
case CLOCK_MONOTONIC:
|
||||
return monotonic_time(TimePrecision::Precise);
|
||||
return monotonic_time(TimePrecision::Precise).time_since_start({});
|
||||
case CLOCK_MONOTONIC_COARSE:
|
||||
return monotonic_time(TimePrecision::Coarse);
|
||||
return monotonic_time(TimePrecision::Coarse).time_since_start({});
|
||||
case CLOCK_MONOTONIC_RAW:
|
||||
return monotonic_time_raw();
|
||||
return monotonic_time_raw().time_since_start({});
|
||||
case CLOCK_REALTIME:
|
||||
return epoch_time(TimePrecision::Precise).offset_to_epoch();
|
||||
case CLOCK_REALTIME_COARSE:
|
||||
|
@ -110,7 +110,7 @@ void TimeManagement::set_epoch_time(UnixDateTime ts)
|
|||
m_remaining_epoch_time_adjustment = {};
|
||||
}
|
||||
|
||||
Duration TimeManagement::monotonic_time(TimePrecision precision) const
|
||||
MonotonicTime TimeManagement::monotonic_time(TimePrecision precision) const
|
||||
{
|
||||
// This is the time when last updated by an interrupt.
|
||||
u64 seconds;
|
||||
|
@ -145,7 +145,7 @@ Duration TimeManagement::monotonic_time(TimePrecision precision) const
|
|||
VERIFY(ticks < m_time_ticks_per_second);
|
||||
u64 ns = ((u64)ticks * 1000000000ull) / m_time_ticks_per_second;
|
||||
VERIFY(ns < 1000000000ull);
|
||||
return Duration::from_timespec({ (i64)seconds, (i32)ns });
|
||||
return MonotonicTime::from_hardware_time({}, seconds, ns);
|
||||
}
|
||||
|
||||
UnixDateTime TimeManagement::epoch_time(TimePrecision) const
|
||||
|
@ -162,7 +162,7 @@ UnixDateTime TimeManagement::epoch_time(TimePrecision) const
|
|||
|
||||
u64 TimeManagement::uptime_ms() const
|
||||
{
|
||||
auto mtime = monotonic_time().to_timespec();
|
||||
auto mtime = monotonic_time().time_since_start({}).to_timespec();
|
||||
// This overflows after 292 million years of uptime.
|
||||
// Since this is only used for performance timestamps and sys$times, that's probably enough.
|
||||
u64 ms = mtime.tv_sec * 1000ull;
|
||||
|
@ -539,7 +539,7 @@ void TimeManagement::update_time_page()
|
|||
auto& page = time_page();
|
||||
u32 update_iteration = AK::atomic_fetch_add(&page.update2, 1u, AK::MemoryOrder::memory_order_acquire);
|
||||
page.clocks[CLOCK_REALTIME_COARSE] = m_epoch_time.to_timespec();
|
||||
page.clocks[CLOCK_MONOTONIC_COARSE] = monotonic_time(TimePrecision::Coarse).to_timespec();
|
||||
page.clocks[CLOCK_MONOTONIC_COARSE] = monotonic_time(TimePrecision::Coarse).time_since_start({}).to_timespec();
|
||||
AK::atomic_store(&page.update1, update_iteration + 1u, AK::MemoryOrder::memory_order_release);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,10 @@ public:
|
|||
static u64 scheduler_current_time();
|
||||
|
||||
static ErrorOr<void> validate_clock_id(clockid_t);
|
||||
// This API cannot distinguish returned time types; prefer the clock-specific functions instead.
|
||||
Duration current_time(clockid_t) const;
|
||||
Duration monotonic_time(TimePrecision = TimePrecision::Coarse) const;
|
||||
Duration monotonic_time_raw() const
|
||||
MonotonicTime monotonic_time(TimePrecision = TimePrecision::Coarse) const;
|
||||
MonotonicTime monotonic_time_raw() const
|
||||
{
|
||||
// TODO: implement
|
||||
return monotonic_time(TimePrecision::Precise);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue