netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: netdev@vger.kernel.org
Cc: Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCH net-next 09/14] nfp: use AND instead of modulo to get ring indexes
Date: Mon, 31 Oct 2016 20:43:17 +0000	[thread overview]
Message-ID: <1477946602-19644-10-git-send-email-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <1477946602-19644-1-git-send-email-jakub.kicinski@netronome.com>

We already force ring sizes to be power of 2 so replace
modulo operations with AND (size - 1) in index calculations.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index b43d2dbae368..7225ab61a120 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -778,7 +778,7 @@ static int nfp_net_tx(struct sk_buff *skb, struct net_device *netdev)
 	if (dma_mapping_error(&nn->pdev->dev, dma_addr))
 		goto err_free;
 
-	wr_idx = tx_ring->wr_p % tx_ring->cnt;
+	wr_idx = tx_ring->wr_p & (tx_ring->cnt - 1);
 
 	/* Stash the soft descriptor of the head then initialize it */
 	txbuf = &tx_ring->txbufs[wr_idx];
@@ -822,7 +822,7 @@ static int nfp_net_tx(struct sk_buff *skb, struct net_device *netdev)
 			if (dma_mapping_error(&nn->pdev->dev, dma_addr))
 				goto err_unmap;
 
-			wr_idx = (wr_idx + 1) % tx_ring->cnt;
+			wr_idx = (wr_idx + 1) & (tx_ring->cnt - 1);
 			tx_ring->txbufs[wr_idx].skb = skb;
 			tx_ring->txbufs[wr_idx].dma_addr = dma_addr;
 			tx_ring->txbufs[wr_idx].fidx = f;
@@ -917,7 +917,7 @@ static void nfp_net_tx_complete(struct nfp_net_tx_ring *tx_ring)
 		todo = qcp_rd_p + tx_ring->cnt - tx_ring->qcp_rd_p;
 
 	while (todo--) {
-		idx = tx_ring->rd_p % tx_ring->cnt;
+		idx = tx_ring->rd_p & (tx_ring->cnt - 1);
 		tx_ring->rd_p++;
 
 		skb = tx_ring->txbufs[idx].skb;
@@ -992,7 +992,7 @@ static void nfp_net_tx_complete(struct nfp_net_tx_ring *tx_ring)
 		int nr_frags, fidx, idx;
 		struct sk_buff *skb;
 
-		idx = tx_ring->rd_p % tx_ring->cnt;
+		idx = tx_ring->rd_p & (tx_ring->cnt - 1);
 		skb = tx_ring->txbufs[idx].skb;
 		nr_frags = skb_shinfo(skb)->nr_frags;
 		fidx = tx_ring->txbufs[idx].fidx;
@@ -1129,7 +1129,7 @@ static void nfp_net_rx_give_one(struct nfp_net_rx_ring *rx_ring,
 {
 	unsigned int wr_idx;
 
-	wr_idx = rx_ring->wr_p % rx_ring->cnt;
+	wr_idx = rx_ring->wr_p & (rx_ring->cnt - 1);
 
 	/* Stash SKB and DMA address away */
 	rx_ring->rxbufs[wr_idx].frag = frag;
@@ -1164,7 +1164,7 @@ static void nfp_net_rx_ring_reset(struct nfp_net_rx_ring *rx_ring)
 	unsigned int wr_idx, last_idx;
 
 	/* Move the empty entry to the end of the list */
-	wr_idx = rx_ring->wr_p % rx_ring->cnt;
+	wr_idx = rx_ring->wr_p & (rx_ring->cnt - 1);
 	last_idx = rx_ring->cnt - 1;
 	rx_ring->rxbufs[wr_idx].dma_addr = rx_ring->rxbufs[last_idx].dma_addr;
 	rx_ring->rxbufs[wr_idx].frag = rx_ring->rxbufs[last_idx].frag;
@@ -1413,7 +1413,7 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget)
 	int idx;
 
 	while (pkts_polled < budget) {
-		idx = rx_ring->rd_p % rx_ring->cnt;
+		idx = rx_ring->rd_p & (rx_ring->cnt - 1);
 
 		rxd = &rx_ring->rxds[idx];
 		if (!(rxd->rxd.meta_len_dd & PCIE_DESC_RX_DD))
-- 
1.9.1

  parent reply	other threads:[~2016-10-31 20:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-31 20:43 [PATCH net-next 00/14] cleanups and RX path rewrite Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 01/14] nfp: simplify nfp_net_poll() Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 02/14] nfp: remove support for nfp3200 Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 03/14] nfp: remove unnecessary call to ether_setup() Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 04/14] nfp: remove inline attributes and dead code Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 05/14] nfp: centralize the buffer size calculation Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 06/14] nfp: add buffer drop/recycle helper for RX Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 07/14] nfp: use alloc_frag() and build_skb() Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 08/14] nfp: add separate buffer allocation function for napi Jakub Kicinski
2016-10-31 20:43 ` Jakub Kicinski [this message]
2016-10-31 20:43 ` [PATCH net-next 10/14] nfp: create separate define for max number of vectors Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 11/14] nfp: use unsigned int for vector/ring counts Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 12/14] nfp: remove nfp_net_irqs_wanted() Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 13/14] nfp: replace num_irqs with max_r_vecs Jakub Kicinski
2016-10-31 20:43 ` [PATCH net-next 14/14] nfp: bring back support for different ring counts Jakub Kicinski
2016-11-01 15:05 ` [PATCH net-next 00/14] cleanups and RX path rewrite David Miller

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=1477946602-19644-10-git-send-email-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.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).