added depend label
[unix-history] / usr / src / usr.bin / vmstat / vmstat.c
index 074358d..34e173b 100644 (file)
@@ -1,6 +1,18 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)vmstat.c    4.17 (Berkeley) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)vmstat.c   5.8 (Berkeley) %G%";
+#endif not lint
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -9,11 +21,12 @@ static       char *sccsid = "@(#)vmstat.c    4.17 (Berkeley) %G%";
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/vm.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/vm.h>
-#include <sys/dk.h>
+#include <sys/dkstat.h>
 #include <sys/buf.h>
 #include <sys/dir.h>
 #include <sys/inode.h>
 #include <sys/namei.h>
 #include <sys/buf.h>
 #include <sys/dir.h>
 #include <sys/inode.h>
 #include <sys/namei.h>
+#include <sys/text.h>
 
 struct nlist nl[] = {
 #define        X_CPTIME        0
 
 struct nlist nl[] = {
 #define        X_CPTIME        0
@@ -56,11 +69,21 @@ struct nlist nl[] = {
        { "_eintrcnt" },
 #define        X_DK_NDRIVE     19
        { "_dk_ndrive" },
        { "_eintrcnt" },
 #define        X_DK_NDRIVE     19
        { "_dk_ndrive" },
+#define        X_XSTATS        20
+       { "_xstats" },
 #ifdef vax
 #ifdef vax
-#define X_MBDINIT      20
+#define X_MBDINIT      (X_XSTATS+1)
        { "_mbdinit" },
        { "_mbdinit" },
-#define X_UBDINIT      21
+#define X_UBDINIT      (X_XSTATS+2)
        { "_ubdinit" },
        { "_ubdinit" },
+#endif
+#ifdef tahoe
+#define        X_VBDINIT       (X_XSTATS+1)
+       { "_vbdinit" },
+#define        X_CKEYSTATS     (X_XSTATS+2)
+       { "_ckeystats" },
+#define        X_DKEYSTATS     (X_XSTATS+3)
+       { "_dkeystats" },
 #endif
        { "" },
 };
 #endif
        { "" },
 };
@@ -80,10 +103,6 @@ int hz;
 int    phz;
 int    HZ;
 
 int    phz;
 int    HZ;
 
-#ifdef vax
-#define        INTS(x) ((x) - (hz + phz))
-#endif
-
 struct {
        int     busy;
        long    time[CPUSTATES];
 struct {
        int     busy;
        long    time[CPUSTATES];
@@ -101,33 +120,33 @@ struct {
 #define        forkstat        s.Forkstat
 
 struct vmmeter osum;
 #define        forkstat        s.Forkstat
 
 struct vmmeter osum;
-int    zero;
 int    deficit;
 double etime;
 int    mf;
 time_t now, boottime;
 int    printhdr();
 int    deficit;
 double etime;
 int    mf;
 time_t now, boottime;
 int    printhdr();
+int    lines = 1;
+
+#define        INTS(x) ((x) - (hz + phz))
 
 main(argc, argv)
        int argc;
        char **argv;
 {
 
 main(argc, argv)
        int argc;
        char **argv;
 {
-       int lines;
        extern char *ctime();
        extern char *ctime();
-       register i,j;
+       register i;
        int iter, nintv, iflag = 0;
        int iter, nintv, iflag = 0;
-       double f1, f2;
        long t;
        long t;
-       char *arg, **cp, name[6], buf[BUFSIZ];
+       char *arg, **cp, buf[BUFSIZ];
 
        nlist("/vmunix", nl);
        if(nl[0].n_type == 0) {
 
        nlist("/vmunix", nl);
        if(nl[0].n_type == 0) {
-               printf("no /vmunix namelist\n");
+               fprintf(stderr, "no /vmunix namelist\n");
                exit(1);
        }
        mf = open("/dev/kmem", 0);
        if(mf < 0) {
                exit(1);
        }
        mf = open("/dev/kmem", 0);
        if(mf < 0) {
-               printf("cannot open /dev/kmem\n");
+               fprintf(stderr, "cannot open /dev/kmem\n");
                exit(1);
        }
        iter = 0;
                exit(1);
        }
        iter = 0;
@@ -179,14 +198,14 @@ main(argc, argv)
                read(mf, &phz, sizeof phz);
        }
        HZ = phz ? phz : hz;
                read(mf, &phz, sizeof phz);
        }
        HZ = phz ? phz : hz;
-       if (nl[DK_NDRIVE].n_value == 0) {
-               printf("dk_ndrive undefined in system\n");
+       if (nl[X_DK_NDRIVE].n_value == 0) {
+               fprintf(stderr, "dk_ndrive undefined in system\n");
                exit(1);
        }
        lseek(mf, nl[X_DK_NDRIVE].n_value, L_SET);
        read(mf, &dk_ndrive, sizeof (dk_ndrive));
        if (dk_ndrive <= 0) {
                exit(1);
        }
        lseek(mf, nl[X_DK_NDRIVE].n_value, L_SET);
        read(mf, &dk_ndrive, sizeof (dk_ndrive));
        if (dk_ndrive <= 0) {
-               printf("dk_ndrive %d\n", dk_ndrive);
+               fprintf(stderr, "dk_ndrive %d\n", dk_ndrive);
                exit(1);
        }
        dr_select = (int *)calloc(dk_ndrive, sizeof (int));
                exit(1);
        }
        dr_select = (int *)calloc(dk_ndrive, sizeof (int));
@@ -204,7 +223,8 @@ main(argc, argv)
        time(&now);
        nintv = now - boottime;
        if (nintv <= 0 || nintv > 60*60*24*365*10) {
        time(&now);
        nintv = now - boottime;
        if (nintv <= 0 || nintv > 60*60*24*365*10) {
-               printf("Time makes no sense... namelist must be wrong.\n");
+               fprintf(stderr,
+                   "Time makes no sense... namelist must be wrong.\n");
                exit(1);
        }
        if (iflag) {
                exit(1);
        }
        if (iflag) {
@@ -247,11 +267,9 @@ main(argc, argv)
        if (argc > 1)
                iter = atoi(argv[1]);
        signal(SIGCONT, printhdr);
        if (argc > 1)
                iter = atoi(argv[1]);
        signal(SIGCONT, printhdr);
-reprint:
-       lines = 20;
-       /* s1 = z; */
-       printhdr();
 loop:
 loop:
+       if (--lines == 0)
+               printhdr();
        lseek(mf, (long)nl[X_CPTIME].n_value, L_SET);
        read(mf, s.time, sizeof s.time);
        lseek(mf, (long)nl[X_DKXFER].n_value, L_SET);
        lseek(mf, (long)nl[X_CPTIME].n_value, L_SET);
        read(mf, s.time, sizeof s.time);
        lseek(mf, (long)nl[X_DKXFER].n_value, L_SET);
@@ -284,7 +302,7 @@ loop:
                etime = 1.;
        printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw);
 #define pgtok(a) ((a)*NBPG/1024)
                etime = 1.;
        printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw);
 #define pgtok(a) ((a)*NBPG/1024)
-       printf("%6d%5d", pgtok(total.t_avm), pgtok(total.t_free));
+       printf("%6d%6d", pgtok(total.t_avm), pgtok(total.t_free));
        printf("%4d%3d", (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv,
            (rate.v_xsfrec+rate.v_xifrec)/nintv);
        printf("%4d", pgtok(rate.v_pgpgin)/nintv);
        printf("%4d%3d", (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv,
            (rate.v_xsfrec+rate.v_xifrec)/nintv);
        printf("%4d", pgtok(rate.v_pgpgin)/nintv);
@@ -306,14 +324,9 @@ loop:
        }
        printf("\n");
        fflush(stdout);
        }
        printf("\n");
        fflush(stdout);
-contin:
        nintv = 1;
        nintv = 1;
-       --iter;
-       if(iter)
-       if(argc > 0) {
+       if (--iter &&argc > 0) {
                sleep(atoi(argv[0]));
                sleep(atoi(argv[0]));
-               if (--lines <= 0)
-                       goto reprint;
                goto loop;
        }
 }
                goto loop;
        }
 }
@@ -322,7 +335,7 @@ printhdr()
 {
        register int i, j;
 
 {
        register int i, j;
 
-       printf(" procs    memory              page           ");
+       printf(" procs     memory              page           ");
        i = (ndrives * 3 - 6) / 2;
        if (i < 0)
                i = 0;
        i = (ndrives * 3 - 6) / 2;
        if (i < 0)
                i = 0;
@@ -333,11 +346,12 @@ printhdr()
        for (j = 0; j < i; j++)
                putchar(' ');
        printf("               cpu\n");
        for (j = 0; j < i; j++)
                putchar(' ');
        printf("               cpu\n");
-       printf(" r b w   avm  fre  re at  pi  po  fr  de  sr ");
+       printf(" r b w   avm   fre  re at  pi  po  fr  de  sr ");
        for (i = 0; i < dk_ndrive; i++)
                if (dr_select[i])
                        printf("%c%c ", dr_name[i][0], dr_name[i][2]);  
        printf(" in  sy  cs us sy id\n");
        for (i = 0; i < dk_ndrive; i++)
                if (dr_select[i])
                        printf("%c%c ", dr_name[i][0], dr_name[i][2]);  
        printf(" in  sy  cs us sy id\n");
+       lines = 19;
 }
 
 dotimes()
 }
 
 dotimes()
@@ -356,10 +370,18 @@ dotimes()
        printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0));
 }
 
        printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0));
 }
 
