netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Damato <jdamato@fastly.com>
To: Ahmed Zaki <ahmed.zaki@intel.com>
Cc: netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
	andrew+netdev@lunn.ch, edumazet@google.com, kuba@kernel.org,
	horms@kernel.org, pabeni@redhat.com, davem@davemloft.net,
	michael.chan@broadcom.com, tariqt@nvidia.com,
	anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
	shayd@nvidia.com, akpm@linux-foundation.org, shayagr@amazon.com,
	kalesh-anakkur.purayil@broadcom.com,
	David Arinzon <darinzon@amazon.com>
Subject: Re: [PATCH net-next v6 1/5] net: move ARFS rmap management to core
Date: Thu, 23 Jan 2025 12:20:34 -0800	[thread overview]
Message-ID: <Z5KkkldrWpw8wayS@LQ3V64L9R2> (raw)
In-Reply-To: <414c773d-5b7b-44b8-82a7-da49168ee791@intel.com>

On Thu, Jan 23, 2025 at 01:13:10PM -0700, Ahmed Zaki wrote:
> 
> 
> On 2025-01-23 12:28 p.m., Joe Damato wrote:
> > On Fri, Jan 17, 2025 at 05:33:31PM -0700, Ahmed Zaki wrote:
> > > Add a new netdev flag "rx_cpu_rmap_auto". Drivers supporting ARFS should
> > > set the flag via netif_enable_cpu_rmap() and core will allocate and manage
> > > the ARFS rmap. Freeing the rmap is also done by core when the netdev is
> > > freed.
> > > 
> > > For better IRQ affinity management, move the IRQ rmap notifier inside the
> > > napi_struct. Consequently, add new notify.notify and notify.release
> > > functions: netif_irq_cpu_rmap_notify() and netif_napi_affinity_release().
> > > 
> > > Acked-by: David Arinzon <darinzon@amazon.com>
> > > Signed-off-by: Ahmed Zaki <ahmed.zaki@intel.com>
> > 
> > [...]
> > 
> > > diff --git a/net/core/dev.c b/net/core/dev.c
> > > index fe5f5855593d..dbb63005bc2b 100644
> > > --- a/net/core/dev.c
> > > +++ b/net/core/dev.c
> > > @@ -6862,6 +6862,141 @@ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
> > >   }
> > >   EXPORT_SYMBOL(netif_queue_set_napi);
> > > +#ifdef CONFIG_RFS_ACCEL
> > > +static void
> > > +netif_irq_cpu_rmap_notify(struct irq_affinity_notify *notify,
> > > +			  const cpumask_t *mask)
> > > +{
> > > +	struct napi_struct *napi =
> > > +		container_of(notify, struct napi_struct, notify);
> > > +	struct cpu_rmap *rmap = napi->dev->rx_cpu_rmap;
> > > +	int err;
> > 
> > I wonder if this generates a warning with some compilers? err is
> > defined not used if !napi->dev->rx_cpu_rmap_auto ? Not sure.
> > 
> > > +	if (napi->dev->rx_cpu_rmap_auto) {
> > > +		err = cpu_rmap_update(rmap, napi->napi_rmap_idx, mask);
> > > +		if (err)
> > > +			pr_warn("%s: RMAP update failed (%d)\n",
> > > +				__func__, err);
> > > +	}
> > > +}
> > > +
> > > +static void netif_napi_affinity_release(struct kref *ref)
> > > +{
> > > +	struct napi_struct *napi =
> > > +		container_of(ref, struct napi_struct, notify.kref);
> > > +	struct cpu_rmap *rmap = napi->dev->rx_cpu_rmap;
> > > +
> > > +	if (!napi->dev->rx_cpu_rmap_auto)
> > > +		return;
> > > +	rmap->obj[napi->napi_rmap_idx] = NULL;
> > > +	napi->napi_rmap_idx = -1;
> > > +	cpu_rmap_put(rmap);
> > > +}
> > > +
> > > +static int napi_irq_cpu_rmap_add(struct napi_struct *napi, int irq)
> > > +{
> > > +	struct cpu_rmap *rmap = napi->dev->rx_cpu_rmap;
> > > +	int rc;
> > > +
> > > +	if (!rmap)
> > > +		return -EINVAL;
> > > +
> > > +	napi->notify.notify = netif_irq_cpu_rmap_notify;
> > > +	napi->notify.release = netif_napi_affinity_release;
> > 
> > Maybe the callbacks should only be set at the end after everything
> > else is successful, just before the return 0 ?
> > 
> 
> I believe this is needed before irq_set_affinity_notifier(), OW we could
> have some racing. I can move it there if you like.
> 
> > > +	cpu_rmap_get(rmap);
> > > +	rc = cpu_rmap_add(rmap, napi);
> > > +	if (rc < 0)
> > > +		goto err_add;
> > > +
> > > +	napi->napi_rmap_idx = rc;
> > > +	rc = irq_set_affinity_notifier(irq, &napi->notify);
> > > +	if (rc)
> > > +		goto err_set;
> > > +
> > > +	return 0;
> > > +
> > > +err_set:
> > > +	rmap->obj[napi->napi_rmap_idx] = NULL;
> > > +	napi->napi_rmap_idx = -1;
> > > +err_add:
> > > +	cpu_rmap_put(rmap);
> > > +	return rc;
> > > +}
> > 
> > [...]
> > 
> > > +void netif_napi_set_irq_locked(struct napi_struct *napi, int irq)
> > > +{
> > > +	int rc;
> > > +
> > > +	if (!napi->dev->rx_cpu_rmap_auto)
> > > +		goto out;
> > 
> > Maybe the above if statement could be extended to be something like:
> > 
> > if (!napi->dev->rx_cpu_rmap_auto || napi->irq < 0)
> >    goto out;
> > 
> > then you can omit the irq > 0 checks in the code below, potentially?
> 
> I am afraid I don't get this, the checks below one is for the new irq (could
> be valid or -1) and one for the existing (nap->irq).

