virtinst: add vcpupin support

Add vcpupin support to virt-install so that it can create guest
domains with statically allocated vcpu pinning towards a given cpuset.

Syntax: to pin vcpu=0 to cpuset="1,3" and vcpu=1 to cpuset=2

  --cputune vcpupin0.vcpu=0,vcpupin0.cpuset=1,3,vcpupin1.vcpu=1,vcpupin1.cpuset=2

generates below XML description for the guest domain.

  <cputune>
    <vcpupin vcpu="0" cpuset="1,3"/>
    <vcpupin vcpu="1" cpuset="2"/>
  </cputune>

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Signed-off-by: Menno Lageman <menno.lageman@oracle.com>
This commit is contained in:
Wim ten Have 2018-02-06 12:56:41 +01:00 committed by Cole Robinson
parent 582c1d3ded
commit 708516c39e
7 changed files with 88 additions and 0 deletions

View File

@ -255,6 +255,16 @@ Example of passing through the host cpu's cache information.
Use --cpu=? to see a list of all available sub options. Complete details at L<http://libvirt.org/formatdomain.html#elementsCPU>
=item B<--cputune> OPTIONS
Tune CPU parameters for the guest.
Configure which of the host's physical CPUs the domain VCPU will be pinned to. Example invocation
--cputune vpcupin0.vcpu=0,vpcupin0.cpuset=0-3,vpcupin1.vcpu=1,vpcupin1.cpuset=4-7
Use --cputune=? to see a list of all available sub options. Complete details at L<http://libvirt.org/formatdomain.html#elementsCPUTuning>
=item B<--security> type=TYPE[,label=LABEL][,relabel=yes|no]
Configure domain security driver settings. Type can be either 'static' or

View File

@ -159,6 +159,9 @@
<label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
</seclabel>
<on_lockfailure>ignore</on_lockfailure>
<cputune>
<vcpupin vcpu="0" cpuset="0-3"/>
</cputune>
</domain>
<domain type="kvm">
<name>foobar</name>
@ -324,4 +327,7 @@
<label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
</seclabel>
<on_lockfailure>ignore</on_lockfailure>
<cputune>
<vcpupin vcpu="0" cpuset="0-3"/>
</cputune>
</domain>

View File

@ -430,6 +430,7 @@ cell0.distances.sibling1.id=1,cell0.distances.sibling1.value=21,\
cell1.distances.sibling0.id=0,cell1.distances.sibling0.value=21,\
cell1.distances.sibling1.id=1,cell1.distances.sibling1.value=10,\
cache.mode=emulate,cache.level=3 \
--cputune vcpupin0.vcpu=0,vcpupin0.cpuset=0-3 \
--metadata title=my-title,description=my-description,uuid=00000000-1111-2222-3333-444444444444 \
--boot cdrom,fd,hd,network,menu=off,loader=/foo/bar \
--idmap uid_start=0,uid_target=1000,uid_count=10,gid_start=0,gid_target=1000,gid_count=10 \

View File

@ -50,6 +50,7 @@ from virtinst.domainmemorybacking import DomainMemorybacking
from virtinst.domainresource import DomainResource
from virtinst.clock import Clock
from virtinst.cpu import CPU, CPUFeature
from virtinst.cputune import CPUTune
from virtinst.seclabel import Seclabel
from virtinst.pm import PM
from virtinst.idmap import IdMap

View File

@ -39,6 +39,7 @@ from virtcli import CLIConfig
from . import util
from .clock import Clock
from .cpu import CPU
from .cputune import CPUTune
from .deviceaudio import VirtualAudio
from .devicechar import (VirtualChannelDevice, VirtualConsoleDevice,
VirtualSerialDevice, VirtualParallelDevice)
@ -717,6 +718,8 @@ def add_device_options(devg, sound_back_compat=False):
def add_guest_xml_options(geng):
geng.add_argument("--security", action="append",
help=_("Set domain security driver configuration."))
geng.add_argument("--cputune",
help=_("Tune CPU parameters for the domain process."))
geng.add_argument("--numatune",
help=_("Tune NUMA policy for the domain process."))
geng.add_argument("--memtune", action="append",
@ -1562,6 +1565,31 @@ ParserCPU.add_arg("mode", "cache.mode", find_inst_cb=ParserCPU.set_l3_cache_cb)
ParserCPU.add_arg("level", "cache.level", find_inst_cb=ParserCPU.set_l3_cache_cb)
#####################
# --cputune parsing #
#####################
class ParserCPUTune(VirtCLIParser):
cli_arg_name = "cputune"
objclass = CPUTune
remove_first = "model"
stub_none = False
def vcpu_find_inst_cb(self, *args, **kwargs):
cliarg = "vcpupin" # vcpupin[0-9]*
objpropname = "vcpus"
objaddfn = "add_vcpu"
cb = self._make_find_inst_cb(cliarg, objpropname, objaddfn)
return cb(*args, **kwargs)
_register_virt_parser(ParserCPUTune)
# Options for CPU.vcpus config
ParserCPUTune.add_arg("vcpu", "vcpupin[0-9]*.vcpu",
find_inst_cb=ParserCPUTune.vcpu_find_inst_cb)
ParserCPUTune.add_arg("cpuset", "vcpupin[0-9]*.cpuset", can_comma=True,
find_inst_cb=ParserCPUTune.vcpu_find_inst_cb)
###################
# --vcpus parsing #
###################

40
virtinst/cputune.py Normal file
View File

@ -0,0 +1,40 @@
#
# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.
from .xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty
class _VCPUPin(XMLBuilder):
"""
Class for generating <cputune> child <vcpupin> XML
"""
_XML_ROOT_NAME = "vcpupin"
_XML_PROP_ORDER = ["vcpu", "cpuset"]
vcpu = XMLProperty("./@vcpu", is_int=True)
cpuset = XMLProperty("./@cpuset")
class CPUTune(XMLBuilder):
"""
Class for generating <cpu> XML
"""
_XML_ROOT_NAME = "cputune"
vcpus = XMLChildProperty(_VCPUPin)
def add_vcpu(self):
obj = _VCPUPin(self.conn)
self.add_child(obj)
return obj

View File

@ -31,6 +31,7 @@ from . import support
from .osdict import OSDB
from .clock import Clock
from .cpu import CPU
from .cputune import CPUTune
from .device import VirtualDevice
from .deviceaudio import VirtualAudio
from .devicechar import VirtualChannelDevice, VirtualConsoleDevice
@ -210,6 +211,7 @@ class Guest(XMLBuilder):
features = XMLChildProperty(DomainFeatures, is_single=True)
clock = XMLChildProperty(Clock, is_single=True)
cpu = XMLChildProperty(CPU, is_single=True)
cputune = XMLChildProperty(CPUTune, is_single=True)
numatune = XMLChildProperty(DomainNumatune, is_single=True)
pm = XMLChildProperty(PM, is_single=True)
blkiotune = XMLChildProperty(DomainBlkiotune, is_single=True)