Skip to content

Commit 2a502ff

Browse files
anambiarinkuba-moo
authored andcommitted
net: Add queue and napi association
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 <[email protected]> Reviewed-by: Sridhar Samudrala <[email protected]> Link: https://lore.kernel.org/r/170147331483.5260.15723438819994285695.stgit@anambiarhost.jf.intel.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent bc87795 commit 2a502ff

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

include/linux/netdevice.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ struct netdev_queue {
665665
#ifdef CONFIG_XDP_SOCKETS
666666
struct xsk_buff_pool *pool;
667667
#endif
668+
/* NAPI instance for the queue
669+
* Readers and writers must hold RTNL
670+
*/
671+
struct napi_struct *napi;
668672
/*
669673
* write-mostly part
670674
*/
@@ -2657,6 +2661,10 @@ static inline void *netdev_priv(const struct net_device *dev)
26572661
*/
26582662
#define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
26592663

2664+
void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
2665+
enum netdev_queue_type type,
2666+
struct napi_struct *napi);
2667+
26602668
/* Default NAPI poll() weight
26612669
* Device drivers are strongly advised to not use bigger value
26622670
*/

include/net/netdev_rx_queue.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ struct netdev_rx_queue {
2121
#ifdef CONFIG_XDP_SOCKETS
2222
struct xsk_buff_pool *pool;
2323
#endif
24+
/* NAPI instance for the queue
25+
* Readers and writers must hold RTNL
26+
*/
27+
struct napi_struct *napi;
2428
} ____cacheline_aligned_in_smp;
2529

2630
/*

net/core/dev.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6400,6 +6400,43 @@ int dev_set_threaded(struct net_device *dev, bool threaded)
64006400
}
64016401
EXPORT_SYMBOL(dev_set_threaded);
64026402

6403+
/**
6404+
* netif_queue_set_napi - Associate queue with the napi
6405+
* @dev: device to which NAPI and queue belong
6406+
* @queue_index: Index of queue
6407+
* @type: queue type as RX or TX
6408+
* @napi: NAPI context, pass NULL to clear previously set NAPI
6409+
*
6410+
* Set queue with its corresponding napi context. This should be done after
6411+
* registering the NAPI handler for the queue-vector and the queues have been
6412+
* mapped to the corresponding interrupt vector.
6413+
*/
6414+
void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
6415+
enum netdev_queue_type type, struct napi_struct *napi)
6416+
{
6417+
struct netdev_rx_queue *rxq;
6418+
struct netdev_queue *txq;
6419+
6420+
if (WARN_ON_ONCE(napi && !napi->dev))
6421+
return;
6422+
if (dev->reg_state >= NETREG_REGISTERED)
6423+
ASSERT_RTNL();
6424+
6425+
switch (type) {
6426+
case NETDEV_QUEUE_TYPE_RX:
6427+
rxq = __netif_get_rx_queue(dev, queue_index);
6428+
rxq->napi = napi;
6429+
return;
6430+
case NETDEV_QUEUE_TYPE_TX:
6431+
txq = netdev_get_tx_queue(dev, queue_index);
6432+
txq->napi = napi;
6433+
return;
6434+
default:
6435+
return;
6436+
}
6437+
}
6438+
EXPORT_SYMBOL(netif_queue_set_napi);
6439+
64036440
void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
64046441
int (*poll)(struct napi_struct *, int), int weight)
64056442
{

0 commit comments

Comments
 (0)