Skip to content

Commit 8e7583a

Browse files
samikhawajakuba-moo
authored andcommitted
net: define an enum for the napi threaded state
Instead of using '0' and '1' for napi threaded state use an enum with 'disabled' and 'enabled' states. Tested: ./tools/testing/selftests/net/nl_netdev.py TAP version 13 1..7 ok 1 nl_netdev.empty_check ok 2 nl_netdev.lo_check ok 3 nl_netdev.page_pool_check ok 4 nl_netdev.napi_list_check ok 5 nl_netdev.dev_set_threaded ok 6 nl_netdev.napi_set_threaded ok 7 nl_netdev.nsim_rxq_reset_down # Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Samiullah Khawaja <skhawaja@google.com> Link: https://patch.msgid.link/20250723013031.2911384-4-skhawaja@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 78afdad commit 8e7583a

File tree

11 files changed

+62
-41
lines changed

11 files changed

+62
-41
lines changed

Documentation/netlink/specs/netdev.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ definitions:
8585
name: qstats-scope
8686
type: flags
8787
entries: [queue]
88+
-
89+
name: napi-threaded
90+
type: enum
91+
entries: [disabled, enabled]
8892

8993
attribute-sets:
9094
-
@@ -286,11 +290,10 @@ attribute-sets:
286290
-
287291
name: threaded
288292
doc: Whether the NAPI is configured to operate in threaded polling
289-
mode. If this is set to 1 then the NAPI context operates in
290-
threaded polling mode.
291-
type: uint
292-
checks:
293-
max: 1
293+
mode. If this is set to enabled then the NAPI context operates
294+
in threaded polling mode.
295+
type: u32
296+
enum: napi-threaded
294297
-
295298
name: xsk-info
296299
attributes: []

Documentation/networking/net_cachelines/net_device.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ unsigned_char addr_assign_type
6868
unsigned_char addr_len
6969
unsigned_char upper_level
7070
unsigned_char lower_level
71+
u8 threaded napi_poll(napi_enable,netif_set_threaded)
7172
unsigned_short neigh_priv_len
7273
unsigned_short padded
7374
unsigned_short dev_id
@@ -165,7 +166,6 @@ struct sfp_bus* sfp_bus
165166
struct lock_class_key* qdisc_tx_busylock
166167
bool proto_down
167168
unsigned:1 wol_enabled
168-
unsigned:1 threaded napi_poll(napi_enable,netif_set_threaded)
169169
unsigned_long:1 see_all_hwtstamp_requests
170170
unsigned_long:1 change_proto_down
171171
unsigned_long:1 netns_immutable

include/linux/netdevice.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ struct napi_config {
369369
u64 irq_suspend_timeout;
370370
u32 defer_hard_irqs;
371371
cpumask_t affinity_mask;
372-
bool threaded;
372+
u8 threaded;
373373
unsigned int napi_id;
374374
};
375375

@@ -590,7 +590,8 @@ static inline bool napi_complete(struct napi_struct *n)
590590
}
591591

592592
void netif_threaded_enable(struct net_device *dev);
593-
int dev_set_threaded(struct net_device *dev, bool threaded);
593+
int dev_set_threaded(struct net_device *dev,
594+
enum netdev_napi_threaded threaded);
594595

