@@ -300,6 +300,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
#define PC_COMPAT_2_4 \
HW_COMPAT_2_4 \
{\
+ .driver = TYPE_X86_CPU,\
+ .property = "save-tsc-freq",\
+ .value = "off",\
+ },\
+ {\
.driver = "Haswell-" TYPE_X86_CPU,\
.property = "abm",\
.value = "off",\
@@ -3143,6 +3143,7 @@ static Property x86_cpu_properties[] = {
DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, false),
DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true),
+ DEFINE_PROP_BOOL("save-tsc-freq", X86CPU, env.save_tsc_khz, true),
DEFINE_PROP_UINT32("level", X86CPU, env.cpuid_level, 0),
DEFINE_PROP_UINT32("xlevel", X86CPU, env.cpuid_xlevel, 0),
DEFINE_PROP_UINT32("xlevel2", X86CPU, env.cpuid_xlevel2, 0),
@@ -966,6 +966,8 @@ typedef struct CPUX86State {
uint32_t sipi_vector;
bool tsc_valid;
int64_t tsc_khz;
+ int64_t tsc_khz_incoming;
+ bool save_tsc_khz;
void *kvm_xsave_buf;
uint64_t mcg_cap;
@@ -752,6 +752,24 @@ static const VMStateDescription vmstate_xss = {
}
};
+static bool tsc_khz_needed(void *opaque)
+{
+ X86CPU *cpu = opaque;
+ CPUX86State *env = &cpu->env;
+ return env->tsc_khz_incoming && env->save_tsc_khz;
+}
+
+static const VMStateDescription vmstate_tsc_khz = {
+ .name = "cpu/tsc_khz",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .needed = tsc_khz_needed,
+ .fields = (VMStateField[]) {
+ VMSTATE_INT64(env.tsc_khz_incoming, X86CPU),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
VMStateDescription vmstate_x86_cpu = {
.name = "cpu",
.version_id = 12,
@@ -871,6 +889,7 @@ VMStateDescription vmstate_x86_cpu = {
&vmstate_msr_hyperv_crash,
&vmstate_avx512,
&vmstate_xss,
+ &vmstate_tsc_khz,
NULL
}
};
The newly added subsection 'vmstate_tsc_khz' is used by following patches to migrate vcpu's TSC rate. For the back migration compatibility, this subsection is not migrated on pc-*-2.4 and older machine types by default. If users do want to migrate this subsection on older machine types, they can enable it by giving a new cpu option 'save-tsc-freq'. Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com> --- include/hw/i386/pc.h | 5 +++++ target-i386/cpu.c | 1 + target-i386/cpu.h | 2 ++ target-i386/machine.c | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+)