From Jim.Pirzyk@disney.com  Mon May 21 16:57:55 2001
Return-Path: <Jim.Pirzyk@disney.com>
Received: from mail.disney.com (mail.disney.com [204.128.192.15])
	by hub.freebsd.org (Postfix) with ESMTP id 7090C37B424
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 May 2001 16:57:55 -0700 (PDT)
	(envelope-from Jim.Pirzyk@disney.com)
Received: from pain10.corp.disney.com (root@pain10.corp.disney.com [153.7.110.100])
	by mail.disney.com (Switch-2.0.1/Switch-2.0.1) with SMTP id f4LNvIA04416
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 May 2001 16:57:18 -0700 (PDT)
Received: from louie.fa.disney.com by pain.corp.disney.com with ESMTP for FreeBSD-gnats-submit@freebsd.org; Mon, 21 May 2001 16:58:42 -0700
Received: from plio.fan.fa.disney.com (plio.fan.fa.disney.com [153.7.118.2])
	by louie.fa.disney.com (8.9.2/8.9.2) with ESMTP id QAA20065
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 May 2001 16:57:52 -0700 (PDT)
	(envelope-from Jim.Pirzyk@fa.disney.com)
Received: from snoopy.fan.fa.disney.com (snoopy.fan.fa.disney.com [153.7.117.170])
	by plio.fan.fa.disney.com (8.9.2/8.9.2) with ESMTP id QAA22710
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 May 2001 16:57:52 -0700 (PDT)
	(envelope-from Jim.Pirzyk@fa.disney.com)
Received: (from Jim.Pirzyk@localhost)
	by snoopy.fan.fa.disney.com (8.11.3/8.9.3) id f4LNvp745724;
	Mon, 21 May 2001 16:57:51 -0700 (PDT)
	(envelope-from Jim.Pirzyk@fa.disney.com)
Message-Id: <200105212357.f4LNvp745724@snoopy.fan.fa.disney.com>
Date: Mon, 21 May 2001 16:57:51 -0700 (PDT)
From: Jim.Pirzyk@disney.com
Reply-To: Jim.Pirzyk@disney.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: linprocfs:/proc/stat does not handle SMP hosts
X-Send-Pr-Version: 3.113

>Number:         27522
>Category:       kern
>Synopsis:       linprocfs:/proc/stat does not handle SMP hosts
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 21 17:00:02 PDT 2001
>Closed-Date:    Sat Aug 07 20:33:38 GMT 2004
>Last-Modified:  Sat Aug 07 20:33:38 GMT 2004
>Originator:     Jim Pirzyk
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
>Environment:
System: FreeBSD snoopy.fan.fa.disney.com 4.3-RELEASE FreeBSD 4.3-RELEASE #4: Fri Apr 27 01:14:59 PDT 2001 root@snoopy.fan.fa.disney.com:/auto/roy/dist/pub/FreeBSD/4.3-RELEASE/sys/compile/UP_WORKSTATION i386


	
>Description:
	when cat'ing /compat/linux/proc/stat on an smp host, we only get this:

cpu 2678 0 1439 605126
disk 0 0 0 0
page 6384 0
swap 0 0
intr 820322
ctxt 198102
btime 990486334

but we should be getting this:

cpu 2678 0 1439 605126
cpu0 1339 0 719 302563
cpu1 1339 0 719 302563
disk 0 0 0 0
page 6384 0
swap 0 0
intr 820322
ctxt 198102
btime 990486334

>How-To-Repeat:
	cat /compat/linux/proc/stat

>Fix:

	
--- linprocfs_misc.c.orig	Thu Dec  7 05:17:55 2000
+++ linprocfs_misc.c	Mon May 21 16:49:01 2001
@@ -52,6 +52,7 @@
 #include <sys/tty.h>
 #include <sys/vnode.h>
 #include <sys/lock.h>
+#include <sys/sysctl.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
@@ -266,20 +267,39 @@
         char *ps;
 	char psbuf[512];
 	int xlen;
+	int ncpu, mib[2], i, olen=sizeof(ncpu), plen=0;
 
 	ps = psbuf;
 	ps += sprintf(ps,
-		      "cpu %ld %ld %ld %ld\n"
+		      "cpu %ld %ld %ld %ld\n",
+		      T2J(cp_time[CP_USER]),
+		      T2J(cp_time[CP_NICE]),
+		      T2J(cp_time[CP_SYS] /*+ cp_time[CP_INTR]*/),
+		      T2J(cp_time[CP_IDLE]));
+
+	mib[0] = CTL_HW; mib[1] = HW_NCPU;
+	if (kernel_sysctl(p, mib, 2, &ncpu, &olen, NULL, 0, &plen))
+		ncpu=1;		/* Fake out if the sysctl failed */
+
+	if ( ncpu > 1 ) {
+		for (i = 0; i < ncpu; i++) {
+			ps += sprintf(ps,
+		      	"cpu%d %ld %ld %ld %ld\n",
+				i,
+		      	T2J(cp_time[CP_USER]/ncpu),
+		      	T2J(cp_time[CP_NICE]/ncpu),
+		      	T2J(cp_time[CP_SYS]/ncpu /*+ cp_time[CP_INTR]*/),
+		      	T2J(cp_time[CP_IDLE]/ncpu));
+		}
+	}
+
+	ps+= sprintf(ps,
 		      "disk 0 0 0 0\n"
 		      "page %u %u\n"
 		      "swap %u %u\n"
 		      "intr %u\n"
 		      "ctxt %u\n"
 		      "btime %ld\n",
-		      T2J(cp_time[CP_USER]),
-		      T2J(cp_time[CP_NICE]),
-		      T2J(cp_time[CP_SYS] /*+ cp_time[CP_INTR]*/),
-		      T2J(cp_time[CP_IDLE]),
 		      cnt.v_vnodepgsin,
 		      cnt.v_vnodepgsout,
 		      cnt.v_swappgsin,
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: des 
Responsible-Changed-When: Sat May 26 10:06:23 PDT 2001 
Responsible-Changed-Why:  
linprocfs is mine. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27522 
State-Changed-From-To: open->patched 
State-Changed-By: des 
State-Changed-When: Mon Sep 22 08:56:44 PDT 2003 
State-Changed-Why:  
Similar patch committed to -CURRENT. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=27522 
State-Changed-From-To: patched->closed 
State-Changed-By: des 
State-Changed-When: Sat Aug 7 20:33:37 GMT 2004 
State-Changed-Why:  
Will not MFC. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=27522 
>Unformatted:
