r8169: improve memory barriers
Heiner Kallweit
maintainercover r8169: improve memory barriers
This series includes improvements for (too heavy) memory barriers. Tested on x86-64 with RTL8168g chip version.
Heiner Kallweit (4):
r8169: use smp_store_mb in rtl_tx
r8169: change wmb to dma-wmb in rtl8169_start_xmit
r8169: replace dma_rmb with READ_ONCE in rtl_rx
r8169: use WRITE_ONCE instead of dma_wmb in rtl8169_mark_to_asic
drivers/net/ethernet/realtek/r8169_main.c | 26 ++++++++--------------- 1 file changed, 9 insertions(+), 17 deletions(-)
Signature · 1 line
2.26.1
Heiner Kallweit
maintainerPATCH 1/4 r8169: use smp_store_mb in rtl_tx
Use helper smp_store_mb() instead of open-coding the functionality.
--- drivers/net/ethernet/realtek/r8169_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +1 -2
@@ -4438,7 +4438,6 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp, tp->tx_stats.bytes += bytes_compl;u64_stats_update_end (&tp->tx_stats.syncp); - tp->dirty_tx = dirty_tx;/* Sync with rtl8169_start_xmit: * - publish dirty_tx ring index (write barrier) * - refresh cur_tx ring index and queue status (read barrier)
@@ -4446,7 +4445,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,* a racing xmit thread can only have a right view of the * ring status. */ -smp_mb (); +smp_store_mb (tp->dirty_tx, dirty_tx);if (netif_queue_stopped (dev) &&rtl_tx_slots_avail (tp,MAX_SKB_FRAGS )) {netif_wake_queue (dev);
Signature · 1 line
2.26.1
Heiner Kallweit
maintainerPATCH 2/4 r8169: change wmb to dma_wmb in rtl8169_start_xmit
In reply to Heiner KallweitIt's the typical dma_wmb() use case to finish descriptor writes before ringing the device doorbell. Therefore switch to this lighter barrier.
--- drivers/net/ethernet/realtek/r8169_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +1 -1
@@ -4259,7 +4259,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, txd_first->opts1 |=cpu_to_le32 (DescOwn | FirstFrag);/* Force all memory writes to complete before notifying device */ -wmb (); +dma_wmb (); tp->cur_tx += frags +1 ;
Signature · 1 line
2.26.1
Heiner Kallweit
maintainerPATCH 3/4 r8169: replace dma_rmb with READ_ONCE in rtl_rx
In reply to Heiner KallweitWe want to ensure that desc->opts1 is read before desc->opts2. This doesn't require a full compiler barrier. READ_ONCE provides the ordering guarantee we need.
--- drivers/net/ethernet/realtek/r8169_main.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +3 -8
@@ -1548,7 +1548,7 @@ static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb)static void rtl8169_rx_vlan_tag (struct RxDesc *desc,struct sk_buff *skb) { -u32 opts2 =le32_to_cpu (desc->opts2); +u32 opts2 =le32_to_cpu (READ_ONCE (desc->opts2));if (opts2 & RxVlanTag)__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ),swab16 (opts2 &0xffff ));
@@ -4490,16 +4490,11 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budgetstruct RxDesc *desc = tp->RxDescArray + entry;u32 status; - status =le32_to_cpu (desc->opts1); +/* Use READ_ONCE to order descriptor field reads */ + status =le32_to_cpu (READ_ONCE (desc->opts1));if (status & DescOwn)break ; -/* This barrier is needed to keep us from reading -* any other fields out of the Rx descriptor until -* we know the status of DescOwn -*/ -dma_rmb (); -if (unlikely (status & RxRES)) {netif_info (tp, rx_err, dev,"Rx ERROR. status = %08x\n" , status);
Signature · 1 line
2.26.1
Heiner Kallweit
maintainerPATCH 4/4 r8169: use WRITE_ONCE instead of dma_wmb in rtl8169_mark_to_asic
In reply to Heiner KallweitWe want to ensure that desc->opts1 is written as last descriptor field. This doesn't require a full compiler barrier, WRITE_ONCE provides the ordering guarantee we need.
--- drivers/net/ethernet/realtek/r8169_main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +4 -6
@@ -3892,11 +3892,9 @@ static inline void rtl8169_mark_to_asic(struct RxDesc *desc) {u32 eor =le32_to_cpu (desc->opts1) & RingEnd; - desc->opts2 =0 ; -/* Force memory writes to complete before releasing descriptor */ -dma_wmb (); - - desc->opts1 =cpu_to_le32 (DescOwn | eor |R8169_RX_BUF_SIZE ); +/* Ensure ordering of writes */ +WRITE_ONCE (desc->opts2,0 ); +WRITE_ONCE (desc->opts1,cpu_to_le32 (DescOwn | eor |R8169_RX_BUF_SIZE )); } static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
@@ -3919,7 +3917,7 @@ static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp,return NULL ; } - desc->addr =cpu_to_le64 (mapping); +WRITE_ONCE (desc->addr,cpu_to_le64 (mapping));rtl8169_mark_to_asic (desc);return data;
Signature · 1 line
2.26.1
Heiner Kallweit
maintainerQuoted 6 lines · Heiner Kallweit
This series includes improvements for (too heavy) memory barriers. Tested on x86-64 with RTL8168g chip version.
Heiner Kallweit (4):
r8169: usesmp_store_mbinrtl_tx
r8169: change wmb todma_wmbinrtl8169_start_xmit
I think I'll have to drip this patch from the series. These Realtek chips are also used on non-x86 platforms, and these platforms may not be coherent. I'll send a v2.
Quoted 6 lines
r8169: replace
dma_rmbwithREAD_ONCEinrtl_rx
r8169: useWRITE_ONCEinstead ofdma_wmbinrtl8169_mark_to_asicdrivers/net/ethernet/realtek/r8169_main.c | 26 ++++++++--------------- 1 file changed, 9 insertions(+), 17 deletions(-)