summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorHumberto Alves <hjalves@live.com>2023-02-20 21:06:29 +0000
committerAndreas Kling <kling@serenityos.org>2023-02-21 01:00:06 +0100
commitf6eb155167e8bca9fba9cddb88b39ab7b049ff5d (patch)
tree47ee0ecc7c72466f2e5147facc20910190b0a31b /Kernel
parent3c7a0ef1ac279c99bc4ee72085278ea70c210889 (diff)
downloadserenity-f6eb155167e8bca9fba9cddb88b39ab7b049ff5d.zip
Kernel: Support more clocks in sys$clock_getres()
Support all the available clocks in clock_getres(). Also, fix this function to use the actual ticks per second value, not the constant `_SC_CLK_TCK` (which is always equal to 8) and move the resolution computation logic to TimeManagement.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Syscalls/clock.cpp15
-rw-r--r--Kernel/Time/TimeManagement.cpp6
-rw-r--r--Kernel/Time/TimeManagement.h1
3 files changed, 12 insertions, 10 deletions
diff --git a/Kernel/Syscalls/clock.cpp b/Kernel/Syscalls/clock.cpp
index 0f0f5d4d7e..8dc4571e71 100644
--- a/Kernel/Syscalls/clock.cpp
+++ b/Kernel/Syscalls/clock.cpp
@@ -98,16 +98,11 @@ ErrorOr<FlatPtr> Process::sys$clock_getres(Userspace<Syscall::SC_clock_getres_pa
{
VERIFY_NO_PROCESS_BIG_LOCK(this);
auto params = TRY(copy_typed_from_user(user_params));
- timespec ts {};
- switch (params.clock_id) {
- case CLOCK_REALTIME:
- ts.tv_sec = 0;
- ts.tv_nsec = 1000000000 / _SC_CLK_TCK;
- TRY(copy_to_user(params.result, &ts));
- break;
- default:
- return EINVAL;
- }
+
+ TRY(TimeManagement::validate_clock_id(params.clock_id));
+
+ auto ts = TimeManagement::the().clock_resolution().to_timespec();
+ TRY(copy_to_user(params.result, &ts));
return 0;
}
diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp
index e58b063b46..e11eb47226 100644
--- a/Kernel/Time/TimeManagement.cpp
+++ b/Kernel/Time/TimeManagement.cpp
@@ -237,6 +237,12 @@ Time TimeManagement::boot_time()
#endif
}
+Time TimeManagement::clock_resolution() const
+{
+ long nanoseconds_per_tick = 1'000'000'000 / m_time_keeper_timer->ticks_per_second();
+ return Time::from_nanoseconds(nanoseconds_per_tick);
+}
+
UNMAP_AFTER_INIT TimeManagement::TimeManagement()
: m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Time page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
{
diff --git a/Kernel/Time/TimeManagement.h b/Kernel/Time/TimeManagement.h
index c0371c6d35..4346f16925 100644
--- a/Kernel/Time/TimeManagement.h
+++ b/Kernel/Time/TimeManagement.h
@@ -52,6 +52,7 @@ public:
void set_epoch_time(Time);
time_t ticks_per_second() const;
static Time boot_time();
+ Time clock_resolution() const;
bool is_system_timer(HardwareTimerBase const&) const;