[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z6LR-POHxmBV6D7t@LQ3V64L9R2>
Date: Tue, 4 Feb 2025 18:50:32 -0800
From: Joe Damato <jdamato@...tly.com>
To: Samiullah Khawaja <skhawaja@...gle.com>
Cc: Jakub Kicinski <kuba@...nel.org>,
"David S . Miller " <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>,
almasrymina@...gle.com, netdev@...r.kernel.org
Subject: Re: [PATCH net-next v3 1/4] Add support to set napi threaded for
individual napi
On Wed, Feb 05, 2025 at 12:10:49AM +0000, Samiullah Khawaja wrote:
> A net device has a threaded sysctl that can be used to enable threaded
> napi polling on all of the NAPI contexts under that device. Allow
> enabling threaded napi polling at individual napi level using netlink.
>
> Extend the netlink operation `napi-set` and allow setting the threaded
> attribute of a NAPI. This will enable the threaded polling on a napi
> context.
>
> Tested using following command in qemu/virtio-net:
> ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
> --do napi-set --json '{"id": 66, "threaded": 1}'
At a high level, I think this patch could probably be sent on its
own; IMHO it makes sense to make threaded NAPI per-NAPI via
netdev-genl.
I think its fine if you want to include it in your overall series,
but I think a change like this could probably go in on its own.
[...]
> diff --git a/net/core/dev.c b/net/core/dev.c
> index c0021cbd28fc..50fb234dd7a0 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -6787,6 +6787,30 @@ static void init_gro_hash(struct napi_struct *napi)
> napi->gro_bitmask = 0;
> }
>
> +int napi_set_threaded(struct napi_struct *napi, bool threaded)
> +{
> + if (napi->dev->threaded)
> + return -EINVAL;
I feel this is probably a WARN_ON_ONCE situation? Not sure, but in
any case, see below.
> +
> + if (threaded) {
> + if (!napi->thread) {
> + int err = napi_kthread_create(napi);
> +
> + if (err)
> + return err;
> + }
> + }
> +
> + if (napi->config)
> + napi->config->threaded = threaded;
> +
> + /* Make sure kthread is created before THREADED bit is set. */
> + smp_mb__before_atomic();
> + assign_bit(NAPI_STATE_THREADED, &napi->state, threaded);
> +
> + return 0;
> +}
> +
> int dev_set_threaded(struct net_device *dev, bool threaded)
> {
> struct napi_struct *napi;
> @@ -6798,6 +6822,11 @@ int dev_set_threaded(struct net_device *dev, bool threaded)
> return 0;
>
> if (threaded) {
> + /* Check if threaded is set at napi level already */
> + list_for_each_entry(napi, &dev->napi_list, dev_list)
> + if (test_bit(NAPI_STATE_THREADED, &napi->state))
> + return -EINVAL;
> +
> list_for_each_entry(napi, &dev->napi_list, dev_list) {
> if (!napi->thread) {
> err = napi_kthread_create(napi);
> @@ -6880,6 +6909,8 @@ static void napi_restore_config(struct napi_struct *n)
> napi_hash_add(n);
> n->config->napi_id = n->napi_id;
> }
> +
> + napi_set_threaded(n, n->config->threaded);
The return value isn't checked so even if napi_set_threaded returned
EINVAL it seems like there's no way for that error to "bubble" back
up?
Powered by blists - more mailing lists