Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3483001rwo; Fri, 4 Aug 2023 05:47:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGs54dSR+JO+TmvNeNi/73zGt0i4dgopGalr1NHjY08nPhSWrF/5crwT+s9DKAhH7N2ygKf X-Received: by 2002:a2e:3208:0:b0:2b9:4ac9:6071 with SMTP id y8-20020a2e3208000000b002b94ac96071mr1503852ljy.10.1691153239387; Fri, 04 Aug 2023 05:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691153239; cv=none; d=google.com; s=arc-20160816; b=xck4YqUpmAvBJL4QTo0oNRn0AoXEQKPvhCATGgK8MieOjxk1/t4KVKFJCKMPRib36v rxU8sr1zB4ruV3xPmf5R1sLm5QEOejTvi7KwVaB1mQncsJ/lk1UyyVOl+9uaOHPu/RYI UxpifRXUa1rHxOHSkGm/QDwg2DXeJzgap25YbwxdJs9gLmaahHkDlgbuZz0kQB/1LgDA 95oGFvQBf9HvL9jt4+aLP/mbcSjZXtwhPqzakXaXmWrxinEaLKC5QAX1m4zlfHI1FkOq RlGiJB0f8ZEUTdpKp6uIR64NMoH12d9u0QDLHT2ashE2sqFq5U0p6WwHPvEZfoaIaplM exTw== 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=pyi0hihZY2jn2pAnNhMOJoJ7pshtJwt3VPheJEyFbQY=; fh=w7Jnui2cUMiTJ2TUWQmWTtlLGVu4EPXAehuv8FR1tDs=; b=XeKWLO+iOlOsJBDPLkhKacLIMIvBozrDILzjNQG2+8XK4+w+bNLRjpHqcKAVIRJU4r juVwGPiB6qfAbLO57VUf/Gs3ctGEFMOFyXHv6FXupjwwG+dZsxNRMgPCubaveh/rnzKI UaFpfe0wqVRc0hKJr0O3Bs/CYnIRN+YIdo33Lb+j+9FycldTsP77ey37hI9nDjQGs9rN tQEUrc9a+k/SkPNGHvSM+Xxx+yJMSWwRyIpjl/TV9ll9ULENEOy23m8E5y+hL6zKfCLz 6M7Qh4uv/+7Wpl2OTiGJ/RhLvwAvJL3QGgioCjbpQQu4Rj4WsaxXHf4S4CyuqevriBQN XxdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=T1VtCb5s; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=WV6XnA1M; 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 d24-20020a170906175800b00988c051a9edsi1646975eje.651.2023.08.04.05.46.54; Fri, 04 Aug 2023 05:47:19 -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=T1VtCb5s; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=WV6XnA1M; 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 S230369AbjHDLa7 (ORCPT + 99 others); Fri, 4 Aug 2023 07:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbjHDLau (ORCPT ); Fri, 4 Aug 2023 07:30:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE67126 for ; Fri, 4 Aug 2023 04:30:49 -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=pyi0hihZY2jn2pAnNhMOJoJ7pshtJwt3VPheJEyFbQY=; b=T1VtCb5summwfo85838+uP2xHDFvzN6L8pIbSEkwnY/Bt+cKFhCDOm9QsKgH4oyCZ/7jis cdVHWkciqXSseqEOQwiDr+0vLtRzh1TBFxBElnlhE+AhRmfVBFfLxYswhBp7tk/7vWEjdh V71wZ7ucT+37ZAq7H8oGEKgfxsDBzGMFchyUMxZLF8BUr8UQZs5L8MacZjkfP4dueYS5JA eztj6HLBkd3Yy+m3AuayEymhBBb2jgCsRyXAPLSAh/r9pZLBfIG9eV4RsHIOQSVLTE7HgY HRLp90yFXYXk4bKbOByTwwYmEyrZwHwnpwmXfVz6y5HklIJWVAeZp8vFknmC2A== 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=pyi0hihZY2jn2pAnNhMOJoJ7pshtJwt3VPheJEyFbQY=; b=WV6XnA1MUccjmajKxXKw6rjDjDZMqwO4T7Nxv7DOikc6Mw/KSWSxDZE7hZL6AKXlo5BpEg ktbaUx5mCTI4yADw== 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 2/3] softirq: Add function to preempt serving softirqs. Date: Fri, 4 Aug 2023 13:30:38 +0200 Message-Id: <20230804113039.419794-3-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 Add a functionality for the softirq handler to preempt its current work if needed. The softirq core has no particular state. It reads and resets the pending softirq bits and then processes one after the other. It can already be preempted while it invokes a certain softirq handler. By enabling the BH the softirq core releases the per-CPU bh lock which serializes all softirq handler. It is safe to do as long as the code does not expect any serialisation in between. A typical scenarion would after the invocation of callback where no state needs to be preserved before the next callback is invoked. Add functionaliry to preempt the serving softirqs. Signed-off-by: Sebastian Andrzej Siewior --- include/linux/bottom_half.h | 2 ++ kernel/softirq.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/bottom_half.h b/include/linux/bottom_half.h index fc53e0ad56d90..448bbef474564 100644 --- a/include/linux/bottom_half.h +++ b/include/linux/bottom_half.h @@ -35,8 +35,10 @@ static inline void local_bh_enable(void) =20 #ifdef CONFIG_PREEMPT_RT extern bool local_bh_blocked(void); +extern void softirq_preempt(void); #else static inline bool local_bh_blocked(void) { return false; } +static inline void softirq_preempt(void) { } #endif =20 #endif /* _LINUX_BH_H */ diff --git a/kernel/softirq.c b/kernel/softirq.c index 807b34ccd7973..dd3307a619af7 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -247,6 +247,19 @@ void __local_bh_enable_ip(unsigned long ip, unsigned i= nt cnt) } EXPORT_SYMBOL(__local_bh_enable_ip); =20 +void softirq_preempt(void) +{ + if (WARN_ON_ONCE(!preemptible())) + return; + + if (WARN_ON_ONCE(__this_cpu_read(softirq_ctrl.cnt) !=3D SOFTIRQ_OFFSET)) + return; + + __local_bh_enable(SOFTIRQ_OFFSET, true); + /* preemption point */ + __local_bh_disable_ip(_RET_IP_, SOFTIRQ_OFFSET); +} + /* * Invoked from ksoftirqd_run() outside of the interrupt disabled section * to acquire the per CPU local lock for reentrancy protection. --=20 2.40.1