diff mbox

[qom-cpu,43/59] kvmclock: Abstract kvmclock_vm_state_change() with qemu_for_each_cpu()

Message ID 1370805206-26574-44-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber June 9, 2013, 7:13 p.m. UTC
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/i386/kvm/clock.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index 87d4d0f..eaeb0ff 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -61,13 +61,25 @@  static int kvmclock_post_load(void *opaque, int version_id)
     return kvm_vm_ioctl(kvm_state, KVM_SET_CLOCK, &data);
 }
 
+static void kvmclock_vm_state_change_one(CPUState *cs, void *data)
+{
+    int *ret = data;
+
+    if (*ret) {
+        return;
+    }
+    *ret = kvm_vcpu_ioctl(cs, KVM_KVMCLOCK_CTRL, 0);
+    if (*ret != -EINVAL) {
+        fprintf(stderr, "%s: %s\n", __func__, strerror(-*ret));
+    }
+}
+
 static void kvmclock_vm_state_change(void *opaque, int running,
                                      RunState state)
 {
     KVMClockState *s = opaque;
-    CPUArchState *penv = first_cpu;
     int cap_clock_ctrl = kvm_check_extension(kvm_state, KVM_CAP_KVMCLOCK_CTRL);
-    int ret;
+    int ret = 0;
 
     if (running) {
         s->clock_valid = false;
@@ -75,15 +87,7 @@  static void kvmclock_vm_state_change(void *opaque, int running,
         if (!cap_clock_ctrl) {
             return;
         }
-        for (penv = first_cpu; penv != NULL; penv = penv->next_cpu) {
-            ret = kvm_vcpu_ioctl(ENV_GET_CPU(penv), KVM_KVMCLOCK_CTRL, 0);
-            if (ret) {
-                if (ret != -EINVAL) {
-                    fprintf(stderr, "%s: %s\n", __func__, strerror(-ret));
-                }
-                return;
-            }
-        }
+        qemu_for_each_cpu(kvmclock_vm_state_change_one, &ret);
     }
 }