Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Dec 2019 02:02:27 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r355840 - in head: sys/net usr.bin/netstat
Message-ID:  <201912170202.xBH22RZb055946@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Tue Dec 17 02:02:26 2019
New Revision: 355840
URL: https://svnweb.freebsd.org/changeset/base/355840

Log:
  Convert routing statistics to VNET_PCPUSTAT.
  
  Submitted by:	ocochard
  Reviewed by:	melifaro, glebius
  Differential Revision:	https://reviews.freebsd.org/D22834

Modified:
  head/sys/net/route.c
  head/sys/net/route.h
  head/usr.bin/netstat/route.c

Modified: head/sys/net/route.c
==============================================================================
--- head/sys/net/route.c	Tue Dec 17 01:37:02 2019	(r355839)
+++ head/sys/net/route.c	Tue Dec 17 02:02:26 2019	(r355840)
@@ -108,9 +108,16 @@ VNET_DEFINE(u_int, rt_add_addr_allfibs) = 1;
 SYSCTL_UINT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RWTUN | CTLFLAG_VNET,
     &VNET_NAME(rt_add_addr_allfibs), 0, "");
 
-VNET_DEFINE(struct rtstat, rtstat);
-#define	V_rtstat	VNET(rtstat)
+VNET_PCPUSTAT_DEFINE_STATIC(struct rtstat, rtstat);
+#define	RTSTAT_ADD(name, val)	\
+	VNET_PCPUSTAT_ADD(struct rtstat, rtstat, name, (val))
+#define	RTSTAT_INC(name)	RTSTAT_ADD(name, 1)
 
+VNET_PCPUSTAT_SYSINIT(rtstat);
+#ifdef VIMAGE
+VNET_PCPUSTAT_SYSUNINIT(rtstat);
+#endif
+
 VNET_DEFINE(struct rib_head *, rt_tables);
 #define	V_rt_tables	VNET(rt_tables)
 
@@ -476,7 +483,7 @@ rtalloc1_fib(struct sockaddr *dst, int report, u_long 
 	 * which basically means: "cannot get there from here".
 	 */
 miss:
-	V_rtstat.rts_unreach++;
+	RTSTAT_INC(rts_unreach);
 
 	if (report) {
 		/*
@@ -587,7 +594,6 @@ rtredirect_fib(struct sockaddr *dst,
 {
 	struct rtentry *rt;
 	int error = 0;
-	short *stat = NULL;
 	struct rt_addrinfo info;
 	struct ifaddr *ifa;
 	struct rib_head *rnh;
@@ -661,8 +667,8 @@ rtredirect_fib(struct sockaddr *dst,
 				RT_LOCK(rt);
 				flags = rt->rt_flags;
 			}
-			
-			stat = &V_rtstat.rts_dynamic;
+			if (error == 0)
+				RTSTAT_INC(rts_dynamic);
 		} else {
 
 			/*
@@ -673,7 +679,7 @@ rtredirect_fib(struct sockaddr *dst,
 				rt->rt_flags &= ~RTF_GATEWAY;
 			rt->rt_flags |= RTF_MODIFIED;
 			flags |= RTF_MODIFIED;
-			stat = &V_rtstat.rts_newgateway;
+			RTSTAT_INC(rts_newgateway);
 			/*
 			 * add the key and gateway (in one malloc'd chunk).
 			 */
@@ -690,9 +696,7 @@ done:
 		RTFREE_LOCKED(rt);
  out:
 	if (error)
-		V_rtstat.rts_badredirect++;
-	else if (stat != NULL)
-		(*stat)++;
+		RTSTAT_INC(rts_badredirect);
 	bzero((caddr_t)&info, sizeof(info));
 	info.rti_info[RTAX_DST] = dst;
 	info.rti_info[RTAX_GATEWAY] = gateway;

Modified: head/sys/net/route.h
==============================================================================
--- head/sys/net/route.h	Tue Dec 17 01:37:02 2019	(r355839)
+++ head/sys/net/route.h	Tue Dec 17 02:02:26 2019	(r355840)
@@ -237,13 +237,14 @@ rt_update_ro_flags(struct route *ro)
 /*
  * Routing statistics.
  */
-struct	rtstat {
-	short	rts_badredirect;	/* bogus redirect calls */
-	short	rts_dynamic;		/* routes created by redirects */
-	short	rts_newgateway;		/* routes modified by redirects */
-	short	rts_unreach;		/* lookups which failed */
-	short	rts_wildcard;		/* lookups satisfied by a wildcard */
+struct rtstat {
+	uint64_t rts_badredirect;	/* bogus redirect calls */
+	uint64_t rts_dynamic;		/* routes created by redirects */
+	uint64_t rts_newgateway;	/* routes modified by redirects */
+	uint64_t rts_unreach;		/* lookups which failed */
+	uint64_t rts_wildcard;		/* lookups satisfied by a wildcard */
 };
+
 /*
  * Structures for routing messages.
  */

Modified: head/usr.bin/netstat/route.c
==============================================================================
--- head/usr.bin/netstat/route.c	Tue Dec 17 01:37:02 2019	(r355839)
+++ head/usr.bin/netstat/route.c	Tue Dec 17 02:02:26 2019	(r355840)
@@ -776,22 +776,22 @@ rt_stats(void)
 		xo_emit("{W:rttrash: symbol not in namelist}\n");
 		return;
 	}
-	kread(rtsaddr, (char *)&rtstat, sizeof (rtstat));
+	kread_counters(rtsaddr, (char *)&rtstat, sizeof (rtstat));
 	kread(rttaddr, (char *)&rttrash, sizeof (rttrash));
 	xo_emit("{T:routing}:\n");
 
 #define	p(f, m) if (rtstat.f || sflag <= 1) \
 	xo_emit(m, rtstat.f, plural(rtstat.f))
 
-	p(rts_badredirect, "\t{:bad-redirects/%hu} "
+	p(rts_badredirect, "\t{:bad-redirects/%ju} "
 	    "{N:/bad routing redirect%s}\n");
-	p(rts_dynamic, "\t{:dynamically-created/%hu} "
+	p(rts_dynamic, "\t{:dynamically-created/%ju} "
 	    "{N:/dynamically created route%s}\n");
-	p(rts_newgateway, "\t{:new-gateways/%hu} "
+	p(rts_newgateway, "\t{:new-gateways/%ju} "
 	    "{N:/new gateway%s due to redirects}\n");
-	p(rts_unreach, "\t{:unreachable-destination/%hu} "
+	p(rts_unreach, "\t{:unreachable-destination/%ju} "
 	    "{N:/destination%s found unreachable}\n");
-	p(rts_wildcard, "\t{:wildcard-uses/%hu} "
+	p(rts_wildcard, "\t{:wildcard-uses/%ju} "
 	    "{N:/use%s of a wildcard route}\n");
 #undef p
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912170202.xBH22RZb055946>