r8169: use new macros from netdev_queues.h
Heiner Kallweit
maintainerv2 cover r8169: use new macros from netdev_queues.h
Add one missing subqueue version of the macros, and use the new macros in r8169 to simplify the code.
Heiner Kallweit (3):
net: add macro netif_subqueue_completed_wake
r8169: use new macro netif_subqueue_maybe_stop in rtl8169_start_xmit
r8169: use new macro netif_subqueue_completed_wake in the tx cleanup path
v2:
- patch 2: ring doorbell if queue was stopped
drivers/net/ethernet/realtek/r8169_main.c | 51 ++++++----------------- include/net/netdev_queues.h | 10 +++++ 2 files changed, 23 insertions(+), 38 deletions(-)
Signature · 1 line
2.40.0
Heiner Kallweit
maintainerPATCH v2 1/3 net: add macro netif_subqueue_completed_wake
Add netif_subqueue_completed_wake, complementing the subqueue versions netif_subqueue_try_stop and netif_subqueue_maybe_stop.
--- include/net/netdev_queues.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/net/netdev_queues.h +10 -0
@@ -160,4 +160,14 @@ netdev_txq_completed_mb(struct netdev_queue *dev_queue,netif_txq_maybe_stop (txq, get_desc, stop_thrs, start_thrs); \ }) +#define netif_subqueue_completed_wake (dev, idx, pkts, bytes, \ + get_desc, start_thrs) \ + ({ \ + struct netdev_queue *txq; \ + \ + txq = netdev_get_tx_queue(dev, idx); \ + netif_txq_completed_wake(txq, pkts, bytes, \ + get_desc, start_thrs); \ + }) +#endif
Signature · 1 line
2.40.0
Heiner Kallweit
maintainerPATCH v2 2/3 r8169: use new macro netif_subqueue_maybe_stop in rtl8169_start_xmit
In reply to Heiner KallweitUse new net core macro netif_subqueue_maybe_stop in the start_xmit path to simplify the code. Whilst at it, set the tx queue start threshold to twice the stop threshold. Before values were the same, resulting in stopping/starting the queue more often than needed.
v2:
- ring doorbell if queue was stopped
--- drivers/net/ethernet/realtek/r8169_main.c | 39 +++++++---------------- 1 file changed, 11 insertions(+), 28 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +11 -28
@@ -30,6 +30,7 @@#include <linux/ipv6.h> #include <asm/unaligned.h> #include <net/ip6_checksum.h> +#include <net/netdev_queues.h> #include "r8169.h" #include "r8169_firmware.h"
@@ -68,6 +69,8 @@#define NUM_RX_DESC 256/* Number of Rx descriptor registers */ #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))#define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) +#define R8169_TX_STOP_THRS (MAX_SKB_FRAGS + 1) +#define R8169_TX_START_THRS (2 * R8169_TX_STOP_THRS)#define OCP_STD_PHY_BASE 0xa400
@@ -4162,13 +4165,9 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,return true; } -static bool rtl_tx_slots_avail (struct rtl8169_private *tp) +static unsigned int rtl_tx_slots_avail (struct rtl8169_private *tp) { -unsigned int slots_avail =READ_ONCE (tp->dirty_tx) +NUM_TX_DESC - -READ_ONCE (tp->cur_tx); - -/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ -return slots_avail >MAX_SKB_FRAGS ; +return READ_ONCE (tp->dirty_tx) +NUM_TX_DESC -READ_ONCE (tp->cur_tx); }/* Versions RTL8102e and from RTL8168c onwards support csum_v2 */
@@ -4245,27 +4244,10 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,WRITE_ONCE (tp->cur_tx, tp->cur_tx + frags +1 ); - stop_queue = !rtl_tx_slots_avail (tp); -if (unlikely (stop_queue)) { -/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must -* not miss a ring update when it notices a stopped queue. -*/ -smp_wmb (); -netif_stop_queue (dev); -/* Sync with rtl_tx: -* - publish queue status and cur_tx ring index (write barrier) -* - refresh dirty_tx ring index (read barrier). -* May the current thread have a pessimistic view of the ring -* status and forget to wake up queue, a racing rtl_tx thread -* can't. -*/ -smp_mb__after_atomic (); -if (rtl_tx_slots_avail (tp)) -netif_start_queue (dev); - door_bell = true; - } - -if (door_bell) + stop_queue = !netif_subqueue_maybe_stop (dev,0 ,rtl_tx_slots_avail (tp), +R8169_TX_STOP_THRS , +R8169_TX_START_THRS ); +if (door_bell || stop_queue)rtl8169_doorbell (tp);return NETDEV_TX_OK ;
@@ -4400,7 +4382,8 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,* ring status. */ smp_store_mb (tp->dirty_tx, dirty_tx); -if (netif_queue_stopped (dev) &&rtl_tx_slots_avail (tp)) +if (netif_queue_stopped (dev) && +rtl_tx_slots_avail (tp) >=R8169_TX_START_THRS )netif_wake_queue (dev);/* * 8168 hack: TxPoll requests are lost when the Tx packets are
Signature · 1 line
2.40.0
Heiner Kallweit
maintainerPATCH v2 3/3 r8169: use new macro netif_subqueue_completed_wake in the tx cleanup path
In reply to Heiner KallweitUse new net core macro netif_subqueue_completed_wake to simplify the code of the tx cleanup path.
--- drivers/net/ethernet/realtek/r8169_main.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +4 -12
@@ -4371,20 +4371,12 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp, }if (tp->dirty_tx != dirty_tx) { -netdev_completed_queue (dev, pkts_compl, bytes_compl);dev_sw_netstats_tx_add (dev, pkts_compl, bytes_compl); +WRITE_ONCE (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) -* May the current thread miss the stopped queue condition, -* a racing xmit thread can only have a right view of the -* ring status. -*/ -smp_store_mb (tp->dirty_tx, dirty_tx); -if (netif_queue_stopped (dev) && -rtl_tx_slots_avail (tp) >=R8169_TX_START_THRS ) -netif_wake_queue (dev); +netif_subqueue_completed_wake (dev,0 , pkts_compl, bytes_compl, +rtl_tx_slots_avail (tp), +R8169_TX_START_THRS );/* * 8168 hack: TxPoll requests are lost when the Tx packets are * too close. Let's kick an extra TxPoll request when a burst
Signature · 1 line
2.40.0
Re: [PATCH net-next v2 2/3] r8169: use new macro netif_subqueue_maybe_stop in rtl8169_start_xmit
In reply to Heiner KallweitQuoted 7 lines · Heiner Kallweit
Use new net core macro
netif_subqueue_maybe_stopin thestart_xmitpath to simplify the code. Whilst at it, set the tx queue start threshold to twice the stop threshold. Before values were the same, resulting in stopping/starting the queue more often than needed.v2:
- ring doorbell if queue was stopped
Please put changelog under "---" markup, below tags section.
Thanks
Quoted 89 lines
Signed-off-by Heiner Kallweit <[email protected]>--- drivers/net/ethernet/realtek/r8169_main.c | 39 +++++++---------------- 1 file changed, 11 insertions(+), 28 deletions(-)drivers/net/ethernet/realtek/r8169_main.c +11
-28@@ -30,6 +30,7 @@#include <linux/ipv6.h> #include <asm/unaligned.h> #include <net/ip6_checksum.h> +#include <net/netdev_queues.h> #include "r8169.h" #include "r8169_firmware.h" @@ -68,6 +69,8 @@#define NUM_RX_DESC 256/* Number of Rx descriptor registers */ #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))#define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) +#define R8169_TX_STOP_THRS (MAX_SKB_FRAGS + 1) +#define R8169_TX_START_THRS (2 * R8169_TX_STOP_THRS)#define OCP_STD_PHY_BASE 0xa400@@ -4162,13 +4165,9 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,return true; } -static bool rtl_tx_slots_avail (struct rtl8169_private *tp) +static unsigned int rtl_tx_slots_avail (struct rtl8169_private *tp) { -unsigned int slots_avail =READ_ONCE (tp->dirty_tx) +NUM_TX_DESC - -READ_ONCE (tp->cur_tx); - -/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ -return slots_avail >MAX_SKB_FRAGS ; +return READ_ONCE (tp->dirty_tx) +NUM_TX_DESC -READ_ONCE (tp->cur_tx); }/* Versions RTL8102e and from RTL8168c onwards support csum_v2 */ @@ -4245,27 +4244,10 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,WRITE_ONCE (tp->cur_tx, tp->cur_tx + frags +1 ); - stop_queue = !rtl_tx_slots_avail (tp); -if (unlikely (stop_queue)) { -/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must -* not miss a ring update when it notices a stopped queue. -*/ -smp_wmb (); -netif_stop_queue (dev); -/* Sync with rtl_tx: -* - publish queue status and cur_tx ring index (write barrier) -* - refresh dirty_tx ring index (read barrier). -* May the current thread have a pessimistic view of the ring -* status and forget to wake up queue, a racing rtl_tx thread -* can't. -*/ -smp_mb__after_atomic (); -if (rtl_tx_slots_avail (tp)) -netif_start_queue (dev); - door_bell = true; - } - -if (door_bell) + stop_queue = !netif_subqueue_maybe_stop (dev,0 ,rtl_tx_slots_avail (tp), +R8169_TX_STOP_THRS , +R8169_TX_START_THRS ); +if (door_bell || stop_queue)rtl8169_doorbell (tp);return NETDEV_TX_OK ;@@ -4400,7 +4382,8 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,* ring status. */ smp_store_mb (tp->dirty_tx, dirty_tx); -if (netif_queue_stopped (dev) &&rtl_tx_slots_avail (tp)) +if (netif_queue_stopped (dev) && +rtl_tx_slots_avail (tp) >=R8169_TX_START_THRS )netif_wake_queue (dev);/* * 8168 hack: TxPoll requests are lost when the Tx packets are Signature · 1 line
2.40.0
Heiner Kallweit
maintainerRe: [PATCH net-next v2 2/3] r8169: use new macro netif_subqueue_maybe_stop in rtl8169_start_xmit
Quoted 11 lines · Leon Romanovsky
Quoted 7 lines · Heiner Kallweit
Use new net core macro
netif_subqueue_maybe_stopin thestart_xmitpath to simplify the code. Whilst at it, set the tx queue start threshold to twice the stop threshold. Before values were the same, resulting in stopping/starting the queue more often than needed.v2:
- ring doorbell if queue was stoppedPlease put changelog under "---" markup, below tags section.
I know that this would be the standard. IIRC Dave once requested to make the change log part of the commit message.
Quoted 2 lines
Thanks
Re: [PATCH net-next v2 2/3] r8169: use new macro netif_subqueue_maybe_stop in rtl8169_start_xmit
Quoted 7 lines · Heiner Kallweit
Quoted 6 lines · Leon Romanovsky
Quoted 5 lines · Heiner Kallweit
Use new net core macro
netif_subqueue_maybe_stopin thestart_xmitpath to simplify the code. Whilst at it, set the tx queue start threshold to twice the stop threshold. Before values were the same, resulting in stopping/starting the queue more often than needed.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
v2:
- ring doorbell if queue was stoppedPlease put changelog under "---" markup, below tags section.
I know that this would be the standard. IIRC Dave once requested to make the change log part of the commit message.
I can imagine how it was useful before lore.kernel.org appeared.
Thanks
Quoted 4 lines
Quoted 3 lines
Thanks