Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3801826imj; Tue, 12 Feb 2019 05:02:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IY7WrZNQdcrSY07kEuKXY+EcZllounK6q1TnZEG748jrCFvjOomNyppHO6wisvPR2LmDZgu X-Received: by 2002:a17:902:b489:: with SMTP id y9mr3980464plr.193.1549976572799; Tue, 12 Feb 2019 05:02:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549976572; cv=none; d=google.com; s=arc-20160816; b=AgZGvvYNDpeobMc8Vaas5MdbM1n2avI5vk9IZkFpk5RXSBqodH3qv2PVIfztncGVpJ 6D/6/IG2AWD3WQCbRF1LDrc01HXBjY+9OYB5JTNisNR3n/xihj/cE+5v/kkyuD1KUr5L RP7XORM+qloSB8ONhXme/GzLRY3Yf3jQGFX5ngtmAqO4eHFSCAvrPs7Yr6Z4NvsvlGWQ QLwXvgAdAlbUa3VuVsH6mrAPtPX80SBAvH/2YRmg1JFqfwpEIrk84ySPVYaZCY6jvir2 nN9Z0t1qXCFtx7/008RvF0N2brL/F6P3yx7wfo4GWodViDnBB50Uo9HBxI2iQk6cKTvu IrVg== 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=O2ZupOs/WFdJwiPbINO+V0JVWJpBFSTcpyV82FP5qBM=; b=zVpdkPpRqak9Mcx6YCVy+d4GPG3OdzYfu3GUtv2QO0z0MKK03bft7hc3/KimBufFgW zZpOqzBxfvSJYQYf8v0tlEWqGXgK2H3lwarXnrgQsxN6hKT6gOLrKgBExRfRUCxF+2jS AtbnbQ8PCrwVz06X3dybc5meO1d+S2c/AgQwYIbgEjJjNB/+N7CAPF2cZBcvwMvl2f1X d97oJXtdUzJydylkAY+VoV3PCW53C6ktiXlzyMErwLuWcRgR3RVWQ3rhfP+xPZ+B9q2r YCQznWcF6uCiQOwDTbO/M00VUs83PRv/UZGzW5luO8vuorHAawUoG2n+zVmH+qzdrx/H v/Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=EdXk3o+6; 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 c8si12115027pgl.507.2019.02.12.05.02.30; Tue, 12 Feb 2019 05:02:52 -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=EdXk3o+6; 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 S1729288AbfBLMxG (ORCPT + 99 others); Tue, 12 Feb 2019 07:53:06 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36004 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728546AbfBLMxG (ORCPT ); Tue, 12 Feb 2019 07:53:06 -0500 Received: by mail-pl1-f195.google.com with SMTP id g9so1271470plo.3 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=t0HO4rylGnMcmF8i1EafLjnjVnjoR3ms7LTp9p/5Uo1mgFYoyUwqHZ6HO5WHEpErjU soTHaQ/3L3L4pg/iLMcOctf5k9A3flVNAyq4F6EuYNSoq8HNgQbOeJW+CPwFPDB+MeT1 hpEga7fyZd+6zHtBEQOfC6jpKfA3bik2IQsUkvOG2scHh9Zowdts7EVxDoQw6YPFPthy IeWYJ/p6ECHyT022Yb7UpyWjK+izDlI5PF4VOAiC5hkZ6jXHVp0ATDVuFT9YyoVShECJ Z8J15Xgk/nU6P/l5dDKwY2iNlhrpxtsHQBKf1IQ0LkFynTu8pnfEWAOKd8cBIf+3D9xa iZ/g== X-Gm-Message-State: AHQUAuYiiQIaP8KutR2dH6znCkroGGEa/dUCPDu18A7ugWv7Nq7BxNR7 0gg6taApntdWNM1zwq6R09o6GQ== 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 Cc: Atish Patra , Christoph Hellwig , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel 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> 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 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++; } -- 2.17.1