Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7026819imu; Thu, 27 Dec 2018 10:48:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/VsDo96SLBNKwHAyy93inRRc82V60hOm0jULzT/IqnRkKQEaEXzNQ48yL8SkiC2AhRTCKbw X-Received: by 2002:a62:1542:: with SMTP id 63mr25383022pfv.230.1545936518696; Thu, 27 Dec 2018 10:48:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545936518; cv=none; d=google.com; s=arc-20160816; b=tuFhDCllZBU7QEs3HrIYfqcqjlkCXTlyxKyv3yTgUCdmtkav0JbTUx2Ky1962OO8dL tW2fAGMSBMkVAgeC2v+OT422adCO1FWEipRH+xRCUlv2x61rz+YutxvucDwj1E0wXVQ1 7jyJMlRvefLe1L8NFy6MX5fsIEC0pbq1BqtxYkZFX1QfKWGA4p0CGNsakJKc0zCMQgyW bMGm2/9KzKObCHVYq+0NYE9+AUsI8B5zKNRKiBk9/iH8eRvYvTJxnPM3FuMI/4wKXzFp bNOfZuIDKYxFB3tWohTjvhwSTZrlcoT8IDUBCEB5IT3TSiizlfPb/TwVAfeoBJ/kiAUO 8Tgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=EWRMoEC/A0hBjLIZuy6KvNFGbEVqYyO/63HQJNeKmb0=; b=woroPWnfRG2GVx5ouAbQuV+3mtEHj61Q0DhdGmMUBisj0x6dD76CqG7TetAUM1LUbu keVob2eZsbCh4QYuo96xrE2xtyyz4x9/19UugXFGbsSI6WtuFr2hplpLh8qMBoO1C881 dZebiNxnYAb4J5c36MUm8D2OpHuGTHdvKsOFYgGG+pEUBrSCSFqV/fTKnn6znrQuWMoB J35ETaeB/i21A9kA7H2JMghyNH+Kw+yIWCjOBGMfjM91KkSvhpaQgg4EmjMDB7rxw/TX wuymeAryEdFy19f0Xhb8zBhkbDGjioWozdRUR3GSUjIjH0F7BITe5WDrShuT6KGXPzk+ 5i6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b="n/d3YUhZ"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k190si34468499pgd.64.2018.12.27.10.48.23; Thu, 27 Dec 2018 10:48:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b="n/d3YUhZ"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730725AbeL0LSm (ORCPT + 99 others); Thu, 27 Dec 2018 06:18:42 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36260 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728373AbeL0LSl (ORCPT ); Thu, 27 Dec 2018 06:18:41 -0500 Received: by mail-pg1-f193.google.com with SMTP id n2so8705881pgm.3 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=folzaSBRUI+5CoWONRwcf8SYQiDmRBcCEHAbOLuAbPmCIOD3gMnnM9Ht/YZrf7FwaL LzX9fBjb7OLNJEG9PgcvRUH+ywL8kvBwBU30u0NcX5oWn3qVUlVHgo73eWVGiNGQl3gs 0BV4JGayTMfJqXUWZhPPpKd4Yb5CcH4FI+l9pkl//TMd2a/vvXyuPWPE5dcXeH6zD6A+ 5TLYCDuuxzJza5GOaWWJ8Ba9J45W8+wyaTH6D/hZ/hH2DUy3CV1gghozLBY5QSeFwGOY 4P7rdFq2vDkE/7nibDpmivxYjLZ74+nS95PyG4xBRLRW86Ihs5soZ+hdldW97TAQ23A/ 7+VQ== X-Gm-Message-State: AA+aEWakY693HznyU95bOlapnIjKMcFhHtBCXP5ShwXQedX6SRf4R77b df1xAWs3mzjT5C7+T3bnIIfQJg== 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 Cc: Atish Patra , Christoph Hellwig , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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++; } -- 2.17.1