diff options
author | ae <ae@FreeBSD.org> | 2013-07-09 09:43:03 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2013-07-09 09:43:03 +0000 |
commit | 1b1e1de2b2e27f692afabbf18eee1f7a70caa049 (patch) | |
tree | ae9cc37d3d61216f4f205b4e2bf561b5cf5ea330 /sys/netinet/ip_input.c | |
parent | 027c687189cc0647592f671691e0a08064401c1d (diff) | |
download | FreeBSD-src-1b1e1de2b2e27f692afabbf18eee1f7a70caa049.zip FreeBSD-src-1b1e1de2b2e27f692afabbf18eee1f7a70caa049.tar.gz |
Use new macros to implement ipstat and tcpstat using PCPU counters.
Change interface of kread_counters() similar ot kread() in the netstat(1).
Diffstat (limited to 'sys/netinet/ip_input.c')
-rw-r--r-- | sys/netinet/ip_input.c | 72 |
1 files changed, 8 insertions, 64 deletions
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 0268ebc..219f362 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -208,73 +208,17 @@ SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, output_flowtable_size, CTLFLAG_RDTUN, static void ip_freef(struct ipqhead *, struct ipq *); /* - * IP statistics are stored in struct ipstat_p, which is - * an "array" of counter(9)s. Although it isn't a real - * array, we treat it as array to reduce code bloat. + * IP statistics are stored in the "array" of counter(9)s. */ -VNET_DEFINE(struct ipstat_p, ipstatp); - -static void -vnet_ipstatp_init(const void *unused) -{ - counter_u64_t *c; - int i; - - for (i = 0, c = (counter_u64_t *)&V_ipstatp; - i < sizeof(V_ipstatp) / sizeof(counter_u64_t); - i++, c++) { - *c = counter_u64_alloc(M_WAITOK); - counter_u64_zero(*c); - } -} -VNET_SYSINIT(vnet_ipstatp_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, - vnet_ipstatp_init, NULL); +VNET_PCPUSTAT_DEFINE(struct ipstat, ipstat); +VNET_PCPUSTAT_SYSINIT(ipstat); +SYSCTL_VNET_PCPUSTAT(_net_inet_ip, IPCTL_STATS, stats, struct ipstat, ipstat, + "IP statistics (struct ipstat, netinet/ip_var.h)"); #ifdef VIMAGE -static void -vnet_ipstatp_uninit(const void *unused) -{ - counter_u64_t *c; - int i; - - for (i = 0, c = (counter_u64_t *)&V_ipstatp; - i < sizeof(V_ipstatp) / sizeof(counter_u64_t); - i++, c++) - counter_u64_free(*c); -} -VNET_SYSUNINIT(vnet_ipstatp_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY, - vnet_ipstatp_uninit, NULL); +VNET_PCPUSTAT_SYSUNINIT(ipstat); #endif /* VIMAGE */ -static int -ipstat_sysctl(SYSCTL_HANDLER_ARGS) -{ - struct ipstat ipstat; - counter_u64_t *c; - uint64_t *v; - int i; - - for (i = 0, c = (counter_u64_t *)&V_ipstatp, v = (uint64_t *)&ipstat; - i < sizeof(V_ipstatp) / sizeof(counter_u64_t); - i++, c++, v++) { - *v = counter_u64_fetch(*c); - /* - * Old interface allowed to rewrite 'struct ipstat', and - * netstat(1) used it to zero the structure. To keep - * compatibility with old netstat(1) we will zero out - * statistics on every write attempt, however we no longer - * support writing arbitrary fake values to the statistics. - */ - if (req->newptr) - counter_u64_zero(*c); - } - - return (SYSCTL_OUT(req, &ipstat, sizeof(ipstat))); -} -SYSCTL_VNET_PROC(_net_inet_ip, IPCTL_STATS, stats, CTLTYPE_OPAQUE | CTLFLAG_RW, - NULL, 0, ipstat_sysctl, "I", - "IP statistics (struct ipstat, netinet/ip_var.h)"); - /* * Kernel module interface for updating ipstat. The argument is an index * into ipstat treated as an array. @@ -283,14 +227,14 @@ void kmod_ipstat_inc(int statnum) { - counter_u64_add(*((counter_u64_t *)&V_ipstatp + statnum), 1); + counter_u64_add(VNET(ipstat)[statnum], 1); } void kmod_ipstat_dec(int statnum) { - counter_u64_add(*((counter_u64_t *)&V_ipstatp + statnum), -1); + counter_u64_add(VNET(ipstat)[statnum], -1); } static int |