On 13/01/26 03:21PM, Peter Maydell wrote:
On Tue, 23 Dec 2025 at 12:02, Ashish Anand <[email protected]> wrote:

From: "ashish.a6" <[email protected]>

    Currently, QEMU implements the 'Wait For Event' (WFE) instruction as a
    a simple yield. This causes high host CPU usage because Guest
    RTOS idle loops effectively become busy-wait loops.

    To improve efficiency, this patch transitions WFE to use the architectural
    'Halt' state (EXCP_HLT) for M-profile CPUs. This allows the host thread
    to sleep when the guest is idle.


diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 39f2b2e54d..44433a444c 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -639,6 +639,7 @@ typedef struct CPUArchState {
         uint32_t nsacr;
         uint32_t ltpsize;
         uint32_t vpr;
+        uint32_t event_register;
     } v7m;

One more small thing that I thought of -- although we're only
implementing WFE support for M-profile here, the concept of the
event register is the same for A-profile. So we should put the
field in the top level of the CPU state struct, not inside the v7m
sub-struct. That way it's available for us to use and share
if and when we ever do it for A-profile.

+static bool m_event_needed(void *opaque)
+{
+    ARMCPU *cpu = opaque;
+    /* Only save the state if the event register is set (non-zero) */
+    return cpu->env.v7m.event_register != 0;
+}
+
+static const VMStateDescription vmstate_m_event = {
+    .name = "cpu/m/event",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = m_event_needed,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT32(env.v7m.event_register, ARMCPU),
+        VMSTATE_END_OF_LIST()
+    }
+};

...and so similarly the migration handling should not have
anything M-profile specific to it.

thanks
-- PMM

Hi Peter,

Thanks for the detailed review. I acknowledge the comments and will incorporate 
the suggested changes and send a v2 shortly.


Regards,
Ashish




Reply via email to