From patchwork Thu Dec 27 11:18:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10743637 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 CF4006C2 for ; Thu, 27 Dec 2018 11:18:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA5AD27DCD for ; Thu, 27 Dec 2018 11:18:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC8A42811E; Thu, 27 Dec 2018 11:18:55 +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 438BF27DCD for ; Thu, 27 Dec 2018 11:18:55 +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=MeJG2M4NMoakJF14aoYZzB3Dws y+7lGkAN16+udkaySuum8R/TZw6cpcpFktemgy1HawUNMKZU8JK2V4Qj36Oy7QDAhFZoS5cEXmnvn jnSFhnLyPC+8bHhiT5vyGETK3GRO4U7QeTT0rZx1LZ+qAqRfyJzRVsqiLwwIms07/WGBcxyzK5PEK jPHD52VGvPI856EK+GP8bj6soKUERxBaXZNH4OTPVSnd7nK6wDyuwib5rUK31Swvta2f7/baT/dxx 2f21m9ockcNHJQ8v/yYgxbrJ6gjSnV7VN7uEpij+6aD9IBYeNpTCmM498H0X34pD7lAFuDRQdH77O 3CsXvAVg==; 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 1gcTgk-0001ok-BV; Thu, 27 Dec 2018 11:18:54 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcTgh-0001lR-HP for linux-riscv@lists.infradead.org; Thu, 27 Dec 2018 11:18:52 +0000 Received: by mail-pg1-x541.google.com with SMTP id g189so8694859pgc.5 for ; Thu, 27 Dec 2018 03:18:41 -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=n/d3YUhZCxj7eZFrEZNSG181qtPIVM9yoXtg+iIHfEprSrzlTFU+Y6dnLD0tX8K3+y j0v3hhLU2YBgUsK5Olw43hiIO77qcYRuqxCkzNB5OYOwgl2GRrrejFLZipAw0VMV+PMI dDAeuDEDSaAoESR1bIByMBMGlqbD3wJiTJXo0qXNyZVN0vxm6Pt788t1Y0y7jy0/HW+6 SExQXa6/7UgKU84z33sTDpfFd4hAWM7+X7Gz1au4UntP4SQRr9XCG4N3DvVUR9/SQiDr 2WvJ2c4OZm/6LV2TGXuzMMecfKJbYCjNxWnamCkm9grVjbAKZmk9LpASFIkkZVBDx2mF /E2A== 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=MSDBRkayi7dkDzUx6C1NwG0fk0UFs4aPDM27oUvYDQhqZ7EJKHqsEQhsGx2UfkdzcS MwI612AwUDAHyjZrEJ9g1Wbk3uxtnCMi8yQcyVktZZ7IqzE8hLElOJXuXspzWTfEW/s7 0Cs4PD1hsKN369Hm+6cHUkVWB/M5lfA3xZWMgd+9+VvTEeIJlI0Nx0dnFY3gbDSSsxvh VPk6lpgSWwigJob4ETynSlCxoK0rKvzGk7ycS0kQwzShQs2jlYjHtCVMpn/cNuffR+Z4 QFKiBj5MfS+uYZLur8wY4y7rCod+/Zx42Tm1bp+Avf1axgUs9hatEiQnvldWNrHfmbrg kZlQ== X-Gm-Message-State: AA+aEWbjE8NYnAxcznImTpPGFS4fhNeBX/FpQc2rau/XQFKMFA/RxrKn hdg1GT2WXXKsFONhhuDYiPuLpA== X-Google-Smtp-Source: AFSGD/UYGcQ9bKMI7TC+KNrvXccHJMd+rk2BtjFCExFwLt2vxNaMFzuyV6LID0v9fU34hzRsRBm3Ew== X-Received: by 2002:a62:29c3:: with SMTP id p186mr24144025pfp.117.1545909520438; Thu, 27 Dec 2018 03:18:40 -0800 (PST) Received: from localhost.localdomain ([106.51.18.57]) by smtp.gmail.com with ESMTPSA id u137sm66830105pfc.140.2018.12.27.03.18.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 03:18:39 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v4 1/5] irqchip: sifive-plic: Pre-compute context hart base and enable base Date: Thu, 27 Dec 2018 16:48:17 +0530 Message-Id: <20181227111821.80908-2-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181227111821.80908-1-anup@brainfault.org> References: <20181227111821.80908-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181227_031851_578073_08B273A1 X-CRM114-Status: GOOD ( 14.58 ) 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 --- 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 Thu Dec 27 11:18:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10743639 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 EC25D746 for ; Thu, 27 Dec 2018 11:19:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAC3F27DCD for ; Thu, 27 Dec 2018 11:19:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEC522811E; Thu, 27 Dec 2018 11:19:00 +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 87D0027DCD for ; Thu, 27 Dec 2018 11:19:00 +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=q3u+1tFuQISdepLgC3idVhsNFl bHUcK/j9PBYizkS3587rYc7LV5XPD866TtdUkev8lTs5G7oZY4qEaEMMlcAD0vNOCTUv/EOTyB8YV JQEQZOfFp1oO699GiqwKdvIuy7+wubgqCekgYEYy3aaPPygFh8VHbTPX/XIFWJNwswHsPX8aBfaA9 CqeOyTGuSns3aXL5SVlruxFKfcVfEKfZXmqbubqh4gnuXHrHmwr6MHqFsZpGmKhwpQnecsXisfbdE erClfIeP68S6Y5e7i8z44RkFS0ROZjYy2baSPkVRuLFeMfgT38o3LMeZtbrdr90qej7dC+FPwVtt/ dFqlBmDA==; 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 1gcTgp-0001rW-TR; Thu, 27 Dec 2018 11:18:59 +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 1gcTgm-0001lb-VR for linux-riscv@lists.infradead.org; Thu, 27 Dec 2018 11:18:58 +0000 Received: by mail-pl1-x642.google.com with SMTP id t13so8654853ply.13 for ; Thu, 27 Dec 2018 03:18:46 -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=RPLOhyn/ZPA2uv/yy5Ps3MLS8pYzhJpuRGoYpUltMvA6vmE58mz/LR/r1hDTPVthSj wHGROTGJdjpsCWsgskJLyojRNfU7ydpY0jwwlthiqaeA7ryGWUZQ0+ahPQxH01AuRTK+ 3Hx+FRHvO17LmtAdp0rtTqkTHKt3Pp98ijHkvLgwjjcQhEzIhcsmc8gtkuyDxHWBxbcg pHPML8c+qjRlbe3ieZ3HzN4Do+e99/MEaL56gUPQZ0f96tG7hwfGNV6fljrIzREvrIAx AReHwez1qL0cACgKMP3B4o2k9mBXWfPPsTJh09+CSLvuZTfs5lvmclBE9fHNhj4PclHC 9ptw== 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=RNJ6hMFoV+evAetSUc5fPfIK1b/zrzdWaBwazAcSYMe/jFmqw2yuSWp4dxfHLhhoSl eMqLQrFiYaU3Ep/tv3Ko+EV0ncdz/YIbx15IuPZpXQs6cZGO/4m+pDLGJD16Hty00s3b QoT6mZCoU2EcD3kGworCUi87Lsc7RSYOHZlQYRSzT3EGU0YsQKUckA8zVuSPnoWExWEQ UKtnQggmGpPk271/EYKDB/+QoK6VhOkHBS/3UVDd025fV6goMVRwUwgeoNmZdfSnnv83 V73RflehnbvKPYh8ILqka9RpZkxUz09F0CLRhEcU9iPxdnKlI6N0iYlS+dx/Pyt+gNpa bHRQ== X-Gm-Message-State: AJcUukc8dXyVBhelI+Z9M7kw+1ccYWgf5W9KAXhTzY6908Rfr41aF8Qr sCk4Lwq/q+qUzdIXHy5N6V6UEA== X-Google-Smtp-Source: ALg8bN4uDjWy44begQ0XzSRbv3KTSIhfATFvV2tBrQMSIeY9rDgNimTI//oKqEcn50oITn7TDtNGQg== X-Received: by 2002:a17:902:8541:: with SMTP id d1mr23693793plo.205.1545909525948; Thu, 27 Dec 2018 03:18:45 -0800 (PST) Received: from localhost.localdomain ([106.51.18.57]) by smtp.gmail.com with ESMTPSA id u137sm66830105pfc.140.2018.12.27.03.18.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 03:18:45 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v4 2/5] irqchip: sifive-plic: Don't inline plic_toggle() and plic_irq_toggle() Date: Thu, 27 Dec 2018 16:48:18 +0530 Message-Id: <20181227111821.80908-3-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181227111821.80908-1-anup@brainfault.org> References: <20181227111821.80908-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181227_031857_006914_2AE1AC8A X-CRM114-Status: GOOD ( 12.25 ) 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 Thu Dec 27 11:18:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10743641 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 6F8AA746 for ; Thu, 27 Dec 2018 11:19:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 514CF27DCD for ; Thu, 27 Dec 2018 11:19:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45A6E2811E; Thu, 27 Dec 2018 11:19: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 E867727DCD for ; Thu, 27 Dec 2018 11:19:05 +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=naLzs6dHO3NH+LTvY33gFK4Hev PFtPa/2p5IPnKs29Rd6G21lO+XPUR01+YlN/o2OIN8GKpj2GnaUtvakOy1/Fy9g56uRFibFx9Od3+ +1uWPx5Ms12XOZ3AUkG7LX0BWrS9lsOAgLmyXlnfesW4xZL7T1oIHkWhC/oYClPeenshekMQvQhi5 yaqMUyzyz4uM9tKjZJq2aGBI1uGCcKeiutouPsIG+p7ygWj/fdgsne3miPRnWtcx3/pVYSGpmmLuz y2u0CMIRoWKFJJ8ltWR0ElnNc6E4c/KyQLIbTjRq7MZs+7fzUM0ny7tFEv0YE5B3Um+qAKWbfEB9x 4xuoNWWw==; 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 1gcTgv-0001uP-FC; Thu, 27 Dec 2018 11:19:05 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcTgt-0001oE-0z for linux-riscv@lists.infradead.org; Thu, 27 Dec 2018 11:19:04 +0000 Received: by mail-pf1-x443.google.com with SMTP id 64so9034451pfr.9 for ; Thu, 27 Dec 2018 03:18:52 -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=Yo59uPbkTm9SD+5pdmZ9lP2fnSUyBZoPxA9s9sXRsD+bXFsq2OpX1UGgalJre/PPrH cJ3I1nj1g+yzMjjmpckYPP3FYKhZIDIW+DTgHTqnctPT28xIQuPPyQgbgIpqvXwAnqZT gl6Tkio30HoAVY7uyXrJllGTTdhGrpunF35YJgVwz4uoeKorUJT7JdI68AkTB4ZxLzRF VgdfOvdiQet9jrG/p4XJ+Y8wwyCUUqhuLav6pSm6xJqV7oUYEwbXP/ZARzdZMpMi4K/2 z71YvBGbaDho9bbVBFtOXPcFpQi+bW5zYYQ2fhN2Xel/0CaQFXPNyA/Qw8nHVfSilrgg Sq1Q== 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=izJibyx9AIfnQWSUx7udZzgxZAR5q5WdMcp9VYzIJHOk1xQxg5My+cu9VtqTVgJ8YZ J4jd2+R0sKaQfgOTSn+510P/k0rkubjG5Tp9UkNiQkiTF50aFjmCUoS3ChppZ1ZnlMMV RpwOfkoSQQt04fk8SwFVGB0CNVbCJwmJyZprmuXeBO5qzkwWsIoTtDV6kqpDQpBEKPT8 HZacOy30/YYGjc1x8LLWE9AkRQz+Xa/rSrCG8u4f26ylw2IW/ihpQFKIYS1ZWquisq3R sS1bH6MQN6+cr6jf3Ip95H5BQiowNMAvWOJKRuph24NO9Dm3FnKL958uIInQ+KeykpE8 wJLg== X-Gm-Message-State: AJcUukcpduWPycFLiHvRVzFRZ1jSej9rzjGRGBOjM6N4/4MY/XTKdd5l akCNxR4Mg8lGGy7IOmuTj4Ytbu463+Q= X-Google-Smtp-Source: ALg8bN4bGjriTsgY8zh/M4PwKlWb+svWCY81ikwiyxUr4j0/Yi39ATET734Y2OTyaLIc0utXCX+qTQ== X-Received: by 2002:a63:cc12:: with SMTP id x18mr22086304pgf.33.1545909532096; Thu, 27 Dec 2018 03:18:52 -0800 (PST) Received: from localhost.localdomain ([106.51.18.57]) by smtp.gmail.com with ESMTPSA id u137sm66830105pfc.140.2018.12.27.03.18.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 03:18:51 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v4 3/5] irqchip: sifive-plic: Add warning in plic_init() if handler already present Date: Thu, 27 Dec 2018 16:48:19 +0530 Message-Id: <20181227111821.80908-4-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181227111821.80908-1-anup@brainfault.org> References: <20181227111821.80908-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181227_031903_066838_DEC19CAE X-CRM114-Status: GOOD ( 12.86 ) 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 Thu Dec 27 11:18:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10743643 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 2ECA16C2 for ; Thu, 27 Dec 2018 11:19:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1257327DCD for ; Thu, 27 Dec 2018 11:19:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05FA32811E; Thu, 27 Dec 2018 11:19:12 +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 A261427DCD for ; Thu, 27 Dec 2018 11:19: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=bNjnoKQr0Trgn8oabkrUsFCnbim60tnBPtd0ucE0LKo=; b=N7O2nOMgzohQ763mc4ZfqceWxF 2YXhFjzShOqMJBaajWawHvuJWN3CpQRYev74efnY/vJ2nvgVG0srhm/EOokk5T0e7NEbF1ae7D9Wo 1Af+O90N5XlumRX/IpvMH+P03zz3VC//a65Jz1pbsG1yyxHUpeJpMrxHGZ7Z68UciwIW+qpKvayZV os9bIFbdzXfMMrhrexhsqockhvP/IfSnlpdylWUqjvZ3N8m7kabV9S+kYpC6tbUFCtKRaKDM4qlmA dre5SmZZs70hSx4v8HImWBl7vDKcZPFlK56SLpoLy/E8WiwM94grrrw+QoKRK7uwJy05xOY8RoC3q AhXnqwyA==; 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 1gcTh1-0001yb-1p; Thu, 27 Dec 2018 11:19:11 +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 1gcTgx-0001r8-TQ for linux-riscv@lists.infradead.org; Thu, 27 Dec 2018 11:19:09 +0000 Received: by mail-pg1-x543.google.com with SMTP id w7so8677382pgp.13 for ; Thu, 27 Dec 2018 03:18:57 -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=WAe7HAbnm+qv9cToQwe0w2BpEYSadHAV9NFIvbw2zg8l4wmOPVaprWswj9twekOMhq rYIQVAe4LelBXZ5O2RNolRB8KvZX3BLohqDYj2UfQPTjLuDST7tmQTAide8wpveB0izD SWCZ9ew+Y7dkuDeb/WlHVcq8KJ5Xbby4pHCoulMohyW13G83jCDC7bUfqk+X3cr20Qed 0AMvDdm+wr99n1LEJaPzUVvcBK26yT7M4GLh0+Pe+DUEE589WVqpS9akf1+TLINjPWgo 0yPINXpFjw7Rzg1V7vk0PXgZRVDaMElD8E0fX8HUN4PkJv54E353XIiodNrK/NUQ1kBI N0Ig== 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=jtnVPsNbJDMXl/CHuOFStLRy+a6Ky1uxgBm7SzjzCwm04vPtLwfSoOBjLlhnWLu29n WgNVIl6L3exyMx+Z4ss7b5WQ8lQRQmYL9pVhnZYRii9ibTUPQyaup2jObUDOQENBfa9I pSHmu/lZZH2344Rqf8MXd/fxzUOfc90g49zLuzHUmGersS/hW9TiMhWE4S4o40VxPsCB nJqa9k9r1/uIi64ny4PSK3YazYc9XjhPgqUrlg5ZHiCJqycGmDtTF+KZY5vWDLD/i88x vUEu+7ehlabSCF9MelEPlTQMREDkG2qX6MAYFSwf0UlO95VaelxaUbwJlk6Y8xQJlQl4 +BnA== X-Gm-Message-State: AJcUukdsllrTCtaeFLfqXQcb+a3IsxlKmV5VZDyEHp9DOoe2Q+S1MuAB AAu5CtnGJn660as1LGfkEUg4hw== X-Google-Smtp-Source: AFSGD/X+LOHWk4aZSzbivi7mbj6HaStEZBpd4C2Oz2kwlxEufHrcAyEZmTI6ihSrnR2GfGep4DVgig== X-Received: by 2002:a62:f247:: with SMTP id y7mr23817585pfl.25.1545909536994; Thu, 27 Dec 2018 03:18:56 -0800 (PST) Received: from localhost.localdomain ([106.51.18.57]) by smtp.gmail.com with ESMTPSA id u137sm66830105pfc.140.2018.12.27.03.18.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 03:18:56 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v4 4/5] irqchip: sifive-plic: Differentiate between PLIC handler and context Date: Thu, 27 Dec 2018 16:48:20 +0530 Message-Id: <20181227111821.80908-5-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181227111821.80908-1-anup@brainfault.org> References: <20181227111821.80908-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181227_031907_949518_DF28602E X-CRM114-Status: GOOD ( 12.89 ) 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 --- 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 Thu Dec 27 11:18:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 10743645 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 D5F3E6C2 for ; Thu, 27 Dec 2018 11:19:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2D01283CA for ; Thu, 27 Dec 2018 11:19:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5F8128468; Thu, 27 Dec 2018 11:19: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 42043283CA for ; Thu, 27 Dec 2018 11:19:17 +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=gRZw3fmV73hMeGQI5RJK4WG1yRw6ICDqsfs7iA/EMp0=; b=c3nn1DSUZPH1twrvR4jGa33rZ5 leybuLvAGOcquCWJWPcfPPlSSqcrnRykq7j1IP4fzjtD+YYgIgVKZNA/iSndDqtWwOhtBGH85PQx6 sd3yKoFd0YXe+wQ5+OggtJDF1JttRsNb+Uhz+rEEFPvjBw2+k5egoo88xBURf9CSceDeHTFPE8h0d VMklEzBrqL7Av9xCSDryiTF3pXHZ8zfJz/biCjlUa9ygrG1Gj7SIdDaBTsOdmtdtSJerv3ExcYmpl rTEnmBwR4RiYApkjtHAdLRS4S2LyetN61bbefDjeOW8DLk2pqxOm0PydHP66/40j5okpR5Eaon65K A25tzswA==; 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 1gcTh6-00021I-KB; Thu, 27 Dec 2018 11:19:16 +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 1gcTh3-0001u2-Ux for linux-riscv@lists.infradead.org; Thu, 27 Dec 2018 11:19:15 +0000 Received: by mail-pl1-x643.google.com with SMTP id e5so8673209plb.5 for ; Thu, 27 Dec 2018 03:19:03 -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=BlKwaKedPU8kFUHvmSJlIsJdtI4hfi1jlcbkI/tlo30=; b=OCTZqQNw7DV07aIFDKDv0z0AYosGSiDht8YH4GvU2kpz3CNiBL+UEJve4odddSgz35 HrTMmLW7DcyUNFmnUtJIiREORENznhqnrhSyctrNA2Gzw1eRj9zlmLdal+kAee3g2Mi0 8koCENIcjxuI3FQLdwBnz7OxfIyopKmhYKbALeghp1kNVCssCGtc9AxO4BPTxNU1ra7D QECsDLI5Jtj+LpBmGH1muNPr3+VKncfNB2yy39ksn2AWT9QLUDynhzA9hPWmq0a83lW6 2OG2AAiIigPqTOF0/TxtCc0RPRem9mzLXErLwIw2YHo/pypng3bXFP9yQAeOnxAXQXPc SVug== 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=BlKwaKedPU8kFUHvmSJlIsJdtI4hfi1jlcbkI/tlo30=; b=jf3pwdCXY+v+IsDwLnmx6IbqekhIoul8wlguuWzyyBEqm5tnpfkiccV8JftUPnD6Zm 7GuozvhhdgtKj6+FvfBYyc7a//bTN4ALWftrnvHEUqMWGzKzwndwMItYofphzE856at2 V7YOBMd8GlAX8+KtqQVpSTgsruvfF/UtzH/ghfW6wLzUjsYvl37FzHXDpPxAZ3neYXQf 6E4wne1Qr+dDdMTugruEJaK6WCy3qf1v7jOit1FNH/Ys6rxst2Ab0rhOa3vSD2lmxT8p 0ttM2ee4gaHGssR42TXnM0DwD8eGaVRwoMz+NOzvkzVCz8iC2RCPReiU20Ljagpf+w2x hlIw== X-Gm-Message-State: AJcUukdfKt74S6in55xwUoUoFKnwXnO5+VfQ+/ieo5+8fX7D1eX1kIZB gyiIqM7KxBD8cZAcaZn3rW+kTA== X-Google-Smtp-Source: ALg8bN7sjGQs3LKy6zrCEASgCguLw8wUXkjefkp68QsylfpBG8VNUiOfuEzhxPFjK2ZB841oYMe6qw== X-Received: by 2002:a17:902:6a4:: with SMTP id 33mr22737414plh.99.1545909543048; Thu, 27 Dec 2018 03:19:03 -0800 (PST) Received: from localhost.localdomain ([106.51.18.57]) by smtp.gmail.com with ESMTPSA id u137sm66830105pfc.140.2018.12.27.03.18.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 03:19:02 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v4 5/5] irqchip: sifive-plic: Implement irq_set_affinity() for SMP host Date: Thu, 27 Dec 2018 16:48:21 +0530 Message-Id: <20181227111821.80908-6-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181227111821.80908-1-anup@brainfault.org> References: <20181227111821.80908-1-anup@brainfault.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181227_031914_014576_26F4F274 X-CRM114-Status: GOOD ( 14.34 ) 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..47da70795145 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_any_and(mask_val, cpu_online_mask); + else + cpu = cpumask_first(mask_val); + + 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,