Received: by 10.223.176.46 with SMTP id f43csp1165660wra; Fri, 19 Jan 2018 07:47:48 -0800 (PST) X-Google-Smtp-Source: ACJfBosrd4yHwJFSdJSTDDGOBpkg9BfDXKd8DuBpNVWI/FDPiSaSG4iAc0Eb2219rb3Q68PILPOq X-Received: by 10.99.4.198 with SMTP id 189mr37867871pge.210.1516376868851; Fri, 19 Jan 2018 07:47:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516376868; cv=none; d=google.com; s=arc-20160816; b=DkmwF3VqUuo8Nnf1/TxyDZfHsCpVX7RXymwUvT2Blceb/pITIEHX8cXREQ2sjiPEbs XM3TkhziCU59rLsAvXYgd6k5AzOuVxlBQlFcsyd6iw4v+NngUg87LP9Pr49crx7ZXk6u gXGvAXKciil+HXsJvfIzrskJw8wmO4shdxlUlvl6oT7zUdKz+M919pBpOYuEwq4PHGJ7 GdNlxk8VRMzgrTtCrmtigweTzI0Q3EWhC0D8qvD2oB+hUD+iK6/UDbxT6gwY6TIZx9vy ON8/va8APi9VI7OoKpAn3CYNkEXhkibU2ARN6d3abfNk88e9PRVTQQRL3WQcDAw38y+O /Dig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:arc-authentication-results; bh=iV5DNTtDYfURL8pv0wqjhRJuYAvZh+WzXpTSNSslTbM=; b=N0uPGSUaZAFRxhwKUxDIs55VbtpzLN98x1DmrK/50AXyhTlcq9fbK5e6AOtBzRE83X crhpLk9h8hcz7mwq2+3Pkjf/+4vMsVSPCtlfO6QID63R8rwmYpZopMMXtyaOSEFxlryu iw2RBLp0MXsaJ/F/GxXSby3EQj87itJppxGM8kfJi5F6gafDGh/X2HSBh9w/huqqxq2e AMDfzspstECL+wwayaQdtAMtByhxt2Qm3nTbfb4AYjR2c2jUcDwxQZ8L6x0Ms3udn4Jv 6q5DDIOeUzI0ch0TmpfAS2xK8zWnNli9TLXffNcdCPRuqwAY8z3Md2s1Yq8r/Ez8iSHR 6E2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3-v6si910105pld.49.2018.01.19.07.47.34; Fri, 19 Jan 2018 07:47:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756120AbeASPq4 (ORCPT + 99 others); Fri, 19 Jan 2018 10:46:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:58486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755956AbeASPq1 (ORCPT ); Fri, 19 Jan 2018 10:46:27 -0500 Received: from localhost.localdomain (i16-les03-th2-31-37-47-191.sfr.lns.abo.bbox.fr [31.37.47.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43E4121719; Fri, 19 Jan 2018 15:46:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43E4121719 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=frederic@kernel.org From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Levin Alexander , Peter Zijlstra , Mauro Carvalho Chehab , Linus Torvalds , Hannes Frederic Sowa , "Paul E . McKenney" , Wanpeng Li , Dmitry Safonov , Thomas Gleixner , Andrew Morton , Paolo Abeni , Radu Rendec , Ingo Molnar , Stanislaw Gruszka , Rik van Riel , Eric Dumazet , David Miller Subject: [RFC PATCH 1/4] softirq: Limit vector to a single iteration on IRQ tail Date: Fri, 19 Jan 2018 16:46:11 +0100 Message-Id: <1516376774-24076-2-git-send-email-frederic@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516376774-24076-1-git-send-email-frederic@kernel.org> References: <1516376774-24076-1-git-send-email-frederic@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Softirqs are currently allowed to execute as much pending work as needed as long as it doesn't overrun 10 iterations or 2 ms. The rest of the pending work is deferred to ksoftirqd beyond that limit. In fact 2 ms is a very high threshold that shouldn't be reachable after only 10 iterations. And just counting iterations doesn't help diagnose which vector forces softirqs to be deferred to a thread at the expense of other vectors that could need quick service. Instead of blindly kicking ksoftirqd when the softirq load becomes too high, we rather want to offload the culprit vector only and let the other vectors to be handled on IRQ tail as usual. To achieve this, we rather keep track of which vectors have run on past iterations and kick them off to threading if they get re-enqueued. We assume that a vector only needs one iteration on normal loads while re-enqueuing is a matter of stress, so this should be a simple yet reliable way to detect which vector needs to be queued off in a task. For now, vectors that get re-enqueued trigger ksoftirqd but they are going to be handled by per-vector workqueues on subsequent patches. Suggested-by: Linus Torvalds Signed-off-by: Frederic Weisbecker Cc: Dmitry Safonov Cc: Eric Dumazet Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Andrew Morton Cc: David Miller Cc: Hannes Frederic Sowa Cc: Ingo Molnar Cc: Levin Alexander Cc: Paolo Abeni Cc: Paul E. McKenney Cc: Radu Rendec Cc: Rik van Riel Cc: Stanislaw Gruszka Cc: Thomas Gleixner Cc: Wanpeng Li Cc: Mauro Carvalho Chehab --- kernel/softirq.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/kernel/softirq.c b/kernel/softirq.c index 2f5e87f..c8c6841 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -190,22 +190,6 @@ void __local_bh_enable_ip(unsigned long ip, unsigned int cnt) } EXPORT_SYMBOL(__local_bh_enable_ip); -/* - * We restart softirq processing for at most MAX_SOFTIRQ_RESTART times, - * but break the loop if need_resched() is set or after 2 ms. - * The MAX_SOFTIRQ_TIME provides a nice upper bound in most cases, but in - * certain cases, such as stop_machine(), jiffies may cease to - * increment and so we need the MAX_SOFTIRQ_RESTART limit as - * well to make sure we eventually return from this method. - * - * These limits have been established via experimentation. - * The two things to balance is latency against fairness - - * we want to handle softirqs as soon as possible, but they - * should not be able to lock up the box. - */ -#define MAX_SOFTIRQ_TIME msecs_to_jiffies(2) -#define MAX_SOFTIRQ_RESTART 10 - #ifdef CONFIG_TRACE_IRQFLAGS /* * When we run softirqs from irq_exit() and thus on the hardirq stack we need @@ -241,12 +225,10 @@ static inline void lockdep_softirq_end(bool in_hardirq) { } asmlinkage __visible void __softirq_entry __do_softirq(void) { - unsigned long end = jiffies + MAX_SOFTIRQ_TIME; unsigned long old_flags = current->flags; - int max_restart = MAX_SOFTIRQ_RESTART; struct softirq_action *h; bool in_hardirq; - __u32 pending; + __u32 pending, executed = 0; int softirq_bit; /* @@ -284,6 +266,9 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) trace_softirq_entry(vec_nr); h->action(h); trace_softirq_exit(vec_nr); + + executed |= 1 << vec_nr; + if (unlikely(prev_count != preempt_count())) { pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n", vec_nr, softirq_to_name[vec_nr], h->action, @@ -299,11 +284,10 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) pending = local_softirq_pending(); if (pending) { - if (time_before(jiffies, end) && !need_resched() && - --max_restart) + if (pending & executed || need_resched()) + wakeup_softirqd(); + else goto restart; - - wakeup_softirqd(); } lockdep_softirq_end(in_hardirq); -- 2.7.4