Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netdev: reshuffle netif_napi_add() APIs to allow dropping weight

Most drivers should not have to worry about selecting the right
weight for their NAPI instances and pass NAPI_POLL_WEIGHT.
It'd be best if we didn't require the argument at all and selected
the default internally.

This change prepares the ground for such reshuffling, allowing
for a smooth transition. The following API should remain after
the next release cycle:
netif_napi_add()
netif_napi_add_weight()
netif_napi_add_tx()
netif_napi_add_tx_weight()
Where the _weight() variants take an explicit weight argument.
I opted for a _weight() suffix rather than a __ prefix, because
we use __ in places to mean that caller needs to also issue a
synchronize_net() call.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/r/20220502232703.396351-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+36 -20
+33 -17
include/linux/netdevice.h
··· 2499 2499 */ 2500 2500 #define NAPI_POLL_WEIGHT 64 2501 2501 2502 + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, 2503 + int (*poll)(struct napi_struct *, int), int weight); 2504 + 2502 2505 /** 2503 - * netif_napi_add - initialize a NAPI context 2504 - * @dev: network device 2505 - * @napi: NAPI context 2506 - * @poll: polling function 2507 - * @weight: default weight 2506 + * netif_napi_add() - initialize a NAPI context 2507 + * @dev: network device 2508 + * @napi: NAPI context 2509 + * @poll: polling function 2510 + * @weight: default weight 2508 2511 * 2509 2512 * netif_napi_add() must be used to initialize a NAPI context prior to calling 2510 2513 * *any* of the other NAPI-related functions. 2511 2514 */ 2512 - void netif_napi_add(struct net_device *dev, struct napi_struct *napi, 2513 - int (*poll)(struct napi_struct *, int), int weight); 2515 + static inline void 2516 + netif_napi_add(struct net_device *dev, struct napi_struct *napi, 2517 + int (*poll)(struct napi_struct *, int), int weight) 2518 + { 2519 + netif_napi_add_weight(dev, napi, poll, weight); 2520 + } 2521 + 2522 + static inline void 2523 + netif_napi_add_tx_weight(struct net_device *dev, 2524 + struct napi_struct *napi, 2525 + int (*poll)(struct napi_struct *, int), 2526 + int weight) 2527 + { 2528 + set_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state); 2529 + netif_napi_add_weight(dev, napi, poll, weight); 2530 + } 2531 + 2532 + #define netif_tx_napi_add netif_napi_add_tx_weight 2514 2533 2515 2534 /** 2516 - * netif_tx_napi_add - initialize a NAPI context 2517 - * @dev: network device 2518 - * @napi: NAPI context 2519 - * @poll: polling function 2520 - * @weight: default weight 2535 + * netif_napi_add_tx() - initialize a NAPI context to be used for Tx only 2536 + * @dev: network device 2537 + * @napi: NAPI context 2538 + * @poll: polling function 2521 2539 * 2522 2540 * This variant of netif_napi_add() should be used from drivers using NAPI 2523 2541 * to exclusively poll a TX queue. 2524 2542 * This will avoid we add it into napi_hash[], thus polluting this hash table. 2525 2543 */ 2526 - static inline void netif_tx_napi_add(struct net_device *dev, 2544 + static inline void netif_napi_add_tx(struct net_device *dev, 2527 2545 struct napi_struct *napi, 2528 - int (*poll)(struct napi_struct *, int), 2529 - int weight) 2546 + int (*poll)(struct napi_struct *, int)) 2530 2547 { 2531 - set_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state); 2532 - netif_napi_add(dev, napi, poll, weight); 2548 + netif_napi_add_tx_weight(dev, napi, poll, NAPI_POLL_WEIGHT); 2533 2549 } 2534 2550 2535 2551 /**
+3 -3
net/core/dev.c
··· 6303 6303 } 6304 6304 EXPORT_SYMBOL(dev_set_threaded); 6305 6305 6306 - void netif_napi_add(struct net_device *dev, struct napi_struct *napi, 6307 - int (*poll)(struct napi_struct *, int), int weight) 6306 + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, 6307 + int (*poll)(struct napi_struct *, int), int weight) 6308 6308 { 6309 6309 if (WARN_ON(test_and_set_bit(NAPI_STATE_LISTED, &napi->state))) 6310 6310 return; ··· 6337 6337 if (dev->threaded && napi_kthread_create(napi)) 6338 6338 dev->threaded = 0; 6339 6339 } 6340 - EXPORT_SYMBOL(netif_napi_add); 6340 + EXPORT_SYMBOL(netif_napi_add_weight); 6341 6341 6342 6342 void napi_disable(struct napi_struct *n) 6343 6343 {