Skip to content

Commit ca1ab89

Browse files
hkallweitkuba-moo
authored andcommitted
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>
1 parent 95f3c54 commit ca1ab89

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎drivers/net/ethernet/realtek/r8169_main.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,11 +4362,11 @@ static void rtl8169_pcierr_interrupt(struct net_device *dev)
43624362
static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,
43634363
int budget)
43644364
{
4365-
unsigned int dirty_tx, tx_left, bytes_compl = 0, pkts_compl = 0;
4365+
unsigned int dirty_tx, bytes_compl = 0, pkts_compl = 0;
43664366

43674367
dirty_tx = tp->dirty_tx;
43684368

4369-
for (tx_left = READ_ONCE(tp->cur_tx) - dirty_tx; tx_left; tx_left--) {
4369+
while (READ_ONCE(tp->cur_tx) != dirty_tx) {
43704370
unsigned int entry = dirty_tx % NUM_TX_DESC;
43714371
struct sk_buff *skb = tp->tx_skb[entry].skb;
43724372
u32 status;
@@ -4389,15 +4389,14 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,
43894389
netdev_completed_queue(dev, pkts_compl, bytes_compl);
43904390
dev_sw_netstats_tx_add(dev, pkts_compl, bytes_compl);
43914391

4392-
tp->dirty_tx = dirty_tx;
43934392
/* Sync with rtl8169_start_xmit:
43944393
* - publish dirty_tx ring index (write barrier)
43954394
* - refresh cur_tx ring index and queue status (read barrier)
43964395
* May the current thread miss the stopped queue condition,
43974396
* a racing xmit thread can only have a right view of the
43984397
* ring status.
43994398
*/
4400-
smp_mb();
4399+
smp_store_mb(tp->dirty_tx, dirty_tx);
44014400
if (netif_queue_stopped(dev) &&
44024401
rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) {
44034402
netif_wake_queue(dev);

0 commit comments

Comments
 (0)