Re: [PATCH 2/3] irqchip/irq-sifive-plic: Fixup couldn't broadcast to multi CPUs

2020-10-23 Thread Guo Ren
On Fri, Oct 23, 2020 at 8:17 PM Anup Patel  wrote:
>
> On Fri, Oct 23, 2020 at 3:48 PM  wrote:
> >
> > From: Guo Ren 
> >
> > If "echo 3 > /proc/irq/1/smp_affinity", we want irq 1 could be
> > broadcast to CPU0 & CPU1 and one of them would pick up the irq
> > handler.
> >
> > But current implementation couldn't let multi CPUs process the
> > same IRQ concurrent.
> >
> > Signed-off-by: Guo Ren 
> > ---
> >  drivers/irqchip/irq-sifive-plic.c | 23 ++-
> >  1 file changed, 6 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/irqchip/irq-sifive-plic.c 
> > b/drivers/irqchip/irq-sifive-plic.c
> > index 2e56576..0003322 100644
> > --- a/drivers/irqchip/irq-sifive-plic.c
> > +++ b/drivers/irqchip/irq-sifive-plic.c
> > @@ -114,15 +114,12 @@ static inline void plic_irq_toggle(const struct 
> > cpumask *mask,
> >  static void plic_irq_unmask(struct irq_data *d)
> >  {
> > struct cpumask amask;
> > -   unsigned int cpu;
> > struct plic_priv *priv = irq_get_chip_data(d->irq);
> >
> > cpumask_and(, >lmask, cpu_online_mask);
> > -   cpu = cpumask_any_and(irq_data_get_affinity_mask(d),
> > -  );
> > -   if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
> > -   return;
> > -   plic_irq_toggle(cpumask_of(cpu), d, 1);
> > +   cpumask_and(, , irq_data_get_affinity_mask(d));
> > +
> > +   plic_irq_toggle(, d, 1);
> >  }
> >
> >  static void plic_irq_mask(struct irq_data *d)
> > @@ -136,24 +133,16 @@ static void plic_irq_mask(struct irq_data *d)
> >  static int plic_set_affinity(struct irq_data *d,
> >  const struct cpumask *mask_val, bool force)
> >  {
> > -   unsigned int cpu;
> > struct cpumask amask;
> > struct plic_priv *priv = irq_get_chip_data(d->irq);
> >
> > cpumask_and(, >lmask, mask_val);
> > +   cpumask_and(, , cpu_online_mask);
> >
> > -   if (force)
> > -   cpu = cpumask_first();
> > -   else
> > -   cpu = cpumask_any_and(, cpu_online_mask);
> > -
> > -   if (cpu >= nr_cpu_ids)
> > -   return -EINVAL;
> > +   irq_data_update_effective_affinity(d, );
> >
> > plic_irq_toggle(>lmask, d, 0);
> > -   plic_irq_toggle(cpumask_of(cpu), d, 1);
> > -
> > -   irq_data_update_effective_affinity(d, cpumask_of(cpu));
> > +   plic_irq_toggle(, d, 1);
> >
> > return IRQ_SET_MASK_OK_DONE;
> >  }
> > --
> > 2.7.4
> >
>
> In the past, a similar patch was proposed by Zong Li (SiFive). We
> have good reasons to not allow multiple CPUs handle the same IRQ.
>
> Refer, https://lkml.org/lkml/2020/4/26/201
>
> NACK from my side.
Thx for sharing the information, I agree with Zong Li & Greentime's
aspect: Don't limit the usage of PLIC! We could let (one hart -> one
irq) as default.

