Message ID | 20221126234134.32660-3-samuel@sholland.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4869576wrr; Sat, 26 Nov 2022 15:45:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf7CqkS1ngyNePe3993f1FwGvDVeUo3nxG/09Ql58rCVOkqWm+XriBi6agt0dtsvncc3gmJ4 X-Received: by 2002:a62:828c:0:b0:574:ae6f:61b7 with SMTP id w134-20020a62828c000000b00574ae6f61b7mr10745627pfd.26.1669506331377; Sat, 26 Nov 2022 15:45:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669506331; cv=none; d=google.com; s=arc-20160816; b=DbT6WLIMc5vq1/i9FyH0KVymQJeu1+igqcSubwOZ2O2hnd8pzk1rpdNWyXfSijFIog HP0oL6L2QHsSvr19ZjdGixcinTB6GEIwoPPOenIysNWawbJmy3tA+QJm7lZ6xeXMoYV4 7VfMQEnXphDpcle5Q3y0FYgYGmAH8/TE3YaFZhTtkQ5hFU/fOCu9X40S768gczqSecuu i8YSiH9rysAFHHinGbWd+cEM+tbV9n5K4c5y1lULJ/RtlfrfB4c+/dBXERd90iW6b+Wl SzWU4HBvM12d7SWXl+34866i5r7DJ2n+Stsbwy3+aNfE1uY9iSB/neGohks9UKpBHiWy apdQ== 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:from :feedback-id:dkim-signature:dkim-signature; bh=ZvVBWKmSl7xxBZYvHtE90BQ1WRQAgayEAOP6BQlkaCs=; b=VZbsaejm0ns+YG2fbBdBt5tY+gGPTekn40l4O7Loe09L4mOiVMPzqpRlz/LzTCKuVS SGwB0gCBV6qChE3SJiiaUlHIFbRQCDR0TsG9C3Y8V5Bs0S8tIrJ9QnlUn5lXAH9JYcNU s8VQcgqNfdToSBdW+I2BmWKIPhuAlI4KB1qohuQobTl7iYmdVBhjBgzO+9SGoM2tAxie hVoIACRG1+OLDy9QJaXr2SuFg9/IT65Rz0XIdaLijQJQjIKx5zVR/wqcrmsQdqsBaAT5 qAfjLduY5g5NCzynqZNqPUVxzmp48fdKZUdhmI4XFXRaQMHqUha7ojFF8O/IzuaaWDp5 KLGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm2 header.b="SjgYiyY/"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WCctj4ZJ; 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=NONE dis=NONE) header.from=sholland.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a17090a8a0300b002191612b405si4237892pjn.177.2022.11.26.15.45.17; Sat, 26 Nov 2022 15:45:31 -0800 (PST) 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=@sholland.org header.s=fm2 header.b="SjgYiyY/"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WCctj4ZJ; 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=NONE dis=NONE) header.from=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbiKZXlp (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Sat, 26 Nov 2022 18:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiKZXlk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 26 Nov 2022 18:41:40 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A28EEE1F for <linux-kernel@vger.kernel.org>; Sat, 26 Nov 2022 15:41:39 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 5FC1E5C0089; Sat, 26 Nov 2022 18:41:38 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sat, 26 Nov 2022 18:41:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1669506098; x=1669592498; bh=Zv VBWKmSl7xxBZYvHtE90BQ1WRQAgayEAOP6BQlkaCs=; b=SjgYiyY/+S4zUa5tKl Cq5BDioncqCbaLz6IfExhT6rEGVgTVEiY5XMUgFwJxUrObXfQLGmIwj8iQEjFKyX QrVM1/rjS5gGEMgjOQiADW+SfFvVKkzUAQgsfTl7asHghlW5mq21olV/bVA6A2EX +rnAyzBsG73Wewm01Cm/269UOTFslFtKHtzUyLm3rf7+hMf69l+EAACCbBkEqA8S VJJ8l0SlXSU/03OXmAvUlkcbFbcgupNce2G029DKafKMuJtbvEaec+jcpxRGnhMy yHhbomkpg4kiBweYpEGKwaqaWRO7V22WfVSdFiZ3svsH4Rid8ccWx20KXWBc3u4r Lg6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1669506098; x=1669592498; bh=ZvVBWKmSl7xxB ZYvHtE90BQ1WRQAgayEAOP6BQlkaCs=; b=WCctj4ZJYSG7ke3JogAFaH9a/pYC/ 7GsYbN8g6AALi2DTzuxojVpXOnPUqvm03CjDmT8fdPfOKZGChQsXe7wrRhMSnnC9 49qvAadRQP8i2yzKoiG81avxhxdTQahft6x7+EiSuZawW5n8/8/olEOxL+Hfh6l2 lajEZPV3grAgD4refxGVtfE1Xgl1JUbXE/wc2ZW7VGmtU6idt0Ur5VtY6QG2SMeU JqX+J9snBGFR9lbwyASwMGoG4z1JK/0u76h+o2m9X9EHmSbTSKpkLvtYjIzSQSVK zFAePkQG5Gcr5ShRHYUezadsyK+z4tbl+LUpyi+PEwpjTPyUorcK3KWPg== X-ME-Sender: <xms:MqSCY9B-FENv_eqkZAUwGqUqD5B8sWa5g1k1AZLTdmPgAbfjPzZZsw> <xme:MqSCY7j6Xok--YmazErBxtqqZVvKCZvifdS8xDEzHdqtcGs_fuUuHslLDhSSWI3l2 Dk33wXsGU9m9FCsLQ> X-ME-Received: <xmr:MqSCY4losntSoYFpbxUgRt0fc0CFspVEAsmBOC0XZKnx3Guj96kdsFh_SUTxZxhXETx5h7wpAGplB-groRo74bfu8zbyXSEScIaG-NINJlG9NKW3VYT9zufMSEmQINbE6TF1Gw> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrieekgdduvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpedukeetueduhedtleetvefguddvvdejhfefudelgfduveeggeehgfdu feeitdevteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: <xmx:MqSCY3wEEWaUqVRcLnPDmo7IM1XgwxJjHZD74rNja4H99mruYjdMAw> <xmx:MqSCYyQV2qWEeHIH0xuB7899CoBhC36r-pPTWDS2xCLaMagUvbPRSA> <xmx:MqSCY6b078JbGq8EKCFdPKnC4WOGgVSRrlKnIS-nm7d_jo21vjAoOA> <xmx:MqSCY_IMnnEQlaG2zq3YbO5f0ghI90dn5A34o4-siQaneOUfnHrQCg> Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 26 Nov 2022 18:41:37 -0500 (EST) From: Samuel Holland <samuel@sholland.org> To: Marc Zyngier <maz@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Palmer Dabbelt <palmer@dabbelt.com> Cc: linux-riscv@lists.infradead.org, Samuel Holland <samuel@sholland.org>, Paul Walmsley <paul.walmsley@sifive.com>, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] genirq: Add support for oneshot-safe threaded EOIs Date: Sat, 26 Nov 2022 17:41:33 -0600 Message-Id: <20221126234134.32660-3-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221126234134.32660-1-samuel@sholland.org> References: <20221126234134.32660-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750604270769936875?= X-GMAIL-MSGID: =?utf-8?q?1750604270769936875?= |
Series |
genirq: oneshot-safe threaded EOIs
|
|
Commit Message
Samuel Holland
Nov. 26, 2022, 11:41 p.m. UTC
For irqchips such as the SiFive PLIC with a claim/EOI flow, each IRQ is
implicitly masked during the claim operation and unmasked after the EOI.
By delaying the EOI until after the thread runs, we can support threaded
IRQs without any explicit mask/unmask operations.
irqchips can declare this capability using the combination of flags
IRQCHIP_ONESHOT_SAFE | IRQCHIP_EOI_THREADED.
In this case, we still set IRQF_ONESHOT and thus action->thread_mask, so
we know based on desc->threads_oneshot when to send the EOI. However, we
do not set IRQS_ONESHOT, so we skip the actual mask/unmask operations.
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
kernel/irq/chip.c | 4 +++-
kernel/irq/manage.c | 15 ++++++++++-----
2 files changed, 13 insertions(+), 6 deletions(-)
Comments
Samuel! On Sat, Nov 26 2022 at 17:41, Samuel Holland wrote: > For irqchips such as the SiFive PLIC with a claim/EOI flow, each IRQ is > implicitly masked during the claim operation and unmasked after the EOI. > By delaying the EOI until after the thread runs, we can support threaded > IRQs without any explicit mask/unmask operations. > > irqchips can declare this capability using the combination of flags > IRQCHIP_ONESHOT_SAFE | IRQCHIP_EOI_THREADED. > > In this case, we still set IRQF_ONESHOT and thus action->thread_mask, so > we know based on desc->threads_oneshot when to send the EOI. However, we > do not set IRQS_ONESHOT, so we skip the actual mask/unmask operations. Lots of 'we' here. https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#changelog > diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c > index 672bad021a1f..7a4b3fa85da0 100644 > --- a/kernel/irq/chip.c > +++ b/kernel/irq/chip.c > @@ -446,7 +446,9 @@ void unmask_threaded_irq(struct irq_desc *desc) > if (chip->flags & IRQCHIP_EOI_THREADED) > chip->irq_eoi(&desc->irq_data); > > - unmask_irq(desc); > + if (!irqd_irq_disabled(&desc->irq_data) && > + (desc->istate & IRQS_ONESHOT)) > + unmask_irq(desc); > > /* > diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c > index 40fe7806cc8c..b9edb66428cd 100644 > --- a/kernel/irq/manage.c > +++ b/kernel/irq/manage.c > @@ -1074,9 +1074,10 @@ static int irq_wait_for_interrupt(struct irqaction *action) > static void irq_finalize_oneshot(struct irq_desc *desc, > struct irqaction *action) > { > - if (!(desc->istate & IRQS_ONESHOT) || > + if (!(action->flags & IRQF_ONESHOT) || > action->handler == irq_forced_secondary_handler) > return; > + > again: > chip_bus_lock(desc); > raw_spin_lock_irq(&desc->lock); > @@ -1112,8 +1113,7 @@ static void irq_finalize_oneshot(struct irq_desc *desc, > > desc->threads_oneshot &= ~action->thread_mask; > > - if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && Same undocumented change vs. disabled and EOI. It might not matter, but if something like this is changed, then it has to be done in a separate commit with a very good explanation why this is correct and not silently burried into a hodgepodge of other changes. > - irqd_irq_masked(&desc->irq_data)) > + if (!desc->threads_oneshot) > unmask_threaded_irq(desc); > > out_unlock: > @@ -1565,8 +1565,12 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) > * MSI based interrupts are per se one shot safe. Check the > * chip flags, so we can avoid the unmask dance at the end of > * the threaded handler for those. > + * > + * If IRQCHIP_EOI_THREADED is also set, we do an EOI dance > + * instead of a mask/unmask dance. > */ > - if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) > + if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE && > + !(desc->irq_data.chip->flags & IRQCHIP_EOI_THREADED)) This flag combination makes my head spin. > new->flags &= ~IRQF_ONESHOT; > > /* > @@ -1755,7 +1759,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) > if (noirqdebug) > irq_settings_set_no_debug(desc); > > - if (new->flags & IRQF_ONESHOT) > + if (new->flags & IRQF_ONESHOT && > + !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) > desc->istate |= IRQS_ONESHOT; And I really detest the resulting action to desc inconsistency: > - if (!(desc->istate & IRQS_ONESHOT) || > + if (!(action->flags & IRQF_ONESHOT) || It's clever, but completely non-obvious. So let's take a step back. You want to defer the EOI to the point where the threaded handler finishes, but you dont want the mask/unmask mechanism which is attached to IRQS_ONESHOT. So instead of playing games with IRQS_ONESHOT and IRQF_ONESHOT and creating something which cannot even be remotely followed, why not having explicit and understandable flags for theses cases. Something like the incomplete, uncompiled below. You get the idea, right? Thanks, tglx --- --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -656,23 +656,27 @@ void handle_level_irq(struct irq_desc *d } EXPORT_SYMBOL_GPL(handle_level_irq); +static inline cond_mask_eoi_irq(struct irq_desc *desc) +{ + if (desc->istate & IRQS_UNMASK_EOI_THREAD) + mask_irq(desc); +} + static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip) { - if (!(desc->istate & IRQS_ONESHOT)) { - chip->irq_eoi(&desc->irq_data); - return; - } - /* - * We need to unmask in the following cases: - * - Oneshot irq which did not wake the thread (caused by a - * spurious interrupt or a primary handler handling it - * completely). - */ - if (!irqd_irq_disabled(&desc->irq_data) && - irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) { - chip->irq_eoi(&desc->irq_data); - unmask_irq(desc); - } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) { + if (desc->istate & IRQS_UNMASK_EOI_THREAD) { + /* + * We need to EOI and unmask when the primary handler + * did not wake the thread due to a spurious interrupt or + * the primary handler handling the interrupt completely. + */ + if (!irqd_irq_disabled(&desc->irq_data) && + irqd_irq_masked(&desc->irq_data) && + !desc->threads_oneshot) { + chip->irq_eoi(&desc->irq_data); + unmask_irq(desc); + } + } else if (!(desc->istate & IRQS_EOI_THREAD) || !desc->threads_oneshot) { chip->irq_eoi(&desc->irq_data); } } @@ -708,8 +712,7 @@ void handle_fasteoi_irq(struct irq_desc } kstat_incr_irqs_this_cpu(desc); - if (desc->istate & IRQS_ONESHOT) - mask_irq(desc); + cond_mask_eoi_irq(desc); handle_irq_event(desc); @@ -1219,8 +1222,7 @@ void handle_fasteoi_ack_irq(struct irq_d } kstat_incr_irqs_this_cpu(desc); - if (desc->istate & IRQS_ONESHOT) - mask_irq(desc); + cond_mask_eoi_irq(desc); /* Start handling the irq */ desc->irq_data.chip->irq_ack(&desc->irq_data); @@ -1266,16 +1268,14 @@ void handle_fasteoi_mask_irq(struct irq_ */ if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) { desc->istate |= IRQS_PENDING; - mask_irq(desc); goto out; } kstat_incr_irqs_this_cpu(desc); - if (desc->istate & IRQS_ONESHOT) - mask_irq(desc); handle_irq_event(desc); + /* Needs more fixes ... */ cond_unmask_eoi_irq(desc, chip); raw_spin_unlock(&desc->lock); --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -53,6 +53,8 @@ enum { * IRQS_SUSPENDED - irq is suspended * IRQS_NMI - irq line is used to deliver NMIs * IRQS_SYSFS - descriptor has been added to sysfs + * IRQS_UNMASK_EOI_THREAD - EOI and unmask is deferred to the threaded handler + * IRQS_EOI_THREAD - EOI is deferred to the threaded handler */ enum { IRQS_AUTODETECT = 0x00000001, @@ -66,6 +68,8 @@ enum { IRQS_TIMINGS = 0x00001000, IRQS_NMI = 0x00002000, IRQS_SYSFS = 0x00004000, + IRQS_UNMASK_EOI_THREAD = 0x00008000, + IRQS_EOI_THREAD = 0x00010000, }; #include "debug.h"
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 672bad021a1f..7a4b3fa85da0 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -446,7 +446,9 @@ void unmask_threaded_irq(struct irq_desc *desc) if (chip->flags & IRQCHIP_EOI_THREADED) chip->irq_eoi(&desc->irq_data); - unmask_irq(desc); + if (!irqd_irq_disabled(&desc->irq_data) && + (desc->istate & IRQS_ONESHOT)) + unmask_irq(desc); } /* diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 40fe7806cc8c..b9edb66428cd 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1074,9 +1074,10 @@ static int irq_wait_for_interrupt(struct irqaction *action) static void irq_finalize_oneshot(struct irq_desc *desc, struct irqaction *action) { - if (!(desc->istate & IRQS_ONESHOT) || + if (!(action->flags & IRQF_ONESHOT) || action->handler == irq_forced_secondary_handler) return; + again: chip_bus_lock(desc); raw_spin_lock_irq(&desc->lock); @@ -1112,8 +1113,7 @@ static void irq_finalize_oneshot(struct irq_desc *desc, desc->threads_oneshot &= ~action->thread_mask; - if (!desc->threads_oneshot && !irqd_irq_disabled(&desc->irq_data) && - irqd_irq_masked(&desc->irq_data)) + if (!desc->threads_oneshot) unmask_threaded_irq(desc); out_unlock: @@ -1565,8 +1565,12 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) * MSI based interrupts are per se one shot safe. Check the * chip flags, so we can avoid the unmask dance at the end of * the threaded handler for those. + * + * If IRQCHIP_EOI_THREADED is also set, we do an EOI dance + * instead of a mask/unmask dance. */ - if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) + if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE && + !(desc->irq_data.chip->flags & IRQCHIP_EOI_THREADED)) new->flags &= ~IRQF_ONESHOT; /* @@ -1755,7 +1759,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) if (noirqdebug) irq_settings_set_no_debug(desc); - if (new->flags & IRQF_ONESHOT) + if (new->flags & IRQF_ONESHOT && + !(desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE)) desc->istate |= IRQS_ONESHOT; /* Exclude IRQ from balancing if requested */