netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
	David Miller <davem@davemloft.net>,
	Paolo Abeni <pabeni@redhat.com>,
	Eric Dumazet <edumazet@google.com>,
	Realtek linux nic maintainers <nic_swsd@realtek.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next v2 2/3] r8169: use new macro netif_subqueue_maybe_stop in rtl8169_start_xmit
Date: Sun, 16 Apr 2023 13:20:58 +0300	[thread overview]
Message-ID: <20230416102058.GC15386@unreal> (raw)
In-Reply-To: <69c2eec2-d82c-290a-d6ce-fba64afb32c6@gmail.com>

On Sat, Apr 15, 2023 at 09:22:11AM +0200, Heiner Kallweit wrote:
> Use 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

Please put changelog under "---" markup, below tags section.

Thanks

> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/ethernet/realtek/r8169_main.c | 39 +++++++----------------
>  1 file changed, 11 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index 9f8357bbc..fff44d46b 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -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
> -- 
> 2.40.0
> 
> 

  reply	other threads:[~2023-04-16 10:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-15  7:18 [PATCH net-next v2 0/3] r8169: use new macros from netdev_queues.h Heiner Kallweit
2023-04-15  7:20 ` [PATCH net-next v2 1/3] net: add macro netif_subqueue_completed_wake Heiner Kallweit
2023-04-15  7:22 ` [PATCH net-next v2 2/3] r8169: use new macro netif_subqueue_maybe_stop in rtl8169_start_xmit Heiner Kallweit
2023-04-16 10:20   ` Leon Romanovsky [this message]
2023-04-16 11:33     ` Heiner Kallweit
2023-04-16 13:24       ` Leon Romanovsky
2023-04-15  7:23 ` [PATCH net-next v2 3/3] r8169: use new macro netif_subqueue_completed_wake in the tx cleanup path Heiner Kallweit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230416102058.GC15386@unreal \
    --to=leon@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).