NeKernel dev
Loading...
Searching...
No Matches
CoreProcessScheduler.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5======================================== */
6
7#pragma once
8
9#include <NeKit/Config.h>
10#include <NeKit/ErrorOr.h>
11
15
16#define kSchedMinMicroTime (AffinityKind::kStandard)
17#define kSchedInvalidPID (-1)
18#define kSchedProcessLimitPerTeam (32U)
19#define kSchedTeamCount (256U)
20
21#define kSchedMaxMemoryLimit (gib_cast(128)) /* max physical memory limit */
22#define kSchedMaxStackSz (kib_cast(8)) /* maximum stack size */
23
24#define kSchedNameLen (128U)
25
27
28namespace Kernel {
29class USER_PROCESS;
30class KERNEL_TASK;
31class KernelTaskScheduler;
32class UserProcessScheduler;
33class UserProcessTeam;
34
35template <typename T>
36struct PROCESS_HEAP_TREE;
37
38template <typename T>
39struct PROCESS_SPECIAL_TREE;
40
41template <typename T>
42struct PROCESS_FILE_TREE;
43
44enum {
49};
50
51template <typename T>
53 static constexpr auto kHeap = true;
54 static constexpr auto kFile = false;
55 static constexpr auto kSpecial = false;
56
57 T Entry{nullptr};
60
62
64 nullptr
65 };
67 nullptr
68 };
69
71 nullptr
72 };
74 nullptr
75 };
76};
77
78template <typename T>
80 static constexpr auto kHeap = false;
81 static constexpr auto kFile = true;
82 static constexpr auto kSpecial = false;
83
84 T Entry{nullptr};
87
89
91 nullptr
92 };
93
95 nullptr
96 };
97
99 nullptr
100 };
101
103 nullptr
104 };
105};
106
108
109template <typename T>
111 static constexpr auto kHeap = false;
112 static constexpr auto kFile = false;
113 static constexpr auto kSpecial = true;
114
115 T Entry{nullptr};
118
120 ProcessCtx EntryContext{0UL}; // could be a socket, printer, device...
121
123
125 nullptr
126 };
127
129 nullptr
130 };
131
133 nullptr
134 };
135
137 nullptr
138 };
139};
140
141/***********************************************************************************/
143/***********************************************************************************/
144
154
155/***********************************************************************************/
157/***********************************************************************************/
167
168/***********************************************************************************/
170/***********************************************************************************/
171enum class AffinityKind : Int32 {
175 kHigh = 200,
176 kStandard = 1000,
177 kLowUsage = 1500,
179};
180
181/***********************************************************************************/
183/***********************************************************************************/
184
185inline bool operator<(AffinityKind lhs, AffinityKind rhs) {
186 Int32 lhs_int = static_cast<Int32>(lhs);
187 Int32 rhs_int = static_cast<Int32>(rhs);
188
189 return lhs_int < rhs_int;
190}
191
192inline bool operator>(AffinityKind lhs, AffinityKind rhs) {
193 Int32 lhs_int = static_cast<Int32>(lhs);
194 Int32 rhs_int = static_cast<Int32>(rhs);
195
196 return lhs_int > rhs_int;
197}
198
199inline bool operator<=(AffinityKind lhs, AffinityKind rhs) {
200 Int32 lhs_int = static_cast<Int>(lhs);
201 Int32 rhs_int = static_cast<Int32>(rhs);
202
203 return lhs_int <= rhs_int;
204}
205
206inline bool operator>=(AffinityKind lhs, AffinityKind rhs) {
207 Int32 lhs_int = static_cast<Int32>(lhs);
208 Int32 rhs_int = static_cast<Int32>(rhs);
209
210 return lhs_int >= rhs_int;
211}
212
213using PTime = UInt64;
215
216/***********************************************************************************/
218/***********************************************************************************/
220
221/***********************************************************************************/
223/***********************************************************************************/
230
231/***********************************************************************************/
233/***********************************************************************************/
235
236/***********************************************************************************/
238/***********************************************************************************/
239struct ProcessImage final {
240 explicit ProcessImage() = default;
241
242 private:
245
248
251
252 public:
253 Bool HasCode() const { return this->fCode != nullptr; }
254
255 Bool HasImage() const { return this->fBlob != nullptr; }
256
258 if (this->fCode) {
259 return ErrorOr<ImagePtr>{this->fCode};
260 }
261
263 }
264
266 if (this->fBlob) {
267 return ErrorOr<ImagePtr>{this->fBlob};
268 }
269
271 }
272};
273} // namespace Kernel
EXTERN_C void sched_idle_task(void)
#define EXTERN_C
ErrorOr class for error handling.
Definition ErrorOr.h:22
UPS inline definitions.
Definition Device.h:12
bool operator>=(AffinityKind lhs, AffinityKind rhs)
Definition CoreProcessScheduler.h:206
UInt32 ProcessCtx
Definition CoreProcessScheduler.h:107
Int64 ProcessID
Local Process Identifier type.
Definition CoreProcessScheduler.h:219
__INT64_TYPE__ Int64
Definition Config.h:46
ProcessSubsystem
Subsystem enum type.
Definition CoreProcessScheduler.h:145
@ kProcessSubsystemUser
Definition CoreProcessScheduler.h:147
@ kProcessSubsystemSecurity
Definition CoreProcessScheduler.h:146
@ kProcessSubsystemKernel
Definition CoreProcessScheduler.h:150
@ kProcessSubsystemInvalid
Definition CoreProcessScheduler.h:152
@ kProcessSubsystemDriver
Definition CoreProcessScheduler.h:149
@ kProcessSubsystemService
Definition CoreProcessScheduler.h:148
@ kProcessSubsystemCount
Definition CoreProcessScheduler.h:151
__SIZE_TYPE__ SizeT
Definition Config.h:60
UInt64 PTime
Definition CoreProcessScheduler.h:213
bool operator<=(AffinityKind lhs, AffinityKind rhs)
Definition CoreProcessScheduler.h:199
ProcessLevelRing
Definition CoreProcessScheduler.h:224
@ kRingSuperUser
Definition CoreProcessScheduler.h:226
@ kRingStdUser
Definition CoreProcessScheduler.h:225
@ kRingCount
Definition CoreProcessScheduler.h:228
@ kRingGuestUser
Definition CoreProcessScheduler.h:227
PTime ProcessTime
Definition CoreProcessScheduler.h:214
__UINT32_TYPE__ UInt32
Definition Config.h:44
void * VoidPtr
Definition Config.h:33
ProcessStatusKind
Local Process status enum.
Definition CoreProcessScheduler.h:158
@ kStarting
Definition CoreProcessScheduler.h:160
@ kKilled
Definition CoreProcessScheduler.h:162
@ kFinished
Definition CoreProcessScheduler.h:164
@ kRunning
Definition CoreProcessScheduler.h:161
@ kCount
Definition CoreProcessScheduler.h:165
@ kFrozen
Definition CoreProcessScheduler.h:163
@ kInvalid
Definition CoreProcessScheduler.h:159
constexpr KPCError kErrorInvalidData
Definition KPC.h:56
__INT32_TYPE__ Int32
Definition Config.h:38
bool operator<(AffinityKind lhs, AffinityKind rhs)
Operators for AffinityKind.
Definition CoreProcessScheduler.h:185
AffinityKind
Affinity is the amount of nano-seconds this process is going to run.
Definition CoreProcessScheduler.h:171
@ kVeryLowUsage
Definition CoreProcessScheduler.h:178
@ kLowUsage
Definition CoreProcessScheduler.h:177
@ kStandard
Definition CoreProcessScheduler.h:176
@ kHigh
Definition CoreProcessScheduler.h:175
@ kVeryHigh
Definition CoreProcessScheduler.h:174
@ kRealTime
Definition CoreProcessScheduler.h:173
@ kTreeKindCount
Definition CoreProcessScheduler.h:48
@ kRedTreeKind
Definition CoreProcessScheduler.h:46
@ kBlackTreeKind
Definition CoreProcessScheduler.h:47
@ kInvalidTreeKind
Definition CoreProcessScheduler.h:45
int Int
Definition Config.h:37
VoidPtr ImagePtr
Helper type to describe a code image.
Definition CoreProcessScheduler.h:234
__UINT64_TYPE__ UInt64
Definition Config.h:48
bool operator>(AffinityKind lhs, AffinityKind rhs)
Definition CoreProcessScheduler.h:192
bool Bool
Definition Config.h:50
Definition CoreProcessScheduler.h:79
UInt32 Color
Definition CoreProcessScheduler.h:88
static constexpr auto kSpecial
Definition CoreProcessScheduler.h:82
static constexpr auto kHeap
Definition CoreProcessScheduler.h:80
struct PROCESS_FILE_TREE< T > * Parent
Definition CoreProcessScheduler.h:90
struct PROCESS_FILE_TREE< T > * Child
Definition CoreProcessScheduler.h:94
SizeT EntryPad
Definition CoreProcessScheduler.h:86
T Entry
Definition CoreProcessScheduler.h:84
static constexpr auto kFile
Definition CoreProcessScheduler.h:81
SizeT EntrySize
Definition CoreProcessScheduler.h:85
struct PROCESS_FILE_TREE< T > * Prev
Definition CoreProcessScheduler.h:98
struct PROCESS_FILE_TREE< T > * Next
Definition CoreProcessScheduler.h:102
Definition CoreProcessScheduler.h:52
T Entry
Definition CoreProcessScheduler.h:57
struct PROCESS_HEAP_TREE< T > * Next
Definition CoreProcessScheduler.h:73
static constexpr auto kHeap
Definition CoreProcessScheduler.h:53
struct PROCESS_HEAP_TREE< T > * Parent
Definition CoreProcessScheduler.h:63
static constexpr auto kSpecial
Definition CoreProcessScheduler.h:55
SizeT EntrySize
Definition CoreProcessScheduler.h:58
SizeT EntryPad
Definition CoreProcessScheduler.h:59
UInt32 Color
Definition CoreProcessScheduler.h:61
struct PROCESS_HEAP_TREE< T > * Prev
Definition CoreProcessScheduler.h:70
struct PROCESS_HEAP_TREE< T > * Child
Definition CoreProcessScheduler.h:66
static constexpr auto kFile
Definition CoreProcessScheduler.h:54
Definition CoreProcessScheduler.h:110
struct PROCESS_SPECIAL_TREE< T > * Prev
Definition CoreProcessScheduler.h:132
struct PROCESS_SPECIAL_TREE< T > * Next
Definition CoreProcessScheduler.h:136
static constexpr auto kFile
Definition CoreProcessScheduler.h:112
UInt32 Color
Definition CoreProcessScheduler.h:122
ProcessCtx EntryContext
a context is where the resource comes from.
Definition CoreProcessScheduler.h:120
T Entry
Definition CoreProcessScheduler.h:115
struct PROCESS_SPECIAL_TREE< T > * Child
Definition CoreProcessScheduler.h:128
SizeT EntryPad
Definition CoreProcessScheduler.h:117
struct PROCESS_SPECIAL_TREE< T > * Parent
Definition CoreProcessScheduler.h:124
static constexpr auto kSpecial
Definition CoreProcessScheduler.h:113
static constexpr auto kHeap
Definition CoreProcessScheduler.h:111
SizeT EntrySize
Definition CoreProcessScheduler.h:116
ImagePtr fBlob
Definition CoreProcessScheduler.h:250
friend UserProcessScheduler
Definition CoreProcessScheduler.h:246
ErrorOr< ImagePtr > LeakImage()
Definition CoreProcessScheduler.h:257
friend KernelTaskScheduler
Definition CoreProcessScheduler.h:247
friend USER_PROCESS
Definition CoreProcessScheduler.h:243
friend KERNEL_TASK
Definition CoreProcessScheduler.h:244
Bool HasCode() const
Definition CoreProcessScheduler.h:253
Bool HasImage() const
Definition CoreProcessScheduler.h:255
ImagePtr fCode
Definition CoreProcessScheduler.h:249
ErrorOr< ImagePtr > LeakBlob()
Definition CoreProcessScheduler.h:265