Subject: Re: Top
To: Karl-Gunnar Hultland <dixie@Krille.Update.UU.SE>
From: Ron Roskens <roskens@reality.cs.umn.edu>
List: amiga
Date: 09/24/1994 06:54:08
Direct from the mouth of Karl-Gunnar Hultland:
>  I am trying to get top to compile on my NetBSD1.0b Amiga
>  and I cant get it to run, all configs I try lack some
>  headerfiles. And now my questions are:
>  
>  Have anyone managed to get top running?
Yes. Well, sorta. Using the BSD4.4 as a base I can provide a patch that will
allow top to compile and run. However, something isn't being done correctly 
because top will exit with a bus error or a seg. fault. I've traced it to the
exit routine called inside libgcc, at least that is where it errored out.
But without a working debugger for a -current kernel, it's impossible to go 
further with it right now.

Ron

*** machine/m_netbsd.c	Sat Sep 24 06:46:26 1994
--- machine/m_bsd44.c	Thu Apr 28 07:26:41 1994
***************
*** 1,22 ****
  /*
   * top - a top users display for Unix
   *
!  * SYNOPSIS:  For a NetBSD 1.0 system
   *	      Note process resident sizes could be wrong, but ps shows
   *	      zero for them too..
   *
   * DESCRIPTION:
!  * This is the machine-dependent module for NetBSD 1.0
   * Works for:
!  *	NetBSD-Amiga
   *
   * LIBS: -lkvm
   *
!  * AUTHORS: Christos Zoulas <christos@ee.cornell.edu>
!  *          Ron Roskens <rosk0001@gold.tc.umn.edu>
!  *
!  * NOTE: Original version was BSD4.4, added changes to compile and run on 
!  *       NetBSD 1.0
   */
  
  #include <sys/types.h>
--- 1,18 ----
  /*
   * top - a top users display for Unix
   *
!  * SYNOPSIS:  For a 4.4BSD system
   *	      Note process resident sizes could be wrong, but ps shows
   *	      zero for them too..
   *
   * DESCRIPTION:
!  * This is the machine-dependent module for BSD4.4 
   * Works for:
!  *	hp300
   *
   * LIBS: -lkvm
   *
!  * AUTHOR:  Christos Zoulas <christos@ee.cornell.edu>
   */
  
  #include <sys/types.h>
***************
*** 29,41 ****
  #include <math.h>
  #include <kvm.h>
  #include <sys/errno.h>
! #include <sys/sysctl.h>
  #include <sys/dir.h>
  #include <sys/dkstat.h>
  #include <sys/file.h>
  #include <sys/time.h>
  #include <vm/vm.h>
  
  static int check_nlist __P((struct nlist *));
  static int getkval __P((unsigned long, int *, int, char *));
  extern char* printable __P((char *));
--- 25,39 ----
  #include <math.h>
  #include <kvm.h>
  #include <sys/errno.h>
! /* #include <sys/sysctl.h> */
  #include <sys/dir.h>
  #include <sys/dkstat.h>
  #include <sys/file.h>
  #include <sys/time.h>
  #include <vm/vm.h>
  
+ #define DOSWAP
+ 
  static int check_nlist __P((struct nlist *));
  static int getkval __P((unsigned long, int *, int, char *));
  extern char* printable __P((char *));
***************
*** 44,49 ****
--- 42,54 ----
  #include "machine.h"
  #include "utils.h"
  
+ #define VMUNIX	"/vmunix"
+ #define KMEM	"/dev/kmem"
+ #define MEM	"/dev/mem"
+ #ifdef DOSWAP
+ #define SWAP	"/dev/drum"
+ #endif
+ 
  /* get_process_info passes back a handle.  This is what it looks like: */
  
  struct handle
***************
*** 60,67 ****
  #define VP(pp, field) ((pp)->kp_eproc.e_vm . field)
  
  /* define what weighted cpu is.  */
