diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-22 22:11:14 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-22 22:11:14 +0200 |
| commit | d67240d20d1d4bbe33134e640fd632cfd5fc6795 (patch) | |
| tree | 999395dbf586a8cb704376024de60f7d80f21f4e /dev/kernel/KernelKit | |
| parent | 70756582de9f79eb2961c7aa91f1b0cdfe11cfc4 (diff) | |
dev, kernel: WiP changes done to kernel and SysChk module.
- Getting SysChk to work again.
- Refactor scheduler.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/KernelKit')
| -rw-r--r-- | dev/kernel/KernelKit/BinaryMutex.h | 8 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/IPEFDylibObject.h | 4 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/ProcessSchedulerCore.h | 137 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/UserProcessScheduler.h | 180 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/UserProcessScheduler.inl | 9 |
5 files changed, 177 insertions, 161 deletions
diff --git a/dev/kernel/KernelKit/BinaryMutex.h b/dev/kernel/KernelKit/BinaryMutex.h index 675396fd..ec1e355d 100644 --- a/dev/kernel/KernelKit/BinaryMutex.h +++ b/dev/kernel/KernelKit/BinaryMutex.h @@ -12,9 +12,9 @@ namespace Kernel { - class Process; + class UserProcess; - typedef Process& UserProcessRef; + typedef UserProcess& UserProcessRef; /// @brief Access control class, which locks a task until one is done. class BinaryMutex final @@ -31,8 +31,8 @@ namespace Kernel BOOL WaitForProcess(const Int16& sec) noexcept; public: - bool Lock(Process& process); - bool LockOrWait(Process& process, TimerInterface* timer); + bool Lock(UserProcess& process); + bool LockOrWait(UserProcess& process, TimerInterface* timer); public: NE_COPY_DEFAULT(BinaryMutex) diff --git a/dev/kernel/KernelKit/IPEFDylibObject.h b/dev/kernel/KernelKit/IPEFDylibObject.h index f1edc1d5..4769f0f9 100644 --- a/dev/kernel/KernelKit/IPEFDylibObject.h +++ b/dev/kernel/KernelKit/IPEFDylibObject.h @@ -99,8 +99,8 @@ namespace Kernel typedef IPEFDylibObject* IDylibRef; - EXTERN_C IDylibRef rtl_init_dylib(Process& header); - EXTERN_C Void rtl_fini_dylib(Process& header, IDylibRef lib, Bool* successful); + EXTERN_C IDylibRef rtl_init_dylib(UserProcess& header); + EXTERN_C Void rtl_fini_dylib(UserProcess& header, IDylibRef lib, Bool* successful); } // namespace Kernel #endif /* ifndef __KERNELKIT_SHARED_OBJECT_H__ */ diff --git a/dev/kernel/KernelKit/ProcessSchedulerCore.h b/dev/kernel/KernelKit/ProcessSchedulerCore.h new file mode 100644 index 00000000..002e685e --- /dev/null +++ b/dev/kernel/KernelKit/ProcessSchedulerCore.h @@ -0,0 +1,137 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.h> + +namespace Kernel +{ + class UserProcess; + class KernelProcess; + class UserProcessTeam; + + /***********************************************************************************/ + /// @brief Subsystem enum type. + /***********************************************************************************/ + + enum class ProcessSubsystem : Int32 + { + kProcessSubsystemSecurity = 100, + kProcessSubsystemApplication, + kProcessSubsystemService, + kProcessSubsystemDriver, + kProcessSubsystemInvalid = 256U, + kProcessSubsystemCount = 4, + }; + + typedef UInt64 PTime; + + /***********************************************************************************/ + //! @brief Local Process identifier. + /***********************************************************************************/ + typedef Int64 ProcessID; + + /***********************************************************************************/ + //! @brief Local Process status enum. + /***********************************************************************************/ + enum class ProcessStatusKind : Int32 + { + kInvalid, + kStarting, + kRunning, + kKilled, + kFrozen, + kFinished, + kCount, + }; + + /***********************************************************************************/ + //! @brief Affinity is the amount of nano-seconds this process is going to run. + /***********************************************************************************/ + enum class AffinityKind : Int32 + { + kRealTime = 500, + kVeryHigh = 250, + kHigh = 200, + kStandard = 1000, + kLowUsage = 1500, + kVeryLowUsage = 2000, + }; + + /***********************************************************************************/ + //! Operators for AffinityKind + /***********************************************************************************/ + + inline bool operator<(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); + + return lhs_int < rhs_int; + } + + inline bool operator>(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); + + return lhs_int > rhs_int; + } + + inline bool operator<=(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); + + return lhs_int <= rhs_int; + } + + inline bool operator>=(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast<Int>(lhs); + Int32 rhs_int = static_cast<Int>(rhs); + + return lhs_int >= rhs_int; + } + + using ProcessTime = UInt64; + using PID = Int64; + + /***********************************************************************************/ + /// @note For User manager, tells where we run the code. + /***********************************************************************************/ + enum class ProcessLevelRing : Int32 + { + kRingStdUser = 1, + kRingSuperUser = 2, + kRingGuestUser = 5, + kRingCount = 5, + }; + + /***********************************************************************************/ + /// @brief Helper type to describe a code image. + /***********************************************************************************/ + using ImagePtr = VoidPtr; + + struct ProcessImage final + { + explicit ProcessImage() = default; + + ImagePtr fCode; + ImagePtr fBlob; + + Bool HasCode() + { + return this->fCode != nullptr; + } + + Bool HasImage() + { + return this->fBlob != nullptr; + } + }; +} // namespace Kernel diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 25ff20e5..4ba4b779 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -8,18 +8,19 @@ #define INC_PROCESS_SCHEDULER_H /// @file UserProcessScheduler.h -/// @brief User Process scheduler code and definitions. +/// @brief User UserProcess scheduler code and definitions. /// @author Amlal El Mahrouss (amlal@nekernel.org) #include <ArchKit/ArchKit.h> #include <KernelKit/LockDelegate.h> #include <KernelKit/User.h> #include <NewKit/MutableArray.h> +#include <KernelKit/ProcessSchedulerCore.h> #define kSchedMinMicroTime (AffinityKind::kStandard) #define kSchedInvalidPID (-1) #define kSchedProcessLimitPerTeam (32U) -#define kSchedTeamCount (512) +#define kSchedTeamCount (512U) #define kSchedMaxMemoryLimit gib_cast(128) /* max physical memory limit */ #define kSchedMaxStackSz mib_cast(8) /* maximum stack size */ @@ -35,147 +36,24 @@ namespace Kernel //! @brief Forward declarations. class IDylibObject; - class Process; - class ProcessTeam; class UserProcessScheduler; class UserProcessHelper; - typedef UInt64 PTime; - - /***********************************************************************************/ - //! @brief Local Process identifier. - /***********************************************************************************/ - typedef Int64 ProcessID; - - /***********************************************************************************/ - //! @brief Local Process status enum. - /***********************************************************************************/ - enum class ProcessStatusKind : Int32 - { - kInvalid, - kStarting, - kRunning, - kKilled, - kFrozen, - kFinished, - kCount, - }; - - /***********************************************************************************/ - //! @brief Affinity is the amount of nano-seconds this process is going to run. - /***********************************************************************************/ - enum class AffinityKind : Int32 - { - kRealTime = 500, - kVeryHigh = 250, - kHigh = 200, - kStandard = 1000, - kLowUsage = 1500, - kVeryLowUsage = 2000, - }; - - /***********************************************************************************/ - //! Operators for AffinityKind - /***********************************************************************************/ - - inline bool operator<(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); - - return lhs_int < rhs_int; - } - - inline bool operator>(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); - - return lhs_int > rhs_int; - } - - inline bool operator<=(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); - - return lhs_int <= rhs_int; - } - - inline bool operator>=(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast<Int>(lhs); - Int32 rhs_int = static_cast<Int>(rhs); - - return lhs_int >= rhs_int; - } - - /***********************************************************************************/ - /// @brief Subsystem enum type. - /***********************************************************************************/ - - enum class ProcessSubsystem : Int32 - { - kProcessSubsystemSecurity = 100, - kProcessSubsystemApplication, - kProcessSubsystemService, - kProcessSubsystemDriver, - kProcessSubsystemInvalid = 256U, - kProcessSubsystemCount = 4, - }; - - using ProcessTime = UInt64; - using PID = Int64; - - /***********************************************************************************/ - /// @note For User manager, tells where we run the code. - /***********************************************************************************/ - enum class ProcessLevelRing : Int32 - { - kRingStdUser = 1, - kRingSuperUser = 2, - kRingGuestUser = 5, - kRingCount = 5, - }; - - /***********************************************************************************/ - /// @brief Helper type to describe a code image. - /***********************************************************************************/ - using ImagePtr = VoidPtr; - - struct ProcessImage final - { - explicit ProcessImage() = default; - - ImagePtr fCode; - ImagePtr fBlob; - - Bool HasCode() - { - return this->fCode != nullptr; - } - - Bool HasImage() - { - return this->fBlob != nullptr; - } - }; - /***********************************************************************************/ - /// @name Process - /// @brief Process class, holds information about the running process/thread. + /// @name UserProcess + /// @brief UserProcess class, holds information about the running process/thread. /***********************************************************************************/ - class Process final + class UserProcess final { public: - explicit Process(); - ~Process(); + explicit UserProcess(); + ~UserProcess(); public: - NE_COPY_DEFAULT(Process) + NE_COPY_DEFAULT(UserProcess) public: - Char Name[kSchedNameLen] = {"Process"}; + Char Name[kSchedNameLen] = {"UserProcess"}; ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemInvalid}; User* Owner{nullptr}; HAL::StackFramePtr StackFrame{nullptr}; @@ -208,7 +86,7 @@ namespace Kernel ProcessSignal ProcessSignal; ProcessMemoryHeapList* ProcessMemoryHeap{nullptr}; - ProcessTeam* ProcessParentTeam; + UserProcessTeam* ProcessParentTeam; VoidPtr VMRegister{0UL}; @@ -220,7 +98,7 @@ namespace Kernel kExecutableKindCount, }; - ProcessTime PTime{0}; //! @brief Process allocated tine. + ProcessTime PTime{0}; //! @brief UserProcess allocated tine. PID ProcessId{kSchedInvalidPID}; Int32 Kind{kExecutableKind}; @@ -294,31 +172,31 @@ namespace Kernel /// \brief Processs Team (contains multiple processes inside it.) /// Equivalent to a process batch - class ProcessTeam final + class UserProcessTeam final { public: - explicit ProcessTeam(); - ~ProcessTeam() = default; + explicit UserProcessTeam(); + ~UserProcessTeam() = default; - NE_COPY_DEFAULT(ProcessTeam) + NE_COPY_DEFAULT(UserProcessTeam) - Array<Process, kSchedProcessLimitPerTeam>& AsArray(); - Ref<Process>& AsRef(); + Array<UserProcess, kSchedProcessLimitPerTeam>& AsArray(); + Ref<UserProcess>& AsRef(); ProcessID& Id() noexcept; public: - Array<Process, kSchedProcessLimitPerTeam> mProcessList; - Ref<Process> mCurrentProcess; + Array<UserProcess, kSchedProcessLimitPerTeam> mProcessList; + Ref<UserProcess> mCurrentProcess; ProcessID mTeamId{0}; ProcessID mProcessCount{0}; }; - typedef Array<Process, kSchedProcessLimitPerTeam> UserThreadArray; + typedef Array<UserProcess, kSchedProcessLimitPerTeam> UserThreadArray; - using UserProcessRef = Process&; + using UserProcessRef = UserProcess&; /***********************************************************************************/ - /// @brief Process scheduler class. + /// @brief UserProcess scheduler class. /// The main class which you call to schedule user processes. /***********************************************************************************/ class UserProcessScheduler final : public ISchedulable @@ -336,8 +214,8 @@ namespace Kernel bool operator!(); public: - ProcessTeam& CurrentTeam(); - BOOL SwitchTeam(ProcessTeam& team); + UserProcessTeam& CurrentTeam(); + BOOL SwitchTeam(UserProcessTeam& team); public: ProcessID Spawn(const Char* name, VoidPtr code, VoidPtr image); @@ -348,19 +226,19 @@ namespace Kernel Bool HasMP() override; public: - Ref<Process>& CurrentProcess(); + Ref<UserProcess>& CurrentProcess(); SizeT Run() noexcept; public: STATIC UserProcessScheduler& The(); private: - ProcessTeam mTeam{}; + UserProcessTeam mTeam{}; }; /***********************************************************************************/ /** - * \brief Process helper class, which contains needed utilities for the scheduler. + * \brief UserProcess helper class, which contains needed utilities for the scheduler. */ /***********************************************************************************/ @@ -368,7 +246,7 @@ namespace Kernel { public: STATIC Bool Switch(VoidPtr image_ptr, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr, PID new_pid); - STATIC Bool CanBeScheduled(const Process& process); + STATIC Bool CanBeScheduled(const UserProcess& process); STATIC ErrorOr<PID> TheCurrentPID(); STATIC SizeT StartScheduling(); }; diff --git a/dev/kernel/KernelKit/UserProcessScheduler.inl b/dev/kernel/KernelKit/UserProcessScheduler.inl index ea57cf65..4179545c 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.inl +++ b/dev/kernel/KernelKit/UserProcessScheduler.inl @@ -3,12 +3,13 @@ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. FILE: UserProcessScheduler.inl - PURPOSE: Low level/Ring-3 Process scheduler. + PURPOSE: Low level/Ring-3 UserProcess scheduler. ------------------------------------------- */ -/// @brief Process scheduler inline definitions. +/// @brief UserProcess scheduler inline definitions. /// @author Amlal El Mahrouss (amlal@nekernel.org) +/// @date Tue Apr 22 22:01:07 CEST 2025 namespace Kernel { @@ -17,14 +18,14 @@ namespace Kernel /***********************************************************************************/ template <typename T> - Boolean Process::Delete(ErrorOr<T*> ptr) + Boolean UserProcess::Delete(ErrorOr<T*> ptr) { if (!ptr) return No; if (!this->ProcessMemoryHeap) { - kout << "Process's heap is empty.\r"; + kout << "UserProcess's heap is empty.\r"; return No; } |
