From c040e64b7d231fc374e99882751c58f50e116339 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sat, 27 Feb 2021 23:56:16 +0100 Subject: [PATCH] Kernel: Make TimeManagement use AK::Time internally I don't dare touch the multi-threading logic and locking mechanism, so it stays timespec for now. However, this could and should be changed to AK::Time, and I bet it will simplify the "increment_time_since_boot()" code. --- Kernel/Process.cpp | 2 +- Kernel/Process.h | 1 + Kernel/Syscalls/alarm.cpp | 3 +-- Kernel/Syscalls/clock.cpp | 12 ++++++------ Kernel/ThreadBlockers.cpp | 6 ++---- Kernel/Time/TimeManagement.cpp | 26 +++++++++++++------------- Kernel/Time/TimeManagement.h | 18 ++++++++++++------ Kernel/TimerQueue.cpp | 9 +++------ 8 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index ec26de63af..8bace0d8f2 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -383,7 +383,7 @@ int Process::alloc_fd(int first_candidate_fd) timeval kgettimeofday() { - return TimeManagement::now_as_timeval(); + return TimeManagement::now().to_timeval(); } void kgettimeofday(timeval& tv) diff --git a/Kernel/Process.h b/Kernel/Process.h index 31aba2b744..f2bef271ed 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -54,6 +54,7 @@ namespace Kernel { +// FIXME: Should use AK::Time internally timeval kgettimeofday(); void kgettimeofday(timeval&); diff --git a/Kernel/Syscalls/alarm.cpp b/Kernel/Syscalls/alarm.cpp index ff3de1350c..18104863ed 100644 --- a/Kernel/Syscalls/alarm.cpp +++ b/Kernel/Syscalls/alarm.cpp @@ -45,8 +45,7 @@ KResultOr Process::sys$alarm(unsigned seconds) } if (seconds > 0) { - // FIXME: Should use AK::Time internally - auto deadline = Time::from_timespec(TimeManagement::the().current_time(CLOCK_REALTIME_COARSE).value()); + auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE).value(); deadline = deadline + Time::from_seconds(seconds); m_alarm_timer = TimerQueue::the().add_timer_without_id(CLOCK_REALTIME_COARSE, deadline, [this]() { [[maybe_unused]] auto rc = send_signal(SIGALRM, nullptr); diff --git a/Kernel/Syscalls/clock.cpp b/Kernel/Syscalls/clock.cpp index d883e6ac04..5296644141 100644 --- a/Kernel/Syscalls/clock.cpp +++ b/Kernel/Syscalls/clock.cpp @@ -34,11 +34,12 @@ KResultOr Process::sys$clock_gettime(clockid_t clock_id, Userspace Process::sys$clock_settime(clockid_t clock_id, Userspaceto_timespec()); + TimeManagement::the().set_epoch_time(ts.value()); break; default: return EINVAL; diff --git a/Kernel/ThreadBlockers.cpp b/Kernel/ThreadBlockers.cpp index 158dee8862..3def0b7b3d 100644 --- a/Kernel/ThreadBlockers.cpp +++ b/Kernel/ThreadBlockers.cpp @@ -42,8 +42,7 @@ Thread::BlockTimeout::BlockTimeout(bool is_absolute, const Time* time, const Tim m_time = *time; m_should_block = true; } - // FIXME: Should use AK::Time internally - m_start_time = start_time ? *start_time : Time::from_timespec(TimeManagement::the().current_time(clock_id).value()); + m_start_time = start_time ? *start_time : TimeManagement::the().current_time(clock_id).value(); if (!is_absolute) m_time = m_time + m_start_time; } @@ -349,8 +348,7 @@ void Thread::SleepBlocker::calculate_remaining() { if (!m_remaining) return; - // FIXME: Should use AK::Time internally - auto time_now = Time::from_timespec(TimeManagement::the().current_time(m_deadline.clock_id()).value()); + auto time_now = TimeManagement::the().current_time(m_deadline.clock_id()).value(); if (time_now < m_deadline.absolute_time()) *m_remaining = m_deadline.absolute_time() - time_now; else diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp index ee4515091f..01efc7c371 100644 --- a/Kernel/Time/TimeManagement.cpp +++ b/Kernel/Time/TimeManagement.cpp @@ -64,7 +64,7 @@ bool TimeManagement::is_valid_clock_id(clockid_t clock_id) }; } -KResultOr TimeManagement::current_time(clockid_t clock_id) const +KResultOr