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;
readproctab;
readtask;
smp_num_cpus;
tty_to_dev;
user_from_uid;
procps_cpu_count;
procps_hertz_get;
procps_linux_version;
procps_meminfo_new;

View File

@ -35,7 +35,6 @@
#include "procps-private.h"
long smp_num_cpus; /* number of CPUs */
long page_bytes; /* this architecture's page size */
#define BAD_OPEN_MESSAGE \
@ -121,6 +120,7 @@ unsigned long getbtime(void) {
return btime;
}
/*
* 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){
cpuinfo();
page_bytes = sysconf(_SC_PAGESIZE);
}
@ -866,19 +865,18 @@ out:
///////////////////////////////////////////////////////////////////////////
void cpuinfo (void) {
// 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
// is the default source. parsing of /proc/cpuinfo
// only occurs if the open on /proc/stat fails
//
// SourceForge has an old Alpha running Linux 2.2.20 that
// 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
/* procps_cpu_count:
*
* Returns the number of CPUs that are currently online.
*
*/
long procps_cpu_count(void)
{
long cpus=1;
smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
if (smp_num_cpus<1) /* SPARC glibc is buggy */
smp_num_cpus=1;
cpus = sysconf(_SC_NPROCESSORS_ONLN);
if (cpus < 1)
return 1;
return cpus;
}

View File

@ -6,7 +6,6 @@
__BEGIN_DECLS
extern long smp_num_cpus; /* number of CPUs */
extern int have_privs; /* boolean, true if setuid or similar */
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);
int loadavg(double *av1, double *av5, double *av15);
long procps_hertz_get(void);
long procps_cpu_count(void);
/* Shmem in 2.6.32+ */
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 void cpuinfo (void);
__END_DECLS
#endif /* SYSINFO_H */

View File

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