[kernel] Fix clock period vs frequency error

Calling `spinwait()` was hanging due to improper computation of the
clock rate because justin did a dumb at math. Also the period can be
greater than 1ns, so the clock's units were updated to microseconds.
This commit is contained in:
2020-07-12 17:43:37 -07:00
parent 794c86f9b4
commit f4cbb9498f
7 changed files with 41 additions and 23 deletions

View File

@@ -12,13 +12,13 @@ public:
using source = uint64_t (*)(void*);
/// Constructor.
/// \arg rate Number of source ticks per ns
/// \arg rate Number of source ticks per us
/// \arg source Function for the clock source
/// \arg data Data to pass to the source function
clock(uint64_t rate, source source_func, void *data);
/// Get the current value of the clock.
/// \returns Current value of the source, in ns
/// \returns Current value of the source, in us
/// TODO: optimize divison by finding a multiply and
/// shift value instead
inline uint64_t value() const { return m_source(m_data) / m_rate; }
@@ -28,15 +28,15 @@ public:
inline void update() { m_current = value(); }
/// Wait in a tight loop
/// \arg interval Time to wait, in ns
void spinwait(uint64_t ns) const;
/// \arg interval Time to wait, in us
void spinwait(uint64_t us) const;
/// Get the master clock
static clock & get() { return *s_instance; }
private:
uint64_t m_current; ///< current ns count
uint64_t m_rate; ///< source ticks per ns
uint64_t m_current; ///< current us count
uint64_t m_rate; ///< source ticks per us
void *m_data;
source m_source;