--- proc/ksym.c +++ proc/ksym.c 2012-06-04 10:06:03.792202072 +0000 @@ -41,7 +41,7 @@ #define KSYMS_FILENAME "/would/be/nice/to/have/this/file" #define SYSMAP_FILENAME "/home/albert/ps/45621/System.map-hacked" #define linux_version_code 131598 /* ? */ -#define smp_num_cpus 2 +#define smp_num_cpus() 2 #endif #if 0 @@ -49,7 +49,7 @@ #define KSYMS_FILENAME "/home/albert/ps/45621/ksyms-2.3.12" #define SYSMAP_FILENAME "/home/albert/ps/45621/System.map-2.3.12" #define linux_version_code 131852 /* 2.3.12 */ -#define smp_num_cpus 2 +#define smp_num_cpus() 2 #endif #if 0 @@ -57,7 +57,7 @@ #define KSYMS_FILENAME "/home/albert/ps/45621/ksyms-2.3.18ac8-MODVERS" #define SYSMAP_FILENAME "/home/albert/ps/45621/System.map-2.3.18ac8-MODVERS" #define linux_version_code 131858 /* 2.3.18ac8 */ -#define smp_num_cpus 2 +#define smp_num_cpus() 2 #endif #if 0 @@ -65,7 +65,7 @@ #define KSYMS_FILENAME "/home/albert/ps/45621/ksyms-2.3.18ac8-NOMODVERS" #define SYSMAP_FILENAME "/home/albert/ps/45621/System.map-2.3.18ac8-NOMODVERS" #define linux_version_code 131858 /* 2.3.18ac8 */ -#define smp_num_cpus 2 +#define smp_num_cpus() 2 #endif /* These are the symbol types, with relative popularity: --- proc/sysinfo.c +++ proc/sysinfo.c 2012-06-04 10:03:34.464009483 +0000 @@ -36,8 +36,6 @@ #include /* 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" \ @@ -196,7 +194,7 @@ static void old_Hertz_hack(void){ free(savelocale); jiffies = user_j + nice_j + sys_j + other_j + wait_j + hirq_j + sirq_j + stol_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) */ @@ -267,8 +265,6 @@ static void init_libproc(void){ have_privs = check_for_privs(); init_Linux_version(); /* Must be called before we check code */ - cpuinfo(); - #ifdef __linux__ if(linux_version_code > LINUX_VERSION(2, 4, 0)){ Hertz = find_elf_note(AT_CLKTCK); @@ -1008,7 +1004,12 @@ out: /////////////////////////////////////////////////////////////////////////// -void cpuinfo (void) { +long smp_num_cpus (void) { + static long _smp_num_cpus=-1; + + 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 // note: that may have been the case but now /proc/stat @@ -1020,7 +1021,9 @@ void cpuinfo (void) { // _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) /* SPARC glibc is buggy */ - smp_num_cpus=1; + _smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + if (_smp_num_cpus<1) /* SPARC glibc is buggy */ + _smp_num_cpus=1; + + return _smp_num_cpus; } --- proc/sysinfo.h +++ proc/sysinfo.h 2012-06-04 10:04:15.812509959 +0000 @@ -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 @@ -137,7 +137,5 @@ extern unsigned int getslabinfo (struct extern unsigned get_pid_digits(void) FUNCTION; -extern void cpuinfo (void); - EXTERN_C_END #endif /* SYSINFO_H */ --- top/top.c +++ top/top.c 2012-06-04 10:08:23.264009898 +0000 @@ -354,7 +354,7 @@ static void bye_bye (const char *str) { , LINUX_VERSION_PATCH(linux_version_code) , procps_version , (unsigned)Hertz, (unsigned)sizeof(Hertz), (unsigned)sizeof(Hertz) * 8 - , Page_size, Cpu_faux_tot, (int)smp_num_cpus, (unsigned)sizeof(CPU_t) + , Page_size, Cpu_faux_tot, (int)smp_num_cpus(), (unsigned)sizeof(CPU_t) , (unsigned)sizeof(HST_t), Page_size / (unsigned)sizeof(HST_t), HHist_siz , (unsigned)sizeof(proc_t), (unsigned)sizeof(p->cmd), (unsigned)sizeof(proc_t*) , (long)Frames_libflags @@ -1764,7 +1764,7 @@ static void zap_fieldstab (void) { always: Fieldstab[P_CPN].head = "P "; Fieldstab[P_CPN].fmts = "%1d "; - if (1 < (digits = (unsigned)snprintf(buf, sizeof(buf), "%u", (unsigned)smp_num_cpus))) { + if (1 < (digits = (unsigned)snprintf(buf, sizeof(buf), "%u", (unsigned)smp_num_cpus()))) { if (5 < digits) error_exit(N_txt(FAIL_widecpu_txt)); snprintf(fmts_cpu, sizeof(fmts_cpu), "%%%ud ", digits); Fieldstab[P_CPN].head = " P " + 5 - digits; @@ -1773,9 +1773,9 @@ always: Cpu_pmax = 99.9; Fieldstab[P_CPU].fmts = " %#4.1f "; - if (Rc.mode_irixps && smp_num_cpus > 1 && !Thread_mode) { - Cpu_pmax = 100.0 * smp_num_cpus; - if (smp_num_cpus > 10) { + if (Rc.mode_irixps && smp_num_cpus() > 1 && !Thread_mode) { + Cpu_pmax = 100.0 * smp_num_cpus(); + if (smp_num_cpus() > 10) { if (Cpu_pmax > 99999.0) Cpu_pmax = 99999.0; Fieldstab[P_CPU].fmts = "%5.0f "; } else { @@ -1841,7 +1841,7 @@ static CPU_t *cpus_refresh (CPU_t *cpus) we'll force it to be treated as 'idle' so as not to present misleading percentages. */ cpus[Cpu_faux_tot].edge = - ((cpus[Cpu_faux_tot].cur.tot - cpus[Cpu_faux_tot].sav.tot) / smp_num_cpus) / (100 / TICS_EDGE); + ((cpus[Cpu_faux_tot].cur.tot - cpus[Cpu_faux_tot].sav.tot) / smp_num_cpus()) / (100 / TICS_EDGE); #endif // now value each separate cpu's tics, maybe for (i = 0; i < Cpu_faux_tot && i < Screen_rows; i++) { @@ -1946,7 +1946,7 @@ static void procs_hlp (proc_t *this) { oldtimev.tv_usec = timev.tv_usec; // if in Solaris mode, adjust our scaling for all cpus - Frame_etscale = 100.0f / ((float)Hertz * (float)et * (Rc.mode_irixps ? 1 : smp_num_cpus)); + Frame_etscale = 100.0f / ((float)Hertz * (float)et * (Rc.mode_irixps ? 1 : smp_num_cpus())); #ifdef OFF_HST_HASH maxt_sav = Frame_maxtask; #endif @@ -2088,8 +2088,7 @@ static void sysinfo_refresh (int forced) #ifndef PRETEND4CPUS /*** hotplug_acclimated ***/ if (300 <= cur_secs - cpu_secs) { - cpuinfo(); - Cpu_faux_tot = smp_num_cpus; + Cpu_faux_tot = smp_num_cpus(); cpu_secs = cur_secs; } #endif @@ -2116,10 +2115,10 @@ static void before (char *me) { initialize_nls(); // establish cpu particulars + Cpu_faux_tot = smp_num_cpus(); #ifdef PRETEND4CPUS - smp_num_cpus = 4; + Cpu_faux_tot = 4; #endif - Cpu_faux_tot = smp_num_cpus; Cpu_States_fmts = N_unq(STATE_lin2x4_fmt); if (linux_version_code > LINUX_VERSION(2, 5, 41)) Cpu_States_fmts = N_unq(STATE_lin2x5_fmt);