Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Nov 2003 11:24:06 +0200
From:      Peter Pentchev <roam@ringlet.net>
To:        Dag-Erling Sm?rgrav <des@des.no>
Cc:        Mike Tancsa <mike@sentex.net>
Subject:   Re: interrupt statistics
Message-ID:  <20031121092406.GR300@straylight.m.ringlet.net>
In-Reply-To: <xzp65heje0n.fsf@dwp.des.no>
References:  <xzpy8ucpwz9.fsf@dwp.des.no> <jfforv4me3snqshljprg8jejht7ias0oih@4ax.com> <20031120044945.GA44933@falcon.midgard.homeip.net> <20031120131903.GG300@straylight.m.ringlet.net> <xzpznerjg2s.fsf@dwp.des.no> <20031120153655.GI300@straylight.m.ringlet.net> <xzpekw2jho0.fsf@dwp.des.no> <xzpad6qjh3z.fsf@dwp.des.no> <20031121085300.GP300@straylight.m.ringlet.net> <xzp65heje0n.fsf@dwp.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help

--xtx0sNU5lZ46KfgK
Content-Type: text/plain; charset=windows-1251
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Nov 21, 2003 at 09:56:40AM +0100, Dag-Erling Sm?rgrav wrote:
> Peter Pentchev <roam@ringlet.net> writes:
> > Point taken.  I was going to attach a patch that uses sysctlbyname(3),
> > fixes another buglet in the !VMSTAT_SYSCTL case (and is less intrusive),
> > and removes the intrcnt/intrnames-related namelist definitions for the
> > VMSTAT_SYSCTL case.  However, it seems to have "issues" on 64-bit
> > platforms, or at least beast.  I'm working on it.
>=20
> Never mind, I'll take it from here.  I've been working on it for the
> past hour and have a ton of additional patches.  There are other
> issues to address such as the fact that your patch breaks post-mortem
> use, and the desirability of removing vmstat's setgid bit.

I was thinking about the setgid bit too, but it can only be removed when
all of vmstat's functionality, not just dointr(), is converted to use
sysctl.  That was the next item on my todo list :)

Still, here's the updated patch I was speaking of, just to show you what
I meant about the !VMSTAT_SYSCTL buglet and it being less intrusive;
kvm_openfiles() was not invoked even in the !VMSTAT_SYSCTL case, meaning
dointr() wouldn't work at all then.

G'luck,
Peter

--=20
Peter Pentchev	roam@ringlet.net    roam@sbnd.net    roam@FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
Thit sentence is not self-referential because "thit" is not a word.

Index: src/usr.bin/vmstat/Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/vmstat/Makefile,v
retrieving revision 1.9
diff -u -r1.9 Makefile
--- src/usr.bin/vmstat/Makefile	8 Feb 2002 23:07:36 -0000	1.9
+++ src/usr.bin/vmstat/Makefile	20 Nov 2003 15:51:53 -0000
@@ -3,6 +3,7 @@
=20
 PROG=3D	vmstat
 MAN=3D	vmstat.8
+CFLAGS+=3D-DVMSTAT_SYSCTL
 BINGRP=3D	kmem
 BINMODE=3D2555
 DPADD=3D	${LIBKVM} ${LIBDEVSTAT}
Index: src/usr.bin/vmstat/vmstat.8
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/vmstat/vmstat.8,v
retrieving revision 1.25
diff -u -r1.25 vmstat.8
--- src/usr.bin/vmstat/vmstat.8	14 Apr 2003 07:22:25 -0000	1.25
+++ src/usr.bin/vmstat/vmstat.8	20 Nov 2003 15:51:53 -0000
@@ -41,7 +41,7 @@
 .Sh SYNOPSIS
 .Nm
 .\" .Op Fl fimst
-.Op Fl fimsz
+.Op Fl afimsz
 .Op Fl c Ar count
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -62,6 +62,10 @@
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl a
+When used with
+.Fl i ,
+include statistics about interrupts that have never been generated.
 .It Fl c
 Repeat the display
 .Ar count
Index: src/usr.bin/vmstat/vmstat.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.69
diff -u -r1.69 vmstat.c
--- src/usr.bin/vmstat/vmstat.c	9 Nov 2003 20:39:56 -0000	1.69
+++ src/usr.bin/vmstat/vmstat.c	21 Nov 2003 08:24:52 -0000
@@ -129,6 +129,7 @@
 struct	vmmeter sum, osum;
=20
 int	winlines =3D 20;
+int	aflag =3D 0;
 int	nflag =3D 0;
=20
 kvm_t *kd;
@@ -174,8 +175,11 @@
 	memf =3D nlistf =3D NULL;
 	interval =3D reps =3D todo =3D 0;
 	maxshowdevs =3D 2;
