mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-04 15:09:40 +00:00
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.
This commit is contained in:
parent
3c7a0ef1ac
commit
f6eb155167
|
@ -98,16 +98,11 @@ ErrorOr<FlatPtr> Process::sys$clock_getres(Userspace<Syscall::SC_clock_getres_pa
|
||||||
{
|
{
|
||||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||||
auto params = TRY(copy_typed_from_user(user_params));
|
auto params = TRY(copy_typed_from_user(user_params));
|
||||||
timespec ts {};
|
|
||||||
switch (params.clock_id) {
|
TRY(TimeManagement::validate_clock_id(params.clock_id));
|
||||||
case CLOCK_REALTIME:
|
|
||||||
ts.tv_sec = 0;
|
auto ts = TimeManagement::the().clock_resolution().to_timespec();
|
||||||
ts.tv_nsec = 1000000000 / _SC_CLK_TCK;
|
TRY(copy_to_user(params.result, &ts));
|
||||||
TRY(copy_to_user(params.result, &ts));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -237,6 +237,12 @@ Time TimeManagement::boot_time()
|
||||||
#endif
|
#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()
|
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())
|
: 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())
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
void set_epoch_time(Time);
|
void set_epoch_time(Time);
|
||||||
time_t ticks_per_second() const;
|
time_t ticks_per_second() const;
|
||||||
static Time boot_time();
|
static Time boot_time();
|
||||||
|
Time clock_resolution() const;
|
||||||
|
|
||||||
bool is_system_timer(HardwareTimerBase const&) const;
|
bool is_system_timer(HardwareTimerBase const&) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue