Scheduler optimizations

This commit is contained in:
Alex 2022-12-29 04:46:12 +02:00
parent 83803fb4cf
commit e8d8f45c8a
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -192,7 +192,7 @@ namespace Tasking
// Find a new process to execute. // Find a new process to execute.
foreach (PCB *pcb in ListProcess) foreach (PCB *pcb in ListProcess)
{ {
if (InvalidPCB(pcb)) if (unlikely(InvalidPCB(pcb)))
continue; continue;
// Check process status. // Check process status.
@ -241,7 +241,7 @@ namespace Tasking
size_t TempIndex = i; size_t TempIndex = i;
RetryAnotherThread: RetryAnotherThread:
TCB *thread = CurrentCPU->CurrentProcess->Threads[TempIndex + 1]; TCB *thread = CurrentCPU->CurrentProcess->Threads[TempIndex + 1];
if (InvalidTCB(thread)) if (unlikely(InvalidTCB(thread)))
{ {
if (TempIndex > CurrentCPU->CurrentProcess->Threads.size()) if (TempIndex > CurrentCPU->CurrentProcess->Threads.size())
break; break;
@ -281,7 +281,7 @@ namespace Tasking
size_t TempIndex = i; size_t TempIndex = i;
RetryAnotherProcess: RetryAnotherProcess:
PCB *pcb = ListProcess[TempIndex + 1]; PCB *pcb = ListProcess[TempIndex + 1];
if (InvalidPCB(pcb)) if (unlikely(InvalidPCB(pcb)))
{ {
if (TempIndex > ListProcess.size()) if (TempIndex > ListProcess.size())
break; break;
@ -315,7 +315,7 @@ namespace Tasking
{ {
foreach (PCB *pcb in ListProcess) foreach (PCB *pcb in ListProcess)
{ {
if (InvalidPCB(pcb)) if (unlikely(InvalidPCB(pcb)))
continue; continue;
RemoveProcess(pcb); RemoveProcess(pcb);
} }
@ -327,7 +327,7 @@ namespace Tasking
foreach (PCB *pcb in ListProcess) foreach (PCB *pcb in ListProcess)
{ {
if (InvalidPCB(pcb)) if (unlikely(InvalidPCB(pcb)))
continue; continue;
if (pcb->Status != TaskStatus::Ready) if (pcb->Status != TaskStatus::Ready)
continue; continue;
@ -355,7 +355,7 @@ namespace Tasking
// Loop through all the processes. // Loop through all the processes.
foreach (PCB *pcb in ListProcess) foreach (PCB *pcb in ListProcess)
{ {
if (InvalidPCB(pcb)) if (unlikely(InvalidPCB(pcb)))
continue; continue;
// Check process status. // Check process status.
@ -402,6 +402,7 @@ namespace Tasking
schedbg("Scheduler called on CPU %d.", CurrentCPU->ID); schedbg("Scheduler called on CPU %d.", CurrentCPU->ID);
schedbg("%d: %ld%%", CurrentCPU->ID, GetUsage(CurrentCPU->ID)); schedbg("%d: %ld%%", CurrentCPU->ID, GetUsage(CurrentCPU->ID));
#ifdef DEBUG_SCHEDULER
{ {
schedbg("================================================================"); schedbg("================================================================");
schedbg("Status: 0-ukn | 1-rdy | 2-run | 3-wait | 4-term"); schedbg("Status: 0-ukn | 1-rdy | 2-run | 3-wait | 4-term");
@ -424,9 +425,10 @@ namespace Tasking
Frame->rip, Frame->rflags, Frame->InterruptNumber, Frame->ErrorCode); Frame->rip, Frame->rflags, Frame->InterruptNumber, Frame->ErrorCode);
schedbg("================================================================"); schedbg("================================================================");
} }
#endif
// Null or invalid process/thread? Let's find a new one to execute. // Null or invalid process/thread? Let's find a new one to execute.
if (InvalidPCB(CurrentCPU->CurrentProcess) || InvalidTCB(CurrentCPU->CurrentThread)) if (unlikely(InvalidPCB(CurrentCPU->CurrentProcess) || InvalidTCB(CurrentCPU->CurrentThread)))
{ {
if (this->FindNewProcess(CurrentCPU)) if (this->FindNewProcess(CurrentCPU))
goto Success; goto Success;