I also agree that using irq broadcast indiscriminately can cause
performance problems. (Anup and Mark Z's view)

I think you've discussed enough at that time and l won't persist the patch.

-- 
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/


Re: [PATCH 2/3] irqchip/irq-sifive-plic: Fixup couldn't broadcast to multi CPUs

2020-10-23 Thread Anup Patel
On Fri, Oct 23, 2020 at 3:48 PM  wrote:
>
> From: Guo Ren 
>
> If "echo 3 > /proc/irq/1/smp_affinity", we want irq 1 could be
> broadcast to CPU0 & CPU1 and one of them would pick up the irq
> handler.
>
> But current implementation couldn't let multi CPUs process the
> same IRQ concurrent.
>
> Signed-off-by: Guo Ren 
> ---
>  drivers/irqchip/irq-sifive-plic.c | 23 ++-
>  1 file changed, 6 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/irqchip/irq-sifive-plic.c 
> b/drivers/irqchip/irq-sifive-plic.c
> index 2e56576..0003322 100644
> --- a/drivers/irqchip/irq-sifive-plic.c
> +++ b/drivers/irqchip/irq-sifive-plic.c
> @@ -114,15 +114,12 @@ static inline void plic_irq_toggle(const struct cpumask 
> *mask,
>  static void plic_irq_unmask(struct irq_data *d)
>  {
> struct cpumask amask;
> -   unsigned int cpu;
> struct plic_priv *priv = irq_get_chip_data(d->irq);
>
> cpumask_and(, >lmask, cpu_online_mask);
> -   cpu = cpumask_any_and(irq_data_get_affinity_mask(d),
> -  );
> -   if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
> -   return;
> -   plic_irq_toggle(cpumask_of(cpu), d, 1);
> +   cpumask_and(, , irq_data_get_affinity_mask(d));
> +
> +   plic_irq_toggle(, d, 1);
>  }
>
>  static void plic_irq_mask(struct irq_data *d)
> @@ -136,24 +133,16 @@ static void plic_irq_mask(struct irq_data *d)
>  static int plic_set_affinity(struct irq_data *d,
>  const struct cpumask *mask_val, bool force)
>  {
> -   unsigned int cpu;
> struct cpumask amask;
> struct plic_priv *priv = irq_get_chip_data(d->irq);
>
> cpumask_and(, >lmask, mask_val);
> +   cpumask_and(, , cpu_online_mask);
>
> -   if (force)
> -   cpu = cpumask_first();
> -   else
> -   cpu = cpumask_any_and(, cpu_online_mask);
> -
> -   if (cpu >= nr_cpu_ids)
> -   return -EINVAL;
> +   irq_data_update_effective_affinity(d, );
>
> plic_irq_toggle(>lmask, d, 0);
> -   plic_irq_toggle(cpumask_of(cpu), d, 1);
> -
> -   irq_data_update_effective_affinity(d, cpumask_of(cpu));
> +   plic_irq_toggle(, d, 1);
>
> return IRQ_SET_MASK_OK_DONE;
>  }
> --
> 2.7.4
>

In the past, a similar patch was proposed by Zong Li (SiFive). We
have good reasons to not allow multiple CPUs handle the same IRQ.

Refer, https://lkml.org/lkml/2020/4/26/201

NACK from my side.

Regards,
Anup


[PATCH 2/3] irqchip/irq-sifive-plic: Fixup couldn't broadcast to multi CPUs

2020-10-23 Thread guoren
From: Guo Ren 

If "echo 3 > /proc/irq/1/smp_affinity", we want irq 1 could be
broadcast to CPU0 & CPU1 and one of them would pick up the irq
handler.

But current implementation couldn't let multi CPUs process the
same IRQ concurrent.

Signed-off-by: Guo Ren 
---
 drivers/irqchip/irq-sifive-plic.c | 23 ++-
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/drivers/irqchip/irq-sifive-plic.c 
b/drivers/irqchip/irq-sifive-plic.c
index 2e56576..0003322 100644
--- a/drivers/irqchip/irq-sifive-plic.c
+++ b/drivers/irqchip/irq-sifive-plic.c
@@ -114,15 +114,12 @@ static inline void plic_irq_toggle(const struct cpumask 
*mask,
 static void plic_irq_unmask(struct irq_data *d)
 {
struct cpumask amask;
-   unsigned int cpu;
struct plic_priv *priv = irq_get_chip_data(d->irq);
 
cpumask_and(, >lmask, cpu_online_mask);
-   cpu = cpumask_any_and(irq_data_get_affinity_mask(d),
-  );
-   if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
-   return;
-   plic_irq_toggle(cpumask_of(cpu), d, 1);
+   cpumask_and(, , irq_data_get_affinity_mask(d));
+
+   plic_irq_toggle(, d, 1);
 }
 
 static void plic_irq_mask(struct irq_data *d)
@@ -136,24 +133,16 @@ static void plic_irq_mask(struct irq_data *d)
 static int plic_set_affinity(struct irq_data *d,
 const struct cpumask *mask_val, bool force)
 {
-   unsigned int cpu;
struct cpumask amask;
struct plic_priv *priv = irq_get_chip_data(d->irq);
 
cpumask_and(, >lmask, mask_val);
+   cpumask_and(, , cpu_online_mask);
 
-   if (force)
-   cpu = cpumask_first();
-   else
-   cpu = cpumask_any_and(, cpu_online_mask);
-
-   if (cpu >= nr_cpu_ids)
-   return -EINVAL;
+   irq_data_update_effective_affinity(d, );
 
plic_irq_toggle(>lmask, d, 0);
-   plic_irq_toggle(cpumask_of(cpu), d, 1);
-
-   irq_data_update_effective_affinity(d, cpumask_of(cpu));
+   plic_irq_toggle(, d, 1);
 
return IRQ_SET_MASK_OK_DONE;
 }
-- 
2.7.4