Subject: bin/16020: top(1) update for UVM/UBC
To: None <gnats-bugs@gnats.netbsd.org>
From: Tomas Svensson <tsn@gbdev.net>
List: netbsd-bugs
Date: 03/23/2002 00:55:31
>Number:         16020
>Category:       bin
>Synopsis:       top(1) update for UVM/UBC
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 22 16:57:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Tomas Svensson
>Release:        NetBSD 1.5ZC
>Organization:
>Environment:
	NetBSD 1.5ZC
>Description:
	I updated top(1) to show some relevant information for UVM/UBC.
	
	Old memory info:
	
	Memory: 32M Act, 16M Inact, 132K Wired, 504K Free, 3912K Swp, 254M Swp free
	
	New memory info (swap got its own line, Exec = cached executable data,
	File = cached file data):

	Memory: 32M Act, 16M Inact, 132K Wired, 1920K Exec, 7292K File, 504K Free
	Swap: 257M Total, 3908K Used, 254M Free

>How-To-Repeat:
>Fix:

Index: display.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/display.c,v
retrieving revision 1.5
diff -u -r1.5 display.c
--- display.c	2001/06/19 13:42:22	1.5
+++ display.c	2002/03/23 00:43:52
@@ -68,14 +68,17 @@
 static char **procstate_names;
 static char **cpustate_names;
 static char **memory_names;
+static char **swap_names;
 
 static int num_procstates;
 static int num_cpustates;
 static int num_memory;
+static int num_swap;
 
 static int *lprocstates;
 static int *lcpustates;
 static int *lmemory;
+static int *lswap;
 
 static int *cpustate_columns;
 static int cpustate_total_length;
@@ -153,6 +156,10 @@
 	num_memory = string_count(memory_names);
 	lmemory = (int *)malloc(num_memory * sizeof(int));
 
+	swap_names = statics->swap_names;
+	num_swap = string_count(swap_names);
+	lswap = (int *)malloc(num_swap * sizeof(int));
+
 	/* calculate starting columns where needed */
 	cpustate_total_length = 0;
 	pp = cpustate_names;
@@ -544,6 +551,42 @@
     /* format the new line */
     summary_format(new, stats, memory_names);
     line_update(memory_buffer, new, x_mem, y_mem);
+}
+
+/*  
+ *  *_swap(stats) - print "Swap: " followed by the memory summary string
+ *  
+ *  Assumptions:  cursor is on "lastline"
+ *                for i_memory ONLY: cursor is on the previous line
+ */
+    
+char swap_buffer[MAX_COLS];
+
+void
+i_swap(stats)
+
+int *stats;
+
+{
+    fputs("\nSwap: ", stdout);
+    lastline++;
+
+    /* format and print the swap summary */
+    summary_format(swap_buffer, stats, swap_names);
+    fputs(swap_buffer, stdout);
+}
+
+void
+u_swap(stats)
+
+int *stats;
+
+{
+    static char new[MAX_COLS];
+
+    /* format the new line */
+    summary_format(new, stats, swap_names);
+    line_update(swap_buffer, new, x_swap, y_swap);
 }
 
 /*
Index: display.h
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/display.h,v
retrieving revision 1.4
diff -u -r1.4 display.h
--- display.h	2000/10/11 14:46:19	1.4
+++ display.h	2002/03/23 00:43:52
@@ -21,6 +21,8 @@
 void z_cpustates __P((void));
 void i_memory __P((int *));
 void u_memory __P((int *));
+void i_swap __P((int *));
+void u_swap __P((int *));
 void i_message __P((void));
 void u_message __P((void));
 void i_header __P((char *));
Index: layout.h
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/layout.h,v
retrieving revision 1.2
diff -u -r1.2 layout.h
--- layout.h	1999/04/12 06:02:26	1.2
+++ layout.h	2002/03/23 00:43:52
@@ -19,11 +19,13 @@
 #define  y_brkdn	1
 #define  x_mem		8
 #define  y_mem		3
-#define  y_message	4
+#define  x_swap 	6
+#define  y_swap 	4
+#define  y_message	5
 #define  x_header	0
-#define  y_header	5
+#define  y_header	6
 #define  x_idlecursor	0
-#define  y_idlecursor	4
-#define  y_procs	6
+#define  y_idlecursor	5
+#define  y_procs	7
 
 #define  y_cpustates	2
Index: machine.h
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/machine.h,v
retrieving revision 1.5
diff -u -r1.5 machine.h
--- machine.h	2001/05/22 15:38:22	1.5
+++ machine.h	2002/03/23 00:43:52
@@ -14,6 +14,7 @@
     char **procstate_names;
     char **cpustate_names;
     char **memory_names;
+    char **swap_names;
 #ifdef ORDER
     char **order_names;
 #endif
@@ -38,6 +39,7 @@
     int    *procstates;
     int    *cpustates;
     int    *memory;
+    int    *swap;
 };
 
 /* cpu_states is an array of percentages * 10.  For example, 
Index: top.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/top.c,v
retrieving revision 1.10
diff -u -r1.10 top.c
--- top.c	2001/06/21 21:27:51	1.10
+++ top.c	2002/03/23 00:43:53
@@ -78,6 +78,7 @@
 void (*d_procstates) __P((int, int *)) = i_procstates;
 void (*d_cpustates) __P((int *)) = i_cpustates;
 void (*d_memory) __P((int *)) = i_memory;
+void (*d_swap) __P((int *)) = i_swap;
 void (*d_message) __P((void)) = i_message;
 void (*d_header) __P((char *)) = i_header;
 void (*d_process) __P((int, char *)) = i_process;
@@ -534,6 +535,9 @@
 	/* display memory stats */
 	(*d_memory)(system_info.memory);
 
