Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/top New module for top based on the old m_netbsd13.c...



details:   https://anonhg.NetBSD.org/src/rev/fad89c76bc0f
branches:  trunk
changeset: 486588:fad89c76bc0f
user:      simonb <simonb%NetBSD.org@localhost>
date:      Fri May 26 04:01:13 2000 +0000

description:
New module for top based on the old m_netbsd13.c module.
Uses new sysctl/kvm interfaces and removes setgid bit.

diffstat:

 usr.bin/top/Makefile             |    6 +-
 usr.bin/top/machine/m_netbsd13.c |  906 ---------------------------------------
 usr.bin/top/machine/m_netbsd15.c |  733 +++++++++++++++++++++++++++++++
 3 files changed, 735 insertions(+), 910 deletions(-)

diffs (truncated from 1671 to 300 lines):

diff -r 87355e1b03e1 -r fad89c76bc0f usr.bin/top/Makefile
--- a/usr.bin/top/Makefile      Fri May 26 03:34:24 2000 +0000
+++ b/usr.bin/top/Makefile      Fri May 26 04:01:13 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.3 1999/03/24 11:57:08 christos Exp $
+#      $NetBSD: Makefile,v 1.4 2000/05/26 04:01:13 simonb Exp $
 
 PROG=  top
 
@@ -6,13 +6,11 @@
 
 CPPFLAGS+=-I${.CURDIR} -I. -DORDER -DHAVE_STRERROR
 SRCS=  top.c commands.c display.c screen.c username.c utils.c version.c \
-       m_netbsd13.c
+       m_netbsd15.c
 DPSRCS+=sigdesc.h
 
 LDADD+=        -ltermcap -lm -lkvm
 DPADD+=        ${LIBTERMCAP} ${LIBM} ${LIBKVM}
-BINGRP=        kmem
-BINMODE=2555
 
 sigdesc.h: ${.CURDIR}/sigconv.awk ${DESTDIR}/usr/include/sys/signal.h
        awk -f ${.CURDIR}/sigconv.awk ${DESTDIR}/usr/include/sys/signal.h > \
