mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 15:29:18 +00:00
Add UserTime and KernelTime tracker
This commit is contained in:
@ -476,8 +476,9 @@ namespace Tasking
|
||||
warn("Scheduler stopped.");
|
||||
return;
|
||||
}
|
||||
bool ProcessNotChanged = false;
|
||||
CPU::x64::writecr3({.raw = (uint64_t)KernelPageTable}); /* Restore kernel page table for safety reasons. */
|
||||
uint64_t SchedTmpTicks = CPU::Counter();
|
||||
uint64_t SchedTmpTicks = TimeManager->GetCounter();
|
||||
this->LastTaskTicks.store(SchedTmpTicks - this->SchedulerTicks.load());
|
||||
CPUData *CurrentCPU = GetCurrentCPU();
|
||||
schedbg("Scheduler called on CPU %d.", CurrentCPU->ID);
|
||||
@ -511,6 +512,7 @@ namespace Tasking
|
||||
if (unlikely(InvalidPCB(CurrentCPU->CurrentProcess.load()) || InvalidTCB(CurrentCPU->CurrentThread.load())))
|
||||
{
|
||||
schedbg("Invalid process or thread. Finding a new one.");
|
||||
ProcessNotChanged = true;
|
||||
if (this->FindNewProcess(CurrentCPU))
|
||||
goto Success;
|
||||
else
|
||||
@ -539,6 +541,7 @@ namespace Tasking
|
||||
#ifdef ON_SCREEN_SCHEDULER_TASK_MANAGER
|
||||
SuccessSource = 1;
|
||||
#endif
|
||||
ProcessNotChanged = true;
|
||||
goto Success;
|
||||
}
|
||||
schedbg("Passed GetNextAvailableThread");
|
||||
@ -567,22 +570,24 @@ namespace Tasking
|
||||
}
|
||||
}
|
||||
|
||||
/* [this]->RealEnd */
|
||||
warn("Unwanted reach!");
|
||||
TaskingScheduler_OneShot(100);
|
||||
goto RealEnd;
|
||||
goto End;
|
||||
|
||||
/* Idle-->Success */
|
||||
Idle:
|
||||
ProcessNotChanged = true;
|
||||
CurrentCPU->CurrentProcess = IdleProcess;
|
||||
CurrentCPU->CurrentThread = IdleThread;
|
||||
|
||||
/* Success-->End */
|
||||
Success:
|
||||
schedbg("Process \"%s\"(%d) Thread \"%s\"(%d) is now running on CPU %d",
|
||||
CurrentCPU->CurrentProcess->Name, CurrentCPU->CurrentProcess->ID,
|
||||
CurrentCPU->CurrentThread->Name, CurrentCPU->CurrentThread->ID, CurrentCPU->ID);
|
||||
|
||||
if (!ProcessNotChanged)
|
||||
UpdateUsage(&CurrentCPU->CurrentProcess->Info, &CurrentCPU->CurrentProcess->Security, CurrentCPU->ID);
|
||||
UpdateUsage(&CurrentCPU->CurrentThread->Info, &CurrentCPU->CurrentThread->Security, CurrentCPU->ID);
|
||||
|
||||
CurrentCPU->CurrentProcess->Status = TaskStatus::Running;
|
||||
CurrentCPU->CurrentThread->Status = TaskStatus::Running;
|
||||
|
||||
@ -621,21 +626,9 @@ namespace Tasking
|
||||
break;
|
||||
}
|
||||
|
||||
/* End-->RealEnd */
|
||||
// End:
|
||||
/* TODO: This is not accurate. */
|
||||
if (CurrentCPU->CurrentProcess->Security.TrustLevel == TaskTrustLevel::User)
|
||||
UpdateUserTime(&CurrentCPU->CurrentProcess->Info);
|
||||
else
|
||||
UpdateKernelTime(&CurrentCPU->CurrentProcess->Info);
|
||||
|
||||
if (CurrentCPU->CurrentThread->Security.TrustLevel == TaskTrustLevel::User)
|
||||
UpdateUserTime(&CurrentCPU->CurrentThread->Info);
|
||||
else
|
||||
UpdateKernelTime(&CurrentCPU->CurrentThread->Info);
|
||||
|
||||
UpdateUsage(&CurrentCPU->CurrentProcess->Info, CurrentCPU->ID);
|
||||
UpdateUsage(&CurrentCPU->CurrentThread->Info, CurrentCPU->ID);
|
||||
if (!ProcessNotChanged)
|
||||
(&CurrentCPU->CurrentProcess->Info)->LastUpdateTime = TimeManager->GetCounter();
|
||||
(&CurrentCPU->CurrentThread->Info)->LastUpdateTime = TimeManager->GetCounter();
|
||||
TaskingScheduler_OneShot(CurrentCPU->CurrentThread->Info.Priority);
|
||||
|
||||
if (CurrentCPU->CurrentThread->Security.IsDebugEnabled && CurrentCPU->CurrentThread->Security.IsKernelDebugEnabled)
|
||||
@ -666,9 +659,8 @@ namespace Tasking
|
||||
Frame->rip, Frame->rflags, Frame->InterruptNumber, Frame->ErrorCode);
|
||||
schedbg("================================================================");
|
||||
|
||||
/* RealEnd->[Function Exit] */
|
||||
RealEnd:
|
||||
this->SchedulerTicks.store(CPU::Counter() - SchedTmpTicks);
|
||||
End:
|
||||
this->SchedulerTicks.store(TimeManager->GetCounter() - SchedTmpTicks);
|
||||
__sync; /* TODO: Is this really needed? */
|
||||
}
|
||||
|
||||
|
@ -172,40 +172,16 @@ namespace Tasking
|
||||
}
|
||||
}
|
||||
|
||||
SafeFunction NIF void Task::UpdateUserTime(TaskInfo *Info)
|
||||
SafeFunction NIF void Task::UpdateUsage(TaskInfo *Info, TaskSecurity *Security, int Core)
|
||||
{
|
||||
// TODO
|
||||
Info->UserTime++;
|
||||
}
|
||||
uint64_t CurrentTime = TimeManager->GetCounter();
|
||||
uint64_t TimePassed = CurrentTime - Info->LastUpdateTime;
|
||||
// Info->LastUpdateTime = CurrentTime;
|
||||
|
||||
SafeFunction NIF void Task::UpdateKernelTime(TaskInfo *Info)
|
||||
{
|
||||
// TODO
|
||||
Info->KernelTime++;
|
||||
}
|
||||
|
||||
SafeFunction NIF void Task::UpdateUsage(TaskInfo *Info, int Core)
|
||||
{
|
||||
if (Info->Affinity[Core] == true)
|
||||
{
|
||||
// TODO: Not working(?)
|
||||
uint64_t CounterNow = CPU::Counter();
|
||||
|
||||
Info->OldUserTime = Info->CurrentUserTime;
|
||||
Info->OldKernelTime = Info->CurrentKernelTime;
|
||||
|
||||
Info->CurrentUserTime = Info->UserTime;
|
||||
Info->CurrentKernelTime = Info->KernelTime;
|
||||
|
||||
Info->Usage[Core] = (Info->CurrentUserTime - Info->OldUserTime) + (Info->CurrentKernelTime - Info->OldKernelTime);
|
||||
Info->Usage[Core] = (Info->Usage[Core] * 100) / (CounterNow - Info->SpawnTime);
|
||||
|
||||
Info->OldUserTime = Info->CurrentUserTime;
|
||||
Info->OldKernelTime = Info->CurrentKernelTime;
|
||||
|
||||
Info->CurrentUserTime = Info->UserTime;
|
||||
Info->CurrentKernelTime = Info->KernelTime;
|
||||
}
|
||||
if (Security->TrustLevel == TaskTrustLevel::User)
|
||||
Info->UserTime += TimePassed;
|
||||
else
|
||||
Info->KernelTime += TimePassed;
|
||||
}
|
||||
|
||||
void ThreadDoExit()
|
||||
@ -635,7 +611,7 @@ namespace Tasking
|
||||
}
|
||||
|
||||
Thread->Info = {};
|
||||
Thread->Info.SpawnTime = CPU::Counter();
|
||||
Thread->Info.SpawnTime = TimeManager->GetCounter();
|
||||
Thread->Info.Year = 0;
|
||||
Thread->Info.Month = 0;
|
||||
Thread->Info.Day = 0;
|
||||
@ -644,7 +620,6 @@ namespace Tasking
|
||||
Thread->Info.Second = 0;
|
||||
for (int i = 0; i < MAX_CPU; i++)
|
||||
{
|
||||
Thread->Info.Usage[i] = 0;
|
||||
Thread->Info.Affinity[i] = true;
|
||||
}
|
||||
Thread->Info.Priority = TaskPriority::Normal;
|
||||
@ -741,7 +716,7 @@ namespace Tasking
|
||||
}
|
||||
|
||||
Process->Info = {};
|
||||
Process->Info.SpawnTime = CPU::Counter();
|
||||
Process->Info.SpawnTime = TimeManager->GetCounter();
|
||||
Process->Info.Year = 0;
|
||||
Process->Info.Month = 0;
|
||||
Process->Info.Day = 0;
|
||||
@ -750,7 +725,6 @@ namespace Tasking
|
||||
Process->Info.Second = 0;
|
||||
for (int i = 0; i < MAX_CPU; i++)
|
||||
{
|
||||
Process->Info.Usage[i] = 0;
|
||||
Process->Info.Affinity[i] = true;
|
||||
}
|
||||
Process->Info.Priority = TaskPriority::Normal;
|
||||
|
Reference in New Issue
Block a user