Bug 700272 - RFE add support for "host cpu" in Libvirt
RFE add support for "host cpu" in Libvirt
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
6.2
Unspecified Unspecified
high Severity medium
: rc
: ---
Assigned To: Jiri Denemark
Virtualization Bugs
: FutureFeature
Depends On:
Blocks: 747667 756082 796527
  Show dependency treegraph
 
Reported: 2011-04-27 20:27 EDT by Andrew Cathrow
Modified: 2014-09-07 18:54 EDT (History)
14 users (show)

See Also:
Fixed In Version: libvirt-0.9.10-1.el6
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
: 796527 (view as bug list)
Environment:
Last Closed: 2012-06-20 02:27:20 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Andrew Cathrow 2011-04-27 20:27:28 EDT
Add support to libvirt to allow user to specify equivalent of -cpu host in domain XML.

Use case : To allow users to squeeze the maximum performance out of their virtual machines if they are willing to forgo the more flexible migration options offered by the existing libvirt support.
Comment 1 Andrew Cathrow 2011-04-28 12:28:23 EDT
The important part is that we allow the VM to be generically configured to use all the resources of the host CPU.
eg <cpu>host</cpu>  

That doesn't mean we have to translate that to qemu-kvm -cpu host
that could mean that libvirt dynamically builds the CPU configuration - so if the VM is started on machine that would translate to  <vendor>Intel</vendor> <model>core2duo</model> but on machine B that would be translated to <model>opteron2</model> etc.

The goal would be a generic guest configuration that would use the maximum available CPU resources on the host.

Using that approach rather that -cpu host would allow migration without sacrificing performance.
Comment 6 Cole Robinson 2011-07-21 10:09:59 EDT
Libvirt already allows doing this in a round about way, the steps are:

virsh capabilities | less
<copy out the <cpu> block>
virsh edit $vmname
<paste under <domain> block>

virt-manager provides a button for this, "copy from host cpu"
virt-install provides a --cpu host option for this

but it would probably be an easy addition to libvirt to have

<cpu>
  <model>host</model>
<cpu>

just be a shortcut for autopopulating the XML with the host CPU info. we wouldn't carry <model>host</model> around in the XML or anything, so it would be exactly the same as the above steps. this would also make tools lives easier since we wouldn't have to do the capabilities->domainxml dance
Comment 7 Cole Robinson 2011-07-21 10:11:27 EDT
Ah I just read comment #2 and realize that the RFE is slightly different. my comment still stands though :)
Comment 8 Dave Allan 2011-07-21 14:25:27 EDT
(In reply to comment #7)
> Ah I just read comment #2 and realize that the RFE is slightly different. my
> comment still stands though :)

Actually, I think your comment 6 about

<cpu>
  <model>host</model>
<cpu>

is exactly what's being requested.
Comment 9 Dave Allan 2011-07-21 14:26:34 EDT
It's just syntactic sugar so applications and users don't have to do the capabilities dance, as you point out.
Comment 10 Andrew Cathrow 2011-07-21 15:51:48 EDT
And also so that they only do it once and the domain XML can be used on many different hosts without change and will always be optimal for that machine.
Comment 11 John Walicki 2011-09-06 19:41:38 EDT
This would be an important feature for IBM.
Comment 13 Jiri Denemark 2012-01-06 10:06:27 EST
An initial version of patches providing this functionality was sent upstream for review: https://www.redhat.com/archives/libvir-list/2012-January/msg00229.html
Comment 14 Jiri Denemark 2012-01-17 06:45:30 EST
This feature is now implemented upstream as of v0.9.9-59-ge7201af:

commit e7201afdf7648a3c2c654218a651ae8c967aa789
Author: Jiri Denemark <jdenemar@redhat.com>
Date:   Wed Dec 21 13:47:17 2011 +0100

    qemu: Add support for host CPU modes
    
    This adds support for host-model and host-passthrough CPU modes to qemu
    driver. The host-passthrough mode is mapped to -cpu host.

Detailed documentation should be available (in about 1 hour since now) at http://www.libvirt.org/formatdomain.html#elementsCPU
Comment 18 min zhan 2012-02-14 04:39:20 EST
Reproduce this bug with libvirt-0.9.9-2.el6;

Verified this bug with libvirt-0.9.10-1.el6
Steps:
1. Check host-model mode

For a shutdown guest, add the following
# virsh edit guest
...
<cpu mode='host-model'/>
...

