top: make more responsive when toggling cpu off/online

Using the <STAT> api under the newlib branch, that top
program is very responsive to changes in the number of
on-line cpus. However under the master branch this top
program is very responsive only to losses of some cpu.

When a cpu is brought back on-line potential delays of
60 seconds could be encountered. That delay was simply
an attempt to reduce costs and reflected the erroneous
assumption that adding a cpu required physical effort.

So without redesigning the cpu refresh code to emulate
that of newlib, this commit just reduces the potential
delay to 3 seconds (the same that is used for memory).

[ As an aside, if one wants to have their confidence ]
[ in that htop program badly shaken, try taking some ]
[ cpus off-line & on-line again while it is running. ]

[ Poor ol' htop just continues to report results for ]
[ whatever were the cpus when started. Nice feature, ]
[ but I wonder where those phantom results are from. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-06-01 00:00:00 -05:00 committed by Craig Small
parent ac8f49e79e
commit 10503c03d4

View File

@ -2694,30 +2694,26 @@ static void procs_refresh (void) {
* portion of libproc. In support of those hotpluggable resources, * portion of libproc. In support of those hotpluggable resources,
* the sampling frequencies are reduced so as to minimize overhead. */ * the sampling frequencies are reduced so as to minimize overhead. */
static void sysinfo_refresh (int forced) { static void sysinfo_refresh (int forced) {
static time_t mem_secs, cpu_secs; static time_t sav_secs;
time_t cur_secs; time_t cur_secs;
if (forced) if (forced)
mem_secs = cpu_secs = 0; sav_secs = 0;
cur_secs = time(NULL); cur_secs = time(NULL);
/*** hotplug_acclimated ***/ /*** hotplug_acclimated ***/
if (3 <= cur_secs - mem_secs) { if (3 <= cur_secs - sav_secs) {
meminfo(); meminfo();
mem_secs = cur_secs;
}
#ifndef PRETEND8CPUS #ifndef PRETEND8CPUS
/*** hotplug_acclimated ***/
if (60 <= cur_secs - cpu_secs) {
cpuinfo(); cpuinfo();
Cpu_faux_tot = smp_num_cpus; Cpu_faux_tot = smp_num_cpus;
cpu_secs = cur_secs;
#ifndef NUMA_DISABLE #ifndef NUMA_DISABLE
if (Libnuma_handle) if (Libnuma_handle)
Numa_node_tot = Numa_max_node() + 1; Numa_node_tot = Numa_max_node() + 1;
#endif #endif
}
#endif #endif
sav_secs = cur_secs;
}
} // end: sysinfo_refresh } // end: sysinfo_refresh
/*###### Inspect Other Output ##########################################*/ /*###### Inspect Other Output ##########################################*/