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

r8169: improve rtl_tx

We can simplify the for() condition and eliminate variable tx_left.
The change also considers that tp->cur_tx may be incremented by a
racing rtl8169_start_xmit().
In addition replace the write to tp->dirty_tx and the following
smp_mb() with an equivalent call to smp_store_mb(). This implicitly
adds a WRITE_ONCE() to the write.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://lore.kernel.org/r/c2e19e5e-3d3f-d663-af32-13c3374f5def@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Heiner Kallweit and committed by
Jakub Kicinski
ca1ab89c 95f3c545

+3 -4
+3 -4
drivers/net/ethernet/realtek/r8169_main.c
··· 4362 4362 static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp, 4363 4363 int budget) 4364 4364 { 4365 - unsigned int dirty_tx, tx_left, bytes_compl = 0, pkts_compl = 0; 4365 + unsigned int dirty_tx, bytes_compl = 0, pkts_compl = 0; 4366 4366 4367 4367 dirty_tx = tp->dirty_tx; 4368 4368 4369 - for (tx_left = READ_ONCE(tp->cur_tx) - dirty_tx; tx_left; tx_left--) { 4369 + while (READ_ONCE(tp->cur_tx) != dirty_tx) { 4370 4370 unsigned int entry = dirty_tx % NUM_TX_DESC; 4371 4371 struct sk_buff *skb = tp->tx_skb[entry].skb; 4372 4372 u32 status; ··· 4389 4389 netdev_completed_queue(dev, pkts_compl, bytes_compl); 4390 4390 dev_sw_netstats_tx_add(dev, pkts_compl, bytes_compl); 4391 4391 4392 - tp->dirty_tx = dirty_tx; 4393 4392 /* Sync with rtl8169_start_xmit: 4394 4393 * - publish dirty_tx ring index (write barrier) 4395 4394 * - refresh cur_tx ring index and queue status (read barrier) ··· 4396 4397 * a racing xmit thread can only have a right view of the 4397 4398 * ring status. 4398 4399 */ 4399 - smp_mb(); 4400 + smp_store_mb(tp->dirty_tx, dirty_tx); 4400 4401 if (netif_queue_stopped(dev) && 4401 4402 rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) { 4402 4403 netif_wake_queue(dev);