-	while ((c =3D getopt(argc, argv, "c:fiM:mN:n:p:stw:z")) !=3D -1) {
+	while ((c =3D getopt(argc, argv, "ac:fiM:mN:n:p:stw:z")) !=3D -1) {
 		switch (c) {
+		case 'a':
+			aflag++;
+			break;
 		case 'c':
 			reps =3D atoi(optarg);
 			break;
@@ -239,6 +243,9 @@
 	if (nlistf !=3D NULL || memf !=3D NULL)
 		setgid(getgid());
=20
+#ifdef VMSTAT_SYSCTL
+	if (todo & ~INTRSTAT) {
+#endif /* VMSTAT_SYSCTL */
 	kd =3D kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
 	if (kd =3D=3D 0)=20
 		errx(1, "kvm_openfiles: %s", errbuf);
@@ -258,6 +265,9 @@
 			warnx("kvm_nlist: %s", kvm_geterr(kd));
 		exit(1);
 	}
+#ifdef VMSTAT_SYSCTL
+	}
+#endif /* VMSTAT_SYSCTL */
=20
 	if (todo & VMSTAT) {
 		struct winsize winsize;
@@ -386,8 +396,26 @@
 	static time_t now;
 	time_t uptime;
=20
-	if (boottime.tv_sec =3D=3D 0)
+	if (boottime.tv_sec =3D=3D 0) {
+#ifdef VMSTAT_SYSCTL
+		int mib[2] =3D { CTL_KERN, KERN_BOOTTIME };
+		char *value;
+		size_t size;
+
+		if (sysctl(mib, 2, NULL, &size, NULL, NULL) =3D=3D -1)
+			err(1, "sysctl(kern.boottime)");
+		if (size < sizeof(boottime))
+			errx(1, "sizeof(kern.boottime) < sizeof(timeval)");
+		value =3D malloc(size);
+		if (value =3D=3D NULL)
+			errx(1, "malloc");
+		if (sysctl(mib, 2, value, &size, NULL, NULL) =3D=3D -1)
+			err(1, "sysctl(kern.boottime)");
+		memcpy(&boottime, value, sizeof(boottime));
+#else  /* VMSTAT_SYSCTL */
 		kread(X_BOOTTIME, &boottime, sizeof(boottime));
+#endif /* VMSTAT_SYSCTL */
+	}
 	(void)time(&now);
 	uptime =3D now - boottime.tv_sec;
 	if (uptime <=3D 0 || uptime > 60*60*24*365*10)
@@ -732,8 +760,41 @@
 	int i, istrnamlen;
 	size_t clen;
 	char *intrname, *tintrname;
+#ifdef VMSTAT_SYSCTL
+	int *mibcnt, *mibname;
+	size_t mibcntsize, mibnamesize;
+#endif /* VMSTAT_SYSCTL */
=20
 	uptime =3D getuptime();
+#ifdef VMSTAT_SYSCTL
+	/* Fetch the sysctl MIB's */
+	if (sysctlnametomib("hw.intrcnt", NULL, &mibcntsize) =3D=3D -1)
+		err(1, "fetching the MIB for the hw.intrcnt sysctl");
+	mibcnt =3D malloc(mibcntsize * sizeof(int));
+	if (mibcnt =3D=3D NULL)
+		errx(1, "malloc");
+	if (sysctlnametomib("hw.intrcnt", mibcnt, &mibcntsize) =3D=3D -1)
+		err(1, "fetching the MIB for the hw.intrcnt sysctl");
+	if (sysctlnametomib("hw.intrnames", NULL, &mibnamesize) =3D=3D -1)
+		err(1, "fetching the MIB for the hw.intrnames sysctl");
+	mibname =3D malloc(mibnamesize * sizeof(int));
+	if (mibname =3D=3D NULL)
+		errx(1, "malloc");
+	if (sysctlnametomib("hw.intrnames", mibname, &mibnamesize) =3D=3D -1)
+		err(1, "fetching the MIB for the hw.intrnames sysctl");
+
+	/* Fetch the arrays themselves */
+	if (sysctl(mibcnt, mibcntsize, NULL, &nintr, NULL, NULL) =3D=3D -1)
+		err(1, "sysctl(hw.intrcnt)");
+	intrcnt =3D malloc((size_t)nintr);
+	if (sysctl(mibcnt, mibcntsize, intrcnt, &nintr, NULL, NULL) =3D=3D -1)
+		err(1, "sysctl(hw.intrcnt)");
+	if (sysctl(mibname, mibnamesize, NULL, &inamlen, NULL, NULL) =3D=3D -1)
+		err(1, "sysctl(hw.intrnames)");
+	intrname =3D malloc((size_t)inamlen);
+	if (sysctl(mibname, mibnamesize, intrname, &inamlen, NULL, NULL) =3D=3D -=
1)
+		err(1, "sysctl(hw.intrnames)");
+#else  /* VMSTAT_SYSCTL */
 	nintr =3D namelist[X_EINTRCNT].n_value - namelist[X_INTRCNT].n_value;
 	inamlen =3D
 	    namelist[X_EINTRNAMES].n_value - namelist[X_INTRNAMES].n_value;
@@ -743,6 +804,7 @@
 		errx(1, "malloc");
 	kread(X_INTRCNT, intrcnt, (size_t)nintr);
 	kread(X_INTRNAMES, intrname, (size_t)inamlen);
+#endif /* VMSTAT_SYSCTL */
 	nintr /=3D sizeof(u_long);
 	tintrname =3D intrname;
 	istrnamlen =3D strlen("interrupt");
@@ -756,7 +818,7 @@
 	    "rate");
 	inttotal =3D 0;
 	while (--nintr >=3D 0) {
-		if (*intrcnt)
+		if (*intrcnt || (aflag && intrname[0]))
 			(void)printf("%-*s %20lu %10lu\n", istrnamlen, intrname,
 			    *intrcnt, *intrcnt / uptime);
 		intrname +=3D strlen(intrname) + 1;
@@ -829,7 +891,7 @@
 usage()
 {
 	(void)fprintf(stderr, "%s%s",
-		"usage: vmstat [-imsz] [-c count] [-M core] [-N system] [-w wait]\n",
+		"usage: vmstat [-aimsz] [-c count] [-M core] [-N system] [-w wait]\n",
 		"              [-n devs] [disks]\n");
 	exit(1);
 }

--xtx0sNU5lZ46KfgK
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (FreeBSD)

iD8DBQE/vdm27Ri2jRYZRVMRAr+MAJ9cTo49Ql6Rq+GsH5EKrYRgqOQ+oACfbLCY
H+LdM96ec4qJiKNC8s98lLY=
=2Rhd
-----END PGP SIGNATURE-----

--xtx0sNU5lZ46KfgK--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031121092406.GR300>