summaryrefslogtreecommitdiff
path: root/Kernel/Scheduler.h
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-07-14 12:05:59 -0600
committerAndreas Kling <kling@serenityos.org>2021-07-18 22:08:26 +0200
commit7e77a2ec40bc339f41e75aa9fdc6744df449612c (patch)
tree374e613b57185d92b6ce7903d8c5c6cd907f7b7a /Kernel/Scheduler.h
parentef85c4f7473e50c936a67a762c158833b9f0160a (diff)
downloadserenity-7e77a2ec40bc339f41e75aa9fdc6744df449612c.zip
Everywhere: Improve CPU usage calculation
As threads come and go, we can't simply account for how many time slices the threads at any given point may have been using. We need to also account for threads that have since disappeared. This means we also need to track how many time slices we have expired globally. However, because this doesn't account for context switches outside of the system timer tick values may still be under-reported. To solve this we will need to track more accurate time information on each context switch. This also fixes top's cpu usage calculation which was still based on the number of context switches. Fixes #6473
Diffstat (limited to 'Kernel/Scheduler.h')
-rw-r--r--Kernel/Scheduler.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/Kernel/Scheduler.h b/Kernel/Scheduler.h
index c703df83a6..3cabdaa9b7 100644
--- a/Kernel/Scheduler.h
+++ b/Kernel/Scheduler.h
@@ -24,6 +24,11 @@ extern WaitQueue* g_finalizer_wait_queue;
extern Atomic<bool> g_finalizer_has_work;
extern RecursiveSpinLock g_scheduler_lock;
+struct TotalTicksScheduled {
+ u64 total { 0 };
+ u64 total_kernel { 0 };
+};
+
class Scheduler {
public:
static void initialize();
@@ -49,6 +54,7 @@ public:
static void queue_runnable_thread(Thread&);
static void dump_scheduler_state(bool = false);
static bool is_initialized();
+ static TotalTicksScheduled get_total_ticks_scheduled();
};
}