diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-08 12:34:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-08 14:24:54 +0200 |
commit | 374972578da58ea6f53373f4fcb85200e565bf7a (patch) | |
tree | c867274de2b61b4b3d0a35f0ad01f07edbc4d677 /Kernel/Scheduler.cpp | |
parent | a425f421acd88792ed92a40c6604fe15c33a5b29 (diff) | |
download | serenity-374972578da58ea6f53373f4fcb85200e565bf7a.zip |
Kernel: Port the scheduler's time tracking to SpinLockProtectedValue
Diffstat (limited to 'Kernel/Scheduler.cpp')
-rw-r--r-- | Kernel/Scheduler.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 6846748b93..64d929e33b 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -55,8 +55,7 @@ struct ThreadReadyQueues { static Singleton<SpinLockProtectedValue<ThreadReadyQueues>> g_ready_queues; -static TotalTimeScheduled g_total_time_scheduled; -static SpinLock<u8> g_total_time_scheduled_lock; +static SpinLockProtectedValue<TotalTimeScheduled> g_total_time_scheduled; // The Scheduler::current_time function provides a current time for scheduling purposes, // which may not necessarily relate to wall time @@ -453,10 +452,11 @@ UNMAP_AFTER_INIT Thread* Scheduler::create_ap_idle_thread(u32 cpu) void Scheduler::add_time_scheduled(u64 time_to_add, bool is_kernel) { - ScopedSpinLock lock(g_total_time_scheduled_lock); - g_total_time_scheduled.total += time_to_add; - if (is_kernel) - g_total_time_scheduled.total_kernel += time_to_add; + g_total_time_scheduled.with([&](auto& total_time_scheduled) { + total_time_scheduled.total += time_to_add; + if (is_kernel) + total_time_scheduled.total_kernel += time_to_add; + }); } void Scheduler::timer_tick(const RegisterState& regs) @@ -563,8 +563,7 @@ bool Scheduler::is_initialized() TotalTimeScheduled Scheduler::get_total_time_scheduled() { - ScopedSpinLock lock(g_total_time_scheduled_lock); - return g_total_time_scheduled; + return g_total_time_scheduled.with([&](auto& total_time_scheduled) { return total_time_scheduled; }); } void dump_thread_list(bool with_stack_traces) |