diff options
-rw-r--r-- | usr.bin/systat/vmstat.c | 190 | ||||
-rw-r--r-- | usr.bin/vmstat/vmstat.8 | 8 | ||||
-rw-r--r-- | usr.bin/vmstat/vmstat.c | 129 |
3 files changed, 85 insertions, 242 deletions
diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c index b61ac4ddf3f..e95f12bbf2d 100644 --- a/usr.bin/systat/vmstat.c +++ b/usr.bin/systat/vmstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmstat.c,v 1.50 2004/06/11 06:31:32 deraadt Exp $ */ +/* $OpenBSD: vmstat.c,v 1.51 2004/06/28 01:45:51 aaron Exp $ */ /* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; #endif -static char rcsid[] = "$OpenBSD: vmstat.c,v 1.50 2004/06/11 06:31:32 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: vmstat.c,v 1.51 2004/06/28 01:45:51 aaron Exp $"; #endif /* not lint */ /* @@ -63,12 +63,6 @@ static char rcsid[] = "$OpenBSD: vmstat.c,v 1.50 2004/06/11 06:31:32 deraadt Exp #include <utmp.h> #include <unistd.h> -#if defined(__i386__) -#define _KERNEL -#include <machine/psl.h> -#undef _KERNEL -#endif - #include "systat.h" #include "extern.h" @@ -144,12 +138,6 @@ static struct nlist namelist[] = { { "_intrcnt" }, #define X_EINTRCNT 3 /* no sysctl */ { "_eintrcnt" }, -#if defined(__i386__) -#define X_INTRHAND 4 /* no sysctl */ - { "_intrhand" }, -#define X_APICINTRHAND 5 /* no sysctl */ - { "_apic_intrhand" }, -#endif { "" }, }; @@ -184,17 +172,12 @@ int ncpu = 1; int initkre(void) { - char *intrnamebuf, *cp; - size_t size = sizeof(ncpu); - int mib[2], i, ret; + int mib[4], i, ret; + size_t size; if (namelist[0].n_type == 0) { if ((ret = kvm_nlist(kd, namelist)) == -1) errx(1, "%s", kvm_geterr(kd)); -#if defined(__i386__) - else if (ret == 1 && namelist[X_APICINTRHAND].n_value != 0) - nlisterr(namelist); -#endif else if (ret > 1) nlisterr(namelist); if (namelist[0].n_type == 0) { @@ -205,102 +188,46 @@ initkre(void) mib[0] = CTL_HW; mib[1] = HW_NCPU; - if (sysctl(mib, 2, &ncpu, &size, NULL, 0) == -1) - return (-1); + size = sizeof(ncpu); + if (sysctl(mib, 2, &ncpu, &size, NULL, 0) < 0) + return (-1); hertz = stathz ? stathz : hz; if (!dkinit(1)) return(0); - if (nintr == 0) { -#if defined(__i386__) - struct intrhand *intrhand[16], *ihp, ih; - struct intrhand *apicintrhand[256]; - char iname[16]; - int namelen, n; - - NREAD(X_INTRHAND, intrhand, sizeof(intrhand)); - for (namelen = 0, i = 0; i < 16; i++) { - ihp = intrhand[i]; - while (ihp) { - nintr++; - KREAD(ihp, &ih, sizeof(ih)); - KREAD(ih.ih_what, iname, 16); - namelen += strlen(iname) + 1; - ihp = ih.ih_next; - } - } - if (namelist[X_APICINTRHAND].n_value) { - NREAD(X_APICINTRHAND, apicintrhand, sizeof(apicintrhand)); - for (namelen = 0, i = 0; i < 256; i++) { - ihp = apicintrhand[i]; - while (ihp) { - nintr++; - KREAD(ihp, &ih, sizeof(ih)); - KREAD(ih.ih_what, iname, 16); - namelen += strlen(iname) + 1; - printf("apic handler %x %s\n", i, iname); - ihp = ih.ih_next; - } - } - } - intrloc = calloc(nintr, sizeof (long)); - intrname = calloc(nintr, sizeof (char *)); - cp = intrnamebuf = malloc(namelen); - for (i = 0, n = 0; i < 16; i++) { - ihp = intrhand[i]; - while (ihp) { - KREAD(ihp, &ih, sizeof(ih)); - KREAD(ih.ih_what, iname, 16); - intrname[n++] = cp; - strlcpy(cp, iname, intrnamebuf + namelen - cp); - cp += strlen(iname) + 1; - ihp = ih.ih_next; - } - } - if (namelist[X_APICINTRHAND].n_value) { - for (i = 0, n = 0; i < 256; i++) { - ihp = apicintrhand[i]; - while (ihp) { - KREAD(ihp, &ih, sizeof(ih)); - KREAD(ih.ih_what, iname, 16); - intrname[n++] = cp; - strlcpy(cp, iname, intrnamebuf + namelen - cp); - cp += strlen(iname) + 1; - ihp = ih.ih_next; - } - } - } -#else - nintr = (namelist[X_EINTRCNT].n_value - - namelist[X_INTRCNT].n_value) / sizeof (int); - intrloc = calloc(nintr, sizeof (long)); - intrname = calloc(nintr, sizeof (long)); - intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value - - namelist[X_INTRNAMES].n_value); - if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) { - error("Out of memory\n"); - if (intrnamebuf) - free(intrnamebuf); - if (intrname) - free(intrname); - if (intrloc) - free(intrloc); - nintr = 0; - return(0); - } - NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) - - NVAL(X_INTRNAMES)); - for (cp = intrnamebuf, i = 0; i < nintr; i++) { - intrname[i] = cp; - cp += strlen(cp) + 1; - } -#endif - nextintsrow = INTSROW + 2; - allocinfo(&s); - allocinfo(&s1); - allocinfo(&s2); - allocinfo(&z); + + mib[0] = CTL_KERN; + mib[1] = KERN_INTRCNT; + mib[2] = KERN_INTRCNT_NUM; + size = sizeof(nintr); + if (sysctl(mib, 3, &nintr, &size, NULL, 0) < 0) + return (-1); + + intrloc = calloc(nintr, sizeof(long)); + intrname = calloc(nintr, sizeof(char *)); + + for (i = 0; i < nintr; i++) { + char name[128]; + + mib[0] = CTL_KERN; + mib[1] = KERN_INTRCNT; + mib[2] = KERN_INTRCNT_NAME; + mib[3] = i; + size = sizeof(name); + if (sysctl(mib, 4, name, &size, NULL, 0) < 0) + return (-1); + + intrname[i] = strdup(name); + if (intrname[i] == NULL) + return (-1); } + + nextintsrow = INTSROW + 2; + allocinfo(&s); + allocinfo(&s1); + allocinfo(&s2); + allocinfo(&z); + getinfo(&s2, RUN); copyinfo(&s2, &s1); return(1); @@ -679,38 +606,21 @@ getinfo(struct Info *s, enum state st) static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS }; static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP }; static int vmtotal_mib[2] = { CTL_VM, VM_METER }; + int mib[4], i; size_t size; -#if defined(__i386__) - struct intrhand *intrhand[16], *ihp, ih; - struct intrhand *apicintrhand[256]; - int i, n; -#endif dkreadstats(); -#if defined(__i386__) - NREAD(X_INTRHAND, intrhand, sizeof(intrhand)); - for (i = 0, n = 0; i < 16; i++) { - ihp = intrhand[i]; - while (ihp) { - KREAD(ihp, &ih, sizeof(ih)); - s->intrcnt[n++] = ih.ih_count; - ihp = ih.ih_next; - } - } - if (namelist[X_APICINTRHAND].n_value) { - NREAD(X_APICINTRHAND, apicintrhand, sizeof(apicintrhand)); - for (i = 0, n = 0; i < 256; i++) { - ihp = apicintrhand[i]; - while (ihp) { - KREAD(ihp, &ih, sizeof(ih)); - s->intrcnt[n++] = ih.ih_count; - ihp = ih.ih_next; - } - } + + for (i = 0; i < nintr; i++) { + mib[0] = CTL_KERN; + mib[1] = KERN_INTRCNT; + mib[2] = KERN_INTRCNT_CNT; + mib[3] = i; + size = sizeof(s->intrcnt[i]); + if (sysctl(mib, 4, &s->intrcnt[i], &size, NULL, 0) < 0) + s->intrcnt[i] = 0; } -#else - NREAD(X_INTRCNT, s->intrcnt, nintr * sizeof(int)); -#endif + size = sizeof(s->time); if (sysctl(cp_time_mib, 2, &s->time, &size, NULL, 0) < 0) { error("Can't get KERN_CPTIME: %s\n", strerror(errno)); diff --git a/usr.bin/vmstat/vmstat.8 b/usr.bin/vmstat/vmstat.8 index 7643074b322..a861e43ad3b 100644 --- a/usr.bin/vmstat/vmstat.8 +++ b/usr.bin/vmstat/vmstat.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: vmstat.8,v 1.30 2004/03/17 09:59:19 jmc Exp $ +.\" $OpenBSD: vmstat.8,v 1.31 2004/06/28 01:45:51 aaron Exp $ .\" $NetBSD: vmstat.8,v 1.12 1996/05/10 23:19:30 thorpej Exp $ .\" .\" Copyright (c) 1986, 1993 @@ -38,7 +38,7 @@ .Nd report statistics about kernel activities .Sh SYNOPSIS .Nm vmstat -.Op Fl fimstv +.Op Fl fimstvz .Nm vmstat .Op Fl c Ar count .Op Fl M Ar core @@ -97,6 +97,10 @@ If no repeat is specified, the default is infinity. .It Fl v Print more verbose information. +.It Fl z +When used with +.Fl i , +also list devices which have not yet generated an interrupt. .El .Pp By default, diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 35cb88b7c42..003a92c9a4e 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -1,5 +1,5 @@ /* $NetBSD: vmstat.c,v 1.29.4.1 1996/06/05 00:21:05 cgd Exp $ */ -/* $OpenBSD: vmstat.c,v 1.86 2004/06/14 00:39:33 deraadt Exp $ */ +/* $OpenBSD: vmstat.c,v 1.87 2004/06/28 01:45:51 aaron Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: vmstat.c,v 1.86 2004/06/14 00:39:33 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: vmstat.c,v 1.87 2004/06/28 01:45:51 aaron Exp $"; #endif #endif /* not lint */ @@ -103,14 +103,6 @@ struct nlist namelist[] = { #define X_EINTRCNT 12 /* no sysctl */ { "_eintrcnt" }, #define X_END 13 /* no sysctl */ -#if defined(__i386__) -#define X_INTRHAND (X_END) /* no sysctl */ - { "_intrhand" }, -#define X_APICINTRHAND (X_END+1) /* no sysctl */ - { "_apic_intrhand" }, -#define X_INTRSTRAY (X_END+2) /* no sysctl */ - { "_intrstray" }, -#endif { "" }, }; @@ -154,6 +146,7 @@ char *nlistf, *memf; extern char *__progname; int verbose = 0; +int zflag = 0; int ncpu; @@ -170,7 +163,7 @@ main(int argc, char *argv[]) char errbuf[_POSIX2_LINE_MAX]; interval = reps = todo = 0; - while ((c = getopt(argc, argv, "c:fiM:mN:stw:v")) != -1) { + while ((c = getopt(argc, argv, "c:fiM:mN:stw:vz")) != -1) { switch (c) { case 'c': reps = atoi(optarg); @@ -202,6 +195,9 @@ main(int argc, char *argv[]) case 'v': verbose = 1; break; + case 'z': + zflag = 1; + break; case '?': default: usage(); @@ -233,11 +229,6 @@ main(int argc, char *argv[]) setgid(getgid()); setegid(getegid()); -#ifdef __i386__ - if (c == 1 && namelist[X_APICINTRHAND].n_value == 0) - ; - else -#endif if (c > 0) { (void)fprintf(stderr, "%s: undefined symbols:", __progname); @@ -712,83 +703,6 @@ cpustats(void) (void)printf("%2.0f", cur.cp_time[CP_IDLE] * pct); } -#if defined(__i386__) -/* To get struct intrhand */ -#define _KERNEL -#include <machine/psl.h> -#include <machine/cpu.h> -#undef _KERNEL -void -dointr(void) -{ - struct intrhand *intrhand[16], *ihp, ih; - struct intrhand *apicintrhand[256]; - u_long inttotal = 0; - time_t uptime; - u_long intrstray[16]; - char iname[17], fname[31]; - int i; - - iname[16] = '\0'; - uptime = getuptime(); - - (void)printf("interrupt total rate\n"); - - kread(X_INTRHAND, intrhand, sizeof(intrhand)); - kread(X_INTRSTRAY, intrstray, sizeof(intrstray)); - - for (i = 0; i < 16; i++) { - ihp = intrhand[i]; - while (ihp) { - if (kvm_read(kd, (u_long)ihp, &ih, - sizeof(ih)) != sizeof(ih)) - errx(1, "vmstat: ih: %s", - kvm_geterr(kd)); - if (kvm_read(kd, (u_long)ih.ih_what, iname, - 16) != 16) - errx(1, "vmstat: ih_what: %s", - kvm_geterr(kd)); - snprintf(fname, sizeof fname, "irq%d/%s", i, - iname); - printf("%-16.16s %10lu %8lu\n", fname, - ih.ih_count, ih.ih_count / uptime); - inttotal += ih.ih_count; - ihp = ih.ih_next; - } - } - if (namelist[X_APICINTRHAND].n_value) { - kread(X_APICINTRHAND, apicintrhand, sizeof(apicintrhand)); - - for (i = 0; i < 256; i++) { - ihp = apicintrhand[i]; - while (ihp) { - if (kvm_read(kd, (u_long)ihp, &ih, - sizeof(ih)) != sizeof(ih)) - errx(1, "vmstat: ih: %s", - kvm_geterr(kd)); - if (kvm_read(kd, (u_long)ih.ih_what, iname, - 16) != 16) - errx(1, "vmstat: ih_what: %s", - kvm_geterr(kd)); - snprintf(fname, sizeof fname, "irq%d/%s", i, - iname); - printf("%-16.16s %10lu %8lu\n", fname, - ih.ih_count, ih.ih_count / uptime); - inttotal += ih.ih_count; - ihp = ih.ih_next; - } - } - } - - for (i = 0; i < 16; i++) - if (intrstray[i]) { - printf("Stray irq %-2d %10lu %8lu\n", - i, intrstray[i], intrstray[i] / uptime); - inttotal += intrstray[i]; - } - printf("Total %10lu %8lu\n", inttotal, inttotal / uptime); -} -#else static void dointr_sysctl(void); static void dointr_kvm(void); @@ -827,18 +741,34 @@ dointr_sysctl(void) return; } + (void)printf("interrupt total rate\n"); + inttotal = 0; for (i = 0; i < nintr; i++) { + char name[128]; int cnt; + int vector; mib[0] = CTL_KERN; mib[1] = KERN_INTRCNT; mib[2] = KERN_INTRCNT_NAME; mib[3] = i; - siz = sizeof(intrname); - if (sysctl(mib, 4, intrname, &siz, NULL, 0) < 0) { + siz = sizeof(name); + if (sysctl(mib, 4, name, &siz, NULL, 0) < 0) { warnx("could not read kern.intrcnt.name.%d", i); - return ; + return; + } + + mib[0] = CTL_KERN; + mib[1] = KERN_INTRCNT; + mib[2] = KERN_INTRCNT_VECTOR; + mib[3] = i; + siz = sizeof(vector); + if (sysctl(mib, 4, &vector, &siz, NULL, 0) < 0) { + strlcpy(intrname, name, sizeof(intrname)); + } else { + snprintf(intrname, sizeof(intrname), "irq%d/%s", + vector, name); } mib[0] = CTL_KERN; @@ -850,8 +780,8 @@ dointr_sysctl(void) warnx("could not read kern.intrcnt.cnt.%d", i); return ; } - if (cnt) - (void)printf("%-14s %12d %8ld\n", intrname, + if (cnt || zflag) + (void)printf("%-16.16s %12d %8ld\n", intrname, cnt, (long)cnt / uptime); inttotal += cnt; } @@ -873,7 +803,7 @@ dointr_sysctl(void) } evptr = evcnt.ev_list.tqe_next; } - (void)printf("Total %12ld %8ld\n", inttotal, inttotal / uptime); + (void)printf("Total %12ld %8ld\n", inttotal, inttotal / uptime); } static void @@ -926,7 +856,6 @@ dointr_kvm(void) } (void)printf("Total %12ld %8ld\n", inttotal, inttotal / uptime); } -#endif /* * These names are defined in <sys/malloc.h>. |