linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special
@ 2021-10-21 17:04 Marc Zyngier
  2021-10-21 17:04 ` [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline() Marc Zyngier
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Marc Zyngier @ 2021-10-21 17:04 UTC (permalink / raw)
  To: linux-mips, linux-kernel
  Cc: Thomas Bogendoerfer, Serge Semin, Huacai Chen, Jiaxun Yang,
	f.fainelli, Thomas Gleixner

Now that Florian has updated BMIPS to not rely on irq_cpu_offline [1],
it is pretty tempting to totally get of this misfeature. We can't
really do that because Octeon uses it like crazy, but the couple of
other users are easy to convert.

Once this is done, these helpers are hidden behind a config symbol
that depends on the Octeon platform being selected. When Octeon is
finally removed from the tree, we'll be able to drop this as well.


Marc Zyngier (3):
  MIPS: loongson64: Drop call to irq_cpu_offline()
  irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()
  genirq: Hide irq_cpu_{on,off}line() behind a deprecated option

 arch/mips/loongson64/smp.c     |  1 -
 drivers/irqchip/irq-mips-gic.c | 37 ++++++++++++++++++++++++----------
 include/linux/irq.h            |  5 ++++-
 kernel/irq/Kconfig             |  7 +++++++
 kernel/irq/chip.c              |  2 ++
 5 files changed, 39 insertions(+), 13 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline()
  2021-10-21 17:04 [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Marc Zyngier
@ 2021-10-21 17:04 ` Marc Zyngier
  2021-10-24 15:28   ` Thomas Bogendoerfer
                     ` (2 more replies)
  2021-10-21 17:04 ` [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online() Marc Zyngier
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 14+ messages in thread
From: Marc Zyngier @ 2021-10-21 17:04 UTC (permalink / raw)
  To: linux-mips, linux-kernel
  Cc: Thomas Bogendoerfer, Serge Semin, Huacai Chen, Jiaxun Yang,
	f.fainelli, Thomas Gleixner

Also loongson64 calls irq_cpu_offline(), none of its interrupt
controllers implement the .irq_cpu_offline callback.

It is thus obvious that this call only serves the dubious purpose
of wasting precious CPU cycles by iterating over all interrupts.

Get rid of the call altogether.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/mips/loongson64/smp.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index 09ebe84a17fe..660e1de4412a 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -550,7 +550,6 @@ static int loongson3_cpu_disable(void)
 	set_cpu_online(cpu, false);
 	calculate_cpu_foreign_map();
 	local_irq_save(flags);
-	irq_cpu_offline();
 	clear_c0_status(ST0_IM);
 	local_irq_restore(flags);
 	local_flush_tlb_all();
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()
  2021-10-21 17:04 [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Marc Zyngier
  2021-10-21 17:04 ` [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline() Marc Zyngier
@ 2021-10-21 17:04 ` Marc Zyngier
  2021-10-22 13:57   ` Serge Semin
                     ` (2 more replies)
  2021-10-21 17:04 ` [PATCH 3/3] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option Marc Zyngier
  2021-10-22 13:53 ` [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Serge Semin
  3 siblings, 3 replies; 14+ messages in thread
From: Marc Zyngier @ 2021-10-21 17:04 UTC (permalink / raw)
  To: linux-mips, linux-kernel
  Cc: Thomas Bogendoerfer, Serge Semin, Huacai Chen, Jiaxun Yang,
	f.fainelli, Thomas Gleixner

The MIPS GIC driver uses irq_cpu_online() to go and program the
per-CPU interrupts. However, this method iterates over all IRQs
in the system, despite only 3 per-CPU interrupts being of interest.

Let's be terribly bold and do the iteration ourselves. To ensure
mutual exclusion, hold the gic_lock spinlock that is otherwise
taken while dealing with these interrupts.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/irqchip/irq-mips-gic.c | 37 ++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index 54c7092cc61d..45c83dd804a0 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -381,24 +381,35 @@ static void gic_unmask_local_irq_all_vpes(struct irq_data *d)
 	spin_unlock_irqrestore(&gic_lock, flags);
 }
 
-static void gic_all_vpes_irq_cpu_online(struct irq_data *d)
+static void gic_all_vpes_irq_cpu_online(void)
 {
-	struct gic_all_vpes_chip_data *cd;
-	unsigned int intr;
+	static unsigned int local_intrs[] = {
+		GIC_LOCAL_INT_TIMER,
+		GIC_LOCAL_INT_PERFCTR,
+		GIC_LOCAL_INT_FDC,
+	};
+	unsigned long flags;
+	int i;
 
-	intr = GIC_HWIRQ_TO_LOCAL(d->hwirq);
-	cd = irq_data_get_irq_chip_data(d);
+	spin_lock_irqsave(&gic_lock, flags);
 
-	write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
-	if (cd->mask)
-		write_gic_vl_smask(BIT(intr));
+	for (i = 0; i < ARRAY_SIZE(local_intrs); i++) {
+		unsigned int intr = local_intrs[i];
+		struct gic_all_vpes_chip_data *cd;
+
+		cd = &gic_all_vpes_chip_data[intr];
+		write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
+		if (cd->mask)
+			write_gic_vl_smask(BIT(intr));
+	}
+
+	spin_unlock_irqrestore(&gic_lock, flags);
 }
 
 static struct irq_chip gic_all_vpes_local_irq_controller = {
 	.name			= "MIPS GIC Local",
 	.irq_mask		= gic_mask_local_irq_all_vpes,
 	.irq_unmask		= gic_unmask_local_irq_all_vpes,
-	.irq_cpu_online		= gic_all_vpes_irq_cpu_online,
 };
 
 static void __gic_irq_dispatch(void)
@@ -477,6 +488,10 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
 	intr = GIC_HWIRQ_TO_LOCAL(hwirq);
 	map = GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin;
 
+	/*
+	 * If adding support for more per-cpu interrupts, keep the the
+	 * array in gic_all_vpes_irq_cpu_online() in sync.
+	 */
 	switch (intr) {
 	case GIC_LOCAL_INT_TIMER:
 		/* CONFIG_MIPS_CMP workaround (see __gic_init) */
@@ -663,8 +678,8 @@ static int gic_cpu_startup(unsigned int cpu)
 	/* Clear all local IRQ masks (ie. disable all local interrupts) */
 	write_gic_vl_rmask(~0);
 
-	/* Invoke irq_cpu_online callbacks to enable desired interrupts */
-	irq_cpu_online();
+	/* Enable desired interrupts */
+	gic_all_vpes_irq_cpu_online();
 
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/3] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option
  2021-10-21 17:04 [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Marc Zyngier
  2021-10-21 17:04 ` [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline() Marc Zyngier
  2021-10-21 17:04 ` [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online() Marc Zyngier
@ 2021-10-21 17:04 ` Marc Zyngier
  2021-10-26  2:41   ` Florian Fainelli
  2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
  2021-10-22 13:53 ` [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Serge Semin
  3 siblings, 2 replies; 14+ messages in thread
From: Marc Zyngier @ 2021-10-21 17:04 UTC (permalink / raw)
  To: linux-mips, linux-kernel
  Cc: Thomas Bogendoerfer, Serge Semin, Huacai Chen, Jiaxun Yang,
	f.fainelli, Thomas Gleixner

irq_cpu_{on,off}line() are now only used by the Octeon platform.
Make their use conditional on this plaform being enabled, and
otherwise hidden away.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 include/linux/irq.h | 5 ++++-
 kernel/irq/Kconfig  | 7 +++++++
 kernel/irq/chip.c   | 2 ++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index c8293c817646..0c746d325206 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -524,9 +524,10 @@ struct irq_chip {
 	void		(*irq_bus_lock)(struct irq_data *data);
 	void		(*irq_bus_sync_unlock)(struct irq_data *data);
 
+#ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
 	void		(*irq_cpu_online)(struct irq_data *data);
 	void		(*irq_cpu_offline)(struct irq_data *data);
-
+#endif
 	void		(*irq_suspend)(struct irq_data *data);
 	void		(*irq_resume)(struct irq_data *data);
 	void		(*irq_pm_shutdown)(struct irq_data *data);
@@ -606,8 +607,10 @@ struct irqaction;
 extern int setup_percpu_irq(unsigned int irq, struct irqaction *new);
 extern void remove_percpu_irq(unsigned int irq, struct irqaction *act);
 
+#ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
 extern void irq_cpu_online(void);
 extern void irq_cpu_offline(void);
+#endif
 extern int irq_set_affinity_locked(struct irq_data *data,
 				   const struct cpumask *cpumask, bool force);
 extern int irq_set_vcpu_affinity(unsigned int irq, void *vcpu_info);
diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
index fbc54c2a7f23..c0b9d4607147 100644
--- a/kernel/irq/Kconfig
+++ b/kernel/irq/Kconfig
@@ -144,3 +144,10 @@ config GENERIC_IRQ_MULTI_HANDLER
 	bool
 	help
 	  Allow to specify the low level IRQ handler at run time.
+
+# Cavium Octeon is the last system to use this deprecated option
+# Do not even think of enabling this on any new platform
+config DEPRECATED_IRQ_CPU_ONOFFLINE
+	bool
+	depends on CAVIUM_OCTEON_SOC
+	default CAVIUM_OCTEON_SOC
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index a98bcfc4be7b..f895265d7548 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -1122,6 +1122,7 @@ void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
 }
 EXPORT_SYMBOL_GPL(irq_modify_status);
 
+#ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
 /**
  *	irq_cpu_online - Invoke all irq_cpu_online functions.
  *
@@ -1181,6 +1182,7 @@ void irq_cpu_offline(void)
 		raw_spin_unlock_irqrestore(&desc->lock, flags);
 	}
 }
+#endif
 
 #ifdef	CONFIG_IRQ_DOMAIN_HIERARCHY
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special
  2021-10-21 17:04 [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Marc Zyngier
                   ` (2 preceding siblings ...)
  2021-10-21 17:04 ` [PATCH 3/3] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option Marc Zyngier
@ 2021-10-22 13:53 ` Serge Semin
  2021-10-22 13:59   ` Serge Semin
  3 siblings, 1 reply; 14+ messages in thread
From: Serge Semin @ 2021-10-22 13:53 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Serge Semin, linux-mips, linux-kernel, Thomas Bogendoerfer,
	Huacai Chen, Jiaxun Yang, f.fainelli, Thomas Gleixner

Hello Marc

On Thu, Oct 21, 2021 at 06:04:11PM +0100, Marc Zyngier wrote:
> Now that Florian has updated BMIPS to not rely on irq_cpu_offline [1],
> it is pretty tempting to totally get of this misfeature. We can't
> really do that because Octeon uses it like crazy, but the couple of
> other users are easy to convert.
> 
> Once this is done, these helpers are hidden behind a config symbol
> that depends on the Octeon platform being selected. When Octeon is
> finally removed from the tree, we'll be able to drop this as well.

The whole series has been tested in kernel 5.13 running on
Baikal-T1 SoC (2x P5600 cores) with MIPS GIC used as the clock source
and clock event device.
Acked-by: Serge Semin <fancer.lancer@gmail.com>

-Sergey

> 
> 
> Marc Zyngier (3):
>   MIPS: loongson64: Drop call to irq_cpu_offline()
>   irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()
>   genirq: Hide irq_cpu_{on,off}line() behind a deprecated option
> 
>  arch/mips/loongson64/smp.c     |  1 -
>  drivers/irqchip/irq-mips-gic.c | 37 ++++++++++++++++++++++++----------
>  include/linux/irq.h            |  5 ++++-
>  kernel/irq/Kconfig             |  7 +++++++
>  kernel/irq/chip.c              |  2 ++
>  5 files changed, 39 insertions(+), 13 deletions(-)
> 
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()
  2021-10-21 17:04 ` [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online() Marc Zyngier
@ 2021-10-22 13:57   ` Serge Semin
  2021-10-26  2:17   ` Florian Fainelli
  2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
  2 siblings, 0 replies; 14+ messages in thread
From: Serge Semin @ 2021-10-22 13:57 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Serge Semin, linux-mips, linux-kernel, Thomas Bogendoerfer,
	Huacai Chen, Jiaxun Yang, f.fainelli, Thomas Gleixner

On Thu, Oct 21, 2021 at 06:04:13PM +0100, Marc Zyngier wrote:
> The MIPS GIC driver uses irq_cpu_online() to go and program the
> per-CPU interrupts. However, this method iterates over all IRQs
> in the system, despite only 3 per-CPU interrupts being of interest.
> 
> Let's be terribly bold and do the iteration ourselves. To ensure
> mutual exclusion, hold the gic_lock spinlock that is otherwise
> taken while dealing with these interrupts.

Please consider a nitpick below. Other than that looks good:
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>

> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  drivers/irqchip/irq-mips-gic.c | 37 ++++++++++++++++++++++++----------
>  1 file changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
> index 54c7092cc61d..45c83dd804a0 100644
> --- a/drivers/irqchip/irq-mips-gic.c
> +++ b/drivers/irqchip/irq-mips-gic.c
> @@ -381,24 +381,35 @@ static void gic_unmask_local_irq_all_vpes(struct irq_data *d)
>  	spin_unlock_irqrestore(&gic_lock, flags);
>  }
>  
> -static void gic_all_vpes_irq_cpu_online(struct irq_data *d)
> +static void gic_all_vpes_irq_cpu_online(void)
>  {
> -	struct gic_all_vpes_chip_data *cd;
> -	unsigned int intr;

> +	static unsigned int local_intrs[] = {

What about adding 'const' here?

-Sergey

> +		GIC_LOCAL_INT_TIMER,
> +		GIC_LOCAL_INT_PERFCTR,
> +		GIC_LOCAL_INT_FDC,
> +	};
> +	unsigned long flags;
> +	int i;
>  
> -	intr = GIC_HWIRQ_TO_LOCAL(d->hwirq);
> -	cd = irq_data_get_irq_chip_data(d);
> +	spin_lock_irqsave(&gic_lock, flags);
>  
> -	write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
> -	if (cd->mask)
> -		write_gic_vl_smask(BIT(intr));
> +	for (i = 0; i < ARRAY_SIZE(local_intrs); i++) {
> +		unsigned int intr = local_intrs[i];
> +		struct gic_all_vpes_chip_data *cd;
> +
> +		cd = &gic_all_vpes_chip_data[intr];
> +		write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
> +		if (cd->mask)
> +			write_gic_vl_smask(BIT(intr));
> +	}
> +
> +	spin_unlock_irqrestore(&gic_lock, flags);
>  }
>  
>  static struct irq_chip gic_all_vpes_local_irq_controller = {
>  	.name			= "MIPS GIC Local",
>  	.irq_mask		= gic_mask_local_irq_all_vpes,
>  	.irq_unmask		= gic_unmask_local_irq_all_vpes,
> -	.irq_cpu_online		= gic_all_vpes_irq_cpu_online,
>  };
>  
>  static void __gic_irq_dispatch(void)
> @@ -477,6 +488,10 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
>  	intr = GIC_HWIRQ_TO_LOCAL(hwirq);
>  	map = GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin;
>  
> +	/*
> +	 * If adding support for more per-cpu interrupts, keep the the
> +	 * array in gic_all_vpes_irq_cpu_online() in sync.
> +	 */
>  	switch (intr) {
>  	case GIC_LOCAL_INT_TIMER:
>  		/* CONFIG_MIPS_CMP workaround (see __gic_init) */
> @@ -663,8 +678,8 @@ static int gic_cpu_startup(unsigned int cpu)
>  	/* Clear all local IRQ masks (ie. disable all local interrupts) */
>  	write_gic_vl_rmask(~0);
>  
> -	/* Invoke irq_cpu_online callbacks to enable desired interrupts */
> -	irq_cpu_online();
> +	/* Enable desired interrupts */
> +	gic_all_vpes_irq_cpu_online();
>  
>  	return 0;
>  }
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special
  2021-10-22 13:53 ` [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Serge Semin
@ 2021-10-22 13:59   ` Serge Semin
  0 siblings, 0 replies; 14+ messages in thread
From: Serge Semin @ 2021-10-22 13:59 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Serge Semin, linux-mips, linux-kernel, Thomas Bogendoerfer,
	Huacai Chen, Jiaxun Yang, f.fainelli, Thomas Gleixner

On Fri, Oct 22, 2021 at 04:53:56PM +0300, Serge Semin wrote:
> Hello Marc
> 
> On Thu, Oct 21, 2021 at 06:04:11PM +0100, Marc Zyngier wrote:
> > Now that Florian has updated BMIPS to not rely on irq_cpu_offline [1],
> > it is pretty tempting to totally get of this misfeature. We can't
> > really do that because Octeon uses it like crazy, but the couple of
> > other users are easy to convert.
> > 
> > Once this is done, these helpers are hidden behind a config symbol
> > that depends on the Octeon platform being selected. When Octeon is
> > finally removed from the tree, we'll be able to drop this as well.
> 
> The whole series has been tested in kernel 5.13 running on
> Baikal-T1 SoC (2x P5600 cores) with MIPS GIC used as the clock source
> and clock event device.

> Acked-by: Serge Semin <fancer.lancer@gmail.com>

Ah, sorry. copy-pasted a wrong tag. Tested-by of course:
Tested-by: Serge Semin <fancer.lancer@gmail.com>

-Sergey

> 
> -Sergey
> 
> > 
> > 
> > Marc Zyngier (3):
> >   MIPS: loongson64: Drop call to irq_cpu_offline()
> >   irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()
> >   genirq: Hide irq_cpu_{on,off}line() behind a deprecated option
> > 
> >  arch/mips/loongson64/smp.c     |  1 -
> >  drivers/irqchip/irq-mips-gic.c | 37 ++++++++++++++++++++++++----------
> >  include/linux/irq.h            |  5 ++++-
> >  kernel/irq/Kconfig             |  7 +++++++
> >  kernel/irq/chip.c              |  2 ++
> >  5 files changed, 39 insertions(+), 13 deletions(-)
> > 
> > -- 
> > 2.30.2
> > 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline()
  2021-10-21 17:04 ` [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline() Marc Zyngier
@ 2021-10-24 15:28   ` Thomas Bogendoerfer
  2021-10-26  2:16   ` Florian Fainelli
  2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
  2 siblings, 0 replies; 14+ messages in thread
From: Thomas Bogendoerfer @ 2021-10-24 15:28 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-mips, linux-kernel, Serge Semin, Huacai Chen, Jiaxun Yang,
	f.fainelli, Thomas Gleixner

On Thu, Oct 21, 2021 at 06:04:12PM +0100, Marc Zyngier wrote:
> Also loongson64 calls irq_cpu_offline(), none of its interrupt
> controllers implement the .irq_cpu_offline callback.
> 
> It is thus obvious that this call only serves the dubious purpose
> of wasting precious CPU cycles by iterating over all interrupts.
> 
> Get rid of the call altogether.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  arch/mips/loongson64/smp.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
> index 09ebe84a17fe..660e1de4412a 100644
> --- a/arch/mips/loongson64/smp.c
> +++ b/arch/mips/loongson64/smp.c
> @@ -550,7 +550,6 @@ static int loongson3_cpu_disable(void)
>  	set_cpu_online(cpu, false);
>  	calculate_cpu_foreign_map();
>  	local_irq_save(flags);
> -	irq_cpu_offline();
>  	clear_c0_status(ST0_IM);
>  	local_irq_restore(flags);
>  	local_flush_tlb_all();
> -- 
> 2.30.2

Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline()
  2021-10-21 17:04 ` [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline() Marc Zyngier
  2021-10-24 15:28   ` Thomas Bogendoerfer
@ 2021-10-26  2:16   ` Florian Fainelli
  2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
  2 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2021-10-26  2:16 UTC (permalink / raw)
  To: Marc Zyngier, linux-mips, linux-kernel
  Cc: Thomas Bogendoerfer, Serge Semin, Huacai Chen, Jiaxun Yang,
	Thomas Gleixner



On 10/21/2021 10:04 AM, Marc Zyngier wrote:
> Also loongson64 calls irq_cpu_offline(), none of its interrupt
> controllers implement the .irq_cpu_offline callback.
> 
> It is thus obvious that this call only serves the dubious purpose
> of wasting precious CPU cycles by iterating over all interrupts.
> 
> Get rid of the call altogether.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
--
Florian

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()
  2021-10-21 17:04 ` [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online() Marc Zyngier
  2021-10-22 13:57   ` Serge Semin
@ 2021-10-26  2:17   ` Florian Fainelli
  2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
  2 siblings, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2021-10-26  2:17 UTC (permalink / raw)
  To: Marc Zyngier, linux-mips, linux-kernel
  Cc: Thomas Bogendoerfer, Serge Semin, Huacai Chen, Jiaxun Yang,
	Thomas Gleixner



On 10/21/2021 10:04 AM, Marc Zyngier wrote:
> The MIPS GIC driver uses irq_cpu_online() to go and program the
> per-CPU interrupts. However, this method iterates over all IRQs
> in the system, despite only 3 per-CPU interrupts being of interest.
> 
> Let's be terribly bold and do the iteration ourselves. To ensure
> mutual exclusion, hold the gic_lock spinlock that is otherwise
> taken while dealing with these interrupts.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/3] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option
  2021-10-21 17:04 ` [PATCH 3/3] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option Marc Zyngier
@ 2021-10-26  2:41   ` Florian Fainelli
  2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
  1 sibling, 0 replies; 14+ messages in thread
From: Florian Fainelli @ 2021-10-26  2:41 UTC (permalink / raw)
  To: Marc Zyngier, linux-mips, linux-kernel
  Cc: Thomas Bogendoerfer, Serge Semin, Huacai Chen, Jiaxun Yang,
	Thomas Gleixner



On 10/21/2021 10:04 AM, Marc Zyngier wrote:
> irq_cpu_{on,off}line() are now only used by the Octeon platform.
> Make their use conditional on this plaform being enabled, and
> otherwise hidden away.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [irqchip: irq/irqchip-next] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option
  2021-10-21 17:04 ` [PATCH 3/3] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option Marc Zyngier
  2021-10-26  2:41   ` Florian Fainelli
@ 2021-10-26 10:35   ` irqchip-bot for Marc Zyngier
  1 sibling, 0 replies; 14+ messages in thread
From: irqchip-bot for Marc Zyngier @ 2021-10-26 10:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: Marc Zyngier, Florian Fainelli, Serge Semin, tglx

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     8d15a7295d33538954df2bca6a4011e4311a9cc2
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/8d15a7295d33538954df2bca6a4011e4311a9cc2
Author:        Marc Zyngier <maz@kernel.org>
AuthorDate:    Thu, 21 Oct 2021 18:04:14 +01:00
Committer:     Marc Zyngier <maz@kernel.org>
CommitterDate: Tue, 26 Oct 2021 11:19:55 +01:00

genirq: Hide irq_cpu_{on,off}line() behind a deprecated option

irq_cpu_{on,off}line() are now only used by the Octeon platform.
Make their use conditional on this plaform being enabled, and
otherwise hidden away.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20211021170414.3341522-4-maz@kernel.org
---
 include/linux/irq.h | 5 ++++-
 kernel/irq/Kconfig  | 7 +++++++
 kernel/irq/chip.c   | 2 ++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index c8293c8..0c746d3 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -524,9 +524,10 @@ struct irq_chip {
 	void		(*irq_bus_lock)(struct irq_data *data);
 	void		(*irq_bus_sync_unlock)(struct irq_data *data);
 
+#ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
 	void		(*irq_cpu_online)(struct irq_data *data);
 	void		(*irq_cpu_offline)(struct irq_data *data);
-
+#endif
 	void		(*irq_suspend)(struct irq_data *data);
 	void		(*irq_resume)(struct irq_data *data);
 	void		(*irq_pm_shutdown)(struct irq_data *data);
@@ -606,8 +607,10 @@ struct irqaction;
 extern int setup_percpu_irq(unsigned int irq, struct irqaction *new);
 extern void remove_percpu_irq(unsigned int irq, struct irqaction *act);
 
+#ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
 extern void irq_cpu_online(void);
 extern void irq_cpu_offline(void);
+#endif
 extern int irq_set_affinity_locked(struct irq_data *data,
 				   const struct cpumask *cpumask, bool force);
 extern int irq_set_vcpu_affinity(unsigned int irq, void *vcpu_info);
diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
index fbc54c2..c0b9d46 100644
--- a/kernel/irq/Kconfig
+++ b/kernel/irq/Kconfig
@@ -144,3 +144,10 @@ config GENERIC_IRQ_MULTI_HANDLER
 	bool
 	help
 	  Allow to specify the low level IRQ handler at run time.
+
+# Cavium Octeon is the last system to use this deprecated option
+# Do not even think of enabling this on any new platform
+config DEPRECATED_IRQ_CPU_ONOFFLINE
+	bool
+	depends on CAVIUM_OCTEON_SOC
+	default CAVIUM_OCTEON_SOC
diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index a98bcfc..f895265 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -1122,6 +1122,7 @@ void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
 }
 EXPORT_SYMBOL_GPL(irq_modify_status);
 
+#ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
 /**
  *	irq_cpu_online - Invoke all irq_cpu_online functions.
  *
@@ -1181,6 +1182,7 @@ void irq_cpu_offline(void)
 		raw_spin_unlock_irqrestore(&desc->lock, flags);
 	}
 }
+#endif
 
 #ifdef	CONFIG_IRQ_DOMAIN_HIERARCHY
 

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [irqchip: irq/irqchip-next] MIPS: loongson64: Drop call to irq_cpu_offline()
  2021-10-21 17:04 ` [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline() Marc Zyngier
  2021-10-24 15:28   ` Thomas Bogendoerfer
  2021-10-26  2:16   ` Florian Fainelli
@ 2021-10-26 10:35   ` irqchip-bot for Marc Zyngier
  2 siblings, 0 replies; 14+ messages in thread
From: irqchip-bot for Marc Zyngier @ 2021-10-26 10:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Marc Zyngier, Thomas Bogendoerfer, Florian Fainelli, Serge Semin, tglx

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     eb5411334c289c473bc11d5cef8b0bea8d7ce324
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/eb5411334c289c473bc11d5cef8b0bea8d7ce324
Author:        Marc Zyngier <maz@kernel.org>
AuthorDate:    Thu, 21 Oct 2021 18:04:12 +01:00
Committer:     Marc Zyngier <maz@kernel.org>
CommitterDate: Tue, 26 Oct 2021 11:18:33 +01:00

MIPS: loongson64: Drop call to irq_cpu_offline()

Also loongson64 calls irq_cpu_offline(), none of its interrupt
controllers implement the .irq_cpu_offline callback.

It is thus obvious that this call only serves the dubious purpose
of wasting precious CPU cycles by iterating over all interrupts.

Get rid of the call altogether.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20211021170414.3341522-2-maz@kernel.org
---
 arch/mips/loongson64/smp.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index 09ebe84..660e1de 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -550,7 +550,6 @@ static int loongson3_cpu_disable(void)
 	set_cpu_online(cpu, false);
 	calculate_cpu_foreign_map();
 	local_irq_save(flags);
-	irq_cpu_offline();
 	clear_c0_status(ST0_IM);
 	local_irq_restore(flags);
 	local_flush_tlb_all();

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [irqchip: irq/irqchip-next] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()
  2021-10-21 17:04 ` [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online() Marc Zyngier
  2021-10-22 13:57   ` Serge Semin
  2021-10-26  2:17   ` Florian Fainelli
@ 2021-10-26 10:35   ` irqchip-bot for Marc Zyngier
  2 siblings, 0 replies; 14+ messages in thread
From: irqchip-bot for Marc Zyngier @ 2021-10-26 10:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: Marc Zyngier, Serge Semin, Florian Fainelli, tglx

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     dd098a0e031928cf88c89f7577d31821e1f0e6de
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/dd098a0e031928cf88c89f7577d31821e1f0e6de
Author:        Marc Zyngier <maz@kernel.org>
AuthorDate:    Thu, 21 Oct 2021 18:04:13 +01:00
Committer:     Marc Zyngier <maz@kernel.org>
CommitterDate: Tue, 26 Oct 2021 11:19:38 +01:00

irqchip/mips-gic: Get rid of the reliance on irq_cpu_online()

The MIPS GIC driver uses irq_cpu_online() to go and program the
per-CPU interrupts. However, this method iterates over all IRQs
in the system, despite only 3 per-CPU interrupts being of interest.

Let's be terribly bold and do the iteration ourselves. To ensure
mutual exclusion, hold the gic_lock spinlock that is otherwise
taken while dealing with these interrupts.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Serge Semin <fancer.lancer@gmail.com>
Link: https://lore.kernel.org/r/20211021170414.3341522-3-maz@kernel.org
---
 drivers/irqchip/irq-mips-gic.c | 37 +++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index 54c7092..d02b05a 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -381,24 +381,35 @@ static void gic_unmask_local_irq_all_vpes(struct irq_data *d)
 	spin_unlock_irqrestore(&gic_lock, flags);
 }
 
-static void gic_all_vpes_irq_cpu_online(struct irq_data *d)
+static void gic_all_vpes_irq_cpu_online(void)
 {
-	struct gic_all_vpes_chip_data *cd;
-	unsigned int intr;
+	static const unsigned int local_intrs[] = {
+		GIC_LOCAL_INT_TIMER,
+		GIC_LOCAL_INT_PERFCTR,
+		GIC_LOCAL_INT_FDC,
+	};
+	unsigned long flags;
+	int i;
 
-	intr = GIC_HWIRQ_TO_LOCAL(d->hwirq);
-	cd = irq_data_get_irq_chip_data(d);
+	spin_lock_irqsave(&gic_lock, flags);
 
-	write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
-	if (cd->mask)
-		write_gic_vl_smask(BIT(intr));
+	for (i = 0; i < ARRAY_SIZE(local_intrs); i++) {
+		unsigned int intr = local_intrs[i];
+		struct gic_all_vpes_chip_data *cd;
+
+		cd = &gic_all_vpes_chip_data[intr];
+		write_gic_vl_map(mips_gic_vx_map_reg(intr), cd->map);
+		if (cd->mask)
+			write_gic_vl_smask(BIT(intr));
+	}
+
+	spin_unlock_irqrestore(&gic_lock, flags);
 }
 
 static struct irq_chip gic_all_vpes_local_irq_controller = {
 	.name			= "MIPS GIC Local",
 	.irq_mask		= gic_mask_local_irq_all_vpes,
 	.irq_unmask		= gic_unmask_local_irq_all_vpes,
-	.irq_cpu_online		= gic_all_vpes_irq_cpu_online,
 };
 
 static void __gic_irq_dispatch(void)
@@ -477,6 +488,10 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
 	intr = GIC_HWIRQ_TO_LOCAL(hwirq);
 	map = GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin;
 
+	/*
+	 * If adding support for more per-cpu interrupts, keep the the
+	 * array in gic_all_vpes_irq_cpu_online() in sync.
+	 */
 	switch (intr) {
 	case GIC_LOCAL_INT_TIMER:
 		/* CONFIG_MIPS_CMP workaround (see __gic_init) */
@@ -663,8 +678,8 @@ static int gic_cpu_startup(unsigned int cpu)
 	/* Clear all local IRQ masks (ie. disable all local interrupts) */
 	write_gic_vl_rmask(~0);
 
-	/* Invoke irq_cpu_online callbacks to enable desired interrupts */
-	irq_cpu_online();
+	/* Enable desired interrupts */
+	gic_all_vpes_irq_cpu_online();
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-10-26 10:36 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 17:04 [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Marc Zyngier
2021-10-21 17:04 ` [PATCH 1/3] MIPS: loongson64: Drop call to irq_cpu_offline() Marc Zyngier
2021-10-24 15:28   ` Thomas Bogendoerfer
2021-10-26  2:16   ` Florian Fainelli
2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
2021-10-21 17:04 ` [PATCH 2/3] irqchip/mips-gic: Get rid of the reliance on irq_cpu_online() Marc Zyngier
2021-10-22 13:57   ` Serge Semin
2021-10-26  2:17   ` Florian Fainelli
2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
2021-10-21 17:04 ` [PATCH 3/3] genirq: Hide irq_cpu_{on,off}line() behind a deprecated option Marc Zyngier
2021-10-26  2:41   ` Florian Fainelli
2021-10-26 10:35   ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
2021-10-22 13:53 ` [PATCH 0/3] genirq: Make irq_cpu_{on,off}line() an Octeon-special Serge Semin
2021-10-22 13:59   ` Serge Semin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).