diff mbox series

[RFC,v2,20/48] cpus: Rename 'vcpu_dirty' field as negated 'hwaccel_synchronized'

Message ID 20250620171342.92678-21-philmd@linaro.org
State New
Headers show
Series accel: Preparatory cleanups for split-accel | expand

Commit Message

Philippe Mathieu-Daudé June 20, 2025, 5:13 p.m. UTC
Try to better describe which side is dirty (QEMU process or
hardware accelerator) by renaming as @hwaccel_synchronized.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/core/cpu.h |  4 ++--
 accel/kvm/kvm-all.c   | 20 ++++++++++----------
 target/mips/kvm.c     |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

Comments

Richard Henderson June 22, 2025, 1:35 a.m. UTC | #1
On 6/20/25 10:13, Philippe Mathieu-Daudé wrote:
> Try to better describe which side is dirty (QEMU process or
> hardware accelerator) by renaming as @hwaccel_synchronized.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/hw/core/cpu.h |  4 ++--
>   accel/kvm/kvm-all.c   | 20 ++++++++++----------
>   target/mips/kvm.c     |  4 ++--
>   3 files changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 69ea425c458..d5f82609943 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -441,7 +441,7 @@ struct qemu_work_item;
>    * @opaque: User data.
>    * @mem_io_pc: Host Program Counter at which the memory was accessed.
>    * @accel: Pointer to accelerator specific state.
> - * @vcpu_dirty: Hardware accelerator is not synchronized with QEMU state
> + * @hwaccel_synchronized: Hardware accelerator is synchronized with QEMU state

Is this change really helpful?  It isn't to me...

If you want to change anything, this could be a tri-state enum:

   - qemu state is current
   - hwaccel state is current
   - qemu+hwaccel are synced


r~
diff mbox series

Patch

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 69ea425c458..d5f82609943 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -441,7 +441,7 @@  struct qemu_work_item;
  * @opaque: User data.
  * @mem_io_pc: Host Program Counter at which the memory was accessed.
  * @accel: Pointer to accelerator specific state.
- * @vcpu_dirty: Hardware accelerator is not synchronized with QEMU state
+ * @hwaccel_synchronized: Hardware accelerator is synchronized with QEMU state
  * @kvm_fd: vCPU file descriptor for KVM.
  * @work_mutex: Lock to prevent multiple access to @work_list.
  * @work_list: List of pending asynchronous work.
@@ -538,7 +538,6 @@  struct CPUState {
     uint32_t kvm_fetch_index;
     uint64_t dirty_pages;
     int kvm_vcpu_stats_fd;
-    bool vcpu_dirty;
 
     /* Use by accel-block: CPU is executing an ioctl() */
     QemuLockCnt in_ioctl_lock;
@@ -555,6 +554,7 @@  struct CPUState {
     int32_t exception_index;
 
     AccelCPUState *accel;
+    bool hwaccel_synchronized;
 
     /* Used to keep track of an outstanding cpu throttle thread for migration
      * autoconverge
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 37faf615cbc..dca6d4b99ef 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -478,8 +478,8 @@  static int kvm_create_vcpu(CPUState *cpu)
 
     cpu->kvm_fd = kvm_fd;
     cpu->kvm_state = s;
-    if (!s->guest_state_protected) {
-        cpu->vcpu_dirty = true;
+    if (s->guest_state_protected) {
+        cpu->hwaccel_synchronized = true;
     }
     cpu->dirty_pages = 0;
     cpu->throttle_us_per_full = 0;
@@ -2880,7 +2880,7 @@  void kvm_flush_coalesced_mmio_buffer(void)
 
 static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
 {
-    if (!cpu->vcpu_dirty && !kvm_state->guest_state_protected) {
+    if (cpu->hwaccel_synchronized && !kvm_state->guest_state_protected) {
         Error *err = NULL;
         int ret = kvm_arch_get_registers(cpu, &err);
         if (ret) {
@@ -2894,13 +2894,13 @@  static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
             vm_stop(RUN_STATE_INTERNAL_ERROR);
         }
 
-        cpu->vcpu_dirty = true;
+        cpu->hwaccel_synchronized = false;
     }
 }
 
 void kvm_cpu_synchronize_state(CPUState *cpu)
 {
-    if (!cpu->vcpu_dirty && !kvm_state->guest_state_protected) {
+    if (cpu->hwaccel_synchronized && !kvm_state->guest_state_protected) {
         run_on_cpu(cpu, do_kvm_cpu_synchronize_state, RUN_ON_CPU_NULL);
     }
 }
@@ -2920,7 +2920,7 @@  static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg
         vm_stop(RUN_STATE_INTERNAL_ERROR);
     }
 
-    cpu->vcpu_dirty = false;
+    cpu->hwaccel_synchronized = true;
 }
 
 void kvm_cpu_synchronize_post_reset(CPUState *cpu)
@@ -2946,7 +2946,7 @@  static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)
         exit(1);
     }
 
-    cpu->vcpu_dirty = false;
+    cpu->hwaccel_synchronized = true;
 }
 
 void kvm_cpu_synchronize_post_init(CPUState *cpu)
@@ -2962,7 +2962,7 @@  void kvm_cpu_synchronize_post_init(CPUState *cpu)
 
 static void do_kvm_cpu_synchronize_pre_loadvm(CPUState *cpu, run_on_cpu_data arg)
 {
-    cpu->vcpu_dirty = true;
+    cpu->hwaccel_synchronized = false;
 }
 
 void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu)
@@ -3131,7 +3131,7 @@  int kvm_cpu_exec(CPUState *cpu)
     do {
         MemTxAttrs attrs;
 
-        if (cpu->vcpu_dirty) {
+        if (!cpu->hwaccel_synchronized) {
             Error *err = NULL;
             ret = kvm_arch_put_registers(cpu, KVM_PUT_RUNTIME_STATE, &err);
             if (ret) {
@@ -3145,7 +3145,7 @@  int kvm_cpu_exec(CPUState *cpu)
                 break;
             }
 
-            cpu->vcpu_dirty = false;
+            cpu->hwaccel_synchronized = true;
         }
 
         kvm_arch_pre_run(cpu, run);
diff --git a/target/mips/kvm.c b/target/mips/kvm.c
index ec53acb51a1..44fca0d649f 100644
--- a/target/mips/kvm.c
+++ b/target/mips/kvm.c
@@ -565,7 +565,7 @@  static void kvm_mips_update_state(void *opaque, bool running, RunState state)
      * already saved and can be restored when it is synced back to KVM.
      */
     if (!running) {
-        if (!cs->vcpu_dirty) {
+        if (cs->hwaccel_synchronized) {
             ret = kvm_mips_save_count(cs);
             if (ret < 0) {
                 warn_report("Failed saving count");
@@ -581,7 +581,7 @@  static void kvm_mips_update_state(void *opaque, bool running, RunState state)
             return;
         }
 
-        if (!cs->vcpu_dirty) {
+        if (cs->hwaccel_synchronized) {
             ret = kvm_mips_restore_count(cs);
             if (ret < 0) {
                 warn_report("Failed restoring count");