forked from Bananymous/banan-os
Kernel: Add Timer::ns_since_boot()
This commit is contained in:
parent
790064d248
commit
f4b901a646
|
@ -12,6 +12,7 @@ namespace Kernel
|
|||
static BAN::ErrorOr<BAN::UniqPtr<HPET>> create(bool force_pic);
|
||||
|
||||
virtual uint64_t ms_since_boot() const override;
|
||||
virtual uint64_t ns_since_boot() const override;
|
||||
virtual timespec time_since_boot() const override;
|
||||
|
||||
virtual void handle_irq() override;
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Kernel
|
|||
static BAN::ErrorOr<BAN::UniqPtr<PIT>> create();
|
||||
|
||||
virtual uint64_t ms_since_boot() const override;
|
||||
virtual uint64_t ns_since_boot() const override;
|
||||
virtual timespec time_since_boot() const override;
|
||||
|
||||
virtual void handle_irq() override;
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Kernel
|
|||
public:
|
||||
virtual ~Timer() {};
|
||||
virtual uint64_t ms_since_boot() const = 0;
|
||||
virtual uint64_t ns_since_boot() const = 0;
|
||||
virtual timespec time_since_boot() const = 0;
|
||||
};
|
||||
|
||||
|
@ -25,6 +26,7 @@ namespace Kernel
|
|||
static bool is_initialized();
|
||||
|
||||
virtual uint64_t ms_since_boot() const override;
|
||||
virtual uint64_t ns_since_boot() const override;
|
||||
virtual timespec time_since_boot() const override;
|
||||
|
||||
void sleep(uint64_t ms) const;
|
||||
|
|
|
@ -148,6 +148,12 @@ namespace Kernel
|
|||
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
|
||||
{
|
||||
uint64_t time_fs = read_register(HPET_REG_COUNTER) * m_counter_tick_period_fs;
|
||||
|
|
|
@ -62,6 +62,11 @@ namespace Kernel
|
|||
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
|
||||
{
|
||||
uint64_t ticks = m_system_time;
|
||||
|
|
|
@ -59,6 +59,11 @@ namespace Kernel
|
|||
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
|
||||
{
|
||||
return m_timer->time_since_boot();
|
||||
|
|
Loading…
Reference in New Issue