Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Jun 2015 14:28:44 GMT
From:      btw@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r286556 - soc2015/btw/head/sys/net
Message-ID:  <201506021428.t52ESihj029738@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: btw
Date: Tue Jun  2 14:28:43 2015
New Revision: 286556
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=286556

Log:
  Add the supports for allocating per-ring counters to ifnet KPI.

Modified:
  soc2015/btw/head/sys/net/if.c
  soc2015/btw/head/sys/net/if.h
  soc2015/btw/head/sys/net/if_var.h

Modified: soc2015/btw/head/sys/net/if.c
==============================================================================
--- soc2015/btw/head/sys/net/if.c	Tue Jun  2 13:07:22 2015	(r286555)
+++ soc2015/btw/head/sys/net/if.c	Tue Jun  2 14:28:43 2015	(r286556)
@@ -514,8 +514,9 @@
 	struct iftype *ift;
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
+	struct ifring **ifrs;
 	struct sockaddr_dl *sdl;
-	int socksize, ifasize, namelen, masklen;
+	int socksize, ifasize, namelen, masklen, nrings;
 
 	KASSERT(ifat->ifat_version == IF_ATTACH_VERSION,
 	    ("%s: version %d, expected %d",
@@ -611,6 +612,18 @@
 	refcount_init(&ifp->if_refcount, 1);
 
 	/*
+	 * Allocate ifring to store the per-ring statistics for this
+	 * interface.
+	 */
+	nrings = ifat->ifat_nrings;
+	ifrs = malloc(sizeof(struct ifring *) * nrings, M_IFNET, M_WAITOK);
+	for (int i = 0; i < nrings; i++)
+		ifrs[i] = malloc(sizeof(struct ifring), M_IFNET,
+		    M_WAITOK | M_ZERO);
+	ifp->if_nrings = nrings;
+	ifp->if_rings = ifrs;
+
+	/*
 	 * Allocate ifaddr to store link level address and name for this
 	 * interface.  Always save enough space for any possiable name so
 	 * we can do a rename in place later.
@@ -683,6 +696,10 @@
 
 	ifmedia_free(ifp);
 
+	for (int i = 0; i < ifp->if_nrings; i++)
+		free(ifp->if_rings[i], M_IFNET);
+	free(ifp->if_rings, M_IFNET);
+
 	rw_destroy(&ifp->if_lock);
 	free(ifp, M_IFNET);
 }
@@ -1572,6 +1589,8 @@
 		return (ifp->if_xname);
 	case IF_VLAN:
 		return (ifp->if_vlantrunk);
+	case IF_RING:
+		return (ifp->if_rings);
 	default:
 		/* fall through */
 		;

Modified: soc2015/btw/head/sys/net/if.h
==============================================================================
--- soc2015/btw/head/sys/net/if.h	Tue Jun  2 13:07:22 2015	(r286555)
+++ soc2015/btw/head/sys/net/if.h	Tue Jun  2 14:28:43 2015	(r286556)
@@ -588,6 +588,7 @@
 	IF_VLAN,
 	IF_TOEDEV,
 	IF_MEDIA,
+	IF_RING,
 	/*
 	 * Space above 99999 is split among different vendors.
 	 *
@@ -597,6 +598,7 @@
 } ift_feature;
 
 typedef struct ifnet * if_t;
+typedef struct ifring * ifring_t;
 
 typedef void	(*if_input_t)(if_t, struct mbuf *);
 typedef int	(*if_transmit_t)(if_t, struct mbuf *);
@@ -726,6 +728,10 @@
 	 * later.  Otherwise it inherits static iftsomax from ifdriver.
 	 */
 	struct iftsomax *ifat_tsomax;
+	/*
+	 * Number of the tx/rx rings.
+	 */
+	int		ifat_nrings;
 };
 
 /*

Modified: soc2015/btw/head/sys/net/if_var.h
==============================================================================
--- soc2015/btw/head/sys/net/if_var.h	Tue Jun  2 13:07:22 2015	(r286555)
+++ soc2015/btw/head/sys/net/if_var.h	Tue Jun  2 14:28:43 2015	(r286556)
@@ -152,7 +152,7 @@
 	size_t		if_linkmiblen;	/* length of above data */
 	u_int		if_refcount;	/* reference count */
 	u_int		if_fib;		/* interface FIB */
-	struct ifring	*if_rings;	/* pairs of tx and rx rings */
+	struct ifring	**if_rings;	/* pairs of tx and rx rings */
 	int		if_nrings;	/* elements in if_rings */
 
 	uint8_t		if_link_state;	/* current link state */



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