summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-07-14 21:46:32 -0600
committerAndreas Kling <kling@serenityos.org>2021-07-18 22:08:26 +0200
commita635ff4e600729fb7d12fdd16ac6ffbaa455bb30 (patch)
tree8625e110b4c9ca2510c3a8ac28b45bddae828af7 /Userland/Applications
parent7e77a2ec40bc339f41e75aa9fdc6744df449612c (diff)
downloadserenity-a635ff4e600729fb7d12fdd16ac6ffbaa455bb30.zip
Everywhere: Make tracking cpu usage independent from system ticks
This switches tracking CPU usage to more accurately measure time in user and kernel land using either the TSC or another time source. This will also come in handy when implementing a tickless kernel mode.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/SystemMonitor/ProcessModel.cpp32
-rw-r--r--Userland/Applications/SystemMonitor/ProcessModel.h10
2 files changed, 21 insertions, 21 deletions
diff --git a/Userland/Applications/SystemMonitor/ProcessModel.cpp b/Userland/Applications/SystemMonitor/ProcessModel.cpp
index 5f91c24449..65364ce2a3 100644
--- a/Userland/Applications/SystemMonitor/ProcessModel.cpp
+++ b/Userland/Applications/SystemMonitor/ProcessModel.cpp
@@ -319,15 +319,15 @@ void ProcessModel::update()
auto all_processes = Core::ProcessStatisticsReader::get_all(m_proc_all);
HashTable<int> live_tids;
- u64 sum_ticks_scheduled = 0, sum_ticks_scheduled_kernel = 0;
- u64 total_ticks_scheduled_diff = 0;
+ u64 sum_time_scheduled = 0, sum_time_scheduled_kernel = 0;
+ u64 total_time_scheduled_diff = 0;
if (all_processes.has_value()) {
- if (m_has_total_ticks)
- total_ticks_scheduled_diff = all_processes->total_ticks_scheduled - m_total_ticks_scheduled;
+ if (m_has_total_scheduled_time)
+ total_time_scheduled_diff = all_processes->total_time_scheduled - m_total_time_scheduled;
- m_total_ticks_scheduled = all_processes->total_ticks_scheduled;
- m_total_ticks_scheduled_kernel = all_processes->total_ticks_scheduled_kernel;
- m_has_total_ticks = true;
+ m_total_time_scheduled = all_processes->total_time_scheduled;
+ m_total_time_scheduled_kernel = all_processes->total_time_scheduled_kernel;
+ m_has_total_scheduled_time = true;
for (auto& process : all_processes.value().processes) {
for (auto& thread : process.threads) {
@@ -361,14 +361,14 @@ void ProcessModel::update()
state.tid = thread.tid;
state.pgid = process.pgid;
state.sid = process.sid;
- state.ticks_user = thread.ticks_user;
- state.ticks_kernel = thread.ticks_kernel;
+ state.time_user = thread.time_user;
+ state.time_kernel = thread.time_kernel;
state.cpu = thread.cpu;
state.cpu_percent = 0;
state.priority = thread.priority;
state.state = thread.state;
- sum_ticks_scheduled += thread.ticks_user + thread.ticks_kernel;
- sum_ticks_scheduled_kernel += thread.ticks_kernel;
+ sum_time_scheduled += thread.time_user + thread.time_kernel;
+ sum_time_scheduled_kernel += thread.time_kernel;
{
auto pit = m_threads.find(thread.tid);
if (pit == m_threads.end())
@@ -397,11 +397,11 @@ void ProcessModel::update()
continue;
}
auto& thread = *it.value;
- u32 ticks_scheduled_diff = (thread.current_state.ticks_user + thread.current_state.ticks_kernel)
- - (thread.previous_state.ticks_user + thread.previous_state.ticks_kernel);
- u32 ticks_scheduled_diff_kernel = thread.current_state.ticks_kernel - thread.previous_state.ticks_kernel;
- thread.current_state.cpu_percent = total_ticks_scheduled_diff > 0 ? ((float)ticks_scheduled_diff * 100) / (float)total_ticks_scheduled_diff : 0;
- thread.current_state.cpu_percent_kernel = total_ticks_scheduled_diff > 0 ? ((float)ticks_scheduled_diff_kernel * 100) / (float)total_ticks_scheduled_diff : 0;
+ u32 time_scheduled_diff = (thread.current_state.time_user + thread.current_state.time_kernel)
+ - (thread.previous_state.time_user + thread.previous_state.time_kernel);
+ u32 time_scheduled_diff_kernel = thread.current_state.time_kernel - thread.previous_state.time_kernel;
+ thread.current_state.cpu_percent = total_time_scheduled_diff > 0 ? ((float)time_scheduled_diff * 100) / (float)total_time_scheduled_diff : 0;
+ thread.current_state.cpu_percent_kernel = total_time_scheduled_diff > 0 ? ((float)time_scheduled_diff_kernel * 100) / (float)total_time_scheduled_diff : 0;
if (it.value->current_state.pid != 0) {
auto& cpu_info = m_cpus[thread.current_state.cpu];
cpu_info.total_cpu_percent += thread.current_state.cpu_percent;
diff --git a/Userland/Applications/SystemMonitor/ProcessModel.h b/Userland/Applications/SystemMonitor/ProcessModel.h
index 13993ff257..c679e51d75 100644
--- a/Userland/Applications/SystemMonitor/ProcessModel.h
+++ b/Userland/Applications/SystemMonitor/ProcessModel.h
@@ -88,8 +88,8 @@ private:
pid_t ppid;
pid_t pgid;
pid_t sid;
- unsigned ticks_user;
- unsigned ticks_kernel;
+ u64 time_user;
+ u64 time_kernel;
bool kernel;
String executable;
String name;
@@ -129,7 +129,7 @@ private:
Vector<int> m_tids;
RefPtr<Core::File> m_proc_all;
GUI::Icon m_kernel_process_icon;
- u64 m_total_ticks_scheduled { 0 };
- u64 m_total_ticks_scheduled_kernel { 0 };
- bool m_has_total_ticks { false };
+ u64 m_total_time_scheduled { 0 };
+ u64 m_total_time_scheduled_kernel { 0 };
+ bool m_has_total_scheduled_time { false };
};