Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Sep 1999 22:36:07 -0700
From:      Arun Sharma <adsharma@home.com>
To:        freebsd-smp@freebsd.org
Subject:   Kernel + xosview patch for cp_time
Message-ID:  <19990901223607.A4616@home.com>

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

--EeQfGwPcQSOJBaQU
Content-Type: text/plain; charset=us-ascii

Here's a minor patch to make the kernel keep track of per CPU times and
another patch to help xosview take advantage of that.

	-Arun


--EeQfGwPcQSOJBaQU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=xosview-bsd-patch

diff -u /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/MeterMaker.cc bsd/MeterMaker.cc
--- /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/MeterMaker.cc	Mon Jan 25 12:15:26 1999
+++ bsd/MeterMaker.cc	Wed Sep  1 21:33:15 1999
@@ -44,8 +44,12 @@
     push(new LoadMeter(_xos));
 
   // Standard meters (usually added, but users could turn them off)
-  if (_xos->isResourceTrue("cpu"))
-    push(new CPUMeter(_xos));
+  if (_xos->isResourceTrue("cpu")) {
+    int cpuCount = CPUMeter::countCPUs();
+    int start = (cpuCount == 0) ? 0 : 1;
+    for (int i = start ; i <= cpuCount ; i++)
+      push(new CPUMeter(_xos, CPUMeter::cpuStr(i), i));	
+  }
 
   if (_xos->isResourceTrue("mem"))
     push(new MemMeter(_xos));
diff -u /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/cpumeter.cc bsd/cpumeter.cc
--- /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/cpumeter.cc	Sun Jan 31 12:18:49 1999
+++ bsd/cpumeter.cc	Wed Sep  1 22:27:33 1999
@@ -16,6 +16,9 @@
 //
 #include <sys/dkstat.h>         //  For CPUSTATES #define.  BCG
 #include <stdlib.h>		//  For use of atoi  BCG
+#include <sys/types.h>
+#include <sys/sysctl.h>     
+#include <strstream.h>
 #include "general.h"
 #include "cpumeter.h"
 #include "kernel.h"             //  For NetBSD-specific icky kvm_ code.  BCG
@@ -23,18 +26,20 @@
 CVSID("$Id: cpumeter.cc,v 1.16 1999/01/31 20:18:49 bgrayson Exp $");
 CVSID_DOT_H(CPUMETER_H_CVSID);
 
-CPUMeter::CPUMeter( XOSView *parent )
+CPUMeter::CPUMeter( XOSView *parent, const char *cpuID, int cpuindex)
 #ifdef XOSVIEW_FREEBSD
