DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 5/5] ixgbe: remove awkward typecasts from ixgbe SSE PMD
Date: Thu, 23 Jul 2015 17:05:06 +0100	[thread overview]
Message-ID: <1437667506-3890-6-git-send-email-bruce.richardson@intel.com> (raw)
In-Reply-To: <1437667506-3890-1-git-send-email-bruce.richardson@intel.com>

The vector/SSE pmd used a different element type for the tx queue sw_ring
entries. This led to lots of typecasts in the code which required specific
use of bracketing, leading to subtle errors.
For example, in the original code:
	txe = (struct ixgbe_tx_entry_v *)&txq->sw_ring[i];
instead needs to be written as:
	txe = &((struct ixgbe_tx_entry_v *)txq->sw_ring)[i];

We can eliminate this problem, by having two software ring pointers in the
structure for the two different element types.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/net/ixgbe/ixgbe_rxtx.h     |  5 ++++-
 drivers/net/ixgbe/ixgbe_rxtx_vec.c | 18 ++++++++----------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ixgbe/ixgbe_rxtx.h b/drivers/net/ixgbe/ixgbe_rxtx.h
index 2ed6816..36388ec 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.h
+++ b/drivers/net/ixgbe/ixgbe_rxtx.h
@@ -192,7 +192,10 @@ struct ixgbe_tx_queue {
 	/** TX ring virtual address. */
 	volatile union ixgbe_adv_tx_desc *tx_ring;
 	uint64_t            tx_ring_phys_addr; /**< TX ring DMA address. */
-	struct ixgbe_tx_entry *sw_ring;      /**< virtual address of SW ring. */
+	union {
+		struct ixgbe_tx_entry *sw_ring; /**< virtual address of SW ring. */
+		struct ixgbe_tx_entry_v *sw_ring_v; /**< address of SW ring for vector PMD */
+	};
 	volatile uint32_t   *tdt_reg_addr; /**< Address of TDT register. */
 	uint16_t            nb_tx_desc;    /**< number of TX descriptors. */
 	uint16_t            tx_tail;       /**< current value of TDT reg. */
diff --git a/drivers/net/ixgbe/ixgbe_rxtx_vec.c b/drivers/net/ixgbe/ixgbe_rxtx_vec.c
index 7d57b63..0c659b7 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx_vec.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx_vec.c
@@ -608,8 +608,7 @@ ixgbe_tx_free_bufs(struct ixgbe_tx_queue *txq)
 	 * first buffer to free from S/W ring is at index
 	 * tx_next_dd - (tx_rs_thresh-1)
 	 */
-	txep = &((struct ixgbe_tx_entry_v *)txq->sw_ring)[txq->tx_next_dd -
-			(n - 1)];
+	txep = &txq->sw_ring_v[txq->tx_next_dd - (n - 1)];
 	m = __rte_pktmbuf_prefree_seg(txep[0].mbuf);
 	if (likely(m != NULL)) {
 		free[0] = m;
@@ -678,7 +677,7 @@ ixgbe_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
 
 	tx_id = txq->tx_tail;
 	txdp = &txq->tx_ring[tx_id];
-	txep = &((struct ixgbe_tx_entry_v *)txq->sw_ring)[tx_id];
+	txep = &txq->sw_ring_v[tx_id];
 
 	txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
 
@@ -699,7 +698,7 @@ ixgbe_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
 
 		/* avoid reach the end of ring */
 		txdp = &(txq->tx_ring[tx_id]);
-		txep = &(((struct ixgbe_tx_entry_v *)txq->sw_ring)[tx_id]);
+		txep = &txq->sw_ring_v[tx_id];
 	}
 
 	tx_backlog_entry(txep, tx_pkts, nb_commit);
@@ -735,14 +734,14 @@ ixgbe_tx_queue_release_mbufs_vec(struct ixgbe_tx_queue *txq)
 	for (i = txq->tx_next_dd - (txq->tx_rs_thresh - 1);
 	     i != txq->tx_tail;
 	     i = (i + 1) & max_desc) {
-		txe = &((struct ixgbe_tx_entry_v *)txq->sw_ring)[i];
+		txe = &txq->sw_ring_v[i];
 		rte_pktmbuf_free_seg(txe->mbuf);
 	}
 	txq->nb_tx_free = max_desc;
 
 	/* reset tx_entry */
 	for (i = 0; i < txq->nb_tx_desc; i++) {
-		txe = (struct ixgbe_tx_entry_v *)&txq->sw_ring[i];
+		txe = &txq->sw_ring_v[i];
 		txe->mbuf = NULL;
 	}
 }
