1994-05-26 05:23:31 +00:00
|
|
|
/*-
|
1997-03-11 13:00:41 +00:00
|
|
|
* Copyright (c) 1980, 1991, 1993, 1994
|
1994-05-26 05:23:31 +00:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
2002-05-28 06:52:21 +00:00
|
|
|
* Copyright (c) 2002 Networks Associates Technologies, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Portions of this software were developed for the FreeBSD Project by
|
|
|
|
* ThinkSec AS and NAI Labs, the Security Research Division of Network
|
|
|
|
* Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
|
|
|
|
* ("CBOSS"), as part of the DARPA CHATS research program.
|
1994-05-26 05:23:31 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-26 05:23:31 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 21:06:42 +00:00
|
|
|
#if 0
|
1994-05-26 05:23:31 +00:00
|
|
|
#ifndef lint
|
1997-10-09 07:22:08 +00:00
|
|
|
static const char copyright[] =
|
1997-03-11 13:00:41 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1991, 1993, 1994\n\
|
1994-05-26 05:23:31 +00:00
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-03-11 13:00:41 +00:00
|
|
|
static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95";
|
1994-05-26 05:23:31 +00:00
|
|
|
#endif /* not lint */
|
2003-05-03 21:06:42 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
2002-05-23 15:09:49 +00:00
|
|
|
#include <sys/stdint.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
1999-01-21 08:08:55 +00:00
|
|
|
#include <sys/blist.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
#include <sys/sysctl.h>
|
2004-11-27 06:51:39 +00:00
|
|
|
#include <vm/vm_param.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
2004-11-27 06:51:39 +00:00
|
|
|
#include <errno.h>
|
1996-09-29 19:25:10 +00:00
|
|
|
#include <fcntl.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <kvm.h>
|
2005-03-21 16:36:05 +00:00
|
|
|
#include <libutil.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2002-05-28 06:37:27 +00:00
|
|
|
enum {
|
|
|
|
NL_CONSTTY,
|
|
|
|
NL_MAXFILES,
|
|
|
|
NL_NFILES,
|
2009-06-11 17:03:28 +00:00
|
|
|
NL_TTY_LIST,
|
|
|
|
NL_MARKER
|
2002-05-28 06:37:27 +00:00
|
|
|
};
|
|
|
|
|
2009-06-11 17:03:28 +00:00
|
|
|
static struct {
|
|
|
|
int order;
|
|
|
|
const char *name;
|
|
|
|
} namelist[] = {
|
|
|
|
{ NL_CONSTTY, "_constty" },
|
|
|
|
{ NL_MAXFILES, "_maxfiles" },
|
|
|
|
{ NL_NFILES, "_openfiles" },
|
|
|
|
{ NL_TTY_LIST, "_tty_list" },
|
|
|
|
{ NL_MARKER, "" },
|
1994-05-26 05:23:31 +00:00
|
|
|
};
|
2009-06-11 17:03:28 +00:00
|
|
|
#define NNAMES (sizeof(namelist) / sizeof(*namelist))
|
|
|
|
static struct nlist nl[NNAMES];
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2005-03-21 16:36:05 +00:00
|
|
|
static int humanflag;
|
2002-05-23 14:44:23 +00:00
|
|
|
static int usenumflag;
|
|
|
|
static int totalflag;
|
|
|
|
static int swapflag;
|
2002-05-23 14:58:07 +00:00
|
|
|
static char *nlistf;
|
|
|
|
static char *memf;
|
2002-05-23 14:44:23 +00:00
|
|
|
static kvm_t *kd;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2009-06-11 09:02:22 +00:00
|
|
|
static const char *usagestr;
|
1995-05-13 17:25:23 +00:00
|
|
|
|
2002-05-23 14:48:25 +00:00
|
|
|
static void filemode(void);
|
2009-06-11 17:03:28 +00:00
|
|
|
static int getfiles(struct xfile **, size_t *);
|
2002-05-23 14:48:25 +00:00
|
|
|
static void swapmode(void);
|
|
|
|
static void ttymode(void);
|
2002-05-28 05:42:32 +00:00
|
|
|
static void ttyprt(struct xtty *);
|
2002-05-23 14:48:25 +00:00
|
|
|
static void usage(void);
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
int
|
2002-05-23 14:48:25 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2009-06-11 17:03:28 +00:00
|
|
|
int ch, quit, ret;
|
2002-05-23 14:53:04 +00:00
|
|
|
int fileflag, ttyflag;
|
2009-06-11 17:03:28 +00:00
|
|
|
unsigned int i;
|
2009-06-11 09:02:22 +00:00
|
|
|
char buf[_POSIX2_LINE_MAX];
|
|
|
|
const char *opts;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2002-05-23 14:53:04 +00:00
|
|
|
fileflag = swapflag = ttyflag = 0;
|
1995-05-13 17:25:23 +00:00
|
|
|
|
|
|
|
/* We will behave like good old swapinfo if thus invoked */
|
2002-05-28 06:52:21 +00:00
|
|
|
opts = strrchr(argv[0], '/');
|
1995-05-13 17:25:23 +00:00
|
|
|
if (opts)
|
|
|
|
opts++;
|
|
|
|
else
|
|
|
|
opts = argv[0];
|
2002-05-28 06:52:21 +00:00
|
|
|
if (!strcmp(opts, "swapinfo")) {
|
1995-05-13 17:25:23 +00:00
|
|
|
swapflag = 1;
|
2007-04-01 20:28:37 +00:00
|
|
|
opts = "ghkmM:N:";
|
|
|
|
usagestr = "swapinfo [-ghkm] [-M core [-N system]]";
|
1995-05-13 17:25:23 +00:00
|
|
|
} else {
|
2007-04-03 08:16:06 +00:00
|
|
|
opts = "TM:N:fghkmnst";
|
|
|
|
usagestr = "pstat [-Tfghkmnst] [-M core [-N system]]";
|
1995-05-13 17:25:23 +00:00
|
|
|
}
|
|
|
|
|
1997-03-31 05:11:47 +00:00
|
|
|
while ((ch = getopt(argc, argv, opts)) != -1)
|
1994-05-26 05:23:31 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
|
|
|
fileflag = 1;
|
|
|
|
break;
|
2007-04-01 20:28:37 +00:00
|
|
|
case 'g':
|
2007-07-04 00:00:41 +00:00
|
|
|
setenv("BLOCKSIZE", "1G", 1);
|
2007-04-01 20:28:37 +00:00
|
|
|
break;
|
2005-03-21 16:36:05 +00:00
|
|
|
case 'h':
|
|
|
|
humanflag = 1;
|
|
|
|
break;
|
1995-05-13 17:25:23 +00:00
|
|
|
case 'k':
|
2007-07-04 00:00:41 +00:00
|
|
|
setenv("BLOCKSIZE", "1K", 1);
|
1995-05-13 17:25:23 +00:00
|
|
|
break;
|
2007-04-01 20:28:37 +00:00
|
|
|
case 'm':
|
2007-07-04 00:00:41 +00:00
|
|
|
setenv("BLOCKSIZE", "1M", 1);
|
2007-04-01 20:28:37 +00:00
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
usenumflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
1999-01-21 08:08:55 +00:00
|
|
|
++swapflag;
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
totalflag = 1;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
ttyflag = 1;
|
|
|
|
break;
|
|
|
|
default:
|
1997-10-09 07:22:08 +00:00
|
|
|
usage();
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 17:03:28 +00:00
|
|
|
/*
|
|
|
|
* Initialize symbol names list.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NNAMES; i++)
|
|
|
|
nl[namelist[i].order].n_name = strdup(namelist[i].name);
|
|
|
|
|
2002-05-23 15:09:49 +00:00
|
|
|
if (memf != NULL) {
|
|
|
|
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf);
|
|
|
|
if (kd == NULL)
|
|
|
|
errx(1, "kvm_openfiles: %s", buf);
|
|
|
|
if ((ret = kvm_nlist(kd, nl)) != 0) {
|
|
|
|
if (ret == -1)
|
|
|
|
errx(1, "kvm_nlist: %s", kvm_geterr(kd));
|
|
|
|
quit = 0;
|
2002-05-28 06:37:27 +00:00
|
|
|
for (i = 0; nl[i].n_name[0] != '\0'; ++i)
|
|
|
|
if (nl[i].n_value == 0) {
|
2002-05-23 15:09:49 +00:00
|
|
|
quit = 1;
|
|
|
|
warnx("undefined symbol: %s",
|
|
|
|
nl[i].n_name);
|
|
|
|
}
|
|
|
|
if (quit)
|
|
|
|
exit(1);
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2002-05-23 14:53:04 +00:00
|
|
|
if (!(fileflag | ttyflag | swapflag | totalflag))
|
1997-10-09 07:22:08 +00:00
|
|
|
usage();
|
1994-05-26 05:23:31 +00:00
|
|
|
if (fileflag || totalflag)
|
|
|
|
filemode();
|
|
|
|
if (ttyflag)
|
|
|
|
ttymode();
|
|
|
|
if (swapflag || totalflag)
|
|
|
|
swapmode();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
1997-10-09 07:22:08 +00:00
|
|
|
static void
|
2002-05-23 14:48:25 +00:00
|
|
|
usage(void)
|
1997-10-09 07:22:08 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: %s\n", usagestr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2003-01-31 15:16:52 +00:00
|
|
|
static const char fhdr32[] =
|
|
|
|
" LOC TYPE FLG CNT MSG DATA OFFSET\n";
|
|
|
|
/* c0000000 ------ RWAI 123 123 c0000000 1000000000000000 */
|
|
|
|
|
|
|
|
static const char fhdr64[] =
|
|
|
|
" LOC TYPE FLG CNT MSG DATA OFFSET\n";
|
|
|
|
/* c000000000000000 ------ RWAI 123 123 c000000000000000 1000000000000000 */
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static const char hdr[] =
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
" LINE INQ CAN LIN LOW OUTQ USE LOW COL SESS PGID STATE\n";
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-28 06:37:27 +00:00
|
|
|
ttymode_kvm(void)
|
|
|
|
{
|
2004-06-09 12:20:44 +00:00
|
|
|
TAILQ_HEAD(, tty) tl;
|
2002-05-28 06:37:27 +00:00
|
|
|
struct tty *tp, tty;
|
|
|
|
struct xtty xt;
|
|
|
|
|
|
|
|
(void)printf("%s", hdr);
|
|
|
|
bzero(&xt, sizeof xt);
|
|
|
|
xt.xt_size = sizeof xt;
|
|
|
|
if (kvm_read(kd, nl[NL_TTY_LIST].n_value, &tl, sizeof tl) != sizeof tl)
|
|
|
|
errx(1, "kvm_read(): %s", kvm_geterr(kd));
|
2004-06-09 12:20:44 +00:00
|
|
|
tp = TAILQ_FIRST(&tl);
|
2002-05-28 06:37:27 +00:00
|
|
|
while (tp != NULL) {
|
|
|
|
if (kvm_read(kd, (u_long)tp, &tty, sizeof tty) != sizeof tty)
|
|
|
|
errx(1, "kvm_read(): %s", kvm_geterr(kd));
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
xt.xt_insize = tty.t_inq.ti_nblocks * TTYINQ_DATASIZE;
|
|
|
|
xt.xt_incc = tty.t_inq.ti_linestart - tty.t_inq.ti_begin;
|
|
|
|
xt.xt_inlc = tty.t_inq.ti_end - tty.t_inq.ti_linestart;
|
|
|
|
xt.xt_inlow = tty.t_inlow;
|
|
|
|
xt.xt_outsize = tty.t_outq.to_nblocks * TTYOUTQ_DATASIZE;
|
|
|
|
xt.xt_outcc = tty.t_outq.to_end - tty.t_outq.to_begin;
|
|
|
|
xt.xt_outlow = tty.t_outlow;
|
|
|
|
xt.xt_column = tty.t_column;
|
|
|
|
/* xt.xt_pgid = ... */
|
|
|
|
/* xt.xt_sid = ... */
|
|
|
|
xt.xt_flags = tty.t_flags;
|
|
|
|
xt.xt_dev = NODEV;
|
2002-05-28 06:37:27 +00:00
|
|
|
ttyprt(&xt);
|
2008-05-14 00:22:57 +00:00
|
|
|
tp = TAILQ_NEXT(&tty, t_list);
|
2002-05-28 06:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ttymode_sysctl(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2009-06-11 17:03:28 +00:00
|
|
|
struct xtty *xttys;
|
2002-05-28 05:42:32 +00:00
|
|
|
size_t len;
|
2009-06-11 17:03:28 +00:00
|
|
|
unsigned int i, n;
|
1999-08-08 19:44:00 +00:00
|
|
|
|
2001-06-17 02:01:43 +00:00
|
|
|
(void)printf("%s", hdr);
|
2009-06-11 17:03:28 +00:00
|
|
|
if ((xttys = malloc(len = sizeof(*xttys))) == NULL)
|
2002-05-28 05:42:32 +00:00
|
|
|
err(1, "malloc()");
|
|
|
|
while (sysctlbyname("kern.ttys", xttys, &len, 0, 0) == -1) {
|
|
|
|
if (errno != ENOMEM)
|
|
|
|
err(1, "sysctlbyname()");
|
|
|
|
len *= 2;
|
|
|
|
if ((xttys = realloc(xttys, len)) == NULL)
|
|
|
|
err(1, "realloc()");
|
|
|
|
}
|
2009-06-11 17:03:28 +00:00
|
|
|
n = len / sizeof(*xttys);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
ttyprt(&xttys[i]);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-28 06:37:27 +00:00
|
|
|
ttymode(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
|
|
|
|
2002-05-28 06:37:27 +00:00
|
|
|
if (kd != NULL)
|
|
|
|
ttymode_kvm();
|
|
|
|
else
|
|
|
|
ttymode_sysctl();
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static struct {
|
1994-05-26 05:23:31 +00:00
|
|
|
int flag;
|
|
|
|
char val;
|
|
|
|
} ttystates[] = {
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
#if 0
|
2009-02-05 14:21:09 +00:00
|
|
|
{ TF_NOPREFIX, 'N' },
|
1995-05-07 23:19:53 +00:00
|
|
|
#endif
|
2009-02-05 14:21:09 +00:00
|
|
|
{ TF_INITLOCK, 'I' },
|
|
|
|
{ TF_CALLOUT, 'C' },
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
|
|
|
|
/* Keep these together -> 'Oi' and 'Oo'. */
|
2009-02-05 14:21:09 +00:00
|
|
|
{ TF_OPENED, 'O' },
|
|
|
|
{ TF_OPENED_IN, 'i' },
|
|
|
|
{ TF_OPENED_OUT, 'o' },
|
|
|
|
{ TF_OPENED_CONS, 'c' },
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
|
2009-02-05 14:21:09 +00:00
|
|
|
{ TF_GONE, 'G' },
|
|
|
|
{ TF_OPENCLOSE, 'B' },
|
|
|
|
{ TF_ASYNC, 'Y' },
|
|
|
|
{ TF_LITERAL, 'L' },
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
|
|
|
|
/* Keep these together -> 'Hi' and 'Ho'. */
|
2009-02-05 14:21:09 +00:00
|
|
|
{ TF_HIWAT, 'H' },
|
|
|
|
{ TF_HIWAT_IN, 'i' },
|
|
|
|
{ TF_HIWAT_OUT, 'o' },
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
|
2009-02-05 14:21:09 +00:00
|
|
|
{ TF_STOPPED, 'S' },
|
|
|
|
{ TF_EXCLUDE, 'X' },
|
|
|
|
{ TF_BYPASS, 'l' },
|
|
|
|
{ TF_ZOMBIE, 'Z' },
|
|
|
|
{ TF_HOOK, 's' },
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
|
2009-02-11 16:28:49 +00:00
|
|
|
/* Keep these together -> 'bi' and 'bo'. */
|
|
|
|
{ TF_BUSY, 'b' },
|
|
|
|
{ TF_BUSY_IN, 'i' },
|
|
|
|
{ TF_BUSY_OUT, 'o' },
|
|
|
|
|
2009-02-05 14:21:09 +00:00
|
|
|
{ 0, '\0'},
|
1994-05-26 05:23:31 +00:00
|
|
|
};
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-28 05:42:32 +00:00
|
|
|
ttyprt(struct xtty *xt)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
1997-03-11 13:00:41 +00:00
|
|
|
int i, j;
|
2016-12-26 17:34:27 +00:00
|
|
|
const char *name;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2002-05-28 05:42:32 +00:00
|
|
|
if (xt->xt_size != sizeof *xt)
|
|
|
|
errx(1, "struct xtty size mismatch");
|
|
|
|
if (usenumflag || xt->xt_dev == 0 ||
|
|
|
|
(name = devname(xt->xt_dev, S_IFCHR)) == NULL)
|
2011-09-28 18:53:36 +00:00
|
|
|
printf("%#10jx ", (uintmax_t)xt->xt_dev);
|
1994-05-26 05:23:31 +00:00
|
|
|
else
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
printf("%10s ", name);
|
|
|
|
printf("%5zu %4zu %4zu %4zu %5zu %4zu %4zu %5u %5d %5d ",
|
|
|
|
xt->xt_insize, xt->xt_incc, xt->xt_inlc,
|
|
|
|
(xt->xt_insize - xt->xt_inlow), xt->xt_outsize,
|
|
|
|
xt->xt_outcc, (xt->xt_outsize - xt->xt_outlow),
|
2008-11-01 13:40:46 +00:00
|
|
|
MIN(xt->xt_column, 99999), xt->xt_sid, xt->xt_pgid);
|
1994-05-26 05:23:31 +00:00
|
|
|
for (i = j = 0; ttystates[i].flag; i++)
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
if (xt->xt_flags & ttystates[i].flag) {
|
|
|
|
putchar(ttystates[i].val);
|
|
|
|
j++;
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
if (j == 0)
|
Integrate the new MPSAFE TTY layer to the FreeBSD operating system.
The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:
- Improved driver model:
The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.
If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.
- Improved hotplugging:
With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).
The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.
- Improved performance:
One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.
Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.
Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan
2008-08-20 08:31:58 +00:00
|
|
|
putchar('-');
|
|
|
|
putchar('\n');
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-23 14:48:25 +00:00
|
|
|
filemode(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2009-06-11 17:03:28 +00:00
|
|
|
struct xfile *fp, *buf;
|
|
|
|
char flagbuf[16], *fbp;
|
2002-05-28 06:52:21 +00:00
|
|
|
int maxf, openf;
|
2002-05-23 15:09:49 +00:00
|
|
|
size_t len;
|
2009-06-11 09:59:47 +00:00
|
|
|
static char const * const dtypes[] = { "???", "inode", "socket",
|
2009-06-11 09:02:22 +00:00
|
|
|
"pipe", "fifo", "kqueue", "crypto" };
|
2002-07-31 12:43:17 +00:00
|
|
|
int i;
|
2003-01-31 15:16:52 +00:00
|
|
|
int wid;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2002-05-23 15:09:49 +00:00
|
|
|
if (kd != NULL) {
|
2002-05-28 06:52:21 +00:00
|
|
|
if (kvm_read(kd, nl[NL_MAXFILES].n_value,
|
|
|
|
&maxf, sizeof maxf) != sizeof maxf ||
|
|
|
|
kvm_read(kd, nl[NL_NFILES].n_value,
|
|
|
|
&openf, sizeof openf) != sizeof openf)
|
|
|
|
errx(1, "kvm_read(): %s", kvm_geterr(kd));
|
2002-05-23 15:09:49 +00:00
|
|
|
} else {
|
2002-05-28 06:52:21 +00:00
|
|
|
len = sizeof(int);
|
|
|
|
if (sysctlbyname("kern.maxfiles", &maxf, &len, 0, 0) == -1 ||
|
|
|
|
sysctlbyname("kern.openfiles", &openf, &len, 0, 0) == -1)
|
2002-05-23 15:09:49 +00:00
|
|
|
err(1, "sysctlbyname()");
|
|
|
|
}
|
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
if (totalflag) {
|
2002-05-28 06:52:21 +00:00
|
|
|
(void)printf("%3d/%3d files\n", openf, maxf);
|
1994-05-26 05:23:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (getfiles(&buf, &len) == -1)
|
|
|
|
return;
|
2002-07-31 12:43:17 +00:00
|
|
|
openf = len / sizeof *fp;
|
2003-01-31 15:16:52 +00:00
|
|
|
|
2002-05-28 06:52:21 +00:00
|
|
|
(void)printf("%d/%d open files\n", openf, maxf);
|
2003-01-31 15:16:52 +00:00
|
|
|
printf(sizeof(uintptr_t) == 4 ? fhdr32 : fhdr64);
|
|
|
|
wid = (int)sizeof(uintptr_t) * 2;
|
2002-07-31 12:43:17 +00:00
|
|
|
for (fp = (struct xfile *)buf, i = 0; i < openf; ++fp, ++i) {
|
2003-01-31 15:16:52 +00:00
|
|
|
if ((size_t)fp->xf_type >= sizeof(dtypes) / sizeof(dtypes[0]))
|
1994-05-26 05:23:31 +00:00
|
|
|
continue;
|
2003-01-31 15:16:52 +00:00
|
|
|
(void)printf("%*jx", wid, (uintmax_t)(uintptr_t)fp->xf_file);
|
|
|
|
(void)printf(" %-6.6s", dtypes[fp->xf_type]);
|
1994-05-26 05:23:31 +00:00
|
|
|
fbp = flagbuf;
|
2002-07-31 12:43:17 +00:00
|
|
|
if (fp->xf_flag & FREAD)
|
1994-05-26 05:23:31 +00:00
|
|
|
*fbp++ = 'R';
|
2002-07-31 12:43:17 +00:00
|
|
|
if (fp->xf_flag & FWRITE)
|
1994-05-26 05:23:31 +00:00
|
|
|
*fbp++ = 'W';
|
2002-07-31 12:43:17 +00:00
|
|
|
if (fp->xf_flag & FAPPEND)
|
1994-05-26 05:23:31 +00:00
|
|
|
*fbp++ = 'A';
|
2002-07-31 12:43:17 +00:00
|
|
|
if (fp->xf_flag & FASYNC)
|
1994-05-26 05:23:31 +00:00
|
|
|
*fbp++ = 'I';
|
|
|
|
*fbp = '\0';
|
2003-01-31 15:16:52 +00:00
|
|
|
(void)printf(" %4s %3d", flagbuf, fp->xf_count);
|
|
|
|
(void)printf(" %3d", fp->xf_msgcount);
|
|
|
|
(void)printf(" %*jx", wid, (uintmax_t)(uintptr_t)fp->xf_data);
|
|
|
|
(void)printf(" %*jx\n", (int)sizeof(fp->xf_offset) * 2,
|
|
|
|
(uintmax_t)fp->xf_offset);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static int
|
2009-06-11 17:03:28 +00:00
|
|
|
getfiles(struct xfile **abuf, size_t *alen)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2009-06-11 17:03:28 +00:00
|
|
|
struct xfile *buf;
|
1994-05-26 05:23:31 +00:00
|
|
|
size_t len;
|
|
|
|
int mib[2];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Add emulation of KINFO_FILE here.
|
|
|
|
*/
|
2002-05-23 15:09:49 +00:00
|
|
|
if (kd != NULL)
|
1997-10-09 07:22:08 +00:00
|
|
|
errx(1, "files on dead kernel, not implemented");
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_FILE;
|
|
|
|
if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1) {
|
|
|
|
warn("sysctl: KERN_FILE");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if ((buf = malloc(len)) == NULL)
|
1997-10-09 07:22:08 +00:00
|
|
|
errx(1, "malloc");
|
1994-05-26 05:23:31 +00:00
|
|
|
if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) {
|
|
|
|
warn("sysctl: KERN_FILE");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*abuf = buf;
|
|
|
|
*alen = len;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* swapmode is based on a program called swapinfo written
|
|
|
|
* by Kevin Lahey <kml@rokkaku.atl.ga.us>.
|
|
|
|
*/
|
2002-05-23 15:09:49 +00:00
|
|
|
|
2005-03-21 16:36:05 +00:00
|
|
|
#define CONVERT(v) ((int64_t)(v) * pagesize / blocksize)
|
2009-08-15 14:39:33 +00:00
|
|
|
#define CONVERT_BLOCKS(v) ((int64_t)(v) * pagesize)
|
2002-05-23 15:09:49 +00:00
|
|
|
static struct kvm_swap swtot;
|
|
|
|
static int nswdev;
|
|
|
|
|
2002-05-23 14:44:23 +00:00
|
|
|
static void
|
2002-05-23 15:09:49 +00:00
|
|
|
print_swap_header(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2002-12-30 18:19:19 +00:00
|
|
|
int hlen;
|
1999-01-22 10:36:48 +00:00
|
|
|
long blocksize;
|
2002-05-23 15:09:49 +00:00
|
|
|
const char *header;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
header = getbsize(&hlen, &blocksize);
|
2002-05-23 15:09:49 +00:00
|
|
|
if (totalflag == 0)
|
2003-07-31 20:46:33 +00:00
|
|
|
(void)printf("%-15s %*s %8s %8s %8s\n",
|
2002-12-30 18:19:19 +00:00
|
|
|
"Device", hlen, header,
|
2003-07-31 20:46:33 +00:00
|
|
|
"Used", "Avail", "Capacity");
|
2002-05-23 15:09:49 +00:00
|
|
|
}
|
1999-01-21 08:08:55 +00:00
|
|
|
|
2002-05-23 15:09:49 +00:00
|
|
|
static void
|
2009-06-11 09:02:22 +00:00
|
|
|
print_swap_line(const char *swdevname, intmax_t nblks, intmax_t bused,
|
2005-03-21 16:36:05 +00:00
|
|
|
intmax_t bavail, float bpercent)
|
2002-05-23 15:09:49 +00:00
|
|
|
{
|
2005-03-21 16:36:05 +00:00
|
|
|
char usedbuf[5];
|
|
|
|
char availbuf[5];
|
2002-12-30 18:19:19 +00:00
|
|
|
int hlen, pagesize;
|
2002-05-23 15:09:49 +00:00
|
|
|
long blocksize;
|
|
|
|
|
|
|
|
pagesize = getpagesize();
|
|
|
|
getbsize(&hlen, &blocksize);
|
2005-03-21 16:36:05 +00:00
|
|
|
|
2009-06-11 09:02:22 +00:00
|
|
|
printf("%-15s %*jd ", swdevname, hlen, CONVERT(nblks));
|
2005-03-21 16:36:05 +00:00
|
|
|
if (humanflag) {
|
|
|
|
humanize_number(usedbuf, sizeof(usedbuf),
|
2009-08-15 14:39:33 +00:00
|
|
|
CONVERT_BLOCKS(bused), "",
|
2005-03-21 16:36:05 +00:00
|
|
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
|
|
|
humanize_number(availbuf, sizeof(availbuf),
|
2009-08-15 14:39:33 +00:00
|
|
|
CONVERT_BLOCKS(bavail), "",
|
2005-03-21 16:36:05 +00:00
|
|
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
|
|
|
printf("%8s %8s %5.0f%%\n", usedbuf, availbuf, bpercent);
|
|
|
|
} else {
|
|
|
|
printf("%8jd %8jd %5.0f%%\n", (intmax_t)CONVERT(bused),
|
|
|
|
(intmax_t)CONVERT(bavail), bpercent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_swap(struct kvm_swap *ksw)
|
|
|
|
{
|
|
|
|
|
2002-05-23 15:09:49 +00:00
|
|
|
swtot.ksw_total += ksw->ksw_total;
|
|
|
|
swtot.ksw_used += ksw->ksw_used;
|
|
|
|
++nswdev;
|
2005-03-21 16:36:05 +00:00
|
|
|
if (totalflag == 0)
|
|
|
|
print_swap_line(ksw->ksw_devname, ksw->ksw_total,
|
2005-11-17 19:31:52 +00:00
|
|
|
ksw->ksw_used, ksw->ksw_total - ksw->ksw_used,
|
2003-07-31 20:46:33 +00:00
|
|
|
(ksw->ksw_used * 100.0) / ksw->ksw_total);
|
2002-05-23 15:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_swap_total(void)
|
|
|
|
{
|
2002-12-30 18:19:19 +00:00
|
|
|
int hlen, pagesize;
|
2002-05-23 15:09:49 +00:00
|
|
|
long blocksize;
|
1999-01-21 08:08:55 +00:00
|
|
|
|
2002-05-23 15:09:49 +00:00
|
|
|
pagesize = getpagesize();
|
|
|
|
getbsize(&hlen, &blocksize);
|
1994-05-26 05:23:31 +00:00
|
|
|
if (totalflag) {
|
1999-01-22 10:36:48 +00:00
|
|
|
blocksize = 1024 * 1024;
|
2005-03-21 16:36:05 +00:00
|
|
|
(void)printf("%jdM/%jdM swap space\n",
|
2002-05-23 15:09:49 +00:00
|
|
|
CONVERT(swtot.ksw_used), CONVERT(swtot.ksw_total));
|
|
|
|
} else if (nswdev > 1) {
|
2005-03-21 16:36:05 +00:00
|
|
|
print_swap_line("Total", swtot.ksw_total, swtot.ksw_used,
|
|
|
|
swtot.ksw_total - swtot.ksw_used,
|
2002-05-23 15:09:49 +00:00
|
|
|
(swtot.ksw_used * 100.0) / swtot.ksw_total);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapmode_kvm(void)
|
|
|
|
{
|
|
|
|
struct kvm_swap kswap[16];
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
n = kvm_getswapinfo(kd, kswap, sizeof kswap / sizeof kswap[0],
|
2003-07-31 21:20:08 +00:00
|
|
|
SWIF_DEV_PREFIX);
|
1999-01-22 10:36:48 +00:00
|
|
|
|
2002-05-23 15:09:49 +00:00
|
|
|
print_swap_header();
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
print_swap(&kswap[i]);
|
|
|
|
print_swap_total();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapmode_sysctl(void)
|
|
|
|
{
|
|
|
|
struct kvm_swap ksw;
|
|
|
|
struct xswdev xsw;
|
|
|
|
size_t mibsize, size;
|
|
|
|
int mib[16], n;
|
|
|
|
|
|
|
|
print_swap_header();
|
|
|
|
mibsize = sizeof mib / sizeof mib[0];
|
|
|
|
if (sysctlnametomib("vm.swap_info", mib, &mibsize) == -1)
|
|
|
|
err(1, "sysctlnametomib()");
|
|
|
|
for (n = 0; ; ++n) {
|
|
|
|
mib[mibsize] = n;
|
|
|
|
size = sizeof xsw;
|
2004-03-05 08:10:19 +00:00
|
|
|
if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, 0) == -1)
|
2002-05-23 15:09:49 +00:00
|
|
|
break;
|
|
|
|
if (xsw.xsw_version != XSWDEV_VERSION)
|
|
|
|
errx(1, "xswdev version mismatch");
|
2003-06-05 21:56:47 +00:00
|
|
|
if (xsw.xsw_dev == NODEV)
|
|
|
|
snprintf(ksw.ksw_devname, sizeof ksw.ksw_devname,
|
|
|
|
"<NFSfile>");
|
|
|
|
else
|
|
|
|
snprintf(ksw.ksw_devname, sizeof ksw.ksw_devname,
|
|
|
|
"/dev/%s", devname(xsw.xsw_dev, S_IFCHR));
|
2002-05-23 15:09:49 +00:00
|
|
|
ksw.ksw_used = xsw.xsw_used;
|
|
|
|
ksw.ksw_total = xsw.xsw_nblks;
|
|
|
|
ksw.ksw_flags = xsw.xsw_flags;
|
|
|
|
print_swap(&ksw);
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2002-05-23 15:09:49 +00:00
|
|
|
if (errno != ENOENT)
|
|
|
|
err(1, "sysctl()");
|
|
|
|
print_swap_total();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swapmode(void)
|
|
|
|
{
|
|
|
|
if (kd != NULL)
|
|
|
|
swapmode_kvm();
|
|
|
|
else
|
|
|
|
swapmode_sysctl();
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|