1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

Kernel: Remove s_processor_lock by making s_processors statically sized

Currently in SMP mode we hard code support for up to only 8 processors.
There is no reason for this to be a dynamic allocation that needs to be
guarded by a spinlock. Instead use a Array<T* with inline storage of 8,
allowing each processor to initialize it self in place, avoiding all
the need for locks.
This commit is contained in:
Brian Gianforcaro 2021-05-18 01:49:34 -07:00 committed by Andreas Kling
parent 1415b2cfc3
commit 7540f4268b
2 changed files with 15 additions and 14 deletions

View file

@ -623,6 +623,11 @@ struct DeferredCallEntry {
bool was_allocated;
};
class Processor;
// Note: We only support processors at most at the moment,
// so allocate 8 slots of inline capacity in the container.
using ProcessorContainer = Array<Processor*, 8>;
class Processor {
friend class ProcessorInfo;
@ -665,7 +670,7 @@ class Processor {
void gdt_init();
void write_raw_gdt_entry(u16 selector, u32 low, u32 high);
void write_gdt_entry(u16 selector, Descriptor& descriptor);
static Vector<Processor*>& processors();
static ProcessorContainer& processors();
static void smp_return_to_pool(ProcessorMessage& msg);
static ProcessorMessage& smp_get_from_pool();
@ -751,8 +756,10 @@ public:
{
auto& procs = processors();
size_t count = procs.size();
for (size_t i = 0; i < count; i++)
callback(*procs[i]);
for (size_t i = 0; i < count; i++) {
if (procs[i] != nullptr)
callback(*procs[i]);
}
return IterationDecision::Continue;
}