Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2156993ima; Mon, 22 Oct 2018 05:23:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV62n4A+m/Ig26rtErDBeBsCJGiOA6sST23LJLDAaQRKUUz5OHXhL5VdEZ3vYZ/Pi3upEu6RO X-Received: by 2002:a62:52cc:: with SMTP id g195-v6mr46503512pfb.241.1540211023848; Mon, 22 Oct 2018 05:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540211023; cv=none; d=google.com; s=arc-20160816; b=y3Y/zdWoX9NfD79uFs+fSfjf2IHTW/KTHm55R/I4BAS38y53yM2QkzrD1szVQ/rgcI AhQtcNVSiNAa0THRTlZLz1x8PkAjtGVHsIxbYBaYVAwo5hYHfdYoKcd2ZDl2jef3a2+J WP5dhOpLNk8VRtwYwtKDUHpZ3whqs8rJ6bTj9BrdXo/rTR7agkm4nuwX0mZvz07blu88 Xatp54qan9erEPJ/Mq4KQXjxqzJMzzfgX12mImxAA8yNT6c8odfYRwSUU757sR6+M2gv S6rPqWFq1r6qRyCMuuT2Za8+IKvnPYuWyZVyTKXH3EPBUqm1PgbFPFk8yn0AZz48lyly D8LQ== 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=ilMbH1SeaC6uzJ9Hi4gKESHzVTgqGMWeA+QgYge5P6c=; b=YMmkQbl0IBHu1iW5AS+GXNp/okmZDwvSmBj6Ck+r9f8kX8T8HtTiuCO7GTgjKYjgVM Nqy7PczWbzOUcIWBmvsgsajcEWRtwE4V0aRb9A2n3dSi32CVwciZWTcGNCTk+Ly/n9NT wjOeK0Qtsy7+GuB8v1cX9SSl+nJ0BjgfMK97yvVcJfHeGKmyC6FYDbDIo7d8wMoaNSIc AWRCZHuxAeIaWPnDMd6MjrjwnSW8bpsnLXaHCiPDK5LiYwkZhjSetnx5Lj7zElkXv/mL uJz4OxyEONcT47fd0DQE8+GZCPFYUjZLS4yHXJ4Q3Vbzfd2edIjBNvlsWEMdgdJdmcv3 ppIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=YsPyyxPd; 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 i128-v6si36169696pfb.256.2018.10.22.05.23.28; Mon, 22 Oct 2018 05:23:43 -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=YsPyyxPd; 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 S1728829AbeJVUWS (ORCPT + 99 others); Mon, 22 Oct 2018 16:22:18 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42333 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727787AbeJVUWR (ORCPT ); Mon, 22 Oct 2018 16:22:17 -0400 Received: by mail-pg1-f194.google.com with SMTP id i4-v6so18914494pgq.9 for ; Mon, 22 Oct 2018 05:04:01 -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=ilMbH1SeaC6uzJ9Hi4gKESHzVTgqGMWeA+QgYge5P6c=; b=YsPyyxPd+yZmkyL2ZyKc0VptbYk8GSOr/c/Re5KrjbQzulCB0sLSG3vM3MLwAS/cFW Q3OPrwUTC4I0hgcnKGfr7ppEAmi4vU1H4Q4SAK7MWNkosvcl93XeQAGxvnXBx7TPOlgE G5KlxGpswSMIajesJjcReNwmy3UkI45/lw/NkEiQQ07pJBWxOmlk/muEk8OVwfMyj7Wl WcMYNrerQy4hUwrhEECjibkC9VyTomkX0oYdlN8aaUeSMet4MAPF2dLWF8bEjpoI2aYs YWtfj65tO8Q1FNCA8kmnKHfx9MKPe876eekrhqB37JvMCQJMPKk0iJkp/yooDo9ayObX e3ww== 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=ilMbH1SeaC6uzJ9Hi4gKESHzVTgqGMWeA+QgYge5P6c=; b=N3gYIYBiV7PYFDOBIYWCNvolCQG4Tk85fZc8peoOrXATfK9u9JvvZxsc/kMZwodII+ huGWjCIDLMZPa9uKLMJ+clLLmNLLakpYDyiNGg17vVbICoimI83XriimrgWXLg5Cvn9I rdn2WP2peFH5RHhwyWQssMcaFWW0gxdGqj1bS7VNko0WmY/1vWlkKJJF27qiI1SDJBR/ BpG3s3Y1cAHnJUZZnfhE/XinJjSXeX7bRXRR+zwTpVVdEzzRpbv2BETrPClSIPuBEa13 QtFFYTeEXIwtHL4JVMlO7EbEmmeKcTJ02GqMB2sywUJHwb7MrDRBFIui/l8oWo45gTGi ZD+Q== X-Gm-Message-State: ABuFfog1CoFnjFC2rObIKQQ5xdD7C7q3YM5OBt6xAnfKAQbBmp2ZhB6u CQPiVJjo64TEB/v5rrHaTtSXVA== X-Received: by 2002:a63:8c0b:: with SMTP id m11-v6mr43040215pgd.422.1540209840480; Mon, 22 Oct 2018 05:04:00 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Oct 2018 05:03:59 -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 4/4] irqchip: sifive-plic: Implement irq_set_affinity() for SMP host Date: Mon, 22 Oct 2018 17:15:17 +0530 Message-Id: <20181022114517.22748-5-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 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 explicity 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 --- drivers/irqchip/irq-sifive-plic.c | 35 +++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index eb9e8aee1a1a..5a53ffb3c413 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -97,14 +97,42 @@ static void plic_irq_toggle(const struct cpumask *mask, int hwirq, int enable) static void plic_irq_enable(struct irq_data *d) { - plic_irq_toggle(irq_data_get_affinity_mask(d), d->hwirq, 1); + unsigned int cpu = cpumask_any_and(irq_data_get_affinity_mask(d), + cpu_online_mask); + WARN_ON(cpu >= nr_cpu_ids); + plic_irq_toggle(cpumask_of(cpu), d->hwirq, 1); } static void plic_irq_disable(struct irq_data *d) { - plic_irq_toggle(irq_data_get_affinity_mask(d), d->hwirq, 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", /* @@ -113,6 +141,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, -- 2.17.1