Skip to content

Commit 7acf8a1

Browse files
Matthew Whiteheaddavem330
authored andcommitted
Replace 2 jiffies with sysctl netdev_budget_usecs to enable softirq tuning
Constants used for tuning are generally a bad idea, especially as hardware changes over time. Replace the constant 2 jiffies with sysctl variable netdev_budget_usecs to enable sysadmins to tune the softirq processing. Also document the variable. For example, a very fast machine might tune this to 1000 microseconds, while my regression testing 486DX-25 needs it to be 4000 microseconds on a nearly idle network to prevent time_squeeze from being incremented. Version 2: changed jiffies to microseconds for predictable units. Signed-off-by: Matthew Whitehead <tedheadster@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 20da848 commit 7acf8a1

6 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎Documentation/sysctl/net.txt‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,16 @@ netdev_budget
188188

189189
Maximum number of packets taken from all interfaces in one polling cycle (NAPI
190190
poll). In one polling cycle interfaces which are registered to polling are
191-
probed in a round-robin manner.
191+
probed in a round-robin manner. Also, a polling cycle may not exceed
192+
netdev_budget_usecs microseconds, even if netdev_budget has not been
193+
exhausted.
194+
195+
netdev_budget_usecs
196+
---------------------
197+
198+
Maximum number of microseconds in one NAPI polling cycle. Polling
199+
will exit when either netdev_budget_usecs have elapsed during the
200+
poll cycle or the number of packets processed reaches netdev_budget.
192201

193202
netdev_max_backlog
194203
------------------

‎include/linux/netdevice.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,6 +3296,7 @@ static __always_inline int ____dev_forward_skb(struct net_device *dev,
32963296
void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
32973297

32983298
extern int netdev_budget;
3299+
extern unsigned int netdev_budget_usecs;
32993300

33003301
/* Called by rtnetlink.c:rtnl_unlock() */
33013302
void netdev_run_todo(void);

‎include/uapi/linux/sysctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ enum
274274
NET_CORE_AEVENT_ETIME=20,
275275
NET_CORE_AEVENT_RSEQTH=21,
276276
NET_CORE_WARNINGS=22,
277+
NET_CORE_BUDGET_USECS=23,
277278
};
278279

279280
/* /proc/sys/net/ethernet */

‎kernel/sysctl_binary.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ static const struct bin_table bin_net_core_table[] = {
197197
{ CTL_INT, NET_CORE_AEVENT_ETIME, "xfrm_aevent_etime" },
198198
{ CTL_INT, NET_CORE_AEVENT_RSEQTH, "xfrm_aevent_rseqth" },
199199
{ CTL_INT, NET_CORE_WARNINGS, "warnings" },
200+
{ CTL_INT, NET_CORE_BUDGET_USECS, "netdev_budget_usecs" },
200201
{},
201202
};
202203

‎net/core/dev.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,7 @@ EXPORT_SYMBOL(netdev_max_backlog);
34413441

34423442
int netdev_tstamp_prequeue __read_mostly = 1;
34433443
int netdev_budget __read_mostly = 300;
3444+
unsigned int __read_mostly netdev_budget_usecs = 2000;
34443445
int weight_p __read_mostly = 64; /* old backlog weight */
34453446
int dev_weight_rx_bias __read_mostly = 1; /* bias for backlog weight */
34463447
int dev_weight_tx_bias __read_mostly = 1; /* bias for output_queue quota */
@@ -5307,7 +5308,8 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll)
53075308
static __latent_entropy void net_rx_action(struct softirq_action *h)
53085309
{
53095310
struct softnet_data *sd = this_cpu_ptr(&softnet_data);
5310-
unsigned long time_limit = jiffies + 2;
5311+
unsigned long time_limit = jiffies +
5312+
usecs_to_jiffies(netdev_budget_usecs);
53115313
int budget = netdev_budget;
53125314
LIST_HEAD(list);
53135315
LIST_HEAD(repoll);

‎net/core/sysctl_net_core.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ static struct ctl_table net_core_table[] = {
452452
.extra1 = &one,
453453
.extra2 = &max_skb_frags,
454454
},
455+
{
456+
.procname = "netdev_budget_usecs",
457+
.data = &netdev_budget_usecs,
458+
.maxlen = sizeof(unsigned int),
459+
.mode = 0644,
460+
.proc_handler = proc_dointvec_minmax,
461+
.extra1 = &zero,
462+
},
455463
{ }
456464
};
457465

0 commit comments

Comments
 (0)