[PATCH] LoongArch: KVM: rework pch_pic_update_batch_irqs()

Yury Norov (NVIDIA) posted 1 patch 2 weeks, 5 days ago
arch/loongarch/kvm/intc/pch_pic.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
[PATCH] LoongArch: KVM: rework pch_pic_update_batch_irqs()
Posted by Yury Norov (NVIDIA) 2 weeks, 5 days ago
Use proper bitmap API and drop all the housekeeping code.

Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 arch/loongarch/kvm/intc/pch_pic.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
index 119290bcea79..57e13ae51d24 100644
--- a/arch/loongarch/kvm/intc/pch_pic.c
+++ b/arch/loongarch/kvm/intc/pch_pic.c
@@ -35,16 +35,11 @@ static void pch_pic_update_irq(struct loongarch_pch_pic *s, int irq, int level)
 /* update batch irqs, the irq_mask is a bitmap of irqs */
 static void pch_pic_update_batch_irqs(struct loongarch_pch_pic *s, u64 irq_mask, int level)
 {
-	int irq, bits;
+	DECLARE_BITMAP(irqs, 64) = { BITMAP_FROM_U64(irq_mask) };
+	unsigned int irq;
 
-	/* find each irq by irqs bitmap and update each irq */
-	bits = sizeof(irq_mask) * 8;
-	irq = find_first_bit((void *)&irq_mask, bits);
-	while (irq < bits) {
+	for_each_set_bit(irq, irqs, 64)
 		pch_pic_update_irq(s, irq, level);
-		bitmap_clear((void *)&irq_mask, irq, 1);
-		irq = find_first_bit((void *)&irq_mask, bits);
-	}
 }
 
 /* called when a irq is triggered in pch pic */
-- 
2.43.0
Re: [PATCH] LoongArch: KVM: rework pch_pic_update_batch_irqs()
Posted by Bibo Mao 2 weeks, 2 days ago

On 2025/9/13 上午8:29, Yury Norov (NVIDIA) wrote:
> Use proper bitmap API and drop all the housekeeping code.
> 
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> ---
>   arch/loongarch/kvm/intc/pch_pic.c | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
> index 119290bcea79..57e13ae51d24 100644
> --- a/arch/loongarch/kvm/intc/pch_pic.c
> +++ b/arch/loongarch/kvm/intc/pch_pic.c
> @@ -35,16 +35,11 @@ static void pch_pic_update_irq(struct loongarch_pch_pic *s, int irq, int level)
>   /* update batch irqs, the irq_mask is a bitmap of irqs */
>   static void pch_pic_update_batch_irqs(struct loongarch_pch_pic *s, u64 irq_mask, int level)
>   {
> -	int irq, bits;
> +	DECLARE_BITMAP(irqs, 64) = { BITMAP_FROM_U64(irq_mask) };
> +	unsigned int irq;
>   
> -	/* find each irq by irqs bitmap and update each irq */
> -	bits = sizeof(irq_mask) * 8;
> -	irq = find_first_bit((void *)&irq_mask, bits);
> -	while (irq < bits) {
> +	for_each_set_bit(irq, irqs, 64)
>   		pch_pic_update_irq(s, irq, level);
> -		bitmap_clear((void *)&irq_mask, irq, 1);
> -		irq = find_first_bit((void *)&irq_mask, bits);
> -	}
>   }
>   
>   /* called when a irq is triggered in pch pic */
> 
Thanks for doing this.

Reviewed-by: Bibo Mao <maobibo@loongson.cn>

Re: [PATCH] LoongArch: KVM: rework pch_pic_update_batch_irqs()
Posted by Huacai Chen 2 weeks, 2 days ago
On Tue, Sep 16, 2025 at 9:30 AM Bibo Mao <maobibo@loongson.cn> wrote:
>
>
>
> On 2025/9/13 上午8:29, Yury Norov (NVIDIA) wrote:
> > Use proper bitmap API and drop all the housekeeping code.
> >
> > Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> > ---
> >   arch/loongarch/kvm/intc/pch_pic.c | 11 +++--------
> >   1 file changed, 3 insertions(+), 8 deletions(-)
> >
> > diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
> > index 119290bcea79..57e13ae51d24 100644
> > --- a/arch/loongarch/kvm/intc/pch_pic.c
> > +++ b/arch/loongarch/kvm/intc/pch_pic.c
> > @@ -35,16 +35,11 @@ static void pch_pic_update_irq(struct loongarch_pch_pic *s, int irq, int level)
> >   /* update batch irqs, the irq_mask is a bitmap of irqs */
> >   static void pch_pic_update_batch_irqs(struct loongarch_pch_pic *s, u64 irq_mask, int level)
> >   {
> > -     int irq, bits;
> > +     DECLARE_BITMAP(irqs, 64) = { BITMAP_FROM_U64(irq_mask) };
> > +     unsigned int irq;
> >
> > -     /* find each irq by irqs bitmap and update each irq */
> > -     bits = sizeof(irq_mask) * 8;
> > -     irq = find_first_bit((void *)&irq_mask, bits);
> > -     while (irq < bits) {
> > +     for_each_set_bit(irq, irqs, 64)
> >               pch_pic_update_irq(s, irq, level);
> > -             bitmap_clear((void *)&irq_mask, irq, 1);
> > -             irq = find_first_bit((void *)&irq_mask, bits);
> > -     }
> >   }
> >
> >   /* called when a irq is triggered in pch pic */
> >
> Thanks for doing this.
>
> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Queued, thanks.

Huacai

>
>