From patchwork Fri Aug 4 11:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 131201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp309161vqb; Fri, 4 Aug 2023 07:41:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpu8nQdM2CGOO91wiD2j2N9286r0yo1UgRtTMVzQF0QYGF0GhQcvy4zbcwe0vx9a119IVt X-Received: by 2002:a05:6a00:1345:b0:682:4ef7:9b17 with SMTP id k5-20020a056a00134500b006824ef79b17mr2038309pfu.32.1691160067398; Fri, 04 Aug 2023 07:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691160067; cv=none; d=google.com; s=arc-20160816; b=Xupnh8VkMKP1jgcH7zwGJ8S7OpCevDkTjBlpL26aAkfH8aVBv+dxlBfzydAhT0yTPX GhUxYeG0b5oZvkJhmpbAnJ7mfQBNmZKTgJhrwk/mX6HUMHX8QG+R92akgp0yVuat7mkz Ii0KFUJiCTF666W4Z7iuU8izISDJGnql/JwST06KwuN/lkhDarlEehocGiwGHNdTexlC Ypw+twaUYKVdc7xmh1ApCnbm+ApUpr4nMmPwewMVOkoBv6WKwMLxlx6szk4UTWcuC2Ay v5RxFhxB+8frnXR+oTIzJAjQ0+2ZCACGFK2qC50n6onKwLXOL96DknzjZblWXc1w0aJc +dRw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bq26-20020a056a000e1a00b006872089fa3fsi1782020pfb.283.2023.08.04.07.40.03; Fri, 04 Aug 2023 07:41:07 -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 S230375AbjHDLbA (ORCPT + 99 others); Fri, 4 Aug 2023 07:31:00 -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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773309858981131625 X-GMAIL-MSGID: 1773309858981131625 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) #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 #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 int cnt) } EXPORT_SYMBOL(__local_bh_enable_ip); +void softirq_preempt(void) +{ + if (WARN_ON_ONCE(!preemptible())) + return; + + if (WARN_ON_ONCE(__this_cpu_read(softirq_ctrl.cnt) != 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.