*** /tmp/,RCSt1a05308	Wed Apr 26 08:35:39 1989
--- system.c	Wed Apr 26 08:35:22 1989
***************
*** 16,21 ****
--- 16,25 ----
  #include <sys/socket.h>
  #include <sys/vm.h>
  #include <sys/dk.h>
+ #ifdef SUN4_0
+ #include <kvm.h>
+ #include <fcntl.h>
+ #endif
  #include <nlist.h>
  #include <sys/buf.h>
  #ifdef vax
***************
*** 59,66 ****
--- 63,109 ----
  int debug = 0;
  #define max(a,b) (a>b ? a:b)
  
+ #ifdef sun386
  struct nlist nl[] = {
  #define X_CPTIME	0
+ 	{ "cp_time" },
+ #define X_RATE	  1
+ 	{ "rate" },
+ #define X_TOTAL	 2
+ 	{ "total" },
+ #define X_DEFICIT       3
+ 	{ "deficit" },
+ #define X_FORKSTAT      4
+ 	{ "forkstat" },
+ #define X_SUM	   5
+ 	{ "sum" },
+ #define X_FIRSTFREE     6
+ 	{ "firstfree" },
+ #define X_MAXFREE       7
+ 	{ "maxfree" },
+ #define X_BOOTTIME      8
+ 	{ "boottime" },
+ #define X_DKXFER	9
+ 	{ "dk_xfer" },
+ #define X_REC	   10
+ 	{ "rectime" },
+ #define X_PGIN	  11
+ 	{ "pgintime" },
+ #define X_HZ	    12
+ 	{ "hz" },
+ #define X_MBDINIT       13
+ 	{ "mbdinit" },
+ #define N_IFNET       14
+ 	{ "ifnet" },
+ #define X_UBDINIT	15
+ 	{ "ubdinit" },
+ #define X_IOCINIT	16
+ 	{ "ioccdinit" },
+ 	{ "" },
+ };
+ #else
+ struct nlist nl[] = {
+ #define X_CPTIME	0
  	{ "_cp_time" },
  #define X_RATE	  1
  	{ "_rate" },
***************
*** 96,101 ****
--- 139,145 ----
  	{ "_ioccdinit" },
  	{ "" },
  };
+ #endif
  
  char dr_name[DK_NDRIVE][10];
  char dr_unit[DK_NDRIVE];
***************
*** 129,135 ****
--- 173,184 ----
  int nintv;
  long t;
  
+ #ifdef SUN4_0
+ kvm_t *kd;
+ #define steal(where, var) kvm_read(kd, where, &var, sizeof var);
+ #else
  #define steal(where, var) lseek(mf, where, 0); read(mf, &var, sizeof var);
+ #endif
  #define pgtok(a) ((a)*NBPG/1024)
  
  void set_sys_defaults()
***************
*** 223,229 ****
--- 272,283 ----
    init_stat(USER_CPU_PERCENTAGE, 0, 100, "User", " CPU");
    init_stat(SYSTEM_CPU_PERCENTAGE, 0, 100, "System", " CPU");
    init_stat(IDLE_CPU_PERCENTAGE, 0, 100, "Idle", " CPU");
+ #ifdef SUN4_0
+   /* Kludge - maxfree isn't kept on Sun 4.0 (sigh) */
+   init_stat(FREE_MEM, 0, max(pgtok(maxfree), (2 * pgtok(total.t_free))), "Free", " memory");
+ #else
    init_stat(FREE_MEM, 0, pgtok(maxfree), "Free", " memory");
+ #endif
    init_stat(DISK_TRANSFERS, 0, 40, "Disk", " transfers");
    init_stat(INTERRUPTS, 0, 60, "Interrupts", "");
    init_stat(INPUT_PACKETS, 0, (have_disk ? 20 : 40), "Input", " packets");
***************
*** 317,326 ****
--- 371,385 ----
  
  	register int i;
  
+ #ifdef SUN4_0
+ 	kvm_read(kd, (long)nl[X_CPTIME].n_value, s.time, sizeof s.time);
+ 	kvm_read(kd, (long)nl[X_DKXFER].n_value, s.xfer, sizeof s.xfer);
+ #else
  	lseek(mf, (long)nl[X_CPTIME].n_value, 0);
  	read(mf, s.time, sizeof s.time);
  	lseek(mf, (long)nl[X_DKXFER].n_value, 0);
  	read(mf, s.xfer, sizeof s.xfer);
+ #endif
  	if (nintv != 1) {
  		steal((long)nl[X_SUM].n_value, rate);
  	} 
***************
*** 378,383 ****
--- 437,454 ----
  	register int i;
  	int nintv;
  
+ #ifdef SUN4_0
+ 	if ((kd = kvm_open(kernel_name, NULL, NULL, O_RDONLY, "xperfmon")) == NULL)
+ 		exit(1);
+ #ifdef sun386
+ 	if ((kvm_nlist(kd, nl) < 0) || ((nl[0].n_type == 0) && (nl[0].n_value == 0))) {
+ #else
+ 	if ((kvm_nlist(kd, nl) < 0) || (nl[0].n_type == 0)) {
+ #endif
+ 		fprintf(stderr, "no %s namelist\n", kernel_name);
+ 		exit(1);
+ 	}
+ #else
  	nlist(kernel_name, nl);
  	if(nl[0].n_type == 0) {
  		fprintf(stderr, "no %s namelist\n", kernel_name);
***************
*** 388,393 ****
--- 459,465 ----
  		fprintf(stderr, "cannot open %s\n", memory_name);
  		exit(1);
  	}
+ #endif
  	steal((long)nl[X_MAXFREE].n_value, maxfree);
  	steal((long)nl[X_BOOTTIME].n_value, boottime);
  	steal((long)nl[X_HZ].n_value, hz);
***************
*** 434,440 ****
  	mp = (struct mba_device *) nl[X_MBDINIT].n_value;
  	up = (struct uba_device *) nl[X_UBDINIT].n_value;
  	if (up == 0) {
! 		fprintf(stderr, "perfmon: Disk init info not in namelist\n");
  		exit(1);
  	}
  	if(mp) for (;;) {
--- 506,512 ----
  	mp = (struct mba_device *) nl[X_MBDINIT].n_value;
  	up = (struct uba_device *) nl[X_UBDINIT].n_value;
  	if (up == 0) {
! 		fprintf(stderr, "xperfmon: Disk init info not in namelist\n");
  		exit(1);
  	}
  	if(mp) for (;;) {
***************
*** 473,479 ****
  
  	mp = (struct mb_device *) nl[X_MBDINIT].n_value;
  	if (mp == 0) {
! 		fprintf(stderr, "vmstat: Disk init info not in namelist\n");
  		exit(1);
  	}
  	for (;;) {
--- 545,551 ----
  
  	mp = (struct mb_device *) nl[X_MBDINIT].n_value;
  	if (mp == 0) {
! 		fprintf(stderr, "xperfmon: Disk init info not in namelist\n");
  		exit(1);
  	}
  	for (;;) {
***************
*** 501,507 ****
  
  	mp = (struct iocc_device *) nl[X_IOCINIT].n_value;
  	if (mp == 0) {
! 		fprintf(stderr, "vmstat: Disk init info not in namelist\n");
  		exit(1);
  	}
  	for (;;) {
--- 573,579 ----
  
  	mp = (struct iocc_device *) nl[X_IOCINIT].n_value;
  	if (mp == 0) {
! 		fprintf(stderr, "xperfmon: Disk init info not in namelist\n");
  		exit(1);
  	}
  	for (;;) {
