Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 May 2001 16:57:51 -0700 (PDT)
From:      Jim.Pirzyk@disney.com
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/27522: linprocfs:/proc/stat does not handle SMP hosts
Message-ID:  <200105212357.f4LNvp745724@snoopy.fan.fa.disney.com>

next in thread | raw e-mail | index | archive | help


>Number:         27522
>Category:       kern
>Synopsis:       linprocfs:/proc/stat does not handle SMP hosts
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 21 17:00:02 PDT 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105212357.f4LNvp745724>