Tue Jun 3 21:16:15 2014 UTC ()
Provide sysctl for namecache statistics.


(joerg)
diff -r1.96 -r1.97 src/sys/kern/vfs_cache.c
diff -r1.32 -r1.33 src/sys/sys/namei.src
diff -r1.77 -r1.78 src/usr.bin/systat/vmstat.c
diff -r1.193 -r1.194 src/usr.bin/vmstat/vmstat.c

cvs diff -r1.96 -r1.97 src/sys/kern/vfs_cache.c (expand / switch to unified diff)

--- src/sys/kern/vfs_cache.c 2014/06/03 19:42:17 1.96
+++ src/sys/kern/vfs_cache.c 2014/06/03 21:16:15 1.97
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_cache.c,v 1.96 2014/06/03 19:42:17 joerg Exp $ */ 1/* $NetBSD: vfs_cache.c,v 1.97 2014/06/03 21:16:15 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -48,33 +48,34 @@ @@ -48,33 +48,34 @@
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE. 55 * SUCH DAMAGE.
56 * 56 *
57 * @(#)vfs_cache.c 8.3 (Berkeley) 8/22/94 57 * @(#)vfs_cache.c 8.3 (Berkeley) 8/22/94
58 */ 58 */
59 59
60#include <sys/cdefs.h> 60#include <sys/cdefs.h>
61__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.96 2014/06/03 19:42:17 joerg Exp $"); 61__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.97 2014/06/03 21:16:15 joerg Exp $");
62 62
63#include "opt_ddb.h" 63#include "opt_ddb.h"
64#include "opt_revcache.h" 64#include "opt_revcache.h"
65 65
66#include <sys/param.h> 66#include <sys/param.h>
67#include <sys/systm.h> 67#include <sys/systm.h>
 68#include <sys/sysctl.h>
68#include <sys/time.h> 69#include <sys/time.h>
69#include <sys/mount.h> 70#include <sys/mount.h>
70#include <sys/vnode.h> 71#include <sys/vnode.h>
71#include <sys/namei.h> 72#include <sys/namei.h>
72#include <sys/errno.h> 73#include <sys/errno.h>
73#include <sys/pool.h> 74#include <sys/pool.h>
74#include <sys/mutex.h> 75#include <sys/mutex.h>
75#include <sys/atomic.h> 76#include <sys/atomic.h>
76#include <sys/kthread.h> 77#include <sys/kthread.h>
77#include <sys/kernel.h> 78#include <sys/kernel.h>
78#include <sys/cpu.h> 79#include <sys/cpu.h>
79#include <sys/evcnt.h> 80#include <sys/evcnt.h>
80 81
@@ -1088,13 +1089,59 @@ namecache_count_pass2(void) @@ -1088,13 +1089,59 @@ namecache_count_pass2(void)
1088 COUNT(cpup->cpu_stats, ncs_pass2); 1089 COUNT(cpup->cpu_stats, ncs_pass2);
1089 mutex_exit(&cpup->cpu_lock); 1090 mutex_exit(&cpup->cpu_lock);
1090} 1091}
1091 1092
1092void 1093void
1093namecache_count_2passes(void) 1094namecache_count_2passes(void)
1094{ 1095{
1095 struct nchcpu *cpup = curcpu()->ci_data.cpu_nch; 1096 struct nchcpu *cpup = curcpu()->ci_data.cpu_nch;
1096 1097
1097 mutex_enter(&cpup->cpu_lock); 1098 mutex_enter(&cpup->cpu_lock);
1098 COUNT(cpup->cpu_stats, ncs_2passes); 1099 COUNT(cpup->cpu_stats, ncs_2passes);
1099 mutex_exit(&cpup->cpu_lock); 1100 mutex_exit(&cpup->cpu_lock);
1100} 1101}
 1102
 1103static int
 1104cache_stat_sysctl(SYSCTLFN_ARGS)
 1105{
 1106 struct nchstats_sysctl stats;
 1107
 1108 if (oldp == NULL) {
 1109 *oldlenp = sizeof(stats);
 1110 return 0;
 1111 }
 1112
 1113 if (*oldlenp < sizeof(stats)) {
 1114 *oldlenp = 0;
 1115 return 0;
 1116 }
 1117
 1118 memset(&stats, 0, sizeof(stats));
 1119
 1120 sysctl_unlock();
 1121 cache_lock_cpus();
 1122 stats.ncs_goodhits = nchstats.ncs_goodhits;
 1123 stats.ncs_neghits = nchstats.ncs_neghits;
 1124 stats.ncs_badhits = nchstats.ncs_badhits;
 1125 stats.ncs_falsehits = nchstats.ncs_falsehits;
 1126 stats.ncs_miss = nchstats.ncs_miss;
 1127 stats.ncs_long = nchstats.ncs_long;
 1128 stats.ncs_pass2 = nchstats.ncs_pass2;
 1129 stats.ncs_2passes = nchstats.ncs_2passes;
 1130 stats.ncs_revhits = nchstats.ncs_revhits;
 1131 stats.ncs_revmiss = nchstats.ncs_revmiss;
 1132 cache_unlock_cpus();
 1133 sysctl_relock();
 1134
 1135 *oldlenp = sizeof(stats);
 1136 return sysctl_copyout(l, &stats, oldp, sizeof(stats));
 1137}
 1138
 1139SYSCTL_SETUP(sysctl_cache_stat_setup, "vfs.namecache_stats subtree setup")
 1140{
 1141 sysctl_createv(clog, 0, NULL, NULL,
 1142 CTLFLAG_PERMANENT,
 1143 CTLTYPE_STRUCT, "namecache_stats",
 1144 SYSCTL_DESCR("namecache statistics"),
 1145 cache_stat_sysctl, 0, NULL, 0,
 1146 CTL_VFS, CTL_CREATE, CTL_EOL);
 1147}

