Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2153987ima; Mon, 22 Oct 2018 05:20:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV63L+tFEZxPrfa9IvOTAaLiCLtXqkNueF7zdhFu+3xw2JwYq1oPuQkMqoKbofuq8jK4ns5mb X-Received: by 2002:a17:902:8f90:: with SMTP id z16-v6mr44758705plo.214.1540210844082; Mon, 22 Oct 2018 05:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540210844; cv=none; d=google.com; s=arc-20160816; b=Z5tNP5P4NC6XIaKjFhYL1WVf03r5YhIHplPzU5TA4BxpwqjU2mg9czLH8Ibl5lYxOF /G1TokKFcKwSf2Rq8zZ80WzJiE+vLQ0n8tNOWpAwQp54YGGDOkGlC0gfN4D5dpuV/1/C 3qUU71ESG8k0R61O9Q9MPZZN0H4OquLJcxpZFdO44JLd6GLxXs5RYFBgn3u76ex7GKhq theqNETjiipBvMT4RzF1ffrKrx1osIC2zMTv48y8iqEVznVIhwvLfJrx3qges5OXlYD7 GvhEkyqIsmTJppBXW6EAIqZnrWKbtydvowoRU5YqG7snAdmvO0ZlDTAaX/a8LXA2lXkL NYDw== 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=TUe06IOQ52AzaiUZGqr/tV47sWpx1zaKoYXhtVZ9bkQ=; b=KsT1EkWmfYAbtD6XFZXf20dTCjr+j+G6dLRUDv1nEoHwQkIw4nUI3mXRHCgwkPkd13 1Jx2tsjA0G2cpCfu+mMuAbEv0B0PzSVxMpgXSrqCNvJpXahAybrn37dnTNPb4LnWW2Ll 7z9jCh/gALTYYMT9Lar/C4fZ3JoNFFeQtW6he56tk1ArzYYmyNcTfQNFHYBdZcgOKVaV 6M4tbyNgloHrPCHfJc49EDyjO5F8zCatPxOGaTgF7f7edejI3YjzM/ty8l/F3sZ2Qye4 JMBMkSa0Ifu0aZ4DtKLV3TNiQb2cA/6UU9fHvvkV+uEgKffcKVjmQkyyHiHrbb+FGptp 9Jlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=rTyT29de; 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 q1-v6si35316199pfb.258.2018.10.22.05.20.27; Mon, 22 Oct 2018 05:20:44 -0700 (PDT) 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=rTyT29de; 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 S1728532AbeJVUWD (ORCPT + 99 others); Mon, 22 Oct 2018 16:22:03 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42508 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727787AbeJVUWD (ORCPT ); Mon, 22 Oct 2018 16:22:03 -0400 Received: by mail-pl1-f193.google.com with SMTP id c8-v6so18961852plo.9 for ; Mon, 22 Oct 2018 05:03:46 -0700 (PDT) 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=TUe06IOQ52AzaiUZGqr/tV47sWpx1zaKoYXhtVZ9bkQ=; b=rTyT29de1bAw5zVn7PpcTaPZNMJiu+AuufRkdusojhJLqtsmR+Hg+6oJdw52BNHU/g /rlQQN09Rky0/o1GiaLde6EWFNXv6cJcMqN/HkdVhCNqD/qutw3kKgLeDNw2U7KubLcP AdBSKlq/n3tM+5uNiyp+hfdfBkAjwyXMleGvwiczLoP9OHwzeE5JtdwAiNCNgUG8KKFf DMiw7WXgW3DJyWU8lpgZFB9DYW0vz+22auPN4lRzESsrnoWnE3BxujMK4UG5SVpbbgGI H+eTQUsw337lanK5kr5Ar+NQKYRWK7JKuxrMfBtCftbY2Z0kIzCIKqVP/8pBJ4ksJGWY Pufg== 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=TUe06IOQ52AzaiUZGqr/tV47sWpx1zaKoYXhtVZ9bkQ=; b=BF4CjJ16373dMxAgHQMO2MeoxMAYKd3GxvMwfKbOe72Ih8B9J3FiaVkHfrDan+M6s3 b5M5yaWE+cR2yNf7FCczgXYG8HBz4GIQMoG7m6G+SgeEYoFp8fulnh5ZsYUszqpx1E/l xU0p5GqxWN6t30Kg1mG7HNRZXobhqS+/zhNBlaZzbaw2DKmj9qKS4PIsMYhU8q3wQgp7 2+B+rmu+UwHQZj00g3dWYuQXF23k9qg9Pxs0NXMbYJ4kt5XAfXoq49i7Si27XZsgB031 8pVDVpeFdMTTt69s+uAdb0P4DyI8QutqScCrUaccZ4KfyXkHMvMKRRma/8BiOQhHpC86 ah3w== X-Gm-Message-State: ABuFfohFyC+HH1XXyWT9jHWg3ZJJLRMwz1kWnyIFUBfF1XGa9GPnV6K7 X2PYFoPkPzsv4KzWiHLcBmD6Kw== X-Received: by 2002:a17:902:bc44:: with SMTP id t4-v6mr13502218plz.300.1540209825763; Mon, 22 Oct 2018 05:03:45 -0700 (PDT) Received: from anup-ubuntu64.dlink.router ([106.51.30.16]) by smtp.googlemail.com with ESMTPSA id n79-v6sm55443405pfk.19.2018.10.22.05.03.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Oct 2018 05:03:44 -0700 (PDT) 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 1/4] irqchip: sifive-plic: Pre-compute context hart base and enable base Date: Mon, 22 Oct 2018 17:15:14 +0530 Message-Id: <20181022114517.22748-2-anup@brainfault.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181022114517.22748-1-anup@brainfault.org> References: <20181022114517.22748-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 | 51 +++++++++++++------------------ 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 357e9daf94ae..f93ec83eaff4 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -36,14 +36,14 @@ * We always hardwire it to one in Linux. */ #define PRIORITY_BASE 0 -#define PRIORITY_PER_ID 4 +#define PRIORITY_PER_ID 4 /* * Each hart context has a vector of interrupt enable bits associated with it. * There's one bit for each interrupt source. */ #define ENABLE_BASE 0x2000 -#define ENABLE_PER_HART 0x80 +#define ENABLE_PER_HART 0x80 /* * Each hart context has a set of control registers associated with it. Right @@ -51,45 +51,33 @@ * take an interrupt, and a register to claim interrupts. */ #define CONTEXT_BASE 0x200000 -#define CONTEXT_PER_HART 0x1000 -#define CONTEXT_THRESHOLD 0x00 -#define CONTEXT_CLAIM 0x04 +#define CONTEXT_PER_HART 0x1000 +#define CONTEXT_THRESHOLD 0x00 +#define CONTEXT_CLAIM 0x04 static void __iomem *plic_regs; struct plic_handler { bool present; int ctxid; + void __iomem *hart_base; + 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) +static inline void plic_toggle(struct plic_handler *handler, + int hwirq, int enable) { - 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) -{ - u32 __iomem *reg = plic_enable_base(ctxid) + (hwirq / 32); + u32 __iomem *reg = handler->enable_base + (hwirq / 32); 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 +89,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 +138,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); @@ -240,11 +228,16 @@ static int __init plic_init(struct device_node *node, 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