summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2023-03-17 19:50:39 +0100
committerJelle Raaijmakers <jelle@gmta.nl>2023-05-24 23:18:07 +0200
commitfc5cab5c2180b4ba8efcf74b937c2b7e26dad781 (patch)
tree59cdd3836d2db037551e7e970d7b64e970814404 /Kernel
parentb2e7b8cdffa2297b335698677f5c0434dbf92e75 (diff)
downloadserenity-fc5cab5c2180b4ba8efcf74b937c2b7e26dad781.zip
Everywhere: Use MonotonicTime instead of Duration
This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Devices/Audio/IntelHDA/Controller.cpp6
-rw-r--r--Kernel/Storage/SD/SDHostController.cpp6
-rw-r--r--Kernel/Time/TimeManagement.cpp16
-rw-r--r--Kernel/Time/TimeManagement.h5
4 files changed, 17 insertions, 16 deletions
diff --git a/Kernel/Devices/Audio/IntelHDA/Controller.cpp b/Kernel/Devices/Audio/IntelHDA/Controller.cpp
index cae6b6800b..74c8498f5a 100644
--- a/Kernel/Devices/Audio/IntelHDA/Controller.cpp
+++ b/Kernel/Devices/Audio/IntelHDA/Controller.cpp
@@ -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 {};
diff --git a/Kernel/Storage/SD/SDHostController.cpp b/Kernel/Storage/SD/SDHostController.cpp
index e65145d84b..b21acdabb1 100644
--- a/Kernel/Storage/SD/SDHostController.cpp
+++ b/Kernel/Storage/SD/SDHostController.cpp
@@ -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();
}
diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp
index d7c3c18716..aea122a818 100644
--- a/Kernel/Time/TimeManagement.cpp
+++ b/Kernel/Time/TimeManagement.cpp
@@ -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);
}
diff --git a/Kernel/Time/TimeManagement.h b/Kernel/Time/TimeManagement.h
index 278852c5be..642298e1b0 100644
--- a/Kernel/Time/TimeManagement.h
+++ b/Kernel/Time/TimeManagement.h
@@ -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);