-: FieldMeterGraph( parent, 5, "CPU", "USR/NICE/SYS/INT/FREE" ){
+: FieldMeterGraph( parent, 5, cpuID, "USR/NICE/SYS/INT/FREE" ){
 #define FREE_INDEX 4
 #else
-: FieldMeterGraph( parent, 4, "CPU", "USR/NICE/SYS/FREE" ){
+: FieldMeterGraph( parent, 4, cpuID, "USR/NICE/SYS/FREE" ){
 #define FREE_INDEX 3
 #endif
   for ( int i = 0 ; i < 2 ; i++ )
     for ( int j = 0 ; j < 4 ; j++ )
       cputime_[i][j] = 0;
+
   cpuindex_ = 0;
+  index = cpuindex - 1;
   //  The setting of the priority will be done in checkResources().  BCG
   dodecay_ = 0;
 
@@ -74,7 +79,7 @@
   //  Begin NetBSD-specific code...  BCG
   long tempCPU[CPUSTATES];
 
-  BSDGetCPUTimes (tempCPU);
+  BSDGetCPUTimes (tempCPU, index);
 
   cputime_[cpuindex_][0] = tempCPU[0];
   cputime_[cpuindex_][1] = tempCPU[1];
@@ -124,3 +129,31 @@
 
   cpuindex_ = (cpuindex_ + 1) % 2;
 }
+
+
+int CPUMeter::countCPUs(void)
+{
+  int mib[2], ncpu;
+  size_t len;  
+
+  mib[0] = CTL_HW;
+  mib[1] = HW_NCPU; 
+  len = sizeof(ncpu); 
+  sysctl(mib, 2, &ncpu, &len, NULL, 0);
+
+  return ncpu;
+}
+
+const char *CPUMeter::cpuStr(int num)
+{
+  static char buffer[32];
+  ostrstream str(buffer, 32);
+  
+  str << "cpu";
+  if (num != 0)
+    str << (num - 1);
+  str << ends;
+
+  return buffer;
+}
+
diff -u /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/cpumeter.h bsd/cpumeter.h
--- /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/cpumeter.h	Tue Oct 20 12:37:33 1998
+++ bsd/cpumeter.h	Wed Sep  1 22:09:32 1999
@@ -23,16 +23,19 @@
 
 class CPUMeter : public FieldMeterGraph {
 public:
-  CPUMeter( XOSView *parent );
+  CPUMeter( XOSView *parent, const char *cpuID = "cpu", int cpuindex = 0);
   ~CPUMeter( void );
 
   const char *name( void ) const { return "CPUMeter"; }
   void checkevent( void );
 
+  static int countCPUs(void);
+  static const char *cpuStr(int num);
   void checkResources( void );
 protected:
   long cputime_[2][5];
   int cpuindex_;
+  int index;
 
   void getcputime( void );
 private:
diff -u /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/kernel.cc bsd/kernel.cc
--- /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/kernel.cc	Wed Sep  1 22:17:57 1999
+++ bsd/kernel.cc	Wed Sep  1 21:52:36 1999
@@ -289,11 +289,13 @@
 }
 
 void
-BSDGetCPUTimes (long* timeArray) {
+BSDGetCPUTimes (long* timeArray, int index) {
+  int size = sizeof (long) * CPUSTATES;
   if (!timeArray) errx (-1, "BSDGetCPUTimes():  passed pointer was null!\n");
   if (CPUSTATES != 5)
     errx (-1, "Error:  xosview for *BSD expects 5 cpu states!\n");
-  safe_kvm_read_symbol (CP_TIME_SYM_INDEX, timeArray, sizeof (long) * CPUSTATES);
+  safe_kvm_read(nlst[CP_TIME_SYM_INDEX].n_value + (index * size), 
+                timeArray, size);
 }
 
 
diff -u /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/kernel.h bsd/kernel.h
--- /usr/ports/sysutils/xosview/work/xosview-1.7.1/bsd/kernel.h	Fri May 29 14:21:36 1998
+++ bsd/kernel.h	Wed Sep  1 21:28:43 1999
@@ -39,7 +39,7 @@
 BSDCPUInit();
 
 void
-BSDGetCPUTimes(long* timesArray);
+BSDGetCPUTimes(long* timesArray, int index);
 
 void
 BSDNetInit();

--EeQfGwPcQSOJBaQU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mp_cp_time.patch"

Index: kern//kern_clock.c
===================================================================
RCS file: /home/adsharma/cvs_root/freebsd-sys/kern/kern_clock.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 kern_clock.c
--- kern_clock.c	1999/08/31 05:12:42	1.1.1.2
+++ kern_clock.c	1999/09/02 04:13:35
@@ -89,7 +89,7 @@
 
 /* Some of these don't belong here, but it's easiest to concentrate them. */
 #if defined(SMP) && defined(BETTER_CLOCK)
-long cp_time[CPUSTATES];
+long cp_time[NCPUS][CPUSTATES];
 #else
 static long cp_time[CPUSTATES];
 #endif
@@ -389,9 +389,17 @@
 		 */
 		p->p_uticks++;
 		if (p->p_nice > NZERO)
+#ifdef SMP
+			cp_time[cpuid][CP_NICE]++;
+#else
 			cp_time[CP_NICE]++;
+#endif
 		else
+#ifdef SMP
+			cp_time[cpuid][CP_USER]++;
+#else
 			cp_time[CP_USER]++;
+#endif
 	} else {
 #ifdef GPROF
 		/*
@@ -428,12 +436,26 @@
 		if (CLKF_INTR(frame)) {
 			if (p != NULL)
 				p->p_iticks++;
+#ifdef SMP
+			cp_time[cpuid][CP_INTR]++;
+#else
 			cp_time[CP_INTR]++;
+#endif
+
 		} else if (p != NULL) {
 			p->p_sticks++;
+#ifdef SMP
+			cp_time[cpuid][CP_SYS]++;
+#else
 			cp_time[CP_SYS]++;
+#endif
 		} else
+#ifdef SMP
+			cp_time[cpuid][CP_IDLE]++;
+#else
 			cp_time[CP_IDLE]++;
+#endif
+
 	}
 	pscnt = psdiv;
 
Index: i386//i386/mp_machdep.c
===================================================================
RCS file: /home/adsharma/cvs_root/freebsd-sys/i386/i386/mp_machdep.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 mp_machdep.c
--- mp_machdep.c	1999/08/31 05:12:10	1.1.1.2
+++ mp_machdep.c	1999/09/02 04:15:26
@@ -2227,8 +2227,9 @@
 int		checkstate_cpustate[NCPU];
 u_long		checkstate_pc[NCPU];
 
-extern long	cp_time[CPUSTATES];
+extern long	cp_time[NCPUS][CPUSTATES];
 
+
 #define PC_TO_INDEX(pc, prof)				\
         ((int)(((u_quad_t)((pc) - (prof)->pr_off) *	\
             (u_quad_t)((prof)->pr_scale)) >> 16) & ~1)
@@ -2278,9 +2279,9 @@
 			return;
 		p->p_uticks++;
 		if (p->p_nice > NZERO)
-			cp_time[CP_NICE]++;
+			cp_time[cpuid][CP_NICE]++;
 		else
-			cp_time[CP_USER]++;
+			cp_time[cpuid][CP_USER]++;
 		break;
 	case CHECKSTATE_SYS:
 #ifdef GPROF
@@ -2300,10 +2301,10 @@
 			return;
 
 		if (!p)
-			cp_time[CP_IDLE]++;
+			cp_time[cpuid][CP_IDLE]++;
 		else {
 			p->p_sticks++;
-			cp_time[CP_SYS]++;
+			cp_time[cpuid][CP_SYS]++;
 		}
 		break;
 	case CHECKSTATE_INTR:
@@ -2325,7 +2326,7 @@
 			return;
 		if (p)
 			p->p_iticks++;
-		cp_time[CP_INTR]++;
+		cp_time[cpuid][CP_INTR]++;
 	}
 	if (p != NULL) {
 		p->p_cpticks++;

--EeQfGwPcQSOJBaQU--


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




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