feat(kernel): add hot and cold attributes to optimize function performance

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
EnderIce2 2025-03-22 03:04:23 +00:00
parent f9476d8c57
commit d06b6d3270
No known key found for this signature in database
GPG Key ID: 2EE20AF089811A5A
5 changed files with 20 additions and 17 deletions

View File

@ -264,7 +264,7 @@ namespace Interrupts
warn("IRQ%d not found.", InterruptNumber);
}
nsa inline void ReturnFromInterrupt()
nsa hot inline void ReturnFromInterrupt()
{
#if defined(__amd64__) || defined(__i386__)
CPUData *CoreData = GetCurrentCPU();
@ -309,7 +309,7 @@ namespace Interrupts
CPU::Stop();
}
extern "C" nsa void MainInterruptHandler(void *Data)
extern "C" nsa hot void MainInterruptHandler(void *Data)
{
class AutoSwitchPageTable
{
@ -384,7 +384,7 @@ namespace Interrupts
#endif
}
extern "C" nsa void SchedulerInterruptHandler(void *Data)
extern "C" nsa hot void SchedulerInterruptHandler(void *Data)
{
#if defined(__amd64__) || defined(__i386__)
KernelPageTable->Update();

View File

@ -458,6 +458,9 @@ typedef uint48_t uint_fast48_t;
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define hot __attribute__((hot))
#define cold __attribute__((cold))
#define NoSecurityAnalysis __no_stack_protector __no_sanitize_address __no_sanitize_undefined __no_sanitize_thread
#define nsa NoSecurityAnalysis

View File

@ -117,7 +117,7 @@ EXTERNC void KPrint(const char *Format, ...)
#endif
}
EXTERNC NIF void Main()
EXTERNC NIF cold void Main()
{
Display = new Video::Display(bInfo.Framebuffer[0]);
KernelConsole::EarlyInit();
@ -265,7 +265,7 @@ typedef void (*CallPtr)(void);
extern CallPtr __init_array_start[0], __init_array_end[0];
extern CallPtr __fini_array_start[0], __fini_array_end[0];
EXTERNC __no_stack_protector NIF void Entry(BootInfo *Info)
EXTERNC __no_stack_protector NIF cold void Entry(BootInfo *Info)
{
trace("Hello, World!");

View File

@ -31,7 +31,7 @@
#include <vm.hpp>
#include <vector>
int SpawnInit()
cold int SpawnInit()
{
const char *envp[6] = {
"PATH=/bin:/usr/bin",
@ -54,7 +54,7 @@ int SpawnInit()
nullptr, false, compat, true);
}
void KernelMainThread()
cold void KernelMainThread()
{
thisThread->SetPriority(Tasking::Critical);
@ -129,7 +129,7 @@ Exit:
}
NewLock(ShutdownLock);
void __no_stack_protector KernelShutdownThread(bool Reboot)
cold void __no_stack_protector KernelShutdownThread(bool Reboot)
{
SmartLock(ShutdownLock);
debug("KernelShutdownThread(%s)", Reboot ? "true" : "false");

View File

@ -234,7 +234,7 @@ namespace Tasking::Scheduler
#endif
}
void Custom::Yield()
hot void Custom::Yield()
{
/* This will trigger the IRQ16
instantly so we won't execute
@ -272,7 +272,7 @@ namespace Tasking::Scheduler
/* --------------------------------------------------------------- */
nsa void Custom::OneShot(int TimeSlice)
hot nsa void Custom::OneShot(int TimeSlice)
{
if (TimeSlice == 0)
TimeSlice = Tasking::TaskPriority::Normal;
@ -288,7 +288,7 @@ namespace Tasking::Scheduler
#endif
}
nsa void Custom::UpdateUsage(TaskInfo *Info, TaskExecutionMode Mode, int Core)
hot nsa void Custom::UpdateUsage(TaskInfo *Info, TaskExecutionMode Mode, int Core)
{
UNUSED(Core);
uint64_t CurrentTime = TimeManager->GetCounter();
@ -301,7 +301,7 @@ namespace Tasking::Scheduler
Info->KernelTime += TimePassed;
}
nsa NIF bool Custom::FindNewProcess(void *CPUDataPointer)
hot nsa NIF bool Custom::FindNewProcess(void *CPUDataPointer)
{
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
fnp_schedbg("%d processes", ProcessList.size());
@ -348,7 +348,7 @@ namespace Tasking::Scheduler
return false;
}
nsa NIF bool Custom::GetNextAvailableThread(void *CPUDataPointer)
hot nsa NIF bool Custom::GetNextAvailableThread(void *CPUDataPointer)
{
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
@ -397,7 +397,7 @@ namespace Tasking::Scheduler
return false;
}
nsa NIF bool Custom::GetNextAvailableProcess(void *CPUDataPointer)
hot nsa NIF bool Custom::GetNextAvailableProcess(void *CPUDataPointer)
{
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
@ -445,7 +445,7 @@ namespace Tasking::Scheduler
return false;
}
nsa NIF bool Custom::SchedulerSearchProcessThread(void *CPUDataPointer)
hot nsa NIF bool Custom::SchedulerSearchProcessThread(void *CPUDataPointer)
{
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
@ -564,7 +564,7 @@ namespace Tasking::Scheduler
}
}
nsa NIF void Custom::Schedule(CPU::SchedulerFrame *Frame)
hot nsa NIF void Custom::Schedule(CPU::SchedulerFrame *Frame)
{
if (unlikely(StopScheduler))
{
@ -721,7 +721,7 @@ namespace Tasking::Scheduler
this->SchedulerTicks.store(size_t(TimeManager->GetCounter() - SchedTmpTicks));
}
nsa NIF void Custom::OnInterruptReceived(CPU::SchedulerFrame *Frame)
hot nsa NIF void Custom::OnInterruptReceived(CPU::SchedulerFrame *Frame)
{
SmartCriticalSection(SchedulerLock);
this->Schedule(Frame);