From a9041a5526eddc631b94bac86c09a47e60a3b4e1 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 3 Feb 2012 00:00:00 -0600 Subject: [PATCH] top: reduce % CPU distortions when a core was turned off This patch provides for cpu cores which can be turned off completely when idle (Nehalem, etc.) thus registering very few or no tics since the last update cycle. When CPU_ZEROTICS is not defined (the default), any displayed cpu with less than a certain amount of total tics will show as 100% idle. That amount is tempered by the delay interval and total number of cpus. This commit also satisfies the Debian 'top_nohz' patch (11/24/09) in a slightly more efficient manner. That patch concerned kernels built with CONFIG_NO_HZ. Reference: http://www.freelists.org/post/procps/CStates-handling-new-switch,4 --- top/top.c | 7 ++++++- top/top.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/top/top.c b/top/top.c index 172507f8..8d24962e 100644 --- a/top/top.c +++ b/top/top.c @@ -3324,13 +3324,18 @@ static void summaryhlp (CPU_t *cpu, const char *pfx) { s_frme = TRIMz(cpu->cur.s - cpu->sav.s); n_frme = TRIMz(cpu->cur.n - cpu->sav.n); i_frme = TRIMz(cpu->cur.i - cpu->sav.i); - if ((u_frme == 0) && (i_frme == 0)) i_frme = 100; w_frme = TRIMz(cpu->cur.w - cpu->sav.w); x_frme = TRIMz(cpu->cur.x - cpu->sav.x); y_frme = TRIMz(cpu->cur.y - cpu->sav.y); z_frme = TRIMz(cpu->cur.z - cpu->sav.z); tot_frme = u_frme + s_frme + n_frme + i_frme + w_frme + x_frme + y_frme + z_frme; +#ifdef CPU_ZEROTICS if (1 > tot_frme) tot_frme = 1; +#else + if (tot_frme < ((smp_num_cpus * 10) * Rc.delay_time)) + tot_frme = u_frme = s_frme = n_frme = i_frme = w_frme = x_frme = y_frme = z_frme = 0; + if (1 > tot_frme) i_frme = tot_frme = 1; +#endif scale = 100.0 / (float)tot_frme; /* display some kinda' cpu state percentages diff --git a/top/top.h b/top/top.h index 0abf9552..c4daa1bb 100644 --- a/top/top.h +++ b/top/top.h @@ -27,6 +27,7 @@ //#define ATEOJ_RPTSTD /* report on misc stuff, at end-of-job */ //#define CASEUP_HEXES /* show any hex values in upper case */ //#define CASEUP_SUFIX /* show time/mem/cnts suffix in upper case */ +//#define CPU_ZEROTICS /* tolerate few tics when cpu off vs. idle */ //#define EQUCOLHDRYES /* yes, do equalize column header lengths */ //#define OFF_HST_HASH /* use BOTH qsort+bsrch vs. hashing scheme */ //#define OFF_STDIOLBF /* disable our own stdout _IOFBF override */