procps/procps-ng-3.3.8-bnc634071_procstat2.diff
2013-05-29 13:55:21 +00:00

233 lines
8.8 KiB
Diff

--- 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 2013-05-29 11:26:47.797640941 +0000
@@ -37,8 +37,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" \
@@ -200,7 +198,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) */
@@ -271,8 +269,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);
@@ -1012,7 +1008,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
@@ -1024,7 +1025,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 2013-05-29 11:28:34.945439635 +0000
@@ -411,7 +411,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
@@ -2230,7 +2230,7 @@ static void zap_fieldstab (void) {
/*** hotplug_acclimated ***/
Fieldstab[P_CPN].width = 1;
- 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));
Fieldstab[P_CPN].width = digits;
}
@@ -2238,9 +2238,9 @@ static void zap_fieldstab (void) {
#ifdef BOOST_PERCNT
Cpu_pmax = 99.9;
Fieldstab[P_CPU].width = 5;
- 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;
} else {
if (Cpu_pmax > 999.9) Cpu_pmax = 999.9;
@@ -2249,9 +2249,9 @@ static void zap_fieldstab (void) {
#else
Cpu_pmax = 99.9;
Fieldstab[P_CPU].width = 4;
- 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;
} else {
if (Cpu_pmax > 999.9) Cpu_pmax = 999.9;
@@ -2294,8 +2294,8 @@ static void zap_fieldstab (void) {
* cpus[sumSLOT] == tics from the 1st /proc/stat line
* [ and beyond sumSLOT == tics for each cpu NUMA node ] */
static CPU_t *cpus_refresh (CPU_t *cpus) {
- #define sumSLOT ( smp_num_cpus )
- #define totSLOT ( 1 + smp_num_cpus + Numa_node_tot)
+ #define sumSLOT ( smp_num_cpus() )
+ #define totSLOT ( 1 + smp_num_cpus() + Numa_node_tot)
static FILE *fp = NULL;
static int siz, sav_slot = -1;
static char *buf;
@@ -2358,7 +2358,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[sumSLOT].edge =
- ((cpus[sumSLOT].cur.tot - cpus[sumSLOT].sav.tot) / smp_num_cpus) / (100 / TICS_EDGE);
+ ((cpus[sumSLOT].cur.tot - cpus[sumSLOT].sav.tot) / smp_num_cpus()) / (100 / TICS_EDGE);
#endif
#ifndef NUMA_DISABLE
@@ -2496,7 +2496,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
@@ -2649,8 +2649,7 @@ static void sysinfo_refresh (int forced)
#ifndef PRETEND8CPUS
/*** 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;
#ifndef NUMA_DISABLE
if (Libnuma_handle)
@@ -3219,9 +3219,8 @@ static void before (char *me) {
// establish cpu particulars
#ifdef PRETEND8CPUS
- smp_num_cpus = 8;
+ Cpu_faux_tot = 8;
#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);
@@ -5020,19 +5019,19 @@ static void summary_show (void) {
if (CHKw(w, View_CPUNOD)) {
if (Numa_node_sel < 0) {
// display the 1st /proc/stat line, then the nodes (if room)
- summary_hlp(&smpcpu[smp_num_cpus], N_txt(WORD_allcpus_txt));
+ summary_hlp(&smpcpu[smp_num_cpus()], N_txt(WORD_allcpus_txt));
Msg_row += 1;
// display each cpu node's states
for (i = 0; i < Numa_node_tot; i++) {
if (!isROOM(anyFLG, 1)) break;
snprintf(tmp, sizeof(tmp), N_fmt(NUMA_nodenam_fmt), i);
- summary_hlp(&smpcpu[1 + smp_num_cpus + i], tmp);
+ summary_hlp(&smpcpu[1 + smp_num_cpus() + i], tmp);
Msg_row += 1;
}
} else {
// display the node summary, then the associated cpus (if room)
snprintf(tmp, sizeof(tmp), N_fmt(NUMA_nodenam_fmt), Numa_node_sel);
- summary_hlp(&smpcpu[1 + smp_num_cpus + Numa_node_sel], tmp);
+ summary_hlp(&smpcpu[1 + smp_num_cpus() + Numa_node_sel], tmp);
Msg_row += 1;
for (i = 0; i < Cpu_faux_tot; i++) {
if (Numa_node_sel == smpcpu[i].node) {