Bug 9497 - Procinfo incorrectly lists number of CPUs on i386 SMP
Summary: Procinfo incorrectly lists number of CPUs on i386 SMP
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: procinfo   
(Show other bugs)
Version: 6.2
Hardware: i386 Linux
medium
low
Target Milestone: ---
Assignee: Mike A. Harris
QA Contact: David Lawrence
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-02-16 20:44 UTC by Travis Shugarts
Modified: 2007-04-18 16:26 UTC (History)
0 users

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


Attachments (Terms of Use)

Description Travis Shugarts 2000-02-16 20:44:35 UTC
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 21:26:59 UTC
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 12:14:59 UTC
Thanks, fixed in 17-4

Comment 3 Derek Tattersall 2000-03-09 17:07:59 UTC
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 11:11:48 UTC
Fixed

Comment 5 Mike A. Harris 2004-01-16 20:17:07 UTC
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 07:16:20 UTC
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.