forked from Bananymous/banan-os
Kernel: Rename TimerHandler to SystemTimer
I changed SystemTimer to only handle the "best" supported timer it can initialize.
This commit is contained in:
parent
17f1737c9a
commit
bc0e1fa898
|
@ -15,11 +15,11 @@ namespace Kernel
|
|||
virtual timespec time_since_boot() const = 0;
|
||||
};
|
||||
|
||||
class TimerHandler : public Timer
|
||||
class SystemTimer : public Timer
|
||||
{
|
||||
public:
|
||||
static void initialize();
|
||||
static TimerHandler& get();
|
||||
static SystemTimer& get();
|
||||
static bool is_initialized();
|
||||
|
||||
virtual uint64_t ms_since_boot() const override;
|
||||
|
@ -27,10 +27,10 @@ namespace Kernel
|
|||
|
||||
void sleep(uint64_t) const;
|
||||
|
||||
uint64_t get_unix_timestamp();
|
||||
uint64_t get_unix_timestamp() const;
|
||||
|
||||
private:
|
||||
TimerHandler() = default;
|
||||
SystemTimer() = default;
|
||||
|
||||
void initialize_timers();
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace Debug
|
|||
|
||||
void print_prefix(const char* file, int line)
|
||||
{
|
||||
auto ms_since_boot = Kernel::TimerHandler::is_initialized() ? Kernel::TimerHandler::get().ms_since_boot() : 0;
|
||||
auto ms_since_boot = Kernel::SystemTimer::is_initialized() ? Kernel::SystemTimer::get().ms_since_boot() : 0;
|
||||
BAN::Formatter::print(Debug::putchar, "[{5}.{3}] {}:{}: ", ms_since_boot / 1000, ms_since_boot % 1000, file, line);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Kernel
|
|||
);
|
||||
s_instance->m_device_lock.unlock();
|
||||
|
||||
Kernel::TimerHandler::get().sleep(1);
|
||||
Kernel::SystemTimer::get().sleep(1);
|
||||
}
|
||||
}, nullptr
|
||||
);
|
||||
|
|
|
@ -384,7 +384,7 @@ namespace Kernel
|
|||
if (error_or.error().get_error_code() != ENOENT)
|
||||
return error_or.error();
|
||||
|
||||
uint64_t current_time = TimerHandler::get().get_unix_timestamp();
|
||||
uint64_t current_time = SystemTimer::get().get_unix_timestamp();
|
||||
|
||||
Ext2::Inode ext2_inode;
|
||||
ext2_inode.mode = mode;
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Kernel
|
|||
: m_uid(credentials.euid())
|
||||
, m_gid(credentials.egid())
|
||||
{
|
||||
uint64_t current_time = TimerHandler::get().get_unix_timestamp();
|
||||
uint64_t current_time = SystemTimer::get().get_unix_timestamp();
|
||||
m_atime = { .tv_sec = current_time, .tv_nsec = 0 };
|
||||
m_mtime = { .tv_sec = current_time, .tv_nsec = 0 };
|
||||
m_ctime = { .tv_sec = current_time, .tv_nsec = 0 };
|
||||
|
@ -57,7 +57,7 @@ namespace Kernel
|
|||
memmove(m_buffer.data(), m_buffer.data() + to_copy, m_buffer.size() - to_copy);
|
||||
MUST(m_buffer.resize(m_buffer.size() - to_copy));
|
||||
|
||||
uint64_t current_time = TimerHandler::get().get_unix_timestamp();
|
||||
uint64_t current_time = SystemTimer::get().get_unix_timestamp();
|
||||
m_atime = { .tv_sec = current_time, .tv_nsec = 0 };
|
||||
|
||||
m_semaphore.unblock();
|
||||
|
@ -76,7 +76,7 @@ namespace Kernel
|
|||
TRY(m_buffer.resize(old_size + count));
|
||||
memcpy(m_buffer.data() + old_size, buffer, count);
|
||||
|
||||
uint64_t current_time = TimerHandler::get().get_unix_timestamp();
|
||||
uint64_t current_time = SystemTimer::get().get_unix_timestamp();
|
||||
m_mtime = { .tv_sec = current_time, .tv_nsec = 0 };
|
||||
m_ctime = { .tv_sec = current_time, .tv_nsec = 0 };
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Kernel
|
|||
RamInode::RamInode(RamFileSystem& fs, mode_t mode, uid_t uid, gid_t gid)
|
||||
: m_fs(fs)
|
||||
{
|
||||
uint64_t current_unix_time = TimerHandler::get().get_unix_timestamp();
|
||||
uint64_t current_unix_time = SystemTimer::get().get_unix_timestamp();
|
||||
timespec current_timespec;
|
||||
current_timespec.tv_sec = current_unix_time;
|
||||
current_timespec.tv_nsec = 0;
|
||||
|
|
|
@ -108,8 +108,8 @@ namespace Kernel::Input
|
|||
{
|
||||
if (device == 1)
|
||||
IO::outb(PS2::IOPort::COMMAND, PS2::Command::WRITE_TO_SECOND_PORT);
|
||||
uint64_t timeout = TimerHandler::get().ms_since_boot() + s_device_timeout_ms;
|
||||
while (TimerHandler::get().ms_since_boot() < timeout)
|
||||
uint64_t timeout = SystemTimer::get().ms_since_boot() + s_device_timeout_ms;
|
||||
while (SystemTimer::get().ms_since_boot() < timeout)
|
||||
{
|
||||
if (!(IO::inb(PS2::IOPort::STATUS) & PS2::Status::INPUT_FULL))
|
||||
{
|
||||
|
@ -122,8 +122,8 @@ namespace Kernel::Input
|
|||
|
||||
static BAN::ErrorOr<uint8_t> device_read_byte()
|
||||
{
|
||||
uint64_t timeout = TimerHandler::get().ms_since_boot() + s_device_timeout_ms;
|
||||
while (TimerHandler::get().ms_since_boot() < timeout)
|
||||
uint64_t timeout = SystemTimer::get().ms_since_boot() + s_device_timeout_ms;
|
||||
while (SystemTimer::get().ms_since_boot() < timeout)
|
||||
if (IO::inb(PS2::IOPort::STATUS) & PS2::Status::OUTPUT_FULL)
|
||||
return IO::inb(PS2::IOPort::DATA);
|
||||
return BAN::Error::from_error_code(ErrorCode::PS2_Timeout);
|
||||
|
|
|
@ -216,7 +216,7 @@ namespace Kernel::Input
|
|||
|
||||
if (event.pressed() && event.key == Input::Key::F11)
|
||||
{
|
||||
auto time = TimerHandler::get().time_since_boot();
|
||||
auto time = SystemTimer::get().time_since_boot();
|
||||
dprintln("{}.{9} s", time.tv_sec, time.tv_nsec);
|
||||
}
|
||||
|
||||
|
|
|
@ -473,7 +473,7 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<long> Process::sys_sleep(int seconds)
|
||||
{
|
||||
TimerHandler::get().sleep(seconds * 1000);
|
||||
SystemTimer::get().sleep(seconds * 1000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -811,7 +811,7 @@ namespace Kernel
|
|||
{
|
||||
case CLOCK_MONOTONIC:
|
||||
{
|
||||
uint64_t time_ms = TimerHandler::get().ms_since_boot();
|
||||
uint64_t time_ms = SystemTimer::get().ms_since_boot();
|
||||
tp->tv_sec = time_ms / 1000;
|
||||
tp->tv_nsec = (time_ms % 1000) * 1000000;
|
||||
break;
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace Kernel
|
|||
{
|
||||
VERIFY_CLI();
|
||||
|
||||
uint64_t current_time = TimerHandler::get().ms_since_boot();
|
||||
uint64_t current_time = SystemTimer::get().ms_since_boot();
|
||||
while (!m_sleeping_threads.empty() && m_sleeping_threads.front().wake_time <= current_time)
|
||||
{
|
||||
Thread* thread = m_sleeping_threads.front().thread;
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace Kernel
|
|||
{
|
||||
uint8_t device_index = this->device_index(device);
|
||||
io_write(ATA_PORT_DRIVE_SELECT, 0xA0 | (device_index << 4));
|
||||
TimerHandler::get().sleep(1);
|
||||
SystemTimer::get().sleep(1);
|
||||
}
|
||||
|
||||
ATABus::DeviceType ATABus::identify(const ATADevice& device, uint16_t* buffer)
|
||||
|
@ -111,7 +111,7 @@ namespace Kernel
|
|||
io_write(ATA_PORT_CONTROL, ATA_CONTROL_nIEN);
|
||||
|
||||
io_write(ATA_PORT_COMMAND, ATA_COMMAND_IDENTIFY);
|
||||
TimerHandler::get().sleep(1);
|
||||
SystemTimer::get().sleep(1);
|
||||
|
||||
// No device on port
|
||||
if (io_read(ATA_PORT_STATUS) == 0)
|
||||
|
@ -135,7 +135,7 @@ namespace Kernel
|
|||
}
|
||||
|
||||
io_write(ATA_PORT_COMMAND, ATA_COMMAND_IDENTIFY_PACKET);
|
||||
TimerHandler::get().sleep(1);
|
||||
SystemTimer::get().sleep(1);
|
||||
|
||||
if (auto res = wait(true); res.is_error())
|
||||
{
|
||||
|
@ -304,7 +304,7 @@ namespace Kernel
|
|||
io_write(ATA_PORT_LBA2, (uint8_t)(lba >> 16));
|
||||
io_write(ATA_PORT_COMMAND, ATA_COMMAND_WRITE_SECTORS);
|
||||
|
||||
TimerHandler::get().sleep(1);
|
||||
SystemTimer::get().sleep(1);
|
||||
|
||||
for (uint32_t sector = 0; sector < sector_count; sector++)
|
||||
{
|
||||
|
|
|
@ -6,29 +6,29 @@
|
|||
namespace Kernel
|
||||
{
|
||||
|
||||
static TimerHandler* s_instance = nullptr;
|
||||
static SystemTimer* s_instance = nullptr;
|
||||
|
||||
void TimerHandler::initialize()
|
||||
void SystemTimer::initialize()
|
||||
{
|
||||
ASSERT(s_instance == nullptr);
|
||||
auto* temp = new TimerHandler;
|
||||
auto* temp = new SystemTimer;
|
||||
ASSERT(temp);
|
||||
temp->initialize_timers();
|
||||
s_instance = temp;
|
||||
}
|
||||
|
||||
TimerHandler& TimerHandler::get()
|
||||
SystemTimer& SystemTimer::get()
|
||||
{
|
||||
ASSERT(s_instance);
|
||||
return *s_instance;
|
||||
}
|
||||
|
||||
bool TimerHandler::is_initialized()
|
||||
bool SystemTimer::is_initialized()
|
||||
{
|
||||
return !!s_instance;
|
||||
}
|
||||
|
||||
void TimerHandler::initialize_timers()
|
||||
void SystemTimer::initialize_timers()
|
||||
{
|
||||
m_rtc = MUST(BAN::UniqPtr<RTC>::create());
|
||||
m_boot_time = BAN::to_unix_time(m_rtc->get_current_time());
|
||||
|
@ -54,17 +54,17 @@ namespace Kernel
|
|||
Kernel::panic("Could not initialize any timer");
|
||||
}
|
||||
|
||||
uint64_t TimerHandler::ms_since_boot() const
|
||||
uint64_t SystemTimer::ms_since_boot() const
|
||||
{
|
||||
return m_timer->ms_since_boot();
|
||||
}
|
||||
|
||||
timespec TimerHandler::time_since_boot() const
|
||||
timespec SystemTimer::time_since_boot() const
|
||||
{
|
||||
return m_timer->time_since_boot();
|
||||
}
|
||||
|
||||
void TimerHandler::sleep(uint64_t ms) const
|
||||
void SystemTimer::sleep(uint64_t ms) const
|
||||
{
|
||||
if (ms == 0)
|
||||
return;
|
||||
|
@ -74,7 +74,7 @@ namespace Kernel
|
|||
dwarnln("sleep woke {} ms too soon", wake_time - ms_since_boot());
|
||||
}
|
||||
|
||||
uint64_t TimerHandler::get_unix_timestamp()
|
||||
uint64_t SystemTimer::get_unix_timestamp() const
|
||||
{
|
||||
return m_boot_time + ms_since_boot() / 1000;
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ extern "C" void kernel_main()
|
|||
InterruptController::initialize(cmdline.force_pic);
|
||||
dprintln("Interrupt controller initialized");
|
||||
|
||||
TimerHandler::initialize();
|
||||
SystemTimer::initialize();
|
||||
dprintln("Timers initialized");
|
||||
|
||||
DevFileSystem::initialize();
|
||||
|
|
Loading…
Reference in New Issue