Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3536913rwo; Fri, 4 Aug 2023 06:29:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGE+zVTAd9J5XmarHPEtoHPp4KNqS/V5nWjVbnPX7KdR/H2GA2B1ctJGEHaWAYLf5fCd1fq X-Received: by 2002:a05:6a00:b84:b0:67d:22a6:2f54 with SMTP id g4-20020a056a000b8400b0067d22a62f54mr1860903pfj.31.1691155780014; Fri, 04 Aug 2023 06:29:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691155779; cv=none; d=google.com; s=arc-20160816; b=IME4/Waul3KUX+1Ee0yQvI7+twnMZcQX1/dWrZLrFfBOLxxDpUhrX1wS65+1DQJi+A 9i1q5EWpDuq8OckbF4NqHOcVeH8Ky5cgtFEbZ6Ym+SKnrKL68EUuQU4/AzyPjzg3pxcB AHopWUix0tOuJQn8CAFnhbiyxpK6ZRN95eapjwB/H1JJ1GEdbrDZF0FY2+wh97uCfbwl wuHVi+ZrRjHdL4v6iQZIL664SGJlzVNkpxxfzbvkWCjdEqg3tjo7Fe47mIj7Vf6jsz9G TYtRLzQs5018XZODcU01ZsOGiKFjImvmsJDTL8cQRBCubWMFWIiZSBKmpJZwkR5zcNWf v5Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=u9DRriWNDJonfqILcAsrrLxxJbWS0AzfymHX8jUCjo8=; fh=w7Jnui2cUMiTJ2TUWQmWTtlLGVu4EPXAehuv8FR1tDs=; b=X+l56F+FD7T9cJX1imEaXYqwbHKcIZHpINE6HzsAc33eDa5LRgwzqgdaxod0gFESZr M21QEMLi2V2pJNuAiEJ4r4xwuHvHMEnKGZOfB79oRw6KydOildcfwRPQhDkcfPQFVRt0 Q+nIcm4R6hzGQ2jmkHJEuj5d+9mAynQxJNXaGVTCFWI4r2mYJGOYyrgmN0BuwzchuZIH dov54hFT73qlMXqLepYLuf4tsv6ZzNMGxUSXxBEIChY0xAkKybnJsRkbwFw/g6BxVc3V vxkPNIKbQKa7mp14U8/DWRfVnbIV9u/9HB5vtEBxqeCKESXcqAf2o1beKzpZv1LGe8Oj mXhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fk745ond; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a6543c7000000b00564b8e5521csi1546127pgp.214.2023.08.04.06.29.28; Fri, 04 Aug 2023 06:29:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fk745ond; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbjHDLa5 (ORCPT + 99 others); Fri, 4 Aug 2023 07:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbjHDLau (ORCPT ); Fri, 4 Aug 2023 07:30:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D321122 for ; Fri, 4 Aug 2023 04:30:48 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691148647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u9DRriWNDJonfqILcAsrrLxxJbWS0AzfymHX8jUCjo8=; b=fk745ondrh8eLE4m+TZCnu5htor3AbCLsT4+gFHOWDRVKIbdOc2TCz6/3Rf3T9RhXPsMNG +IqdHUMAIID8mVdpg3Y9QmcRvEf4at/XN1X9ZCQYAXrVspw6fUL+TdrTIWzjagne9uHgoL R2VhE9VJuQ9xSOqdTCNZYoZ7klEeTxH5DglueMXM8samBWOEi3VcICroY+KLuV0OA/05pJ O+WNMMcWkJHgRfxm2gL3I2O2seurRBpcZSLFdzWrMnWTUAg8jiGVT98xViKDo20s4XLuRw /XTSpZVmctAOtP2fIA5N36/N3omJ/I/ZBa871vz5UAqUaMpfpvZKPcOZTvy+SQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691148647; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u9DRriWNDJonfqILcAsrrLxxJbWS0AzfymHX8jUCjo8=; b=GmBffpV5Rx7yoUp7D7U90VSB2AeDuKYy9aGkOaDP6w1kbSCJCZkUAhLR0rDVNZamigz879 akaXrATbou6VVCBg== To: linux-kernel@vger.kernel.org Cc: Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Frederic Weisbecker , Ingo Molnar , John Stultz , Juri Lelli , Mel Gorman , Peter Zijlstra , Stephen Boyd , Steven Rostedt , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Sebastian Andrzej Siewior Subject: [RFC PATCH 3/3] time: Allow to preempt after a callback. Date: Fri, 4 Aug 2023 13:30:39 +0200 Message-Id: <20230804113039.419794-4-bigeasy@linutronix.de> In-Reply-To: <20230804113039.419794-1-bigeasy@linutronix.de> References: <20230804113039.419794-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The TIMER_SOFTIRQ handler invokes timer callbacks of the expired timers. Before each invocation the timer_base::lock is dropped. The only lock that is still held is the timer_base::expiry_lock and the per-CPU bh-lock as part of local_bh_disable(). The former is released as part of lock up prevention if the timer is preempted by the caller which is waiting for its completion. Both locks are already released as part of timer_sync_wait_running(). This can be extended by also releasing in bh-lock. The timer core does not rely on any state that is serialized by the bh-lock. The timer callback expects the bh-state to be serialized by the lock but there is no need to keep state synchronized while invoking multiple callbacks. Preempt handling softirqs and release all locks after a timer invocation if the current has inherited priority. Signed-off-by: Sebastian Andrzej Siewior --- kernel/time/timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 63a8ce7177dd4..b76856bc2edd2 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1470,9 +1470,16 @@ static inline void timer_base_unlock_expiry(struct t= imer_base *base) */ static void timer_sync_wait_running(struct timer_base *base) { - if (atomic_read(&base->timer_waiters)) { + bool need_preempt; + + need_preempt =3D task_is_pi_boosted(current); + if (need_preempt || atomic_read(&base->timer_waiters)) { raw_spin_unlock_irq(&base->lock); spin_unlock(&base->expiry_lock); + + if (need_preempt) + softirq_preempt(); + spin_lock(&base->expiry_lock); raw_spin_lock_irq(&base->lock); } --=20 2.40.1