[kernel] Add HPET support, create clock class

Create a clock class which can be queried for current timestamp in
nanoseconds. Also implements a simple HPET class as one possible clock
source.

Tags: time
This commit is contained in:
Justin C. Miller
2020-06-28 17:47:46 -07:00
parent 9b67f87062
commit 6c468a134b
13 changed files with 347 additions and 36 deletions

22
src/kernel/clock.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include "clock.h"
clock * clock::s_instance = nullptr;
clock::clock(uint64_t rate, clock::source source_func, void *data) :
m_rate(rate),
m_data(data),
m_source(source_func)
{
// TODO: make this atomic
if (s_instance == nullptr)
s_instance = this;
update();
}
void
clock::spinwait(uint64_t ns) const
{
uint64_t when = m_source(m_data) + ns;
while (value() < when);
}