tolerate sparse CPU numbering
This commit is contained in:
parent
2b55ead81b
commit
e8b5f776a3
10
Makefile
10
Makefile
@ -110,6 +110,16 @@ check_gcc = $(shell if $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) dummy.c $(ALL_LDFLAGS
|
||||
|
||||
ALL_CFLAGS += $(call check_gcc,-Wdeclaration-after-statement,)
|
||||
ALL_CFLAGS += $(call check_gcc,-Wpadded,)
|
||||
ALL_CFLAGS += $(call check_gcc,-Wstrict-aliasing=2,)
|
||||
|
||||
# Adding -fno-gcse might be good for those files which
|
||||
# use computed goto.
|
||||
#ALL_CFLAGS += $(call check_gcc,-fno-gcse,)
|
||||
|
||||
# These are part of -O3 but we dislike -finline-functions.
|
||||
# Using -fno-inline-functions with -O3 would work too.
|
||||
ALL_CFLAGS += $(call check_gcc,-fweb,)
|
||||
ALL_CFLAGS += $(call check_gcc,-frename-registers,)
|
||||
|
||||
# Be 64-bit if at all possible. In a cross-compiling situation, one may
|
||||
# do "make m64=-m32 lib64=lib" to produce 32-bit executables. DO NOT
|
||||
|
4
NEWS
4
NEWS
@ -1,10 +1,12 @@
|
||||
procps-3.2.1 --> procps-3.2.2
|
||||
|
||||
now using gcc -fweb and -frename-registers options
|
||||
avoid warning about -lncurses when not linking -- thanks FLWM
|
||||
ps: personality-specific -x support (HP-UX and SVR4-MP)
|
||||
ps: k option, same as --sort
|
||||
vmstat: fixed -d
|
||||
top: try to handle terminals lacking rmam and smam
|
||||
top: try to handle terminals lacking rmam and smam #235003
|
||||
top: tolerate sparse CPU numbering
|
||||
|
||||
procps-3.2.0 --> procps-3.2.1
|
||||
|
||||
|
33
top.c
33
top.c
@ -78,9 +78,8 @@ static RCF_t Rc = DEF_RCFILE;
|
||||
static unsigned Page_size;
|
||||
static unsigned page_to_kb_shift;
|
||||
|
||||
/* SMP, Irix/Solaris mode, Linux 2.5.xx support */
|
||||
static int Cpu_tot,
|
||||
*Cpu_map;
|
||||
/* SMP Irix/Solaris mode */
|
||||
static int Cpu_tot;
|
||||
/* assume no IO-wait stats, overridden if linux 2.5.41 */
|
||||
static const char *States_fmts = STATES_line2x4;
|
||||
|
||||
@ -928,7 +927,7 @@ static CPU_t *cpus_refresh (CPU_t *cpus)
|
||||
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
|
||||
cpus[Cpu_tot].x = 0; // FIXME: can't tell by kernel version number
|
||||
cpus[Cpu_tot].y = 0; // FIXME: can't tell by kernel version number
|
||||
num = sscanf(buf, CPU_FMTS_JUST1,
|
||||
num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
|
||||
&cpus[Cpu_tot].u,
|
||||
&cpus[Cpu_tot].n,
|
||||
&cpus[Cpu_tot].s,
|
||||
@ -939,18 +938,20 @@ static CPU_t *cpus_refresh (CPU_t *cpus)
|
||||
);
|
||||
if (num < 4)
|
||||
std_err("failed /proc/stat read");
|
||||
|
||||
// and just in case we're 2.2.xx compiled without SMP support...
|
||||
if (Cpu_tot == 1) memcpy(cpus, &cpus[1], sizeof(CPU_t));
|
||||
if (Cpu_tot == 1) {
|
||||
cpus[1].id = 0;
|
||||
memcpy(cpus, &cpus[1], sizeof(CPU_t));
|
||||
}
|
||||
|
||||
// now value each separate cpu's tics
|
||||
for (i = 0; 1 < Cpu_tot && i < Cpu_tot; i++) {
|
||||
#ifdef PRETEND4CPUS
|
||||
rewind(fp);
|
||||
#endif
|
||||
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read");
|
||||
cpus[i].x = 0; // FIXME: can't tell by kernel version number
|
||||
cpus[i].y = 0; // FIXME: can't tell by kernel version number
|
||||
num = sscanf(buf, CPU_FMTS_MULTI,
|
||||
num = sscanf(buf, "cpu%u %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
|
||||
&cpus[i].id,
|
||||
&cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w, &cpus[i].x, &cpus[i].y
|
||||
);
|
||||
if (num < 4)
|
||||
@ -1535,13 +1536,8 @@ static const char *rc_write_whatever (void) {
|
||||
|
||||
/*###### Startup routines ##############################################*/
|
||||
|
||||
#ifdef PRETEND4CPUS
|
||||
#define smp_num_cpus 4
|
||||
#endif
|
||||
|
||||
/*
|
||||
* No mater what *they* say, we handle the really really BIG and
|
||||
* IMPORTANT stuff upon which all those lessor functions depend! */
|
||||
// No mater what *they* say, we handle the really really BIG and
|
||||
// IMPORTANT stuff upon which all those lessor functions depend!
|
||||
static void before (char *me)
|
||||
{
|
||||
int i;
|
||||
@ -1552,9 +1548,6 @@ static void before (char *me)
|
||||
|
||||
/* establish cpu particulars -- even bigger! */
|
||||
Cpu_tot = smp_num_cpus;
|
||||
Cpu_map = alloc_r(NULL, sizeof(int) * Cpu_tot);
|
||||
for (i = 0; i < Cpu_tot; i++)
|
||||
Cpu_map[i] = i;
|
||||
if (linux_version_code > LINUX_VERSION(2, 5, 41))
|
||||
States_fmts = STATES_line2x5;
|
||||
if (linux_version_code >= LINUX_VERSION(2, 6, 0)) // grrr... only some 2.6.0-testX :-(
|
||||
@ -2875,7 +2868,7 @@ static proc_t **summary_show (void)
|
||||
char tmp[SMLBUFSIZ];
|
||||
// display each cpu's states separately
|
||||
for (i = 0; i < Cpu_tot; i++) {
|
||||
snprintf(tmp, sizeof(tmp), " Cpu%-2d:", Rc.mode_irixps ? i : Cpu_map[i]);
|
||||
snprintf(tmp, sizeof(tmp), "Cpu%-3d:", smpcpu[i].id);
|
||||
summaryhlp(&smpcpu[i], tmp);
|
||||
}
|
||||
}
|
||||
|
11
top.h
11
top.h
@ -33,7 +33,6 @@
|
||||
// Development/Debugging defines -----------------------------------
|
||||
//#define ATEOJ_REPORT // report a bunch of stuff, at end-of-job
|
||||
//#define PRETEND2_5_X // pretend we're linux 2.5.x (for IO-wait)
|
||||
//#define PRETEND4CPUS // pretend we're smp with 4 ticsers (sic)
|
||||
//#define PRETENDNOCAP // use a terminal without essential caps
|
||||
//#define STDOUT_IOLBF // disable our own stdout _IOFBF override
|
||||
|
||||
@ -197,6 +196,7 @@ typedef struct HST_t {
|
||||
typedef struct CPU_t {
|
||||
TIC_t u, n, s, i, w, x, y; // as represented in /proc/stat
|
||||
TIC_t u_sav, s_sav, n_sav, i_sav, w_sav, x_sav, y_sav; // in the order of our display
|
||||
unsigned id; // the CPU ID number
|
||||
} CPU_t;
|
||||
|
||||
// These 2 types support rcfile compatibility
|
||||
@ -355,15 +355,6 @@ typedef struct WIN_t {
|
||||
"Usr", USR_FIELDS } \
|
||||
} }
|
||||
|
||||
// These are the possible fscanf formats used in /proc/stat
|
||||
// reads during history processing.
|
||||
// ( 5th number only for Linux 2.5.41 and above ) */
|
||||
#define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
|
||||
#ifdef PRETEND4CPUS
|
||||
#define CPU_FMTS_MULTI CPU_FMTS_JUST1
|
||||
#else
|
||||
#define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
|
||||
#endif
|
||||
|
||||
// Summary Lines specially formatted string(s) --
|
||||
// see 'show_special' for syntax details + other cautions.
|
||||
|
Loading…
Reference in New Issue
Block a user