From 5b7cb97c2b6f73e3a9fdc9e7e3d8771e29be9889 Mon Sep 17 00:00:00 2001 From: "Andrey V. Elsukov" Date: Tue, 9 Jul 2013 09:50:15 +0000 Subject: [PATCH] Migrate structs arpstat, icmpstat, mrtstat, pimstat and udpstat to PCPU counters. --- sys/net/if_arp.h | 12 ++++++++++-- sys/netinet/icmp_var.h | 11 ++++++----- sys/netinet/if_ether.c | 13 ++++++++----- sys/netinet/in.c | 3 --- sys/netinet/ip_icmp.c | 13 +++++++++---- sys/netinet/ip_mroute.c | 21 +++++++++++---------- sys/netinet/ip_mroute.h | 3 ++- sys/netinet/pim_var.h | 3 ++- sys/netinet/udp_usrreq.c | 13 ++++++++----- sys/netinet/udp_var.h | 12 +++++++----- usr.bin/netstat/inet.c | 8 ++++---- usr.bin/netstat/mroute.c | 2 +- 12 files changed, 68 insertions(+), 46 deletions(-) diff --git a/sys/net/if_arp.h b/sys/net/if_arp.h index 3826d067ddb1..2dd8c32d06c9 100644 --- a/sys/net/if_arp.h +++ b/sys/net/if_arp.h @@ -127,13 +127,21 @@ struct arpstat { uint64_t dupips; /* # of duplicate IPs detected. */ }; +#ifdef _KERNEL +#include +#include + +VNET_PCPUSTAT_DECLARE(struct arpstat, arpstat); /* * In-kernel consumers can use these accessor macros directly to update * stats. */ -#define ARPSTAT_ADD(name, val) V_arpstat.name += (val) -#define ARPSTAT_SUB(name, val) V_arpstat.name -= (val) +#define ARPSTAT_ADD(name, val) \ + VNET_PCPUSTAT_ADD(struct arpstat, arpstat, name, (val)) +#define ARPSTAT_SUB(name, val) ARPSTAT_ADD(name, -(val)) #define ARPSTAT_INC(name) ARPSTAT_ADD(name, 1) #define ARPSTAT_DEC(name) ARPSTAT_SUB(name, 1) +#endif /* _KERNEL */ + #endif /* !_NET_IF_ARP_H_ */ diff --git a/sys/netinet/icmp_var.h b/sys/netinet/icmp_var.h index d939cc2e6d85..809879db9d7d 100644 --- a/sys/netinet/icmp_var.h +++ b/sys/netinet/icmp_var.h @@ -58,11 +58,15 @@ struct icmpstat { }; #ifdef _KERNEL +#include + +VNET_PCPUSTAT_DECLARE(struct icmpstat, icmpstat); /* * In-kernel consumers can use these accessor macros directly to update * stats. */ -#define ICMPSTAT_ADD(name, val) V_icmpstat.name += (val) +#define ICMPSTAT_ADD(name, val) \ + VNET_PCPUSTAT_ADD(struct icmpstat, icmpstat, name, (val)) #define ICMPSTAT_INC(name) ICMPSTAT_ADD(name, 1) /* @@ -70,7 +74,7 @@ struct icmpstat { */ void kmod_icmpstat_inc(int statnum); #define KMOD_ICMPSTAT_INC(name) \ - kmod_icmpstat_inc(offsetof(struct icmpstat, name) / sizeof(u_long)) + kmod_icmpstat_inc(offsetof(struct icmpstat, name) / sizeof(uint64_t)) #endif /* @@ -91,9 +95,6 @@ void kmod_icmpstat_inc(int statnum); #ifdef _KERNEL SYSCTL_DECL(_net_inet_icmp); -VNET_DECLARE(struct icmpstat, icmpstat); /* icmp statistics. */ -#define V_icmpstat VNET(icmpstat) - extern int badport_bandlim(int); #define BANDLIM_UNLIMITED -1 #define BANDLIM_ICMP_UNREACH 0 diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index ad31557b0026..675e0ddadc9c 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -89,7 +89,12 @@ VNET_DEFINE(int, useloopback) = 1; /* use loopback interface for static VNET_DEFINE(int, arp_proxyall) = 0; static VNET_DEFINE(int, arpt_down) = 20; /* keep incomplete entries for * 20 seconds */ -VNET_DEFINE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */ +VNET_PCPUSTAT_DEFINE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */ +VNET_PCPUSTAT_SYSINIT(arpstat); + +#ifdef VIMAGE +VNET_PCPUSTAT_SYSUNINIT(arpstat); +#endif /* VIMAGE */ static VNET_DEFINE(int, arp_maxhold) = 1; @@ -97,7 +102,6 @@ static VNET_DEFINE(int, arp_maxhold) = 1; #define V_arpt_down VNET(arpt_down) #define V_arp_maxtries VNET(arp_maxtries) #define V_arp_proxyall VNET(arp_proxyall) -#define V_arpstat VNET(arpstat) #define V_arp_maxhold VNET(arp_maxhold) SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW, @@ -115,9 +119,8 @@ SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW, SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, wait, CTLFLAG_RW, &VNET_NAME(arpt_down), 0, "Incomplete ARP entry lifetime in seconds"); -SYSCTL_VNET_STRUCT(_net_link_ether_arp, OID_AUTO, stats, CTLFLAG_RW, - &VNET_NAME(arpstat), arpstat, - "ARP statistics (struct arpstat, net/if_arp.h)"); +SYSCTL_VNET_PCPUSTAT(_net_link_ether_arp, OID_AUTO, stats, struct arpstat, + arpstat, "ARP statistics (struct arpstat, net/if_arp.h)"); SYSCTL_VNET_INT(_net_link_ether_inet, OID_AUTO, maxhold, CTLFLAG_RW, &VNET_NAME(arp_maxhold), 0, "Number of packets to hold per ARP entry"); diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 4e73b959fe59..363f671e7dd9 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -85,9 +85,6 @@ SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, no_same_prefix, CTLFLAG_RW, VNET_DECLARE(struct inpcbinfo, ripcbinfo); #define V_ripcbinfo VNET(ripcbinfo) -VNET_DECLARE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */ -#define V_arpstat VNET(arpstat) - /* * Return 1 if an internet address is for a ``local'' host * (one to which we have a connection). diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 39d6f7ea0049..deabf44f7a9e 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -92,9 +92,14 @@ SYSCTL_VNET_INT(_net_inet_icmp, OID_AUTO, icmplim_output, CTLFLAG_RW, "Enable logging of ICMP response rate limiting"); #ifdef INET -VNET_DEFINE(struct icmpstat, icmpstat); -SYSCTL_VNET_STRUCT(_net_inet_icmp, ICMPCTL_STATS, stats, CTLFLAG_RW, - &VNET_NAME(icmpstat), icmpstat, ""); +VNET_PCPUSTAT_DEFINE(struct icmpstat, icmpstat); +VNET_PCPUSTAT_SYSINIT(icmpstat); +SYSCTL_VNET_PCPUSTAT(_net_inet_icmp, ICMPCTL_STATS, stats, struct icmpstat, + icmpstat, "ICMP statistics (struct icmpstat, netinet/icmp_var.h)"); + +#ifdef VIMAGE +VNET_PCPUSTAT_SYSUNINIT(icmpstat); +#endif /* VIMAGE */ static VNET_DEFINE(int, icmpmaskrepl) = 0; #define V_icmpmaskrepl VNET(icmpmaskrepl) @@ -197,7 +202,7 @@ void kmod_icmpstat_inc(int statnum) { - (*((u_long *)&V_icmpstat + statnum))++; + counter_u64_add(VNET(icmpstat)[statnum], 1); } /* diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index b2b52c0e9b06..23f1be7fb872 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -93,6 +93,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -145,11 +146,11 @@ static struct mtx mrouter_mtx; static int ip_mrouter_cnt; /* # of vnets with active mrouters */ static int ip_mrouter_unloading; /* Allow no more V_ip_mrouter sockets */ -static VNET_DEFINE(struct mrtstat, mrtstat); -#define V_mrtstat VNET(mrtstat) -SYSCTL_VNET_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW, - &VNET_NAME(mrtstat), mrtstat, - "IPv4 Multicast Forwarding Statistics (struct mrtstat, " +static VNET_PCPUSTAT_DEFINE(struct mrtstat, mrtstat); +VNET_PCPUSTAT_SYSINIT(mrtstat); +VNET_PCPUSTAT_SYSUNINIT(mrtstat); +SYSCTL_VNET_PCPUSTAT(_net_inet_ip, OID_AUTO, mrtstat, struct mrtstat, + mrtstat, "IPv4 Multicast Forwarding Statistics (struct mrtstat, " "netinet/ip_mroute.h)"); static VNET_DEFINE(u_long, mfchash); @@ -225,13 +226,13 @@ static VNET_DEFINE(struct callout, bw_upcalls_ch); #define BW_UPCALLS_PERIOD (hz) /* periodical flush of bw upcalls */ -static VNET_DEFINE(struct pimstat, pimstat); -#define V_pimstat VNET(pimstat) +static VNET_PCPUSTAT_DEFINE(struct pimstat, pimstat); +VNET_PCPUSTAT_SYSINIT(pimstat); +VNET_PCPUSTAT_SYSUNINIT(pimstat); SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM"); -SYSCTL_VNET_STRUCT(_net_inet_pim, PIMCTL_STATS, stats, CTLFLAG_RD, - &VNET_NAME(pimstat), pimstat, - "PIM Statistics (struct pimstat, netinet/pim_var.h)"); +SYSCTL_VNET_PCPUSTAT(_net_inet_pim, PIMCTL_STATS, stats, struct pimstat, + pimstat, "PIM Statistics (struct pimstat, netinet/pim_var.h)"); static u_long pim_squelch_wholepkt = 0; SYSCTL_ULONG(_net_inet_pim, OID_AUTO, squelch_wholepkt, CTLFLAG_RW, diff --git a/sys/netinet/ip_mroute.h b/sys/netinet/ip_mroute.h index 605b80dfe67b..65f7d83ca3e8 100644 --- a/sys/netinet/ip_mroute.h +++ b/sys/netinet/ip_mroute.h @@ -222,7 +222,8 @@ struct mrtstat { }; #ifdef _KERNEL -#define MRTSTAT_ADD(name, val) V_mrtstat.name += (val) +#define MRTSTAT_ADD(name, val) \ + VNET_PCPUSTAT_ADD(struct mrtstat, mrtstat, name, (val)) #define MRTSTAT_INC(name) MRTSTAT_ADD(name, 1) #endif diff --git a/sys/netinet/pim_var.h b/sys/netinet/pim_var.h index a4ea2344f7ad..1fdfb108fe67 100644 --- a/sys/netinet/pim_var.h +++ b/sys/netinet/pim_var.h @@ -60,7 +60,8 @@ struct pimstat { }; #ifdef _KERNEL -#define PIMSTAT_ADD(name, val) V_pimstat.name += (val) +#define PIMSTAT_ADD(name, val) \ + VNET_PCPUSTAT_ADD(struct pimstat, pimstat, name, (val)) #define PIMSTAT_INC(name) PIMSTAT_ADD(name, 1) #endif diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 6bc94c36f36d..982a2db305fd 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -143,11 +143,14 @@ static VNET_DEFINE(uma_zone_t, udpcb_zone); #define UDBHASHSIZE 128 #endif -VNET_DEFINE(struct udpstat, udpstat); /* from udp_var.h */ -SYSCTL_VNET_STRUCT(_net_inet_udp, UDPCTL_STATS, stats, CTLFLAG_RW, - &VNET_NAME(udpstat), udpstat, - "UDP statistics (struct udpstat, netinet/udp_var.h)"); +VNET_PCPUSTAT_DEFINE(struct udpstat, udpstat); /* from udp_var.h */ +VNET_PCPUSTAT_SYSINIT(udpstat); +SYSCTL_VNET_PCPUSTAT(_net_inet_udp, UDPCTL_STATS, stats, struct udpstat, + udpstat, "UDP statistics (struct udpstat, netinet/udp_var.h)"); +#ifdef VIMAGE +VNET_PCPUSTAT_SYSUNINIT(udpstat); +#endif /* VIMAGE */ #ifdef INET static void udp_detach(struct socket *so); static int udp_output(struct inpcb *, struct mbuf *, struct sockaddr *, @@ -207,7 +210,7 @@ void kmod_udpstat_inc(int statnum) { - (*((u_long *)&V_udpstat + statnum))++; + counter_u64_add(VNET(udpstat)[statnum], 1); } int diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 53bbf1efa0b9..0c26b88cd436 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -94,19 +94,23 @@ struct udpstat { }; #ifdef _KERNEL +#include + +VNET_PCPUSTAT_DECLARE(struct udpstat, udpstat); /* * In-kernel consumers can use these accessor macros directly to update * stats. */ -#define UDPSTAT_ADD(name, val) V_udpstat.name += (val) +#define UDPSTAT_ADD(name, val) \ + VNET_PCPUSTAT_ADD(struct udpstat, udpstat, name, (val)) #define UDPSTAT_INC(name) UDPSTAT_ADD(name, 1) /* * Kernel module consumers must use this accessor macro. */ void kmod_udpstat_inc(int statnum); -#define KMOD_UDPSTAT_INC(name) \ - kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(u_long)) +#define KMOD_UDPSTAT_INC(name) \ + kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(uint64_t)) #endif /* @@ -140,10 +144,8 @@ VNET_DECLARE(struct inpcbinfo, udbinfo); extern u_long udp_sendspace; extern u_long udp_recvspace; VNET_DECLARE(int, udp_cksum); -VNET_DECLARE(struct udpstat, udpstat); VNET_DECLARE(int, udp_blackhole); #define V_udp_cksum VNET(udp_cksum) -#define V_udpstat VNET(udpstat) #define V_udp_blackhole VNET(udp_blackhole) extern int udp_log_in_vain; diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 1df1bfa665f2..f937392a4b65 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -756,7 +756,7 @@ udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) return; } } else - kread(off, &udpstat, len); + kread_counters(off, &udpstat, len); printf("%s:\n", name); #define p(f, m) if (udpstat.f || sflag <= 1) \ @@ -923,7 +923,7 @@ arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) return; } } else - kread(off, &arpstat, len); + kread_counters(off, &arpstat, len); printf("%s:\n", name); @@ -1010,7 +1010,7 @@ icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) return; } } else - kread(off, &icmpstat, len); + kread_counters(off, &icmpstat, len); printf("%s:\n", name); @@ -1217,7 +1217,7 @@ pim_stats(u_long off __unused, const char *name, int af1 __unused, } else { if (off == 0) return; - kread(off, &pimstat, len); + kread_counters(off, &pimstat, len); } printf("%s:\n", name); diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c index b8e5d6da7b63..7cade4e906a1 100644 --- a/usr.bin/netstat/mroute.c +++ b/usr.bin/netstat/mroute.c @@ -350,7 +350,7 @@ mrt_stats(u_long mstaddr) return; } } else - kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); + kread_counters(mstaddr, &mrtstat, len); printf("IPv4 multicast forwarding:\n");