From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>
Cc: kvm-devel@lists.sourceforge.net, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 3/5] QEMU/KVM: save and load mp state
Date: Fri, 11 Apr 2008 13:24:43 -0300 [thread overview]
Message-ID: <20080411162949.124986756@localhost.localdomain> (raw)
In-Reply-To: 20080411162440.693057357@localhost.localdomain
[-- Attachment #1: smpmig-qemu --]
[-- Type: text/plain, Size: 4437 bytes --]
Use the new interface to save and restore MP_STATE for all vcpu's.
Increase version_id for cpu_load/cpu_save.
Fixes SMP migration.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm-userspace.io/qemu/hw/pc.c
===================================================================
--- kvm-userspace.io.orig/qemu/hw/pc.c
+++ kvm-userspace.io/qemu/hw/pc.c
@@ -750,7 +750,7 @@ CPUState *pc_new_cpu(int cpu, const char
/* XXX: enable it in all cases */
env->cpuid_features |= CPUID_APIC;
}
- register_savevm("cpu", cpu, 4, cpu_save, cpu_load, env);
+ register_savevm("cpu", cpu, 5, cpu_save, cpu_load, env);
qemu_register_reset(main_cpu_reset, env);
if (pci_enabled) {
apic_init(env);
Index: kvm-userspace.io/qemu/qemu-kvm-x86.c
===================================================================
--- kvm-userspace.io.orig/qemu/qemu-kvm-x86.c
+++ kvm-userspace.io/qemu/qemu-kvm-x86.c
@@ -277,6 +277,33 @@ void kvm_arch_load_regs(CPUState *env)
perror("kvm_set_msrs FAILED");
}
+void kvm_save_mpstate(CPUState *env)
+{
+#ifdef KVM_CAP_MP_STATE
+ int r;
+ struct kvm_mp_state mp_state;
+
+ r = kvm_get_mpstate(kvm_context, env->cpu_index, &mp_state);
+ if (r < 0)
+ env->mp_state = -1;
+ else
+ env->mp_state = mp_state.mp_state;
+#endif
+}
+
+void kvm_load_mpstate(CPUState *env)
+{
+#ifdef KVM_CAP_MP_STATE
+ struct kvm_mp_state mp_state = { .mp_state = env->mp_state };
+
+ /*
+ * -1 indicates that the host did not support GET_MP_STATE ioctl,
+ * so don't touch it.
+ */
+ if (env->mp_state != -1)
+ kvm_set_mpstate(kvm_context, env->cpu_index, &mp_state);
+#endif
+}
void kvm_arch_save_regs(CPUState *env)
{
Index: kvm-userspace.io/qemu/qemu-kvm.h
===================================================================
--- kvm-userspace.io.orig/qemu/qemu-kvm.h
+++ kvm-userspace.io/qemu/qemu-kvm.h
@@ -18,6 +18,8 @@ int kvm_init_ap(void);
void kvm_qemu_destroy(void);
void kvm_load_registers(CPUState *env);
void kvm_save_registers(CPUState *env);
+void kvm_load_mpstate(CPUState *env);
+void kvm_save_mpstate(CPUState *env);
int kvm_cpu_exec(CPUState *env);
int kvm_update_debugger(CPUState *env);
int kvm_qemu_init_env(CPUState *env);
Index: kvm-userspace.io/qemu/target-i386/cpu.h
===================================================================
--- kvm-userspace.io.orig/qemu/target-i386/cpu.h
+++ kvm-userspace.io/qemu/target-i386/cpu.h
@@ -599,6 +599,7 @@ typedef struct CPUX86State {
/* in order to simplify APIC support, we leave this pointer to the
user */
struct APICState *apic_state;
+ int mp_state;
} CPUX86State;
CPUX86State *cpu_x86_init(const char *cpu_model);
Index: kvm-userspace.io/qemu/vl.c
===================================================================
--- kvm-userspace.io.orig/qemu/vl.c
+++ kvm-userspace.io/qemu/vl.c
@@ -6655,8 +6655,10 @@ void cpu_save(QEMUFile *f, void *opaque)
uint32_t hflags;
int i;
- if (kvm_enabled())
+ if (kvm_enabled()) {
kvm_save_registers(env);
+ kvm_save_mpstate(env);
+ }
for(i = 0; i < CPU_NB_REGS; i++)
qemu_put_betls(f, &env->regs[i]);
@@ -6748,6 +6750,7 @@ void cpu_save(QEMUFile *f, void *opaque)
qemu_put_be32s(f, &env->kvm_interrupt_bitmap[i]);
}
qemu_put_be64s(f, &env->tsc);
+ qemu_put_be32s(f, &env->mp_state);
}
}
@@ -6782,7 +6785,7 @@ int cpu_load(QEMUFile *f, void *opaque,
uint32_t hflags;
uint16_t fpus, fpuc, fptag, fpregs_format;
- if (version_id != 3 && version_id != 4)
+ if (version_id < 3 || version_id > 5)
return -EINVAL;
for(i = 0; i < CPU_NB_REGS; i++)
qemu_get_betls(f, &env->regs[i]);
@@ -6900,6 +6903,10 @@ int cpu_load(QEMUFile *f, void *opaque,
}
qemu_get_be64s(f, &env->tsc);
kvm_load_registers(env);
+ if (version_id >= 5) {
+ qemu_get_be32s(f, &env->mp_state);
+ kvm_load_mpstate(env);
+ }
}
return 0;
}
--
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
next prev parent reply other threads:[~2008-04-11 16:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-11 16:24 [patch 0/5] fix SMP migration and loadvm/savevm (V3) Marcelo Tosatti
2008-04-11 16:24 ` [patch 1/5] QEMU/KVM: properly copy the in-kernel apicbase value Marcelo Tosatti
2008-04-11 16:24 ` [patch 2/5] QEMU/KVM: Add libkvm interface to get/set the mpstate Marcelo Tosatti
2008-04-11 16:24 ` Marcelo Tosatti [this message]
2008-04-11 16:24 ` [patch 4/5] QEMU/KVM: ignore SIG_IPI signals in userspace Marcelo Tosatti
2008-04-11 16:24 ` [patch 5/5] KVM: add ioctls to save/store mpstate Marcelo Tosatti
2008-04-13 14:59 ` Avi Kivity
2008-04-13 15:01 ` [patch 0/5] fix SMP migration and loadvm/savevm (V3) Avi Kivity
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=20080411162949.124986756@localhost.localdomain \
--to=mtosatti@redhat.com \
--cc=avi@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox