move reading of ifq counters for if_data into ifq.c

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

move reading of ifq counters for if_data into ifq.c

David Gwynne-5
this moves the reading of counters out of an interfaces ifqs into
ifq.c.

there's no semantic change, i just want to keep the knowledge about
locking in an ifq all in the same place.

ok?

Index: if.c
===================================================================
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.523
diff -u -p -r1.523 if.c
--- if.c 4 Nov 2017 16:58:46 -0000 1.523
+++ if.c 14 Nov 2017 00:22:13 -0000
@@ -2276,30 +2276,14 @@ void
 if_getdata(struct ifnet *ifp, struct if_data *data)
 {
  unsigned int i;
- struct ifqueue *ifq;
- uint64_t opackets = 0;
- uint64_t obytes = 0;
- uint64_t omcasts = 0;
- uint64_t oqdrops = 0;
+
+ *data = ifp->if_data;
 
  for (i = 0; i < ifp->if_nifqs; i++) {
- ifq = ifp->if_ifqs[i];
+ struct ifqueue *ifq = ifp->if_ifqs[i];
 
- mtx_enter(&ifq->ifq_mtx);
- opackets += ifq->ifq_packets;
- obytes += ifq->ifq_bytes;
- oqdrops += ifq->ifq_qdrops;
- omcasts += ifq->ifq_mcasts;
- mtx_leave(&ifq->ifq_mtx);
- /* ifq->ifq_errors */
+ ifq_add_data(ifq, data);
  }
-
- *data = ifp->if_data;
- data->ifi_opackets += opackets;
- data->ifi_obytes += obytes;
- data->ifi_oqdrops += oqdrops;
- data->ifi_omcasts += omcasts;
- /* ifp->if_data.ifi_oerrors */
 }
 
 /*
Index: ifq.c
===================================================================
RCS file: /cvs/src/sys/net/ifq.c,v
retrieving revision 1.13
diff -u -p -r1.13 ifq.c
--- ifq.c 14 Nov 2017 00:00:35 -0000 1.13
+++ ifq.c 14 Nov 2017 00:22:13 -0000
@@ -289,6 +289,18 @@ ifq_destroy(struct ifqueue *ifq)
  ml_purge(&ml);
 }
 
+void
+ifq_add_data(struct ifqueue *ifq, struct if_data *data)
+{
+ mtx_enter(&ifq->ifq_mtx);
+ data->ifi_opackets += ifq->ifq_packets;
+ data->ifi_obytes += ifq->ifq_bytes;
+ data->ifi_oqdrops += ifq->ifq_qdrops;
+ data->ifi_omcasts += ifq->ifq_mcasts;
+ /* ifp->if_data.ifi_oerrors */
+ mtx_leave(&ifq->ifq_mtx);
+}
+
 int
 ifq_enqueue(struct ifqueue *ifq, struct mbuf *m)
 {
Index: ifq.h
===================================================================
RCS file: /cvs/src/sys/net/ifq.h,v
retrieving revision 1.14
diff -u -p -r1.14 ifq.h
--- ifq.h 14 Nov 2017 00:00:35 -0000 1.14
+++ ifq.h 14 Nov 2017 00:22:13 -0000
@@ -379,6 +379,7 @@ struct ifq_ops {
 void ifq_init(struct ifqueue *, struct ifnet *, unsigned int);
 void ifq_attach(struct ifqueue *, const struct ifq_ops *, void *);
 void ifq_destroy(struct ifqueue *);
+void ifq_add_data(struct ifqueue *, struct if_data *);
 int ifq_enqueue(struct ifqueue *, struct mbuf *);
 void ifq_start(struct ifqueue *);
 struct mbuf *ifq_deq_begin(struct ifqueue *);