Kernel: Add Timer::ns_since_boot()

This commit is contained in:
Bananymous 2023-10-12 21:16:39 +03:00
parent b723ed5fd2
commit 75fdf4c3c6
6 changed files with 20 additions and 0 deletions

View File

@ -12,6 +12,7 @@ namespace Kernel
static BAN::ErrorOr<BAN::UniqPtr<HPET>> create(bool force_pic); static BAN::ErrorOr<BAN::UniqPtr<HPET>> create(bool force_pic);
virtual uint64_t ms_since_boot() const override; virtual uint64_t ms_since_boot() const override;
virtual uint64_t ns_since_boot() const override;
virtual timespec time_since_boot() const override; virtual timespec time_since_boot() const override;
virtual void handle_irq() override; virtual void handle_irq() override;

View File

@ -12,6 +12,7 @@ namespace Kernel
static BAN::ErrorOr<BAN::UniqPtr<PIT>> create(); static BAN::ErrorOr<BAN::UniqPtr<PIT>> create();
virtual uint64_t ms_since_boot() const override; virtual uint64_t ms_since_boot() const override;
virtual uint64_t ns_since_boot() const override;
virtual timespec time_since_boot() const override; virtual timespec time_since_boot() const override;
virtual void handle_irq() override; virtual void handle_irq() override;

View File

@ -14,6 +14,7 @@ namespace Kernel
public: public:
virtual ~Timer() {}; virtual ~Timer() {};
virtual uint64_t ms_since_boot() const = 0; virtual uint64_t ms_since_boot() const = 0;
virtual uint64_t ns_since_boot() const = 0;
virtual timespec time_since_boot() const = 0; virtual timespec time_since_boot() const = 0;
}; };
@ -25,6 +26,7 @@ namespace Kernel
static bool is_initialized(); static bool is_initialized();
virtual uint64_t ms_since_boot() const override; virtual uint64_t ms_since_boot() const override;
virtual uint64_t ns_since_boot() const override;
virtual timespec time_since_boot() const override; virtual timespec time_since_boot() const override;
void sleep(uint64_t ms) const; void sleep(uint64_t ms) const;

View File

@ -148,6 +148,12 @@ namespace Kernel
return read_register(HPET_REG_COUNTER) * m_counter_tick_period_fs / FS_PER_MS; return read_register(HPET_REG_COUNTER) * m_counter_tick_period_fs / FS_PER_MS;
} }
uint64_t HPET::ns_since_boot() const
{
// FIXME: 32 bit CPUs should use 32 bit counter with 32 bit reads
return read_register(HPET_REG_COUNTER) * m_counter_tick_period_fs / FS_PER_NS;
}
timespec HPET::time_since_boot() const timespec HPET::time_since_boot() const
{ {
uint64_t time_fs = read_register(HPET_REG_COUNTER) * m_counter_tick_period_fs; uint64_t time_fs = read_register(HPET_REG_COUNTER) * m_counter_tick_period_fs;

View File

@ -62,6 +62,11 @@ namespace Kernel
return m_system_time * (MS_PER_S / TICKS_PER_SECOND); return m_system_time * (MS_PER_S / TICKS_PER_SECOND);
} }
uint64_t PIT::ns_since_boot() const
{
return m_system_time * (NS_PER_S / TICKS_PER_SECOND);
}
timespec PIT::time_since_boot() const timespec PIT::time_since_boot() const
{ {
uint64_t ticks = m_system_time; uint64_t ticks = m_system_time;

View File

@ -59,6 +59,11 @@ namespace Kernel
return m_timer->ms_since_boot(); return m_timer->ms_since_boot();
} }
uint64_t SystemTimer::ns_since_boot() const
{
return m_timer->ns_since_boot();
}
timespec SystemTimer::time_since_boot() const timespec SystemTimer::time_since_boot() const
{ {
return m_timer->time_since_boot(); return m_timer->time_since_boot();