File gsm-fix-inaccurate-cpu-values.patch of Package gnome-system-monitor

From 9224515cd6b19ba2dc59afe14684749b4dbf0349 Mon Sep 17 00:00:00 2001
From: Daniel van Vugt <daniel.van.vugt@canonical.com>
Date: Fri, 27 Oct 2017 19:11:33 +0800
Subject: [PATCH] Fix inaccurate %CPU values in the Processes table
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Multi-core machines were displaying inaccurate %CPU values due to a
loss of precision from performing integer division before multiplication.
This changes the order of operations so that no precision is lost, and
now all machines will display process %CPU values to within 1% accuracy.

https://bugzilla.gnome.org/show_bug.cgi?id=788922
Signed-off-by: BenoƮt Dejean <bdejean@gmail.com>
---
 src/proctable.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/proctable.cpp b/src/proctable.cpp
index e41d6d08..c37a48b2 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -917,11 +917,13 @@ update_info (GsmApplication *app, ProcInfo *info)
     guint64 difference = proctime.rtime - info->cpu_time;
     if (difference > 0) 
         info->status = GLIBTOP_PROCESS_RUNNING;
-    info->pcpu = difference * 100 / app->cpu_total_time;
-    info->pcpu = MIN(info->pcpu, 100);
 
+    guint cpu_scale = 100;
     if (not app->config.solaris_mode)
-        info->pcpu *= app->config.num_cpus;
+        cpu_scale *= app->config.num_cpus;
+
+    info->pcpu = difference * cpu_scale / app->cpu_total_time;
+    info->pcpu = MIN(info->pcpu, cpu_scale);
 
     app->processes.cpu_times[info->pid] = info->cpu_time = proctime.rtime;
     info->nice = procuid.nice;
-- 
2.15.0