public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: Paul Barker <paul.barker.ct@bp.renesas.com>
Cc: Sergey Shtylyov <s.shtylyov@omp.ru>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [net-next RFC v3 1/7] net: ravb: Simplify poll & receive functions
Date: Mon, 15 Apr 2024 13:23:01 +0200	[thread overview]
Message-ID: <20240415112301.GF3156415@ragnatech.se> (raw)
In-Reply-To: <20240415094804.8016-2-paul.barker.ct@bp.renesas.com>

Hi Paul,

I really like this patch!

One nit below.

On 2024-04-15 10:47:58 +0100, Paul Barker wrote:
> We don't need to pass the work budget to ravb_rx() by reference, it's
> cleaner to pass this by value and return the amount of work done. This
> allows us to simplify the ravb_poll() function and use the common
> `work_done` variable name seen in other network drivers for consistency
> and ease of understanding.
> 
> This is a pure refactor and should not affect behaviour.
> 
> Signed-off-by: Paul Barker <paul.barker.ct@bp.renesas.com>
> ---
>  drivers/net/ethernet/renesas/ravb.h      |  2 +-
>  drivers/net/ethernet/renesas/ravb_main.c | 29 ++++++++++--------------
>  2 files changed, 13 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/net/ethernet/renesas/ravb.h b/drivers/net/ethernet/renesas/ravb.h
> index b48935ec7e28..71de2a7aa27c 100644
> --- a/drivers/net/ethernet/renesas/ravb.h
> +++ b/drivers/net/ethernet/renesas/ravb.h
> @@ -1039,7 +1039,7 @@ struct ravb_ptp {
>  };
>  
>  struct ravb_hw_info {
> -	bool (*receive)(struct net_device *ndev, int *quota, int q);
> +	int (*receive)(struct net_device *ndev, int budget, int q);
>  	void (*set_rate)(struct net_device *ndev);
>  	int (*set_feature)(struct net_device *ndev, netdev_features_t features);
>  	int (*dmac_init)(struct net_device *ndev);
> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
> index fd2679ce4e3d..33f8043143c1 100644
> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -759,7 +759,7 @@ static struct sk_buff *ravb_get_skb_gbeth(struct net_device *ndev, int entry,
>  }
>  
>  /* Packet receive function for Gigabit Ethernet */
> -static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
> +static int ravb_rx_gbeth(struct net_device *ndev, int budget, int q)
>  {
>  	struct ravb_private *priv = netdev_priv(ndev);
>  	const struct ravb_hw_info *info = priv->info;
> @@ -778,7 +778,7 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
>  	limit = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q];
>  	stats = &priv->stats[q];
>  
> -	for (i = 0; i < limit && rx_packets < *quota; i++, priv->cur_rx[q]++) {
> +	for (i = 0; i < limit && rx_packets < budget; i++, priv->cur_rx[q]++) {
>  		entry = priv->cur_rx[q] % priv->num_rx_ring[q];
>  		desc = &priv->rx_ring[q].desc[entry];
>  		if (desc->die_dt == DT_FEMPTY)
> @@ -881,13 +881,11 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
>  		desc->die_dt = DT_FEMPTY;
>  	}
>  
> -	stats->rx_packets += rx_packets;
> -	*quota -= rx_packets;
> -	return *quota == 0;
> +	return rx_packets;
>  }
>  
>  /* Packet receive function for Ethernet AVB */
> -static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q)
> +static int ravb_rx_rcar(struct net_device *ndev, int budget, int q)
>  {
>  	struct ravb_private *priv = netdev_priv(ndev);
>  	const struct ravb_hw_info *info = priv->info;
> @@ -904,7 +902,7 @@ static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q)
>  	int i;
>  
>  	limit = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q];
> -	for (i = 0; i < limit && rx_packets < *quota; i++, priv->cur_rx[q]++) {
> +	for (i = 0; i < limit && rx_packets < budget; i++, priv->cur_rx[q]++) {
>  		entry = priv->cur_rx[q] % priv->num_rx_ring[q];
>  		desc = &priv->rx_ring[q].ex_desc[entry];
>  		if (desc->die_dt == DT_FEMPTY)
> @@ -992,18 +990,16 @@ static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q)
>  		desc->die_dt = DT_FEMPTY;
>  	}
>  
> -	stats->rx_packets += rx_packets;

Don't we still need to update the statistics? Same for ravb_rx_gbeth().

