Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: add netdev_txq_bql_{enqueue, complete}_prefetchw() helpers

Add two helpers so that drivers do not have to care of BQL being
available or not.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Jim Davis <jim.epost@gmail.com>
Fixes: 29d40c903247 ("net/mlx4_en: Use prefetch in tx path")
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Eric Dumazet and committed by
David S. Miller
53511453 709c48b3

+32 -2
+3 -2
drivers/net/ethernet/mellanox/mlx4/en_tx.c
··· 392 392 if (!priv->port_up) 393 393 return true; 394 394 395 - prefetchw(&ring->tx_queue->dql.limit); 395 + netdev_txq_bql_complete_prefetchw(ring->tx_queue); 396 + 396 397 index = cons_index & size_mask; 397 398 cqe = mlx4_en_get_cqe(buf, index, priv->cqe_size) + factor; 398 399 last_nr_txbb = ACCESS_ONCE(ring->last_nr_txbb); ··· 738 737 vlan_tag = vlan_tx_tag_get(skb); 739 738 740 739 741 - prefetchw(&ring->tx_queue->dql); 740 + netdev_txq_bql_enqueue_prefetchw(ring->tx_queue); 742 741 743 742 /* Track current inflight packets for performance analysis */ 744 743 AVG_PERF_COUNTER(priv->pstats.inflight_avg,
+29
include/linux/netdevice.h
··· 30 30 #include <linux/bug.h> 31 31 #include <linux/delay.h> 32 32 #include <linux/atomic.h> 33 + #include <linux/prefetch.h> 33 34 #include <asm/cache.h> 34 35 #include <asm/byteorder.h> 35 36 ··· 2479 2478 netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue) 2480 2479 { 2481 2480 return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN; 2481 + } 2482 + 2483 + /** 2484 + * netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write 2485 + * @dev_queue: pointer to transmit queue 2486 + * 2487 + * BQL enabled drivers might use this helper in their ndo_start_xmit(), 2488 + * to give appropriate hint to the cpu. 2489 + */ 2490 + static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue) 2491 + { 2492 + #ifdef CONFIG_BQL 2493 + prefetchw(&dev_queue->dql.num_queued); 2494 + #endif 2495 + } 2496 + 2497 + /** 2498 + * netdev_txq_bql_complete_prefetchw - prefetch bql data for write 2499 + * @dev_queue: pointer to transmit queue 2500 + * 2501 + * BQL enabled drivers might use this helper in their TX completion path, 2502 + * to give appropriate hint to the cpu. 2503 + */ 2504 + static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue) 2505 + { 2506 + #ifdef CONFIG_BQL 2507 + prefetchw(&dev_queue->dql.limit); 2508 + #endif 2482 2509 } 2483 2510 2484 2511 static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,