library: Replace smp_num_cpu with function

Instead of exposing a variable smp_num_cpus that is updated
with cpuinfo, use procps_cpu_count() which returns the same
value.
This commit is contained in:
Craig Small 2015-06-29 22:31:36 +10:00
parent 639daf5468
commit c183b18301
4 changed files with 20 additions and 21 deletions

View File

@ -47,9 +47,9 @@ global:
readproctab3; readproctab3;
readproctab; readproctab;
readtask; readtask;
smp_num_cpus;
tty_to_dev; tty_to_dev;
user_from_uid; user_from_uid;
procps_cpu_count;
procps_hertz_get; procps_hertz_get;
procps_linux_version; procps_linux_version;
procps_meminfo_new; procps_meminfo_new;

View File

@ -35,7 +35,6 @@
#include "procps-private.h" #include "procps-private.h"
long smp_num_cpus; /* number of CPUs */
long page_bytes; /* this architecture's page size */ long page_bytes; /* this architecture's page size */
#define BAD_OPEN_MESSAGE \ #define BAD_OPEN_MESSAGE \
@ -121,6 +120,7 @@ unsigned long getbtime(void) {
return btime; return btime;
} }
/* /*
* procps_hertz_get: * procps_hertz_get:
* *
@ -159,7 +159,6 @@ PROCPS_EXPORT long procps_hertz_get(void)
static void init_libproc(void) __attribute__((constructor)); static void init_libproc(void) __attribute__((constructor));
static void init_libproc(void){ static void init_libproc(void){
cpuinfo();
page_bytes = sysconf(_SC_PAGESIZE); page_bytes = sysconf(_SC_PAGESIZE);
} }
@ -866,19 +865,18 @@ out:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
void cpuinfo (void) { /* procps_cpu_count:
// ought to count CPUs in /proc/stat instead of relying *
// on glibc, which foolishly tries to parse /proc/cpuinfo * Returns the number of CPUs that are currently online.
// note: that may have been the case but now /proc/stat *
// is the default source. parsing of /proc/cpuinfo */
// only occurs if the open on /proc/stat fails long procps_cpu_count(void)
// {
// SourceForge has an old Alpha running Linux 2.2.20 that long cpus=1;
// 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); cpus = sysconf(_SC_NPROCESSORS_ONLN);
if (smp_num_cpus<1) /* SPARC glibc is buggy */ if (cpus < 1)
smp_num_cpus=1; return 1;
return cpus;
} }

View File

@ -6,7 +6,6 @@
__BEGIN_DECLS __BEGIN_DECLS
extern long smp_num_cpus; /* number of CPUs */
extern int have_privs; /* boolean, true if setuid or similar */ extern int have_privs; /* boolean, true if setuid or similar */
extern long page_bytes; /* this architecture's bytes per page */ extern long page_bytes; /* this architecture's bytes per page */
@ -14,6 +13,7 @@ extern int uptime (double *uptime_secs, double *idle_secs);
extern unsigned long getbtime(void); extern unsigned long getbtime(void);
int loadavg(double *av1, double *av5, double *av15); int loadavg(double *av1, double *av5, double *av15);
long procps_hertz_get(void); long procps_hertz_get(void);
long procps_cpu_count(void);
/* Shmem in 2.6.32+ */ /* Shmem in 2.6.32+ */
extern unsigned long kb_main_shared; extern unsigned long kb_main_shared;
@ -132,7 +132,5 @@ extern unsigned int getslabinfo (struct slab_cache**);
extern unsigned get_pid_digits(void) FUNCTION; extern unsigned get_pid_digits(void) FUNCTION;
extern void cpuinfo (void);
__END_DECLS __END_DECLS
#endif /* SYSINFO_H */ #endif /* SYSINFO_H */

View File

@ -67,6 +67,8 @@
/*###### Miscellaneous global stuff ####################################*/ /*###### Miscellaneous global stuff ####################################*/
static long Hertz; static long Hertz;
static long smp_num_cpus;
/* The original and new terminal definitions /* The original and new terminal definitions
(only set when not in 'Batch' mode) */ (only set when not in 'Batch' mode) */
static struct termios Tty_original, // our inherited terminal definition static struct termios Tty_original, // our inherited terminal definition
@ -2675,7 +2677,7 @@ static void sysinfo_refresh (int forced) {
#ifndef PRETEND8CPUS #ifndef PRETEND8CPUS
/*** hotplug_acclimated ***/ /*** hotplug_acclimated ***/
if (60 <= cur_secs - cpu_secs) { if (60 <= cur_secs - cpu_secs) {
cpuinfo(); smp_num_cpus = procps_cpu_count();
Cpu_faux_tot = smp_num_cpus; Cpu_faux_tot = smp_num_cpus;
cpu_secs = cur_secs; cpu_secs = cur_secs;
#ifndef NUMA_DISABLE #ifndef NUMA_DISABLE
@ -3248,6 +3250,7 @@ static void before (char *me) {
initialize_nls(); initialize_nls();
Hertz = procps_hertz_get(); Hertz = procps_hertz_get();
smp_num_cpus = procps_cpu_count();
// establish cpu particulars // establish cpu particulars
#ifdef PRETEND8CPUS #ifdef PRETEND8CPUS
smp_num_cpus = 8; smp_num_cpus = 8;