@@ -781,7 +780,7 @@ static void __attribute__((cold))
 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
 {
 	static const union ixgbe_adv_tx_desc zeroed_desc = {{0}};
-	struct ixgbe_tx_entry_v *txe = (struct ixgbe_tx_entry_v *)txq->sw_ring;
+	struct ixgbe_tx_entry_v *txe = txq->sw_ring_v;
 	uint16_t i;
 
 	/* Zero out HW ring memory */
@@ -838,12 +837,11 @@ ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
 int __attribute__((cold))
 ixgbe_txq_vec_setup(struct ixgbe_tx_queue *txq)
 {
-	if (txq->sw_ring == NULL)
+	if (txq->sw_ring_v == NULL)
 		return -1;
 
 	/* leave the first one for overflow */
-	txq->sw_ring = (struct ixgbe_tx_entry *)
-		((struct ixgbe_tx_entry_v *)txq->sw_ring + 1);
+	txq->sw_ring_v = txq->sw_ring_v + 1;
 	txq->ops = &vec_txq_ops;
 
 	return 0;
-- 
1.8.3.1

      parent reply	other threads:[~2015-07-23 16:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23 16:05 [dpdk-dev] [PATCH 0/5] ixgbe: fix mbuf release on RX and TX Bruce Richardson
2015-07-23 16:05 ` [dpdk-dev] [PATCH 1/5] Revert "ixgbe: check mbuf refcnt when clearing a ring" Bruce Richardson
2015-07-24 13:58   ` [dpdk-dev] [PATCHv2 0/5] ixgbe: fix mbuf release on RX and TX Konstantin Ananyev
2015-07-24 13:58     ` [dpdk-dev] [PATCHv2 1/5] Revert "ixgbe: check mbuf refcnt when clearing a ring" Konstantin Ananyev
2015-07-24 15:30       ` Zhang, Helin
2015-07-24 13:58     ` [dpdk-dev] [PATCHv2 2/5] ixgbe: fix comments on rx_queue fields Konstantin Ananyev
2015-07-24 13:58     ` [dpdk-dev] [PATCHv2 3/5] ixgbe: fix bug on release of mbufs from queue Konstantin Ananyev
2015-07-24 13:58     ` [dpdk-dev] [PATCHv2 4/5] ixgbe: rename tx queue release function for consistency Konstantin Ananyev
2015-07-24 15:32       ` Zhang, Helin
2015-07-24 13:58     ` [dpdk-dev] [PATCHv2 5/5] ixgbe: remove awkward typecasts from ixgbe SSE PMD Konstantin Ananyev
2015-07-26  8:48     ` [dpdk-dev] [PATCHv2 0/5] ixgbe: fix mbuf release on RX and TX Thomas Monjalon
2015-07-23 16:05 ` [dpdk-dev] [PATCH 2/5] ixgbe: fix comments on rx_queue fields Bruce Richardson
2015-07-23 16:05 ` [dpdk-dev] [PATCH 3/5] ixgbe: fix bug on release of mbufs from queue Bruce Richardson
2015-07-23 16:05 ` [dpdk-dev] [PATCH 4/5] ixgbe: rename tx queue release function for consistency Bruce Richardson
2015-07-23 16:05 ` Bruce Richardson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1437667506-3890-6-git-send-email-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).