! #define weighted_cpu(pct, pp) (PP((pp),p_uticks) == 0 ? 0.0 : \
! 			 ((pct) / (1.0 - exp(PP((pp),p_uticks) * logcpu))))
  
  /* what we consider to be process size: */
  #define PROCSIZE(pp) (VP((pp), vm_tsize) + VP((pp), vm_dsize) + VP((pp), vm_ssize))
--- 65,72 ----
  #define VP(pp, field) ((pp)->kp_eproc.e_vm . field)
  
  /* define what weighted cpu is.  */
! #define weighted_cpu(pct, pp) (PP((pp), p_time) == 0 ? 0.0 : \
! 			 ((pct) / (1.0 - exp(PP((pp), p_time) * logcpu))))
  
  /* what we consider to be process size: */
  #define PROCSIZE(pp) (VP((pp), vm_tsize) + VP((pp), vm_dsize) + VP((pp), vm_ssize))
***************
*** 174,183 ****
      register int i = 0;
      register int pagesize;
  
!     /* KERNEL, KMEM, SWAP */
!     /* NetBSD definition states that NULL entries open the appropriate
!        file by default. */
!     if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)
  	return -1;
  
  
--- 179,185 ----
      register int i = 0;
      register int pagesize;
  
!     if ((kd = kvm_open(VMUNIX, MEM, SWAP, O_RDONLY, "kvm_open")) == NULL)
  	return -1;
  
  
***************
*** 371,377 ****
  	 *  processes---these get ignored unless show_sysprocs is set.
  	 */
  	if (PP(pp, p_stat) != 0 &&
! 	    (show_system || ((PP(pp, p_flag) & P_SYSTEM) == 0)))
  	{
  	    total_procs++;
  	    process_states[(unsigned char) PP(pp, p_stat)]++;
--- 373,379 ----
  	 *  processes---these get ignored unless show_sysprocs is set.
  	 */
  	if (PP(pp, p_stat) != 0 &&
! 	    (show_system || ((PP(pp, p_flag) & SSYS) == 0)))
  	{
  	    total_procs++;
  	    process_states[(unsigned char) PP(pp, p_stat)]++;
***************
*** 422,428 ****
      
  
      /* get the process's user struct and set cputime */
!     if ((PP(pp, p_flag) & P_INMEM) == 0) {
  	/*
  	 * Print swapped processes as <pname>
  	 */
--- 424,430 ----
      
  
      /* get the process's user struct and set cputime */
!     if ((PP(pp, p_flag) & SLOAD) == 0) {
  	/*
  	 * Print swapped processes as <pname>
  	 */
***************
*** 451,457 ****
  	    Proc_format,
  	    PP(pp, p_pid),
  	    (*get_userid)(EP(pp, e_pcred.p_ruid)),
! 	    PP(pp, p_priority) - PZERO,
  	    PP(pp, p_nice) - NZERO,
  	    format_k(pagetok(PROCSIZE(pp))),
  	    format_k(pagetok(VP(pp, vm_rssize))),
--- 453,459 ----
  	    Proc_format,
  	    PP(pp, p_pid),
  	    (*get_userid)(EP(pp, e_pcred.p_ruid)),
! 	    PP(pp, p_pri) - PZERO,
  	    PP(pp, p_nice) - NZERO,
  	    format_k(pagetok(PROCSIZE(pp))),
  	    format_k(pagetok(VP(pp, vm_rssize))),
***************
*** 587,593 ****
  			  sorted_state[(unsigned char) PP(p1, p_stat)])  == 0)
  	    {
  		/* use priority to break the tie */
! 		if ((result = PP(p2, p_priority) - PP(p1, p_priority)) == 0)
  		{
  		    /* use resident set size (rssize) to break the tie */
  		    if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0)
--- 589,595 ----
  			  sorted_state[(unsigned char) PP(p1, p_stat)])  == 0)
  	    {
  		/* use priority to break the tie */
! 		if ((result = PP(p2, p_pri) - PP(p1, p_pri)) == 0)
  		{
  		    /* use resident set size (rssize) to break the tie */
  		    if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0)