summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/main.c8
-rw-r--r--usr.bin/netstat/mbuf.c196
-rw-r--r--usr.bin/netstat/netstat.14
-rw-r--r--usr.bin/netstat/netstat.h1
-rw-r--r--usr.bin/systat/mbufs.c53
5 files changed, 21 insertions, 241 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index ac9dd26..8992599 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -256,7 +256,6 @@ static char *nlistf = NULL, *memf = NULL;
int Aflag; /* show addresses of protocol control block */
int aflag; /* show all sockets (including servers) */
int bflag; /* show i/f total bytes in/out */
-int cflag; /* show mbuf cache information */
int dflag; /* show i/f dropped packets */
int gflag; /* show group (multicast) routing or stats */
int iflag; /* show interfaces */
@@ -297,9 +296,6 @@ main(int argc, char *argv[])
case 'b':
bflag = 1;
break;
- case 'c':
- cflag = 1;
- break;
case 'd':
dflag = 1;
break;
@@ -425,10 +421,6 @@ main(int argc, char *argv[])
if (nlistf != NULL || memf != NULL)
setgid(getgid());
- if (cflag && !mflag) {
- (void)fprintf(stderr, "-c only valid with -m\n");
- usage();
- }
if (mflag) {
if (memf != NULL) {
if (kread(0, 0, 0) == 0)
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c
index aa6a8d2..98546c4 100644
--- a/usr.bin/netstat/mbuf.c
+++ b/usr.bin/netstat/mbuf.c
@@ -99,17 +99,12 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
u_long mbhiaddr, u_long clhiaddr, u_long mbloaddr, u_long clloaddr,
u_long cpusaddr __unused, u_long pgsaddr, u_long mbpaddr)
{
- int i, j, nmbufs, nmbclusters, page_size, num_objs;
+ int i, nmbclusters;
int nsfbufs, nsfbufspeak, nsfbufsused;
- u_int mbuf_hiwm, clust_hiwm, mbuf_lowm, clust_lowm;
- u_long totspace[2], totused[2];
- u_long gentotnum, gentotfree, totnum, totfree;
- u_long totmem, totmemalloced, totmemused;
short nmbtypes;
size_t mlen;
long *mbtypes = NULL;
struct mbstat *mbstat = NULL;
- struct mbpstat **mbpstat = NULL;
struct mbtypenames *mp;
bool *seen = NULL;
@@ -119,50 +114,12 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
goto err;
}
- /*
- * XXX: Unfortunately, for the time being, we have to fetch
- * the total length of the per-CPU stats area via sysctl
- * (regardless of whether we're looking at a core or not.
- */
- if (sysctlbyname("kern.ipc.mb_statpcpu", NULL, &mlen, NULL, 0) < 0) {
- warn("sysctl: retrieving mb_statpcpu len");
- goto err;
- }
- num_objs = (int)(mlen / sizeof(struct mbpstat));
- if ((mbpstat = calloc(num_objs, sizeof(struct mbpstat *))) == NULL) {
- warn("calloc: cannot allocate memory for mbpstats pointers");
- goto err;
- }
- if ((mbpstat[0] = calloc(num_objs, sizeof(struct mbpstat))) == NULL) {
- warn("calloc: cannot allocate memory for mbpstats");
- goto err;
- }
-
if (mbaddr) {
- if (kread(mbpaddr, (char *)mbpstat[0], mlen))
- goto err;
if (kread(mbaddr, (char *)mbstat, sizeof mbstat))
goto err;
if (kread(nmbcaddr, (char *)&nmbclusters, sizeof(int)))
goto err;
- if (kread(nmbufaddr, (char *)&nmbufs, sizeof(int)))
- goto err;
- if (kread(mbhiaddr, (char *)&mbuf_hiwm, sizeof(u_int)))
- goto err;
- if (kread(clhiaddr, (char *)&clust_hiwm, sizeof(u_int)))
- goto err;
- if (kread(mbloaddr, (char *)&mbuf_lowm, sizeof(u_int)))
- goto err;
- if (kread(clloaddr, (char *)&clust_lowm, sizeof(u_int)))
- goto err;
- if (kread(pgsaddr, (char *)&page_size, sizeof(int)))
- goto err;
} else {
- if (sysctlbyname("kern.ipc.mb_statpcpu", mbpstat[0], &mlen,
- NULL, 0) < 0) {
- warn("sysctl: retrieving mb_statpcpu");
- goto err;
- }
mlen = sizeof *mbstat;
if (sysctlbyname("kern.ipc.mbstat", mbstat, &mlen, NULL, 0)
< 0) {
@@ -175,43 +132,9 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
warn("sysctl: retrieving nmbclusters");
goto err;
}
- mlen = sizeof(int);
- if (sysctlbyname("kern.ipc.nmbufs", &nmbufs, &mlen, NULL, 0)
- < 0) {
- warn("sysctl: retrieving nmbufs");
- goto err;
- }
- mlen = sizeof(u_int);
- if (sysctlbyname("kern.ipc.mbuf_hiwm", &mbuf_hiwm, &mlen,
- NULL, 0) < 0) {
- warn("sysctl: retrieving mbuf_hiwm");
- goto err;
- }
- mlen = sizeof(u_int);
- if (sysctlbyname("kern.ipc.clust_hiwm", &clust_hiwm, &mlen,
- NULL, 0) < 0) {
- warn("sysctl: retrieving clust_hiwm");
- goto err;
- }
- mlen = sizeof(u_int);
- if (sysctlbyname("kern.ipc.mbuf_lowm", &mbuf_lowm, &mlen,
- NULL, 0) < 0) {
- warn("sysctl: retrieving mbuf_lowm");
- goto err;
- }
- mlen = sizeof(u_int);
- if (sysctlbyname("kern.ipc.clust_lowm", &clust_lowm, &mlen,
- NULL, 0) < 0) {
- warn("sysctl: retrieving clust_lowm");
- goto err;
- }
- mlen = sizeof(int);
- if (sysctlbyname("hw.pagesize", &page_size, &mlen, NULL, 0)
- < 0) {
- warn("sysctl: retrieving hw.pagesize");
- goto err;
- }
}
+ if (mbstat->m_mbufs < 0) mbstat->m_mbufs = 0; /* XXX */
+ if (mbstat->m_mclusts < 0) mbstat->m_mclusts = 0; /* XXX */
nmbtypes = mbstat->m_numtypes;
if ((seen = calloc(nmbtypes, sizeof(*seen))) == NULL) {
@@ -223,59 +146,13 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
goto err;
}
- for (i = 0; i < num_objs; i++)
- mbpstat[i] = mbpstat[0] + i;
-
#undef MSIZE
#define MSIZE (mbstat->m_msize)
#undef MCLBYTES
#define MCLBYTES (mbstat->m_mclbytes)
-#define GENLST (num_objs - 1)
- totnum = mbpstat[GENLST]->mb_mbbucks * mbstat->m_mbperbuck;
- totfree = mbpstat[GENLST]->mb_mbfree;
- for (j = 1; j < nmbtypes; j++)
- mbtypes[j] += mbpstat[GENLST]->mb_mbtypes[j];
- totspace[0] = mbpstat[GENLST]->mb_mbbucks * mbstat->m_mbperbuck * MSIZE;
- for (i = 0; i < (num_objs - 1); i++) {
- if (mbpstat[i]->mb_active == 0)
- continue;
- totspace[0] += mbpstat[i]->mb_mbbucks*mbstat->m_mbperbuck*MSIZE;
- totnum += mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck;
- totfree += mbpstat[i]->mb_mbfree;
- for (j = 1; j < nmbtypes; j++)
- mbtypes[j] += mbpstat[i]->mb_mbtypes[j];
- }
- totused[0] = totnum - totfree;
- if (cflag) {
- printf("mbuf usage:\n"
- "\tTotal:\t\t%lu/%lu/%d (in use/in pool/max)\n",
- totused[0], totnum, nmbufs);
- gentotnum = mbpstat[GENLST]->mb_mbbucks * mbstat->m_mbperbuck;
- gentotfree = mbpstat[GENLST]->mb_mbfree;
- printf("\tGEN cache:\t%lu/%lu (in use/in pool)\n",
- gentotnum - gentotfree, gentotnum);
- } else {
- /* XXX: peak is now wrong. */
- printf("%lu/%lu/%d mbufs in use (current/peak/max):\n",
- totused[0], totnum, nmbufs);
- }
+ printf("%lu mbufs in use\n", mbstat->m_mbufs);
- for (i = 0; cflag && i < (num_objs - 1); i++) {
- if (mbpstat[i]->mb_active == 0)
- continue;
- printf("\tCPU #%d cache:\t%lu/%lu (in use/in pool)\n",
- i,
- (mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck -
- mbpstat[i]->mb_mbfree),
- (mbpstat[i]->mb_mbbucks * mbstat->m_mbperbuck));
- }
- if (cflag) {
- printf("\tMbuf cache high watermark: %d\n", mbuf_hiwm);
-#ifdef NOTYET
- printf("\tMbuf cache low watermark: %d\n", mbuf_lowm);
-#endif
- }
for (mp = mbtypenames; mp->mt_name; mp++) {
if (mbtypes[mp->mt_type]) {
seen[mp->mt_type] = YES;
@@ -288,53 +165,10 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
printf("\t %lu mbufs allocated to <mbuf type: %d>\n",
mbtypes[i], i);
}
- if (cflag)
- printf("\t%.1f%% of mbuf map consumed\n",
- totspace[0] * 100.0 / (nmbufs * MSIZE));
- totnum = mbpstat[GENLST]->mb_clbucks * mbstat->m_clperbuck;
- totfree = mbpstat[GENLST]->mb_clfree;
- totspace[1] = mbpstat[GENLST]->mb_clbucks*mbstat->m_clperbuck*MCLBYTES;
- for (i = 0; i < (num_objs - 1); i++) {
- if (mbpstat[i]->mb_active == 0)
- continue;
- totspace[1] += mbpstat[i]->mb_clbucks * mbstat->m_clperbuck
- * MCLBYTES;
- totnum += mbpstat[i]->mb_clbucks * mbstat->m_clperbuck;
- totfree += mbpstat[i]->mb_clfree;
- }
- totused[1] = totnum - totfree;
- if (cflag) {
- printf("mbuf cluster usage:\n"
- "\tTotal:\t\t%lu/%lu/%d (in use/in pool/max)\n",
- totused[1], totnum, nmbclusters);
- gentotnum = mbpstat[GENLST]->mb_clbucks * mbstat->m_clperbuck;
- gentotfree = mbpstat[GENLST]->mb_clfree;
- printf("\tGEN cache:\t%lu/%lu (in use/in pool)\n",
- gentotnum - gentotfree, gentotnum);
- } else {
- /* XXX: peak is now wrong. */
- printf("%lu/%lu/%d mbuf clusters in use (current/peak/max)\n",
- totused[1], totnum, nmbclusters);
- }
- for (i = 0; cflag && i < (num_objs - 1); i++) {
- if (mbpstat[i]->mb_active == 0)
- continue;
- printf("\tCPU #%d cache:\t%lu/%lu (in use/in pool)\n",
- i,
- (mbpstat[i]->mb_clbucks * mbstat->m_clperbuck -
- mbpstat[i]->mb_clfree),
- (mbpstat[i]->mb_clbucks * mbstat->m_clperbuck));
- }
- if (cflag) {
- printf("\tCluster cache high watermark: %d\n", clust_hiwm);
-#ifdef NOTYET
- printf("\tCluster cache low watermark: %d\n", clust_lowm);
-#endif
- }
- if (cflag)
- printf("\t%.1f%% of cluster map consumed\n",
- totspace[1] * 100.0 / (nmbclusters * MCLBYTES));
+ printf("%lu/%d mbuf clusters in use (current/max)\n",
+ mbstat->m_mclusts, nmbclusters);
+
mlen = sizeof(nsfbufs);
if (!sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, 0) &&
!sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, &mlen, NULL,
@@ -344,15 +178,8 @@ mbpr(u_long mbaddr, u_long mbtaddr __unused, u_long nmbcaddr, u_long nmbufaddr,
printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
nsfbufsused, nsfbufspeak, nsfbufs);
}
- totmem = nmbufs * MSIZE + nmbclusters * MCLBYTES;
- totmemalloced = totspace[0] + totspace[1];
- totmemused = totused[0] * MSIZE + totused[1] * MCLBYTES;
- printf(
- "%lu KBytes allocated to network (%.1f%% in use, %.1f%% wired)\n",
- totmem / 1024, totmemused * 100.0 / totmem,
- totmemalloced * 100.0 / totmem);
- printf("%lu requests for memory denied\n", mbstat->m_drops);
- printf("%lu requests for memory delayed\n", mbstat->m_wait);
+ printf("%lu KBytes allocated to network\n", (mbstat->m_mbufs * MSIZE +
+ mbstat->m_mclusts * MCLBYTES) / 1024);
printf("%lu requests for sfbufs denied\n", mbstat->sf_allocfail);
printf("%lu requests for sfbufs delayed\n", mbstat->sf_allocwait);
printf("%lu requests for I/O initiated by sendfile\n",
@@ -366,9 +193,4 @@ err:
free(seen);
if (mbstat != NULL)
free(mbstat);
- if (mbpstat != NULL) {
- if (mbpstat[0] != NULL)
- free(mbpstat[0]);
- free(mbpstat);
- }
}
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 45023fe..32edfec 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -181,7 +181,6 @@ or for a single
.Bk -words
.Nm
.Fl m
-.Op Fl c
.Op Fl M Ar core
.Op Fl N Ar system
.Ek
@@ -189,9 +188,6 @@ or for a single
Show statistics recorded by the memory management routines
.Pq Xr mbuf 9 .
The network manages a private pool of memory buffers.
-The
-.Fl c
-option shows per-CPU statistics for caching.
.It Xo
.Bk -words
.Nm
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index c59b7e8..e2b3f29 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -39,7 +39,6 @@
extern int Aflag; /* show addresses of protocol control block */
extern int aflag; /* show all sockets (including servers) */
extern int bflag; /* show i/f total bytes in/out */
-extern int cflag; /* show mbuf cache information */
extern int dflag; /* show i/f dropped packets */
extern int gflag; /* show group (multicast) routing or stats */
extern int iflag; /* show interfaces */
diff --git a/usr.bin/systat/mbufs.c b/usr.bin/systat/mbufs.c
index e1b665b2..1193a3e 100644
--- a/usr.bin/systat/mbufs.c
+++ b/usr.bin/systat/mbufs.c
@@ -52,12 +52,9 @@ static const char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93";
#include "systat.h"
#include "extern.h"
-static struct mbpstat **mbpstat;
static struct mbstat *mbstat;
-static int num_objs;
static long *m_mbtypes;
static short nmbtypes;
-#define GENLST (num_objs - 1)
static struct mtnames {
short mt_type;
@@ -101,20 +98,11 @@ void
showmbufs()
{
int i, j, max, idx;
- u_long totfree;
+ u_long totmbufs;
char buf[10];
const char *mtname;
- totfree = mbpstat[GENLST]->mb_mbfree;
- for (i = 1; i < nmbtypes; i++)
- m_mbtypes[i] += mbpstat[GENLST]->mb_mbtypes[i];
- for (i = 0; i < GENLST; i++) {
- if (mbpstat[i]->mb_active == 0)
- continue;
- totfree += mbpstat[i]->mb_mbfree;
- for (j = 1; j < nmbtypes; j++)
- m_mbtypes[j] += mbpstat[i]->mb_mbtypes[j];
- }
+ totmbufs = mbstat->m_mbufs;
/*
* Print totals for different mbuf types.
@@ -159,16 +147,16 @@ showmbufs()
/*
* Print total number of free mbufs.
*/
- if (totfree > 0) {
- mvwprintw(wnd, 1+j, 0, "%-10.10s", "free");
- if (totfree > 60) {
- snprintf(buf, sizeof(buf), " %lu", totfree);
- totfree = 60;
- while(totfree--)
+ if (totmbufs > 0) {
+ mvwprintw(wnd, 1+j, 0, "%-10.10s", "Mbufs");
+ if (totmbufs > 60) {
+ snprintf(buf, sizeof(buf), " %lu", totmbufs);
+ totmbufs = 60;
+ while(totmbufs--)
waddch(wnd, 'X');
waddstr(wnd, buf);
} else {
- while(totfree--)
+ while(totmbufs--)
waddch(wnd, 'X');
}
wclrtoeol(wnd);
@@ -198,23 +186,6 @@ initmbufs()
return 0;
}
- if (sysctlbyname("kern.ipc.mb_statpcpu", NULL, &len, NULL, 0) < 0) {
- error("sysctl getting mbpstat total size failed");
- return 0;
- }
- num_objs = (int)(len / sizeof(struct mbpstat));
- if ((mbpstat = calloc(num_objs, sizeof(struct mbpstat *))) == NULL) {
- error("calloc mbpstat pointers failed");
- return 0;
- }
- if ((mbpstat[0] = calloc(num_objs, sizeof(struct mbpstat))) == NULL) {
- error("calloc mbpstat structures failed");
- return 0;
- }
-
- for (i = 0; i < num_objs; i++)
- mbpstat[i] = mbpstat[0] + i;
-
return 1;
}
@@ -223,7 +194,7 @@ fetchmbufs()
{
size_t len;
- len = num_objs * sizeof(struct mbpstat);
- if (sysctlbyname("kern.ipc.mb_statpcpu", mbpstat[0], &len, NULL, 0) < 0)
- printw("sysctl: mbpstat: %s", strerror(errno));
+ len = sizeof *mbstat;
+ if (sysctlbyname("kern.ipc.mbstat", mbstat, &len, NULL, 0) < 0)
+ printw("sysctl: mbstat: %s", strerror(errno));
}
OpenPOWER on IntegriCloud