From patchwork Sat Jan 19 05:56:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10771929 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 192326C2 for ; Sat, 19 Jan 2019 05:57:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04E522F03E for ; Sat, 19 Jan 2019 05:57:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA0B32F044; Sat, 19 Jan 2019 05:57:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 832572F03E for ; Sat, 19 Jan 2019 05:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vMt/R8qiaQKYuN+klNJZbjttu1qEiqj0nNRVIuk23Gg=; b=PryFBJbuqKU8Y/BQB3xpLl6WC6 NHID++exZHEtsBLTgAvIGeAhePP7DXHQsLpVSQ1MEIRdwsgP9VdVYQoPfU/an+zN8I1GpveU/kDAj Cevayiv+Ns/HWmfJ/U7N5H8PFjCNifcDFE97U+jIZIeibuFe3JDWXhqLcXZJQwzYAffGrGykZI+Kb h4jPF9tHQlS1amMs80dWnsy5bEeRHbvFaFSO74cnP1nRYtlSWoi2oWYJjSCvaMvBcccQ2yd0rBeJe Wh4aWCKbCqSSSv5Ku3sYHNtGCjosXFpSXvqJTg8aPsW9zjuLy8nJYcZiOEM3x3olY+IB4LciqR+0h zkf2VBqg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjcv-0003NK-Ry; Sat, 19 Jan 2019 05:57:05 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjct-0003Kb-2j for linux-riscv@lists.infradead.org; Sat, 19 Jan 2019 05:57:04 +0000 Received: by mail-pg1-x544.google.com with SMTP id d72so7042426pga.9 for ; Fri, 18 Jan 2019 21:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EWRMoEC/A0hBjLIZuy6KvNFGbEVqYyO/63HQJNeKmb0=; b=dZFTDj0Ya6EcAtlyUcEu4BiZbYNG/xDcT5iJvYmDrkGQLsx1DXejQXxmceFjoEp27B rbBt6MTGC3h9vVTwcfrFgIwDACfyJ4/prnj1P4FgBgeRP/aUR2Bk+BK/gB0fEe9iZWxL Lfom12NuuVYR1UWJqG/MmSIn48YChsd8IBwM2BlfRoJtEa7L6oKA7Bp9TuMKDTn+nxQ9 0mPbBjbyKs+zKiS1Sh6WCauPNnawrf/A/P7hKy+qWm05Oi8OUZfXKD+rFH2H+lXUJDP2 aXYTMzmQ520zBrK04OngyhV47E9QzRT1slgh7OJwiAAWlNCdI4T12mB1yoWjOhuAS/oX ivmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EWRMoEC/A0hBjLIZuy6KvNFGbEVqYyO/63HQJNeKmb0=; b=ABhChAImMLUkBRJ40j8Kq2vkEfz6JW+RKyJpO8h0IJvbcvolKndSnY5fx/Tn9siQzX 0cjwrU/ReAhs5kHu8CLmVKZ4GXq1qgj2aJNIUoKgHM/Q7v/qdbLk55JohcLP9VQjTNYF shnlka1F/ifANm/EsXZEC/mX9B4zdw+USM2Bf2CLeJufRC/6aW1gUKN9iKIZewWOW+yk QslkY5EqsR6Tm1A1Vy3iOTxQ93JusnqhYDjv+tHyfIS2KW++rpXsOfcD18iv52nHsD+k z9pOfgvttmylMrwCEQ/66ot5T5ZnFq2AZGXVGWQuyjIPnltnxiYeXZFJPGk6OmFMDb+6 fnLw== X-Gm-Message-State: AJcUukdik3CCFY5SQg3mXkmCJJtKXZkYU7Wnzjsh1v4DxQzSy0VupMzU 7OCkMLOW3yLF7NESAferdxkiLg== X-Google-Smtp-Source: ALg8bN61IkRQSEUTXsZ3EeWFQ05eXFxjs8Xju7PLQrVSYaHYST+20SAx2hj7YtXVuFCou/O5f2kWaQ== X-Received: by 2002:a62:ed0f:: with SMTP id u15mr21757184pfh.188.1547877421890; Fri, 18 Jan 2019 21:57:01 -0800 (PST) Received: from localhost.localdomain ([49.207.51.221]) by smtp.gmail.com with ESMTPSA id c7sm9295535pfh.18.2019.01.18.21.56.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 21:57:01 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v5 1/5] irqchip: sifive-plic: Pre-compute context hart base and enable base Date: Sat, 19 Jan 2019 11:26:21 +0530 Message-Id: <20190119055625.100054-2-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119055625.100054-1-anup@brainfault.org> References: <20190119055625.100054-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190118_215703_121630_DE2EE02F X-CRM114-Status: GOOD ( 14.28 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch does following optimizations: 1. Pre-compute hart base for each context handler 2. Pre-compute enable base for each context handler 3. Have enable lock for each context handler instead of global plic_toggle_lock Signed-off-by: Anup Patel Reviewed-by: Christoph Hellwig --- drivers/irqchip/irq-sifive-plic.c | 47 ++++++++++++++----------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 357e9daf94ae..c23a293a2aae 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -59,37 +59,28 @@ static void __iomem *plic_regs; struct plic_handler { bool present; - int ctxid; + void __iomem *hart_base; + /* + * Protect mask operations on the registers given that we can't + * assume atomic memory operations work on them. + */ + raw_spinlock_t enable_lock; + void __iomem *enable_base; }; static DEFINE_PER_CPU(struct plic_handler, plic_handlers); -static inline void __iomem *plic_hart_offset(int ctxid) -{ - return plic_regs + CONTEXT_BASE + ctxid * CONTEXT_PER_HART; -} - -static inline u32 __iomem *plic_enable_base(int ctxid) -{ - return plic_regs + ENABLE_BASE + ctxid * ENABLE_PER_HART; -} - -/* - * Protect mask operations on the registers given that we can't assume that - * atomic memory operations work on them. - */ -static DEFINE_RAW_SPINLOCK(plic_toggle_lock); - -static inline void plic_toggle(int ctxid, int hwirq, int enable) +static inline void plic_toggle(struct plic_handler *handler, + int hwirq, int enable) { - u32 __iomem *reg = plic_enable_base(ctxid) + (hwirq / 32); + u32 __iomem *reg = handler->enable_base + (hwirq / 32) * sizeof(u32); u32 hwirq_mask = 1 << (hwirq % 32); - raw_spin_lock(&plic_toggle_lock); + raw_spin_lock(&handler->enable_lock); if (enable) writel(readl(reg) | hwirq_mask, reg); else writel(readl(reg) & ~hwirq_mask, reg); - raw_spin_unlock(&plic_toggle_lock); + raw_spin_unlock(&handler->enable_lock); } static inline void plic_irq_toggle(struct irq_data *d, int enable) @@ -101,7 +92,7 @@ static inline void plic_irq_toggle(struct irq_data *d, int enable) struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); if (handler->present) - plic_toggle(handler->ctxid, d->hwirq, enable); + plic_toggle(handler, d->hwirq, enable); } } @@ -150,7 +141,7 @@ static struct irq_domain *plic_irqdomain; static void plic_handle_irq(struct pt_regs *regs) { struct plic_handler *handler = this_cpu_ptr(&plic_handlers); - void __iomem *claim = plic_hart_offset(handler->ctxid) + CONTEXT_CLAIM; + void __iomem *claim = handler->hart_base + CONTEXT_CLAIM; irq_hw_number_t hwirq; WARN_ON_ONCE(!handler->present); @@ -239,12 +230,16 @@ static int __init plic_init(struct device_node *node, cpu = riscv_hartid_to_cpuid(hartid); handler = per_cpu_ptr(&plic_handlers, cpu); handler->present = true; - handler->ctxid = i; + handler->hart_base = + plic_regs + CONTEXT_BASE + i * CONTEXT_PER_HART; + raw_spin_lock_init(&handler->enable_lock); + handler->enable_base = + plic_regs + ENABLE_BASE + i * ENABLE_PER_HART; /* priority must be > threshold to trigger an interrupt */ - writel(0, plic_hart_offset(i) + CONTEXT_THRESHOLD); + writel(0, handler->hart_base + CONTEXT_THRESHOLD); for (hwirq = 1; hwirq <= nr_irqs; hwirq++) - plic_toggle(i, hwirq, 0); + plic_toggle(handler, hwirq, 0); nr_mapped++; } From patchwork Sat Jan 19 05:56:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10771931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5CEE1580 for ; Sat, 19 Jan 2019 05:57:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B53522F03E for ; Sat, 19 Jan 2019 05:57:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A90622F051; Sat, 19 Jan 2019 05:57:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5D6422F03E for ; Sat, 19 Jan 2019 05:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8ytRvaArCk5GjPXTtmt3DJ/GWYIHScqt6rlm/9ARlQA=; b=bAeK5AhD1UQufQywSA9W3FTkEE 6NfeUQA1EeetD8Tzk+7MCXh3BDeQdhkemUQLqL1cgSEVCPZTILEbb83owTQxVC/G7zIModOGHy/p9 DZTgzyduntRtI9yQNy7/oR4C/IvMV6zQD3LcfHNWkKKthiYzAhIKauJD4UB/pJ2A52mW+zktPaysM xgH/QobLmA405dkb0Hi9k7tDgWJiEuehCyT7l5CojEp3xpKF9cIHy/HV5XfjwUiLbDOc/mSrZqjTe 7NKwQezY2P80uXGI7VHel8XzhiQSQ0bwqVtmetGp/3bltuVJ5N9b6iyQNMuWw+vMtdjcIA35MX1QJ pfIdgXxQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjd0-0003Q4-Ii; Sat, 19 Jan 2019 05:57:10 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjcy-0003P6-GS for linux-riscv@lists.infradead.org; Sat, 19 Jan 2019 05:57:09 +0000 Received: by mail-pg1-x543.google.com with SMTP id w6so7051368pgl.6 for ; Fri, 18 Jan 2019 21:57:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+5uWZcZTnUMYkzU8RtvAyOycmBx9913OmwDsy9awI1U=; b=UG1Cwrsee516w8BNGvbRF4/j28/qVMEu5Xmu/3v0qMapBN8duHPlhINsPr0igqeInS NPgRGkg9KZ8nsAKjStecrDf9Xnprj0yJ5SjQ3xMTpSoEh3SSGG1t1LfVCFx9ZmncNTnz s8vP98s8NfMgBOzXfP2Krco8Lt0ZsOU9nVN/1UmtkWVXyKKS+L/b2n962p1UpzFqVsKx YcJ/xQeczW17pxycRV2m8CU5Ek5w25C2pzOPAyC+0kXU5vcRQ+fZaZcqJGNfw/QpIHi9 j+vo3FgCN6P0aQINqz5caDxXwlXByUC1HqQ0jpAjxORchQDFMvGhCwRc4LGZWzpKep77 F+JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+5uWZcZTnUMYkzU8RtvAyOycmBx9913OmwDsy9awI1U=; b=EgEUPd/DV0B+YNJ8bpsurOhjqVYG7e5WI54H7sPdJUazfMtrvI6fEjNXi7B1cR5RWW dwd1JqHfQ+Un/3+0sPfY97/rLJFKiV+TUXvtXp1oZX8S0zrcJoyWlwOPsEP9h/IUGaET L3b8FUKp7WfL24IfhY1ZBQxvL9GFJNNVVU2C2lG2JCTKfA0QMfF2O8uthtphZmyW8iuw ngRPpqKIO7ZixDMQ0Jewbib19KbDnCb5r/eOjn4pg6gLCtVtMlq3XVqEkVWhN0If3YMP ZKGGVmNqLQkbuII/hPEjwEumPIPux5Pt1RkgL/lTp6g0iyVzxLrzbQDuZuHTnbQd2pOo aV1g== X-Gm-Message-State: AJcUukfgp+csPb4sY0KVnYo5QIfmbupOfsdK7kdmmpCCoINcLTf4N4gE SyayRxnRSv8BM6o3zZgSHxSrRg== X-Google-Smtp-Source: ALg8bN5hh8Y87U3+JnY9xdXjts/r8Nz0wxNzUFqNsbVeYHTwEhJOo+suPGf+fbnO8qNDagL61b/HMw== X-Received: by 2002:a62:9657:: with SMTP id c84mr22700141pfe.77.1547877427469; Fri, 18 Jan 2019 21:57:07 -0800 (PST) Received: from localhost.localdomain ([49.207.51.221]) by smtp.gmail.com with ESMTPSA id c7sm9295535pfh.18.2019.01.18.21.57.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 21:57:06 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v5 2/5] irqchip: sifive-plic: Don't inline plic_toggle() and plic_irq_toggle() Date: Sat, 19 Jan 2019 11:26:22 +0530 Message-Id: <20190119055625.100054-3-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119055625.100054-1-anup@brainfault.org> References: <20190119055625.100054-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190118_215708_545742_6654D40D X-CRM114-Status: GOOD ( 12.14 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The plic_toggle() uses raw_spin_lock() and plic_irq_toggle has a for loop so both these functions are not suitable for being inline hence this patch removes the inline keyword. Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index c23a293a2aae..01bbbbffbcae 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -69,8 +69,8 @@ struct plic_handler { }; static DEFINE_PER_CPU(struct plic_handler, plic_handlers); -static inline void plic_toggle(struct plic_handler *handler, - int hwirq, int enable) +static void plic_toggle(struct plic_handler *handler, + int hwirq, int enable) { u32 __iomem *reg = handler->enable_base + (hwirq / 32) * sizeof(u32); u32 hwirq_mask = 1 << (hwirq % 32); @@ -83,7 +83,7 @@ static inline void plic_toggle(struct plic_handler *handler, raw_spin_unlock(&handler->enable_lock); } -static inline void plic_irq_toggle(struct irq_data *d, int enable) +static void plic_irq_toggle(struct irq_data *d, int enable) { int cpu; From patchwork Sat Jan 19 05:56:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10771933 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 521151580 for ; Sat, 19 Jan 2019 05:57:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41AEB2F03E for ; Sat, 19 Jan 2019 05:57:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3509C2F044; Sat, 19 Jan 2019 05:57:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1A7D22F03E for ; Sat, 19 Jan 2019 05:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=gWRnVcyiWT6UQ5roJZpaiCu3Yw9WRVpIH9no9QSvZzg=; b=BATrwIDPcJy11PjHXJv1FwZXy8 vWeDkVKUaoTSqLhSzJBhkRK3bToXbJ8mHobmqguAc6uIyBt7GS6hfYPqi/TXXWDpAtl8UPdgzYlgv CsPpf0PJ4yhH9tcOmuHtWJ1c7jK97onza/LsP4AtGKPoskF5MksV5NNt3CQaXT/CFImhETyqHELsK F/9cG++ihMJ7SR1bd3GPxzO810781sjAh6UOfh+YjEkwIai1WwFeB7EhDamzY0lVe8RAfivMlVaj2 NY9EhNrpRVWOTkfJHJswbJdKCRw6zN/AjVC/cEez6cLXj62rniug2aLPc7K38ScjHeGEN9qJbmWiG /aLrvH1w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjd7-0003Tb-4U; Sat, 19 Jan 2019 05:57:17 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjd3-0003Rv-Nr for linux-riscv@lists.infradead.org; Sat, 19 Jan 2019 05:57:15 +0000 Received: by mail-pg1-x542.google.com with SMTP id z11so7067328pgu.0 for ; Fri, 18 Jan 2019 21:57:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QPq/o0R9ggNlb2oMRGbkSeTpgM0rzBY83T9WPQ+nWrg=; b=c9iglgffLpFLhSbvvzWlFeS/AvjO1P40S00smgVlLs3YsQBwjZMXqbP/aAAXhAhoaU sKCAXePv6bS9r+kmQxgtpiCwwGLxGZXp18KdPCWPBXk+TdXZmD/7a0tuyJQ0d8R87xnr Q07fJcQPr9WP5xf5QruBLirguXjfdTkl/nCWXHQXBo05DtYfxtdR562jSwn/QG2Kt4n9 SXqkAy/msiA/fclUCpM8xKtfjqpzZnHtdmGNkRFjfrx47tJrq76JfHYFCdmYsDT13s7T tdwo5AXFp3mV+gX8qwruOOmNRzuHiJz0djr8IRmL84vE+A5Lpx0b7h/WeDJGL4Spqm87 KbOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QPq/o0R9ggNlb2oMRGbkSeTpgM0rzBY83T9WPQ+nWrg=; b=ruLYGt/NmdiE5whbAz/bk4rMpr0d/JJbDB2919+HJP7t99LgLnRZH2ZTNInlNS6u3R PMjSPBy/9am8SoluAyZvyoHuokbcnphuIOwNTUqJEN7Va10VUjoicwbKm+N9vfoYgRGA PUl24RHFD3TqSLywfPF2SoOHwVX1+IdfJTwgUeCbFeGSPvw0fhwmeFLkn9m2/OM3TVrR x1RBEYCCpgQj+zfwHt7LVhUZMkG5ey1i8253OyOE91paHEjFWJ8I7/zmEqaK6baLksDx g9Es2EdEHGB7yfc2a1Joh0s1Khb4rMf7Yjs6fsZkpkR7LkGRkBa+3/agfABmva7Vp+ne 73sg== X-Gm-Message-State: AJcUukcqMkWax3JLZllt3ETSPtPw2K5Lp3SRzpFhPY0ah7L9PKP58AyP ZunEqOFDepgp6zzouuzF6dlp9Q== X-Google-Smtp-Source: ALg8bN6JYdjBjQL1iTQMTWXvrOTiU/Fa0DfbRJm4zuIRUgdZLqvPh2JyNaWwYssKxs/5vtkL9ZBrAQ== X-Received: by 2002:a63:f412:: with SMTP id g18mr20671728pgi.262.1547877432781; Fri, 18 Jan 2019 21:57:12 -0800 (PST) Received: from localhost.localdomain ([49.207.51.221]) by smtp.gmail.com with ESMTPSA id c7sm9295535pfh.18.2019.01.18.21.57.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 21:57:12 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v5 3/5] irqchip: sifive-plic: Add warning in plic_init() if handler already present Date: Sat, 19 Jan 2019 11:26:23 +0530 Message-Id: <20190119055625.100054-4-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119055625.100054-1-anup@brainfault.org> References: <20190119055625.100054-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190118_215713_823584_4435D44A X-CRM114-Status: GOOD ( 12.66 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We have two enteries (one for M-mode and another for S-mode) in the interrupts-extended DT property of PLIC DT node for each HART. It is expected that firmware/bootloader will set M-mode HWIRQ line of each HART to 0xffffffff (i.e. -1) in interrupts-extended DT property because Linux runs in S-mode only. If firmware/bootloader is buggy then it will not correctly update interrupts-extended DT property which might result in a plic_handler configured twice. This patch adds a warning in plic_init() if a plic_handler is already marked present. This warning provides us a hint about incorrectly updated interrupts-extended DT property. Signed-off-by: Anup Patel Reviewed-by: Christoph Hellwig --- drivers/irqchip/irq-sifive-plic.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 01bbbbffbcae..b9a0bcefe426 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -229,6 +229,11 @@ static int __init plic_init(struct device_node *node, cpu = riscv_hartid_to_cpuid(hartid); handler = per_cpu_ptr(&plic_handlers, cpu); + if (handler->present) { + pr_warn("handler already present for context %d.\n", i); + continue; + } + handler->present = true; handler->hart_base = plic_regs + CONTEXT_BASE + i * CONTEXT_PER_HART; From patchwork Sat Jan 19 05:56:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10771935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF6D96C2 for ; Sat, 19 Jan 2019 05:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD9792F03E for ; Sat, 19 Jan 2019 05:57:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A137E2F044; Sat, 19 Jan 2019 05:57:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4AD9A2F03E for ; Sat, 19 Jan 2019 05:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bNjnoKQr0Trgn8oabkrUsFCnbim60tnBPtd0ucE0LKo=; b=pahpbTBNIaJaQMFDYaxvQ5NNNA U1MBktBaJt6HWhdZxjSG8/XYMOGjrLvtoRM0fI1i9l4F7GHDoPXrmJor6lkVFl2eD2RhKkO6KcCHT RJ1H3kdIqQHuvVk4/HVLnPPDfwb2QKX2OldMb+fx13stje74DhXZgmYaDf47SKbYvAsBHyr2A/yHz LnNd4e4PNozk0cLqZhfVljjBXt32G46GBZ06hO7xyW79qNqe8GjSOaX/73cGaMWk5PDuS9JYGLLsN dSQ2HKHddo27VfJlMRDv4xOHWQ7azbrEmm68iry9OVqb9JCEB/l0J7w+evFOEbWbY4Ijy99UCpWaT AxiqwELA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjdA-0003WA-R4; Sat, 19 Jan 2019 05:57:20 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjd8-0003UX-8N for linux-riscv@lists.infradead.org; Sat, 19 Jan 2019 05:57:19 +0000 Received: by mail-pg1-x543.google.com with SMTP id j10so7070466pga.1 for ; Fri, 18 Jan 2019 21:57:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zz52nPvPtFJqyPj2XZVPMynhhMIZtDAuu6S8fhVpQdc=; b=f/6EgnVaPcImxeZ24fW1x3B5RgtHb20eZMqTQ96nYxSVMUllIaqDMVJprUUnRUxpsn mKCOlaefUjQF3kfbvkVxg28riYDbStDjlKgTaSm3dQD6JQpCiQKEwsv8OUl8dgawEYPo ic5/xhdDU1M0ZhHGZDicrWjpwYif6fPWPpwaDJbC1zxvXFziFUbVGlFi+7lbKOZjMHiE RydhpZA+l2O8O9BVWgo5WzkOL83oNG5WbLSb7Nc9J7/W8LDtSANpWGPGD8G5NfkIMgpm jpE1L/Hbq8tEco++PE4lo3gXhBwS/RjUyhOp6mhQdRdhG3tDcLesyYVvPTCWNPDMXRRu kRLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zz52nPvPtFJqyPj2XZVPMynhhMIZtDAuu6S8fhVpQdc=; b=UH7U10vqXJ3KI+dfDyPFZgxAvBp0Up8xLZ9LWzH5rZZh+q2lxqgeodvCtZdTAv+MTE qpbDk+waVNKKti7ElFajKD2OgNtvMI2dmYgEhPEODoL05m/cj1M4sITAWvGwX+Mff0zP yp+PLwGeeVArxYQMQ+1soSbOXWTxvnpfHUl9zfRQYX00203h0CPeRpLxpNXBvo5lsowL FkOQuvRy1MvM5iEjU8Qv9EDa6Zvpng6t6EZKeu9swifFDbglrtmBfvCCUfZ3OwyC3DI8 g/KFYj8/ojVhABcDJkl5Au5D4eCbVIcURHqTVBK/Dp9iOV+PmgFCkPokzVx0ugqZooAC ZwIQ== X-Gm-Message-State: AJcUukc3jWsQmq94Hrg0FDsHfkCPYRuaEO2t4odCkHa5BR7WaJx2mZEB pPwIMPYFC/zPpX/wzZY33BPohA== X-Google-Smtp-Source: ALg8bN5yaqJwyxbRwG4IIcWKUrLsn+0tH7+5XWFIVPrlf3zW4l96BtUsxikPVWNhTZZqfJ6OEB+Eiw== X-Received: by 2002:a63:4e15:: with SMTP id c21mr20644687pgb.50.1547877437499; Fri, 18 Jan 2019 21:57:17 -0800 (PST) Received: from localhost.localdomain ([49.207.51.221]) by smtp.gmail.com with ESMTPSA id c7sm9295535pfh.18.2019.01.18.21.57.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 21:57:16 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v5 4/5] irqchip: sifive-plic: Differentiate between PLIC handler and context Date: Sat, 19 Jan 2019 11:26:24 +0530 Message-Id: <20190119055625.100054-5-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119055625.100054-1-anup@brainfault.org> References: <20190119055625.100054-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190118_215718_293710_8682E6EB X-CRM114-Status: GOOD ( 12.79 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We explicitly differentiate between PLIC handler and context because PLIC context is for given mode of HART whereas PLIC handler is per-CPU software construct meant for handling interrupts from a particular PLIC context. To achieve this differentiation, we rename "nr_handlers" to "nr_contexts" and "nr_mapped" to "nr_handlers" in plic_init(). Signed-off-by: Anup Patel Reviewed-by: Christoph Hellwig --- drivers/irqchip/irq-sifive-plic.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index b9a0bcefe426..24c906f4be93 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -177,7 +177,7 @@ static int plic_find_hart_id(struct device_node *node) static int __init plic_init(struct device_node *node, struct device_node *parent) { - int error = 0, nr_handlers, nr_mapped = 0, i; + int error = 0, nr_contexts, nr_handlers = 0, i; u32 nr_irqs; if (plic_regs) { @@ -194,10 +194,10 @@ static int __init plic_init(struct device_node *node, if (WARN_ON(!nr_irqs)) goto out_iounmap; - nr_handlers = of_irq_count(node); - if (WARN_ON(!nr_handlers)) + nr_contexts = of_irq_count(node); + if (WARN_ON(!nr_contexts)) goto out_iounmap; - if (WARN_ON(nr_handlers < num_possible_cpus())) + if (WARN_ON(nr_contexts < num_possible_cpus())) goto out_iounmap; error = -ENOMEM; @@ -206,7 +206,7 @@ static int __init plic_init(struct device_node *node, if (WARN_ON(!plic_irqdomain)) goto out_iounmap; - for (i = 0; i < nr_handlers; i++) { + for (i = 0; i < nr_contexts; i++) { struct of_phandle_args parent; struct plic_handler *handler; irq_hw_number_t hwirq; @@ -245,11 +245,11 @@ static int __init plic_init(struct device_node *node, writel(0, handler->hart_base + CONTEXT_THRESHOLD); for (hwirq = 1; hwirq <= nr_irqs; hwirq++) plic_toggle(handler, hwirq, 0); - nr_mapped++; + nr_handlers++; } - pr_info("mapped %d interrupts to %d (out of %d) handlers.\n", - nr_irqs, nr_mapped, nr_handlers); + pr_info("mapped %d interrupts with %d handlers for %d contexts.\n", + nr_irqs, nr_handlers, nr_contexts); set_handle_irq(plic_handle_irq); return 0; From patchwork Sat Jan 19 05:56:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10771937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D871B1580 for ; Sat, 19 Jan 2019 05:57:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C73DF2F03E for ; Sat, 19 Jan 2019 05:57:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB1702F044; Sat, 19 Jan 2019 05:57:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4DBEC2F03E for ; Sat, 19 Jan 2019 05:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Rxjsi4KJprJVdSH8P88Vk9dwrr0ddxOd31Oem5ozUCQ=; b=Iume7VlcBdtaepLIgUjXnNGJi6 u1iWT1NHZoTa96ANAkbVGA5WhJ1OR95cRfMJKexQTqBEWJ2f8kxkQLU3sbyyjuofrEVRFLfb9Qg6n udVtWDCiUUllgxk+WKeV6ltu0Mk7qASNlUGfLzH9WSBT+6zFt8/but7sth/zc0QkgaqFdzl48I11+ e0dgq2zRD2Dr8jlLA+R4tIXEERxSod40kTDS5rGSV6GFYgjSOMbXQ1xi8FDS7GCLmpnxTM3h8pwAD a41oN12rBBOjq2vTCezbU8E1Klhjm+LFiy5UH/+nEK6DxjCcjEEBw4q29Mfcn+avxIVEEHWBhf5s0 wYrNMM3w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjdH-0003Zo-Mr; Sat, 19 Jan 2019 05:57:27 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gkjdF-0003Z0-6f for linux-riscv@lists.infradead.org; Sat, 19 Jan 2019 05:57:26 +0000 Received: by mail-pl1-x643.google.com with SMTP id w4so7287105plz.1 for ; Fri, 18 Jan 2019 21:57:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CjZIBVEjqmdShbw4sLzqrHILGuR+HGi+gie0rBXNKAc=; b=rBGDm4uR5MsMj4AVHwedS1S8fZWjCWGgE/axmXhYebfnuSRUr/kZ24MZPJgiXKeoLr mQ9tSSrg7kno7tuZbA1jK3fz6/DuZdXCStw7nsuEr9dVdhbemRWNvN4hcbkwD99zmds2 hZiQp0CtzXBfZIE7wJVPSPtolYA/Gpnu2OCZLNoOP/Ds/kGpAnDKjpbS1DX3gabyX0z6 BO/45ETnAB8Gu6iDoWdigvkApfiSuQAbrHdKGgB8VM/No3BZje2eRF1kO5fw//68Tgno B52mVQp6kdFVsMPBZ0fS6JFnEnG0MdCuNAqTYlGMHRtG11rWVGCJ4PX8STEo4u+IDh9e AWcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CjZIBVEjqmdShbw4sLzqrHILGuR+HGi+gie0rBXNKAc=; b=VRd2G4ZaixKLK92TggFrda2CSaHjb8yG1hLc7Bymn7cVfyXce/9B1BVwYQwZsACXnD qXr9kW3ajd7M6IPjx3LWd487O2B0iWSKGTrhFv9AKA3Lkj379bUSdBYAkWwNtDwKHjA/ u1seTHbzlCg/WMTywHINYSaubfSiCA6SNo6eeenKanT2OQcHGNmu4iRPoTjSdP1AEd8i DFrS3ddg4TY9z1l4B9Et4xByMH2CCawYkIcm4Uhfw15HaGG74yET25QSO+D+IAovm37+ SI0BPJi4FNnuPHDntdxh5nAVZ4ZU+NfbDsPEfqC8po3UGVbmQqhDgoG/SoWWcxqdA+Kr OtBg== X-Gm-Message-State: AJcUukcfwnnztmUX3j9ac/uOGBPj8mxaZyTqrnI95Y5hSm/9AU/8yK5l MSgiP8id49v0T2LXgLpPdDaJWQ== X-Google-Smtp-Source: ALg8bN4pAQmq9qeZTy/18Z5B+okIFRCgQ/SRHTp6JCBZWsGQ10lNn4bWZRRPbOeAxn5h6BSM3+kPiA== X-Received: by 2002:a17:902:29ab:: with SMTP id h40mr21767170plb.238.1547877444212; Fri, 18 Jan 2019 21:57:24 -0800 (PST) Received: from localhost.localdomain ([49.207.51.221]) by smtp.gmail.com with ESMTPSA id c7sm9295535pfh.18.2019.01.18.21.57.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 21:57:23 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v5 5/5] irqchip: sifive-plic: Implement irq_set_affinity() for SMP host Date: Sat, 19 Jan 2019 11:26:25 +0530 Message-Id: <20190119055625.100054-6-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190119055625.100054-1-anup@brainfault.org> References: <20190119055625.100054-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190118_215725_240336_6707823A X-CRM114-Status: GOOD ( 14.21 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoph Hellwig , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently on SMP host, all CPUs take external interrupts routed via PLIC. All CPUs will try to claim a given external interrupt but only one of them will succeed while other CPUs would simply resume whatever they were doing before. This means if we have N CPUs then for every external interrupt N-1 CPUs will always fail to claim it and waste their CPU time. Instead of above, external interrupts should be taken by only one CPU and we should have provision to explicitly specify IRQ affinity from kernel-space or user-space. This patch provides irq_set_affinity() implementation for PLIC driver. It also updates irq_enable() such that PLIC interrupts are only enabled for one of CPUs specified in IRQ affinity mask. With this patch in-place, we can change IRQ affinity at any-time from user-space using procfs. Example: / # cat /proc/interrupts CPU0 CPU1 CPU2 CPU3 8: 44 0 0 0 SiFive PLIC 8 virtio0 10: 48 0 0 0 SiFive PLIC 10 ttyS0 IPI0: 55 663 58 363 Rescheduling interrupts IPI1: 0 1 3 16 Function call interrupts / # / # / # echo 4 > /proc/irq/10/smp_affinity / # / # cat /proc/interrupts CPU0 CPU1 CPU2 CPU3 8: 45 0 0 0 SiFive PLIC 8 virtio0 10: 160 0 17 0 SiFive PLIC 10 ttyS0 IPI0: 68 693 77 410 Rescheduling interrupts IPI1: 0 2 3 16 Function call interrupts Signed-off-by: Anup Patel Reviewed-by: Christoph Hellwig --- drivers/irqchip/irq-sifive-plic.c | 44 ++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 24c906f4be93..e04a862c2cfb 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -83,29 +83,58 @@ static void plic_toggle(struct plic_handler *handler, raw_spin_unlock(&handler->enable_lock); } -static void plic_irq_toggle(struct irq_data *d, int enable) +static void plic_irq_toggle(const struct cpumask *mask, int hwirq, int enable) { int cpu; - writel(enable, plic_regs + PRIORITY_BASE + d->hwirq * PRIORITY_PER_ID); - for_each_cpu(cpu, irq_data_get_affinity_mask(d)) { + writel(enable, plic_regs + PRIORITY_BASE + hwirq * PRIORITY_PER_ID); + for_each_cpu(cpu, mask) { struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); if (handler->present) - plic_toggle(handler, d->hwirq, enable); + plic_toggle(handler, hwirq, enable); } } static void plic_irq_enable(struct irq_data *d) { - plic_irq_toggle(d, 1); + unsigned int cpu = cpumask_any_and(irq_data_get_affinity_mask(d), + cpu_online_mask); + if (WARN_ON_ONCE(cpu >= nr_cpu_ids)) + return; + plic_irq_toggle(cpumask_of(cpu), d->hwirq, 1); } static void plic_irq_disable(struct irq_data *d) { - plic_irq_toggle(d, 0); + plic_irq_toggle(cpu_possible_mask, d->hwirq, 0); } +#ifdef CONFIG_SMP +static int plic_set_affinity(struct irq_data *d, + const struct cpumask *mask_val, bool force) +{ + unsigned int cpu; + + if (force) + cpu = cpumask_first(mask_val); + else + cpu = cpumask_any_and(mask_val, cpu_online_mask); + + if (cpu >= nr_cpu_ids) + return -EINVAL; + + if (!irqd_irq_disabled(d)) { + plic_irq_toggle(cpu_possible_mask, d->hwirq, 0); + plic_irq_toggle(cpumask_of(cpu), d->hwirq, 1); + } + + irq_data_update_effective_affinity(d, cpumask_of(cpu)); + + return IRQ_SET_MASK_OK_DONE; +} +#endif + static struct irq_chip plic_chip = { .name = "SiFive PLIC", /* @@ -114,6 +143,9 @@ static struct irq_chip plic_chip = { */ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, +#ifdef CONFIG_SMP + .irq_set_affinity = plic_set_affinity, +#endif }; static int plic_irqdomain_map(struct irq_domain *d, unsigned int irq,