procps/bug-634071_procstat2.diff

115 lines
3.9 KiB
Diff

--- procps-3.2.7/proc/sysinfo.c 2010-08-20 15:59:36.991845322 -0500
+++ procps-3.2.7/proc/sysinfo.c 2010-08-25 09:01:49.867972887 -0500
@@ -26,8 +26,6 @@
#include <netinet/in.h> /* htons */
#endif
-long smp_num_cpus; /* number of CPUs */
-
#define BAD_OPEN_MESSAGE \
"Error: /proc must be mounted\n" \
" To mount /proc at boot you need an /etc/fstab line like:\n" \
@@ -169,7 +167,7 @@
setlocale(LC_NUMERIC, savelocale);
jiffies = user_j + nice_j + sys_j + other_j;
seconds = (up_1 + up_2) / 2;
- h = (unsigned)( (double)jiffies/seconds/smp_num_cpus );
+ h = (unsigned)( (double)jiffies/seconds/smp_num_cpus() );
/* actual values used by 2.4 kernels: 32 64 100 128 1000 1024 1200 */
switch(h){
case 9 ... 11 : Hertz = 10; break; /* S/390 (sometimes) */
@@ -234,9 +232,13 @@
return !!rc;
}
-static void init_libproc(void) __attribute__((constructor));
-static void init_libproc(void){
- have_privs = check_for_privs();
+long smp_num_cpus(void)
+{
+ static long _smp_num_cpus=-1; /* number of CPUs */
+
+ if (_smp_num_cpus != -1)
+ return(_smp_num_cpus);
+
// ought to count CPUs in /proc/stat instead of relying
// on glibc, which foolishly tries to parse /proc/cpuinfo
//
@@ -244,8 +247,15 @@
// appears to have a non-SMP kernel on a 2-way SMP box.
// _SC_NPROCESSORS_CONF returns 2, resulting in HZ=512
// _SC_NPROCESSORS_ONLN returns 1, which should work OK
- smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
- if(smp_num_cpus<1) smp_num_cpus=1; /* SPARC glibc is buggy */
+ _smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ if(_smp_num_cpus<1) _smp_num_cpus=1; /* SPARC glibc is buggy */
+
+ return(_smp_num_cpus);
+}
+
+static void init_libproc(void) __attribute__((constructor));
+static void init_libproc(void){
+ have_privs = check_for_privs();
if(linux_version_code > LINUX_VERSION(2, 4, 0)){
Hertz = find_elf_note(AT_CLKTCK);
--- procps-3.2.7/proc/sysinfo.h 2010-08-20 15:59:37.011847000 -0500
+++ procps-3.2.7/proc/sysinfo.h 2010-08-25 08:58:17.557096693 -0500
@@ -7,7 +7,7 @@
EXTERN_C_BEGIN
extern unsigned long long Hertz; /* clock tick frequency */
-extern long smp_num_cpus; /* number of CPUs */
+extern long smp_num_cpus(void); /* number of CPUs */
extern int have_privs; /* boolean, true if setuid or similar */
#if 0
--- procps-3.2.7/top.c 2010-08-20 15:59:37.507910544 -0500
+++ procps-3.2.7/top.c 2010-08-20 16:24:36.623565229 -0500
@@ -1656,7 +1656,7 @@
if (Myname) ++Myname; else Myname = me;
/* establish cpu particulars -- even bigger! */
- Cpu_tot = smp_num_cpus;
+ Cpu_tot = smp_num_cpus();
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 :-(
@@ -1676,15 +1676,15 @@
Fieldstab[P_CPN].head = " P";
Fieldstab[P_CPN].fmts = " %1u";
- if(smp_num_cpus>9){
+ if(smp_num_cpus()>9){
Fieldstab[P_CPN].head = " P";
Fieldstab[P_CPN].fmts = " %2u";
}
- if(smp_num_cpus>99){
+ if(smp_num_cpus()>99){
Fieldstab[P_CPN].head = " P";
Fieldstab[P_CPN].fmts = " %3u";
}
- if(smp_num_cpus>999){
+ if(smp_num_cpus()>999){
Fieldstab[P_CPN].head = " P";
Fieldstab[P_CPN].fmts = " %4u";
}
@@ -1831,7 +1831,7 @@
confighlp(Winstk[i].rc.fieldscur);
}
- if(Rc.mode_irixps && smp_num_cpus>1){
+ if(Rc.mode_irixps && smp_num_cpus()>1){
// good for 100 CPUs per process
pcpu_max_value = 9999.0;
Fieldstab[P_CPU].fmts = " %4.0f";
@@ -2677,7 +2677,7 @@
Rc.mode_irixps = !Rc.mode_irixps;
show_msg(fmtmk("Irix mode %s", Rc.mode_irixps ? "On" : "Off"));
#endif
- if(Rc.mode_irixps && smp_num_cpus>1){
+ if(Rc.mode_irixps && smp_num_cpus()>1){
// good for 100 CPUs per process
pcpu_max_value = 9999.0;
Fieldstab[P_CPU].fmts = " %4.0f";