Skip to content

Commit 730b3ab

Browse files
Jakub Kicinskidavem330
authored andcommitted
nfp: eliminate an if statement in calculation of completed frames
Given that our rings are always a power of 2, we can simplify the calculation of number of completed TX descriptors by using masking instead of if statement based on whether the index have wrapped or not. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4aa3b76 commit 730b3ab

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

drivers/net/ethernet/netronome/nfp/nfp_net_common.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,10 +940,7 @@ static void nfp_net_tx_complete(struct nfp_net_tx_ring *tx_ring)
940940
if (qcp_rd_p == tx_ring->qcp_rd_p)
941941
return;
942942

943-
if (qcp_rd_p > tx_ring->qcp_rd_p)
944-
todo = qcp_rd_p - tx_ring->qcp_rd_p;
945-
else
946-
todo = qcp_rd_p + tx_ring->cnt - tx_ring->qcp_rd_p;
943+
todo = D_IDX(tx_ring, qcp_rd_p + tx_ring->cnt - tx_ring->qcp_rd_p);
947944

948945
while (todo--) {
949946
idx = D_IDX(tx_ring, tx_ring->rd_p++);
@@ -1014,10 +1011,7 @@ static bool nfp_net_xdp_complete(struct nfp_net_tx_ring *tx_ring)
10141011
if (qcp_rd_p == tx_ring->qcp_rd_p)
10151012
return true;
10161013

1017-
if (qcp_rd_p > tx_ring->qcp_rd_p)
1018-
todo = qcp_rd_p - tx_ring->qcp_rd_p;
1019-
else
1020-
todo = qcp_rd_p + tx_ring->cnt - tx_ring->qcp_rd_p;
1014+
todo = D_IDX(tx_ring, qcp_rd_p + tx_ring->cnt - tx_ring->qcp_rd_p);
10211015

10221016
done_all = todo <= NFP_NET_XDP_MAX_COMPLETE;
10231017
todo = min(todo, NFP_NET_XDP_MAX_COMPLETE);

0 commit comments

Comments
 (0)