diff mbox series

[net-next,v3,02/10] net: Add queue and napi association

Message ID 169516244584.7377.16939532936643936800.stgit@anambiarhost.jf.intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Introduce queue and NAPI support in netdev-genl (Was: Introduce NAPI queues support) | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5499 this patch: 5499
netdev/cc_maintainers warning 4 maintainers not CCed: edumazet@google.com pabeni@redhat.com daniel@iogearbox.net davem@davemloft.net
netdev/build_clang success Errors and warnings before: 1672 this patch: 1672
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5879 this patch: 5879
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 65 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Nambiar, Amritha Sept. 19, 2023, 10:27 p.m. UTC
Add the napi pointer in netdev queue for tracking the napi
instance for each queue. This achieves the queue<->napi mapping.

Signed-off-by: Amritha Nambiar <amritha.nambiar@intel.com>
Reviewed-by: Sridhar Samudrala <sridhar.samudrala@intel.com>
---
 include/linux/netdevice.h     |    5 +++++
 include/net/netdev_rx_queue.h |    2 ++
 net/core/dev.c                |   34 ++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

Comments

Paolo Abeni Sept. 28, 2023, 10:47 a.m. UTC | #1
On Tue, 2023-09-19 at 15:27 -0700, Amritha Nambiar wrote:
> Add the napi pointer in netdev queue for tracking the napi
> instance for each queue. This achieves the queue<->napi mapping.
> 
> Signed-off-by: Amritha Nambiar <amritha.nambiar@intel.com>
> Reviewed-by: Sridhar Samudrala <sridhar.samudrala@intel.com>
> ---
>  include/linux/netdevice.h     |    5 +++++
>  include/net/netdev_rx_queue.h |    2 ++
>  net/core/dev.c                |   34 ++++++++++++++++++++++++++++++++++
>  3 files changed, 41 insertions(+)
> 
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index db3d8429d50d..69e363918e4b 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -657,6 +657,8 @@ struct netdev_queue {
>  
>  	unsigned long		state;
>  
> +	/* NAPI instance for the queue */
> +	struct napi_struct      *napi;

This should be probably moved into the 'read-mostly' section, before
the '_xmit_lock' field, 

>  +/**
> + * netif_napi_add_queue - Associate queue with the napi
> + * @napi: NAPI context
> + * @queue_index: Index of queue
> + * @type: queue type as RX or TX
> + *
> + * Add queue with its corresponding napi context
> + */
> +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index,
> +			 enum netdev_queue_type type)

Very minor nit and others may have different opinion, but I feel like
this function name is misleading, since at this point both the rx and
tx queue should already exist. Perhaps 'netif_napi_link_queue' ?

Cheers,

Paolo
Nambiar, Amritha Sept. 28, 2023, 11:12 p.m. UTC | #2
On 9/28/2023 3:47 AM, Paolo Abeni wrote:
> On Tue, 2023-09-19 at 15:27 -0700, Amritha Nambiar wrote:
>> Add the napi pointer in netdev queue for tracking the napi
>> instance for each queue. This achieves the queue<->napi mapping.
>>
>> Signed-off-by: Amritha Nambiar <amritha.nambiar@intel.com>
>> Reviewed-by: Sridhar Samudrala <sridhar.samudrala@intel.com>
>> ---
>>   include/linux/netdevice.h     |    5 +++++
>>   include/net/netdev_rx_queue.h |    2 ++
>>   net/core/dev.c                |   34 ++++++++++++++++++++++++++++++++++
>>   3 files changed, 41 insertions(+)
>>
>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>> index db3d8429d50d..69e363918e4b 100644
>> --- a/include/linux/netdevice.h
>> +++ b/include/linux/netdevice.h
>> @@ -657,6 +657,8 @@ struct netdev_queue {
>>   
>>   	unsigned long		state;
>>   
>> +	/* NAPI instance for the queue */
>> +	struct napi_struct      *napi;
> 
> This should be probably moved into the 'read-mostly' section, before
> the '_xmit_lock' field,
> 

Agree. Will fix.

>>   +/**
>> + * netif_napi_add_queue - Associate queue with the napi
>> + * @napi: NAPI context
>> + * @queue_index: Index of queue
>> + * @type: queue type as RX or TX
>> + *
>> + * Add queue with its corresponding napi context
>> + */
>> +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index,
>> +			 enum netdev_queue_type type)
> 
> Very minor nit and others may have different opinion, but I feel like
> this function name is misleading, since at this point both the rx and
> tx queue should already exist. Perhaps 'netif_napi_link_queue' ?
> 

Sounds right. Since, we are basically just setting the napi for the 
queue, and this function may probably be used by both 'queue-get' and 
'queue-set' commands in future, does 'netif_queue_set_napi' suit better ?

> Cheers,
> 
> Paolo
>
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index db3d8429d50d..69e363918e4b 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -657,6 +657,8 @@  struct netdev_queue {
 
 	unsigned long		state;
 
+	/* NAPI instance for the queue */
+	struct napi_struct      *napi;
 #ifdef CONFIG_BQL
 	struct dql		dql;
 #endif
@@ -2618,6 +2620,9 @@  static inline void *netdev_priv(const struct net_device *dev)
  */
 #define SET_NETDEV_DEVTYPE(net, devtype)	((net)->dev.type = (devtype))
 
+int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index,
+			 enum netdev_queue_type type);
+
 /* 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 cc03a5758d2d..508b1d799681 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_napi_add_queue - Associate queue with the napi
+ * @napi: NAPI context
+ * @queue_index: Index of queue
+ * @type: queue type as RX or TX
+ *
+ * Add queue with its corresponding napi context
+ */
+int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index,
+			 enum netdev_queue_type type)
+{
+	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_napi_add_queue);
+
 void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
 			   int (*poll)(struct napi_struct *, int), int weight)
 {