top: tweak hotplugged response and frame refresh logic

For some time now, top has refrained from updating the
current number of cpus and memory totals with each and
every refresh cycle. Rather, to lessen overhead costs,
such values are updated periodically (5 min & 3 secs).

The delay in updating the cpu count was only important
with the addition of a cpu, since any loss is detected
immediately. And the large interval was chosen because
of the costs once associated with a glibc sysconf call
and an unlikely scenario of physically adding the cpu.

But the ease with which cpus can be taken offline then
placed back online under linux suggests that 5 minutes
may be too high. So, without addressing the likelihood
of that act, top is now more responsive in these ways:

1) that 5 minute interval has been reduced to 1 minute
2) any key, not just Enter/Space, refreshes cpus & mem

Note: we leave the man document as is, suggesting that
only the Enter/Space keys force an update for hotplug.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2014-05-27 00:00:00 -05:00 committed by Craig Small
parent 9e4986f4ea
commit 23ebb9f44d

View File

@ -2668,9 +2668,7 @@ static void procs_refresh (void) {
/*
* This serves as our interface to the memory & cpu count (sysinfo)
* portion of libproc. In support of those hotpluggable resources,
* the sampling frequencies are reduced so as to minimize overhead.
* We'll strive to verify the number of cpus every 5 minutes and the
* memory availability/usage every 3 seconds. */
* the sampling frequencies are reduced so as to minimize overhead. */
static void sysinfo_refresh (int forced) {
static time_t mem_secs, cpu_secs;
time_t cur_secs;
@ -2686,7 +2684,7 @@ static void sysinfo_refresh (int forced) {
}
#ifndef PRETEND8CPUS
/*** hotplug_acclimated ***/
if (300 <= cur_secs - cpu_secs) {
if (60 <= cur_secs - cpu_secs) {
cpuinfo();
Cpu_faux_tot = smp_num_cpus;
cpu_secs = cur_secs;
@ -4452,9 +4450,8 @@ static void keys_global (int ch) {
Rc.zero_suppress = !Rc.zero_suppress;
break;
case kbd_ENTER: // these two have the effect of waking us
case kbd_SPACE: // from 'select()', updating hotplugged
sysinfo_refresh(1); // resources and refreshing the display
break;
case kbd_SPACE: // from 'pselect', refreshing the display
break; // and updating any hot-plugged resources
default: // keep gcc happy
break;
}
@ -5000,6 +4997,7 @@ static void do_key (int ch) {
show_msg(N_txt(UNKNOWN_cmds_txt));
all_done:
sysinfo_refresh(1); // let's be more responsive to hot-pluggin'
putp((Cursor_state = Cap_curs_hide));
} // end: do_key
@ -5551,8 +5549,8 @@ static void frame_make (void) {
} else
putp(Batch ? "\n\n" : Cap_home);
procs_refresh();
sysinfo_refresh(0);
procs_refresh();
Tree_idx = Pseudo_row = Msg_row = scrlins = 0;
summary_show();