sysconf(_SC_NPROCESSORS_CONF) returning zero
Hi,
the following program
===
#include <unistd.h>
#include <stdio.h>
main()
{
printf("Number of processors: %d\n", sysconf(_SC_NPROCESSORS_CONF));
}
===
produces
Number of processors: 0
on my system.
# uname -a Linux dirk 2.6.26 #1 Wed Jul 30 10:56:10 CEST 2008 i686 GNU/Linux
# cat /proc/cpuinfo processor : 0 vendor_id : User Mode Linux model name : UML mode : skas host : Linux seldon-base 2.6.23.17 #2 SMP Sat Jun 21 15:04:22 CEST 2008 i686 bogomips : 4771.02
# ls -l /lib/libc.so.6 lrwxrwxrwx 1 root root 11 2008-07-17 17:16 /lib/libc.so.6 -> libc-2.7.so
The monit monitoring tool (http://www.tildeslash.com/monit/)
crashes because of this. I don't know whose fault it is, but I suspect the UML - otherwise I'd expect many more instances of this problem when googling for it.
Regards
Signature · 11 lines
Stano ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ User-mode-linux-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 12 lines · Stanislav Meduna
Hi,
the following program
===
#include <unistd.h>
#include <stdio.h>
main(){ printf("Number of processors: %d\n", sysconf(_SC_NPROCESSORS_CONF)); }
Quoted 7 lines
===
produces
Number of processors: 0
on my system.
Works here...
[root@uml-test ~]# cc -o ncpus ncpus.c
[root@uml-test ~]# ./ncpus
Number of processors: 1
sysconf seems to be looking at /proc/stat, which looks like this here:
cpu 80 0 157 12771 984 0 0 0 0 cpu0 80 0 157 12771 984 0 0 0 0 intr 15259 12519 0 75 0 2590 0 0 0 0 0 0 74 0 0 1 ctxt 8081 btime 1217881784 processes 1144 procs_running 3 procs_blocked 0
I'd guess it's looking at the cpu0 (and cpu<n>) lines.
Jeff
Signature · 11 lines
Work email - jdike at linux dot intel dot com ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ User-mode-linux-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 11 lines · Jeff Dike
sysconf seems to be looking at
/proc/stat, which looks like this here:cpu 80 0 157 12771 984 0 0 0 0 cpu0 80 0 157 12771 984 0 0 0 0 intr 15259 12519 0 75 0 2590 0 0 0 0 0 0 74 0 0 1 ctxt 8081 btime 1217881784 processes 1144 procs_running 3 procs_blocked 0
Quoted 1 line
I'd guess it's looking at the cpu0 (and cpu<n>) lines.
# cat /proc/stat cpu 38822 537 3376 46871329 174924 0 9 0 0 cpu0 38822 537 3376 46871329 174924 0 9 0 0 intr 47644940 47088997 0 5 0 395871 160067 0 0 0 0 0 0 0 0 0 ctxt 9822902 btime 1217412992 processes 26529 procs_running 2 procs_blocked 0
Hmmm... so I have cpu0 similar to yours. What version of UML and libc do you have?
Signature · 11 lines
Stano ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ User-mode-linux-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 2 lines · Stanislav Meduna
Hmmm... so I have cpu0 similar to yours. What version of UML and libc do you have?
UML 2.6.26 and an older libc:
% ls -l /lib/libc.so.6
lrwxrwxrwx 1 root root 11 Jun 2 2007 /lib/libc.so.6 -> libc-2.5.so
Looking through libc at
http://www.google.com/codesearch?hl=en&q=file:\.c%24+\"/stat\"+package:http://su-se.lunar-linux.org/lunar/mirrors/glibc-2.3.3-cvs-20040708.tar.bz2+show:m1O9RV1wlw4:qbkros5194A:MbxD3_8dUHU&sa=N&cd=1&ct=rc&cs_p=http://su-se.lunar-linux.org/lunar/mirrors/glibc-2.3.3-cvs-20040708.tar.bz2&cs_f=glibc-2.3.3-cvs-20040708/sysdeps/unix/sysv/linux/getsysstats.c
I see it counting cpu<n> lines in /proc/stat, which is what I'm seeing. It will also look at /proc/cpuinfo. Can you strace your version and see if it's looking there at all?
Jeff
Signature · 11 lines
Work email - jdike at linux dot intel dot com ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ User-mode-linux-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 3 lines · Jeff Dike
I see it counting cpu<n> lines in
/proc/stat, which is what I'm seeing. It will also look at/proc/cpuinfo. Can you strace your version and see if it's looking there at all?
No.. looks like they changed the method:
open("/sys/devices/system/cpu", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|0x80
000) = 3fstat64(3, {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
fcntl64(3, F_GETFD) = 0x1 (flags FD_CLOEXEC) getdents64(3, /* 5 entries */, 4096) = 144 getdents64(3, /* 0 entries */, 4096) = 0 close(3) = 0
No reference to /proc/stat nor /proc/cpuinfo.
# ls -l /sys/devices/system/cpu -r--r--r-- 1 root root 4096 2008-08-04 23:51 online -r--r--r-- 1 root root 4096 2008-08-04 23:51 possible -r--r--r-- 1 root root 4096 2008-08-04 23:51 present
# cat /sys/devices/system/cpu/online 0 # cat /sys/devices/system/cpu/possible 0 # cat /sys/devices/system/cpu/present 0
On another Linux (real, 2.6.18) this looks completely different:
$ ls -l /sys/devices/system/cpu total 0 drwxr-xr-x 4 root root 0 2008-08-04 23:53 cpu0
$ ls -l /sys/devices/system/cpu/cpu0/ total 0 drwxr-xr-x 5 root root 0 2007-06-11 09:30 cache -r-------- 1 root root 4096 2008-08-04 23:53 crash_notes drwxr-xr-x 2 root root 0 2007-06-11 09:30 topology
Well.. so this is an interface definition problem.. now who has changet something and did not tell the others..
Signature · 11 lines
Stano ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ User-mode-linux-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 8 lines · Jeff Dike
Quoted 2 lines
Hmmm... so I have cpu0 similar to yours. What version of UML and libc do you have?
UML 2.6.26 and an older libc:
% ls -l
/lib/libc.so.6
lrwxrwxrwx 1 root root 11 Jun 2 2007/lib/libc.so.6-> libc-2.5.so
Quoted 7 lines
Looking through libc at
http://www.google.com/codesearch?hl=en&q=file:\.c%24+\"/stat\"+package:http://su-se.lunar-linux.org/lunar/mirrors/glibc-2.3.3-cvs-20040708.tar.bz2+show:m1O9RV1wlw4:qbkros5194A:MbxD3_8dUHU&sa=N&cd=1&ct=rc&cs_p=http://su-se.lunar-linux.org/lunar/mirrors/glibc-2.3.3-cvs-20040708.tar.bz2&cs_f=glibc-2.3.3-cvs-20040708/sysdeps/unix/sysv/linux/getsysstats.c
I see it counting cpu<n> lines in
/proc/stat, which is what I'm seeing. It will also look at/proc/cpuinfo. Can you strace your version and see if it's looking there at all?
More recent versions of glibc (here: 2.8 on Fedora 9) seem to look at the contents of /sys/devices/system/cpu instead. That directory is empty in UML, which might explain the odd result from Stanislav's program.
Cheers,
Ingo
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel