All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: patches@linaro.org
Subject: [Qemu-devel] [PATCH 04/19] nvic: Add cached vectpending_prio state
Date: Tue, 12 Sep 2017 19:13:51 +0100	[thread overview]
Message-ID: <1505240046-11454-5-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1505240046-11454-1-git-send-email-peter.maydell@linaro.org>

Instead of looking up the pending priority
in nvic_pending_prio(), cache it in a new state struct
field. The calculation of the pending priority given
the interrupt number is more complicated in v8M with
the security extension, so the caching will be worthwhile.

This changes nvic_pending_prio() from returning a full
(group + subpriority) priority value to returning a group
priority. This doesn't require changes to its callsites
because we use it only in comparisons of the form
  execution_prio > nvic_pending_prio()
and execution priority is always a group priority, so
a test (exec prio > full prio) is true if and only if
(execprio > group_prio).

(Architecturally the expected comparison is with the
group priority for this sort of "would we preempt" test;
we were only doing a test with a full priority as an
optimisation to avoid the mask, which is possible
precisely because the two comparisons always give the
same answer.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/intc/armv7m_nvic.h |  2 ++
 hw/intc/armv7m_nvic.c         | 23 +++++++++++++----------
 hw/intc/trace-events          |  2 +-
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
index 87c78b3..329774e 100644
--- a/include/hw/intc/armv7m_nvic.h
+++ b/include/hw/intc/armv7m_nvic.h
@@ -62,6 +62,7 @@ typedef struct NVICState {
      *  - vectpending
      *  - vectpending_is_secure
      *  - exception_prio
+     *  - vectpending_prio
      */
     unsigned int vectpending; /* highest prio pending enabled exception */
     /* true if vectpending is a banked secure exception, ie it is in
@@ -69,6 +70,7 @@ typedef struct NVICState {
      */
     bool vectpending_is_s_banked;
     int exception_prio; /* group prio of the highest prio active exception */
+    int vectpending_prio; /* group prio of the exeception in vectpending */
 
     MemoryRegion sysregmem;
     MemoryRegion sysreg_ns_mem;
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index 417a456..8388d64 100644
--- a/hw/intc/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -61,10 +61,10 @@ static const uint8_t nvic_id[] = {
 
 static int nvic_pending_prio(NVICState *s)
 {
-    /* return the priority of the current pending interrupt,
+    /* return the group priority of the current pending interrupt,
      * or NVIC_NOEXC_PRIO if no interrupt is pending
      */
-    return s->vectpending ? s->vectors[s->vectpending].prio : NVIC_NOEXC_PRIO;
+    return s->vectpending_prio;
 }
 
 /* Return the value of the ISCR RETTOBASE bit:
@@ -156,10 +156,17 @@ static void nvic_recompute_state(NVICState *s)
         active_prio &= nvic_gprio_mask(s);
     }
 
+    if (pend_prio > 0) {
+        pend_prio &= nvic_gprio_mask(s);
+    }
+
     s->vectpending = pend_irq;
+    s->vectpending_prio = pend_prio;
     s->exception_prio = active_prio;
 
-    trace_nvic_recompute_state(s->vectpending, s->exception_prio);
+    trace_nvic_recompute_state(s->vectpending,
+                               s->vectpending_prio,
+                               s->exception_prio);
 }
 
 /* Return the current execution priority of the CPU
@@ -323,7 +330,6 @@ void armv7m_nvic_acknowledge_irq(void *opaque)
     CPUARMState *env = &s->cpu->env;
     const int pending = s->vectpending;
     const int running = nvic_exec_prio(s);
-    int pendgroupprio;
     VecInfo *vec;
 
     assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq);
@@ -333,13 +339,9 @@ void armv7m_nvic_acknowledge_irq(void *opaque)
     assert(vec->enabled);
     assert(vec->pending);
 
-    pendgroupprio = vec->prio;
-    if (pendgroupprio > 0) {
-        pendgroupprio &= nvic_gprio_mask(s);
-    }
-    assert(pendgroupprio < running);
+    assert(s->vectpending_prio < running);
 
-    trace_nvic_acknowledge_irq(pending, vec->prio);
+    trace_nvic_acknowledge_irq(pending, s->vectpending_prio);
 
     vec->active = 1;
     vec->pending = 0;
@@ -1251,6 +1253,7 @@ static void armv7m_nvic_reset(DeviceState *dev)
     s->exception_prio = NVIC_NOEXC_PRIO;
     s->vectpending = 0;
     s->vectpending_is_s_banked = false;
+    s->vectpending_prio = NVIC_NOEXC_PRIO;
 }
 
 static void nvic_systick_trigger(void *opaque, int n, int level)
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 4762329..5635a5f 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -167,7 +167,7 @@ gicv3_redist_set_irq(uint32_t cpu, int irq, int level) "GICv3 redistributor 0x%x
 gicv3_redist_send_sgi(uint32_t cpu, int irq) "GICv3 redistributor 0x%x pending SGI %d"
 
 # hw/intc/armv7m_nvic.c
-nvic_recompute_state(int vectpending, int exception_prio) "NVIC state recomputed: vectpending %d exception_prio %d"
+nvic_recompute_state(int vectpending, int vectpending_prio, int exception_prio) "NVIC state recomputed: vectpending %d vectpending_prio %d exception_prio %d"
 nvic_set_prio(int irq, uint8_t prio) "NVIC set irq %d priority %d"
 nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d"
 nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d"
-- 
2.7.4

  parent reply	other threads:[~2017-09-12 18:13 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-12 18:13 [Qemu-devel] [PATCH 00/19] ARMv8M: support security extn in the NVIC Peter Maydell
2017-09-12 18:13 ` [Qemu-devel] [PATCH 01/19] target/arm: Implement MSR/MRS access to NS banked registers Peter Maydell
2017-09-13 22:58   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 02/19] nvic: Add banked exception states Peter Maydell
2017-09-13 23:08   ` Richard Henderson
2017-09-19 18:31   ` [Qemu-devel] [Qemu-arm] " Peter Maydell
2017-09-12 18:13 ` [Qemu-devel] [PATCH 03/19] nvic: Add cached vectpending_is_s_banked state Peter Maydell
2017-09-12 18:13 ` Peter Maydell [this message]
2017-09-13 23:25   ` [Qemu-devel] [PATCH 04/19] nvic: Add cached vectpending_prio state Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 05/19] nvic: Implement AIRCR changes for v8M Peter Maydell
2017-09-13 23:35   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 06/19] nvic: Make ICSR.RETTOBASE handle banked exceptions Peter Maydell
2017-09-19 18:04   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 07/19] nvic: Implement NVIC_ITNS<n> registers Peter Maydell
2017-09-19 18:19   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 08/19] nvic: Handle banked exceptions in nvic_recompute_state() Peter Maydell
2017-09-19 18:32   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 09/19] nvic: Make set_pending and clear_pending take a secure parameter Peter Maydell
2017-09-19 18:41   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 10/19] nvic: Make SHPR registers banked Peter Maydell
2017-09-19 18:47   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 11/19] nvic: Compare group priority for escalation to HF Peter Maydell
2017-09-19 18:48   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 12/19] nvic: In escalation to HardFault, support HF not being priority -1 Peter Maydell
2017-09-19 18:50   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 13/19] nvic: Implement v8M changes to fixed priority exceptions Peter Maydell
2017-09-19 18:54   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 14/19] nvic: Disable the non-secure HardFault if AIRCR.BFHFNMINS is clear Peter Maydell
2017-09-19 18:59   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 15/19] nvic: Handle v8M changes in nvic_exec_prio() Peter Maydell
2017-09-20 17:21   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 16/19] target/arm: Handle banking in negative-execution-priority check in cpu_mmu_index() Peter Maydell
2017-09-20 17:35   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 17/19] nvic: Make ICSR banked for v8M Peter Maydell
2017-09-20 17:43   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 18/19] nvic: Make SHCSR " Peter Maydell
2017-09-20 18:37   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 19/19] nvic: Support banked exceptions in acknowledge and complete Peter Maydell
2017-09-20 18:39   ` Richard Henderson
2017-09-19 18:12 ` [Qemu-devel] [PATCH 00/19] ARMv8M: support security extn in the NVIC no-reply
2017-09-19 18:29   ` Peter Maydell
2017-09-19 18:22 ` no-reply

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=1505240046-11454-5-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=patches@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.