595596
void napi_disable(struct napi_struct *n);
596597
void napi_disable_locked(struct napi_struct *n);
@@ -1872,6 +1873,7 @@ enum netdev_reg_state {
18721873
* @addr_len: Hardware address length
18731874
* @upper_level: Maximum depth level of upper devices.
18741875
* @lower_level: Maximum depth level of lower devices.
1876+
* @threaded: napi threaded state.
18751877
* @neigh_priv_len: Used in neigh_alloc()
18761878
* @dev_id: Used to differentiate devices that share
18771879
* the same link layer address
@@ -2011,8 +2013,6 @@ enum netdev_reg_state {
20112013
* switch driver and used to set the phys state of the
20122014
* switch port.
20132015
*
2014-
* @threaded: napi threaded mode is enabled
2015-
*
20162016
* @irq_affinity_auto: driver wants the core to store and re-assign the IRQ
20172017
* affinity. Set by netif_enable_irq_affinity(), then
20182018
* the driver must create a persistent napi by
@@ -2248,6 +2248,7 @@ struct net_device {
22482248
unsigned char addr_len;
22492249
unsigned char upper_level;
22502250
unsigned char lower_level;
2251+
u8 threaded;
22512252

22522253
unsigned short neigh_priv_len;
22532254
unsigned short dev_id;
@@ -2429,7 +2430,6 @@ struct net_device {
24292430
struct sfp_bus *sfp_bus;
24302431
struct lock_class_key *qdisc_tx_busylock;
24312432
bool proto_down;
2432-
bool threaded;
24332433
bool irq_affinity_auto;
24342434
bool rx_cpu_rmap_auto;
24352435

include/uapi/linux/netdev.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ enum netdev_qstats_scope {
7777
NETDEV_QSTATS_SCOPE_QUEUE = 1,
7878
};
7979

80+
enum netdev_napi_threaded {
81+
NETDEV_NAPI_THREADED_DISABLED,
82+
NETDEV_NAPI_THREADED_ENABLED,
83+
};
84+
8085
enum {
8186
NETDEV_A_DEV_IFINDEX = 1,
8287
NETDEV_A_DEV_PAD,

net/core/dev.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6963,7 +6963,8 @@ static void napi_stop_kthread(struct napi_struct *napi)
69636963
napi->thread = NULL;
69646964
}
69656965

6966-
int napi_set_threaded(struct napi_struct *napi, bool threaded)
6966+
int napi_set_threaded(struct napi_struct *napi,
6967+
enum netdev_napi_threaded threaded)
69676968
{
69686969
if (threaded) {
69696970
if (!napi->thread) {
@@ -6988,7 +6989,8 @@ int napi_set_threaded(struct napi_struct *napi, bool threaded)
69886989
return 0;
69896990
}
69906991

6991-
int netif_set_threaded(struct net_device *dev, bool threaded)
6992+
int netif_set_threaded(struct net_device *dev,
6993+
enum netdev_napi_threaded threaded)
69926994
{
69936995
struct napi_struct *napi;
69946996
int err = 0;
@@ -7000,7 +7002,7 @@ int netif_set_threaded(struct net_device *dev, bool threaded)
70007002
if (!napi->thread) {
70017003
err = napi_kthread_create(napi);
70027004
if (err) {
7003-
threaded = false;
7005+
threaded = NETDEV_NAPI_THREADED_DISABLED;
70047006
break;
70057007
}
70067008
}
@@ -7043,7 +7045,7 @@ int netif_set_threaded(struct net_device *dev, bool threaded)
70437045
*/
70447046
void netif_threaded_enable(struct net_device *dev)
70457047
{
7046-
WARN_ON_ONCE(netif_set_threaded(dev, true));
7048+
WARN_ON_ONCE(netif_set_threaded(dev, NETDEV_NAPI_THREADED_ENABLED));
70477049
}
70487050
EXPORT_SYMBOL(netif_threaded_enable);
70497051

@@ -7360,7 +7362,7 @@ void netif_napi_add_weight_locked(struct net_device *dev,
73607362
* threaded mode will not be enabled in napi_enable().
73617363
*/
73627364
if (dev->threaded && napi_kthread_create(napi))
7363-
dev->threaded = false;
7365+
dev->threaded = NETDEV_NAPI_THREADED_DISABLED;
73647366
netif_napi_set_irq_locked(napi, -1);
73657367
}
73667368
EXPORT_SYMBOL(netif_napi_add_weight_locked);

net/core/dev.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,19 @@ static inline void napi_set_irq_suspend_timeout(struct napi_struct *n,
315315
WRITE_ONCE(n->irq_suspend_timeout, timeout);
316316
}
317317

318-
static inline bool napi_get_threaded(struct napi_struct *n)
318+
static inline enum netdev_napi_threaded napi_get_threaded(struct napi_struct *n)
319319
{
320-
return test_bit(NAPI_STATE_THREADED, &n->state);
320+
if (test_bit(NAPI_STATE_THREADED, &n->state))
321+
return NETDEV_NAPI_THREADED_ENABLED;
322+
323+
return NETDEV_NAPI_THREADED_DISABLED;
321324
}
322325

323-
int napi_set_threaded(struct napi_struct *n, bool threaded);
326+
int napi_set_threaded(struct napi_struct *n,
327+
enum netdev_napi_threaded threaded);
324328

325-
int netif_set_threaded(struct net_device *dev, bool threaded);
329+
int netif_set_threaded(struct net_device *dev,
330+
enum netdev_napi_threaded threaded);
326331

327332
int rps_cpumask_housekeeping(struct cpumask *mask);
328333

net/core/dev_api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ void netdev_state_change(struct net_device *dev)
368368
}
369369
EXPORT_SYMBOL(netdev_state_change);
370370

371-
int dev_set_threaded(struct net_device *dev, bool threaded)
371+
int dev_set_threaded(struct net_device *dev,
372+
enum netdev_napi_threaded threaded)
372373
{
373374
int ret;
374375

net/core/netdev-genl-gen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static const struct nla_policy netdev_napi_set_nl_policy[NETDEV_A_NAPI_THREADED
9797
[NETDEV_A_NAPI_DEFER_HARD_IRQS] = NLA_POLICY_FULL_RANGE(NLA_U32, &netdev_a_napi_defer_hard_irqs_range),
9898
[NETDEV_A_NAPI_GRO_FLUSH_TIMEOUT] = { .type = NLA_UINT, },
9999
[NETDEV_A_NAPI_IRQ_SUSPEND_TIMEOUT] = { .type = NLA_UINT, },
100-
[NETDEV_A_NAPI_THREADED] = NLA_POLICY_MAX(NLA_UINT, 1),
100+
[NETDEV_A_NAPI_THREADED] = NLA_POLICY_MAX(NLA_U32, 1),
101101
};
102102

103103
/* NETDEV_CMD_BIND_TX - do */

net/core/netdev-genl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ netdev_nl_napi_set_config(struct napi_struct *napi, struct genl_info *info)
333333
int ret;
334334

335335
threaded = nla_get_uint(info->attrs[NETDEV_A_NAPI_THREADED]);
336-
ret = napi_set_threaded(napi, !!threaded);
336+
ret = napi_set_threaded(napi, threaded);
337337
if (ret)
338338
return ret;
339339
}

tools/include/uapi/linux/netdev.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ enum netdev_qstats_scope {
7777
NETDEV_QSTATS_SCOPE_QUEUE = 1,
7878
};
7979

80+
enum netdev_napi_threaded {
81+
NETDEV_NAPI_THREADED_DISABLED,
82+
NETDEV_NAPI_THREADED_ENABLED,
83+
};
84+
8085
enum {
8186
NETDEV_A_DEV_IFINDEX = 1,
8287
NETDEV_A_DEV_PAD,

0 commit comments

Comments
 (0)