From 7373c4e48f293fb4d361b1bf2d0986166d8480be Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Thu, 23 Mar 2017 15:54:38 +0100 Subject: [PATCH] qemu: Add support for setting TSC frequency QEMU allows for TSC frequency to be explicitly set to enable migration with invtsc (migration fails if the destination QEMU cannot set the exact same frequency used when starting the domain on the source host). Libvirt already supports setting the TSC frequency in the XML using which will be transformed into -cpu Model,tsc-frequency=1234567890 QEMU command line. Signed-off-by: Jiri Denemark --- src/qemu/qemu_command.c | 16 +++++---- .../qemuxml2argv-cpu-tsc-frequency.args | 23 ++++++++++++ .../qemuxml2argv-cpu-tsc-frequency.xml | 35 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2a2ab3e9b0..987b95afa5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6329,12 +6329,12 @@ qemuBuildClockCommandLine(virCommandPtr cmd, for (i = 0; i < def->clock.ntimers; i++) { switch ((virDomainTimerNameType) def->clock.timers[i]->name) { case VIR_DOMAIN_TIMER_NAME_PLATFORM: - case VIR_DOMAIN_TIMER_NAME_TSC: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported timer type (name) '%s'"), virDomainTimerNameTypeToString(def->clock.timers[i]->name)); return -1; + case VIR_DOMAIN_TIMER_NAME_TSC: case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: /* Timers above are handled when building -cpu. */ @@ -6921,19 +6921,23 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, for (i = 0; i < def->clock.ntimers; i++) { virDomainTimerDefPtr timer = def->clock.timers[i]; - if (timer->present == -1) - continue; - - if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK) { + if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK && + timer->present != -1) { virBufferAsprintf(&buf, "%s,%ckvmclock", have_cpu ? "" : default_model, timer->present ? '+' : '-'); have_cpu = true; } else if (timer->name == VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK && - timer->present) { + timer->present == 1) { virBufferAsprintf(&buf, "%s,hv_time", have_cpu ? "" : default_model); have_cpu = true; + } else if (timer->name == VIR_DOMAIN_TIMER_NAME_TSC && + timer->frequency > 0) { + virBufferAsprintf(&buf, "%s,tsc-frequency=%lu", + have_cpu ? "" : default_model, + timer->frequency); + have_cpu = true; } } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.args new file mode 100644 index 0000000000..50223fab2b --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.args @@ -0,0 +1,23 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-cpu Haswell,+vme,+ds,+acpi,+ss,+ht,+tm,+pbe,+dtes64,+monitor,+ds_cpl,+vmx,\ ++smx,+est,+tm2,+xtpr,+pdcm,+osxsave,+f16c,+rdrand,+pdpe1gb,+abm,+lahf_lm,\ ++invtsc,tsc-frequency=3504000000 \ +-m 214 \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.xml new file mode 100644 index 0000000000..72afe6cd27 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-tsc-frequency.xml @@ -0,0 +1,35 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + A description of the test machine. + + A test of qemu's minimal configuration. + This test also tests the description and title elements. + + 219100 + 219100 + 1 + + hvm + + + + + + + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e523236df4..41461eadc8 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1552,6 +1552,7 @@ mymain(void) DO_TEST("cpu-Haswell3", QEMU_CAPS_KVM); DO_TEST("cpu-Haswell-noTSX", QEMU_CAPS_KVM); DO_TEST("cpu-host-model-cmt", NONE); + DO_TEST("cpu-tsc-frequency", QEMU_CAPS_KVM); qemuTestSetHostCPU(driver.caps, NULL); DO_TEST("encrypted-disk", NONE); -- 2.47.2