File sysstat-compute-global-CPU-stats-2.patch of Package sysstat.7878
From 9057b41fcbf509a6dd2cefe8be31c7181e3c905c Mon Sep 17 00:00:00 2001
From: Sebastien GODARD <sysstat@users.noreply.github.com>
Date: Sat, 10 Mar 2018 15:08:49 +0100
Subject: [PATCH] Change condition used in workaround for CPU coming back
online
Compare counter's value to ULLONG_MAX - 0x7ffff (and not ULLONG_MAX &
0x80000) to guess if it has overflown.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
---
rd_stats.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: sysstat-10.2.1/common.c
===================================================================
--- sysstat-10.2.1.orig/common.c 2014-01-19 10:01:01.000000000 +0000
+++ sysstat-10.2.1/common.c 2018-06-20 10:29:26.722239561 +0000
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <limits.h>
#include <time.h>
#include <errno.h>
#include <unistd.h> /* For STDOUT_FILENO, among others */
@@ -601,6 +602,24 @@ unsigned long long get_per_cpu_interval(
}
/*
+ * Workaround for CPU coming back online: With recent kernels
+ * some fields (user, nice, system) restart from their previous value,
+ * whereas others (idle, iowait) restart from zero.
+ * For the latter we need to set their previous value to zero to
+ * avoid getting an interval value < 0.
+ * (I don't know how the other fields like hardirq, steal... behave).
+ * Don't assume the CPU has come back from offline state if previous
+ * value was greater than ULLONG_MAX - 0x7ffff (the counter probably
+ * overflew).
+ */
+ if ((scc->cpu_idle < scp->cpu_idle) && (scp->cpu_idle < (ULLONG_MAX - 0x7ffff))) {
+ scp->cpu_idle = 0;
+ }
+ if ((scc->cpu_iowait < scp->cpu_iowait) && (scp->cpu_iowait < (ULLONG_MAX - 0x7ffff))) {
+ scp->cpu_iowait = 0;
+ }
+
+ /*
* Don't take cpu_guest and cpu_guest_nice into account
* because cpu_user and cpu_nice already include them.
*/