Skip to content

Commit

Permalink
forcedeth: optimize the xmit/rx with unlikely
Browse files Browse the repository at this point in the history
In the xmit/rx fastpath, the function dma_map_single rarely fails.
Therefore, add an unlikely() optimization to this error check
conditional.

Signed-off-by: Zhu Yanjun <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Zhu Yanjun authored and davem330 committed Sep 24, 2017
1 parent 1f8d31d commit 39e50d9
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions drivers/net/ethernet/nvidia/forcedeth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1817,8 +1817,8 @@ static int nv_alloc_rx(struct net_device *dev)
skb->data,
skb_tailroom(skb),
DMA_FROM_DEVICE);
if (dma_mapping_error(&np->pci_dev->dev,
np->put_rx_ctx->dma)) {
if (unlikely(dma_mapping_error(&np->pci_dev->dev,
np->put_rx_ctx->dma))) {
kfree_skb(skb);
goto packet_dropped;
}
Expand Down Expand Up @@ -1858,8 +1858,8 @@ static int nv_alloc_rx_optimized(struct net_device *dev)
skb->data,
skb_tailroom(skb),
DMA_FROM_DEVICE);
if (dma_mapping_error(&np->pci_dev->dev,
np->put_rx_ctx->dma)) {
if (unlikely(dma_mapping_error(&np->pci_dev->dev,
np->put_rx_ctx->dma))) {
kfree_skb(skb);
goto packet_dropped;
}
Expand Down Expand Up @@ -2227,8 +2227,8 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
np->put_tx_ctx->dma = dma_map_single(&np->pci_dev->dev,
skb->data + offset, bcnt,
DMA_TO_DEVICE);
if (dma_mapping_error(&np->pci_dev->dev,
np->put_tx_ctx->dma)) {
if (unlikely(dma_mapping_error(&np->pci_dev->dev,
np->put_tx_ctx->dma))) {
/* on DMA mapping error - drop the packet */
dev_kfree_skb_any(skb);
u64_stats_update_begin(&np->swstats_tx_syncp);
Expand Down Expand Up @@ -2268,7 +2268,8 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
frag, offset,
bcnt,
DMA_TO_DEVICE);
if (dma_mapping_error(&np->pci_dev->dev, np->put_tx_ctx->dma)) {
if (unlikely(dma_mapping_error(&np->pci_dev->dev,
np->put_tx_ctx->dma))) {

/* Unwind the mapped fragments */
do {
Expand Down Expand Up @@ -2377,8 +2378,8 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
np->put_tx_ctx->dma = dma_map_single(&np->pci_dev->dev,
skb->data + offset, bcnt,
DMA_TO_DEVICE);
if (dma_mapping_error(&np->pci_dev->dev,
np->put_tx_ctx->dma)) {
if (unlikely(dma_mapping_error(&np->pci_dev->dev,
np->put_tx_ctx->dma))) {
/* on DMA mapping error - drop the packet */
dev_kfree_skb_any(skb);
u64_stats_update_begin(&np->swstats_tx_syncp);
Expand Down Expand Up @@ -2419,7 +2420,8 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
bcnt,
DMA_TO_DEVICE);

if (dma_mapping_error(&np->pci_dev->dev, np->put_tx_ctx->dma)) {
if (unlikely(dma_mapping_error(&np->pci_dev->dev,
np->put_tx_ctx->dma))) {

/* Unwind the mapped fragments */
do {
Expand Down Expand Up @@ -5075,8 +5077,8 @@ static int nv_loopback_test(struct net_device *dev)
test_dma_addr = dma_map_single(&np->pci_dev->dev, tx_skb->data,
skb_tailroom(tx_skb),
DMA_FROM_DEVICE);
if (dma_mapping_error(&np->pci_dev->dev,
test_dma_addr)) {
if (unlikely(dma_mapping_error(&np->pci_dev->dev,
test_dma_addr))) {
dev_kfree_skb_any(tx_skb);
goto out;
}
Expand Down

0 comments on commit 39e50d9

Please sign in to comment.