diff options
author | bmilekic <bmilekic@FreeBSD.org> | 2001-09-30 01:58:39 +0000 |
---|---|---|
committer | bmilekic <bmilekic@FreeBSD.org> | 2001-09-30 01:58:39 +0000 |
commit | 5b4fe25981cd9b92f1fba2da8c4ce7be3a7a37e1 (patch) | |
tree | f7d4110dfccc8085ec2e36a342d82da2c9a55ffe /usr.bin/systat | |
parent | c605847554205a074c69591402a21d9edb6d06a7 (diff) | |
download | FreeBSD-src-5b4fe25981cd9b92f1fba2da8c4ce7be3a7a37e1.zip FreeBSD-src-5b4fe25981cd9b92f1fba2da8c4ce7be3a7a37e1.tar.gz |
Re-enable mbtypes statistics in the mbuf allocator. I disabled these
when I changed the allocator bits. This implements per-CPU mbtypes
stats by keeping net number of decrements/increments of a given mbtype
per-CPU and then summing all of the per-CPU mbtypes to produce the total
net number of allocated mbufs of the given mbtype.
Counters are carefully balanced to avoid/prevent underflows/overflows.
mbtypes stats are re-enabled with the idea that we may occasionally
(although very rarely) observe slight inconsistencies in the stat
reporting. Most of the time, we should be fine, though.
Also make appropriate modifications to netstat(1) and systat(1) to do
the necessary reporting.
Submitted by: Jiangyi Liu <jyliu@163.net>
Diffstat (limited to 'usr.bin/systat')
-rw-r--r-- | usr.bin/systat/mbufs.c | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/usr.bin/systat/mbufs.c b/usr.bin/systat/mbufs.c index 1983e0a..5dee078 100644 --- a/usr.bin/systat/mbufs.c +++ b/usr.bin/systat/mbufs.c @@ -50,16 +50,14 @@ static const char rcsid[] = #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) -/* XXX: mbtypes stats temporarily disabled. */ -#if 0 -static u_long *m_mbtypes; -static int nmbtypes; - static struct mtnames { - int mt_type; + short mt_type; char *mt_name; } mtnames[] = { { MT_DATA, "data"}, @@ -69,9 +67,7 @@ static struct mtnames { { MT_CONTROL, "control"}, { MT_OOBDATA, "oobdata"} }; - #define NNAMES (sizeof (mtnames) / sizeof (mtnames[0])) -#endif WINDOW * openmbufs() @@ -106,12 +102,24 @@ showmbufs() char buf[10]; char *mtname; -/* XXX: mbtypes stats temporarily disabled (will be back soon!) */ -#if 0 + 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]; + } + + /* + * Print totals for different mbuf types. + */ for (j = 0; j < wnd->_maxy; j++) { max = 0, index = -1; for (i = 0; i < wnd->_maxy; i++) { - if (i == MT_FREE) + if (i == MT_NOTMBUF) continue; if (i >= nmbtypes) break; @@ -144,18 +152,10 @@ showmbufs() wclrtoeol(wnd); m_mbtypes[index] = 0; } -#endif /* * Print total number of free mbufs. */ - totfree = mbpstat[GENLST]->mb_mbfree; - for (i = 0; i < (num_objs - 1); i++) { - if (mbpstat[i]->mb_active == 0) - continue; - totfree += mbpstat[i]->mb_mbfree; - } - j = 0; /* XXX */ if (totfree > 0) { mvwprintw(wnd, 1+j, 0, "%-10.10s", "free"); if (totfree > 60) { @@ -179,19 +179,22 @@ initmbufs() { int i; size_t len; -#if 0 - size_t mbtypeslen; - if (sysctlbyname("kern.ipc.mbtypes", NULL, &mbtypeslen, NULL, 0) < 0) { - error("sysctl getting mbtypes size failed"); + len = sizeof *mbstat; + if ((mbstat = malloc(len)) == NULL) { + error("malloc mbstat failed"); return 0; } - if ((m_mbtypes = calloc(1, mbtypeslen)) == NULL) { - error("calloc mbtypes failed"); + if (sysctlbyname("kern.ipc.mbstat", mbstat, &len, NULL, 0) < 0) { + error("sysctl retrieving mbstat"); return 0; } - nmbtypes = mbtypeslen / sizeof(*m_mbtypes); -#endif + nmbtypes = mbstat->m_numtypes; + if ((m_mbtypes = calloc(nmbtypes, sizeof(long *))) == NULL) { + error("calloc m_mbtypes failed"); + return 0; + } + if (sysctlbyname("kern.ipc.mb_statpcpu", NULL, &len, NULL, 0) < 0) { error("sysctl getting mbpstat total size failed"); return 0; @@ -205,6 +208,7 @@ initmbufs() error("calloc mbpstat structures failed"); return 0; } + for (i = 0; i < num_objs; i++) mbpstat[i] = mbpstat[0] + i; @@ -219,9 +223,4 @@ fetchmbufs() len = num_objs * sizeof(struct mbpstat); if (sysctlbyname("kern.ipc.mb_statpcpu", mbpstat[0], &len, NULL, 0) < 0) printw("sysctl: mbpstat: %s", strerror(errno)); -#if 0 - len = nmbtypes * sizeof *m_mbtypes; - if (sysctlbyname("kern.ipc.mbtypes", m_mbtypes, &len, 0, 0) < 0) - printw("sysctl: mbtypes: %s", strerror(errno)); -#endif } |