From: Jakub Kicinski <kuba@kernel.org>
To: David Wei <dw@davidwei.uk>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH v1 1/2] netdevsim: add NAPI support
Date: Tue, 16 Apr 2024 17:27:30 -0700 [thread overview]
Message-ID: <20240416172730.1b588eef@kernel.org> (raw)
In-Reply-To: <20240416051527.1657233-2-dw@davidwei.uk>
On Mon, 15 Apr 2024 22:15:26 -0700 David Wei wrote:
> Add NAPI support to netdevim, similar to veth.
>
> * Add a nsim_rq rx queue structure to hold a NAPI instance and a skb
> queue.
> * During xmit, store the skb in the peer skb queue and schedule NAPI.
> * During napi_poll(), drain the skb queue and pass up the stack.
> * Add assoc between rxq and NAPI instance using netif_queue_set_napi().
> +#define NSIM_RING_SIZE 256
> +
> +static int nsim_napi_rx(struct nsim_rq *rq, struct sk_buff *skb)
> +{
> + if (list_count_nodes(&rq->skb_queue) > NSIM_RING_SIZE) {
> + dev_kfree_skb_any(skb);
> + return NET_RX_DROP;
> + }
> +
> + list_add_tail(&skb->list, &rq->skb_queue);
Why not use struct sk_buff_head ?
It has a purge helper for freeing, and remembers its own length.
> +static int nsim_poll(struct napi_struct *napi, int budget)
> +{
> + struct nsim_rq *rq = container_of(napi, struct nsim_rq, napi);
> + int done;
> +
> + done = nsim_rcv(rq, budget);
> +
> + if (done < budget && napi_complete_done(napi, done)) {
> + if (unlikely(!list_empty(&rq->skb_queue)))
> + napi_schedule(&rq->napi);
I think you can drop the re-check, NAPI has a built in protection
for this kind of race.
> + }
> +
> + return done;
> +}
> static int nsim_open(struct net_device *dev)
> {
> struct netdevsim *ns = netdev_priv(dev);
> - struct page_pool_params pp = { 0 };
> + int err;
> +
> + err = nsim_init_napi(ns);
> + if (err)
> + return err;
> +
> + nsim_enable_napi(ns);
>
> - pp.pool_size = 128;
> - pp.dev = &dev->dev;
> - pp.dma_dir = DMA_BIDIRECTIONAL;
> - pp.netdev = dev;
> + netif_carrier_on(dev);
Why the carrier? It's on by default.
Should be a separate patch if needed.
> - ns->pp = page_pool_create(&pp);
> - return PTR_ERR_OR_ZERO(ns->pp);
> + return 0;
> +}
> diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
> index 7664ab823e29..87bf45ec4dd2 100644
> --- a/drivers/net/netdevsim/netdevsim.h
> +++ b/drivers/net/netdevsim/netdevsim.h
> @@ -90,11 +90,18 @@ struct nsim_ethtool {
> struct ethtool_fecparam fec;
> };
>
> +struct nsim_rq {
> + struct napi_struct napi;
> + struct list_head skb_queue;
> + struct page_pool *page_pool;
You added the new page_pool pointer but didn't delete the one
I added recently to the device?
> +};
> +
> struct netdevsim {
> struct net_device *netdev;
> struct nsim_dev *nsim_dev;
> struct nsim_dev_port *nsim_dev_port;
> struct mock_phc *phc;
> + struct nsim_rq *rq;
>
> u64 tx_packets;
> u64 tx_bytes;
next prev parent reply other threads:[~2024-04-17 0:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 5:15 [PATCH v1 0/2] netdevsim: add NAPI support David Wei
2024-04-16 5:15 ` [PATCH v1 1/2] " David Wei
2024-04-17 0:27 ` Jakub Kicinski [this message]
2024-04-19 16:08 ` David Wei
2024-04-16 5:15 ` [PATCH v1 2/2] net: selftest: add test for netdev netlink queue-get API David Wei
2024-04-17 0:31 ` Jakub Kicinski
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=20240416172730.1b588eef@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.