[PATCH v1 3/3] hw/intc: ibex_plic: Honour source priorities

Alistair Francis posted 3 patches 5 years, 3 months ago
Maintainers: Alistair Francis <Alistair.Francis@wdc.com>
[PATCH v1 3/3] hw/intc: ibex_plic: Honour source priorities
Posted by Alistair Francis 5 years, 3 months ago
This patch follows what commit aa4d30f6618dc "riscv: plic: Honour source
priorities" does and ensures that the highest priority interrupt will be
serviced first.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Cc: Jessica Clarke <jrtc27@jrtc27.com>
---
 hw/intc/ibex_plic.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c
index 669247ef08..f49fa67c91 100644
--- a/hw/intc/ibex_plic.c
+++ b/hw/intc/ibex_plic.c
@@ -57,6 +57,8 @@ static void ibex_plic_irqs_set_pending(IbexPlicState *s, int irq, bool level)
 static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context)
 {
     int i;
+    uint32_t max_irq = 0;
+    uint32_t max_prio = s->threshold;
 
     for (i = 0; i < s->pending_num; i++) {
         uint32_t irq_num = ctz64(s->pending[i]) + (i * 32);
@@ -66,14 +68,17 @@ static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context)
             continue;
         }
 
-        if (s->priority[irq_num] > s->threshold) {
-            if (!s->claim) {
-                s->claim = irq_num;
-            }
-            return true;
+        if (s->priority[irq_num] > max_prio) {
+            max_irq = irq_num;
+            max_prio = s->priority[irq_num];
         }
     }
 
+    if (max_irq) {
+        s->claim = max_irq;
+        return true;
+    }
+
     return false;
 }
 
-- 
2.27.0


Re: [PATCH v1 3/3] hw/intc: ibex_plic: Honour source priorities
Posted by Philippe Mathieu-Daudé 5 years, 3 months ago
On 7/25/20 7:34 AM, Alistair Francis wrote:
> This patch follows what commit aa4d30f6618dc "riscv: plic: Honour source
> priorities" does and ensures that the highest priority interrupt will be
> serviced first.
> 
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> Cc: Jessica Clarke <jrtc27@jrtc27.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  hw/intc/ibex_plic.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c
> index 669247ef08..f49fa67c91 100644
> --- a/hw/intc/ibex_plic.c
> +++ b/hw/intc/ibex_plic.c
> @@ -57,6 +57,8 @@ static void ibex_plic_irqs_set_pending(IbexPlicState *s, int irq, bool level)
>  static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context)
>  {
>      int i;
> +    uint32_t max_irq = 0;
> +    uint32_t max_prio = s->threshold;
>  
>      for (i = 0; i < s->pending_num; i++) {
>          uint32_t irq_num = ctz64(s->pending[i]) + (i * 32);
> @@ -66,14 +68,17 @@ static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context)
>              continue;
>          }
>  
> -        if (s->priority[irq_num] > s->threshold) {
> -            if (!s->claim) {
> -                s->claim = irq_num;
> -            }
> -            return true;
> +        if (s->priority[irq_num] > max_prio) {
> +            max_irq = irq_num;
> +            max_prio = s->priority[irq_num];
>          }
>      }
>  
> +    if (max_irq) {
> +        s->claim = max_irq;
> +        return true;
> +    }
> +
>      return false;
>  }
>  
>