Kernel: Implement per cpu fast pages
Basically every fast page usage should be converted into this but I'll do them one by one when they show up in profiles
This commit is contained in:
@@ -258,7 +258,11 @@ namespace Kernel
|
||||
|
||||
ASSERT(index < 512);
|
||||
ASSERT(s_fast_page_pt);
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
|
||||
if (index < reserved_fast_pages)
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
else
|
||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
||||
|
||||
ASSERT(!(s_fast_page_pt[index] & Flags::Present));
|
||||
s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
|
||||
@@ -272,7 +276,11 @@ namespace Kernel
|
||||
{
|
||||
ASSERT(index < 512);
|
||||
ASSERT(s_fast_page_pt);
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
|
||||
if (index < reserved_fast_pages)
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
else
|
||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
||||
|
||||
ASSERT((s_fast_page_pt[index] & Flags::Present));
|
||||
s_fast_page_pt[index] = 0;
|
||||
|
||||
@@ -382,7 +382,11 @@ namespace Kernel
|
||||
|
||||
ASSERT(index < 512);
|
||||
ASSERT(s_fast_page_pt);
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
|
||||
if (index < reserved_fast_pages)
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
else
|
||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
||||
|
||||
ASSERT(!(s_fast_page_pt[index] & Flags::Present));
|
||||
s_fast_page_pt[index] = paddr | Flags::ReadWrite | Flags::Present;
|
||||
@@ -396,7 +400,11 @@ namespace Kernel
|
||||
{
|
||||
ASSERT(index < 512);
|
||||
ASSERT(s_fast_page_pt);
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
|
||||
if (index < reserved_fast_pages)
|
||||
ASSERT(s_fast_page_lock.current_processor_has_lock());
|
||||
else
|
||||
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
|
||||
|
||||
ASSERT((s_fast_page_pt[index] & Flags::Present));
|
||||
s_fast_page_pt[index] = 0;
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace Kernel
|
||||
requires BAN::is_same_v<decltype(func()), void>;
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
concept with_per_cpu_fast_page_callback = requires(F func, void* addr)
|
||||
{
|
||||
requires BAN::is_same_v<decltype(func(addr)), void>;
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
concept with_fast_page_callback_error = requires(F func)
|
||||
{
|
||||
@@ -47,6 +53,8 @@ namespace Kernel
|
||||
|
||||
static constexpr bool full_tlb_flush_threshold = 32;
|
||||
|
||||
static constexpr size_t reserved_fast_pages = 0x10;
|
||||
|
||||
public:
|
||||
static void initialize_fast_page();
|
||||
static void initialize_and_load();
|
||||
@@ -74,6 +82,18 @@ namespace Kernel
|
||||
unmap_fast_page();
|
||||
}
|
||||
|
||||
template<with_per_cpu_fast_page_callback F>
|
||||
static void with_per_cpu_fast_page(paddr_t paddr, F callback)
|
||||
{
|
||||
const auto state = Processor::get_interrupt_state();
|
||||
Processor::set_interrupt_state(InterruptState::Disabled);
|
||||
const size_t index = Processor::current_index() + reserved_fast_pages;
|
||||
void* addr = map_fast_page(index, paddr);
|
||||
callback(addr);
|
||||
unmap_fast_page(index);
|
||||
Processor::set_interrupt_state(state);
|
||||
}
|
||||
|
||||
template<with_fast_page_callback_error F>
|
||||
static BAN::ErrorOr<void> with_fast_page(paddr_t paddr, F callback)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user