+#if defined(tahoe)
+#include <tahoe/cpu.h>
+#endif
+
 dosum()
 {
        struct nchstats nchstats;
 dosum()
 {
        struct nchstats nchstats;
+       struct xstats xstats;
        long nchtotal;
        long nchtotal;
+#if defined(tahoe)
+       struct keystats keystats;
+#endif
 
        lseek(mf, (long)nl[X_SUM].n_value, L_SET);
        read(mf, &sum, sizeof sum);
 
        lseek(mf, (long)nl[X_SUM].n_value, L_SET);
        read(mf, &sum, sizeof sum);
@@ -374,7 +396,7 @@ dosum()
        printf("%9d pages paged out\n", sum.v_pgpgout);
        printf("%9d sequential process pages freed\n", sum.v_seqfree);
        printf("%9d total reclaims (%d%% fast)\n", sum.v_pgrec,
        printf("%9d pages paged out\n", sum.v_pgpgout);
        printf("%9d sequential process pages freed\n", sum.v_seqfree);
        printf("%9d total reclaims (%d%% fast)\n", sum.v_pgrec,
-           (sum.v_fastpgrec * 100) / (sum.v_pgrec == 0 ? 1 : sum.v_pgrec));
+           pct(sum.v_fastpgrec, sum.v_pgrec));
        printf("%9d reclaims from free list\n", sum.v_pgfrec);
        printf("%9d intransit blocking page faults\n", sum.v_intrans);
        printf("%9d zero fill pages created\n", sum.v_nzfod / CLSIZE);
        printf("%9d reclaims from free list\n", sum.v_pgfrec);
        printf("%9d intransit blocking page faults\n", sum.v_intrans);
        printf("%9d zero fill pages created\n", sum.v_nzfod / CLSIZE);
@@ -392,7 +414,7 @@ dosum()
        printf("%9d device interrupts\n", sum.v_intr);
        printf("%9d software interrupts\n", sum.v_soft);
 #ifdef vax
        printf("%9d device interrupts\n", sum.v_intr);
        printf("%9d software interrupts\n", sum.v_soft);
 #ifdef vax
-       printf("%9d pseduo-dma dz interrupts\n", sum.v_pdma);
+       printf("%9d pseudo-dma dz interrupts\n", sum.v_pdma);
 #endif
        printf("%9d traps\n", sum.v_trap);
        printf("%9d system calls\n", sum.v_syscall);
 #endif
        printf("%9d traps\n", sum.v_trap);
        printf("%9d system calls\n", sum.v_syscall);
@@ -401,12 +423,38 @@ dosum()
        nchtotal = nchstats.ncs_goodhits + nchstats.ncs_badhits +
            nchstats.ncs_falsehits + nchstats.ncs_miss + nchstats.ncs_long;
        printf("%9d total name lookups", nchtotal);
        nchtotal = nchstats.ncs_goodhits + nchstats.ncs_badhits +
            nchstats.ncs_falsehits + nchstats.ncs_miss + nchstats.ncs_long;
        printf("%9d total name lookups", nchtotal);
-#define        nz(x)   ((x) ? (x) : 1)
        printf(" (cache hits %d%% system %d%% per-process)\n",
        printf(" (cache hits %d%% system %d%% per-process)\n",
-           nchstats.ncs_goodhits * 100 / nz(nchtotal),
-           nchstats.ncs_pass2 * 100 / nz(nchtotal));
+           pct(nchstats.ncs_goodhits, nchtotal),
+           pct(nchstats.ncs_pass2, nchtotal));
        printf("%9s badhits %d, falsehits %d, toolong %d\n", "",
            nchstats.ncs_badhits, nchstats.ncs_falsehits, nchstats.ncs_long);
        printf("%9s badhits %d, falsehits %d, toolong %d\n", "",
            nchstats.ncs_badhits, nchstats.ncs_falsehits, nchstats.ncs_long);
+       lseek(mf, (long)nl[X_XSTATS].n_value, 0);
+       read(mf, &xstats, sizeof xstats);
+       printf("%9d total calls to xalloc (cache hits %d%%)\n",
+           xstats.alloc, pct(xstats.alloc_cachehit, xstats.alloc));
+       printf("%9s sticky %d flushed %d unused %d\n", "",
+           xstats.alloc_inuse, xstats.alloc_cacheflush, xstats.alloc_unused);
+       printf("%9d total calls to xfree", xstats.free);
+       printf(" (sticky %d cached %d swapped %d)\n",
+           xstats.free_inuse, xstats.free_cache, xstats.free_cacheswap);
+#if defined(tahoe)
+       lseek(mf, (long)nl[X_CKEYSTATS].n_value, 0);
+       read(mf, &keystats, sizeof keystats);
+       printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
+           keystats.ks_allocs, "code cache keys allocated",
+           pct(keystats.ks_free, keystats.ks_allocs),
+           pct(keystats.ks_norefs, keystats.ks_allocs),
+           pct(keystats.ks_taken, keystats.ks_allocs),
+           pct(keystats.ks_shared, keystats.ks_allocs));
+       lseek(mf, (long)nl[X_DKEYSTATS].n_value, 0);
+       read(mf, &keystats, sizeof keystats);
+       printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
+           keystats.ks_allocs, "data cache keys allocated",
+           pct(keystats.ks_free, keystats.ks_allocs),
+           pct(keystats.ks_norefs, keystats.ks_allocs),
+           pct(keystats.ks_taken, keystats.ks_allocs),
+           pct(keystats.ks_shared, keystats.ks_allocs));
+#endif
 }
 
 doforkst()
 }
 
 doforkst()
@@ -533,3 +581,35 @@ read_names()
        }
 }
 #endif
        }
 }
 #endif
+
+#ifdef tahoe
+#include <tahoevba/vbavar.h>
+
+/*
+ * Read the drive names out of kmem.
+ */
+read_names()
+{
+       struct vba_device udev, *up;
+       struct vba_driver udrv;
+       short two_char;
+       char *cp = (char *)&two_char;
+
+       up = (struct vba_device *) nl[X_VBDINIT].n_value;
+       if (up == 0) {
+               fprintf(stderr, "vmstat: Disk init info not in namelist\n");
+               exit(1);
+       }
+       for (;;) {
+               steal(up++, udev);
+               if (udev.ui_driver == 0)
+                       break;
+               if (udev.ui_dk < 0 || udev.ui_alive == 0)
+                       continue;
+               steal(udev.ui_driver, udrv);
+               steal(udrv.ud_dname, two_char);
+               sprintf(dr_name[udev.ui_dk], "%c%c%d",
+                    cp[0], cp[1], udev.ui_unit);
+       }
+}
+#endif