On 07/30/2010 04:06 AM, Denys Vlasenko wrote:
On Thursday 22 July 2010 12:43, Marek Polacek wrote:
Currently we're determining the number of CPUs by the function
get_cpu_nr() which in turn calls get_sys_cpu_nr() or even
get_proc_cpu(). I think we could easily use sysconf(
_SC_NPROCESSORS_CONF), and if this symbol isn't defined, then we'll read
/proc/cpuinfo. This way we can get rid of those two not very pretty
functions.
Well, uh... uclibc unfortunately always returns 1
for _SC_NPROCESSORS_CONF...
Ah, didn't know that. That's mean.
Reading lines into char buf[16] is buggy:
every line longer than 15 chars will get split into 15 char
chunks, which might cause misparsing and misdetection.
OK, here's another version -- it just removes function, which determines
number of CPUs in /sys.
mpstat.c | 49 +------------------------------------------------
1 file changed, 1 insertion(+), 48 deletions(-)
Please consider usage.
Thanks,
Marek
diff --git a/procps/mpstat.c b/procps/mpstat.c
index b0d187e..97c2af4 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -770,45 +770,11 @@ static void print_header(struct tm *t)
}
/*
- * Get number of processors in /sys
- */
-static int get_sys_cpu_nr(void)
-{
- DIR *dir;
- struct dirent *d;
- struct stat buf;
- char line[MAX_PF_NAME];
- int proc_nr = 0;
-
- dir = opendir(SYSFS_DEVCPU);
- if (!dir)
- return 0; /* /sys not mounted */
-
- /* Get current file entry */
- while ((d = readdir(dir)) != NULL) {
- if (starts_with_cpu(d->d_name) && isdigit(d->d_name[3])) {
- snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU,
- d->d_name);
- line[MAX_PF_NAME - 1] = '\0';
- /* Get information about file */
- if (stat(line, &buf) < 0)
- continue;
- /* If found 'cpuN', we have one more processor */
- if (S_ISDIR(buf.st_mode))
- proc_nr++;
- }
- }
-
- closedir(dir);
- return proc_nr;
-}
-
-/*
* Get number of processors in /proc/stat
* Return value '0' means one CPU and non SMP kernel.
* Otherwise N means N processor(s) and SMP kernel.
*/
-static int get_proc_cpu_nr(void)
+static int get_cpu_nr(void)
{
FILE *fp;
char line[256];
@@ -835,19 +801,6 @@ static int get_proc_cpu_nr(void)
return proc_nr + 1;
}
-static int get_cpu_nr(void)
-{
- int n;
-
- /* Try to use /sys, if possible */
- n = get_sys_cpu_nr();
- if (n == 0)
- /* Otherwise use /proc/stat */
- n = get_proc_cpu_nr();
-
- return n;
-}
-
/*
* Get number of interrupts available per processor
*/
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox