mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-30 00:08:03 +00:00
Optimize smp GetCurrentCPU()
This commit is contained in:
parent
2c714bbcbc
commit
0f1f66668b
@ -28,27 +28,22 @@ volatile bool CPUEnabled = false;
|
|||||||
static __attribute__((aligned(PAGE_SIZE))) CPUData CPUs[MAX_CPU] = {0};
|
static __attribute__((aligned(PAGE_SIZE))) CPUData CPUs[MAX_CPU] = {0};
|
||||||
|
|
||||||
CPUData *GetCPU(long id) { return &CPUs[id]; }
|
CPUData *GetCPU(long id) { return &CPUs[id]; }
|
||||||
|
|
||||||
SafeFunction CPUData *GetCurrentCPU()
|
SafeFunction CPUData *GetCurrentCPU()
|
||||||
{
|
{
|
||||||
CPUData *data = (CPUData *)CPU::x64::rdmsr(CPU::x64::MSR_GS_BASE);
|
if (unlikely(!Interrupts::apic[0]))
|
||||||
|
return &CPUs[0]; /* No APIC means we are on the BSP. */
|
||||||
|
int CoreID = ((APIC::APIC *)Interrupts::apic[0])->Read(APIC::APIC_ID) >> 24;
|
||||||
|
|
||||||
if (unlikely(data == nullptr && Interrupts::apic[0]))
|
if (unlikely((&CPUs[CoreID])->IsActive != true))
|
||||||
data = &CPUs[((APIC::APIC *)Interrupts::apic[0])->Read(APIC::APIC_ID) >> 24];
|
|
||||||
|
|
||||||
if (unlikely(data == nullptr))
|
|
||||||
return nullptr; // The caller should handle this.
|
|
||||||
|
|
||||||
if (unlikely(data->IsActive != true))
|
|
||||||
{
|
{
|
||||||
error("CPU %d is not active!", data->ID);
|
error("CPU %d is not active!", CoreID);
|
||||||
if ((&CPUs[0])->IsActive)
|
assert((&CPUs[0])->IsActive == true); /* We can't continue without the BSP. */
|
||||||
return &CPUs[0];
|
return &CPUs[0];
|
||||||
else
|
|
||||||
return nullptr; // We are in trouble.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(data->Checksum == CPU_DATA_CHECKSUM); // This should never happen.
|
assert((&CPUs[CoreID])->Checksum == CPU_DATA_CHECKSUM); /* This should never happen. */
|
||||||
return data;
|
return &CPUs[CoreID];
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void StartCPU()
|
extern "C" void StartCPU()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user