Ah yes, my mistake; I misread the other half of the if statement
below. My apologies.

> > 
> > > +	/* Remove existing rmap entries */
> > > +	if (napi->irq != irq && napi->irq > 0)
> > > +		irq_set_affinity_notifier(napi->irq, NULL);
> > > +
> > > +	if (irq > 0) {
> > > +		rc = napi_irq_cpu_rmap_add(napi, irq);
> > > +		if (rc) {
> > > +			netdev_warn(napi->dev, "Unable to update ARFS map (%d)\n",
> > > +				    rc);
> > > +			netif_disable_cpu_rmap(napi->dev);
> > > +		}
> > > +	}
> > > +
> > > +out:
> > > +	napi->irq = irq;
> > > +}
> > > +EXPORT_SYMBOL(netif_napi_set_irq_locked);
> > > +
> 
> Thanks.
> 

  reply	other threads:[~2025-01-23 20:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-18  0:33 [PATCH net-next v6 0/5] net: napi: add CPU affinity to napi->config Ahmed Zaki
2025-01-18  0:33 ` [PATCH net-next v6 1/5] net: move ARFS rmap management to core Ahmed Zaki
2025-01-21  0:59   ` Jakub Kicinski
2025-01-21 14:52     ` Ahmed Zaki
2025-01-23 19:28   ` Joe Damato
2025-01-23 20:13     ` Ahmed Zaki
2025-01-23 20:20       ` Joe Damato [this message]
2025-01-18  0:33 ` [PATCH net-next v6 2/5] net: napi: add CPU affinity to napi_config Ahmed Zaki
2025-01-21  1:03   ` Jakub Kicinski
2025-01-23 20:18   ` Joe Damato
2025-02-03 21:32     ` Ahmed Zaki
2025-01-18  0:33 ` [PATCH net-next v6 3/5] bnxt: use napi's irq affinity Ahmed Zaki
2025-01-18  0:33 ` [PATCH net-next v6 4/5] ice: " Ahmed Zaki
2025-01-18  0:33 ` [PATCH net-next v6 5/5] idpf: " Ahmed Zaki
2025-01-21  1:03 ` [PATCH net-next v6 0/5] net: napi: add CPU affinity to napi->config Jakub Kicinski
2025-01-21 14:54   ` Ahmed Zaki
2025-01-23 20:27 ` Joe Damato

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=Z5KkkldrWpw8wayS@LQ3V64L9R2 \
    --to=jdamato@fastly.com \
    --cc=ahmed.zaki@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=darinzon@amazon.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=kuba@kernel.org \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=shayagr@amazon.com \
    --cc=shayd@nvidia.com \
    --cc=tariqt@nvidia.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).