> -	*quota -= rx_packets;
> -	return *quota == 0;
> +	return rx_packets;
>  }
>  
>  /* Packet receive function for Ethernet AVB */
> -static bool ravb_rx(struct net_device *ndev, int *quota, int q)
> +static int ravb_rx(struct net_device *ndev, int budget, int q)
>  {
>  	struct ravb_private *priv = netdev_priv(ndev);
>  	const struct ravb_hw_info *info = priv->info;
>  
> -	return info->receive(ndev, quota, q);
> +	return info->receive(ndev, budget, q);
>  }
>  
>  static void ravb_rcv_snd_disable(struct net_device *ndev)
> @@ -1320,13 +1316,12 @@ static int ravb_poll(struct napi_struct *napi, int budget)
>  	unsigned long flags;
>  	int q = napi - priv->napi;
>  	int mask = BIT(q);
> -	int quota = budget;
> -	bool unmask;
> +	int work_done;
>  
>  	/* Processing RX Descriptor Ring */
>  	/* Clear RX interrupt */
>  	ravb_write(ndev, ~(mask | RIS0_RESERVED), RIS0);
> -	unmask = !ravb_rx(ndev, &quota, q);
> +	work_done = ravb_rx(ndev, budget, q);
>  
>  	/* Processing TX Descriptor Ring */
>  	spin_lock_irqsave(&priv->lock, flags);
> @@ -1345,7 +1340,7 @@ static int ravb_poll(struct napi_struct *napi, int budget)
>  	if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors)
>  		ndev->stats.rx_fifo_errors = priv->rx_fifo_errors;
>  
> -	if (!unmask)
> +	if (work_done == budget)
>  		goto out;
>  
>  	napi_complete(napi);
> @@ -1362,7 +1357,7 @@ static int ravb_poll(struct napi_struct *napi, int budget)
>  	spin_unlock_irqrestore(&priv->lock, flags);
>  
>  out:
> -	return budget - quota;
> +	return work_done;
>  }
>  
>  static void ravb_set_duplex_gbeth(struct net_device *ndev)
> -- 
> 2.39.2
> 

-- 
Kind Regards,
Niklas Söderlund

  reply	other threads:[~2024-04-15 11:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15  9:47 [net-next RFC v3 0/7] Improve GbEth performance on Renesas RZ/G2L and related SoCs Paul Barker
2024-04-15  9:47 ` [net-next RFC v3 1/7] net: ravb: Simplify poll & receive functions Paul Barker
2024-04-15 11:23   ` Niklas Söderlund [this message]
2024-04-15 11:31     ` Paul Barker
2024-04-15  9:47 ` [net-next RFC v3 2/7] net: ravb: Align poll function with NAPI docs Paul Barker
2024-04-15 11:44   ` Niklas Söderlund
2024-04-15 12:08     ` Paul Barker
2024-04-15  9:48 ` [net-next RFC v3 3/7] net: ravb: Refactor RX ring refill Paul Barker
2024-04-15 11:57   ` Niklas Söderlund
2024-04-15 12:18     ` Paul Barker
2024-04-15 12:30       ` Niklas Söderlund
2024-04-15  9:48 ` [net-next RFC v3 4/7] net: ravb: Refactor GbEth RX code path Paul Barker
2024-04-19 20:03   ` Sergey Shtylyov
2024-04-21 15:49     ` Paul Barker
2024-04-21 20:23       ` Sergey Shtylyov
2024-04-15  9:48 ` [net-next RFC v3 5/7] net: ravb: Enable SW IRQ Coalescing for GbEth Paul Barker
2024-04-19 20:26   ` Sergey Shtylyov
2024-04-15  9:48 ` [net-next RFC v3 6/7] net: ravb: Use NAPI threaded mode on 1-core CPUs with GbEth IP Paul Barker
2024-04-19 20:32   ` Sergey Shtylyov
2024-04-15  9:48 ` [net-next RFC v3 7/7] net: ravb: Allocate RX buffers via page pool Paul Barker
2024-04-15 12:16   ` Niklas Söderlund
2024-04-19  8:02     ` Paul Barker

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=20240415112301.GF3156415@ragnatech.se \
    --to=niklas.soderlund+renesas@ragnatech.se \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=geert+renesas@glider.be \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paul.barker.ct@bp.renesas.com \
    --cc=s.shtylyov@omp.ru \
    /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