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.
75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <BAN/Vector.h>
|
|
#include <kernel/ACPI/AML/Method.h>
|
|
#include <kernel/ACPI/AML/Namespace.h>
|
|
#include <kernel/ACPI/Headers.h>
|
|
#include <kernel/Memory/Types.h>
|
|
#include <kernel/ThreadBlocker.h>
|
|
|
|
namespace Kernel::ACPI
|
|
{
|
|
|
|
class ACPI : public Interruptable
|
|
{
|
|
public:
|
|
static BAN::ErrorOr<void> initialize();
|
|
static ACPI& get();
|
|
|
|
static void acquire_global_lock();
|
|
static void release_global_lock();
|
|
|
|
bool hardware_reduced() const { return m_hardware_reduced; }
|
|
|
|
const SDTHeader* get_header(BAN::StringView signature, uint32_t index);
|
|
|
|
// mode
|
|
// 0: PIC
|
|
// 1: APIC
|
|
// 2: SAPIC
|
|
BAN::ErrorOr<void> enter_acpi_mode(uint8_t mode);
|
|
|
|
// This function will power off the system
|
|
// This function will return only if there was an error
|
|
void poweroff();
|
|
|
|
// This function will reset the system
|
|
// This function will return only if there was an error
|
|
void reset();
|
|
|
|
void handle_irq() override;
|
|
|
|
private:
|
|
ACPI() = default;
|
|
BAN::ErrorOr<void> initialize_impl();
|
|
|
|
FADT& fadt() { return *m_fadt; }
|
|
|
|
bool prepare_sleep(uint8_t sleep_state);
|
|
void acpi_event_task();
|
|
|
|
private:
|
|
paddr_t m_header_table_paddr = 0;
|
|
vaddr_t m_header_table_vaddr = 0;
|
|
uint32_t m_entry_size = 0;
|
|
|
|
struct MappedPage
|
|
{
|
|
Kernel::paddr_t paddr;
|
|
Kernel::vaddr_t vaddr;
|
|
|
|
SDTHeader* as_header() { return (SDTHeader*)vaddr; }
|
|
};
|
|
BAN::Vector<MappedPage> m_mapped_headers;
|
|
|
|
FADT* m_fadt { nullptr };
|
|
|
|
ThreadBlocker m_event_thread_blocker;
|
|
BAN::Array<BAN::RefPtr<AML::Method>, 0xFF> m_gpe_methods;
|
|
|
|
bool m_hardware_reduced { false };
|
|
BAN::RefPtr<AML::Namespace> m_namespace;
|
|
};
|
|
|
|
}
|