mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
Kernel: Do timekeeping manually instead of asking the RTC all the time.
This introduces a tiny amount of timer drift which I will have to fix somehow eventually, but it's a huge improvement in timing consistency as we no longer suddenly jump from e.g 10:45:49.123 to 10:45:50.000.
This commit is contained in:
parent
20f7d7ec67
commit
ab11f42094
5 changed files with 34 additions and 21 deletions
|
@ -57,26 +57,34 @@ asm(
|
|||
|
||||
#define BASE_FREQUENCY 1193182
|
||||
|
||||
static dword s_ticks_since_boot;
|
||||
static dword s_ticks_this_second;
|
||||
static dword s_seconds_since_boot;
|
||||
|
||||
void timer_interrupt_handler(RegisterDump& regs)
|
||||
{
|
||||
IRQHandlerScope scope(IRQ_TIMER);
|
||||
++s_ticks_since_boot;
|
||||
if (++s_ticks_this_second >= TICKS_PER_SECOND) {
|
||||
// FIXME: Synchronize with the RTC somehow to prevent drifting apart.
|
||||
++s_seconds_since_boot;
|
||||
s_ticks_this_second = 0;
|
||||
}
|
||||
Scheduler::timer_tick(regs);
|
||||
}
|
||||
|
||||
namespace PIT {
|
||||
|
||||
dword ticks_since_boot()
|
||||
dword ticks_this_second()
|
||||
{
|
||||
return s_ticks_since_boot;
|
||||
return s_ticks_this_second;
|
||||
}
|
||||
|
||||
dword seconds_since_boot()
|
||||
{
|
||||
return s_seconds_since_boot;
|
||||
}
|
||||
|
||||
void initialize()
|
||||
{
|
||||
s_ticks_since_boot = 0;
|
||||
|
||||
word timer_reload;
|
||||
|
||||
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_WORD | MODE_SQUARE_WAVE);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue