=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/top/display.c,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- src/usr.bin/top/display.c 2018/01/04 17:44:20 1.54 +++ src/usr.bin/top/display.c 2018/09/26 17:23:13 1.55 @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.54 2018/01/04 17:44:20 deraadt Exp $ */ +/* $OpenBSD: display.c,v 1.55 2018/09/26 17:23:13 cheloha Exp $ */ /* * Top users/processes display for Unix @@ -125,9 +125,11 @@ int display_resize(void) { - int display_lines; - int cpu_lines = (combine_cpus ? 1 : ncpu); + int cpu_lines, display_lines, ncpuonline; + ncpuonline = getncpuonline(); + cpu_lines = (combine_cpus ? 1 : ncpuonline); + y_mem = 2 + cpu_lines; y_header = 4 + cpu_lines; y_procs = 5 + cpu_lines; @@ -136,7 +138,7 @@ /* if operating in "dumb" mode, we only need one line */ display_lines = smart_terminal ? screen_length - y_procs : 1; - y_idlecursor = y_message = 3 + (combine_cpus ? 1 : ncpu); + y_idlecursor = y_message = 3 + cpu_lines; if (screen_length <= y_message) y_idlecursor = y_message = screen_length - 1; @@ -377,13 +379,19 @@ } void -i_cpustates(int64_t *ostates) +i_cpustates(int64_t *ostates, int *online) { - int i, first, cpu; + int i, first, cpu, ncpuonline; double value; int64_t *states; char **names, *thisname; + ncpuonline = 0; + for (i = 0; i < ncpu; i++) { + if (online[i]) + ncpuonline++; + } + if (combine_cpus) { static double *values; if (!values) { @@ -393,6 +401,8 @@ } memset(values, 0, num_cpustates * sizeof(*values)); for (cpu = 0; cpu < ncpu; cpu++) { + if (!online[cpu]) + continue; names = cpustate_names; states = ostates + (CPUSTATES * cpu); i = 0; @@ -409,11 +419,11 @@ first = 0; move(2, 0); clrtoeol(); - printwp("%-3d CPUs: ", ncpu); + printwp("%-3d CPUs: ", ncpuonline); while ((thisname = *names++) != NULL) { if (*thisname != '\0') { - value = values[i++] / ncpu; + value = values[i++] / ncpuonline; /* if percentage is >= 1000, print it as 100% */ printwp((value >= 1000 ? "%s%4.0f%% %s" : "%s%4.1f%% %s"), first++ == 0 ? "" : ", ", @@ -430,13 +440,20 @@ first = 0; states = ostates + (CPUSTATES * cpu); - if (screen_length > 2 + cpu || !smart_terminal) { + if ((screen_length > 2 + cpu && 2 + cpu < y_mem) || + !smart_terminal) { move(2 + cpu, 0); clrtoeol(); addstrp(cpustates_tag(cpu)); while ((thisname = *names++) != NULL) { if (*thisname != '\0') { + if (!online[cpu]) { + printwp("%s%5s %s", + first++ == 0 ? "" : ", ", + "-", thisname); + continue; + } /* retrieve the value and remember it */ value = *states++;