From patchwork Tue Feb 12 12:52:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10807855 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 8895913B5 for ; Tue, 12 Feb 2019 12:53:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76B642B80F for ; Tue, 12 Feb 2019 12:53:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A70B2B815; Tue, 12 Feb 2019 12:53:14 +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 328C42B80F for ; Tue, 12 Feb 2019 12:53:13 +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=j7bqfwD8zsANAYVSRFFswVkBZKK+sFJ4tNpzbjDVXHo=; b=TxOfrzSQmTopURkSXEiO4Z9htA R93jkQgLlfURfBXGKRh9MlEGruvDCfNHKaFCel1pvC6m+mxISO8d8TZRYjSVWOyrzqQno3HKJR7F6 5JfsVXuAPY96pkT60dM9WCdDP29kcbjHJ3wtfp095F3cD/es5R2lm2D+35NviFhkLnmsIlA6Znoi5 bRh9QFpT+i8lIZgbwXcvBom2cM0u8mnTtyI2m/qoRU2G1J30KpONM1UXi0ksg9VKnt8WaEzZ5C+hn aNvEe8bUrdJd+ehtnqwO1rP10mVNbCUbzZnbbP+LJ4kDl0Y33bN4K+7LmQBfNOMb3vF2W/lRvrOgb fLiQdphw==; 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 1gtXYk-0007UT-89; Tue, 12 Feb 2019 12:53:10 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtXYf-0007So-TJ for linux-riscv@lists.infradead.org; Tue, 12 Feb 2019 12:53:08 +0000 Received: by mail-pl1-x642.google.com with SMTP id p8so1274946plo.2 for ; Tue, 12 Feb 2019 04:53:05 -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=O2ZupOs/WFdJwiPbINO+V0JVWJpBFSTcpyV82FP5qBM=; b=EdXk3o+6gdqZKzksNpcQPvKazI9T4E+YuALjwlEN4jqTM3nsgzi0G+ONOdProNnzGi MT+RIUATXqc4I7sVFHico//NN3pteF0wLMN90CiNOjMrm1AGeVmk1xNe8/7JOtb9AfFw y1T+//eYC349DP5llgisAvJZd0eCpJ3Pr6NQMpTk6856Oh4lsfgIvyqxNhFdvbvufPSA 1MV1MEnrvMFRfCKqOXuGoImmWkzasQxGSePY9a2OXjNzpBo0XueN6Y2Ihppzom+SDLaN UWcPBY8MCmof+Ocj1UhznO2it7iw0Vmt9NBd8Dfr2O1B97W/HB3khVBs1GwhAUhxpxYn MTLw== 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=O2ZupOs/WFdJwiPbINO+V0JVWJpBFSTcpyV82FP5qBM=; b=G71lMwWJc+o59Avvtv1JbbkbY/Y9RHQj2dwAgW7zfNpGwWoWSgzNYnUijcOaNUviIg GiNjUlQpy0n/rsWdaMYkW0GG92EuwJQpoSx/W1z4HuaFrYh3xtCAJ87cwj59ZOE+dFqA RMmdxj6tiHjWFJLEDke5ueKKdiBPNJS31KTcG8orQZlM7fQo0jcS7EniCYhhbLGWZW8o Sh89uYIQNgR1w8fSIEDCnrvo2xJwoa3130hQZbNmNDgtJdtgDxpWDipz/Zu/LEcZihxl PBDTOyjFlB53SQ7VkP73L3NqzJOW4kdE2NwJZ6QBOvj0kTz7jNZ6JOWGFGaz7vByQErq 3/Zw== X-Gm-Message-State: AHQUAubULVgKEoXKDfIe1PQNGpFIKb33ceTsksF9aehw0TSnKctoi8RU LAvDVhXWIOqviccIe5xkRpw7/Q== X-Google-Smtp-Source: AHgI3IbGqT57HdMf9TSaf9uzNQL4Nsb2en1MF+Af7z4R0Du5m7S1+OaE5P2A5Axwy8ck9gG8OVEDpA== X-Received: by 2002:a17:902:6a4:: with SMTP id 33mr3831492plh.99.1549975985360; Tue, 12 Feb 2019 04:53:05 -0800 (PST) Received: from localhost.localdomain ([49.207.48.205]) by smtp.gmail.com with ESMTPSA id z67sm27894828pfd.188.2019.02.12.04.53.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 04:53:04 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v6 1/4] irqchip: sifive-plic: Pre-compute context hart base and enable base Date: Tue, 12 Feb 2019 18:22:43 +0530 Message-Id: <20190212125246.69239-2-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190212125246.69239-1-anup@brainfault.org> References: <20190212125246.69239-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190212_045305_952060_F911D5D4 X-CRM114-Status: GOOD ( 14.41 ) 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 Tue Feb 12 12:52:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10807857 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 CAE01922 for ; Tue, 12 Feb 2019 12:53:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B91792B80F for ; Tue, 12 Feb 2019 12:53:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACB8C2B81B; Tue, 12 Feb 2019 12:53:17 +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 775102B80F for ; Tue, 12 Feb 2019 12:53:16 +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=kELjD4mZ6QopsqTD+7Qe6Cwg437LRd5xUnWSGAvjB+0=; b=beeXBDSiioh31evIrq2CsktQsJ 4Soz41KVMQ+Cvh9LS0GXvlAcs39HYouad+xZZ6LUdI3yNvTFU4TDAeZksn274tJEmpAHDj0KVumGQ MH3YQBuN92FCAxdIMuVDl40/icSqjU6hbPvf6oFsAqSgGIdyIBNOb1tyPgqE/v1NyYmCymBLPG6rR ckmpdkknMcNLa80QyzBqy0YxPRL4TXtqlFFao/BUog1etB1Gjdy5dXGCoMv2km/YHnVXhuEZAVsW2 wLiZEdXXK0H+7UBE218cARLAKubrCz/S3AHjA00rj5X39ziyW+WiRzcQBUqOF5oasLmnUeSKwlRdY kvGNHIaA==; 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 1gtXYn-0007XS-SE; Tue, 12 Feb 2019 12:53:13 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtXYk-0007Ul-Oz for linux-riscv@lists.infradead.org; Tue, 12 Feb 2019 12:53:12 +0000 Received: by mail-pl1-x642.google.com with SMTP id k15so1264152pls.8 for ; Tue, 12 Feb 2019 04:53:10 -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=KN7W2zftQeNZmthGr7261iLl0/Bm6gqlbkD5vYrU3Gg=; b=clu9Clm+93UAt2QM1XWrn1vYPSq8oKz3lHcIePW3ElbCv/vD1r/1EAYTg4Dsy8ZvyV PzCZ7vqUm9CIxcohKr3rfqfPZPBiNLyr9MYaqSiWF8zX9o9Kzeb00pXDXUIk+uQ+EBCF +Oh/zxkUTtWxZHDLdCNVbt4CivKTEBMeosjUlv8wIrXzaWiyN0zI26MRyg/OGMoiU84K lmDfJ6Kdqt5+hSGJg3U7R/49sSxcfwwZYCzCaKwoVLXP6n9ZeGmzQjTLQ2epB0JNxKVa WAuThza2V7FR07Xmco8aD1OZR5aLpGz2hx3HVz88gT9TklF6RP6Y/hGESlTNI28YJqah oXBA== 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=KN7W2zftQeNZmthGr7261iLl0/Bm6gqlbkD5vYrU3Gg=; b=auQuSkDFP4+YWhVwKD2TkK4FiV8pAlA1DWUdH5rS5uPi8ybGYIXSuFsuFCjtQ9M2B9 u5JjvZzDFS0mjuiQVpyxsQAkE5r92HBRmN9xfaCyUIw/xDWQV7NNLHjPEQMs3bCKYBxL vuqwnJ4WVl4NUofd6aJbNbNzhV/2XBp/VS250RU46ywNzzZYz5gWygyEj9GeqpCVl83L eJerDJWA6P8ns3jVqLbyRVEqMn+AeyJaNz4X4cbBdWrTkl6YK1O2dOjcslTEE2ajYADv 6emIJxAkI77PUsGRxAweDYhjn61o4zGEdzvJLKJgyhOA9pnSDABFcO8e2nIABwBOadCy K5aQ== X-Gm-Message-State: AHQUAuYdb9/JerPqNqEPw/MdbTVqZx3ffM3Ocd7lEXrSa+eR4/yz8a8/ RX2MC595wtAQT+LYas9GlNIrLg== X-Google-Smtp-Source: AHgI3IZXlLtSjUmye988PQqP+32ZggHZf2XeImz4rG1qXMbBln/IxB0Jf0Xl+N9odDXR/sJQCv2bCA== X-Received: by 2002:a17:902:8303:: with SMTP id bd3mr4030967plb.10.1549975990187; Tue, 12 Feb 2019 04:53:10 -0800 (PST) Received: from localhost.localdomain ([49.207.48.205]) by smtp.gmail.com with ESMTPSA id z67sm27894828pfd.188.2019.02.12.04.53.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 04:53:09 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v6 2/4] irqchip: sifive-plic: Add warning in plic_init() if handler already present Date: Tue, 12 Feb 2019 18:22:44 +0530 Message-Id: <20190212125246.69239-3-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190212125246.69239-1-anup@brainfault.org> References: <20190212125246.69239-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190212_045311_125232_8151EBD0 X-CRM114-Status: GOOD ( 12.74 ) 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 c23a293a2aae..da09f46fad64 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 Tue Feb 12 12:52:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10807859 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 10BEB922 for ; Tue, 12 Feb 2019 12:53:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F27A52B80F for ; Tue, 12 Feb 2019 12:53:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4D7C2B815; Tue, 12 Feb 2019 12:53: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 8F0EA2B80F for ; Tue, 12 Feb 2019 12:53: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=SxlTxSyCfCjQDckrc5psabEizFh+6OOayvxqlAO7XLk=; b=d9AFhtgSUPefpbOMYHbaZcKRyd rWqj63HA/Sc0JtyMzLb+1mg7WhHRJu8eECaEIMqygaJXHs1W6e1/bEJv6q99FFSu6pgGI1i/f0A+F Etctq1j+RlT6yLi2WEUUZiHhfuHHuH2/odGVeHqNn6vDyLf1KHFF7aNt7SZjXUYNQBMD63CnkjOUp WD/BWy0gMjW4GE/N0NsAx1P+9jG5qIYaH5kaGDBleHuUgA8LqREQoR1z8eTBvAdWjWYv/Wvv8g9I4 2Y/MmhTaWE3G+YPyLACpbaXKxnH9M2kp/79pTrJHDSo1rdRMJ9UUE0a3vuW9OTemOpYucvqk3t67o c119Cmyw==; 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 1gtXYs-0007bF-W7; Tue, 12 Feb 2019 12:53:18 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtXYp-0007ZF-VL for linux-riscv@lists.infradead.org; Tue, 12 Feb 2019 12:53:17 +0000 Received: by mail-pf1-x444.google.com with SMTP id n74so1249240pfi.9 for ; Tue, 12 Feb 2019 04:53:15 -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=gsJS4yIBKT28AV4SM0RQ9vanzyz+KIa+304VYw5cpNg=; b=eGeQXCrAfG8ecew51ixd+Ac7u9cHblpOfC3x2VIestEm3l6OJrv91fKp/chn7pHbmw qTGPdy7Sm2e8YJLLunTQ32oxestJRfmAdc18+vosvs0/GFLPp4q2Z8ch1aCN3r2mxUlD pLpVdysDGowHQ6fU2NRlixxGsEJfsQs80CW/IDLZIlLpN2g/ZxUMMdBPB5vi8APmxOF1 6MEW5kEnp/Vr8eTsv0FbKDaz/pUhjqs7NpfxolIO7fPBrZFgtIZgpTIF+YMC2BAPZmDM 9SfpgtsbdoOwxcKkvfSUIAgBi6e3WO7KpRog68VmEtymfcTNaf9D92zAG657pA+dxdVf 4zHw== 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=gsJS4yIBKT28AV4SM0RQ9vanzyz+KIa+304VYw5cpNg=; b=pewvAvJm/CzS1lIUdh5Q1scQcZG8rp9Ia7qr9uWMmARVZVAqxyrgAFTT6d3oaajlHf 85oLoi2BvlDLrs1TflbQnqYWVOeA8L3bZCr9eesgnxuN9yQME/5xqMKef4FavpNNI4NP uap6mb2nRiJ4oS8ZyqdWvO0pnsBJ+1l6qw47DXE5FdiLsWEgeZ42Z0g1Tp/JybPgpx9F BSfzfjgUd3AUico7cwoQd7W2ncqDxKG4cZn/NZ/K/wUjYuRPA1xZrljnJxqok6VGRX/k CWnEkCdoC1OJ/bfwLwu//FdCcZTHzvkJ0eYTYwpFDjKyuQlJOtfGNfm9AQX423bjQLqU b6Tg== X-Gm-Message-State: AHQUAuav+uyYt0AOuwM4AwZdy83LzsFUZ1ATAy0OPNc5zpGrNKy5aaCu aT/52EyyM4OaMkdKSpzKsXsIgA== X-Google-Smtp-Source: AHgI3IbZlbgAG111vB2Qds3H2DoDuEUXcMbwnPw8/9IQsf02qUY+paif0M6Mj0tE45zdvj+zjrz03g== X-Received: by 2002:a63:1544:: with SMTP id 4mr3590228pgv.290.1549975994963; Tue, 12 Feb 2019 04:53:14 -0800 (PST) Received: from localhost.localdomain ([49.207.48.205]) by smtp.gmail.com with ESMTPSA id z67sm27894828pfd.188.2019.02.12.04.53.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 04:53:14 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v6 3/4] irqchip: sifive-plic: Differentiate between PLIC handler and context Date: Tue, 12 Feb 2019 18:22:45 +0530 Message-Id: <20190212125246.69239-4-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190212125246.69239-1-anup@brainfault.org> References: <20190212125246.69239-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190212_045316_018027_99819EE9 X-CRM114-Status: GOOD ( 12.68 ) 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 da09f46fad64..542a9e4c47fc 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 Tue Feb 12 12:52:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10807861 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 09ACD13B5 for ; Tue, 12 Feb 2019 12:53:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBA842B814 for ; Tue, 12 Feb 2019 12:53:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEFDA2B81E; Tue, 12 Feb 2019 12:53:26 +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 732F42B814 for ; Tue, 12 Feb 2019 12:53:26 +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=ZuFx6u0WoT0Ul5FMwTOZWYFpB1PGZ7Fyd08kbgd4VVk=; b=rXekaKROG4tQJvyIbfmx/JJCAP ZoPtqF4sb6URjFc3xlJuyqNo7nObjUE91lMIuStBG9MVGRhb16JplTTx0gAqCVoEM7t6Ou7ynW5oj 5eWHo8XNRr7pYk3c9o7ZScSeD62M6vN3+GUt+QlnbgObEKbTog6zSCofZZAOs5kw5pv1ZcFQ3eFOQ oUKMGY2LLWto29NyPxgOOHarGrdBbEbNo92SRpekT8g5TAqSz5h4IBQtts03QSnS8HT9ih6xUpnSo fzZEIEdQt3KWrXcrF4motjTkbagICH8bcJC7ZzAgELjyQZhJRk3IplQsxe0pvXm4SCa03HglfxBPO aIQxBMgw==; 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 1gtXYx-0007eb-P9; Tue, 12 Feb 2019 12:53:23 +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 1gtXYu-0007d9-Q5 for linux-riscv@lists.infradead.org; Tue, 12 Feb 2019 12:53:22 +0000 Received: by mail-pl1-x643.google.com with SMTP id y10so1285171plp.0 for ; Tue, 12 Feb 2019 04:53:20 -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=kuVNCLAmtNZ7nQGEdg5l4VKoYRRZRzHCCstiWr3/9CU=; b=I+DbVC7/okKpwAiJJcB1GATjESetKUgkI0BoI3+DjMgrS8FUYAuRtMHAxn3ESb6CQH IuEHvlLhzRPqo4FOvyWlGTZJomz++sVlyCakfoWx/3yER5xlZxZ62KrZ0QbmF96PO+27 iHllMe7JB5y3RhqJSAio49yAL1FaJzwKGBghC9PP+S+k4ygCHo+cEQfMIlwJzaQUlwM0 fpdp0Fw5h0pKS+DR0DdanPrtIpneNmnNEb5o8o67kjCCZNFD0eUhEZp7rsur/IXxd4xR D7JKYoG3gTzBSvcbkIcPQebLGMI0M5voyRNUMMqnVjMGYqSMbn3exMOadC3jqbIEo1qN O4kQ== 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=kuVNCLAmtNZ7nQGEdg5l4VKoYRRZRzHCCstiWr3/9CU=; b=fp5W10gRdR3U7dqxIuXt7EmC0DbgeS4BP0P3Z9Q7cktYcxzDzr9+1l06RmYjY9mTqW +lfBXOSJ/frUjslv5zF1pNecyjXrgKjfzFA9D4TatcVWX5jSCfmFEmhxTgu50bPGPI9M e56I/GCCnC0MbMA4IYVbCd9OjJM11KN829k4fxJ37uBcw+WPJmQkujOJGFvnFxshk5Cx l7gKpuvMikvKwmfNM3tYLPkrw0U6hjqMjqUOJd+J/0nQvgnLumzhmDgWEpdgdHaowrdN ttAR1x2f9DTRNxH56gXCy85kB5StipZyRJCCtxoiTcHkCS7Opn4sRs4Jp01INUxaqShv 1Cgw== X-Gm-Message-State: AHQUAubTPxH/Fi/b9FpbluNvqAbY+/aMXpK4srDhYciKh0asoibWQgQy w0Ho2H/5sm3lxZVfXJMfBq8JMw== X-Google-Smtp-Source: AHgI3IYLdLL+MySfql0HYFYy9zD1GRJ8Mh86SWC5YPd157Wu6QBnP+sEFlqPdwT5SvSAuutd7b39Bw== X-Received: by 2002:a17:902:583:: with SMTP id f3mr3992870plf.202.1549976000057; Tue, 12 Feb 2019 04:53:20 -0800 (PST) Received: from localhost.localdomain ([49.207.48.205]) by smtp.gmail.com with ESMTPSA id z67sm27894828pfd.188.2019.02.12.04.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 04:53:19 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v6 4/4] irqchip: sifive-plic: Implement irq_set_affinity() for SMP host Date: Tue, 12 Feb 2019 18:22:46 +0530 Message-Id: <20190212125246.69239-5-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190212125246.69239-1-anup@brainfault.org> References: <20190212125246.69239-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190212_045320_858202_C72BC354 X-CRM114-Status: GOOD ( 14.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 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 | 45 ++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 542a9e4c47fc..5eba0713b2e1 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -83,29 +83,59 @@ 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 inline 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 +144,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,