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 */