]> granicus.if.org Git - procps-ng/commitdiff
library: allow negative system DELTA stats, <STAT> api
authorJim Warner <james.warner@comcast.net>
Fri, 13 Dec 2019 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Sun, 5 Jan 2020 22:11:20 +0000 (09:11 +1100)
All TIC delta fields are checked for possible negative
results and set to zero when found. This is done so as
to protect against potential anomalies which depend on
kernel version and/or toggling cpus offline or online.

[ it's probably unnecessary with the latest kernels, ]
[ except for iowait. documentation suggests it might ]
[ decrease which would then create a negative delta. ]

The same approach is employed for most of the 'system'
deltas (ctxt, intr & procs_created). However, with two
of the fields (procs_blocked & procs_running) negative
results were allowed. But it now seems such a division
is unwise so this patch will allow all to go negative.

[ rather than force any 'system' delta value to show ]
[ what's logical, we'll now let all reflect reality. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/stat.c

index 66b1b88c238593804338005115776fa1d13f7cf9..c837dd4b500218926826cc3eced9c1234efa80f7 100644 (file)
@@ -154,8 +154,7 @@ struct stat_info {
     (void)S; R->result. t = ( T->new. x - T->old. x ); \
     if (R->result. t < 0) R->result. t = 0; }
 #define SYSsetH(e,t,x) setDECL(e) { \
-    (void)T; R->result. t = ( S->new. x - S->old. x ); \
-    if (R->result. t < 0) R->result. t = 0; }
+    (void)T; R->result. t = ( S->new. x - S->old. x ); }
 
 setDECL(noop)  { (void)R; (void)S; (void)T; }
 setDECL(extra) { (void)S; (void)T; R->result.ull_int = 0; }
@@ -207,9 +206,9 @@ SYS_set(SYS_TIME_OF_BOOT,         ul_int,   btime)
 
 SYSsetH(SYS_DELTA_CTX_SWITCHES,   s_int,    ctxt)
 SYSsetH(SYS_DELTA_INTERRUPTS,     s_int,    intr)
-setDECL(SYS_DELTA_PROC_BLOCKED) { (void)T; R->result.s_int = S->new.procs_blocked - S->old.procs_blocked; }
+SYSsetH(SYS_DELTA_PROC_BLOCKED,   s_int,    procs_blocked)
 SYSsetH(SYS_DELTA_PROC_CREATED,   s_int,    procs_created)
-setDECL(SYS_DELTA_PROC_RUNNING) { (void)T; R->result.s_int = S->new.procs_running - S->old.procs_running; }
+SYSsetH(SYS_DELTA_PROC_RUNNING,   s_int,    procs_running)
 
 #undef setDECL
 #undef TIC_set