From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 7F8495963 for ; Tue, 19 Aug 2014 15:48:38 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 19 Aug 2014 06:46:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,894,1400050800"; d="scan'208";a="590206519" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 19 Aug 2014 06:52:04 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s7JDq3RO002079; Tue, 19 Aug 2014 14:52:03 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id s7JDq3I4002922; Tue, 19 Aug 2014 14:52:03 +0100 Received: (from dwdohert@localhost) by sivswdev02.ir.intel.com with id s7JDq3GT002918; Tue, 19 Aug 2014 14:52:03 +0100 From: Declan Doherty To: dev@dpdk.org Date: Tue, 19 Aug 2014 14:51:51 +0100 Message-Id: <1408456313-28812-5-git-send-email-declan.doherty@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1408456313-28812-1-git-send-email-declan.doherty@intel.com> References: <1408456313-28812-1-git-send-email-declan.doherty@intel.com> Subject: [dpdk-dev] [PATCH 4/6] bond: free mbufs if transmission fails in bonding tx_burst functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Aug 2014 13:48:40 -0000 Fixing a number of corner cases that if transmission failed on slave devices then this could lead to leaked mbufs Signed-off-by: Declan Doherty --- app/test/test_link_bonding.c | 4 +- lib/librte_pmd_bond/rte_eth_bond_pmd.c | 46 +++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c index 02823b6..3c265ee 100644 --- a/app/test/test_link_bonding.c +++ b/app/test/test_link_bonding.c @@ -3415,7 +3415,7 @@ test_broadcast_tx_burst(void) /* Send burst on bonded port */ nb_tx = rte_eth_tx_burst(test_params->bonded_port_id, 0, pkts_burst, burst_size); - if (nb_tx != burst_size * test_params->bonded_slave_count) { + if (nb_tx != burst_size) { printf("Bonded Port (%d) rx burst failed, packets transmitted value (%u) not as expected (%d)\n", test_params->bonded_port_id, nb_tx, burst_size); @@ -3770,7 +3770,7 @@ test_broadcast_verify_slave_link_status_change_behaviour(void) } if (rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt_burst[0][0], - burst_size) != (burst_size * slave_count)) { + burst_size) != burst_size) { printf("rte_eth_tx_burst failed\n"); return -1; } diff --git a/lib/librte_pmd_bond/rte_eth_bond_pmd.c b/lib/librte_pmd_bond/rte_eth_bond_pmd.c index 70123fc..ae9726e 100644 --- a/lib/librte_pmd_bond/rte_eth_bond_pmd.c +++ b/lib/librte_pmd_bond/rte_eth_bond_pmd.c @@ -101,7 +101,7 @@ bond_ethdev_tx_burst_round_robin(void *queue, struct rte_mbuf **bufs, uint8_t num_of_slaves; uint8_t slaves[RTE_MAX_ETHPORTS]; - uint16_t num_tx_total = 0; + uint16_t num_tx_total = 0, num_tx_slave; static int slave_idx = 0; int i, cs_idx = 0; @@ -130,9 +130,17 @@ bond_ethdev_tx_burst_round_robin(void *queue, struct rte_mbuf **bufs, /* Send packet burst on each slave device */ for (i = 0; i < num_of_slaves; i++) - if (slave_nb_pkts[i] > 0) - num_tx_total += rte_eth_tx_burst(slaves[i], + if (slave_nb_pkts[i] > 0) { + num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id, slave_bufs[i], slave_nb_pkts[i]); + num_tx_total += num_tx_slave; + + /* if tx burst fails, free unsent mbufs */ + while (unlikely(num_tx_slave < slave_nb_pkts[i])) { + rte_pktmbuf_free(slave_bufs[i][num_tx_slave]); + num_tx_slave++; + } + } return num_tx_total; } @@ -283,7 +291,7 @@ bond_ethdev_tx_burst_balance(void *queue, struct rte_mbuf **bufs, uint8_t num_of_slaves; uint8_t slaves[RTE_MAX_ETHPORTS]; - uint16_t num_tx_total = 0; + uint16_t num_tx_total = 0, num_tx_slave = 0; int i, op_slave_id; @@ -315,11 +323,19 @@ bond_ethdev_tx_burst_balance(void *queue, struct rte_mbuf **bufs, /* Send packet burst on each slave device */ for (i = 0; i < num_of_slaves; i++) { if (slave_nb_pkts[i] > 0) { - num_tx_total += rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id, + num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id, slave_bufs[i], slave_nb_pkts[i]); + num_tx_total += num_tx_slave; + + /* if tx burst fails, free unsent mbufs */ + while (unlikely(num_tx_slave < slave_nb_pkts[i])) { + rte_pktmbuf_free(slave_bufs[i][num_tx_slave]); + num_tx_slave++; + } } } + return num_tx_total; } @@ -333,7 +349,7 @@ bond_ethdev_tx_burst_broadcast(void *queue, struct rte_mbuf **bufs, uint8_t num_of_slaves; uint8_t slaves[RTE_MAX_ETHPORTS]; - uint16_t num_tx_total = 0; + uint16_t num_tx_slave = 0, max_tx_pkts = 0; int i; @@ -354,11 +370,21 @@ bond_ethdev_tx_burst_broadcast(void *queue, struct rte_mbuf **bufs, rte_mbuf_refcnt_update(bufs[i], num_of_slaves - 1); /* Transmit burst on each active slave */ - for (i = 0; i < num_of_slaves; i++) - num_tx_total += rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id, - bufs, nb_pkts); + for (i = 0; i < num_of_slaves; i++) { + num_tx_slave = rte_eth_tx_burst(slaves[i], bd_tx_q->queue_id, + bufs, nb_pkts); - return num_tx_total; + if (max_tx_pkts < num_tx_slave) + max_tx_pkts = num_tx_slave; + + /* if tx burst fails, free unsent mbufs */ + while (unlikely(num_tx_slave < nb_pkts)) { + rte_pktmbuf_free(bufs[num_tx_slave]); + num_tx_slave++; + } + } + + return max_tx_pkts; } void -- 1.7.0.7