1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:27:43 +00:00

AK: Rename Time to Duration

That's what this class really is; in fact that's what the first line of
the comment says it is.

This commit does not rename the main files, since those will contain
other time-related classes in a little bit.
This commit is contained in:
kleines Filmröllchen 2023-03-13 16:30:34 +01:00 committed by Jelle Raaijmakers
parent 82ddc813d5
commit 213025f210
140 changed files with 634 additions and 628 deletions

View file

@ -77,7 +77,7 @@ ErrorOr<void> TimeManagement::validate_clock_id(clockid_t clock_id)
};
}
Time TimeManagement::current_time(clockid_t clock_id) const
Duration TimeManagement::current_time(clockid_t clock_id) const
{
switch (clock_id) {
case CLOCK_MONOTONIC:
@ -101,15 +101,15 @@ bool TimeManagement::is_system_timer(HardwareTimerBase const& timer) const
return &timer == m_system_timer.ptr();
}
void TimeManagement::set_epoch_time(Time ts)
void TimeManagement::set_epoch_time(Duration ts)
{
InterruptDisabler disabler;
// FIXME: Should use AK::Time internally
// FIXME: Should use AK::Duration internally
m_epoch_time = ts.to_timespec();
m_remaining_epoch_time_adjustment = { 0, 0 };
}
Time TimeManagement::monotonic_time(TimePrecision precision) const
Duration TimeManagement::monotonic_time(TimePrecision precision) const
{
// This is the time when last updated by an interrupt.
u64 seconds;
@ -144,10 +144,10 @@ Time 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 Time::from_timespec({ (i64)seconds, (i32)ns });
return Duration::from_timespec({ (i64)seconds, (i32)ns });
}
Time TimeManagement::epoch_time(TimePrecision) const
Duration TimeManagement::epoch_time(TimePrecision) const
{
// TODO: Take into account precision
timespec ts;
@ -156,7 +156,7 @@ Time TimeManagement::epoch_time(TimePrecision) const
update_iteration = m_update1.load(AK::MemoryOrder::memory_order_acquire);
ts = m_epoch_time;
} while (update_iteration != m_update2.load(AK::MemoryOrder::memory_order_acquire));
return Time::from_timespec(ts);
return Duration::from_timespec(ts);
}
u64 TimeManagement::uptime_ms() const
@ -186,14 +186,14 @@ UNMAP_AFTER_INIT void TimeManagement::initialize([[maybe_unused]] u32 cpu)
// would trigger a deadlock trying to get the s_the instance while
// creating it.
if (auto* apic_timer = APIC::the().initialize_timers(*s_the->m_system_timer)) {
dmesgln("Time: Using APIC timer as system timer");
dmesgln("Duration: Using APIC timer as system timer");
s_the->set_system_timer(*apic_timer);
}
}
} else {
VERIFY(s_the.is_initialized());
if (auto* apic_timer = APIC::the().get_timer()) {
dmesgln("Time: Enable APIC timer on CPU #{}", cpu);
dmesgln("Duration: Enable APIC timer on CPU #{}", cpu);
apic_timer->enable_local_timer();
}
}
@ -226,26 +226,26 @@ time_t TimeManagement::ticks_per_second() const
return m_time_keeper_timer->ticks_per_second();
}
Time TimeManagement::boot_time()
Duration TimeManagement::boot_time()
{
#if ARCH(X86_64)
return RTC::boot_time();
#elif ARCH(AARCH64)
// FIXME: Return correct boot time
return Time::from_seconds(0);
return Duration::from_seconds(0);
#else
# error Unknown architecture
#endif
}
Time TimeManagement::clock_resolution() const
Duration 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);
return Duration::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())
: m_time_page_region(MM.allocate_kernel_region(PAGE_SIZE, "Duration page"sv, Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow).release_value_but_fixme_should_propagate_errors())
{
#if ARCH(X86_64)
bool probe_non_legacy_hardware_timers = !(kernel_command_line().is_legacy_time_enabled());
@ -275,7 +275,7 @@ UNMAP_AFTER_INIT TimeManagement::TimeManagement()
#endif
}
Time TimeManagement::now()
Duration TimeManagement::now()
{
return s_the.ptr()->epoch_time();
}
@ -283,7 +283,7 @@ Time TimeManagement::now()
UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_and_initialize_periodic_timers()
{
bool should_enable = is_hpet_periodic_mode_allowed();
dbgln("Time: Scanning for periodic timers");
dbgln("Duration: Scanning for periodic timers");
Vector<HardwareTimerBase*> timers;
for (auto& hardware_timer : m_hardware_timers) {
if (hardware_timer->is_periodic_capable()) {
@ -297,7 +297,7 @@ UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_and_initialize_
UNMAP_AFTER_INIT Vector<HardwareTimerBase*> TimeManagement::scan_for_non_periodic_timers()
{
dbgln("Time: Scanning for non-periodic timers");
dbgln("Duration: Scanning for non-periodic timers");
Vector<HardwareTimerBase*> timers;
for (auto& hardware_timer : m_hardware_timers) {
if (!hardware_timer->is_periodic_capable())

View file

@ -41,18 +41,18 @@ public:
static u64 scheduler_current_time();
static ErrorOr<void> validate_clock_id(clockid_t);
Time current_time(clockid_t) const;
Time monotonic_time(TimePrecision = TimePrecision::Coarse) const;
Time monotonic_time_raw() const
Duration current_time(clockid_t) const;
Duration monotonic_time(TimePrecision = TimePrecision::Coarse) const;
Duration monotonic_time_raw() const
{
// TODO: implement
return monotonic_time(TimePrecision::Precise);
}
Time epoch_time(TimePrecision = TimePrecision::Precise) const;
void set_epoch_time(Time);
Duration epoch_time(TimePrecision = TimePrecision::Precise) const;
void set_epoch_time(Duration);
time_t ticks_per_second() const;
static Time boot_time();
Time clock_resolution() const;
static Duration boot_time();
Duration clock_resolution() const;
bool is_system_timer(HardwareTimerBase const&) const;
@ -64,12 +64,12 @@ public:
bool disable_profile_timer();
u64 uptime_ms() const;
static Time now();
static Duration now();
// FIXME: Should use AK::Time internally
// FIXME: Should use AK::Duration internally
// FIXME: Also, most likely broken, because it does not check m_update[12] for in-progress updates.
timespec remaining_epoch_time_adjustment() const { return m_remaining_epoch_time_adjustment; }
// FIXME: Should use AK::Time internally
// FIXME: Should use AK::Duration internally
// FIXME: Also, most likely broken, because it does not check m_update[12] for in-progress updates.
void set_remaining_epoch_time_adjustment(timespec const& adjustment) { m_remaining_epoch_time_adjustment = adjustment; }
@ -102,7 +102,7 @@ private:
Atomic<u32> m_update1 { 0 };
u32 m_ticks_this_second { 0 };
u64 m_seconds_since_boot { 0 };
// FIXME: Should use AK::Time internally
// FIXME: Should use AK::Duration internally
timespec m_epoch_time { 0, 0 };
timespec m_remaining_epoch_time_adjustment { 0, 0 };
Atomic<u32> m_update2 { 0 };