diff mbox

[ovs-dev,05/13] netdev-dpdk: Acquire dev->stats_lock only once.

Message ID 20161005012224.107729-6-diproiettod@vmware.com
State Accepted
Headers show

Commit Message

Daniele Di Proietto Oct. 5, 2016, 1:22 a.m. UTC
Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
---
 lib/netdev-dpdk.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

Comments

Ben Pfaff Oct. 12, 2016, 8:07 p.m. UTC | #1
On Tue, Oct 04, 2016 at 06:22:16PM -0700, Daniele Di Proietto wrote:
> Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>

Acked-by: Ben Pfaff <blp@ovn.org>
diff mbox

Patch

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index f3f0b27..fec3e68 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -1261,9 +1261,13 @@  netdev_dpdk_rxq_dealloc(struct netdev_rxq *rxq)
     rte_free(rx);
 }
 
-static inline void
+/* Tries to transmit 'pkts' to txq 'qid' of device 'dev'.  Takes ownership of
+ * 'pkts', even in case of failure.
+ *
+ * Returns the number of packets that weren't transmitted. */
+static inline int
 netdev_dpdk_eth_tx_burst(struct netdev_dpdk *dev, int qid,
-                             struct rte_mbuf **pkts, int cnt)
+                         struct rte_mbuf **pkts, int cnt)
 {
     uint32_t nb_tx = 0;
 
@@ -1279,17 +1283,16 @@  netdev_dpdk_eth_tx_burst(struct netdev_dpdk *dev, int qid,
     }
 
     if (OVS_UNLIKELY(nb_tx != cnt)) {
-        /* free buffers, which we couldn't transmit, one at a time (each
+        /* Free buffers, which we couldn't transmit, one at a time (each
          * packet could come from a different mempool) */
         int i;
 
         for (i = nb_tx; i < cnt; i++) {
             rte_pktmbuf_free(pkts[i]);
         }
-        rte_spinlock_lock(&dev->stats_lock);
-        dev->stats.tx_dropped += cnt - nb_tx;
-        rte_spinlock_unlock(&dev->stats_lock);
     }
+
+    return cnt - nb_tx;
 }
 
 static inline bool
@@ -1666,7 +1669,7 @@  dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch)
         newcnt = netdev_dpdk_qos_run(dev, pkts, newcnt);
 
         dropped += qos_pkts - newcnt;
-        netdev_dpdk_eth_tx_burst(dev, qid, pkts, newcnt);
+        dropped += netdev_dpdk_eth_tx_burst(dev, qid, pkts, newcnt);
     }
 
     if (OVS_UNLIKELY(dropped)) {
@@ -1723,7 +1726,7 @@  netdev_dpdk_send__(struct netdev_dpdk *dev, int qid,
         cnt = netdev_dpdk_qos_run(dev, pkts, cnt);
         dropped = batch->count - cnt;
 
-        netdev_dpdk_eth_tx_burst(dev, qid, pkts, cnt);
+        dropped += netdev_dpdk_eth_tx_burst(dev, qid, pkts, cnt);
 
         if (OVS_UNLIKELY(dropped)) {
             rte_spinlock_lock(&dev->stats_lock);