diff -r 87355e1b03e1 -r fad89c76bc0f usr.bin/top/machine/m_netbsd13.c
--- a/usr.bin/top/machine/m_netbsd13.c  Fri May 26 03:34:24 2000 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,906 +0,0 @@
-/*     $NetBSD: m_netbsd13.c,v 1.11 2000/05/26 00:44:58 thorpej Exp $  */
-
-/*
- * top - a top users display for Unix
- *
- * SYNOPSIS:  For a NetBSD-1.3 (or later) system
- *
- * DESCRIPTION:
- * Originally written for BSD4.4 system by Christos Zoulas.
- * Based on the FreeBSD 2.0 version by Steven Wallace and Wolfram Schneider.
- * NetBSD-1.0 port by Arne Helme. Process ordering by Luke Mewburn.
- * NetBSD-1.3 port by Luke Mewburn, based on code by Matthew Green.
- * NetBSD-1.4/UVM port by matthew green.
- * -
- * This is the machine-dependent module for NetBSD-1.3 and later
- * works for:
- *     NetBSD-1.3
- *     NetBSD-1.3.1
- *     NetBSD-1.3.2
- *     NetBSD-1.3.3
- *     NetBSD-1.3.4 (beta)
- * and should work for:
- *     NetBSD-1.4   (when released)
- *
- * LIBS: -lkvm
- *
- * CFLAGS: -DHAVE_GETOPT -DORDER -DHAVE_STRERROR `printf ".include <bsd.own.mk>\nxxx:\n.if defined(UVM)\n\techo -DUVM\n.endif\n" | make -s -f-`
- *
- * AUTHORS:    Christos Zoulas <christos%ee.cornell.edu@localhost>
- *             Steven Wallace <swallace%freebsd.org@localhost>
- *             Wolfram Schneider <wosch%cs.tu-berlin.de@localhost>
- *             Arne Helme <arne%acm.org@localhost>
- *             Luke Mewburn <lukem%netbsd.org@localhost>
- *             matthew green <mrg%eterna.com.au@localhost>
- *
- *
- * $Id: m_netbsd13.c,v 1.11 2000/05/26 00:44:58 thorpej Exp $
- */
-#define UVM
-
-#include <sys/types.h>
-#include <sys/signal.h>
-#include <sys/param.h>
-#include <sys/stat.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>
-
-/* NetBSD 1.4 has <sys/swap.h> */
-#if defined(__NetBSD_Version__) && __NetBSD_Version__ >= 104000000
-#include <sys/swap.h>
-#else
-#include <vm/vm_swap.h>
-#endif
-
-#if defined(UVM)
-#include <uvm/uvm_extern.h>
-#endif
-
-#include "os.h"
-#include <err.h>
-#include <errno.h>
-#include <kvm.h>
-#include <math.h>
-#include <nlist.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static int check_nlist __P((struct nlist *));
-static int getkval __P((unsigned long, int *, int, char *));
-extern char* printable __P((char *));
-
-#include "top.h"
-#include "machine.h"
-#include "utils.h"
-
-
-/* get_process_info passes back a handle.  This is what it looks like: */
-
-struct handle
-{
-    struct kinfo_proc **next_proc;     /* points to next valid proc pointer */
-    int remaining;             /* number of pointers remaining */
-};
-
-/* declarations for load_avg */
-#include "loadavg.h"
-
-#define PP(pp, field) ((pp)->kp_proc . field)
-#define EP(pp, field) ((pp)->kp_eproc . field)
-#define VP(pp, field) ((pp)->kp_eproc.e_vm . field)
-
-/* define what weighted cpu is.  */
-#define weighted_cpu(pct, pp) (PP((pp), p_swtime) == 0 ? 0.0 : \
-                        ((pct) / (1.0 - exp(PP((pp), p_swtime) * logcpu))))
-
-/* what we consider to be process size: */
-#define PROCSIZE(pp) \
-       (VP((pp), vm_tsize) + VP((pp), vm_dsize) + VP((pp), vm_ssize))
-
-/* definitions for indices in the nlist array */
-
-
-static struct nlist nlst[] = {
-#define X_CCPU         0
-    { "_ccpu" },               /* 0 */
-#define X_CP_TIME      1
-    { "_cp_time" },            /* 1 */
-#define X_HZ           2
-    { "_hz" },                 /* 2 */
-#define X_STATHZ       3
-    { "_stathz" },             /* 3 */
-#define X_AVENRUN      4
-    { "_averunnable" },                /* 4 */
-#if !defined(UVM)
-#define X_CNT          5
-    { "_cnt" },
-#endif
-
-    { 0 }
-};
-
-/*
- *  These definitions control the format of the per-process area
- */
-
-static char header[] =
-  "  PID X        PRI NICE   SIZE   RES STATE     TIME   WCPU    CPU COMMAND";
-/* 0123456   -- field to fill in starts at header+6 */
-#define UNAME_START 6
-
-#define Proc_format \
-       "%5d %-8.8s %3d %4d%7s %5s %-7s%7s %5.2f%% %5.2f%% %.12s"
-
-
-/* process state names for the "STATE" column of the display */
-/* the extra nulls in the string "run" are for adding a slash and
-   the processor number when needed */
-
-char *state_abbrev[] =
-{
-    "", "start", "run\0\0\0", "sleep", "stop", "zomb"
-#ifdef SDEAD
-    , "dead"
-#endif
-#ifdef SONPROC
-    , "onproc"
-#endif
-};
-
-static kvm_t *kd;
-
-/* values that we stash away in _init and use in later routines */
-
-static double logcpu;
-
-/* these are retrieved from the kernel in _init */
-
-static int hz;
-static int ccpu;
-
-/* these are offsets obtained via nlist and used in the get_ functions */
-
-static unsigned long cp_time_offset;
-static unsigned long avenrun_offset;
-#if !defined(UVM)
-static unsigned long cnt_offset;
-#endif
-/* these are for calculating cpu state percentages */
-
-static long cp_time[CPUSTATES];
-static long cp_old[CPUSTATES];
-static long cp_diff[CPUSTATES];
-
-/* these are for detailing the process states */
-
-int process_states[8];
-char *procstatenames[] = {
-    "", " starting, ", " runnable, ", " sleeping, ", " stopped, ",
-    " zombie, ", " dead, ", " on processor, ",
-    NULL
-};
-
-/* these are for detailing the cpu states */
-
-int cpu_states[CPUSTATES];
-char *cpustatenames[] = {
-    "user", "nice", "system", "interrupt", "idle", NULL
-};
-
-/* these are for detailing the memory statistics */
-
-int memory_stats[7];
-char *memorynames[] = {
-    "K Act, ", "K Inact, ", "K Wired, ", "K Free, ",
-    "K Swap, ", "K Swap free, ",
-    NULL
-};
-
-
-/* these are names given to allowed sorting orders -- first is default */
-char *ordernames[] = {
-    "cpu",
-    "pri",
-    "res",
-    "size",
-    "state",
-    "time",
-    NULL
-};
-
-/* forward definitions for comparison functions */
-int (*proc_compares[]) __P((struct proc **, struct proc **)) = {
-    compare_cpu,
-    compare_prio,
-    compare_res,
-    compare_size,
-    compare_state,
-    compare_time,
-    NULL
-};
-
-
-/* these are for keeping track of the proc array */
-
-static int nproc;
-static int onproc = -1;
-static int pref_len;
-static struct kinfo_proc *pbase;
-static struct kinfo_proc **pref;
-
-/* these are for getting the memory statistics */
-
-static int pageshift;          /* log base 2 of the pagesize */
-
-/* define pagetok in terms of pageshift */
-
-#define pagetok(size) ((size) << pageshift)
-
-int
-machine_init(statics)
-    struct statics *statics;
-{
-    int i = 0;
-    int pagesize;
-
-    if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)
-       return -1;
-
-
-    /* get the list of symbols we want to access in the kernel */
-    (void) kvm_nlist(kd, nlst);
-    if (nlst[0].n_type == 0)
-    {
-       fprintf(stderr, "top: nlist failed\n");
-       return(-1);
-    }
-
-    /* make sure they were all found */
-    if (i > 0 && check_nlist(nlst) > 0)
-    {
-       return(-1);
-    }
-
-    /* get the symbol values out of kmem */
-    (void) getkval(nlst[X_STATHZ].n_value, (int *)(&hz), sizeof(hz), "!");
-    if (!hz) {



Home | Main Index | Thread Index | Old Index