Skip to content

Commit c10d736

Browse files
Eric Dumazetdavem330
Eric Dumazet
authored andcommitted
softirq: reduce latencies
In various network workloads, __do_softirq() latencies can be up to 20 ms if HZ=1000, and 200 ms if HZ=100. This is because we iterate 10 times in the softirq dispatcher, and some actions can consume a lot of cycles. This patch changes the fallback to ksoftirqd condition to : - A time limit of 2 ms. - need_resched() being set on current task When one of this condition is met, we wakeup ksoftirqd for further softirq processing if we still have pending softirqs. Using need_resched() as the only condition can trigger RCU stalls, as we can keep BH disabled for too long. I ran several benchmarks and got no significant difference in throughput, but a very significant reduction of latencies (one order of magnitude) : In following bench, 200 antagonist "netperf -t TCP_RR" are started in background, using all available cpus. Then we start one "netperf -t TCP_RR", bound to the cpu handling the NIC IRQ (hard+soft) Before patch : # netperf -H 7.7.7.84 -t TCP_RR -T2,2 -- -k RT_LATENCY,MIN_LATENCY,MAX_LATENCY,P50_LATENCY,P90_LATENCY,P99_LATENCY,MEAN_LATENCY,STDDEV_LATENCY MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 7.7.7.84 () port 0 AF_INET : first burst 0 : cpu bind RT_LATENCY=550110.424 MIN_LATENCY=146858 MAX_LATENCY=997109 P50_LATENCY=305000 P90_LATENCY=550000 P99_LATENCY=710000 MEAN_LATENCY=376989.12 STDDEV_LATENCY=184046.92 After patch : # netperf -H 7.7.7.84 -t TCP_RR -T2,2 -- -k RT_LATENCY,MIN_LATENCY,MAX_LATENCY,P50_LATENCY,P90_LATENCY,P99_LATENCY,MEAN_LATENCY,STDDEV_LATENCY MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 7.7.7.84 () port 0 AF_INET : first burst 0 : cpu bind RT_LATENCY=40545.492 MIN_LATENCY=9834 MAX_LATENCY=78366 P50_LATENCY=33583 P90_LATENCY=59000 P99_LATENCY=69000 MEAN_LATENCY=38364.67 STDDEV_LATENCY=12865.26 Signed-off-by: Eric Dumazet <[email protected]> Cc: David Miller <[email protected]> Cc: Tom Herbert <[email protected]> Cc: Ben Hutchings <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1def923 commit c10d736

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kernel/softirq.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,21 @@ void local_bh_enable_ip(unsigned long ip)
195195
EXPORT_SYMBOL(local_bh_enable_ip);
196196

197197
/*
198-
* We restart softirq processing MAX_SOFTIRQ_RESTART times,
199-
* and we fall back to softirqd after that.
198+
* We restart softirq processing for at most 2 ms,
199+
* and if need_resched() is not set.
200200
*
201-
* This number has been established via experimentation.
201+
* These limits have been established via experimentation.
202202
* The two things to balance is latency against fairness -
203203
* we want to handle softirqs as soon as possible, but they
204204
* should not be able to lock up the box.
205205
*/
206-
#define MAX_SOFTIRQ_RESTART 10
206+
#define MAX_SOFTIRQ_TIME msecs_to_jiffies(2)
207207

208208
asmlinkage void __do_softirq(void)
209209
{
210210
struct softirq_action *h;
211211
__u32 pending;
212-
int max_restart = MAX_SOFTIRQ_RESTART;
212+
unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
213213
int cpu;
214214
unsigned long old_flags = current->flags;
215215

@@ -264,11 +264,12 @@ asmlinkage void __do_softirq(void)
264264
local_irq_disable();
265265

266266
pending = local_softirq_pending();
267-
if (pending && --max_restart)
268-
goto restart;
267+
if (pending) {
268+
if (time_before(jiffies, end) && !need_resched())
269+
goto restart;
269270

270-
if (pending)
271271
wakeup_softirqd();
272+
}
272273

273274
lockdep_softirq_exit();
274275

0 commit comments

Comments
 (0)