Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: Paul Burton <paul.burton@imgtec.com>,
	linux-mips@linux-mips.org, Jason Cooper <jason@lakedaemon.net>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Ralf Baechle <ralf@linux-mips.org>
Subject: Re: [PATCH 35/38] irqchip: mips-gic: Use pcpu_masks to avoid reading GIC_SH_MASK*
Date: Fri, 18 Aug 2017 16:44:15 +0100	[thread overview]
Message-ID: <405f8fc2-2947-cc68-e40a-b7e26a03e713@arm.com> (raw)
In-Reply-To: <20170813043646.25821-36-paul.burton@imgtec.com>

On 13/08/17 05:36, Paul Burton wrote:
> This patch avoids the need to read the GIC_SH_MASK* registers when
> decoding shared interrupts by setting & clearing the interrupt's bit in
> the appropriate CPU's pcpu_masks entry when masking or unmasking the
> interrupt.
> 
> This effectively means that whilst an interrupt is masked we clear its
> bit in all pcpu_masks, which causes gic_handle_shared_int() to ignore it
> on all CPUs without needing to check GIC_SH_MASK*.
> 
> In essence, we add a little overhead to masking or unmasking interrupts
> but in return reduce the overhead of the far more common task of
> decoding interrupts.
> 
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> Cc: Jason Cooper <jason@lakedaemon.net>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: linux-mips@linux-mips.org
> ---
> 
>  drivers/irqchip/irq-mips-gic.c | 49 ++++++++++++++++++++++++------------------
>  1 file changed, 28 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
> index 00153231376a..7a42f0b3822f 100644
> --- a/drivers/irqchip/irq-mips-gic.c
> +++ b/drivers/irqchip/irq-mips-gic.c
> @@ -55,6 +55,19 @@ static struct irq_chip gic_level_irq_controller, gic_edge_irq_controller;
>  DECLARE_BITMAP(ipi_resrv, GIC_MAX_INTRS);
>  DECLARE_BITMAP(ipi_available, GIC_MAX_INTRS);
>  
> +static void gic_setup_pcpu_mask(unsigned int intr, unsigned int cpu)
> +{
> +	unsigned int i;
> +
> +	/* Clear the interrupt's bit in all pcpu_masks */
> +	for_each_possible_cpu(i)
> +		clear_bit(intr, per_cpu_ptr(pcpu_masks, i));

This iterates from 0 to nr_cpu_ids-1...

> +
> +	/* Set the interrupt's bit in the appropriate CPU's mask */
> +	if (cpu < NR_CPUS)

and here you're using NR_CPUS. I'm a bit worried that you're not quite
using the same thing (nr_cpu_ids <= NR_CPUS).

> +		set_bit(intr, per_cpu_ptr(pcpu_masks, cpu));
> +}
> +
>  static bool gic_local_irq_is_routable(int intr)
>  {
>  	u32 vpe_ctl;
> @@ -133,24 +146,17 @@ static void gic_handle_shared_int(bool chained)
>  	unsigned int intr, virq;
>  	unsigned long *pcpu_mask;
>  	DECLARE_BITMAP(pending, GIC_MAX_INTRS);
> -	DECLARE_BITMAP(intrmask, GIC_MAX_INTRS);
>  
>  	/* Get per-cpu bitmaps */
>  	pcpu_mask = this_cpu_ptr(pcpu_masks);
>  
> -	if (mips_cm_is64) {
> +	if (mips_cm_is64)
>  		__ioread64_copy(pending, addr_gic_pend(),
>  				DIV_ROUND_UP(gic_shared_intrs, 64));
> -		__ioread64_copy(intrmask, addr_gic_mask(),
> -				DIV_ROUND_UP(gic_shared_intrs, 64));
> -	} else {
> +	else
>  		__ioread32_copy(pending, addr_gic_pend(),
>  				DIV_ROUND_UP(gic_shared_intrs, 32));
> -		__ioread32_copy(intrmask, addr_gic_mask(),
> -				DIV_ROUND_UP(gic_shared_intrs, 32));
> -	}
>  
> -	bitmap_and(pending, pending, intrmask, gic_shared_intrs);
>  	bitmap_and(pending, pending, pcpu_mask, gic_shared_intrs);
>  
>  	for_each_set_bit(intr, pending, gic_shared_intrs) {
> @@ -165,12 +171,19 @@ static void gic_handle_shared_int(bool chained)
>  
>  static void gic_mask_irq(struct irq_data *d)
>  {
> -	write_gic_rmask(BIT(GIC_HWIRQ_TO_SHARED(d->hwirq)));
> +	unsigned int intr = GIC_HWIRQ_TO_SHARED(d->hwirq);
> +
> +	write_gic_rmask(BIT(intr));
> +	gic_setup_pcpu_mask(intr, NR_CPUS);
>  }
>  
>  static void gic_unmask_irq(struct irq_data *d)
>  {
> -	write_gic_smask(BIT(GIC_HWIRQ_TO_SHARED(d->hwirq)));
> +	struct cpumask *affinity = irq_data_get_affinity_mask(d);
> +	unsigned int intr = GIC_HWIRQ_TO_SHARED(d->hwirq);
> +
> +	write_gic_smask(BIT(intr));
> +	gic_setup_pcpu_mask(intr, cpumask_first_and(affinity, cpu_online_mask));
>  }
>  
>  static void gic_ack_irq(struct irq_data *d)
> @@ -239,7 +252,6 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
>  	unsigned int irq = GIC_HWIRQ_TO_SHARED(d->hwirq);
>  	cpumask_t	tmp = CPU_MASK_NONE;
>  	unsigned long	flags;
> -	int		i;
>  
>  	cpumask_and(&tmp, cpumask, cpu_online_mask);
>  	if (cpumask_empty(&tmp))
> @@ -252,9 +264,7 @@ static int gic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
>  	write_gic_map_vp(irq, BIT(mips_cm_vp_id(cpumask_first(&tmp))));
>  
>  	/* Update the pcpu_masks */
> -	for (i = 0; i < min(gic_vpes, NR_CPUS); i++)
> -		clear_bit(irq, per_cpu_ptr(pcpu_masks, i));
> -	set_bit(irq, per_cpu_ptr(pcpu_masks, cpumask_first(&tmp)));
> +	gic_setup_pcpu_mask(irq, read_gic_mask(irq) ? cpumask_first(&tmp) : NR_CPUS);
>  
>  	cpumask_copy(irq_data_get_affinity_mask(d), cpumask);
>  	spin_unlock_irqrestore(&gic_lock, flags);
> @@ -405,18 +415,15 @@ static int gic_local_irq_domain_map(struct irq_domain *d, unsigned int virq,
>  }
>  
>  static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,
> -				     irq_hw_number_t hw, unsigned int vpe)
> +				     irq_hw_number_t hw, unsigned int cpu)
>  {
>  	int intr = GIC_HWIRQ_TO_SHARED(hw);
>  	unsigned long flags;
> -	int i;
>  
>  	spin_lock_irqsave(&gic_lock, flags);
>  	write_gic_map_pin(intr, GIC_MAP_PIN_MAP_TO_PIN | gic_cpu_pin);
> -	write_gic_map_vp(intr, BIT(mips_cm_vp_id(vpe)));
> -	for (i = 0; i < min(gic_vpes, NR_CPUS); i++)
> -		clear_bit(intr, per_cpu_ptr(pcpu_masks, i));
> -	set_bit(intr, per_cpu_ptr(pcpu_masks, vpe));
> +	write_gic_map_vp(intr, BIT(mips_cm_vp_id(cpu)));
> +	gic_setup_pcpu_mask(intr, cpu);
>  	spin_unlock_irqrestore(&gic_lock, flags);
>  
>  	return 0;
> 

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

  parent reply	other threads:[~2017-08-18 15:44 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-13  4:36 [PATCH 00/38] irqchip: mips-gic: Cleanup & optimisation Paul Burton
2017-08-13  4:36 ` Paul Burton
2017-08-13  4:36 ` [PATCH 01/38] irqchip: mips-gic: SYNC after enabling GIC region Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 02/38] MIPS: GIC: Introduce asm/mips-gic.h with accessor functions Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-18 11:10   ` Marc Zyngier
2017-08-18 16:43     ` Paul Burton
2017-08-18 16:43       ` Paul Burton
2017-08-13  4:36 ` [PATCH 03/38] clocksource: mips-gic-timer: Use new GIC " Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 04/38] irqchip: mips-gic: Remove counter access functions Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 05/38] MIPS: CPS: Read GIC_VL_IDENT directly, not via irqchip driver Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 06/38] irqchip: mips-gic: Remove gic_read_local_vp_id() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 07/38] lib/iomap_copy.c: Add __ioread64_copy Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 08/38] irqchip: mips-gic: Simplify shared interrupt pending/mask reads Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 09/38] irqchip: mips-gic: Simplify gic_local_irq_domain_map() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 10/38] irqchip: mips-gic: Drop gic_(re)set_mask() functions Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 11/38] irqchip: mips-gic: Remove gic_set_polarity() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 12/38] irqchip: mips-gic: Remove gic_set_trigger() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 13/38] irqchip: mips-gic: Remove gic_set_dual_edge() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 14/38] irqchip: mips-gic: Remove gic_map_to_pin() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 15/38] irqchip: mips-gic: Remove gic_map_to_vpe() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 16/38] irqchip: mips-gic: Convert remaining shared reg access to new accessors Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 17/38] irqchip: mips-gic: Convert local int mask " Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 18/38] irqchip: mips-gic: Convert remaining local reg " Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 19/38] MIPS: GIC: Move GIC_LOCAL_INT_* to asm/mips-gic.h Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 20/38] irqchip: mips-gic: Remove GIC_CPU_INT* macros Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 21/38] irqchip: mips-gic: Move various definitions to the driver Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 22/38] MIPS: VDSO: Drop gic_get_usm_range() usage Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-18 11:38   ` Marc Zyngier
2017-08-18 16:47     ` Paul Burton
2017-08-18 16:47       ` Paul Burton
2017-08-18 16:52       ` Marc Zyngier
2017-08-13  4:36 ` [PATCH 23/38] irqchip: mips-gic: Remove gic_get_usm_range() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 24/38] irqchip: mips-gic: Remove __gic_irq_dispatch() forward declaration Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 25/38] irqchip: mips-gic: Remove gic_init() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 26/38] MIPS: Use mips_gic_present() in place of gic_present Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 27/38] irqchip: mips-gic: Remove gic_present Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 28/38] irqchip: mips-gic: Move gic_get_c0_*_int() to asm/mips-gic.h Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 29/38] MIPS: VDSO: Avoid use of linux/irqchip/mips-gic.h Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 30/38] MIPS: Remove unnecessary inclusions " Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 31/38] irqchip: mips-gic: Remove linux/irqchip/mips-gic.h Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 32/38] irqchip: mips-gic: Inline __gic_init() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 33/38] irqchip: mips-gic: Inline gic_basic_init() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 34/38] irqchip: mips-gic: Make pcpu_masks a per-cpu variable Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-18 15:37   ` Marc Zyngier
2017-08-18 17:02     ` Paul Burton
2017-08-18 17:02       ` Paul Burton
2017-08-18 17:18       ` Marc Zyngier
2017-08-13  4:36 ` [PATCH 35/38] irqchip: mips-gic: Use pcpu_masks to avoid reading GIC_SH_MASK* Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-18 15:44   ` Marc Zyngier [this message]
2017-08-18 17:11     ` Paul Burton
2017-08-18 17:11       ` Paul Burton
2017-08-18 17:25       ` Marc Zyngier
2017-08-18 21:02         ` [PATCH v2 " Paul Burton
2017-08-18 21:02           ` Paul Burton
2017-08-13  4:36 ` [PATCH 36/38] irqchip: mips-gic: Clean up mti,reserved-cpu-vectors handling Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  4:36 ` [PATCH 37/38] irqchip: mips-gic: Use cpumask_first_and() in gic_set_affinity() Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-13  9:08   ` Sergei Shtylyov
2017-08-14 16:18     ` Paul Burton
2017-08-14 16:18       ` Paul Burton
2017-08-14 16:48       ` Sergei Shtylyov
2017-08-18 21:04   ` [PATCH v2 " Paul Burton
2017-08-18 21:04     ` Paul Burton
2017-08-13  4:36 ` [PATCH 38/38] irqchip: mips-gic: Let the core set struct irq_common_data affinity Paul Burton
2017-08-13  4:36   ` Paul Burton
2017-08-15 10:13 ` [PATCH 00/38] irqchip: mips-gic: Cleanup & optimisation Marc Zyngier
2017-08-15 16:16   ` Paul Burton
2017-08-15 16:16     ` Paul Burton
2017-08-15 16:49     ` Marc Zyngier
2017-08-18 17:28 ` Marc Zyngier
2017-08-18 17:44   ` Paul Burton
2017-08-18 17:44     ` Paul Burton
2017-08-18 17:49     ` Marc Zyngier
2017-08-18 21:09       ` Paul Burton
2017-08-18 21:09         ` Paul Burton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=405f8fc2-2947-cc68-e40a-b7e26a03e713@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=jason@lakedaemon.net \
    --cc=linux-mips@linux-mips.org \
    --cc=paul.burton@imgtec.com \
    --cc=ralf@linux-mips.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox