Skip to content

Commit acb8d4e

Browse files
jdamato-fslykuba-moo
authored andcommitted
net: napi: Make gro_flush_timeout per-NAPI
Allow per-NAPI gro_flush_timeout setting. The existing sysfs parameter is respected; writes to sysfs will write to all NAPI structs for the device and the net_device gro_flush_timeout field. Reads from sysfs will read from the net_device field. The ability to set gro_flush_timeout on specific NAPI instances will be added in a later commit, via netdev-genl. Signed-off-by: Joe Damato <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5160104 commit acb8d4e

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

Documentation/networking/net_cachelines/net_device.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,6 @@ struct dpll_pin* dpll_pin
186186
struct hlist_head page_pools
187187
struct dim_irq_moder* irq_moder
188188
u64 max_pacing_offload_horizon
189+
unsigned_long gro_flush_timeout
189190
u32 napi_defer_hard_irqs
190191
=================================== =========================== =================== =================== ===================================================================================

include/linux/netdevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ struct napi_struct {
373373
unsigned int napi_id;
374374
struct hrtimer timer;
375375
struct task_struct *thread;
376+
unsigned long gro_flush_timeout;
376377
u32 defer_hard_irqs;
377378
/* control-path-only fields follow */
378379
struct list_head dev_list;
@@ -2085,7 +2086,6 @@ struct net_device {
20852086
int ifindex;
20862087
unsigned int real_num_rx_queues;
20872088
struct netdev_rx_queue *_rx;
2088-
unsigned long gro_flush_timeout;
20892089
unsigned int gro_max_size;
20902090
unsigned int gro_ipv4_max_size;
20912091
rx_handler_func_t __rcu *rx_handler;
@@ -2413,6 +2413,7 @@ struct net_device {
24132413
struct dim_irq_moder *irq_moder;
24142414

24152415
u64 max_pacing_offload_horizon;
2416+
unsigned long gro_flush_timeout;
24162417
u32 napi_defer_hard_irqs;
24172418

24182419
/**

net/core/dev.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6232,12 +6232,12 @@ bool napi_complete_done(struct napi_struct *n, int work_done)
62326232

62336233
if (work_done) {
62346234
if (n->gro_bitmask)
6235-
timeout = READ_ONCE(n->dev->gro_flush_timeout);
6235+
timeout = napi_get_gro_flush_timeout(n);
62366236
n->defer_hard_irqs_count = napi_get_defer_hard_irqs(n);
62376237
}
62386238
if (n->defer_hard_irqs_count > 0) {
62396239
n->defer_hard_irqs_count--;
6240-
timeout = READ_ONCE(n->dev->gro_flush_timeout);
6240+
timeout = napi_get_gro_flush_timeout(n);
62416241
if (timeout)
62426242
ret = false;
62436243
}
@@ -6372,7 +6372,7 @@ static void busy_poll_stop(struct napi_struct *napi, void *have_poll_lock,
63726372

63736373
if (flags & NAPI_F_PREFER_BUSY_POLL) {
63746374
napi->defer_hard_irqs_count = napi_get_defer_hard_irqs(napi);
6375-
timeout = READ_ONCE(napi->dev->gro_flush_timeout);
6375+
timeout = napi_get_gro_flush_timeout(napi);
63766376
if (napi->defer_hard_irqs_count && timeout) {
63776377
hrtimer_start(&napi->timer, ns_to_ktime(timeout), HRTIMER_MODE_REL_PINNED);
63786378
skip_schedule = true;
@@ -6654,6 +6654,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
66546654
hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
66556655
napi->timer.function = napi_watchdog;
66566656
napi_set_defer_hard_irqs(napi, READ_ONCE(dev->napi_defer_hard_irqs));
6657+
napi_set_gro_flush_timeout(napi, READ_ONCE(dev->gro_flush_timeout));
66576658
init_gro_hash(napi);
66586659
napi->skb = NULL;
66596660
INIT_LIST_HEAD(&napi->rx_list);
@@ -11059,7 +11060,7 @@ void netdev_sw_irq_coalesce_default_on(struct net_device *dev)
1105911060
WARN_ON(dev->reg_state == NETREG_REGISTERED);
1106011061

1106111062
if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
11062-
dev->gro_flush_timeout = 20000;
11063+
netdev_set_gro_flush_timeout(dev, 20000);
1106311064
netdev_set_defer_hard_irqs(dev, 1);
1106411065
}
1106511066
}
@@ -12003,7 +12004,6 @@ static void __init net_dev_struct_check(void)
1200312004
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, ifindex);
1200412005
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, real_num_rx_queues);
1200512006
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, _rx);
12006-
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_flush_timeout);
1200712007
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_max_size);
1200812008
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, gro_ipv4_max_size);
1200912009
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, rx_handler);
@@ -12015,7 +12015,7 @@ static void __init net_dev_struct_check(void)
1201512015
#ifdef CONFIG_NET_XGRESS
1201612016
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_rx, tcx_ingress);
1201712017
#endif
12018-
CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 100);
12018+
CACHELINE_ASSERT_GROUP_SIZE(struct net_device, net_device_read_rx, 92);
1201912019
}
1202012020

1202112021
/*

net/core/dev.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,46 @@ static inline void netdev_set_defer_hard_irqs(struct net_device *netdev,
184184
napi_set_defer_hard_irqs(napi, defer);
185185
}
186186

187+
/**
188+
* napi_get_gro_flush_timeout - get the gro_flush_timeout
189+
* @n: napi struct to get the gro_flush_timeout from
190+
*
191+
* Return: the per-NAPI value of the gro_flush_timeout field.
192+
*/
193+
static inline unsigned long
194+
napi_get_gro_flush_timeout(const struct napi_struct *n)
195+
{
196+
return READ_ONCE(n->gro_flush_timeout);
197+
}
198+
199+
/**
200+
* napi_set_gro_flush_timeout - set the gro_flush_timeout for a napi
201+
* @n: napi struct to set the gro_flush_timeout
202+
* @timeout: timeout value to set
203+
*
204+
* napi_set_gro_flush_timeout sets the per-NAPI gro_flush_timeout
205+
*/
206+
static inline void napi_set_gro_flush_timeout(struct napi_struct *n,
207+
unsigned long timeout)
208+
{
209+
WRITE_ONCE(n->gro_flush_timeout, timeout);
210+
}
211+
212+
/**
213+
* netdev_set_gro_flush_timeout - set gro_flush_timeout of a netdev's NAPIs
214+
* @netdev: the net_device for which all NAPIs will have gro_flush_timeout set
215+
* @timeout: the timeout value to set
216+
*/
217+
static inline void netdev_set_gro_flush_timeout(struct net_device *netdev,
218+
unsigned long timeout)
219+
{
220+
struct napi_struct *napi;
221+
222+
WRITE_ONCE(netdev->gro_flush_timeout, timeout);
223+
list_for_each_entry(napi, &netdev->napi_list, dev_list)
224+
napi_set_gro_flush_timeout(napi, timeout);
225+
}
226+
187227
int rps_cpumask_housekeeping(struct cpumask *mask);
188228

189229
#if defined(CONFIG_DEBUG_NET) && defined(CONFIG_BPF_SYSCALL)

net/core/net-sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ NETDEVICE_SHOW_RW(tx_queue_len, fmt_dec);
409409

410410
static int change_gro_flush_timeout(struct net_device *dev, unsigned long val)
411411
{
412-
WRITE_ONCE(dev->gro_flush_timeout, val);
412+
netdev_set_gro_flush_timeout(dev, val);
413413
return 0;
414414
}
415415

0 commit comments

Comments
 (0)