Received: by 10.223.185.116 with SMTP id b49csp4417169wrg; Tue, 6 Mar 2018 15:42:01 -0800 (PST) X-Google-Smtp-Source: AG47ELudlgEYap38dnlIw1NdbPjKW3mShWVqleM/GNQGZZ13RxeY9l27VEdhTgWKMk4QSXVxxQc8 X-Received: by 10.99.7.15 with SMTP id 15mr15941075pgh.388.1520379721485; Tue, 06 Mar 2018 15:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520379721; cv=none; d=google.com; s=arc-20160816; b=vLLFQZv+59SUOMZTImZSOs0F8Kn97MIoLWZ3a59oGpieUU1FfYceOoBO58hystGF2+ dT8d8tkZjgfvD1f5JzVSY/89buI2wAzc9hu/jZ+cQA7OKvotoMly6fRH5QrFGuMEL0/L 2rrn3h0zx0kOiYoLrzwobf2sJn53ycu5lX5A1+8bYCo1NMydLogOdHZyeGlUD3raWmbe DCP8okuDtHXFaFTTp3rzHMa2B+u4pN7x955eQsxvSJhwITJSovFyyZPi9X/qHk26qpZW I0sVY+Iv3nvvvC7eIv/10vhzhyZAgS8PMPf+4fGcDfuHhN10L3KuG1LvfuH8VcPifdVu +VNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=0DKHbOP2TIHOdLy5a0hB7Yfxjqx+SL0vGxIMbEEmBBQ=; b=J1DvEAeEJWFBav/DHoaDd1MW3MlRao7Cf6Xar/Pz7Rz7rWZFhH+yAZ95pHxObgoDsz TcX0yhz1ET2lzE8UqDRHVIKe357npXBLEMytt20fgOo6A0/OfhyAW19+4O5/oTKhoNTm XsbrNaVufkjKBmr7rwQrtDtU2oHUTpyLHyFLJ7Tx7t0TVG1pdUaFVvm+uvgfplUSpgai 5dhGegnBb/SJuMjOPvZkGeQ1QZ1iKAI5OQrFSGYducC84YulDHcOejIYpiv+QwdEiMvu XF8GrgKG12o1S9zX+Jnpt+lkwltcxlw/mLZhHI1u4brwT0vnJ7TKr0aX/mKpbIZ37xFh JRRQ== 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 203si6340153pfz.110.2018.03.06.15.41.46; Tue, 06 Mar 2018 15:42:01 -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 S1754108AbeCFXkP (ORCPT + 99 others); Tue, 6 Mar 2018 18:40:15 -0500 Received: from mx0a-00010702.pphosted.com ([148.163.156.75]:44716 "EHLO mx0b-00010702.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753923AbeCFXkK (ORCPT ); Tue, 6 Mar 2018 18:40:10 -0500 Received: from pps.filterd (m0098781.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w26Nagkb015485; Tue, 6 Mar 2018 17:39:57 -0600 Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by mx0a-00010702.pphosted.com with ESMTP id 2gh8xwnckb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Mar 2018 17:39:57 -0600 Received: from us-aus-exhub2.ni.corp.natinst.com (us-aus-exhub2.ni.corp.natinst.com [130.164.68.32]) by us-aus-skprod3.natinst.com (8.16.0.22/8.16.0.22) with ESMTPS id w26NduXh018431 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 6 Mar 2018 17:39:56 -0600 Received: from us-aus-exch5.ni.corp.natinst.com (130.164.68.15) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 6 Mar 2018 17:39:56 -0600 Received: from us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) by us-aus-exch5.ni.corp.natinst.com (130.164.68.15) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 6 Mar 2018 17:39:56 -0600 Received: from harisdt.amer.corp.natinst.com (130.164.49.7) by us-aus-exhub2.ni.corp.natinst.com (130.164.68.32) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Tue, 6 Mar 2018 17:39:56 -0600 From: Haris Okanovic To: , CC: , , , , , , , Subject: [PATCH v4 2/2] timers: Don't search for expired timers while TIMER_SOFTIRQ is scheduled Date: Tue, 6 Mar 2018 17:39:44 -0600 Message-ID: <20180306233944.11271-2-haris.okanovic@ni.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180306233944.11271-1-haris.okanovic@ni.com> References: <20180306233944.11271-1-haris.okanovic@ni.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-06_13:,, signatures=0 X-Proofpoint-Spam-Reason: safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change avoid needlessly searching for more timers in run_local_timers() (hard interrupt context) when they can't fire. For example, when ktimersoftd/run_timer_softirq() is scheduled but preempted due to cpu contention. When it runs, run_timer_softirq() will discover newly expired timers up to current jiffies in addition to firing previously expired timers. However, this change also adds an edge case where non-hrtimer firing is sometimes delayed by an additional tick. This is acceptable since we don't make latency guarantees for non-hrtimers and would prefer to minimize hard interrupt time instead. Signed-off-by: Haris Okanovic --- [PATCH v3] - Split block_softirq into separate commit [PATCH v4] - Rebase onto v4.14.20-rt17 https://github.com/harisokanovic/linux/tree/dev/hokanovi/timer-peek-v6 --- kernel/time/timer.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 98e952a6428d..5687e9bcf378 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -207,6 +207,7 @@ struct timer_base { unsigned int cpu; bool is_idle; bool must_forward_clk; + bool block_softirq; DECLARE_BITMAP(pending_map, WHEEL_SIZE); struct hlist_head vectors[WHEEL_SIZE]; struct hlist_head expired_lists[LVL_DEPTH]; @@ -1404,9 +1405,11 @@ static int __collect_expired_timers(struct timer_base *base) /* * expire_timers() must be called at least once before we can - * collect more timers. + * collect more timers. We should never hit this case unless + * TIMER_SOFTIRQ got raised without expired timers. */ - if (base->expired_levels) + if (WARN_ONCE(base->expired_levels, + "Must expire collected timers before collecting more")) return base->expired_levels; clk = base->clk; @@ -1748,6 +1751,9 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h) __run_timers(base); if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF])); + + /* Allow new TIMER_SOFTIRQs to get scheduled by run_local_timers() */ + base->block_softirq = false; } /* @@ -1758,6 +1764,14 @@ void run_local_timers(void) struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); hrtimer_run_queues(); + + /* + * Skip if TIMER_SOFTIRQ is already running on this CPU, since it + * will find and expire all timers up to current jiffies. + */ + if (base->block_softirq) + return; + /* Raise the softirq only if required. */ if (time_before(jiffies, base->clk) || !tick_find_expired(base)) { if (!IS_ENABLED(CONFIG_NO_HZ_COMMON)) @@ -1766,7 +1780,10 @@ void run_local_timers(void) base++; if (time_before(jiffies, base->clk) || !tick_find_expired(base)) return; + base--; } + + base->block_softirq = true; raise_softirq(TIMER_SOFTIRQ); } -- 2.15.1