diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-30 20:10:00 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-30 20:10:00 +0100 |
commit | a69734bf2e41c9a48692bef867a92a75991eb0c9 (patch) | |
tree | cf96c6ca70105f3e0ac3ba61c55cb0c58db40871 | |
parent | 0dea0fd06f16490eb4cac567d4fb0151835f2e86 (diff) | |
download | serenity-a69734bf2e41c9a48692bef867a92a75991eb0c9.zip |
Kernel: Also add a process boosting mechanism
Let's also have set_process_boost() for giving all threads in a process
the same boost.
-rw-r--r-- | Kernel/Process.cpp | 14 | ||||
-rw-r--r-- | Kernel/Process.h | 10 | ||||
-rw-r--r-- | Kernel/Syscall.h | 3 | ||||
-rw-r--r-- | Kernel/Thread.h | 2 | ||||
-rw-r--r-- | Libraries/LibC/serenity.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibC/serenity.h | 1 |
6 files changed, 33 insertions, 2 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 7196f44e3f..779c42f6a7 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -3922,3 +3922,17 @@ int Process::sys$set_thread_boost(int tid, int amount) thread->set_priority_boost(amount); return 0; } + +int Process::sys$set_process_boost(pid_t pid, int amount) +{ + if (amount < 0 || amount > 20) + return -EINVAL; + InterruptDisabler disabler; + auto* process = Process::from_pid(pid); + if (!process || process->is_dead()) + return -ESRCH; + if (!is_superuser() && process->uid() != euid()) + return -EPERM; + process->m_priority_boost = amount; + return 0; +} diff --git a/Kernel/Process.h b/Kernel/Process.h index 5694f59b03..d91c5668a1 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -235,6 +235,7 @@ public: void* sys$get_kernel_info_page(); int sys$futex(const Syscall::SC_futex_params*); int sys$set_thread_boost(int tid, int amount); + int sys$set_process_boost(pid_t, int amount); static void initialize(); @@ -308,6 +309,8 @@ public: int icon_id() const { return m_icon_id; } + u32 priority_boost() const { return m_priority_boost; } + private: friend class MemoryManager; friend class Scheduler; @@ -396,6 +399,8 @@ private: int m_icon_id { -1 }; + u32 m_priority_boost { 0 }; + WaitQueue& futex_queue(i32*); HashMap<u32, OwnPtr<WaitQueue>> m_futex_queues; }; @@ -520,3 +525,8 @@ inline const LogStream& operator<<(const LogStream& stream, const Process& proce { return stream << process.name() << '(' << process.pid() << ')'; } + +inline u32 Thread::effective_priority() const +{ + return m_priority + m_process.priority_boost() + m_priority_boost + m_extra_priority; +} diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 7a595b7c81..3661d9a594 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -152,7 +152,8 @@ typedef u32 socklen_t; __ENUMERATE_SYSCALL(profiling_disable) \ __ENUMERATE_SYSCALL(get_kernel_info_page) \ __ENUMERATE_SYSCALL(futex) \ - __ENUMERATE_SYSCALL(set_thread_boost) + __ENUMERATE_SYSCALL(set_thread_boost) \ + __ENUMERATE_SYSCALL(set_process_boost) namespace Syscall { diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 681401909d..ff1a4d8659 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -65,7 +65,7 @@ public: void set_priority_boost(u32 boost) { m_priority_boost = boost; } u32 priority_boost() const { return m_priority_boost; } - u32 effective_priority() const { return m_priority + m_priority_boost + m_extra_priority; } + u32 effective_priority() const; void set_joinable(bool j) { m_is_joinable = j; } bool is_joinable() const { return m_is_joinable; } diff --git a/Libraries/LibC/serenity.cpp b/Libraries/LibC/serenity.cpp index 379036f919..5b47f6ae41 100644 --- a/Libraries/LibC/serenity.cpp +++ b/Libraries/LibC/serenity.cpp @@ -34,6 +34,11 @@ int set_thread_boost(int tid, int amount) __RETURN_WITH_ERRNO(rc, rc, -1); } +int set_process_boost(int tid, int amount) +{ + int rc = syscall(SC_set_process_boost, tid, amount); + __RETURN_WITH_ERRNO(rc, rc, -1); +} int futex(int32_t* userspace_address, int futex_op, int32_t value, const struct timespec* timeout) { diff --git a/Libraries/LibC/serenity.h b/Libraries/LibC/serenity.h index fbc2750787..634d804502 100644 --- a/Libraries/LibC/serenity.h +++ b/Libraries/LibC/serenity.h @@ -51,6 +51,7 @@ int profiling_disable(pid_t); #define THREAD_PRIORITY_MAX 99 int set_thread_boost(int tid, int amount); +int set_process_boost(pid_t, int amount); #define FUTEX_WAIT 1 #define FUTEX_WAKE 2 |