+	/* display swap stats */
+	(*d_swap)(system_info.swap); 
+
 	/* handle message area */
 	(*d_message)();
 
@@ -594,6 +598,7 @@
 		    d_procstates = u_procstates;
 		    d_cpustates = u_cpustates;
 		    d_memory = u_memory;
+		    d_swap = u_swap;
 		    d_message = u_message;
 		    d_header = u_header;
 		    d_process = u_process;
@@ -903,6 +908,7 @@
     d_procstates = i_procstates;
     d_cpustates  = i_cpustates;
     d_memory     = i_memory;
+    d_swap       = i_swap;
     d_message	 = i_message;
     d_header	 = i_header;
     d_process	 = i_process;
Index: top.h
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/top.h,v
retrieving revision 1.3
diff -u -r1.3 top.h
--- top.h	1999/04/12 06:02:26	1.3
+++ top.h	2002/03/23 00:43:53
@@ -10,7 +10,7 @@
 #define VERSION		3
 
 /* Number of lines of header information on the standard screen */
-#define Header_lines	6
+#define Header_lines	7
 
 /* Maximum number of columns allowed for display */
 #define MAX_COLS	128
Index: machine/m_netbsd15.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/machine/m_netbsd15.c,v
retrieving revision 1.15
diff -u -r1.15 m_netbsd15.c
--- m_netbsd15.c	2001/07/03 01:36:07	1.15
+++ m_netbsd15.c	2002/03/23 00:43:53
@@ -12,12 +12,13 @@
  * NetBSD-1.3 port by Luke Mewburn, based on code by Matthew Green.
  * NetBSD-1.4/UVM port by matthew green.
  * NetBSD-1.5 port by Simon Burge.
+ * NetBSD-1.6/UBC port by Tomas Svensson.
  * -
  * This is the machine-dependent module for NetBSD-1.5 and later
  * works for:
- *	NetBSD-1.4Z
+ *	NetBSD-1.5ZC
  * and should work for:
- *	NetBSD-1.5	(when released)
+ *	NetBSD-1.6	(when released)
  * -
  * top does not need to be installed setuid or setgid with this module.
  *
@@ -32,6 +33,7 @@
  *		Luke Mewburn <lukem@netbsd.org>
  *		matthew green <mrg@eterna.com.au>
  *		Simon Burge <simonb@netbsd.org>
+ *		Tomas Svensson <ts@unix1.net>
  *
  *
  * $Id: m_netbsd15.c,v 1.15 2001/07/03 01:36:07 christos Exp $
@@ -135,12 +137,18 @@
 
 int memory_stats[7];
 char *memorynames[] = {
-	"K Act, ", "K Inact, ", "K Wired, ", "K Free, ",
-	"K Swp, ", "K Swp free, ",
+	"K Act, ", "K Inact, ", "K Wired, ", "K Exec, ", "K File, ",
+	"K Free, ",
 	NULL
 };
 
+int swap_stats[4];
+char *swapnames[] = {
+	"K Total, ", "K Used, ", "K Free, ",
+	NULL
+};
 
+
 /* these are names given to allowed sorting orders -- first is default */
 char *ordernames[] = {
 	"cpu",
@@ -240,6 +248,7 @@
 	statics->procstate_names = procstatenames;
 	statics->cpustate_names = cpustatenames;
 	statics->memory_names = memorynames;
+	statics->swap_names = swapnames;
 	statics->order_names = ordernames;
 
 	/* all done! */
@@ -305,8 +314,11 @@
 	memory_stats[0] = pagetok(uvmexp.active);
 	memory_stats[1] = pagetok(uvmexp.inactive);
 	memory_stats[2] = pagetok(uvmexp.wired);
-	memory_stats[3] = pagetok(uvmexp.free);
-	memory_stats[4] = memory_stats[5] = 0;
+	memory_stats[3] = pagetok(uvmexp.execpages);
+	memory_stats[4] = pagetok(uvmexp.filepages);
+	memory_stats[5] = pagetok(uvmexp.free);
+
+	swap_stats[0] = swap_stats[1] = swap_stats[2] = 0;
 
 	seporig = NULL;
 	do {
@@ -332,8 +344,9 @@
 			totalsize += size;
 			totalinuse += inuse;
 		}
-		memory_stats[4] = dbtob(totalinuse) / 1024;
-		memory_stats[5] = dbtob(totalsize) / 1024 - memory_stats[4];
+		swap_stats[0] = dbtob(totalsize) / 1024;
+		swap_stats[1] = dbtob(totalinuse) / 1024;
+		swap_stats[2] = dbtob(totalsize) / 1024 - swap_stats[1];
 		/* Free here, before we malloc again in the next
 		 * iteration of this loop.
 		 */
@@ -349,10 +362,12 @@
 		free(seporig);
 
 	memory_stats[6] = -1;
+	swap_stats[3] = -1;
 
 	/* set arrays and strings */
 	si->cpustates = cpu_states;
 	si->memory = memory_stats;
+	si->swap = swap_stats;
 	si->last_pid = -1;
 }
 
>Release-Note:
>Audit-Trail:
>Unformatted: