mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-30 00:08:03 +00:00
Optimize GetCurrentCPU
This commit is contained in:
parent
b3cbcd474d
commit
2c714bbcbc
@ -28,17 +28,17 @@ 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]; }
|
||||||
CPUData *GetCurrentCPU()
|
SafeFunction CPUData *GetCurrentCPU()
|
||||||
{
|
{
|
||||||
CPUData *data = (CPUData *)CPU::x64::rdmsr(CPU::x64::MSR_GS_BASE);
|
CPUData *data = (CPUData *)CPU::x64::rdmsr(CPU::x64::MSR_GS_BASE);
|
||||||
|
|
||||||
if (data == nullptr && Interrupts::apic[0])
|
if (unlikely(data == nullptr && Interrupts::apic[0]))
|
||||||
data = &CPUs[((APIC::APIC *)Interrupts::apic[0])->Read(APIC::APIC_ID) >> 24];
|
data = &CPUs[((APIC::APIC *)Interrupts::apic[0])->Read(APIC::APIC_ID) >> 24];
|
||||||
|
|
||||||
if (data == nullptr)
|
if (unlikely(data == nullptr))
|
||||||
return nullptr; // The caller should handle this.
|
return nullptr; // The caller should handle this.
|
||||||
|
|
||||||
if (!data->IsActive)
|
if (unlikely(data->IsActive != true))
|
||||||
{
|
{
|
||||||
error("CPU %d is not active!", data->ID);
|
error("CPU %d is not active!", data->ID);
|
||||||
if ((&CPUs[0])->IsActive)
|
if ((&CPUs[0])->IsActive)
|
||||||
@ -46,6 +46,7 @@ CPUData *GetCurrentCPU()
|
|||||||
else
|
else
|
||||||
return nullptr; // We are in trouble.
|
return nullptr; // We are in trouble.
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(data->Checksum == CPU_DATA_CHECKSUM); // This should never happen.
|
assert(data->Checksum == CPU_DATA_CHECKSUM); // This should never happen.
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ namespace NetworkInterfaceManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
TaskManager->GetCurrentThread()->SetPriority(Tasking::TaskPriority::Idle);
|
TaskManager->GetCurrentThread()->SetPriority(Tasking::TaskPriority::Idle);
|
||||||
CPU::Pause(true);
|
CPU::Halt(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkInterface::StopNetworkStack()
|
void NetworkInterface::StopNetworkStack()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user