mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
Kernel: Simplify the way we pass HardwareTimers around a bit
Instead of passing around indices into the m_hardware_timers vector, just pass around a HardwareTimer* instead.
This commit is contained in:
parent
b0b204822f
commit
44d58b85ef
2 changed files with 44 additions and 58 deletions
|
@ -41,9 +41,10 @@ namespace Kernel {
|
||||||
|
|
||||||
static TimeManagement* s_time_management;
|
static TimeManagement* s_time_management;
|
||||||
|
|
||||||
bool TimeManagement::initialized()
|
TimeManagement& TimeManagement::the()
|
||||||
{
|
{
|
||||||
return s_time_management != nullptr;
|
ASSERT(s_time_management);
|
||||||
|
return *s_time_management;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimeManagement::is_system_timer(const HardwareTimer& timer) const
|
bool TimeManagement::is_system_timer(const HardwareTimer& timer) const
|
||||||
|
@ -64,7 +65,7 @@ time_t TimeManagement::epoch_time() const
|
||||||
|
|
||||||
void TimeManagement::initialize()
|
void TimeManagement::initialize()
|
||||||
{
|
{
|
||||||
ASSERT(!TimeManagement::initialized());
|
ASSERT(!s_time_management);
|
||||||
if (kernel_command_line().lookup("time").value_or("modern") == "legacy")
|
if (kernel_command_line().lookup("time").value_or("modern") == "legacy")
|
||||||
s_time_management = new TimeManagement(false);
|
s_time_management = new TimeManagement(false);
|
||||||
else
|
else
|
||||||
|
@ -118,35 +119,30 @@ TimeManagement::TimeManagement(bool probe_non_legacy_hardware_timers)
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<size_t> TimeManagement::scan_and_initialize_periodic_timers()
|
Vector<HardwareTimer*> TimeManagement::scan_and_initialize_periodic_timers()
|
||||||
{
|
{
|
||||||
bool enable_periodic_mode = is_hpet_periodic_mode_allowed();
|
bool should_enable = is_hpet_periodic_mode_allowed();
|
||||||
dbg() << "Scanning for Periodic timers";
|
dbg() << "Time: Scanning for periodic timers";
|
||||||
Vector<size_t> periodic_timers_indexes;
|
Vector<HardwareTimer*> timers;
|
||||||
periodic_timers_indexes.ensure_capacity(m_hardware_timers.size());
|
for (auto& hardware_timer : m_hardware_timers) {
|
||||||
for (size_t index = 0; index < m_hardware_timers.size(); index++) {
|
if (hardware_timer && hardware_timer->is_periodic_capable()) {
|
||||||
if (!m_hardware_timers[index].is_null()) {
|
timers.append(hardware_timer);
|
||||||
if (m_hardware_timers[index]->is_periodic_capable()) {
|
if (should_enable)
|
||||||
periodic_timers_indexes.append(index);
|
hardware_timer->set_periodic();
|
||||||
if (enable_periodic_mode)
|
|
||||||
m_hardware_timers[index]->set_periodic();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return periodic_timers_indexes;
|
return timers;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<size_t> TimeManagement::scan_for_non_periodic_timers()
|
Vector<HardwareTimer*> TimeManagement::scan_for_non_periodic_timers()
|
||||||
{
|
{
|
||||||
dbg() << "Scanning for Non-Periodic timers";
|
dbg() << "Time: Scanning for non-periodic timers";
|
||||||
Vector<size_t> non_periodic_timers_indexes;
|
Vector<HardwareTimer*> timers;
|
||||||
non_periodic_timers_indexes.ensure_capacity(m_hardware_timers.size());
|
for (auto& hardware_timer : m_hardware_timers) {
|
||||||
for (size_t index = 0; index < m_hardware_timers.size(); index++) {
|
if (hardware_timer && !hardware_timer->is_periodic_capable())
|
||||||
if (!m_hardware_timers[index].is_null())
|
timers.append(hardware_timer);
|
||||||
if (!m_hardware_timers[index]->is_periodic_capable())
|
|
||||||
non_periodic_timers_indexes.append(index);
|
|
||||||
}
|
}
|
||||||
return non_periodic_timers_indexes;
|
return timers;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimeManagement::is_hpet_periodic_mode_allowed()
|
bool TimeManagement::is_hpet_periodic_mode_allowed()
|
||||||
|
@ -174,32 +170,27 @@ bool TimeManagement::probe_and_set_non_legacy_hardware_timers()
|
||||||
}
|
}
|
||||||
dbg() << "HPET: Setting appropriate functions to timers.";
|
dbg() << "HPET: Setting appropriate functions to timers.";
|
||||||
|
|
||||||
m_hardware_timers.resize(HPET::the().comparators().size());
|
for (auto& hpet_comparator : HPET::the().comparators())
|
||||||
for (size_t index = 0; index < m_hardware_timers.size(); index++) {
|
m_hardware_timers.append(hpet_comparator);
|
||||||
m_hardware_timers[index] = HPET::the().comparators()[index];
|
|
||||||
#ifdef TIME_DEBUG
|
|
||||||
dbg() << m_hardware_timers[index].ptr() << " <- " << HPET::the().comparators()[index].ptr();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
auto periodic_timer_indexes = scan_and_initialize_periodic_timers();
|
auto periodic_timers = scan_and_initialize_periodic_timers();
|
||||||
auto non_periodic_timer_indexes = scan_for_non_periodic_timers();
|
auto non_periodic_timers = scan_for_non_periodic_timers();
|
||||||
|
|
||||||
if (is_hpet_periodic_mode_allowed())
|
if (is_hpet_periodic_mode_allowed())
|
||||||
ASSERT(!periodic_timer_indexes.is_empty());
|
ASSERT(!periodic_timers.is_empty());
|
||||||
|
|
||||||
ASSERT(periodic_timer_indexes.size() + non_periodic_timer_indexes.size() >= 2);
|
ASSERT(periodic_timers.size() + non_periodic_timers.size() >= 2);
|
||||||
|
|
||||||
if (periodic_timer_indexes.size() >= 2) {
|
if (periodic_timers.size() >= 2) {
|
||||||
m_time_keeper_timer = m_hardware_timers[periodic_timer_indexes[1]];
|
m_time_keeper_timer = periodic_timers[1];
|
||||||
m_system_timer = m_hardware_timers[periodic_timer_indexes[0]];
|
m_system_timer = periodic_timers[0];
|
||||||
} else {
|
} else {
|
||||||
if (periodic_timer_indexes.size() == 1) {
|
if (periodic_timers.size() == 1) {
|
||||||
m_time_keeper_timer = m_hardware_timers[periodic_timer_indexes[0]];
|
m_time_keeper_timer = periodic_timers[0];
|
||||||
m_system_timer = m_hardware_timers[non_periodic_timer_indexes[0]];
|
m_system_timer = non_periodic_timers[0];
|
||||||
} else {
|
} else {
|
||||||
m_time_keeper_timer = m_hardware_timers[non_periodic_timer_indexes[1]];
|
m_time_keeper_timer = non_periodic_timers[1];
|
||||||
m_system_timer = m_hardware_timers[non_periodic_timer_indexes[0]];
|
m_system_timer = non_periodic_timers[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,19 +214,13 @@ bool TimeManagement::probe_and_set_legacy_hardware_timers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hardware_timers[0] = PIT::initialize([](const RegisterState& regs) { update_time(regs); });
|
m_hardware_timers.append(PIT::initialize([](const RegisterState& regs) { update_time(regs); }));
|
||||||
m_hardware_timers[1] = RealTimeClock::create([](const RegisterState& regs) { update_scheduler_ticks(regs); });
|
m_hardware_timers.append(RealTimeClock::create([](const RegisterState& regs) { update_scheduler_ticks(regs); }));
|
||||||
m_time_keeper_timer = m_hardware_timers[0];
|
m_time_keeper_timer = m_hardware_timers[0];
|
||||||
m_system_timer = m_hardware_timers[1];
|
m_system_timer = m_hardware_timers[1];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeManagement& TimeManagement::the()
|
|
||||||
{
|
|
||||||
ASSERT(TimeManagement::initialized());
|
|
||||||
return *s_time_management;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeManagement::update_time(const RegisterState& regs)
|
void TimeManagement::update_time(const RegisterState& regs)
|
||||||
{
|
{
|
||||||
TimeManagement::the().increment_time_since_boot(regs);
|
TimeManagement::the().increment_time_since_boot(regs);
|
||||||
|
|
|
@ -27,10 +27,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/FixedArray.h>
|
#include <AK/FixedArray.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/OwnPtr.h>
|
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/WeakPtr.h>
|
|
||||||
#include <Kernel/UnixTypes.h>
|
#include <Kernel/UnixTypes.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
@ -38,7 +36,10 @@ namespace Kernel {
|
||||||
#define OPTIMAL_TICKS_PER_SECOND_RATE 1000
|
#define OPTIMAL_TICKS_PER_SECOND_RATE 1000
|
||||||
|
|
||||||
class HardwareTimer;
|
class HardwareTimer;
|
||||||
|
|
||||||
class TimeManagement {
|
class TimeManagement {
|
||||||
|
AK_MAKE_ETERNAL;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool initialized();
|
static bool initialized();
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
@ -66,9 +67,9 @@ private:
|
||||||
explicit TimeManagement(bool probe_non_legacy_hardware_timers);
|
explicit TimeManagement(bool probe_non_legacy_hardware_timers);
|
||||||
bool probe_and_set_legacy_hardware_timers();
|
bool probe_and_set_legacy_hardware_timers();
|
||||||
bool probe_and_set_non_legacy_hardware_timers();
|
bool probe_and_set_non_legacy_hardware_timers();
|
||||||
Vector<size_t> scan_and_initialize_periodic_timers();
|
Vector<HardwareTimer*> scan_and_initialize_periodic_timers();
|
||||||
Vector<size_t> scan_for_non_periodic_timers();
|
Vector<HardwareTimer*> scan_for_non_periodic_timers();
|
||||||
FixedArray<RefPtr<HardwareTimer>> m_hardware_timers { 2 };
|
Vector<RefPtr<HardwareTimer>> m_hardware_timers;
|
||||||
|
|
||||||
u32 m_ticks_this_second { 0 };
|
u32 m_ticks_this_second { 0 };
|
||||||
u32 m_seconds_since_boot { 0 };
|
u32 m_seconds_since_boot { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue