Bug 9497 - Procinfo incorrectly lists number of CPUs on i386 SMP
Procinfo incorrectly lists number of CPUs on i386 SMP
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: procinfo (Show other bugs)
6.2
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Mike A. Harris
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-02-16 15:44 EST by Travis Shugarts
Modified: 2007-04-18 12:26 EDT (History)
0 users

See Also:
Fixed In Version: procinfo-18-11
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-01-17 02:16:20 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Travis Shugarts 2000-02-16 15:44:35 EST
Procinfo counts incorrectly the number of processors on i386 based smp
systems.  /proc/cpuinfo correctly lists the number of processors, but
procinfo always returns 1CPU.
Comment 1 Travis Shugarts 2000-02-16 16:26:59 EST
The below patch should fix the problem.


--- procinfo.old        Wed Feb 16 16:18:43 2000
+++ procinfo.c  Wed Feb 16 16:34:39 2000
@@ -786,9 +786,9 @@
        while (fgets (line, sizeof (line), cpuinfofp))
            if (!strncmp ("processor", line, 9))          /* intel */
                nr_cpus++;
-           else if (strncmp ("ncpus active", line, 12))  /* sparc */
+           else if (!strncmp ("ncpus active", line, 12))  /* sparc */
                nr_cpus = atoi(line+19);
-           else if (strncmp ("cpus detected", line, 13)) /* alpha */
+           else if (!strncmp ("cpus detected", line, 13)) /* alpha */
                nr_cpus = atoi(line+27);
        fclose (cpuinfofp);
     }
Comment 2 Bernhard Rosenkraenzer 2000-02-18 07:14:59 EST
Thanks, fixed in 17-4
Comment 3 Derek Tattersall 2000-03-09 12:07:59 EST
On every sparc, procinfo -a reports 3 CPU [ sparc2] or [ ultra]
Linux 2.2.14-5.0 (root@lisa) (gcc egcs-2.92.11) #1 3CPU [ultra1]
Comment 4 Bernhard Rosenkraenzer 2000-08-08 07:11:48 EDT
Fixed
Comment 5 Mike A. Harris 2004-01-16 15:17:07 EST
Ick, this is insane.  Detecting CPU count by parsing proc files.
Using sysconf is both more portable, and less likely to encounter
random kernel modification skewage problems.
Comment 6 Mike A. Harris 2004-01-17 02:16:20 EST
Fixed to be portable using sysconf as mentioned above:

--- procinfo-18/procinfo.c.mharris-use-sysconf  2004-01-16
15:40:37.000000000 -0500
+++ procinfo-18/procinfo.c      2004-01-17 02:01:16.000000000 -0500
@@ -837,19 +837,7 @@
     }

     /* Count number of CPUs */
-    cpuinfofp = myfopen (PROC_DIR "cpuinfo");
-    if (cpuinfofp) {
-       while (fgets (line, sizeof (line), cpuinfofp))
-           if (!strncmp ("processor", line, 9))          /* intel */
-               nr_cpus++;
-           else if (!strncmp ("ncpus ", line, 6))  /* sparc */
-               nr_cpus = atoi(line+19);
-           else if (!strncmp ("cpus detected", line, 13)) /* alpha */
-               nr_cpus = atoi(line+27);
-       fclose (cpuinfofp);
-    }
-    if (nr_cpus == 0)
-       nr_cpus = 1;
+    nr_cpus = sysconf (_SC_NPROCESSORS_ONLN);

     /* Gets called from winsz(), but in case stdout is redirected: */
     version = make_version (versionfp);



Built into rawhide as procinfo-18-11

Note You need to log in before you can comment on or make changes to this bug.