forked from Bananymous/banan-os
Kernel: Rewrite the whole scheduler and re-architecture SMP handling
Change Semaphore -> ThreadBlocker
This was not a semaphore, I just named it one because I didn't know
what semaphore was. I have meant to change this sooner, but it was in
no way urgent :D
Implement SMP events. Processors can now be sent SMP events through
IPIs. SMP events can be sent either to a single processor or broadcasted
to every processor.
PageTable::{map_page,map_range,unmap_page,unmap_range}() now send SMP
event to invalidate TLB caches for the changed pages.
Scheduler no longer uses a global run queue. Each processor has its own
scheduler that keeps track of the load on the processor. Once every
second schedulers do load balancing. Schedulers have no access to other
processors' schedulers, they just see approximate loads. If scheduler
decides that it has too much load, it will send a thread to another
processor through a SMP event.
Schedulers are currently run using the timer interrupt on BSB. This
should be not the case, and each processor should use its LAPIC timer
for interrupts. There is no reason to broadcast SMP event to all
processors when BSB gets timer interrupt.
Old scheduler only achieved 20% idle load on qemu. That was probably a
very inefficient implementation. This new scheduler seems to average
around 1% idle load. This is much closer to what I would expect. On my
own laptop idle load seems to be only around 0.5% on each processor.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <kernel/InterruptController.h>
|
||||
#include <kernel/Memory/PageTable.h>
|
||||
#include <kernel/MMIO.h>
|
||||
#include <kernel/Scheduler.h>
|
||||
#include <kernel/Processor.h>
|
||||
#include <kernel/Timer/HPET.h>
|
||||
|
||||
#define HPET_PERIOD_MAX 0x05F5E100
|
||||
@@ -272,7 +272,7 @@ namespace Kernel
|
||||
m_last_ticks = current_ticks;
|
||||
}
|
||||
|
||||
Scheduler::get().timer_reschedule();
|
||||
Processor::scheduler().timer_interrupt();
|
||||
}
|
||||
|
||||
uint64_t HPET::ms_since_boot() const
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <kernel/IDT.h>
|
||||
#include <kernel/InterruptController.h>
|
||||
#include <kernel/IO.h>
|
||||
#include <kernel/Scheduler.h>
|
||||
#include <kernel/Processor.h>
|
||||
#include <kernel/Timer/PIT.h>
|
||||
|
||||
#define PIT_IRQ 0
|
||||
@@ -58,7 +58,7 @@ namespace Kernel
|
||||
SpinLockGuard _(m_lock);
|
||||
m_system_time++;
|
||||
}
|
||||
Kernel::Scheduler::get().timer_reschedule();
|
||||
Processor::scheduler().timer_interrupt();
|
||||
}
|
||||
|
||||
uint64_t PIT::read_counter() const
|
||||
|
||||
@@ -69,15 +69,17 @@ namespace Kernel
|
||||
return m_timer->time_since_boot();
|
||||
}
|
||||
|
||||
void SystemTimer::sleep(uint64_t ms) const
|
||||
void SystemTimer::sleep_ns(uint64_t ns) const
|
||||
{
|
||||
if (ms == 0)
|
||||
if (ns == 0)
|
||||
return;
|
||||
uint64_t wake_time = ms_since_boot() + ms;
|
||||
Scheduler::get().set_current_thread_sleeping(wake_time);
|
||||
uint64_t current_time = ms_since_boot();
|
||||
if (current_time < wake_time)
|
||||
dwarnln("sleep woke {} ms too soon", wake_time - current_time);
|
||||
|
||||
const uint64_t wake_time_ns = ns_since_boot() + ns;
|
||||
Processor::scheduler().block_current_thread(nullptr, wake_time_ns);
|
||||
|
||||
//const uint64_t current_time_ns = ns_since_boot();
|
||||
//if (current_time_ns < wake_time_ns)
|
||||
// dwarnln("sleep woke {} ms too soon", BAN::Math::div_round_up<uint64_t>(wake_time_ns - current_time_ns, 1'000'000));
|
||||
}
|
||||
|
||||
timespec SystemTimer::real_time() const
|
||||
|
||||
Reference in New Issue
Block a user