Initialize smp_num_cpus only if really required
Initialize smp_num_cpus only if really required Signed-off-by: Werner Fink <werner@suse.de>
This commit is contained in:
parent
e646984924
commit
aac0de8994
@ -24,7 +24,9 @@
|
|||||||
#include <netinet/in.h> /* htons */
|
#include <netinet/in.h> /* htons */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ZAP_SUSEONLY
|
||||||
long smp_num_cpus; /* number of CPUs */
|
long smp_num_cpus; /* number of CPUs */
|
||||||
|
#endif
|
||||||
|
|
||||||
#define BAD_OPEN_MESSAGE \
|
#define BAD_OPEN_MESSAGE \
|
||||||
"Error: /proc must be mounted\n" \
|
"Error: /proc must be mounted\n" \
|
||||||
@ -180,7 +182,11 @@ static void old_Hertz_hack(void){
|
|||||||
setlocale(LC_NUMERIC, savelocale);
|
setlocale(LC_NUMERIC, savelocale);
|
||||||
jiffies = user_j + nice_j + sys_j + other_j;
|
jiffies = user_j + nice_j + sys_j + other_j;
|
||||||
seconds = (up_1 + up_2) / 2;
|
seconds = (up_1 + up_2) / 2;
|
||||||
|
#ifndef ZAP_SUSEONLY
|
||||||
h = (unsigned)( (double)jiffies/seconds/smp_num_cpus );
|
h = (unsigned)( (double)jiffies/seconds/smp_num_cpus );
|
||||||
|
#else
|
||||||
|
h = (unsigned)( (double)jiffies/seconds/smp_num_cpus() );
|
||||||
|
#endif
|
||||||
/* actual values used by 2.4 kernels: 32 64 100 128 1000 1024 1200 */
|
/* actual values used by 2.4 kernels: 32 64 100 128 1000 1024 1200 */
|
||||||
switch(h){
|
switch(h){
|
||||||
case 9 ... 11 : Hertz = 10; break; /* S/390 (sometimes) */
|
case 9 ... 11 : Hertz = 10; break; /* S/390 (sometimes) */
|
||||||
@ -246,10 +252,34 @@ static int check_for_privs(void){
|
|||||||
return !!rc;
|
return !!rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ZAP_SUSEONLY
|
||||||
|
long smp_num_cpus(void)
|
||||||
|
{
|
||||||
|
static long _smp_num_cpus=-1; /* number of CPUs */
|
||||||
|
|
||||||
|
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
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
_smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
if(_smp_num_cpus<1) _smp_num_cpus=1; /* SPARC glibc is buggy */
|
||||||
|
|
||||||
|
return(_smp_num_cpus);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void init_libproc(void) __attribute__((constructor));
|
static void init_libproc(void) __attribute__((constructor));
|
||||||
static void init_libproc(void){
|
static void init_libproc(void){
|
||||||
have_privs = check_for_privs();
|
have_privs = check_for_privs();
|
||||||
init_Linux_version(); /* Must be called before we check code */
|
init_Linux_version(); /* Must be called before we check code */
|
||||||
|
#ifndef ZAP_SUSEONLY
|
||||||
// ought to count CPUs in /proc/stat instead of relying
|
// ought to count CPUs in /proc/stat instead of relying
|
||||||
// on glibc, which foolishly tries to parse /proc/cpuinfo
|
// on glibc, which foolishly tries to parse /proc/cpuinfo
|
||||||
//
|
//
|
||||||
@ -259,7 +289,7 @@ static void init_libproc(void){
|
|||||||
// _SC_NPROCESSORS_ONLN returns 1, which should work OK
|
// _SC_NPROCESSORS_ONLN returns 1, which should work OK
|
||||||
smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
|
smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
if(smp_num_cpus<1) smp_num_cpus=1; /* SPARC glibc is buggy */
|
if(smp_num_cpus<1) smp_num_cpus=1; /* SPARC glibc is buggy */
|
||||||
|
#endif
|
||||||
if(linux_version_code > LINUX_VERSION(2, 4, 0)){
|
if(linux_version_code > LINUX_VERSION(2, 4, 0)){
|
||||||
Hertz = find_elf_note(AT_CLKTCK);
|
Hertz = find_elf_note(AT_CLKTCK);
|
||||||
if(Hertz!=NOTE_NOT_FOUND) return;
|
if(Hertz!=NOTE_NOT_FOUND) return;
|
||||||
|
@ -7,7 +7,11 @@
|
|||||||
EXTERN_C_BEGIN
|
EXTERN_C_BEGIN
|
||||||
|
|
||||||
extern unsigned long long Hertz; /* clock tick frequency */
|
extern unsigned long long Hertz; /* clock tick frequency */
|
||||||
|
#ifndef ZAP_SUSEONLY
|
||||||
extern long smp_num_cpus; /* number of CPUs */
|
extern long smp_num_cpus; /* number of CPUs */
|
||||||
|
#else
|
||||||
|
extern long smp_num_cpus(void); /* number of CPUs */
|
||||||
|
#endif
|
||||||
extern int have_privs; /* boolean, true if setuid or similar */
|
extern int have_privs; /* boolean, true if setuid or similar */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user