mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
Kernel: Add basic process priority support.
For now, the WindowServer process will run with high priority, while the Finalizer process will run with low priority. Everyone else gets to be "normal". At the moment, priority simply determines the size of your time slices.
This commit is contained in:
parent
ee2bb98b88
commit
71b9ec1ae0
6 changed files with 46 additions and 7 deletions
|
@ -496,7 +496,7 @@ ByteBuffer procfs$all(InodeIdentifier)
|
||||||
auto processes = Process::all_processes();
|
auto processes = Process::all_processes();
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
auto build_process_line = [&builder] (Process* process) {
|
auto build_process_line = [&builder] (Process* process) {
|
||||||
builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u,%u,%u\n",
|
builder.appendf("%u,%u,%u,%u,%u,%u,%u,%s,%u,%u,%s,%s,%u,%u,%u,%u,%u,%s\n",
|
||||||
process->pid(),
|
process->pid(),
|
||||||
process->times_scheduled(),
|
process->times_scheduled(),
|
||||||
process->tty() ? process->tty()->pgid() : 0,
|
process->tty() ? process->tty()->pgid() : 0,
|
||||||
|
@ -513,7 +513,8 @@ ByteBuffer procfs$all(InodeIdentifier)
|
||||||
process->amount_resident(),
|
process->amount_resident(),
|
||||||
process->amount_shared(),
|
process->amount_shared(),
|
||||||
process->amount_in_bitmaps(),
|
process->amount_in_bitmaps(),
|
||||||
process->ticks()
|
process->ticks(),
|
||||||
|
to_string(process->priority())
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
build_process_line(Scheduler::colonel());
|
build_process_line(Scheduler::colonel());
|
||||||
|
|
|
@ -80,6 +80,12 @@ public:
|
||||||
BlockedSelect,
|
BlockedSelect,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Priority {
|
||||||
|
LowPriority,
|
||||||
|
NormalPriority,
|
||||||
|
HighPriority,
|
||||||
|
};
|
||||||
|
|
||||||
enum RingLevel {
|
enum RingLevel {
|
||||||
Ring0 = 0,
|
Ring0 = 0,
|
||||||
Ring3 = 3,
|
Ring3 = 3,
|
||||||
|
@ -100,6 +106,9 @@ public:
|
||||||
|
|
||||||
static Process* from_pid(pid_t);
|
static Process* from_pid(pid_t);
|
||||||
|
|
||||||
|
void set_priority(Priority p) { m_priority = p; }
|
||||||
|
Priority priority() const { return m_priority; }
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
pid_t pid() const { return m_pid; }
|
pid_t pid() const { return m_pid; }
|
||||||
pid_t sid() const { return m_sid; }
|
pid_t sid() const { return m_sid; }
|
||||||
|
@ -328,6 +337,7 @@ private:
|
||||||
dword m_stack_top3 { 0 };
|
dword m_stack_top3 { 0 };
|
||||||
FarPtr m_far_ptr;
|
FarPtr m_far_ptr;
|
||||||
State m_state { Invalid };
|
State m_state { Invalid };
|
||||||
|
Priority m_priority { NormalPriority };
|
||||||
dword m_wakeup_time { 0 };
|
dword m_wakeup_time { 0 };
|
||||||
TSS32 m_tss;
|
TSS32 m_tss;
|
||||||
TSS32 m_tss_to_resume_kernel;
|
TSS32 m_tss_to_resume_kernel;
|
||||||
|
@ -464,6 +474,17 @@ static inline const char* to_string(Process::State state)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline const char* to_string(Process::Priority state)
|
||||||
|
{
|
||||||
|
switch (state) {
|
||||||
|
case Process::LowPriority: return "Low";
|
||||||
|
case Process::NormalPriority: return "Normal";
|
||||||
|
case Process::HighPriority: return "High";
|
||||||
|
}
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
extern void block(Process::State);
|
extern void block(Process::State);
|
||||||
extern void sleep(dword ticks);
|
extern void sleep(dword ticks);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,18 @@
|
||||||
//#define LOG_EVERY_CONTEXT_SWITCH
|
//#define LOG_EVERY_CONTEXT_SWITCH
|
||||||
//#define SCHEDULER_DEBUG
|
//#define SCHEDULER_DEBUG
|
||||||
|
|
||||||
static const dword time_slice = 20; // *1ms
|
static dword time_slice_for(Process::Priority priority)
|
||||||
|
{
|
||||||
|
// One time slice unit == 1ms
|
||||||
|
switch (priority) {
|
||||||
|
case Process::LowPriority:
|
||||||
|
return 5;
|
||||||
|
case Process::NormalPriority:
|
||||||
|
return 15;
|
||||||
|
case Process::HighPriority:
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Process* current;
|
Process* current;
|
||||||
Process* g_last_fpu_process;
|
Process* g_last_fpu_process;
|
||||||
|
@ -244,7 +255,7 @@ void Scheduler::switch_now()
|
||||||
|
|
||||||
bool Scheduler::context_switch(Process& process)
|
bool Scheduler::context_switch(Process& process)
|
||||||
{
|
{
|
||||||
process.set_ticks_left(time_slice);
|
process.set_ticks_left(time_slice_for(process.priority()));
|
||||||
process.did_schedule();
|
process.did_schedule();
|
||||||
|
|
||||||
if (current == &process)
|
if (current == &process)
|
||||||
|
|
|
@ -187,6 +187,7 @@ void init()
|
||||||
});
|
});
|
||||||
Process::create_kernel_process("Finalizer", [] {
|
Process::create_kernel_process("Finalizer", [] {
|
||||||
g_finalizer = current;
|
g_finalizer = current;
|
||||||
|
current->set_priority(Process::LowPriority);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Process::finalize_dying_processes();
|
Process::finalize_dying_processes();
|
||||||
current->block(Process::BlockedLurking);
|
current->block(Process::BlockedLurking);
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct Process {
|
||||||
String name;
|
String name;
|
||||||
String state;
|
String state;
|
||||||
String user;
|
String user;
|
||||||
|
String priority;
|
||||||
unsigned linear;
|
unsigned linear;
|
||||||
unsigned committed;
|
unsigned committed;
|
||||||
unsigned in_bitmaps;
|
unsigned in_bitmaps;
|
||||||
|
@ -43,7 +44,7 @@ static Snapshot get_snapshot()
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
break;
|
break;
|
||||||
auto parts = String(buf, Chomp).split(',');
|
auto parts = String(buf, Chomp).split(',');
|
||||||
if (parts.size() < 17)
|
if (parts.size() < 18)
|
||||||
break;
|
break;
|
||||||
bool ok;
|
bool ok;
|
||||||
pid_t pid = parts[0].to_uint(ok);
|
pid_t pid = parts[0].to_uint(ok);
|
||||||
|
@ -57,6 +58,7 @@ static Snapshot get_snapshot()
|
||||||
unsigned uid = parts[5].to_uint(ok);
|
unsigned uid = parts[5].to_uint(ok);
|
||||||
ASSERT(ok);
|
ASSERT(ok);
|
||||||
process.user = s_usernames->get(uid);
|
process.user = s_usernames->get(uid);
|
||||||
|
process.priority = parts[17];
|
||||||
process.state = parts[7];
|
process.state = parts[7];
|
||||||
process.name = parts[11];
|
process.name = parts[11];
|
||||||
process.linear = parts[12].to_uint(ok);
|
process.linear = parts[12].to_uint(ok);
|
||||||
|
@ -88,8 +90,9 @@ int main(int, char**)
|
||||||
auto sum_diff = current.sum_nsched - prev.sum_nsched;
|
auto sum_diff = current.sum_nsched - prev.sum_nsched;
|
||||||
|
|
||||||
printf("\033[3J\033[H\033[2J");
|
printf("\033[3J\033[H\033[2J");
|
||||||
printf("\033[47;30m%6s % 8s %8s %6s %6s %6s %4s %s\033[K\033[0m\n",
|
printf("\033[47;30m%6s %3s % 8s % 8s %6s %6s %6s %4s %s\033[K\033[0m\n",
|
||||||
"PID",
|
"PID",
|
||||||
|
"PRI",
|
||||||
"USER",
|
"USER",
|
||||||
"STATE",
|
"STATE",
|
||||||
"LINEAR",
|
"LINEAR",
|
||||||
|
@ -120,8 +123,9 @@ int main(int, char**)
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto* process : processes) {
|
for (auto* process : processes) {
|
||||||
printf("%6d % 8s %8s %6u %6u %6u %2u.%1u %s\n",
|
printf("%6d %c % 8s % 8s %6u %6u %6u %2u.%1u %s\n",
|
||||||
process->pid,
|
process->pid,
|
||||||
|
process->priority[0],
|
||||||
process->user.characters(),
|
process->user.characters(),
|
||||||
process->state.characters(),
|
process->state.characters(),
|
||||||
process->linear / 1024,
|
process->linear / 1024,
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
void WindowServer_main()
|
void WindowServer_main()
|
||||||
{
|
{
|
||||||
|
current->set_priority(Process::HighPriority);
|
||||||
auto info = current->set_video_resolution(1024, 768);
|
auto info = current->set_video_resolution(1024, 768);
|
||||||
|
|
||||||
dbgprintf("Screen is %ux%ux%ubpp\n", info.width, info.height, info.bpp);
|
dbgprintf("Screen is %ux%ux%ubpp\n", info.width, info.height, info.bpp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue