From patchwork Sun Jun 16 21:03:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699661 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED8605B1E5; Sun, 16 Jun 2024 21:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571816; cv=none; b=b6/cwfiqe7R6p8ELCFnr6Y4+GYC62tkSFMoW358ovrQP7mhrfYJWKquIgdj1bexn/6oUozFwUs3TBQxdg3gK9ZHKEAcR1gDYRbFSDvKKboprEPVGGkB7C2MsSwdO/1vrhpAlQnaeL/gI41C24/0BQXPaV7J4XL9RuJCD2epGvvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571816; c=relaxed/simple; bh=KsQJA78l2EG1AePEtuNM5A5yp2HhCualT38E0jX+dDE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c7fDerRVQZVWpaKkVVPL/FjFlTD1YBuVj+sYzeTYOw2Id3fTZRDaAg6ufrHgGS5oDZ7cqrVky+ksQ3xxnlDGzYFKFEq2x4yBX6v2xx7PS6BgFA0KpHUS3S0TBgvq+cLK8l8z/ayu+wrt+5FSUG2lSCfn9dmpAdpusn58+drzlu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=R2kH3w3s; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ovIofMuG; arc=none smtp.client-ip=64.147.123.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="R2kH3w3s"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ovIofMuG" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 87CDD18000AC; Sun, 16 Jun 2024 17:03:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 16 Jun 2024 17:03:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571812; x=1718658212; bh=x3gpIaj0Pn6na4DuLdp1UEvubuCDt4zg+JvemqwjwM0=; b= R2kH3w3ssWvHColII/ZEFBx+6FiR24xKHQk3fgMNsjZaS8cb4zqEx3MY5OJy5+XS XXJsvfbUdMtvwOrdJNMu21/Ly4lV//hjWAyGFLYVl0s3rdmovldWv31upn0dra9F zXR0BK6vUnM57rm4m3Wp8TfZWW9zIPFt0YjyxpQuGWLWfRJJFBRq6BO/NZswBdCO S3IfEzKEJIaSYh9EMrtq0yRKdAtQd2489V6yqw6VvuAoU/V/fUSVWVZkGzVQtUZB mZtruvuC9ZeLiKOvfmV+SRzo6O/x+Ck7bgiB69twktpBbKy9z3hw/MLS0CfMaUM2 CzCP3gDpiactzo6DfbA8zw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571812; x= 1718658212; bh=x3gpIaj0Pn6na4DuLdp1UEvubuCDt4zg+JvemqwjwM0=; b=o vIofMuGRntyoilMNBrKguI4QRdP8g+CJvdE4awUokQ8509HhAJAYifjr6Z9HQ6eM AvyC7qGho0tJm8EMssfahIHL/3qZ0COcbu622Nsy2dveMVg5RYQOYUFT9YIYAKbE /hLloiw3FX2NLaOs7CWt7OXVCIM3tLcpeIfGdf9vTRkjs4zy3D7l2QAj54RVqxkH Dn4MxfASuO8Fx0nWeAtF0PVOY1CKJeCfGqrYRyoEkficQeottJ1o5SBZng0HxRuE 3YBBkDqp0HVzMA7zCGKBTy7KpyEGcK3cbLRhyt9asPqoOmuAEiUM+uHEZQ907RTN dQ8t2JlamGpWB9QMZpBhw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:30 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:05 +0100 Subject: [PATCH 01/10] MIPS: smp: Make IPI interrupts scalable Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-1-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=30059; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=KsQJA78l2EG1AePEtuNM5A5yp2HhCualT38E0jX+dDE=; b=kA0DAAoWQ3EMfdd3KcMByyZiAGZvUx+iS7cpjC/e075p72+UcOYUuQTF+i9UVCcma+OtXKTgc Yh1BAAWCgAdFiEEVBAijrCB0aDX4Gr8Q3EMfdd3KcMFAmZvUx8ACgkQQ3EMfdd3KcPvWgD/WaAe gVwWYm2U5WKlIHZlkVWVdWuyKWZo42hvYHxvcfoBAJADOnGLLqN7EWpUm5c31nJgEIuR3QhsFSD j3kESGa4H X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Define enum ipi_message_type as other architectures did to allow easy extension to number of IPI interrupts, fiddle around platform IPI code to adopt to the new infra, add extensive BUILD_BUG_ON on IPI numbers to ensure future extensions won't break existing platforms. IPI related stuff are pulled to asm/ipi.h to avoid include linux/interrupt.h in asm/smp.h. Signed-off-by: Jiaxun Yang --- arch/mips/cavium-octeon/smp.c | 109 ++++++++++++----------------------- arch/mips/include/asm/ipi.h | 34 +++++++++++ arch/mips/include/asm/smp-ops.h | 8 +-- arch/mips/include/asm/smp.h | 42 ++++++-------- arch/mips/kernel/smp-bmips.c | 43 +++++++------- arch/mips/kernel/smp-cps.c | 1 + arch/mips/kernel/smp.c | 124 ++++++++++++++++++++-------------------- arch/mips/loongson64/smp.c | 51 +++++++++-------- arch/mips/mm/c-octeon.c | 2 +- arch/mips/sgi-ip27/ip27-smp.c | 15 +++-- arch/mips/sgi-ip30/ip30-smp.c | 15 +++-- arch/mips/sibyte/bcm1480/smp.c | 19 +++--- arch/mips/sibyte/sb1250/smp.c | 13 +++-- 13 files changed, 236 insertions(+), 240 deletions(-) diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c index 08ea2cde1eb5..7cf8dd2eddce 100644 --- a/arch/mips/cavium-octeon/smp.c +++ b/arch/mips/cavium-octeon/smp.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -40,30 +41,19 @@ EXPORT_SYMBOL(octeon_bootloader_entry_addr); extern void kernel_entry(unsigned long arg1, ...); -static void octeon_icache_flush(void) +static irqreturn_t octeon_icache_flush(int irq, void *dev_id) { asm volatile ("synci 0($0)\n"); + return IRQ_HANDLED; } -static void (*octeon_message_functions[8])(void) = { - scheduler_ipi, - generic_smp_call_function_interrupt, - octeon_icache_flush, -}; - static irqreturn_t mailbox_interrupt(int irq, void *dev_id) { u64 mbox_clrx = CVMX_CIU_MBOX_CLRX(cvmx_get_core_num()); - u64 action; - int i; + unsigned long action; + int op; - /* - * Make sure the function array initialization remains - * correct. - */ - BUILD_BUG_ON(SMP_RESCHEDULE_YOURSELF != (1 << 0)); - BUILD_BUG_ON(SMP_CALL_FUNCTION != (1 << 1)); - BUILD_BUG_ON(SMP_ICACHE_FLUSH != (1 << 2)); + BUILD_BUG_ON(IPI_MAX > 8); /* * Load the mailbox register to figure out what we're supposed @@ -79,16 +69,10 @@ static irqreturn_t mailbox_interrupt(int irq, void *dev_id) /* Clear the mailbox to clear the interrupt */ cvmx_write_csr(mbox_clrx, action); - for (i = 0; i < ARRAY_SIZE(octeon_message_functions) && action;) { - if (action & 1) { - void (*fn)(void) = octeon_message_functions[i]; - - if (fn) - fn(); - } - action >>= 1; - i++; + for_each_set_bit(op, &action, IPI_MAX) { + ipi_handlers[op](0, NULL); } + return IRQ_HANDLED; } @@ -97,23 +81,23 @@ static irqreturn_t mailbox_interrupt(int irq, void *dev_id) * cpu. When the function has finished, increment the finished field of * call_data. */ -void octeon_send_ipi_single(int cpu, unsigned int action) +void octeon_send_ipi_single(int cpu, enum ipi_message_type op) { int coreid = cpu_logical_map(cpu); /* pr_info("SMP: Mailbox send cpu=%d, coreid=%d, action=%u\n", cpu, coreid, action); */ - cvmx_write_csr(CVMX_CIU_MBOX_SETX(coreid), action); + cvmx_write_csr(CVMX_CIU_MBOX_SETX(coreid), BIT(op)); } static inline void octeon_send_ipi_mask(const struct cpumask *mask, - unsigned int action) + enum ipi_message_type op) { unsigned int i; for_each_cpu(i, mask) - octeon_send_ipi_single(i, action); + octeon_send_ipi_single(i, BIT(op)); } /* @@ -149,6 +133,9 @@ static void __init octeon_smp_setup(void) unsigned int num_cores = cvmx_octeon_num_cores(); #endif + ipi_handlers[IPI_ICACHE_FLUSH] = octeon_icache_flush; + ipi_names[IPI_ICACHE_FLUSH] = "Octeon ICache Flush"; + /* The present CPUs are initially just the boot cpu (CPU 0). */ for (id = 0; id < NR_CPUS; id++) { set_cpu_possible(id, id == 0); @@ -427,67 +414,41 @@ static const struct plat_smp_ops octeon_smp_ops = { #endif }; -static irqreturn_t octeon_78xx_reched_interrupt(int irq, void *dev_id) -{ - scheduler_ipi(); - return IRQ_HANDLED; -} - -static irqreturn_t octeon_78xx_call_function_interrupt(int irq, void *dev_id) -{ - generic_smp_call_function_interrupt(); - return IRQ_HANDLED; -} - -static irqreturn_t octeon_78xx_icache_flush_interrupt(int irq, void *dev_id) -{ - octeon_icache_flush(); - return IRQ_HANDLED; -} - /* * Callout to firmware before smp_init */ static void octeon_78xx_prepare_cpus(unsigned int max_cpus) { - if (request_irq(OCTEON_IRQ_MBOX0 + 0, - octeon_78xx_reched_interrupt, - IRQF_PERCPU | IRQF_NO_THREAD, "Scheduler", - octeon_78xx_reched_interrupt)) { - panic("Cannot request_irq for SchedulerIPI"); - } - if (request_irq(OCTEON_IRQ_MBOX0 + 1, - octeon_78xx_call_function_interrupt, - IRQF_PERCPU | IRQF_NO_THREAD, "SMP-Call", - octeon_78xx_call_function_interrupt)) { - panic("Cannot request_irq for SMP-Call"); - } - if (request_irq(OCTEON_IRQ_MBOX0 + 2, - octeon_78xx_icache_flush_interrupt, - IRQF_PERCPU | IRQF_NO_THREAD, "ICache-Flush", - octeon_78xx_icache_flush_interrupt)) { - panic("Cannot request_irq for ICache-Flush"); + int i; + + /* + * FIXME: Hardware have 10 MBOX but only 4 virqs are reserved + * for CIU3 MBOX. + */ + BUILD_BUG_ON(IPI_MAX > 4); + + for (i = 0; i < IPI_MAX; i++) { + if (request_irq(OCTEON_IRQ_MBOX0 + i, + ipi_handlers[i], + IRQF_PERCPU | IRQF_NO_THREAD, "IPI", + ipi_handlers[i])) { + panic("Cannot request_irq for %s", ipi_names[i]); + } } } -static void octeon_78xx_send_ipi_single(int cpu, unsigned int action) +static void octeon_78xx_send_ipi_single(int cpu, enum ipi_message_type op) { - int i; - - for (i = 0; i < 8; i++) { - if (action & 1) - octeon_ciu3_mbox_send(cpu, i); - action >>= 1; - } + octeon_ciu3_mbox_send(cpu, op); } static void octeon_78xx_send_ipi_mask(const struct cpumask *mask, - unsigned int action) + enum ipi_message_type op) { unsigned int cpu; for_each_cpu(cpu, mask) - octeon_78xx_send_ipi_single(cpu, action); + octeon_78xx_send_ipi_single(cpu, op); } static const struct plat_smp_ops octeon_78xx_smp_ops = { diff --git a/arch/mips/include/asm/ipi.h b/arch/mips/include/asm/ipi.h new file mode 100644 index 000000000000..df7a0ac4227a --- /dev/null +++ b/arch/mips/include/asm/ipi.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include + +#ifndef __ASM_IPI_H +#define __ASM_IPI_H + +#ifdef CONFIG_SMP +extern const char *ipi_names[]; +extern irq_handler_t ipi_handlers[]; + +#ifdef CONFIG_GENERIC_IRQ_IPI +extern void mips_smp_send_ipi_single(int cpu, + enum ipi_message_type op); +extern void mips_smp_send_ipi_mask(const struct cpumask *mask, + enum ipi_message_type op); + +/* + * This function will set up the necessary IPIs for Linux to communicate + * with the CPUs in mask. + * Return 0 on success. + */ +int mips_smp_ipi_allocate(const struct cpumask *mask); + +/* + * This function will free up IPIs allocated with mips_smp_ipi_allocate to the + * CPUs in mask, which must be a subset of the IPIs that have been configured. + * Return 0 on success. + */ +int mips_smp_ipi_free(const struct cpumask *mask); +#endif /* CONFIG_GENERIC_IRQ_IPI */ +#endif /* CONFIG_SMP */ +#endif diff --git a/arch/mips/include/asm/smp-ops.h b/arch/mips/include/asm/smp-ops.h index 1617b207723f..8cf4156cb301 100644 --- a/arch/mips/include/asm/smp-ops.h +++ b/arch/mips/include/asm/smp-ops.h @@ -20,8 +20,8 @@ struct task_struct; struct plat_smp_ops { - void (*send_ipi_single)(int cpu, unsigned int action); - void (*send_ipi_mask)(const struct cpumask *mask, unsigned int action); + void (*send_ipi_single)(int cpu, enum ipi_message_type op); + void (*send_ipi_mask)(const struct cpumask *mask, enum ipi_message_type op); void (*init_secondary)(void); void (*smp_finish)(void); int (*boot_secondary)(int cpu, struct task_struct *idle); @@ -47,10 +47,6 @@ static inline void plat_smp_setup(void) mp_ops->smp_setup(); } -extern void mips_smp_send_ipi_single(int cpu, unsigned int action); -extern void mips_smp_send_ipi_mask(const struct cpumask *mask, - unsigned int action); - #else /* !CONFIG_SMP */ struct plat_smp_ops; diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h index bc2c240f414b..0c7467f15014 100644 --- a/arch/mips/include/asm/smp.h +++ b/arch/mips/include/asm/smp.h @@ -16,8 +16,6 @@ #include #include -#include - extern int smp_num_siblings; extern cpumask_t cpu_sibling_map[]; extern cpumask_t cpu_core_map[]; @@ -46,12 +44,6 @@ extern int __cpu_logical_map[NR_CPUS]; #define NO_PROC_ID (-1) -#define SMP_RESCHEDULE_YOURSELF 0x1 /* XXX braindead */ -#define SMP_CALL_FUNCTION 0x2 -/* Octeon - Tell another core to flush its icache */ -#define SMP_ICACHE_FLUSH 0x4 -#define SMP_ASK_C0COUNT 0x8 - /* Mask of CPUs which are currently definitely operating coherently */ extern cpumask_t cpu_coherent_mask; @@ -63,6 +55,20 @@ extern void calculate_cpu_foreign_map(void); asmlinkage void start_secondary(void); +enum ipi_message_type { + IPI_RESCHEDULE, + IPI_CALL_FUNC, +#ifdef CONFIG_CAVIUM_OCTEON_SOC + IPI_ICACHE_FLUSH, +#endif +#ifdef CONFIG_MACH_LOONGSON64 + IPI_ASK_C0COUNT, +#endif + IPI_MAX +}; + +#include + /* * this function sends a 'reschedule' IPI to another CPU. * it goes straight through and wastes no time serializing @@ -72,7 +78,7 @@ static inline void arch_smp_send_reschedule(int cpu) { extern const struct plat_smp_ops *mp_ops; /* private */ - mp_ops->send_ipi_single(cpu, SMP_RESCHEDULE_YOURSELF); + mp_ops->send_ipi_single(cpu, IPI_RESCHEDULE); } #ifdef CONFIG_HOTPLUG_CPU @@ -109,32 +115,18 @@ static inline void *kexec_nonboot_cpu_func(void) } #endif -/* - * This function will set up the necessary IPIs for Linux to communicate - * with the CPUs in mask. - * Return 0 on success. - */ -int mips_smp_ipi_allocate(const struct cpumask *mask); - -/* - * This function will free up IPIs allocated with mips_smp_ipi_allocate to the - * CPUs in mask, which must be a subset of the IPIs that have been configured. - * Return 0 on success. - */ -int mips_smp_ipi_free(const struct cpumask *mask); - static inline void arch_send_call_function_single_ipi(int cpu) { extern const struct plat_smp_ops *mp_ops; /* private */ - mp_ops->send_ipi_single(cpu, SMP_CALL_FUNCTION); + mp_ops->send_ipi_single(cpu, IPI_CALL_FUNC); } static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask) { extern const struct plat_smp_ops *mp_ops; /* private */ - mp_ops->send_ipi_mask(mask, SMP_CALL_FUNCTION); + mp_ops->send_ipi_mask(mask, IPI_CALL_FUNC); } #endif /* __ASM_SMP_H */ diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c index b3dbf9ecb0d6..428b39aee344 100644 --- a/arch/mips/kernel/smp-bmips.c +++ b/arch/mips/kernel/smp-bmips.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -282,36 +283,31 @@ static void bmips_smp_finish(void) * BMIPS5000 raceless IPIs * * Each CPU has two inbound SW IRQs which are independent of all other CPUs. - * IPI0 is used for SMP_RESCHEDULE_YOURSELF - * IPI1 is used for SMP_CALL_FUNCTION */ -static void bmips5000_send_ipi_single(int cpu, unsigned int action) +static void bmips5000_send_ipi_single(int cpu, enum ipi_message_type op) { - write_c0_brcm_action(ACTION_SET_IPI(cpu, action == SMP_CALL_FUNCTION)); + write_c0_brcm_action(ACTION_SET_IPI(cpu, op)); } static irqreturn_t bmips5000_ipi_interrupt(int irq, void *dev_id) { int action = irq - IPI0_IRQ; - write_c0_brcm_action(ACTION_CLR_IPI(smp_processor_id(), action)); + BUILD_BUG_ON(IPI_MAX > 2); - if (action == 0) - scheduler_ipi(); - else - generic_smp_call_function_interrupt(); + write_c0_brcm_action(ACTION_CLR_IPI(smp_processor_id(), action)); - return IRQ_HANDLED; + return ipi_handlers[action](0, NULL); } static void bmips5000_send_ipi_mask(const struct cpumask *mask, - unsigned int action) + enum ipi_message_type op) { unsigned int i; for_each_cpu(i, mask) - bmips5000_send_ipi_single(i, action); + bmips5000_send_ipi_single(i, op); } /* @@ -325,23 +321,26 @@ static void bmips5000_send_ipi_mask(const struct cpumask *mask, */ static DEFINE_SPINLOCK(ipi_lock); -static DEFINE_PER_CPU(int, ipi_action_mask); +static DEFINE_PER_CPU(unsigned long, ipi_action_mask); -static void bmips43xx_send_ipi_single(int cpu, unsigned int action) +static void bmips43xx_send_ipi_single(int cpu, enum ipi_message_type op) { unsigned long flags; spin_lock_irqsave(&ipi_lock, flags); set_c0_cause(cpu ? C_SW1 : C_SW0); - per_cpu(ipi_action_mask, cpu) |= action; + per_cpu(ipi_action_mask, cpu) |= BIT(op); irq_enable_hazard(); spin_unlock_irqrestore(&ipi_lock, flags); } static irqreturn_t bmips43xx_ipi_interrupt(int irq, void *dev_id) { - unsigned long flags; - int action, cpu = irq - IPI0_IRQ; + unsigned long flags, action; + int cpu = irq - IPI0_IRQ; + int op; + + BUILD_BUG_ON(IPI_MAX > BITS_PER_LONG); spin_lock_irqsave(&ipi_lock, flags); action = __this_cpu_read(ipi_action_mask); @@ -349,21 +348,19 @@ static irqreturn_t bmips43xx_ipi_interrupt(int irq, void *dev_id) clear_c0_cause(cpu ? C_SW1 : C_SW0); spin_unlock_irqrestore(&ipi_lock, flags); - if (action & SMP_RESCHEDULE_YOURSELF) - scheduler_ipi(); - if (action & SMP_CALL_FUNCTION) - generic_smp_call_function_interrupt(); + for_each_set_bit(op, &action, IPI_MAX) + ipi_handlers[op](0, NULL); return IRQ_HANDLED; } static void bmips43xx_send_ipi_mask(const struct cpumask *mask, - unsigned int action) + enum ipi_message_type op) { unsigned int i; for_each_cpu(i, mask) - bmips43xx_send_ipi_single(i, action); + bmips43xx_send_ipi_single(i, op); } #ifdef CONFIG_HOTPLUG_CPU diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c index 9cc087dd1c19..8c322f441164 100644 --- a/arch/mips/kernel/smp-cps.c +++ b/arch/mips/kernel/smp-cps.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index 0b53d35a116e..a6cf6444533e 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -92,11 +93,6 @@ static int __init early_smt(char *s) } early_param("smt", early_smt); -#ifdef CONFIG_GENERIC_IRQ_IPI -static struct irq_desc *call_desc; -static struct irq_desc *sched_desc; -#endif - static inline void set_cpu_sibling_map(int cpu) { int i; @@ -164,13 +160,42 @@ void register_smp_ops(const struct plat_smp_ops *ops) mp_ops = ops; } +static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id) +{ + scheduler_ipi(); + + return IRQ_HANDLED; +} + +static irqreturn_t ipi_call_interrupt(int irq, void *dev_id) +{ + generic_smp_call_function_interrupt(); + + return IRQ_HANDLED; +} + + +const char *ipi_names[IPI_MAX] __read_mostly = { + [IPI_RESCHEDULE] = "Rescheduling interrupts", + [IPI_CALL_FUNC] = "Function call interrupts", +}; + +irq_handler_t ipi_handlers[IPI_MAX] __read_mostly = { + [IPI_RESCHEDULE] = ipi_resched_interrupt, + [IPI_CALL_FUNC] = ipi_call_interrupt, +}; + #ifdef CONFIG_GENERIC_IRQ_IPI -void mips_smp_send_ipi_single(int cpu, unsigned int action) +static int ipi_virqs[IPI_MAX] __ro_after_init; +static struct irq_desc *ipi_desc[IPI_MAX] __read_mostly; + +void mips_smp_send_ipi_single(int cpu, enum ipi_message_type op) { - mips_smp_send_ipi_mask(cpumask_of(cpu), action); + mips_smp_send_ipi_mask(cpumask_of(cpu), op); } -void mips_smp_send_ipi_mask(const struct cpumask *mask, unsigned int action) +void mips_smp_send_ipi_mask(const struct cpumask *mask, + enum ipi_message_type op) { unsigned long flags; unsigned int core; @@ -178,18 +203,7 @@ void mips_smp_send_ipi_mask(const struct cpumask *mask, unsigned int action) local_irq_save(flags); - switch (action) { - case SMP_CALL_FUNCTION: - __ipi_send_mask(call_desc, mask); - break; - - case SMP_RESCHEDULE_YOURSELF: - __ipi_send_mask(sched_desc, mask); - break; - - default: - BUG(); - } + __ipi_send_mask(ipi_desc[op], mask); if (mips_cpc_present()) { for_each_cpu(cpu, mask) { @@ -211,21 +225,6 @@ void mips_smp_send_ipi_mask(const struct cpumask *mask, unsigned int action) local_irq_restore(flags); } - -static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id) -{ - scheduler_ipi(); - - return IRQ_HANDLED; -} - -static irqreturn_t ipi_call_interrupt(int irq, void *dev_id) -{ - generic_smp_call_function_interrupt(); - - return IRQ_HANDLED; -} - static void smp_ipi_init_one(unsigned int virq, const char *name, irq_handler_t handler) { @@ -236,11 +235,9 @@ static void smp_ipi_init_one(unsigned int virq, const char *name, BUG_ON(ret); } -static unsigned int call_virq, sched_virq; - int mips_smp_ipi_allocate(const struct cpumask *mask) { - int virq; + int virq, i; struct irq_domain *ipidomain; struct device_node *node; @@ -267,33 +264,30 @@ int mips_smp_ipi_allocate(const struct cpumask *mask) * setup, if we're running with only a single CPU. */ if (!ipidomain) { - BUG_ON(num_present_cpus() > 1); + WARN_ON(num_present_cpus() > 1); return 0; } - virq = irq_reserve_ipi(ipidomain, mask); - BUG_ON(!virq); - if (!call_virq) - call_virq = virq; - - virq = irq_reserve_ipi(ipidomain, mask); - BUG_ON(!virq); - if (!sched_virq) - sched_virq = virq; + for (i = 0; i < IPI_MAX; i++) { + virq = irq_reserve_ipi(ipidomain, mask); + WARN_ON(!virq); + ipi_virqs[i] = virq; + } if (irq_domain_is_ipi_per_cpu(ipidomain)) { int cpu; for_each_cpu(cpu, mask) { - smp_ipi_init_one(call_virq + cpu, "IPI call", - ipi_call_interrupt); - smp_ipi_init_one(sched_virq + cpu, "IPI resched", - ipi_resched_interrupt); + for (i = 0; i < IPI_MAX; i++) { + smp_ipi_init_one(ipi_virqs[i] + cpu, ipi_names[i], + ipi_handlers[i]); + } } } else { - smp_ipi_init_one(call_virq, "IPI call", ipi_call_interrupt); - smp_ipi_init_one(sched_virq, "IPI resched", - ipi_resched_interrupt); + for (i = 0; i < IPI_MAX; i++) { + smp_ipi_init_one(ipi_virqs[i], ipi_names[i], + ipi_handlers[i]); + } } return 0; @@ -301,6 +295,7 @@ int mips_smp_ipi_allocate(const struct cpumask *mask) int mips_smp_ipi_free(const struct cpumask *mask) { + int i; struct irq_domain *ipidomain; struct device_node *node; @@ -321,25 +316,32 @@ int mips_smp_ipi_free(const struct cpumask *mask) int cpu; for_each_cpu(cpu, mask) { - free_irq(call_virq + cpu, NULL); - free_irq(sched_virq + cpu, NULL); + for (i = 0; i < IPI_MAX; i++) + free_irq(ipi_virqs[i] + cpu, NULL); } } - irq_destroy_ipi(call_virq, mask); - irq_destroy_ipi(sched_virq, mask); + + for (i = 0; i < IPI_MAX; i++) + irq_destroy_ipi(ipi_virqs[i], mask); + return 0; } static int __init mips_smp_ipi_init(void) { + int i; + if (num_possible_cpus() == 1) return 0; mips_smp_ipi_allocate(cpu_possible_mask); - call_desc = irq_to_desc(call_virq); - sched_desc = irq_to_desc(sched_virq); + for (i = 0; i < IPI_MAX; i++) { + ipi_desc[i] = irq_to_desc(ipi_virqs[i]); + if (!ipi_desc[i]) + return -ENODEV; + } return 0; } diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c index 5a990cdef91a..3c64d7cd835b 100644 --- a/arch/mips/loongson64/smp.c +++ b/arch/mips/loongson64/smp.c @@ -13,8 +13,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -368,44 +368,44 @@ static void ipi_mailbox_buf_init(void) /* * Simple enough, just poke the appropriate ipi register */ -static void loongson3_send_ipi_single(int cpu, unsigned int action) +static void loongson3_send_ipi_single(int cpu, enum ipi_message_type op) { - ipi_write_action(cpu_logical_map(cpu), (u32)action); + ipi_write_action(cpu_logical_map(cpu), BIT(op)); } static void -loongson3_send_ipi_mask(const struct cpumask *mask, unsigned int action) +loongson3_send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op) { unsigned int i; for_each_cpu(i, mask) - ipi_write_action(cpu_logical_map(i), (u32)action); + ipi_write_action(cpu_logical_map(i), BIT(op)); } - -static irqreturn_t loongson3_ipi_interrupt(int irq, void *dev_id) +static irqreturn_t loongson3_ask_c0count(int irq, void *dev_id) { int i, cpu = smp_processor_id(); - unsigned int action, c0count; + unsigned long c0count; - action = ipi_read_clear(cpu); + BUG_ON(cpu != 0); + c0count = read_c0_count(); + c0count = c0count ? c0count : 1; + for (i = 1; i < nr_cpu_ids; i++) + core0_c0count[i] = c0count; + nudge_writes(); /* Let others see the result ASAP */ - if (action & SMP_RESCHEDULE_YOURSELF) - scheduler_ipi(); + return IRQ_HANDLED; +} - if (action & SMP_CALL_FUNCTION) { - irq_enter(); - generic_smp_call_function_interrupt(); - irq_exit(); - } +static irqreturn_t loongson3_ipi_interrupt(int irq, void *dev_id) +{ + int op, cpu = smp_processor_id(); + unsigned long action; - if (action & SMP_ASK_C0COUNT) { - BUG_ON(cpu != 0); - c0count = read_c0_count(); - c0count = c0count ? c0count : 1; - for (i = 1; i < nr_cpu_ids; i++) - core0_c0count[i] = c0count; - nudge_writes(); /* Let others see the result ASAP */ + action = ipi_read_clear(cpu); + + for_each_set_bit(op, &action, IPI_MAX) { + ipi_handlers[op](0, NULL); } return IRQ_HANDLED; @@ -435,7 +435,7 @@ static void loongson3_init_secondary(void) i = 0; core0_c0count[cpu] = 0; - loongson3_send_ipi_single(0, SMP_ASK_C0COUNT); + loongson3_send_ipi_single(0, IPI_ASK_C0COUNT); while (!core0_c0count[cpu]) { i++; cpu_relax(); @@ -493,6 +493,9 @@ static void __init loongson3_smp_setup(void) num++; } + ipi_handlers[IPI_ASK_C0COUNT] = loongson3_ask_c0count; + ipi_names[IPI_ASK_C0COUNT] = "Loongson Ask C0 Count"; + csr_ipi_probe(); ipi_set0_regs_init(); ipi_clear0_regs_init(); diff --git a/arch/mips/mm/c-octeon.c b/arch/mips/mm/c-octeon.c index b7393b61cfa7..10b201a09859 100644 --- a/arch/mips/mm/c-octeon.c +++ b/arch/mips/mm/c-octeon.c @@ -85,7 +85,7 @@ static void octeon_flush_icache_all_cores(struct vm_area_struct *vma) cpumask_clear_cpu(cpu, &mask); #ifdef CONFIG_CAVIUM_OCTEON_SOC for_each_cpu(cpu, &mask) - octeon_send_ipi_single(cpu, SMP_ICACHE_FLUSH); + octeon_send_ipi_single(cpu, IPI_ICACHE_FLUSH); #else smp_call_function_many(&mask, (smp_call_func_t)octeon_local_flush_icache, NULL, 1); diff --git a/arch/mips/sgi-ip27/ip27-smp.c b/arch/mips/sgi-ip27/ip27-smp.c index 5d2652a1d35a..87da545d0c3f 100644 --- a/arch/mips/sgi-ip27/ip27-smp.c +++ b/arch/mips/sgi-ip27/ip27-smp.c @@ -94,15 +94,17 @@ static __init void intr_clear_all(nasid_t nasid) REMOTE_HUB_CLR_INTR(nasid, i); } -static void ip27_send_ipi_single(int destid, unsigned int action) +static void ip27_send_ipi_single(int destid, enum ipi_message_type op) { int irq; - switch (action) { - case SMP_RESCHEDULE_YOURSELF: + BUILD_BUG_ON(IPI_MAX > 2); + + switch (op) { + case IPI_RESCHEDULE: irq = CPU_RESCHED_A_IRQ; break; - case SMP_CALL_FUNCTION: + case IPI_CALL_FUNC: irq = CPU_CALL_A_IRQ; break; default: @@ -118,12 +120,13 @@ static void ip27_send_ipi_single(int destid, unsigned int action) REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq); } -static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action) +static void ip27_send_ipi_mask(const struct cpumask *mask, + enum ipi_message_type op) { unsigned int i; for_each_cpu(i, mask) - ip27_send_ipi_single(i, action); + ip27_send_ipi_single(i, op); } static void ip27_init_cpu(void) diff --git a/arch/mips/sgi-ip30/ip30-smp.c b/arch/mips/sgi-ip30/ip30-smp.c index 4bfe654602b1..1c674c0cf419 100644 --- a/arch/mips/sgi-ip30/ip30-smp.c +++ b/arch/mips/sgi-ip30/ip30-smp.c @@ -43,15 +43,17 @@ struct mpconf { u32 idleflag; }; -static void ip30_smp_send_ipi_single(int cpu, u32 action) +static void ip30_smp_send_ipi_single(int cpu, enum ipi_message_type op) { int irq; - switch (action) { - case SMP_RESCHEDULE_YOURSELF: + BUILD_BUG_ON(IPI_MAX > 2); + + switch (op) { + case IPI_RESCHEDULE: irq = HEART_L2_INT_RESCHED_CPU_0; break; - case SMP_CALL_FUNCTION: + case IPI_CALL_FUNC: irq = HEART_L2_INT_CALL_CPU_0; break; default: @@ -64,12 +66,13 @@ static void ip30_smp_send_ipi_single(int cpu, u32 action) heart_write(BIT_ULL(irq), &heart_regs->set_isr); } -static void ip30_smp_send_ipi_mask(const struct cpumask *mask, u32 action) +static void ip30_smp_send_ipi_mask(const struct cpumask *mask, + enum ipi_message_type op) { u32 i; for_each_cpu(i, mask) - ip30_smp_send_ipi_single(i, action); + ip30_smp_send_ipi_single(i, op); } static void __init ip30_smp_setup(void) diff --git a/arch/mips/sibyte/bcm1480/smp.c b/arch/mips/sibyte/bcm1480/smp.c index 5861e50255bf..040230e3f4a0 100644 --- a/arch/mips/sibyte/bcm1480/smp.c +++ b/arch/mips/sibyte/bcm1480/smp.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -64,18 +65,18 @@ void bcm1480_smp_init(void) * Simple enough; everything is set up, so just poke the appropriate mailbox * register, and we should be set */ -static void bcm1480_send_ipi_single(int cpu, unsigned int action) +static void bcm1480_send_ipi_single(int cpu, enum ipi_message_type op) { - __raw_writeq((((u64)action)<< 48), mailbox_0_set_regs[cpu]); + __raw_writeq((((u64)BIT_ULL(op)) << 48), mailbox_0_set_regs[cpu]); } static void bcm1480_send_ipi_mask(const struct cpumask *mask, - unsigned int action) + enum ipi_message_type op) { unsigned int i; for_each_cpu(i, mask) - bcm1480_send_ipi_single(i, action); + bcm1480_send_ipi_single(i, op); } /* @@ -159,19 +160,21 @@ void bcm1480_mailbox_interrupt(void) { int cpu = smp_processor_id(); int irq = K_BCM1480_INT_MBOX_0_0; - unsigned int action; + u64 action; + + BUILD_BUG_ON(IPI_MAX > 2); kstat_incr_irq_this_cpu(irq); /* Load the mailbox register to figure out what we're supposed to do */ action = (__raw_readq(mailbox_0_regs[cpu]) >> 48) & 0xffff; /* Clear the mailbox to clear the interrupt */ - __raw_writeq(((u64)action)<<48, mailbox_0_clear_regs[cpu]); + __raw_writeq(((u64)action) << 48, mailbox_0_clear_regs[cpu]); - if (action & SMP_RESCHEDULE_YOURSELF) + if (action & BIT_ULL(IPI_RESCHEDULE)) scheduler_ipi(); - if (action & SMP_CALL_FUNCTION) { + if (action & BIT_ULL(IPI_CALL_FUNC)) { irq_enter(); generic_smp_call_function_interrupt(); irq_exit(); diff --git a/arch/mips/sibyte/sb1250/smp.c b/arch/mips/sibyte/sb1250/smp.c index 7a794234e3d7..dc2c889fa0b6 100644 --- a/arch/mips/sibyte/sb1250/smp.c +++ b/arch/mips/sibyte/sb1250/smp.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -53,18 +54,18 @@ void sb1250_smp_init(void) * Simple enough; everything is set up, so just poke the appropriate mailbox * register, and we should be set */ -static void sb1250_send_ipi_single(int cpu, unsigned int action) +static void sb1250_send_ipi_single(int cpu, enum ipi_message_type op) { - __raw_writeq((((u64)action) << 48), mailbox_set_regs[cpu]); + __raw_writeq((((u64)BIT_ULL(op)) << 48), mailbox_set_regs[cpu]); } static inline void sb1250_send_ipi_mask(const struct cpumask *mask, - unsigned int action) + enum ipi_message_type op) { unsigned int i; for_each_cpu(i, mask) - sb1250_send_ipi_single(i, action); + sb1250_send_ipi_single(i, op); } /* @@ -157,10 +158,10 @@ void sb1250_mailbox_interrupt(void) /* Clear the mailbox to clear the interrupt */ ____raw_writeq(((u64)action) << 48, mailbox_clear_regs[cpu]); - if (action & SMP_RESCHEDULE_YOURSELF) + if (action & BIT(IPI_RESCHEDULE)) scheduler_ipi(); - if (action & SMP_CALL_FUNCTION) { + if (action & BIT(IPI_CALL_FUNC)) { irq_enter(); generic_smp_call_function_interrupt(); irq_exit(); From patchwork Sun Jun 16 21:03:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699662 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C77EC6BB5C; Sun, 16 Jun 2024 21:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571818; cv=none; b=iqaLnEnBeF02riFsbfhqFW649D3w1tI/ChwYMCF/IbtXv2I2daNbGqFXvYQEsA/WukrMjn1g2+Eecvvb5gtYEl6deZWAIMAVEaIfzI2wQsNhxYRfKb8FZtKbvGIHutlLija0GVTh/JEOAhbwZmo5eyKVd8CbmvHMRzno0y5yMQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571818; c=relaxed/simple; bh=wHsDiD50RoPx24lzv2aOKc2oWoxz6/3EkKTUFYyyMAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZU4iI/B7A7ZS/YFDCCKbwRMogK1wdBa/d0zobr2nXRvWpKNZySN5WuUkVHjT+riVQo4lsHS03wEcORMtLZUVQY4jd9qYyPc5nlAjhxyLMCrXpJn3+mDdontQD82dzb/BpyfsfcU9mvBxSy04M2mSvlNaXAd0NQXL0opYDm/1LvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=tarcx+hS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=S+kv6tWH; arc=none smtp.client-ip=64.147.123.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="tarcx+hS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="S+kv6tWH" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 67B3718000C9; Sun, 16 Jun 2024 17:03:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 16 Jun 2024 17:03:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571815; x=1718658215; bh=xeKPCFLBIzT9HCzsGdHFFaJZDOn08aeSjaXQqx0+yro=; b= tarcx+hSGrF6xNUSrbMPqXCwveKyYQXyRfTpsoUKHfnXDgtfPvy+vMZCBES2IQ0P vON61floAI8FBruWRKjAIuRkpFIlbijjb/0+Q/OHvZLTe0bRNdRFWpS3y8ho1QiI XotywrEffh+2en05vVfN9DoI+s5xXd3ql/YxJvqNwAS49u2Xu9h7gBWWLAM/nBuE stDLaaSNJDCw4lkcxVo1L/dW29lK9Jn6h3CE6pdX+U/gNxyjJPghB+DxQ5hYU7XY 9c05/TA6nxfUyJGH/gw1aaJ1yFXCzTE7AtUS8HKTAjm/YAHon0eGuvIrePqxfnPI 6/medlsT3soy/HwKFcdUQA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571815; x= 1718658215; bh=xeKPCFLBIzT9HCzsGdHFFaJZDOn08aeSjaXQqx0+yro=; b=S +kv6tWH6xLI0UzjJV6Aat4h8fApPndBa0cW09AjvjQNOqad5IW2FT9HQtG8Fotz2 0OsY8JehEddHkbn2hFQ8pSAvOLxOmr1SO+EshQD2+e7+Ckok7xBGEBZ1YHjdjHS5 eR0q+ypvSa9sYFsIA+TTPszy7nZ9I01XznW+A4GBawF9MaB7rjYWLYVOKno7DjvZ GWSHUByh4NIhLgURuN+lGGx7xvvxklbIvVCh73ptlyzRsvdIimfkKQmSL5ixAwP9 zaMhHzgIEd8wFH0ab5pxafWNMcww3NsN56TdPz/ZBd2kaXiHnpy0kb6kmU0Ny7VJ 7qDxgNOeWW2Thz4ksuZiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:33 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:06 +0100 Subject: [PATCH 02/10] MIPS: smp: Manage IPI interrupts as percpu_devid interrupts Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-2-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2703; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=wHsDiD50RoPx24lzv2aOKc2oWoxz6/3EkKTUFYyyMAw=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YHn15v5VvZtXvrzFMZHxUdzxS4+urXDyun5xx9nOL Tx+Rcu5OkpZGMS4GGTFFFlCBJT6NjReXHD9QdYfmDmsTCBDGLg4BWAi9kqMDGdmdUh3JUbe2xpt wyP48MC0s8fPxLuEBiSGidxOlbpbqcrIMMNGfdZT2+WdpXN441a/mP9O5d82uyCLB9qLXlg1iqR LswAA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 IPI interrupts need to be enabled when a new CPU coming up. Manage them as percpu_devid interrupts and invoke enable/disable functions at appropriate time to perform enabling as required, similar to what RISC-V and Arm doing. Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/ipi.h | 11 +++++++++++ arch/mips/kernel/smp.c | 26 ++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/arch/mips/include/asm/ipi.h b/arch/mips/include/asm/ipi.h index df7a0ac4227a..88b507339f51 100644 --- a/arch/mips/include/asm/ipi.h +++ b/arch/mips/include/asm/ipi.h @@ -29,6 +29,17 @@ int mips_smp_ipi_allocate(const struct cpumask *mask); * Return 0 on success. */ int mips_smp_ipi_free(const struct cpumask *mask); + +void mips_smp_ipi_enable(void); +void mips_smp_ipi_disable(void); +#else +static inline void mips_smp_ipi_enable(void) +{ +} + +static inline void mips_smp_ipi_disable(void) +{ +} #endif /* CONFIG_GENERIC_IRQ_IPI */ #endif /* CONFIG_SMP */ #endif diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index a6cf6444533e..710644d47106 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -186,6 +186,7 @@ irq_handler_t ipi_handlers[IPI_MAX] __read_mostly = { }; #ifdef CONFIG_GENERIC_IRQ_IPI +static DEFINE_PER_CPU_READ_MOSTLY(int, ipi_dummy_dev); static int ipi_virqs[IPI_MAX] __ro_after_init; static struct irq_desc *ipi_desc[IPI_MAX] __read_mostly; @@ -225,13 +226,29 @@ void mips_smp_send_ipi_mask(const struct cpumask *mask, local_irq_restore(flags); } +void mips_smp_ipi_enable(void) +{ + int i; + + for (i = 0; i < IPI_MAX; i++) + enable_percpu_irq(ipi_virqs[i], IRQ_TYPE_NONE); +} + +void mips_smp_ipi_disable(void) +{ + int i; + + for (i = 0; i < IPI_MAX; i++) + disable_percpu_irq(ipi_virqs[i]); +} + static void smp_ipi_init_one(unsigned int virq, const char *name, irq_handler_t handler) { int ret; - irq_set_handler(virq, handle_percpu_irq); - ret = request_irq(virq, handler, IRQF_PERCPU, name, NULL); + irq_set_percpu_devid(virq); + ret = request_percpu_irq(virq, handler, "IPI", &ipi_dummy_dev); BUG_ON(ret); } @@ -343,6 +360,9 @@ static int __init mips_smp_ipi_init(void) return -ENODEV; } + /* Enable IPI for Boot CPU */ + mips_smp_ipi_enable(); + return 0; } early_initcall(mips_smp_ipi_init); @@ -383,6 +403,8 @@ asmlinkage void start_secondary(void) synchronise_count_slave(cpu); + mips_smp_ipi_enable(); + /* The CPU is running and counters synchronised, now mark it online */ set_cpu_online(cpu, true); From patchwork Sun Jun 16 21:03:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699663 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 913E44964F; Sun, 16 Jun 2024 21:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571821; cv=none; b=d0CJmqh/UOe1b3vK1Oul3fjIup3/z1tON2VTR5kExqkKmEE45iCUXtAgxbqlovkOyYzGQQw4MZvfuFLySYpnbYmxqpYz8wu0fSFNCuPu0lbKvvkq2Wp4/TC0cnJ3VqMZJdwyH/qzvGJGEzHWCR+J3DGsiVDFP9TEginaWmiVP8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571821; c=relaxed/simple; bh=d2OknMMxorxFkf5DImwHqEQaLveM9KNB4VtRA7GbSRo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lT6Kq2Uqs9rs+lt4eSBOX0nyRbmVGfzyEhWyctVeYmM0Jh8HzwtF24F221NmoujQuXhSPHsHO02YKXIFHvet1kLShBCKIpvcmLym+IAMfJytOnIk4dqWOIAKwqsKPRyorxuFo/PyAKNtca7bdJyEs6F018e4Ii0Vcqtz5TAEBB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=lHCSSdlX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kxYmoByL; arc=none smtp.client-ip=64.147.123.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="lHCSSdlX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kxYmoByL" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 6384A1C000A9; Sun, 16 Jun 2024 17:03:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 16 Jun 2024 17:03:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571817; x=1718658217; bh=3f+6SXfbFhh9e7SA6hXsiueGsGMJnsyYnROP7YyoBKg=; b= lHCSSdlXeFXhCvjMlHb5w0NT0UDeHZBKzzMfm2g/yjnsE4DIzNkdy5SvfwRRQlne Fzyne0wi1lSnJuS6OVsnHnUj+vOIA44Dx8VKIdVsEfQr66dQupf1D3Yo02YrQCyi gQY7Qh3+9LCnQOI16pvM9vd+CCTqSuN9NyEtPluaAvjBodEP05TmTOT2MHVWfaJh Etkf1iIvkTRlRT9m+XUiEUJFdK+a0/YTLJKFiitQHh+PysxfaXFvzfdCL2PYv28T tVfPq+mtn4qHxaMJCozvahuKawWUs94w45PNkM1nlgk1vuVyHfJSC3OXod3VGfOV lfFHc/M59kDEb6ra7zT04Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571817; x= 1718658217; bh=3f+6SXfbFhh9e7SA6hXsiueGsGMJnsyYnROP7YyoBKg=; b=k xYmoByL/NzcTVIGAIIf7LSpjuylHJibdRpSUJoWrKKjszg85i5NLRMUt/Jm+zX7/ /q5JUK+cgUhtfi/SzTl7D+Gb5j4HyEL4KiwiYMS8rhC2hDS+g3HVt9n88x0poChz +FnKEFAMW5tl+HpE2P7ioAkF5DvqPfvItr1jbejsV72p+WBdAs2QcxkFE7iIeTCt +mmqydwQYfSie9RUCIrYne4OQ8641A+z5Uu/Ukv/fsG7gTfWBAQ7RdhOIZcW/beP zKm42X9bxRre7Yehy8OrdEfJY07hi7M5XyADRZ7AAOu3nXA9LNnIVaS8ns861PA3 Z9KCMKAuqVCjFVS4ZpdUQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:36 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:07 +0100 Subject: [PATCH 03/10] MIPS: smp: Provide platform IPI virq & domain hooks Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-3-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4880; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=d2OknMMxorxFkf5DImwHqEQaLveM9KNB4VtRA7GbSRo=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YPnKSx/4NuhsOdrTcWyRh9DF36pM31tLH7C+Zvt11 0L4dlJYRykLgxgXg6yYIkuIgFLfhsaLC64/yPoDM4eVCWQIAxenAExky2lGhvbTGaGie66/1Lnw +t4rkZrM65cjtTXm12yNjGOw3tY7YQXD/6zD34yOJTKYPJipIx95dHeU9Z6tkR0/XqS0/bt67LV IGTsA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Provide platform virq & domain hooks to allow platform interrupt controllers or SMP code to override IPI interrupt allocation. This is required by ipi-mux, the API is aligned with RISC-V and Arm. Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/ipi.h | 17 ++++++++++ arch/mips/kernel/smp.c | 78 +++++++++++++++++++++++++-------------------- 2 files changed, 61 insertions(+), 34 deletions(-) diff --git a/arch/mips/include/asm/ipi.h b/arch/mips/include/asm/ipi.h index 88b507339f51..0fc8c31c6a52 100644 --- a/arch/mips/include/asm/ipi.h +++ b/arch/mips/include/asm/ipi.h @@ -2,6 +2,7 @@ #include #include +#include #ifndef __ASM_IPI_H #define __ASM_IPI_H @@ -32,6 +33,9 @@ int mips_smp_ipi_free(const struct cpumask *mask); void mips_smp_ipi_enable(void); void mips_smp_ipi_disable(void); +extern bool mips_smp_ipi_have_virq_range(void); +void mips_smp_ipi_set_irqdomain(struct irq_domain *d); +extern void mips_smp_ipi_set_virq_range(int virq, int nr); #else static inline void mips_smp_ipi_enable(void) { @@ -41,5 +45,18 @@ static inline void mips_smp_ipi_disable(void) { } #endif /* CONFIG_GENERIC_IRQ_IPI */ +#else +void mips_smp_ipi_set_virq_range(int virq, int nr) +{ +} + +void mips_smp_ipi_set_irqdomain(struct irq_domain *d) +{ +} + +static inline bool mips_smp_ipi_have_virq_range(void) +{ + return false; +} #endif /* CONFIG_SMP */ #endif diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index 710644d47106..fe053fe52147 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -189,6 +189,7 @@ irq_handler_t ipi_handlers[IPI_MAX] __read_mostly = { static DEFINE_PER_CPU_READ_MOSTLY(int, ipi_dummy_dev); static int ipi_virqs[IPI_MAX] __ro_after_init; static struct irq_desc *ipi_desc[IPI_MAX] __read_mostly; +static struct irq_domain *ipidomain; void mips_smp_send_ipi_single(int cpu, enum ipi_message_type op) { @@ -255,11 +256,12 @@ static void smp_ipi_init_one(unsigned int virq, const char *name, int mips_smp_ipi_allocate(const struct cpumask *mask) { int virq, i; - struct irq_domain *ipidomain; struct device_node *node; - node = of_irq_find_parent(of_root); - ipidomain = irq_find_matching_host(node, DOMAIN_BUS_IPI); + if (!ipidomain) { + node = of_irq_find_parent(of_root); + ipidomain = irq_find_matching_host(node, DOMAIN_BUS_IPI); + } /* * Some platforms have half DT setup. So if we found irq node but @@ -291,43 +293,15 @@ int mips_smp_ipi_allocate(const struct cpumask *mask) ipi_virqs[i] = virq; } - if (irq_domain_is_ipi_per_cpu(ipidomain)) { - int cpu; - - for_each_cpu(cpu, mask) { - for (i = 0; i < IPI_MAX; i++) { - smp_ipi_init_one(ipi_virqs[i] + cpu, ipi_names[i], - ipi_handlers[i]); - } - } - } else { - for (i = 0; i < IPI_MAX; i++) { - smp_ipi_init_one(ipi_virqs[i], ipi_names[i], - ipi_handlers[i]); - } - } - return 0; } int mips_smp_ipi_free(const struct cpumask *mask) { int i; - struct irq_domain *ipidomain; - struct device_node *node; - - node = of_irq_find_parent(of_root); - ipidomain = irq_find_matching_host(node, DOMAIN_BUS_IPI); - - /* - * Some platforms have half DT setup. So if we found irq node but - * didn't find an ipidomain, try to search for one that is not in the - * DT. - */ - if (node && !ipidomain) - ipidomain = irq_find_matching_host(NULL, DOMAIN_BUS_IPI); - BUG_ON(!ipidomain); + if (!ipidomain) + return -ENODEV; if (irq_domain_is_ipi_per_cpu(ipidomain)) { int cpu; @@ -344,6 +318,25 @@ int mips_smp_ipi_free(const struct cpumask *mask) return 0; } +void mips_smp_ipi_set_virq_range(int virq, int nr) +{ + int i; + + WARN_ON(nr < IPI_MAX); + + for (i = 0; i < IPI_MAX; i++) + ipi_virqs[i] = virq + i; +} + +void mips_smp_ipi_set_irqdomain(struct irq_domain *d) +{ + ipidomain = d; +} + +bool mips_smp_ipi_have_virq_range(void) +{ + return ipi_virqs[0]; +} static int __init mips_smp_ipi_init(void) { @@ -352,7 +345,24 @@ static int __init mips_smp_ipi_init(void) if (num_possible_cpus() == 1) return 0; - mips_smp_ipi_allocate(cpu_possible_mask); + if (!mips_smp_ipi_have_virq_range()) + mips_smp_ipi_allocate(cpu_possible_mask); + + if (ipidomain && irq_domain_is_ipi_per_cpu(ipidomain)) { + int cpu; + + for_each_possible_cpu(cpu) { + for (i = 0; i < IPI_MAX; i++) { + smp_ipi_init_one(ipi_virqs[i] + cpu, ipi_names[i], + ipi_handlers[i]); + } + } + } else { + for (i = 0; i < IPI_MAX; i++) { + smp_ipi_init_one(ipi_virqs[i], ipi_names[i], + ipi_handlers[i]); + } + } for (i = 0; i < IPI_MAX; i++) { ipi_desc[i] = irq_to_desc(ipi_virqs[i]); From patchwork Sun Jun 16 21:03:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699664 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EA8771748; Sun, 16 Jun 2024 21:03:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571823; cv=none; b=Tm08bbNuoBPajGplD+H5xm7JRpBi4qXD0H6wPMhm9dG4Njv923Fr88QMib9IziyKNYFRCQZbFJ0M0ylwHbQFuswVxl2J2i6oVhOenuivhNhfJFv/UUDCQlkuUd5OEci5eM6ykqo5Kl4p7f36pkn0NTcDXSMlLtGodhGR3m3FtaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571823; c=relaxed/simple; bh=u+nlZJtxY8gepbbEz7ezIh6OtiFEwscjcqdaTX+j0L0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M+0SA9TGwwAoqISAiwr3b2p0h8A18e6NF4AYCHMamvVFI4FCHGDx4r53+ITxiO4pZD4WYVcSv/O/mt8RIswziEYw0LsR3yC/tN2KCU2bXFis8QH5P46BWTKuOCoADXfHEMM27WQbeqWaXTUnUslJi2IiY8sLT9OU9NrB+bzogSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=Fa/P4nxz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TQkWxUSO; arc=none smtp.client-ip=64.147.123.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="Fa/P4nxz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TQkWxUSO" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 3EF551C000BB; Sun, 16 Jun 2024 17:03:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 16 Jun 2024 17:03:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571820; x=1718658220; bh=hnMTOGvhtZ8qp0qPzOnzDl3VInIwtcNEpdbf+QJCiW0=; b= Fa/P4nxzvsNM5kyzQYciBPKYU2dZP6VoDAxtCzLO0DsaLfXScYFvM5OFWlIyFJCY CoBtjy/ltKJLQ4wHmzeQTks7ynnGSHJ7ITacZfd1iji7KdbzX2bJpCZ68CIoDQ/n qgRX6RrrvHREdgVLsLN7X22nRu2RISqgje/epa1uhDFsOgXkQ3tJl1j/kGuqnag3 CFVqiIUYqRpf1QO4N/8fDlbg/SwgLdBPwAwaaRMbBp1Dc7q5EI8Z5XC/6FtaePq3 1jl5I7wDCPzzxS5eP+Wg0Y+3KRkrYQdueel71ChZfWc4XDwM3cHEbMP5032Dez5f 1ndYbrAeX/RbdpolFCB2Cg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571820; x= 1718658220; bh=hnMTOGvhtZ8qp0qPzOnzDl3VInIwtcNEpdbf+QJCiW0=; b=T QkWxUSOOQWzI8YbGKcrlpULEAY4bsxozxRztnhBAbWO1FfcYhS+LYbP2H/9kcvgd HmjT5JDqlEM6To+HlQ/facLmnaJNFdnxtBXBDIC3/JeY8KNlPeNBRpkSvS+0hdUC 0jc5suJ7wUlDk/l2Vu3jc4d6EOkIwBbhYvzCfH2ZitMBSrG++CFO2ZDgMm69CNd4 8xhaPDglzvcOa1731toB4tNMA2SNgkAWpnI3YKw2Zkd+8qXSQHW46Z2JAJeJVR5O sJKmTt2DUL4kS3q7IC2mTRcJc74+yp79/OSSMQvhW0f0Lv9eGh7wkLjLo23vcyWF Cft1c8kCWgzTC/QBVAwsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:39 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:08 +0100 Subject: [PATCH 04/10] MIPS: Move mips_smp_ipi_init call after prepare_cpus Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-4-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1302; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=u+nlZJtxY8gepbbEz7ezIh6OtiFEwscjcqdaTX+j0L0=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YPlNpbIzp+7JuyQ1daPbkpyISUzP9xm+6T7zvEwok /tekvTqjlIWBjEuBlkxRZYQAaW+DY0XF1x/kPUHZg4rE8gQBi5OAZiIhgHDP5XlsW2FX9JefndR YX3A0v29iLUvxTFX3k97/XJu7ryvPQz/rLv6l/05qyD+xaLVqlWmkvlle9LF9X+n3J1mrXpV+xo vCwA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 This will give platform code a genuine chance to setup IPI IRQ in prepare_cpus. This is the best place for platforms to setup IPI as smp_setup is too early for IRQ subsystem. Signed-off-by: Jiaxun Yang --- arch/mips/kernel/smp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index fe053fe52147..ddf96c28e2f0 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -375,7 +375,6 @@ static int __init mips_smp_ipi_init(void) return 0; } -early_initcall(mips_smp_ipi_init); #endif /* @@ -460,12 +459,22 @@ void __init smp_cpus_done(unsigned int max_cpus) /* called from main before smp_init() */ void __init smp_prepare_cpus(unsigned int max_cpus) { + int rc; + init_new_context(current, &init_mm); current_thread_info()->cpu = 0; mp_ops->prepare_cpus(max_cpus); set_cpu_sibling_map(0); set_cpu_core_map(0); calculate_cpu_foreign_map(); +#ifdef CONFIG_GENERIC_IRQ_IPI + rc = mips_smp_ipi_init(); + if (rc) { + pr_err("Failed to initialize IPI - disabling SMP"); + init_cpu_present(cpumask_of(0)); + return; + } +#endif #ifndef CONFIG_HOTPLUG_CPU init_cpu_present(cpu_possible_mask); #endif From patchwork Sun Jun 16 21:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699665 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7567373451; Sun, 16 Jun 2024 21:03:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571826; cv=none; b=a9CQRIFfoAYLdVQsBveIaGT3A8XXMOxCGKSc5TST5Aw7lRlPg8A7D5coCAuQJpYToLQrKOoB1XF1LfnXD8OtKlpuOjQe+ffcNsnAsS4GJSSnPzetJ2jdtdxFt1O/lu+l6VQ+IztB+KLGvMiVw0B02oa4kOmw9Hks7baqPFJc1x0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571826; c=relaxed/simple; bh=Q0B3ozZ1+tMaT0GsWlC+CEo9IUlB2PFVElh9ipC7Wl4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GjSSTn3kaFdnECHy25+Xwa7D2ffq2VSEgZQ3hAX93jRPm6mUCsLLxba3EbGL/CvzSBTxnSyzNO7dyKP7/oinEDzqSqEhkZfK3R3oGC3lEvnu6ZK94uEqZSEmzDHqTePPW534dnDYkCdQPFGgvmz00XbLEQgPXHXjYLf+ejFoGvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=RTA2e6dx; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ORQAqRci; arc=none smtp.client-ip=64.147.123.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="RTA2e6dx"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ORQAqRci" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 14B3B1C000B9; Sun, 16 Jun 2024 17:03:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 16 Jun 2024 17:03:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571823; x=1718658223; bh=n57a4JQbTyT/KQQXlMbXsgnB1h30lzLN+SudRRABA34=; b= RTA2e6dx94jZvmBQEY1FrwOb2AhnyD3+PtCopGbV7Mj5s2q3lkaABhlL6Xca8AOf TvQykxAqDqUcrUHj/nYia31quKNeh8Rvrdei3+xOiqqi4skNcB9tmEYhcgQ1jmzW okprIBBhox3T8bJUVFLzJNKRRjhQUwDy1fo/g/MgYbA4vfoqs2Z9TIsIZAz5KuYH JoieCo6JeQXq245NDOFkXDzC00WUybd9HLNXIPBs7sM93z469WJO6BY5/wFbWdYc p01I8/aMAJd6wiH1RoyIRPkg4sVzx6FFkSTOGQzK9Jfp4vJnD9WDLEA9OG1uw+C0 I/WeAfzjdnMfJ4Re+E+4ig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571823; x= 1718658223; bh=n57a4JQbTyT/KQQXlMbXsgnB1h30lzLN+SudRRABA34=; b=O RQAqRciQrZzb+ydyl5h9qh6qTZWpOuBG1KS8pf0BvJYuxpfG+F9z4rR10cWEw46I xJXsjdPnbiez7nB3XT6M6srPeKEM7Y+STVHDZrP68R8BkXrfbCZlPufIF6bVXoIy OYTgMz8F2+spWqeKNpulKTaHH7s3JjFtHcNIEcAF2GtNkx2fJ6o5Gs1gSt/XjGJA 1ga6WKSPQq8KcqskB4nssR3vL+caA4zfCj2uP5y4DTyIgqT3N75TVMSbezLasyax y7IgVsdvFsu9+n0dxQqYhnZt2rwoWg0Mt0mqH75eVF+7Mv2b8h+1MzWpTVQNPu0Z zy6MC0hvcEXq0RMvPG7ng== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:42 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:09 +0100 Subject: [PATCH 05/10] MIPS: smp: Implement IPI stats Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-5-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2624; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=Q0B3ozZ1+tMaT0GsWlC+CEo9IUlB2PFVElh9ipC7Wl4=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YPnli6PkHLez7uxN4U++8keXyW6F4/x9uj7cu5ZNW 7+UXdSyo5SFQYyLQVZMkSVEQKlvQ+PFBdcfZP2BmcPKBDKEgYtTACaykYWRYSPD4d1rniw0PGYn Zefte2vjwqhb++wP12XI3mrXvKa7cT4jwyWGZ21e73Nkthw/59zbtmjJRwbW96f6HfcW8Dk/Tei V5gcA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Show IPI statistics in arch_show_interrupts as what RISC-V did. Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/ipi.h | 9 +++++++++ arch/mips/kernel/irq.c | 4 ++++ arch/mips/kernel/smp.c | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/arch/mips/include/asm/ipi.h b/arch/mips/include/asm/ipi.h index 0fc8c31c6a52..1a486f0c934f 100644 --- a/arch/mips/include/asm/ipi.h +++ b/arch/mips/include/asm/ipi.h @@ -36,6 +36,7 @@ void mips_smp_ipi_disable(void); extern bool mips_smp_ipi_have_virq_range(void); void mips_smp_ipi_set_irqdomain(struct irq_domain *d); extern void mips_smp_ipi_set_virq_range(int virq, int nr); +extern void mips_smp_show_ipi_stats(struct seq_file *p, int prec); #else static inline void mips_smp_ipi_enable(void) { @@ -44,6 +45,10 @@ static inline void mips_smp_ipi_enable(void) static inline void mips_smp_ipi_disable(void) { } + +static void mips_smp_show_ipi_stats(struct seq_file *p, int prec) +{ +} #endif /* CONFIG_GENERIC_IRQ_IPI */ #else void mips_smp_ipi_set_virq_range(int virq, int nr) @@ -58,5 +63,9 @@ static inline bool mips_smp_ipi_have_virq_range(void) { return false; } + +static void mips_smp_show_ipi_stats(struct seq_file *p, int prec) +{ +} #endif /* CONFIG_SMP */ #endif diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c index 5e11582fe308..c3ea8d80e0cb 100644 --- a/arch/mips/kernel/irq.c +++ b/arch/mips/kernel/irq.c @@ -26,6 +26,8 @@ #include #include +#include + void *irq_stack[NR_CPUS]; /* @@ -42,6 +44,8 @@ atomic_t irq_err_count; int arch_show_interrupts(struct seq_file *p, int prec) { seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count)); + mips_smp_show_ipi_stats(p, prec); + return 0; } diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c index ddf96c28e2f0..826659214566 100644 --- a/arch/mips/kernel/smp.c +++ b/arch/mips/kernel/smp.c @@ -243,6 +243,19 @@ void mips_smp_ipi_disable(void) disable_percpu_irq(ipi_virqs[i]); } +void mips_smp_show_ipi_stats(struct seq_file *p, int prec) +{ + unsigned int cpu, i; + + for (i = 0; i < IPI_MAX; i++) { + seq_printf(p, "%*s%u:%s", prec - 1, "IPI", i, + prec >= 4 ? " " : ""); + for_each_online_cpu(cpu) + seq_printf(p, "%10u ", irq_desc_kstat_cpu(ipi_desc[i], cpu)); + seq_printf(p, " %s\n", ipi_names[i]); + } +} + static void smp_ipi_init_one(unsigned int virq, const char *name, irq_handler_t handler) { From patchwork Sun Jun 16 21:03:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699666 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 486576A8A3; Sun, 16 Jun 2024 21:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571830; cv=none; b=XBPGBaCytoJYV8iARtAdqVKS7gZWQo5G0m6y9bnFwIk82sGF7wcdnDxdqMl7NRcGt4jDuKMqgii5uml7iQKKhmNq9DzXz1bxrimB9+m5BvnLI6AgJ5KtIK/hR6PbWkJ4i1XJpX/Ofy0QqMDvoTZF09ingj/Da+oivjH6YV/2RI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571830; c=relaxed/simple; bh=U7sa3foNInV86z583JyxtoLd5PJh9VERNgckzOsw5aA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M4qqAZc08eZeGKJHnFvSQ7xFTN/7qy7PR/trlnptmIT5PFw/gDtbKDfd8SpjheNY6a69LdsDk1OI8PhfmHSLd0PDELzobTPtlVtRWcNY9d1GBd+m3DxoBl1hpzM6QQijf3Vv02OOEuB7/uBh/QG6l+vq7otufUnXIPCbtonDXw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=3JcBLjz6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=h+lL9Y4h; arc=none smtp.client-ip=64.147.123.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="3JcBLjz6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="h+lL9Y4h" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id E43781C00096; Sun, 16 Jun 2024 17:03:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 16 Jun 2024 17:03:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571826; x=1718658226; bh=63FS3iPlOmLj2b5kOo6FTLTD9xvdB0VrujqYckkV4Hc=; b= 3JcBLjz6/3e8RIMpmw+6XZoiUAx5fbWLsjP54wvXFcwzLDUQvFft548H9lPrKG9U vmh9l3uvqfJtrxxXMSziXfraJzN1MTcrLnDOJcYtOxcfvK1zjYEi2IplhCRyIKmv I+K5EnOSJSWzeEXM6WfrE5wotyAIbEQXjzb/VdgISiGB/eAzpDSztMGSxWzmdpdM u7Ym7ktxjr+Z4+mmrD4S5acqCIPfV32Zd5QpNxbYcfnYv363X0DLkjZB/Wabpa9q qZpizU3iw+0JmTDSlTuKPH/jUM+A5R7cT3l276Fl1esKOylL/JfJwRFCWEQ2MhMP ldwsfI3pjt3gJKBJQAc1pQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571826; x= 1718658226; bh=63FS3iPlOmLj2b5kOo6FTLTD9xvdB0VrujqYckkV4Hc=; b=h +lL9Y4hj6qaG8uugEJZG/KXJyVSDW5QP/9mkYm4MpaWswKNYqsbc+Ovav9W8fuEg GTgXdoOUIAd1xmJLgEhRPy699oUZgU13rMEoF23+tK2gplOpTVlkWk7YRpq+Zqjv xwlSbcHIc6RsDjv8nCvUnJWK997UmbbqxPvGmkRv2NzHTTpBOj7g5xyeNgp60/o8 AvSuFdSKkYBZnG2FVWg7X3T8c+6cn/rUExUzMWCX+IR0cHo35r6jFGlRVGrtIbJT r8PzO1yeEcbxHAaS35w7hwCu42232Re61kpQznTZ+f65/xsLKnjyj2qnYFrUWv93 HdGgZRdUmHKntkzlsp88A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:45 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:10 +0100 Subject: [PATCH 06/10] irqchip: irq-mips-gic: Switch to ipi_mux Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-6-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=9752; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=U7sa3foNInV86z583JyxtoLd5PJh9VERNgckzOsw5aA=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YPnLduf3evaFH+zW6QxRZq37lHD3XepD3ruWGyTe/ RH5wifaUcrCIMbFICumyBIioNS3ofHigusPsv7AzGFlAhnCwMUpABNZxMLIcKSydRlzzP9ezsbr AdtdlMU0e11St5w+I9/z2dYq9s16TkaGGTNWm9q8risxkXiYO5nTbrMMR4rlO4Md4fLbLPbf8tz EBgA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Use ipi_mux to implement IPI interrupts instead of allocating vector for each individual IPI messages. This can reduce number of reserved GIC shared vectors, which is a huge problem on MSI enabled GIC systems. It also allowed us to easily expand number of IPIs. Signed-off-by: Jiaxun Yang --- drivers/irqchip/Kconfig | 1 + drivers/irqchip/irq-mips-gic.c | 200 ++++++++++++++--------------------------- 2 files changed, 66 insertions(+), 135 deletions(-) diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index 14464716bacb..8665bbf31bb5 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -329,6 +329,7 @@ config KEYSTONE_IRQ config MIPS_GIC bool select GENERIC_IRQ_IPI if SMP + select GENERIC_IRQ_IPI_MUX if SMP select IRQ_DOMAIN_HIERARCHY select MIPS_CM diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c index 76253e864f23..eb58392f0e66 100644 --- a/drivers/irqchip/irq-mips-gic.c +++ b/drivers/irqchip/irq-mips-gic.c @@ -17,12 +17,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -58,7 +60,7 @@ static struct irq_chip gic_level_irq_controller, gic_edge_irq_controller; #ifdef CONFIG_GENERIC_IRQ_IPI static DECLARE_BITMAP(ipi_resrv, GIC_MAX_INTRS); -static DECLARE_BITMAP(ipi_available, GIC_MAX_INTRS); +static int cpu_ipi_intr[NR_CPUS] __read_mostly; #endif /* CONFIG_GENERIC_IRQ_IPI */ static struct gic_all_vpes_chip_data { @@ -108,13 +110,6 @@ static void gic_bind_eic_interrupt(int irq, int set) write_gic_vl_eic_shadow_set(irq, set); } -static void gic_send_ipi(struct irq_data *d, unsigned int cpu) -{ - irq_hw_number_t hwirq = GIC_HWIRQ_TO_SHARED(irqd_to_hwirq(d)); - - write_gic_wedge(GIC_WEDGE_RW | hwirq); -} - int gic_get_c0_compare_int(void) { if (!gic_local_irq_is_routable(GIC_LOCAL_INT_TIMER)) @@ -181,6 +176,11 @@ static void gic_mask_irq(struct irq_data *d) unsigned int intr = GIC_HWIRQ_TO_SHARED(d->hwirq); write_gic_rmask(intr); + +#ifdef CONFIG_GENERIC_IRQ_IPI + if (test_bit(intr, ipi_resrv)) + return; +#endif gic_clear_pcpu_masks(intr); } @@ -191,6 +191,10 @@ static void gic_unmask_irq(struct irq_data *d) write_gic_smask(intr); +#ifdef CONFIG_GENERIC_IRQ_IPI + if (test_bit(intr, ipi_resrv)) + return; +#endif gic_clear_pcpu_masks(intr); cpu = cpumask_first(irq_data_get_effective_affinity_mask(d)); set_bit(intr, per_cpu_ptr(pcpu_masks, cpu)); @@ -263,6 +267,11 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask, unsigned long flags; unsigned int cpu; +#ifdef CONFIG_GENERIC_IRQ_IPI + if (test_bit(irq, ipi_resrv)) + return -EINVAL; +#endif + cpu = cpumask_first_and(cpumask, cpu_online_mask); if (cpu >= NR_CPUS) return -EINVAL; @@ -304,7 +313,6 @@ static struct irq_chip gic_edge_irq_controller = { #ifdef CONFIG_SMP .irq_set_affinity = gic_set_affinity, #endif - .ipi_send_single = gic_send_ipi, }; static void gic_handle_local_int(bool chained) @@ -475,12 +483,6 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq, u32 map; if (hwirq >= GIC_SHARED_HWIRQ_BASE) { -#ifdef CONFIG_GENERIC_IRQ_IPI - /* verify that shared irqs don't conflict with an IPI irq */ - if (test_bit(GIC_HWIRQ_TO_SHARED(hwirq), ipi_resrv)) - return -EBUSY; -#endif /* CONFIG_GENERIC_IRQ_IPI */ - err = irq_domain_set_hwirq_and_chip(d, virq, hwirq, &gic_level_irq_controller, NULL); @@ -570,146 +572,74 @@ static const struct irq_domain_ops gic_irq_domain_ops = { }; #ifdef CONFIG_GENERIC_IRQ_IPI - -static int gic_ipi_domain_xlate(struct irq_domain *d, struct device_node *ctrlr, - const u32 *intspec, unsigned int intsize, - irq_hw_number_t *out_hwirq, - unsigned int *out_type) -{ - /* - * There's nothing to translate here. hwirq is dynamically allocated and - * the irq type is always edge triggered. - * */ - *out_hwirq = 0; - *out_type = IRQ_TYPE_EDGE_RISING; - - return 0; -} - -static int gic_ipi_domain_alloc(struct irq_domain *d, unsigned int virq, - unsigned int nr_irqs, void *arg) -{ - struct cpumask *ipimask = arg; - irq_hw_number_t hwirq, base_hwirq; - int cpu, ret, i; - - base_hwirq = find_first_bit(ipi_available, gic_shared_intrs); - if (base_hwirq == gic_shared_intrs) - return -ENOMEM; - - /* check that we have enough space */ - for (i = base_hwirq; i < nr_irqs; i++) { - if (!test_bit(i, ipi_available)) - return -EBUSY; - } - bitmap_clear(ipi_available, base_hwirq, nr_irqs); - - /* map the hwirq for each cpu consecutively */ - i = 0; - for_each_cpu(cpu, ipimask) { - hwirq = GIC_SHARED_TO_HWIRQ(base_hwirq + i); - - ret = irq_domain_set_hwirq_and_chip(d, virq + i, hwirq, - &gic_edge_irq_controller, - NULL); - if (ret) - goto error; - - ret = irq_domain_set_hwirq_and_chip(d->parent, virq + i, hwirq, - &gic_edge_irq_controller, - NULL); - if (ret) - goto error; - - ret = irq_set_irq_type(virq + i, IRQ_TYPE_EDGE_RISING); - if (ret) - goto error; - - ret = gic_shared_irq_domain_map(d, virq + i, hwirq, cpu); - if (ret) - goto error; - - i++; - } - - return 0; -error: - bitmap_set(ipi_available, base_hwirq, nr_irqs); - return ret; -} - -static void gic_ipi_domain_free(struct irq_domain *d, unsigned int virq, - unsigned int nr_irqs) +static void gic_handle_ipi_irq(struct irq_desc *desc) { - irq_hw_number_t base_hwirq; - struct irq_data *data; + struct irq_chip *chip = irq_desc_get_chip(desc); - data = irq_get_irq_data(virq); - if (!data) - return; - - base_hwirq = GIC_HWIRQ_TO_SHARED(irqd_to_hwirq(data)); - bitmap_set(ipi_available, base_hwirq, nr_irqs); + chained_irq_enter(chip, desc); + ipi_mux_process(); + chained_irq_exit(chip, desc); } -static int gic_ipi_domain_match(struct irq_domain *d, struct device_node *node, - enum irq_domain_bus_token bus_token) +static void gic_ipi_send(unsigned int cpu) { - bool is_ipi; - - switch (bus_token) { - case DOMAIN_BUS_IPI: - is_ipi = d->bus_token == bus_token; - return (!node || to_of_node(d->fwnode) == node) && is_ipi; - break; - default: - return 0; - } + write_gic_wedge(GIC_WEDGE_RW | cpu_ipi_intr[cpu]); } -static const struct irq_domain_ops gic_ipi_domain_ops = { - .xlate = gic_ipi_domain_xlate, - .alloc = gic_ipi_domain_alloc, - .free = gic_ipi_domain_free, - .match = gic_ipi_domain_match, -}; - -static int gic_register_ipi_domain(struct device_node *node) +static int gic_ipi_mux_init(struct device_node *node, struct irq_domain *d) { - struct irq_domain *gic_ipi_domain; - unsigned int v[2], num_ipis; - - gic_ipi_domain = irq_domain_add_hierarchy(gic_irq_domain, - IRQ_DOMAIN_FLAG_IPI_PER_CPU, - GIC_NUM_LOCAL_INTRS + gic_shared_intrs, - node, &gic_ipi_domain_ops, NULL); - if (!gic_ipi_domain) { - pr_err("Failed to add IPI domain"); - return -ENXIO; - } - - irq_domain_update_bus_token(gic_ipi_domain, DOMAIN_BUS_IPI); + unsigned int i, v[2], num_ipis; + int ipi_virq, cpu = 0; if (node && !of_property_read_u32_array(node, "mti,reserved-ipi-vectors", v, 2)) { bitmap_set(ipi_resrv, v[0], v[1]); } else { /* - * Reserve 2 interrupts per possible CPU/VP for use as IPIs, - * meeting the requirements of arch/mips SMP. + * Reserve 1 interrupts per possible CPU/VP for use as IPIs */ - num_ipis = 2 * num_possible_cpus(); + num_ipis = num_possible_cpus(); bitmap_set(ipi_resrv, gic_shared_intrs - num_ipis, num_ipis); } - bitmap_copy(ipi_available, ipi_resrv, GIC_MAX_INTRS); + ipi_virq = ipi_mux_create(IPI_MAX, gic_ipi_send); + + WARN_ON(bitmap_weight(ipi_resrv, GIC_MAX_INTRS) < num_possible_cpus()); + + for_each_set_bit(i, ipi_resrv, GIC_MAX_INTRS) { + struct irq_fwspec fwspec; + int virq; + + fwspec.fwnode = of_node_to_fwnode(node); + fwspec.param_count = 3; + fwspec.param[0] = GIC_SHARED; + fwspec.param[1] = i; + fwspec.param[2] = IRQ_TYPE_EDGE_RISING; + + virq = irq_create_fwspec_mapping(&fwspec); + if (!virq) + return -EINVAL; + + gic_shared_irq_domain_map(d, virq, GIC_SHARED_TO_HWIRQ(i), cpu); + irq_set_chained_handler(virq, gic_handle_ipi_irq); + gic_clear_pcpu_masks(i); + set_bit(i, per_cpu_ptr(pcpu_masks, cpu)); + + cpu_ipi_intr[cpu] = i; + + cpu++; + if (cpu >= num_possible_cpus()) + break; + } + + mips_smp_ipi_set_virq_range(ipi_virq, IPI_MAX); return 0; } #else /* !CONFIG_GENERIC_IRQ_IPI */ -static inline int gic_register_ipi_domain(struct device_node *node) +static inline int gic_ipi_mux_init(struct device_node *node) { return 0; } @@ -809,10 +739,6 @@ static int __init gic_of_init(struct device_node *node, return -ENXIO; } - ret = gic_register_ipi_domain(node); - if (ret) - return ret; - board_bind_eic_interrupt = &gic_bind_eic_interrupt; /* Setup defaults */ @@ -822,6 +748,10 @@ static int __init gic_of_init(struct device_node *node, write_gic_rmask(i); } + ret = gic_ipi_mux_init(node, gic_irq_domain); + if (ret) + return ret; + return cpuhp_setup_state(CPUHP_AP_IRQ_MIPS_GIC_STARTING, "irqchip/mips/gic:starting", gic_cpu_startup, NULL); From patchwork Sun Jun 16 21:03:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699667 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C575757EA; Sun, 16 Jun 2024 21:03:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571832; cv=none; b=a4X6xuhe9vhSKhL7XwXlfflyMs5yaklDvXNafWIDPhqFgem9+eG3YQh6IuX/UtzUSaOMOR/wsqeIj5S/V9LySupcuH8BAkLctrtIbspljmhmLDJQxTYjb3cJp8Z4+AwySgCQcza1PEpsYOFqDfXMB4uD9N67GjXRZWZhFycJvDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571832; c=relaxed/simple; bh=s7QtoyV8CJzkclWybiBuG4D3q2iZmeH1TgYwpMpAX+E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fzaO64Nl8yQWbkihxuvUfEMMoyibHjBOFLGK3Sdx7JWqW1SduVK6P5qv3TZ+EOxbfH2Sildvx/9UfLfzAUR/l6d5a1hnPFjxSEJ5J1PBLVSGpL+i+1X4G7BcVeKL+v1IFVF+IQ9zUlFDb5XwGt5NjagL8LnEQ+sPneBHUxtfqzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=UZQjiHze; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=psr5Pb3G; arc=none smtp.client-ip=64.147.123.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="UZQjiHze"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="psr5Pb3G" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id C6F4218000B3; Sun, 16 Jun 2024 17:03:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 16 Jun 2024 17:03:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571829; x=1718658229; bh=TuRWWa0una2yxVoN3twYoJOXAIorrBg19Mp60gwXJOU=; b= UZQjiHze4fkfCLQgVcSm3i/gWDuvdK1LupImoPnZM5kndNZtyhgeziroWCnSY6Pt Bv3KTAqWErpWx5L/YocDIVh3/NJJtfpbu14YDDLyKTQPdHGtvQnows5KiU0d/9UH Z3MscWCCp+NnVbIyWUqFPk6+1JyhSbGSjdGg1IY6RM3VCBBFxVQwkZs+vDicUznG c7aBLNpy/L3jFhNIGuyxzJWKqneWIqrdBBLMp1TvtP6h+YK5vxbuWKbdhK1hbZ7f weg7x8qIYBYVCfw6XhHbvtulhKrFS9Y3ENJvEp02Dxfb51SOASlpUeG9TjD2j2uw Op1d/HpzmYSVKPU6m4Cmlg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571829; x= 1718658229; bh=TuRWWa0una2yxVoN3twYoJOXAIorrBg19Mp60gwXJOU=; b=p sr5Pb3GSFP3Xz+nF2NOYzkLM08zr0KQAm6g7eAsLFhZXI4ERoRzNavmGMxlNUNs7 Sbo9yQavNYg6q19vOecCA3N7La+SkD7VntqMzzWGp9ChJn+5AUCkMKLkFU8AzYH2 M7u+M1zZFLciQ7DnjYKmAp4v24cdrhR2xMaBZE0SwPchhwU0Vm/Ztd3pBaPVcn5n 4W5kZyGPK19X/miWPxH7sm9GjyIKdDlGdf0tbN851mTzAsCfSE+8Smq7VT0DkfxW n2wyQcdNe1hpDjHCTrcw7aZBBr2qqPizZoiDHtzlsNhrDdLi7Nx5ZvvQS8gB7JEh PLwNEL8apL5nlXzfxHxFg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:47 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:11 +0100 Subject: [PATCH 07/10] MIPS: Implement get_mips_sw_int hook Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-7-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2757; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=s7QtoyV8CJzkclWybiBuG4D3q2iZmeH1TgYwpMpAX+E=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YPnfZc9+npu5/HNwPJvDrsVOBffX9y/dvmJ7mpNDH gvPymyTjlIWBjEuBlkxRZYQAaW+DY0XF1x/kPUHZg4rE8gQBi5OAZjILDdGhgmiun19zJX6N8P3 rL3Du69zo8WhYA6Rjdve5Z5tEXurvIzhn8r0nBNsC97ZfzU6oBUcMG9DzNK5isU926ZvO7AoZNL WZTwA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 For MIPS CPUs with VEIC, SW0 and SW1 interrupts are also routed through external sources. We need such hook to allow architecture code to get interrupt source from platform EIC controllers. Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/irq.h | 1 + arch/mips/include/asm/irq_cpu.h | 3 +++ arch/mips/kernel/irq.c | 17 +++++++++++++++++ drivers/irqchip/irq-mips-cpu.c | 11 +++++++++++ 4 files changed, 32 insertions(+) diff --git a/arch/mips/include/asm/irq.h b/arch/mips/include/asm/irq.h index 3a848e7e69f7..6edad40ef663 100644 --- a/arch/mips/include/asm/irq.h +++ b/arch/mips/include/asm/irq.h @@ -51,6 +51,7 @@ static inline int irq_canonicalize(int irq) #else #define irq_canonicalize(irq) (irq) /* Sane hardware, sane code ... */ #endif +int get_mips_sw_int(int hwint); asmlinkage void plat_irq_dispatch(void); diff --git a/arch/mips/include/asm/irq_cpu.h b/arch/mips/include/asm/irq_cpu.h index 83d7331ab215..50a99ba2d503 100644 --- a/arch/mips/include/asm/irq_cpu.h +++ b/arch/mips/include/asm/irq_cpu.h @@ -9,7 +9,10 @@ #ifndef _ASM_IRQ_CPU_H #define _ASM_IRQ_CPU_H +#include + extern void mips_cpu_irq_init(void); +extern int mips_cpu_get_sw_int(int hwint); #ifdef CONFIG_IRQ_DOMAIN struct device_node; diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c index c3ea8d80e0cb..c79504b12134 100644 --- a/arch/mips/kernel/irq.c +++ b/arch/mips/kernel/irq.c @@ -26,10 +26,27 @@ #include #include +#include #include void *irq_stack[NR_CPUS]; +int __weak get_mips_sw_int(int hwint) +{ + /* Only SW0 and SW1 */ + WARN_ON(hwint > 1); + + /* SW int is routed to external source */ + if (cpu_has_veic) + return 0; + +#ifdef CONFIG_IRQ_MIPS_CPU + return mips_cpu_get_sw_int(hwint); +#endif + + return MIPS_CPU_IRQ_BASE + hwint; +} + /* * 'what should we do if we get a hw irq event on an illegal vector'. * each architecture has to answer this themselves. diff --git a/drivers/irqchip/irq-mips-cpu.c b/drivers/irqchip/irq-mips-cpu.c index 0c7ae71a0af0..7b3501485d95 100644 --- a/drivers/irqchip/irq-mips-cpu.c +++ b/drivers/irqchip/irq-mips-cpu.c @@ -254,6 +254,17 @@ static inline void mips_cpu_register_ipi_domain(struct device_node *of_node) {} #endif /* !CONFIG_GENERIC_IRQ_IPI */ +int mips_cpu_get_sw_int(int hwint) +{ + /* Only 0 and 1 for SW INT */ + WARN_ON(hwint > 1); + + if (!irq_domain) + return 0; + + return irq_create_mapping(irq_domain, hwint); +} + static void __init __mips_cpu_irq_init(struct device_node *of_node) { /* Mask interrupts. */ From patchwork Sun Jun 16 21:03:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699668 Received: from wfout5-smtp.messagingengine.com (wfout5-smtp.messagingengine.com [64.147.123.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 136C4770E0; Sun, 16 Jun 2024 21:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571835; cv=none; b=WL0kppPOu/JakdwqbUGTA3WKHj/1rCHhyzM5nqdpTigPncjTLU8uL31/m+Hj/BAygB20b/HaRxFgFhaK9LibwTyR1NL0f88e/qcyzavNscuMuYTmIRDyeKb9ERJygGVYDGkh5yiFczVqIVTdi93JgflPIlTs8x9kQFUdhb0nLAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571835; c=relaxed/simple; bh=M7QLa/e1lk3STQUI3hDEqiWEkdYQ/BEky6bbW4aA6gc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g0Q0FbFcSCc6ECoalBAvLPHoR/AO4E2zlOuIP/l3xg4xw87LYa5oUah060u6KNQOEQP/z2oXlKo/WimknMsakKcVTTue+4VmHehJ63UaVBSd3yGSueRxsU+lbMLzk4evVzmR3CJBUUvphq4Aaj86Z/DnPLYYUKMJLy4SXar48EM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=Jx8lS8jg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=M4yGCOW2; arc=none smtp.client-ip=64.147.123.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="Jx8lS8jg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="M4yGCOW2" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 8D3171C00096; Sun, 16 Jun 2024 17:03:52 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 16 Jun 2024 17:03:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571832; x=1718658232; bh=ntsitKeg5CsLfeZpSVRZzPRKq1noIPQvxwa7wZoq0QM=; b= Jx8lS8jgU0MYxmaRAlGEz1VZ0qeGv6uolEPGMKlgtUSkT7zQvh+vLO1Qi7/yJHCU rxbxA63nhwhpq+Q1cM3rsPIDG8dsBEJqVilTEOLCxMxzabChKLy1Hw0j5vAPF/Aw /MPsJ4tBIYSFfnfCM9fyD/5HEJtHsgXCHSEYkM4V3GYCQmN6CXDmphOB7VeESs39 QpU1a/Qui+npPnolyUkMjzmhv8vBqGA0o5rScxEZ8xhsm8pr5Tas9xSAhHNONmeV uc/0Il/zmNS6GeA0KjbFrVdO/82/sXXIOuHnekVwM1fVXxrdMCN6IDhndL/pDd10 3sSUA8+yKolwTLjmErFOsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571832; x= 1718658232; bh=ntsitKeg5CsLfeZpSVRZzPRKq1noIPQvxwa7wZoq0QM=; b=M 4yGCOW2sJWN+rz2zTowNuOlGZ2cMey1fTrYm+X32iVuN/Qd2ZJ4DYVOm6coz53Yl nt2FhNu9Tmk6CjHNvkyZWLnvgIfuvhhGIv9I+xX+HwhkBlZXlan+0KccDvaodHXz +ONBH1L6mlKjAZGyT4F04q/1oTnCXoSoB0XLg5LvLuHnCiV6UpoqYortfkg4Q4pm 7mYxslMBC6of+Lw50fntCdzXkijr1DDOeuf8md5QVctHK4yBCqapw3rs3wS8bshc g/Tp084hlWoF7/JfOdPS0O+kMjCC0fpEKtC327j1E+d658oJ/3w3sq3FSF3/qGNB ruftV3OY8fpOqu3xR8fJQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:50 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:12 +0100 Subject: [PATCH 08/10] MIPS: GIC: Implement get_sw_int hook Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-8-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2476; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=M7QLa/e1lk3STQUI3hDEqiWEkdYQ/BEky6bbW4aA6gc=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YHlBJ44nRxJXZH9fIXHq+H7B15Vrr9+4FXZH++ey0 JDUdXOudpSyMIhxMciKKbKECCj1bWi8uOD6g6w/MHNYmUCGMHBxCsBEXi9iZOi9evH8h1ThLeyW CyfvYG1cbm4xXaT5y0/WXM1j+/J6Njxi+KfvcDi0VXPavtgFa1053mnWLd47iWHHnWChq49U/Tz j1vECAA== X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 SW0 and SW1 interrupts are routed through GIC in EIC mode, implement get_sw_int hook for GIC and generic platform to create IRQ mapping for SW0 and SW1 in such mode. Signed-off-by: Jiaxun Yang --- arch/mips/generic/irq.c | 15 +++++++++++++++ arch/mips/include/asm/mips-gic.h | 10 ++++++++++ drivers/irqchip/irq-mips-gic.c | 15 +++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/arch/mips/generic/irq.c b/arch/mips/generic/irq.c index 933119262943..bc3599a76014 100644 --- a/arch/mips/generic/irq.c +++ b/arch/mips/generic/irq.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -59,3 +60,17 @@ unsigned int get_c0_compare_int(void) return mips_cpu_timer_irq; } + +int get_mips_sw_int(int hwint) +{ + int mips_sw_int_irq; + + if (mips_gic_present()) + mips_sw_int_irq = gic_get_sw_int(hwint); + else if (cpu_has_veic) + panic("Unimplemented!"); + else + mips_sw_int_irq = mips_cpu_get_sw_int(hwint); + + return mips_sw_int_irq; +} diff --git a/arch/mips/include/asm/mips-gic.h b/arch/mips/include/asm/mips-gic.h index 084cac1c5ea2..83f0d04763bb 100644 --- a/arch/mips/include/asm/mips-gic.h +++ b/arch/mips/include/asm/mips-gic.h @@ -370,4 +370,14 @@ extern int gic_get_c0_perfcount_int(void); */ extern int gic_get_c0_fdc_int(void); +/** + * gic_get_sw_int() - Return software interrupt virq + * + * Determine the virq number to use for SWINT0 or SWINT1 interrupts, + * which may be routed via the GIC. + * + * Returns the virq number or a negative error number. + */ +extern int gic_get_sw_int(int hwirq); + #endif /* __MIPS_ASM_MIPS_CPS_H__ */ diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c index eb58392f0e66..1fbd7de3796b 100644 --- a/drivers/irqchip/irq-mips-gic.c +++ b/drivers/irqchip/irq-mips-gic.c @@ -143,6 +143,21 @@ int gic_get_c0_fdc_int(void) GIC_LOCAL_TO_HWIRQ(GIC_LOCAL_INT_FDC)); } +int gic_get_sw_int(int hwint) +{ + int local_irq; + + WARN_ON(hwint > 1); + + local_irq = GIC_LOCAL_INT_SWINT0 + hwint; + + if (!gic_local_irq_is_routable(local_irq)) + return MIPS_CPU_IRQ_BASE + hwint; + + return irq_create_mapping(gic_irq_domain, + GIC_LOCAL_TO_HWIRQ(local_irq)); +} + static void gic_handle_shared_int(bool chained) { unsigned int intr; From patchwork Sun Jun 16 21:03:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699669 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D707C811E0; Sun, 16 Jun 2024 21:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571838; cv=none; b=qwNZltuH+oYYNELKlpRFb3+5cSJhxhLDYogmrZplPvDu0nL0lYC7JlrvXVRu5IsOyhztrCIPUgHxPZuN90Rfr9Xe0AEkE55HBsjz43ERICFPsKBTbiYh2W8JsDBrYpeG/SrMr+2F21XOV/M2GFRG9HjDvHCAI1Rs/FMxUvK9Wfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571838; c=relaxed/simple; bh=t0jFM1TdkV0L/QJh4f56eeC76Lk7sZp8QfAutyHMpjY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jNd2gJJpP++VJouK5ryt4QtWee5TxkpqSgxZdCh60EFu8Q7UVGOLy9c8jKT3q+WgzbXOv3LCwQgUu5ZJNYqzYNmgHEGffF+k7YgeN112JGQ7jtrXCv34e459OpRlb05Qgid8leYLgBwAUc0OcLRh0HFbjBQHa7Np02QbOcR9doY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=Z8AQqTam; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LOkZxOgU; arc=none smtp.client-ip=64.147.123.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="Z8AQqTam"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LOkZxOgU" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 6D1BD18000AC; Sun, 16 Jun 2024 17:03:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 16 Jun 2024 17:03:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571835; x=1718658235; bh=BvspTC56CbdmoNTWhom8B4pXPgn+9ltSQD8Mt84pARk=; b= Z8AQqTamFzClAy5d5oKNVNE3FqgQ5ZtXIgUaAM947S4iTlSAEhfHTfcddLMJeis3 MMQ0SXxuA4CFLL9MMHmkCEfJ7p26Llp9SDxF89TdwcrosnOMligwoU/XV1GRx8La z+hkiIKGppRr3bdQTDh46ZqAZLX4IHgXQU3RZZFv4Wj376Zv3L6XrppM5QncpRK6 Ouu757vhfu9br4ic/dufiSjdFfJmEp6hwpEIanjcptS+KVAQ9GOauo2Gio0Q4mZ7 R2y4/3pMDq9OMZO5BKcK07OvIvj7O/lh+kBHHaOY1IngxnLEJpfUB3YfqvH/Yr6S lUIUGEQs88nKh4X+J+n/UQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571835; x= 1718658235; bh=BvspTC56CbdmoNTWhom8B4pXPgn+9ltSQD8Mt84pARk=; b=L OkZxOgUcHPS2yzuaICn7hdxgNC0qQxt8YDKt9bTl7nblErQ8udSZKNLwTs3OlLjf /EiBSXvPXhx7VEMi1lQF35Lv6uwH3dk5wUl4Z4ya5OzgUw5EnViYQZrdpMYPYIhh c34Yod0PdgDYXcTrJe8aQR8YWQOBXovjV+gT24xAiT77+irD/cJ7U0owJMU9Vv97 kTB4PT17tHUn820rTQ5BhZSrpwMyAoeluu48PvraCWcklwRVExxoaWFZze+Gnk0L 9VDfPvwUxX7wrh1RLq0pMJbok1bKY6KihcTOPFClbHA5H+OKB9NiJSr0XE4aADxM OF9rj8qnuA63O18grnG4A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:53 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:13 +0100 Subject: [PATCH 09/10] irqchip: irq-mips-cpu: Rework software IRQ handling flow Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-9-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3767; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=t0jFM1TdkV0L/QJh4f56eeC76Lk7sZp8QfAutyHMpjY=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YPm5CcVGCh/sZ2TU7tYTMJcLKPVcP+/2befuHuGi3 IdeJsYdpSwMYlwMsmKKLCECSn0bGi8uuP4g6w/MHFYmkCEMXJwCMBGja4wMv471RTEs2p221lCn UFmyd5FI9vbAFqWcjfNuKUWxmV7vYmSYoHG4xrbmZ66k59MVb63nJc/fzsJsLRRaYFul9mxihBg jAA== X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Remove unnecessary irq_chip hooks for software interrupts, and don't mask them in ack hook to match kernel's expectation on handling flow. Create a irq_chip for regular (non-MT) mode software interrupts so they will be acked as well. Signed-off-by: Jiaxun Yang --- drivers/irqchip/irq-mips-cpu.c | 57 +++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/drivers/irqchip/irq-mips-cpu.c b/drivers/irqchip/irq-mips-cpu.c index 7b3501485d95..4854c06ce652 100644 --- a/drivers/irqchip/irq-mips-cpu.c +++ b/drivers/irqchip/irq-mips-cpu.c @@ -49,7 +49,21 @@ static inline void mask_mips_irq(struct irq_data *d) irq_disable_hazard(); } -static struct irq_chip mips_cpu_irq_controller = { +static unsigned int mips_sw_irq_startup(struct irq_data *d) +{ + clear_c0_cause(C_SW0 << d->hwirq); + back_to_back_c0_hazard(); + unmask_mips_irq(d); + return 0; +} + +static void mips_sw_irq_ack(struct irq_data *d) +{ + clear_c0_cause(C_SW0 << d->hwirq); + back_to_back_c0_hazard(); +} + +static const struct irq_chip mips_cpu_irq_controller = { .name = "MIPS", .irq_ack = mask_mips_irq, .irq_mask = mask_mips_irq, @@ -60,11 +74,19 @@ static struct irq_chip mips_cpu_irq_controller = { .irq_enable = unmask_mips_irq, }; +static const struct irq_chip mips_cpu_sw_irq_controller = { + .name = "MIPS", + .irq_startup = mips_sw_irq_startup, + .irq_ack = mips_sw_irq_ack, + .irq_mask = mask_mips_irq, + .irq_unmask = unmask_mips_irq, +}; + +#ifdef CONFIG_MIPS_MT /* * Basically the same as above but taking care of all the MT stuff */ - -static unsigned int mips_mt_cpu_irq_startup(struct irq_data *d) +static unsigned int mips_mt_sw_irq_startup(struct irq_data *d) { unsigned int vpflags = dvpe(); @@ -76,14 +98,14 @@ static unsigned int mips_mt_cpu_irq_startup(struct irq_data *d) /* * While we ack the interrupt interrupts are disabled and thus we don't need - * to deal with concurrency issues. Same for mips_cpu_irq_end. + * to deal with concurrency issues. */ -static void mips_mt_cpu_irq_ack(struct irq_data *d) +static void mips_mt_sw_irq_ack(struct irq_data *d) { unsigned int vpflags = dvpe(); + clear_c0_cause(C_SW0 << d->hwirq); evpe(vpflags); - mask_mips_irq(d); } #ifdef CONFIG_GENERIC_IRQ_IPI @@ -108,21 +130,17 @@ static void mips_mt_send_ipi(struct irq_data *d, unsigned int cpu) } #endif /* CONFIG_GENERIC_IRQ_IPI */ - -static struct irq_chip mips_mt_cpu_irq_controller = { +static const struct irq_chip mips_mt_cpu_irq_controller = { .name = "MIPS", - .irq_startup = mips_mt_cpu_irq_startup, - .irq_ack = mips_mt_cpu_irq_ack, + .irq_startup = mips_mt_sw_irq_startup, + .irq_ack = mips_mt_sw_irq_ack, .irq_mask = mask_mips_irq, - .irq_mask_ack = mips_mt_cpu_irq_ack, .irq_unmask = unmask_mips_irq, - .irq_eoi = unmask_mips_irq, - .irq_disable = mask_mips_irq, - .irq_enable = unmask_mips_irq, #ifdef CONFIG_GENERIC_IRQ_IPI .ipi_send_single = mips_mt_send_ipi, #endif }; +#endif asmlinkage void __weak plat_irq_dispatch(void) { @@ -152,11 +170,14 @@ asmlinkage void __weak plat_irq_dispatch(void) static int mips_cpu_intc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw) { - struct irq_chip *chip; + const struct irq_chip *chip; - if (hw < 2 && cpu_has_mipsmt) { - /* Software interrupts are used for MT/CMT IPI */ - chip = &mips_mt_cpu_irq_controller; + if (hw < 2) { + chip = &mips_cpu_sw_irq_controller; +#ifdef CONFIG_MIPS_MT + if (cpu_has_mipsmt) + chip = &mips_mt_cpu_irq_controller; +#endif } else { chip = &mips_cpu_irq_controller; } From patchwork Sun Jun 16 21:03:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13699670 Received: from wfhigh6-smtp.messagingengine.com (wfhigh6-smtp.messagingengine.com [64.147.123.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C65B127E0D; Sun, 16 Jun 2024 21:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571841; cv=none; b=S31i3NxhKpwr34RF6lHWPjVLGE+PuafrWVof65m87Agte7K8uGwnu56oyxvfKlJUUUYqQ8gIzsYfc9ni9DPjQmd8oAW/LOgkuokVZw/RL7kojRvXdb8X25pnLej+XSyiUz8WzWCPqd0p3CAXRCeRuNjY+ZfkBex4nCBGtfRIWgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718571841; c=relaxed/simple; bh=lx7xVfQehBExS3lQLZp71uNbKmPoI6Kqrmrljn//Kv4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WKupRHEnqws+NRMait1Glj+duh687JsqKrh0kb1i6NLYMuN176EfkjBjq8asEI5/lgbqZHbrBj8Xj3JGXfBmF/MQl+BvcW2kUGE+wAPMk124P28QcPU/x8HOe6uyoi6Z6eZumHNGkEpWpGK13QsFOZx0rkWlvfd7JlRVyn8vOOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=aFw6CzoV; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=idsnXLte; arc=none smtp.client-ip=64.147.123.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="aFw6CzoV"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="idsnXLte" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 465CB18000C2; Sun, 16 Jun 2024 17:03:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 16 Jun 2024 17:03:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1718571837; x=1718658237; bh=erzt0wSfB45ZGsaDWZkMLOXkQkwqDZK8Y6ZCLzKDr2o=; b= aFw6CzoV+nJxTHTsQjOcmCYhKbc/9QeKJ3IHoyefrMdFQDljjVLFlK3/Sd2L9cbw H5IwZBhfZ4WR2XOWxDUCPQN3FIh+xhscjxH3iep34wdzrkHBUmVcspyj56CXyx4z bTwUjq+eeHQH/fGrFJ25jwwPky87PR8M0ntynwj9uU/+jj4OkAELPN1hvtBxPx7B AyGnmzgCZlWpvLTlj7xEXKER2fL621wzB8aIdIOyrVYfR2ZC7yd0lDwiwlb1ZIFK jNkeidZT+B+Y0+iscrJwtlIrsRaVBjVggnzDmLGNwcq5rEicYiHihYFp2MS5ze4b 4u6JF9iOXxEOoJ3RcoRqJg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718571837; x= 1718658237; bh=erzt0wSfB45ZGsaDWZkMLOXkQkwqDZK8Y6ZCLzKDr2o=; b=i dsnXLtetrlfn4qXcuCPwkRrNBBmknNUsxz/H0j5Edch4YySHHrh7fyqdLgQN9JH7 vyNiolKb/UPIFjZVkTntKhFb7hp4igVtktjkr7/CYPomzcRYabYPbRSjIW42vfrh D17ny/anKIWnEeMJjF8sZQcDsGaT2SiGNm/fE5RwHLsox2gzgTKE4siUYZphotWL lqeh4JMkdFizg+6S2DOHr1PwmsjBl6GitAFMWZp/YVJZgz4LKVLGT7/L9NeGCTTB RfuSgXtZgm4n3dZhHeKtX0pGgJyDLsn6jlC0I5SZ6Mb+Obaj/dT0azKf5EOafo4/ Us8l1Fsfl4himhoM2yUBQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvfedgudehjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheplfhi rgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmqe enucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleffkeegudeghfdtuddugefh ueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrih hlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 16 Jun 2024 17:03:56 -0400 (EDT) From: Jiaxun Yang Date: Sun, 16 Jun 2024 22:03:14 +0100 Subject: [PATCH 10/10] MIPS: smp-mt: Rework IPI functions Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240616-b4-mips-ipi-improvements-v1-10-e332687f1692@flygoat.com> References: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> In-Reply-To: <20240616-b4-mips-ipi-improvements-v1-0-e332687f1692@flygoat.com> To: Thomas Bogendoerfer , Florian Fainelli , Broadcom internal kernel review list , Huacai Chen , Thomas Gleixner , Serge Semin , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Jiaxun Yang X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8867; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=lx7xVfQehBExS3lQLZp71uNbKmPoI6Kqrmrljn//Kv4=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrT8YHnj7ZpHuKbknH/49PRhB96PTb2udnGfC1TF5Gdoe 17yTe3rKGVhEONikBVTZAkRUOrb0HhxwfUHWX9g5rAygQxh4OIUgIlUPmf4H5km+rs1gmHxwZKa EI+tx39/1tfKTZs5h1dZZGLizVb9fwz/E56d4ogNDy474jzrdpe9buecmcsZtnN12+y+lXfuWJo DFwA= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Move smp IRQ code from irq-mips-cpu to smp-mt as IPI is not really relavant to CPU intc. In VEIC mode we can have irq-mips-cpu not registered and SW interrupts comes from EIC controllers. Implement IPI with ipi-mux to allow easy extension to number of IPIs. Signed-off-by: Jiaxun Yang --- arch/mips/Kconfig | 2 + arch/mips/kernel/smp-mt.c | 70 +++++++++++++++++++++++ drivers/irqchip/Kconfig | 1 - drivers/irqchip/irq-mips-cpu.c | 124 +---------------------------------------- 4 files changed, 74 insertions(+), 123 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 1236ea122061..de06c7425e94 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -2188,6 +2188,8 @@ config MIPS_MT_SMP depends on SYS_SUPPORTS_MULTITHREADING && !CPU_MICROMIPS select CPU_MIPSR2_IRQ_VI select CPU_MIPSR2_IRQ_EI + select GENERIC_IRQ_IPI + select GENERIC_IRQ_IPI_MUX select SYNC_R4K select MIPS_MT select SMP diff --git a/arch/mips/kernel/smp-mt.c b/arch/mips/kernel/smp-mt.c index 7729cc733421..2f00077dbf07 100644 --- a/arch/mips/kernel/smp-mt.c +++ b/arch/mips/kernel/smp-mt.c @@ -10,6 +10,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -19,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +31,65 @@ #include #include +static int vsmp_sw0_virq __ro_after_init; + +static void smvp_handle_ipi_irq(struct irq_desc *desc) +{ + struct irq_chip *chip = irq_desc_get_chip(desc); + + chained_irq_enter(chip, desc); + + /* irq-mips-cpu would ack for us, but EIC drivers won't */ + if (cpu_has_veic) { + unsigned int vpflags = dvpe(); + + clear_c0_cause(C_SW0); + evpe(vpflags); + } + ipi_mux_process(); + + chained_irq_exit(chip, desc); +} + +static void smvp_ipi_send(unsigned int cpu) +{ + unsigned long flags; + int vpflags; + + local_irq_save(flags); + + /* We can only send IPIs to VPEs within the local core */ + WARN_ON(!cpus_are_siblings(smp_processor_id(), cpu)); + vpflags = dvpe(); + settc(cpu_vpe_id(&cpu_data[cpu])); + write_vpe_c0_status(read_vpe_c0_status() | C_SW0); + write_vpe_c0_cause(read_vpe_c0_cause() | C_SW0); + evpe(vpflags); + + local_irq_restore(flags); +} + +static int __init vsmp_ipi_init(void) +{ + int sw0_virq, mux_virq; + + /* SW0 Interrupt for IPI */ + sw0_virq = get_mips_sw_int(0); + if (!sw0_virq) + return -EINVAL; + + mux_virq = ipi_mux_create(IPI_MAX, smvp_ipi_send); + if (!mux_virq) + return -EINVAL; + + irq_set_percpu_devid(sw0_virq); + irq_set_chained_handler(sw0_virq, smvp_handle_ipi_irq); + mips_smp_ipi_set_virq_range(mux_virq, IPI_MAX); + vsmp_sw0_virq = sw0_virq; + + return 0; +} + static void __init smvp_copy_vpe_config(void) { write_vpe_c0_status( @@ -123,6 +187,8 @@ static void vsmp_smp_finish(void) /* CDFIXME: remove this? */ write_c0_compare(read_c0_count() + (8* mips_hpt_frequency/HZ)); + enable_percpu_irq(vsmp_sw0_virq, IRQ_TYPE_NONE); + #ifdef CONFIG_MIPS_MT_FPAFF /* If we have an FPU, enroll ourselves in the FPU-full mask */ if (cpu_has_fpu) @@ -226,7 +292,11 @@ static void __init vsmp_smp_setup(void) static void __init vsmp_prepare_cpus(unsigned int max_cpus) { + int rc; + mips_mt_set_cpuoptions(); + rc = vsmp_ipi_init(); + WARN_ON(rc); } const struct plat_smp_ops vsmp_smp_ops = { diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index 8665bbf31bb5..bb63b07faa27 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -175,7 +175,6 @@ config MADERA_IRQ config IRQ_MIPS_CPU bool select GENERIC_IRQ_CHIP - select GENERIC_IRQ_IPI if SMP && SYS_SUPPORTS_MULTITHREADING select IRQ_DOMAIN select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP diff --git a/drivers/irqchip/irq-mips-cpu.c b/drivers/irqchip/irq-mips-cpu.c index 4854c06ce652..456f58729d00 100644 --- a/drivers/irqchip/irq-mips-cpu.c +++ b/drivers/irqchip/irq-mips-cpu.c @@ -34,8 +34,7 @@ #include #include -static struct irq_domain *irq_domain; -static struct irq_domain *ipi_domain; +static struct irq_domain *irq_domain __read_mostly; static inline void unmask_mips_irq(struct irq_data *d) { @@ -108,37 +107,12 @@ static void mips_mt_sw_irq_ack(struct irq_data *d) evpe(vpflags); } -#ifdef CONFIG_GENERIC_IRQ_IPI - -static void mips_mt_send_ipi(struct irq_data *d, unsigned int cpu) -{ - irq_hw_number_t hwirq = irqd_to_hwirq(d); - unsigned long flags; - int vpflags; - - local_irq_save(flags); - - /* We can only send IPIs to VPEs within the local core */ - WARN_ON(!cpus_are_siblings(smp_processor_id(), cpu)); - - vpflags = dvpe(); - settc(cpu_vpe_id(&cpu_data[cpu])); - write_vpe_c0_cause(read_vpe_c0_cause() | (C_SW0 << hwirq)); - evpe(vpflags); - - local_irq_restore(flags); -} - -#endif /* CONFIG_GENERIC_IRQ_IPI */ static const struct irq_chip mips_mt_cpu_irq_controller = { .name = "MIPS", .irq_startup = mips_mt_sw_irq_startup, .irq_ack = mips_mt_sw_irq_ack, .irq_mask = mask_mips_irq, .irq_unmask = unmask_mips_irq, -#ifdef CONFIG_GENERIC_IRQ_IPI - .ipi_send_single = mips_mt_send_ipi, -#endif }; #endif @@ -154,15 +128,8 @@ asmlinkage void __weak plat_irq_dispatch(void) pending >>= CAUSEB_IP; while (pending) { - struct irq_domain *d; - irq = fls(pending) - 1; - if (IS_ENABLED(CONFIG_GENERIC_IRQ_IPI) && irq < 2) - d = ipi_domain; - else - d = irq_domain; - - do_domain_IRQ(d, irq); + do_domain_IRQ(irq_domain, irq); pending &= ~BIT(irq); } } @@ -195,86 +162,6 @@ static const struct irq_domain_ops mips_cpu_intc_irq_domain_ops = { .xlate = irq_domain_xlate_onecell, }; -#ifdef CONFIG_GENERIC_IRQ_IPI - -struct cpu_ipi_domain_state { - DECLARE_BITMAP(allocated, 2); -}; - -static int mips_cpu_ipi_alloc(struct irq_domain *domain, unsigned int virq, - unsigned int nr_irqs, void *arg) -{ - struct cpu_ipi_domain_state *state = domain->host_data; - unsigned int i, hwirq; - int ret; - - for (i = 0; i < nr_irqs; i++) { - hwirq = find_first_zero_bit(state->allocated, 2); - if (hwirq == 2) - return -EBUSY; - bitmap_set(state->allocated, hwirq, 1); - - ret = irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq, - &mips_mt_cpu_irq_controller, - NULL); - if (ret) - return ret; - - ret = irq_domain_set_hwirq_and_chip(domain->parent, virq + i, hwirq, - &mips_mt_cpu_irq_controller, - NULL); - - if (ret) - return ret; - - ret = irq_set_irq_type(virq + i, IRQ_TYPE_LEVEL_HIGH); - if (ret) - return ret; - } - - return 0; -} - -static int mips_cpu_ipi_match(struct irq_domain *d, struct device_node *node, - enum irq_domain_bus_token bus_token) -{ - bool is_ipi; - - switch (bus_token) { - case DOMAIN_BUS_IPI: - is_ipi = d->bus_token == bus_token; - return (!node || (to_of_node(d->fwnode) == node)) && is_ipi; - default: - return 0; - } -} - -static const struct irq_domain_ops mips_cpu_ipi_chip_ops = { - .alloc = mips_cpu_ipi_alloc, - .match = mips_cpu_ipi_match, -}; - -static void mips_cpu_register_ipi_domain(struct device_node *of_node) -{ - struct cpu_ipi_domain_state *ipi_domain_state; - - ipi_domain_state = kzalloc(sizeof(*ipi_domain_state), GFP_KERNEL); - ipi_domain = irq_domain_add_hierarchy(irq_domain, - IRQ_DOMAIN_FLAG_IPI_SINGLE, - 2, of_node, - &mips_cpu_ipi_chip_ops, - ipi_domain_state); - if (!ipi_domain) - panic("Failed to add MIPS CPU IPI domain"); - irq_domain_update_bus_token(ipi_domain, DOMAIN_BUS_IPI); -} - -#else /* !CONFIG_GENERIC_IRQ_IPI */ - -static inline void mips_cpu_register_ipi_domain(struct device_node *of_node) {} - -#endif /* !CONFIG_GENERIC_IRQ_IPI */ - int mips_cpu_get_sw_int(int hwint) { /* Only 0 and 1 for SW INT */ @@ -297,13 +184,6 @@ static void __init __mips_cpu_irq_init(struct device_node *of_node) NULL); if (!irq_domain) panic("Failed to add irqdomain for MIPS CPU"); - - /* - * Only proceed to register the software interrupt IPI implementation - * for CPUs which implement the MIPS MT (multi-threading) ASE. - */ - if (cpu_has_mipsmt) - mips_cpu_register_ipi_domain(of_node); } void __init mips_cpu_irq_init(void)