Message ID | 169658368866.3683.5936758786055991674.stgit@anambiarhost.jf.intel.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Introduce queue and NAPI support in netdev-genl (Was: Introduce NAPI queues support) | expand |
On Fri, 06 Oct 2023 02:14:48 -0700 Amritha Nambiar wrote: > #endif > + /* NAPI instance for the queue */ > + struct napi_struct *napi; What's the protection on this field? Writers and readers must be under rtnl_lock? > } ____cacheline_aligned_in_smp; > > /* > diff --git a/net/core/dev.c b/net/core/dev.c > index 606a366cc209..9b63a7b76c01 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -6394,6 +6394,40 @@ int dev_set_threaded(struct net_device *dev, bool threaded) > } > EXPORT_SYMBOL(dev_set_threaded); > > +/** > + * netif_queue_set_napi - Associate queue with the napi > + * @queue_index: Index of queue > + * @type: queue type as RX or TX > + * @napi: NAPI context > + * > + * Set queue with its corresponding napi context Let's add more relevant info, like the fact that NAPI must already be added before calling, calling context, etc. > + */ > +int netif_queue_set_napi(unsigned int queue_index, enum netdev_queue_type type, > + struct napi_struct *napi) Let's make this helper void. It will be a PITA for callers to handle any error this may return. > +{ > + struct net_device *dev = napi->dev; > + struct netdev_rx_queue *rxq; > + struct netdev_queue *txq; > + > + if (!dev) > + return -EINVAL; if (WARN_ON_ONCE(...)) return; > + default: > + return -EINVAL; > + } same here
On 10/10/2023 7:17 PM, Jakub Kicinski wrote: > On Fri, 06 Oct 2023 02:14:48 -0700 Amritha Nambiar wrote: >> #endif >> + /* NAPI instance for the queue */ >> + struct napi_struct *napi; > > What's the protection on this field? > Writers and readers must be under rtnl_lock? > Yes, writers and readers must be under rtnl_lock. I will modify netif_queue_set_napi() for rtnl protection from writers. Readers are holding rtnl_lock. >> } ____cacheline_aligned_in_smp; >> >> /* >> diff --git a/net/core/dev.c b/net/core/dev.c >> index 606a366cc209..9b63a7b76c01 100644 >> --- a/net/core/dev.c >> +++ b/net/core/dev.c >> @@ -6394,6 +6394,40 @@ int dev_set_threaded(struct net_device *dev, bool threaded) >> } >> EXPORT_SYMBOL(dev_set_threaded); >> >> +/** >> + * netif_queue_set_napi - Associate queue with the napi >> + * @queue_index: Index of queue >> + * @type: queue type as RX or TX >> + * @napi: NAPI context >> + * >> + * Set queue with its corresponding napi context > > Let's add more relevant info, like the fact that NAPI must already be > added before calling, calling context, etc. > Okay, will fix in v5. >> + */ >> +int netif_queue_set_napi(unsigned int queue_index, enum netdev_queue_type type, >> + struct napi_struct *napi) > > Let's make this helper void. > It will be a PITA for callers to handle any error this may return. > Okay, will make this a void function in v5. >> +{ >> + struct net_device *dev = napi->dev; >> + struct netdev_rx_queue *rxq; >> + struct netdev_queue *txq; >> + >> + if (!dev) >> + return -EINVAL; > > if (WARN_ON_ONCE(...)) > return; > >> + default: >> + return -EINVAL; >> + } > > same here Will fix in v5.
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index e070a4540fba..264ae0bdabe8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -645,6 +645,8 @@ struct netdev_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + /* NAPI instance for the queue */ + struct napi_struct *napi; /* * write-mostly part */ @@ -2619,6 +2621,9 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +int netif_queue_set_napi(unsigned int queue_index, enum netdev_queue_type type, + struct napi_struct *napi); + /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value */ diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index cdcafb30d437..2e65b03d214d 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -21,6 +21,8 @@ struct netdev_rx_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + /* NAPI instance for the queue */ + struct napi_struct *napi; } ____cacheline_aligned_in_smp; /* diff --git a/net/core/dev.c b/net/core/dev.c index 606a366cc209..9b63a7b76c01 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6394,6 +6394,40 @@ int dev_set_threaded(struct net_device *dev, bool threaded) } EXPORT_SYMBOL(dev_set_threaded); +/** + * netif_queue_set_napi - Associate queue with the napi + * @queue_index: Index of queue + * @type: queue type as RX or TX + * @napi: NAPI context + * + * Set queue with its corresponding napi context + */ +int netif_queue_set_napi(unsigned int queue_index, enum netdev_queue_type type, + struct napi_struct *napi) +{ + struct net_device *dev = napi->dev; + struct netdev_rx_queue *rxq; + struct netdev_queue *txq; + + if (!dev) + return -EINVAL; + + switch (type) { + case NETDEV_QUEUE_TYPE_RX: + rxq = __netif_get_rx_queue(dev, queue_index); + rxq->napi = napi; + break; + case NETDEV_QUEUE_TYPE_TX: + txq = netdev_get_tx_queue(dev, queue_index); + txq->napi = napi; + break; + default: + return -EINVAL; + } + return 0; +} +EXPORT_SYMBOL(netif_queue_set_napi); + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight) {