Update kernel

This commit is contained in:
Alex
2023-08-06 04:53:14 +03:00
parent 3b65386399
commit 2c51e4432f
181 changed files with 21873 additions and 21475 deletions

View File

@ -34,8 +34,6 @@
#elif defined(aa64)
#endif
NewLock(SchedulerLock);
/* FIXME: On screen task manager is corrupting the stack... */
// #define ON_SCREEN_SCHEDULER_TASK_MANAGER 1
@ -127,14 +125,15 @@ namespace Tasking
fnp_schedbg("%d processes", ProcessList.size());
#ifdef DEBUG_FIND_NEW_PROCESS
foreach (auto process in ProcessList)
fnp_schedbg("Process %d %s", process->ID, process->Name);
fnp_schedbg("Process %d %s", process->ID,
process->Name);
#endif
foreach (auto process in ProcessList)
{
if (InvalidPCB(process))
continue;
switch (process->Status)
switch (process->Status.load())
{
case TaskStatus::Ready:
fnp_schedbg("Ready process (%s)%d",
@ -158,7 +157,7 @@ namespace Tasking
if (InvalidTCB(thread))
continue;
if (thread->Status != TaskStatus::Ready)
if (thread->Status.load() != TaskStatus::Ready)
continue;
if (thread->Info.Affinity[CurrentCPU->ID] == false)
@ -177,17 +176,22 @@ namespace Tasking
{
CPUData *CurrentCPU = (CPUData *)CPUDataPointer;
for (size_t i = 0; i < CurrentCPU->CurrentProcess->Threads.size(); i++)
size_t ThreadsSize = CurrentCPU->CurrentProcess->Threads.size();
for (size_t i = 0; i < ThreadsSize; i++)
{
if (CurrentCPU->CurrentProcess->Threads[i] == CurrentCPU->CurrentThread.load())
{
size_t TempIndex = i;
RetryAnotherThread:
if (TempIndex + 1 >= ThreadsSize)
break;
TCB *nextThread = CurrentCPU->CurrentProcess->Threads[TempIndex + 1];
if (unlikely(InvalidTCB(nextThread)))
{
if (TempIndex > CurrentCPU->CurrentProcess->Threads.size())
if (TempIndex > ThreadsSize)
break;
TempIndex++;
@ -200,7 +204,7 @@ namespace Tasking
CurrentCPU->CurrentProcess->Threads[i]->ID,
nextThread->Name, nextThread->ID);
if (nextThread->Status != TaskStatus::Ready)
if (nextThread->Status.load() != TaskStatus::Ready)
{
gnat_schedbg("Thread %d is not ready", nextThread->ID);
TempIndex++;
@ -213,7 +217,7 @@ namespace Tasking
CurrentCPU->CurrentThread = nextThread;
gnat_schedbg("[thd 0 -> end] Scheduling thread %d parent of %s->%d Procs %d",
nextThread->ID, nextThread->Parent->Name,
CurrentCPU->CurrentProcess->Threads.size(), ProcessList.size());
ThreadsSize, ProcessList.size());
return true;
}
#ifdef DEBUG
@ -253,7 +257,7 @@ namespace Tasking
continue;
}
if (process->Status != TaskStatus::Ready)
if (process->Status.load() != TaskStatus::Ready)
{
gnap_schedbg("Process %d is not ready", process->ID);
continue;
@ -267,7 +271,7 @@ namespace Tasking
continue;
}
if (thread->Status != TaskStatus::Ready)
if (thread->Status.load() != TaskStatus::Ready)
{
gnap_schedbg("Thread %d is not ready", thread->ID);
continue;
@ -299,7 +303,7 @@ namespace Tasking
continue;
}
if (process->Status != TaskStatus::Ready)
if (process->Status.load() != TaskStatus::Ready)
{
sspt_schedbg("Process %d is not ready", process->ID);
continue;
@ -313,7 +317,7 @@ namespace Tasking
continue;
}
if (thread->Status != TaskStatus::Ready)
if (thread->Status.load() != TaskStatus::Ready)
{
sspt_schedbg("Thread %d is not ready", thread->ID);
continue;
@ -339,14 +343,14 @@ namespace Tasking
if (InvalidPCB(process))
continue;
if (process->Status == TaskStatus::Terminated ||
process->Status == TaskStatus::Stopped)
if (process->Status.load() == TaskStatus::Terminated ||
process->Status.load() == TaskStatus::Zombie)
continue;
bool AllThreadsSleeping = true;
foreach (auto thread in process->Threads)
{
if (thread->Status != TaskStatus::Sleeping)
if (thread->Status.load() != TaskStatus::Sleeping)
{
AllThreadsSleeping = false;
break;
@ -354,9 +358,9 @@ namespace Tasking
}
if (AllThreadsSleeping)
process->Status = TaskStatus::Sleeping;
else if (process->Status == TaskStatus::Sleeping)
process->Status = TaskStatus::Ready;
process->Status.store(TaskStatus::Sleeping);
else if (process->Status.load() == TaskStatus::Sleeping)
process->Status.store(TaskStatus::Ready);
}
}
@ -367,8 +371,8 @@ namespace Tasking
if (InvalidPCB(process))
continue;
if (process->Status == TaskStatus::Terminated ||
process->Status == TaskStatus::Stopped)
if (process->Status.load() == TaskStatus::Terminated ||
process->Status.load() == TaskStatus::Zombie)
continue;
foreach (auto thread in process->Threads)
@ -376,15 +380,15 @@ namespace Tasking
if (InvalidTCB(thread))
continue;
if (thread->Status != TaskStatus::Sleeping)
if (thread->Status.load() != TaskStatus::Sleeping)
continue;
/* Check if the thread is ready to wake up. */
if (thread->Info.SleepUntil < TimeManager->GetCounter())
{
if (process->Status == TaskStatus::Sleeping)
process->Status = TaskStatus::Ready;
thread->Status = TaskStatus::Ready;
if (process->Status.load() == TaskStatus::Sleeping)
process->Status.store(TaskStatus::Ready);
thread->Status.store(TaskStatus::Ready);
thread->Info.SleepUntil = 0;
wut_schedbg("Thread \"%s\"(%d) woke up.", thread->Name, thread->ID);
@ -407,8 +411,8 @@ namespace Tasking
"AAFF00", /* Ready */
"00AA00", /* Running */
"FFAA00", /* Sleeping */
"FFAA00", /* Waiting */
"FF0088", /* Stopped */
"FFAA00", /* Blocked */
"FF0088", /* Zombie */
"FF0000", /* Terminated */
};
@ -526,10 +530,10 @@ namespace Tasking
CurrentCPU->CurrentThread->GSBase = CPU::x64::rdmsr(CPU::x64::MSR_GS_BASE);
CurrentCPU->CurrentThread->FSBase = CPU::x64::rdmsr(CPU::x64::MSR_FS_BASE);
if (CurrentCPU->CurrentProcess->Status == TaskStatus::Running)
CurrentCPU->CurrentProcess->Status = TaskStatus::Ready;
if (CurrentCPU->CurrentThread->Status == TaskStatus::Running)
CurrentCPU->CurrentThread->Status = TaskStatus::Ready;
if (CurrentCPU->CurrentProcess->Status.load() == TaskStatus::Running)
CurrentCPU->CurrentProcess->Status.store(TaskStatus::Ready);
if (CurrentCPU->CurrentThread->Status.load() == TaskStatus::Running)
CurrentCPU->CurrentThread->Status.store(TaskStatus::Ready);
this->UpdateProcessStatus();
schedbg("Passed UpdateProcessStatus");
@ -537,6 +541,9 @@ namespace Tasking
this->WakeUpThreads();
schedbg("Passed WakeUpThreads");
if (this->SchedulerUpdateTrapFrame)
goto Success;
if (this->GetNextAvailableThread(CurrentCPU))
{
#ifdef ON_SCREEN_SCHEDULER_TASK_MANAGER
@ -586,11 +593,16 @@ namespace Tasking
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);
UpdateUsage(&CurrentCPU->CurrentProcess->Info,
CurrentCPU->CurrentProcess->Security.ExecutionMode,
CurrentCPU->ID);
CurrentCPU->CurrentProcess->Status = TaskStatus::Running;
CurrentCPU->CurrentThread->Status = TaskStatus::Running;
UpdateUsage(&CurrentCPU->CurrentThread->Info,
CurrentCPU->CurrentThread->Security.ExecutionMode,
CurrentCPU->ID);
CurrentCPU->CurrentProcess->Status.store(TaskStatus::Running);
CurrentCPU->CurrentThread->Status.store(TaskStatus::Running);
*Frame = CurrentCPU->CurrentThread->Registers;
@ -613,18 +625,18 @@ namespace Tasking
OnScreenTaskManagerUpdate();
#endif
switch (CurrentCPU->CurrentProcess->Security.TrustLevel)
switch (CurrentCPU->CurrentProcess->Security.ExecutionMode)
{
case TaskTrustLevel::System:
case TaskTrustLevel::Kernel:
case TaskExecutionMode::System:
case TaskExecutionMode::Kernel:
// wrmsr(MSR_SHADOW_GS_BASE, (uint64_t)CurrentCPU->CurrentThread);
break;
case TaskTrustLevel::User:
case TaskExecutionMode::User:
// wrmsr(MSR_SHADOW_GS_BASE, CurrentCPU->CurrentThread->gs);
break;
default:
error("Unknown trust level %d.",
CurrentCPU->CurrentProcess->Security.TrustLevel);
CurrentCPU->CurrentProcess->Security.ExecutionMode);
break;
}
@ -663,7 +675,6 @@ namespace Tasking
End:
this->SchedulerTicks.store(TimeManager->GetCounter() - SchedTmpTicks);
__sync; /* TODO: Is this really needed? */
}
SafeFunction NIF void Task::OnInterruptReceived(CPU::x64::TrapFrame *Frame)