top: tweak the new 'reduce % CPU distortions' algorithm

The original approach to potential % CPU distortion due
to Nehalem type cores being turned off completely when
idle worked ok until the user typed something.

At that point, elapsed tics would no longer equal the
calculated value producing an undesirable 100% idle
condition until the next update or <Enter/Space> key.

This commit employs actual elapsed tics in determining
whether a cpu should be considered idle and thus makes
top's individual cpu display immune to user keystrokes.
This commit is contained in:
Jim Warner 2012-02-07 10:10:10 -06:00 committed by Craig Small
parent a9041a5526
commit 9e7dd43ab7
2 changed files with 8 additions and 1 deletions

View File

@ -1823,6 +1823,9 @@ static CPU_t *cpus_refresh (CPU_t *cpus) {
, &cpus[Cpu_faux_tot].cur.i, &cpus[Cpu_faux_tot].cur.w, &cpus[Cpu_faux_tot].cur.x , &cpus[Cpu_faux_tot].cur.i, &cpus[Cpu_faux_tot].cur.w, &cpus[Cpu_faux_tot].cur.x
, &cpus[Cpu_faux_tot].cur.y, &cpus[Cpu_faux_tot].cur.z)) , &cpus[Cpu_faux_tot].cur.y, &cpus[Cpu_faux_tot].cur.z))
error_exit(N_txt(FAIL_statget_txt)); error_exit(N_txt(FAIL_statget_txt));
cpus[Cpu_faux_tot].cur.tot = cpus[Cpu_faux_tot].cur.u + cpus[Cpu_faux_tot].cur.s
+ cpus[Cpu_faux_tot].cur.n + cpus[Cpu_faux_tot].cur.i + cpus[Cpu_faux_tot].cur.w
+ cpus[Cpu_faux_tot].cur.x + cpus[Cpu_faux_tot].cur.y + cpus[Cpu_faux_tot].cur.z;
// now value each separate cpu's tics, maybe // now value each separate cpu's tics, maybe
for (i = 0; i < Cpu_faux_tot && i < Screen_rows; i++) { for (i = 0; i < Cpu_faux_tot && i < Screen_rows; i++) {
@ -1841,6 +1844,9 @@ static CPU_t *cpus_refresh (CPU_t *cpus) {
memmove(&cpus[i], &cpus[Cpu_faux_tot], sizeof(CPU_t)); memmove(&cpus[i], &cpus[Cpu_faux_tot], sizeof(CPU_t));
break; // tolerate cpus taken offline break; // tolerate cpus taken offline
} }
cpus[i].cur.tot = cpus[i].cur.u + cpus[i].cur.s
+ cpus[i].cur.n + cpus[i].cur.i + cpus[i].cur.w
+ cpus[i].cur.x + cpus[i].cur.y + cpus[i].cur.z;
#ifdef PRETEND4CPUS #ifdef PRETEND4CPUS
cpus[i].id = i; cpus[i].id = i;
#endif #endif
@ -3332,7 +3338,7 @@ static void summaryhlp (CPU_t *cpu, const char *pfx) {
#ifdef CPU_ZEROTICS #ifdef CPU_ZEROTICS
if (1 > tot_frme) tot_frme = 1; if (1 > tot_frme) tot_frme = 1;
#else #else
if (tot_frme < ((smp_num_cpus * 10) * Rc.delay_time)) if (tot_frme < (cpu->cur.tot - cpu->sav.tot) / 10)
tot_frme = u_frme = s_frme = n_frme = i_frme = w_frme = x_frme = y_frme = z_frme = 0; 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; if (1 > tot_frme) i_frme = tot_frme = 1;
#endif #endif

View File

@ -214,6 +214,7 @@ typedef struct CT_t {
2.6.0 kernel: x == hi (hardware irq time), y == si (software irq time) 2.6.0 kernel: x == hi (hardware irq time), y == si (software irq time)
2.6.11 kernel: z == st (virtual steal time) */ 2.6.11 kernel: z == st (virtual steal time) */
TIC_t u, n, s, i, w, x, y, z; // as represented in /proc/stat TIC_t u, n, s, i, w, x, y, z; // as represented in /proc/stat
SIC_t tot; // total of above
} CT_t; } CT_t;
typedef struct CPU_t { typedef struct CPU_t {