qemu -enable-kvm *slower* than pure emulation for x86_64

1

Running qemu-system-x86_64 -enable-kvm -cpu host -smp cores=4 hosted on an Intel Xeon/Core-2 (newgen, Family=6) or better machine (total number of cores on guest=24, total ram=196gb), and the guest kernel hangs for several minutes and the host kernel pushes messages like:

kvm: SMP vm created on host with unstable TSC; guest TSC will not be reliable
kvm [..]: vcpu0, guest rIP: 0xffffffff81064724 disabled perfctr wrmsr: 0xc2 data 0xffff

Removing -enable-kvm -cpu host ... the guest system becomes faster!?

What gives?

Ahmed Masud

Posted 2018-04-28T05:19:52.883

Reputation: 424

What kernel versions are you using on either side? Could it be related to a bug, fixed by the patch x86/tsc: Fix erroneous TSC rate on Skylake Xeon?

– Lekensteyn – 2018-04-28T08:50:22.837

Answers

1

Well it turns out that issue is the clock source used by kvm on the host system. Have a look at the output of:

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource

if it's tcs or tcs_early you have found the culprit, change it to one of the other available clock sources on your system:

$ cat /sys/devices/system/clocksource/clocksource0/available_clocksource

For example hpet (high performance event timer):

$ echo hpet | sudo tee /sys/devices/system/clocksource/clocksource0/current_clocksource

Ahmed Masud

Posted 2018-04-28T05:19:52.883

Reputation: 424

Any chance of an explanation of why tcs is a bad clock source to use compared to others? Are there any other downsides or benefits to changing the clock source? – Mokubai – 2018-04-28T07:51:53.357

Possible information on the why from Intel (https://software.intel.com/en-us/blogs/2013/06/20/eliminate-the-dreaded-clocksource-is-unstable-message-switch-to-tsc-for-a-stable) but I'm not convinced as it mentions the Xeon Phi as problematic and not supporting invariant tsc.

– Mokubai – 2018-04-28T08:05:29.863

1I didn't get into figuring out why tcs clock is a bad source, just didn't have the time to go around hacking kvm code. I'll probably run some tests after the silly project that I have going gets done. However it's definitely the culprit, because the problem is easily reproduced on multiple hardwares with several permutations – Ahmed Masud – 2018-04-28T16:09:02.007