cvs diff -r1.32 -r1.33 src/sys/sys/namei.src (expand / switch to unified diff)

--- src/sys/sys/namei.src 2014/06/03 19:30:29 1.32
+++ src/sys/sys/namei.src 2014/06/03 21:16:15 1.33
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: namei.src,v 1.32 2014/06/03 19:30:29 joerg Exp $ */ 1/* $NetBSD: namei.src,v 1.33 2014/06/03 21:16:15 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1985, 1989, 1991, 1993 4 * Copyright (c) 1985, 1989, 1991, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -294,17 +294,30 @@ void namecache_print(struct vnode *, voi @@ -294,17 +294,30 @@ void namecache_print(struct vnode *, voi
294struct nchstats { 294struct nchstats {
295 long ncs_goodhits; /* hits that we can really use */ 295 long ncs_goodhits; /* hits that we can really use */
296 long ncs_neghits; /* negative hits that we can use */ 296 long ncs_neghits; /* negative hits that we can use */
297 long ncs_badhits; /* hits we must drop */ 297 long ncs_badhits; /* hits we must drop */
298 long ncs_falsehits; /* hits with id mismatch */ 298 long ncs_falsehits; /* hits with id mismatch */
299 long ncs_miss; /* misses */ 299 long ncs_miss; /* misses */
300 long ncs_long; /* long names that ignore cache */ 300 long ncs_long; /* long names that ignore cache */
301 long ncs_pass2; /* names found with passes == 2 */ 301 long ncs_pass2; /* names found with passes == 2 */
302 long ncs_2passes; /* number of times we attempt it */ 302 long ncs_2passes; /* number of times we attempt it */
303 long ncs_revhits; /* reverse-cache hits */ 303 long ncs_revhits; /* reverse-cache hits */
304 long ncs_revmiss; /* reverse-cache misses */ 304 long ncs_revmiss; /* reverse-cache misses */
305}; 305};
306 306
 307struct nchstats_sysctl {
 308 uint64_t ncs_goodhits; /* hits that we can really use */
 309 uint64_t ncs_neghits; /* negative hits that we can use */
 310 uint64_t ncs_badhits; /* hits we must drop */
 311 uint64_t ncs_falsehits; /* hits with id mismatch */
 312 uint64_t ncs_miss; /* misses */
 313 uint64_t ncs_long; /* long names that ignore cache */
 314 uint64_t ncs_pass2; /* names found with passes == 2 */
 315 uint64_t ncs_2passes; /* number of times we attempt it */
 316 uint64_t ncs_revhits; /* reverse-cache hits */
 317 uint64_t ncs_revmiss; /* reverse-cache misses */
 318};
 319