# virsh start guest
# ps -ef|grep kvm 
qemu      8338     1 28 04:14 ?        00:00:20 /usr/libexec/qemu-kvm -S -M rhel6.2.0 -cpu Penryn,+osxsave,+xsave,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+monitor,+dtes64,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name rhel62......

# virsh capabilities
...
  <host>
...
      <model>Penryn</model>
...

Found the guest is using the same model as host. Here is Penryn.

But there is a issue that virt-manager can not get and display this model info. For virt-manager it could be correct only if you click 'copy host model' button. Is it a bug for virt-manager, at least rfe, right? 

Cole, could you help to confirm? Thanks


2. Check host-passthrough model

For a shutdown guest, add the following
# virsh edit guest
...
<cpu mode='host-passthrough'/>
...

# virsh start guest

# ps -ef |grep kvm
qemu     10137     1 10 04:28 ?        00:00:00 /usr/libexec/qemu-kvm -S -M rhel6.2.0 -cpu host -enable-kvm -m 1024 -smp 1,sockets=1,cores=1,threads=1 -name rhel62 ....

We can find '-cpu host' from qemu cmd.

----------------
For the 2 newly added cpu models, the verification passed. So move to VERIFIED status. But also waiting for dev's confirmation about the issue above. Maybe open a new bug to track in virt-manager.
Comment 20 Cole Robinson 2012-03-04 14:05:36 EST
Clearing NEEDINFO since a virt-manager bug was opened.
Comment 22 errata-xmlrpc 2012-06-20 02:27:20 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2012-0748.html
Comment 23 Yaniv Kaul 2012-12-04 09:54:04 EST
Why isn't it adding +x2apic?
Comment 24 Jiri Denemark 2012-12-04 12:33:45 EST
Well, with <cpu mode='host-passthrough'/> libvirt is supposed to call qemu-kvm with -cpu host and it's up to qemu-kvm to decide what the guest CPU should look like.
Comment 25 Doron Fediuck 2012-12-04 12:51:23 EST
(In reply to comment #23)
> Why isn't it adding +x2apic?

Yaniv, IIUC x2apic is a specific flag of the cpu, which may / may not be exposed by the host processor. So this will work even with host-passthrough if all hosts have the same processor capabilities.

See also: http://www.linux-kvm.org/page/Tuning_KVM
Comment 26 Yaniv Kaul 2012-12-04 12:52:54 EST
(In reply to comment #25)
> (In reply to comment #23)
> > Why isn't it adding +x2apic?
> 
> Yaniv, IIUC x2apic is a specific flag of the cpu, which may / may not be
> exposed by the host processor. So this will work even with host-passthrough
> if all hosts have the same processor capabilities.
> 
> See also: http://www.linux-kvm.org/page/Tuning_KVM

That's not true, x2apic is emulated by KVM. Even if the host doesn't have it, it's worth (for linux guests) to have it.
Comment 27 Doron Fediuck 2012-12-04 12:56:08 EST
(In reply to comment #26)
> (In reply to comment #25)
> > (In reply to comment #23)
> > > Why isn't it adding +x2apic?

> > See also: http://www.linux-kvm.org/page/Tuning_KVM
> 
> That's not true, x2apic is emulated by KVM. Even if the host doesn't have
> it, it's worth (for linux guests) to have it.

In this case it cannot work together, as host-passthrough exposes flags which kvm does not support / aware of. So it cannot maintain compatibility when using flags kvm does not support.
Comment 28 Yaniv Kaul 2012-12-04 16:56:07 EST
(In reply to comment #27)
> (In reply to comment #26)
> > (In reply to comment #25)
> > > (In reply to comment #23)
> > > > Why isn't it adding +x2apic?
> 
> > > See also: http://www.linux-kvm.org/page/Tuning_KVM
> > 
> > That's not true, x2apic is emulated by KVM. Even if the host doesn't have
> > it, it's worth (for linux guests) to have it.
> 
> In this case it cannot work together, as host-passthrough exposes flags
> which kvm does not support / aware of. So it cannot maintain compatibility
> when using flags kvm does not support.

Of course KVM supports it. I would not have recommended it otherwise.
It has nothing to do with the host, it's emulated by KVM (see http://patchwork.ozlabs.org/patch/98478/).

It's probably a libvirt bug (RFE?) to add it to the host delivered flags, unconditionally (pending the kvm version?).

Note You need to log in before you can comment on or make changes to this bug.