arch/Timer: Make sure ARCH_TIMER_FREQ is a power of two
(avoid division and modulo, division is slow) Fortunately, GCC will optimize divisions by powers of two to simple bitwise shifts :)
This commit is contained in:
parent
d0600f5714
commit
1b807a4e06
@ -2,8 +2,10 @@
|
||||
#include "Log.h"
|
||||
#include "arch/Serial.h"
|
||||
#include "boot/bootboot.h"
|
||||
#include <luna/TypeTraits.h>
|
||||
|
||||
// FIXME: Storing these values as unsigned integers doesn't allow for pre-epoch times.
|
||||
// NOTE: Storing these values as unsigned integers doesn't allow for pre-epoch times.
|
||||
// We are in 2023 anyway, not sure why anybody would want to set their computer's time to 1945.
|
||||
static u64 timer_ticks = 0;
|
||||
static u64 boot_timestamp;
|
||||
|
||||
@ -134,8 +136,9 @@ namespace Timer
|
||||
}
|
||||
}
|
||||
|
||||
static_assert(IsPowerOfTwo<usize, ARCH_TIMER_FREQ>, "ARCH_TIMER_FREQ must be a power of two");
|
||||
|
||||
bool should_invoke_scheduler()
|
||||
{
|
||||
// FIXME: Modulo is SLOW. We're calling this every tick.
|
||||
return (timer_ticks % ARCH_TIMER_FREQ) == 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#include <luna/Types.h>
|
||||
|
||||
const usize ARCH_TIMER_FREQ = 5;
|
||||
const usize ARCH_TIMER_FREQ = 4;
|
||||
|
Loading…
Reference in New Issue
Block a user