diff --git a/man/virt-install.pod b/man/virt-install.pod index 349e4e6c0..e75f517f1 100644 --- a/man/virt-install.pod +++ b/man/virt-install.pod @@ -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 +=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 + =item B<--security> type=TYPE[,label=LABEL][,relabel=yes|no] Configure domain security driver settings. Type can be either 'static' or diff --git a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml index 3b9210f5a..b25d8c60b 100644 --- a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml +++ b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml @@ -159,6 +159,9 @@ ignore + + + foobar @@ -324,4 +327,7 @@ ignore + + + diff --git a/tests/clitest.py b/tests/clitest.py index a7d38b6d9..18513597a 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -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 \ diff --git a/virtinst/__init__.py b/virtinst/__init__.py index 175303a57..eb3ec9b37 100644 --- a/virtinst/__init__.py +++ b/virtinst/__init__.py @@ -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 diff --git a/virtinst/cli.py b/virtinst/cli.py index 50b366e6c..3d3ac0ac4 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -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 # ################### diff --git a/virtinst/cputune.py b/virtinst/cputune.py new file mode 100644 index 000000000..df0c38899 --- /dev/null +++ b/virtinst/cputune.py @@ -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 . + +from .xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty + + +class _VCPUPin(XMLBuilder): + """ + Class for generating child 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 XML + """ + _XML_ROOT_NAME = "cputune" + vcpus = XMLChildProperty(_VCPUPin) + def add_vcpu(self): + obj = _VCPUPin(self.conn) + self.add_child(obj) + return obj diff --git a/virtinst/guest.py b/virtinst/guest.py index 903ee188d..32acd5210 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -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)