307#ifdef _KERNEL 320#ifdef _KERNEL
308extern struct nchstats nchstats; 321extern struct nchstats nchstats;
309#endif 322#endif
310/* #endif !_SYS_NAMEI_H_ (generated by gennameih.awk) */ 323/* #endif !_SYS_NAMEI_H_ (generated by gennameih.awk) */

cvs diff -r1.77 -r1.78 src/usr.bin/systat/vmstat.c (expand / switch to unified diff)

--- src/usr.bin/systat/vmstat.c 2010/04/30 16:21:05 1.77
+++ src/usr.bin/systat/vmstat.c 2014/06/03 21:16:15 1.78
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vmstat.c,v 1.77 2010/04/30 16:21:05 njoly Exp $ */ 1/* $NetBSD: vmstat.c,v 1.78 2014/06/03 21:16:15 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1983, 1989, 1992, 1993 4 * Copyright (c) 1983, 1989, 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; 35static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
36#endif 36#endif
37__RCSID("$NetBSD: vmstat.c,v 1.77 2010/04/30 16:21:05 njoly Exp $"); 37__RCSID("$NetBSD: vmstat.c,v 1.78 2014/06/03 21:16:15 joerg Exp $");
38#endif /* not lint */ 38#endif /* not lint */
39 39
40/* 40/*
41 * Cursed vmstat -- from Robert Elz. 41 * Cursed vmstat -- from Robert Elz.
42 */ 42 */
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/uio.h> 45#include <sys/uio.h>
46#include <sys/namei.h> 46#include <sys/namei.h>
47#include <sys/sysctl.h> 47#include <sys/sysctl.h>
48#include <sys/evcnt.h> 48#include <sys/evcnt.h>
49 49
50#include <uvm/uvm_extern.h> 50#include <uvm/uvm_extern.h>
@@ -53,27 +53,27 @@ __RCSID("$NetBSD: vmstat.c,v 1.77 2010/0 @@ -53,27 +53,27 @@ __RCSID("$NetBSD: vmstat.c,v 1.77 2010/0
53#include <stdlib.h> 53#include <stdlib.h>
54#include <string.h> 54#include <string.h>
55#include <util.h> 55#include <util.h>
56 56
57#include "systat.h" 57#include "systat.h"
58#include "extern.h" 58#include "extern.h"
59#include "drvstats.h" 59#include "drvstats.h"
60#include "utmpentry.h" 60#include "utmpentry.h"
61#include "vmstat.h" 61#include "vmstat.h"
62 62
63static struct Info { 63static struct Info {
64 struct uvmexp_sysctl uvmexp; 64 struct uvmexp_sysctl uvmexp;
65 struct vmtotal Total; 65 struct vmtotal Total;
66 struct nchstats nchstats; 66 struct nchstats_sysctl nchstats;
67 long nchcount; 67 long nchcount;
68 long *intrcnt; 68 long *intrcnt;
69 u_int64_t *evcnt; 69 u_int64_t *evcnt;
70} s, s1, s2, z; 70} s, s1, s2, z;
71 71
72enum display_mode display_mode = TIME; 72enum display_mode display_mode = TIME;
73 73
74static void allocinfo(struct Info *); 74static void allocinfo(struct Info *);
75static void copyinfo(struct Info *, struct Info *); 75static void copyinfo(struct Info *, struct Info *);
76static float cputime(int); 76static float cputime(int);
77static void dinfo(int, int, int); 77static void dinfo(int, int, int);
78static void getinfo(struct Info *); 78static void getinfo(struct Info *);
79static int ucount(void); 79static int ucount(void);
@@ -766,27 +766,32 @@ putfloat(double f, int l, int c, int w,  @@ -766,27 +766,32 @@ putfloat(double f, int l, int c, int w,
766 } 766 }
767 addstr(b); 767 addstr(b);
768} 768}
769 769
770static void 770static void
771getinfo(struct Info *stats) 771getinfo(struct Info *stats)
772{ 772{
773 int mib[2]; 773 int mib[2];
774 size_t size; 774 size_t size;
775 int i; 775 int i;
776 776
777 cpureadstats(); 777 cpureadstats();
778 drvreadstats(); 778 drvreadstats();
779 NREAD(X_NCHSTATS, &stats->nchstats, sizeof stats->nchstats); 779 size = sizeof(stats->nchstats);
 780 if (sysctlbyname("vfs.namecache_stats", &stats->nchstats, &size,
 781 NULL, 0) < 0) {
 782 error("can't get namecache statistics: %s\n", strerror(errno));
 783 memset(&stats->nchstats, 0, sizeof(stats->nchstats));
 784 }
780 if (nintr) 785 if (nintr)
781 NREAD(X_INTRCNT, stats->intrcnt, nintr * LONG); 786 NREAD(X_INTRCNT, stats->intrcnt, nintr * LONG);
782 for (i = 0; i < nevcnt; i++) 787 for (i = 0; i < nevcnt; i++)
783 KREAD(ie_head[i].ie_count, &stats->evcnt[i], 788 KREAD(ie_head[i].ie_count, &stats->evcnt[i],
784 sizeof stats->evcnt[i]); 789 sizeof stats->evcnt[i]);
785 size = sizeof(stats->uvmexp); 790 size = sizeof(stats->uvmexp);
786 mib[0] = CTL_VM; 791 mib[0] = CTL_VM;
787 mib[1] = VM_UVMEXP2; 792 mib[1] = VM_UVMEXP2;
788 if (sysctl(mib, 2, &stats->uvmexp, &size, NULL, 0) < 0) { 793 if (sysctl(mib, 2, &stats->uvmexp, &size, NULL, 0) < 0) {
789 error("can't get uvmexp: %s\n", strerror(errno)); 794 error("can't get uvmexp: %s\n", strerror(errno));
790 memset(&stats->uvmexp, 0, sizeof(stats->uvmexp)); 795 memset(&stats->uvmexp, 0, sizeof(stats->uvmexp));
791 } 796 }
792 size = sizeof(stats->Total); 797 size = sizeof(stats->Total);

cvs diff -r1.193 -r1.194 src/usr.bin/vmstat/vmstat.c (expand / switch to unified diff)

--- src/usr.bin/vmstat/vmstat.c 2014/06/02 19:16:10 1.193
+++ src/usr.bin/vmstat/vmstat.c 2014/06/03 21:16:15 1.194
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vmstat.c,v 1.193 2014/06/02 19:16:10 joerg Exp $ */ 1/* $NetBSD: vmstat.c,v 1.194 2014/06/03 21:16:15 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation by: 7 * This code is derived from software contributed to The NetBSD Foundation by:
8 * - Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * - Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * - Simon Burge and Luke Mewburn of Wasabi Systems, Inc. 10 * - Simon Burge and Luke Mewburn of Wasabi Systems, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -60,27 +60,27 @@ @@ -60,27 +60,27 @@
60 * SUCH DAMAGE. 60 * SUCH DAMAGE.
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64#ifndef lint 64#ifndef lint
65__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\ 65__COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\
66 The Regents of the University of California. All rights reserved."); 66 The Regents of the University of California. All rights reserved.");
67#endif /* not lint */ 67#endif /* not lint */
68 68
69#ifndef lint 69#ifndef lint
70#if 0 70#if 0
71static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95"; 71static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
72#else 72#else
73__RCSID("$NetBSD: vmstat.c,v 1.193 2014/06/02 19:16:10 joerg Exp $"); 73__RCSID("$NetBSD: vmstat.c,v 1.194 2014/06/03 21:16:15 joerg Exp $");
74#endif 74#endif
75#endif /* not lint */ 75#endif /* not lint */
76 76
77#define __POOL_EXPOSE 77#define __POOL_EXPOSE
78 78
79#include <sys/param.h> 79#include <sys/param.h>
80#include <sys/types.h> 80#include <sys/types.h>
81#include <sys/mount.h> 81#include <sys/mount.h>
82#include <sys/uio.h> 82#include <sys/uio.h>
83 83
84#include <sys/buf.h> 84#include <sys/buf.h>
85#include <sys/evcnt.h> 85#include <sys/evcnt.h>
86#include <sys/ioctl.h> 86#include <sys/ioctl.h>
@@ -838,28 +838,28 @@ pct(long top, long bot) @@ -838,28 +838,28 @@ pct(long top, long bot)
838 long ans; 838 long ans;
839 839
840 if (bot == 0) 840 if (bot == 0)
841 return (0); 841 return (0);
842 ans = (long)((quad_t)top * 100 / bot); 842 ans = (long)((quad_t)top * 100 / bot);
843 return (ans); 843 return (ans);
844} 844}
845 845
846#define PCT(top, bot) (int)pct((long)(top), (long)(bot)) 846#define PCT(top, bot) (int)pct((long)(top), (long)(bot))
847 847
848void 848void
849dosum(void) 849dosum(void)
850{ 850{
851 struct nchstats nchstats; 851 struct nchstats_sysctl nch_stats;
852 u_long nchtotal; 852 uint64_t nchtotal;
853 struct uvmexp_sysctl uvmexp2; 853 struct uvmexp_sysctl uvmexp2;
854 size_t ssize; 854 size_t ssize;
855 int active_kernel; 855 int active_kernel;
856 struct cpu_counter cc; 856 struct cpu_counter cc;
857 857
858 /* 858 /*
859 * The "active" and "inactive" variables 859 * The "active" and "inactive" variables
860 * are now estimated by the kernel and sadly 860 * are now estimated by the kernel and sadly
861 * can not easily be dug out of a crash dump. 861 * can not easily be dug out of a crash dump.
862 */ 862 */
863 ssize = sizeof(uvmexp2); 863 ssize = sizeof(uvmexp2);
864 memset(&uvmexp2, 0, ssize); 864 memset(&uvmexp2, 0, ssize);
865 active_kernel = (memf == NULL); 865 active_kernel = (memf == NULL);
@@ -955,48 +955,71 @@ dosum(void) @@ -955,48 +955,71 @@ dosum(void)
955 955
956 (void)printf("%9u times daemon wokeup\n",uvmexp.pdwoke); 956 (void)printf("%9u times daemon wokeup\n",uvmexp.pdwoke);
957 (void)printf("%9u revolutions of the clock hand\n", uvmexp.pdrevs); 957 (void)printf("%9u revolutions of the clock hand\n", uvmexp.pdrevs);
958 (void)printf("%9u pages freed by daemon\n", uvmexp.pdfreed); 958 (void)printf("%9u pages freed by daemon\n", uvmexp.pdfreed);
959 (void)printf("%9u pages scanned by daemon\n", uvmexp.pdscans); 959 (void)printf("%9u pages scanned by daemon\n", uvmexp.pdscans);
960 (void)printf("%9u anonymous pages scanned by daemon\n", 960 (void)printf("%9u anonymous pages scanned by daemon\n",
961 uvmexp.pdanscan); 961 uvmexp.pdanscan);
962 (void)printf("%9u object pages scanned by daemon\n", uvmexp.pdobscan); 962 (void)printf("%9u object pages scanned by daemon\n", uvmexp.pdobscan);
963 (void)printf("%9u pages reactivated\n", uvmexp.pdreact); 963 (void)printf("%9u pages reactivated\n", uvmexp.pdreact);
964 (void)printf("%9u pages found busy by daemon\n", uvmexp.pdbusy); 964 (void)printf("%9u pages found busy by daemon\n", uvmexp.pdbusy);
965 (void)printf("%9u total pending pageouts\n", uvmexp.pdpending); 965 (void)printf("%9u total pending pageouts\n", uvmexp.pdpending);
966 (void)printf("%9u pages deactivated\n", uvmexp.pddeact); 966 (void)printf("%9u pages deactivated\n", uvmexp.pddeact);
967 967
968 kread(namelist, X_NCHSTATS, &nchstats, sizeof(nchstats)); 968 if (active_kernel) {
969 nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits + 969 ssize = sizeof(nch_stats);
970 nchstats.ncs_badhits + nchstats.ncs_falsehits + 970 if (sysctlbyname("vfs.namecache_stats", &nch_stats, &ssize,
971 nchstats.ncs_miss + nchstats.ncs_long; 971 NULL, 0)) {
972 (void)printf("%9lu total name lookups\n", nchtotal); 972 warn("vfs.namecache_stats failed");
973 (void)printf("%9lu good hits\n", nchstats.ncs_goodhits); 973 memset(&nch_stats, 0, sizeof(nch_stats));
974 (void)printf("%9lu negative hits\n", nchstats.ncs_neghits); 974 }
975 (void)printf("%9lu bad hits\n", nchstats.ncs_badhits); 975 } else {
976 (void)printf("%9lu false hits\n", nchstats.ncs_falsehits); 976 struct nchstats nch_stats_kvm;
977 (void)printf("%9lu miss\n", nchstats.ncs_miss); 977
978 (void)printf("%9lu too long\n", nchstats.ncs_long); 978 kread(namelist, X_NCHSTATS, &nch_stats_kvm,
979 (void)printf("%9lu pass2 hits\n", nchstats.ncs_pass2); 979 sizeof(nch_stats_kvm));
980 (void)printf("%9lu 2passes\n", nchstats.ncs_2passes); 980 nch_stats.ncs_goodhits = nch_stats_kvm.ncs_goodhits;
 981 nch_stats.ncs_neghits = nch_stats_kvm.ncs_neghits;
 982 nch_stats.ncs_badhits = nch_stats_kvm.ncs_badhits;
 983 nch_stats.ncs_falsehits = nch_stats_kvm.ncs_falsehits;
 984 nch_stats.ncs_miss = nch_stats_kvm.ncs_miss;
 985 nch_stats.ncs_long = nch_stats_kvm.ncs_long;
 986 nch_stats.ncs_pass2 = nch_stats_kvm.ncs_pass2;
 987 nch_stats.ncs_2passes = nch_stats_kvm.ncs_2passes;
 988 nch_stats.ncs_revhits = nch_stats_kvm.ncs_revhits;
 989 nch_stats.ncs_revmiss = nch_stats_kvm.ncs_revmiss;
 990 }
 991
 992 nchtotal = nch_stats.ncs_goodhits + nch_stats.ncs_neghits +
 993 nch_stats.ncs_badhits + nch_stats.ncs_falsehits +
 994 nch_stats.ncs_miss + nch_stats.ncs_long;
 995 (void)printf("%9" PRIu64 " total name lookups\n", nchtotal);
 996 (void)printf("%9" PRIu64 " good hits\n", nch_stats.ncs_goodhits);
 997 (void)printf("%9" PRIu64 " negative hits\n", nch_stats.ncs_neghits);
 998 (void)printf("%9" PRIu64 " bad hits\n", nch_stats.ncs_badhits);
 999 (void)printf("%9" PRIu64 " false hits\n", nch_stats.ncs_falsehits);
 1000 (void)printf("%9" PRIu64 " miss\n", nch_stats.ncs_miss);
 1001 (void)printf("%9" PRIu64 " too long\n", nch_stats.ncs_long);
 1002 (void)printf("%9" PRIu64 " pass2 hits\n", nch_stats.ncs_pass2);
 1003 (void)printf("%9" PRIu64 " 2passes\n", nch_stats.ncs_2passes);
981 (void)printf( 1004 (void)printf(
982 "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n", 1005 "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
983 "", PCT(nchstats.ncs_goodhits, nchtotal), 1006 "", PCT(nch_stats.ncs_goodhits, nchtotal),
984 PCT(nchstats.ncs_neghits, nchtotal), 1007 PCT(nch_stats.ncs_neghits, nchtotal),
985 PCT(nchstats.ncs_pass2, nchtotal)); 1008 PCT(nch_stats.ncs_pass2, nchtotal));
986 (void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "", 1009 (void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "",
987 PCT(nchstats.ncs_badhits, nchtotal), 1010 PCT(nch_stats.ncs_badhits, nchtotal),
988 PCT(nchstats.ncs_falsehits, nchtotal), 1011 PCT(nch_stats.ncs_falsehits, nchtotal),
989 PCT(nchstats.ncs_long, nchtotal)); 1012 PCT(nch_stats.ncs_long, nchtotal));
990} 1013}
991 1014
992void 1015void
993doforkst(void) 1016doforkst(void)
994{ 1017{
995 kread(namelist, X_UVMEXP, &uvmexp, sizeof(uvmexp)); 1018 kread(namelist, X_UVMEXP, &uvmexp, sizeof(uvmexp));
996 1019
997 (void)printf("%u forks total\n", uvmexp.forks); 1020 (void)printf("%u forks total\n", uvmexp.forks);
998 (void)printf("%u forks blocked parent\n", uvmexp.forks_ppwait); 1021 (void)printf("%u forks blocked parent\n", uvmexp.forks_ppwait);
999 (void)printf("%u forks shared address space with parent\n", 1022 (void)printf("%u forks shared address space with parent\n",
1000 uvmexp.forks_sharevm); 1023 uvmexp.forks_sharevm);
1001} 1024}
1002 1025