Allow specification of cpuset (#923)

Allows the pinning of vcpus to physical cpus.
This commit is contained in:
Quinten Johnson 2020-04-29 13:08:01 -05:00 committed by GitHub
parent 398258e306
commit 60ef4b03d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 3 deletions

View File

@ -297,12 +297,14 @@ end
Libvirt](https://libvirt.org/formatdomain.html#elementsNICSModel).
* `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
* `cpus` - Number of virtual cpus. Defaults to 1 if not set.
* `cpuset` - Physical cpus to which the vcpus can be pinned. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPUAllocation).
* `cputopology` - Number of CPU sockets, cores and threads running per core. All fields of `:sockets`, `:cores` and `:threads` are mandatory, `cpus` domain option must be present and must be equal to total count of **sockets * cores * threads**. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPU).
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.cpus = 4
libvirt.cpuset = '1-4,^3,6'
libvirt.cputopology :sockets => '2', :cores => '2', :threads => '1'
end
end

View File

@ -33,6 +33,7 @@ module VagrantPlugins
@name = env[:domain_name]
@uuid = config.uuid
@cpus = config.cpus.to_i
@cpuset = config.cpuset
@cpu_features = config.cpu_features
@cpu_topology = config.cpu_topology
@features = config.features
@ -189,6 +190,9 @@ module VagrantPlugins
env[:ui].info(" -- Forced UUID: #{@uuid}") if @uuid != ''
env[:ui].info(" -- Domain type: #{@domain_type}")
env[:ui].info(" -- Cpus: #{@cpus}")
unless @cpuset.nil?
env[:ui].info(" -- Cpuset: #{@cpuset}")
end
if not @cpu_topology.empty?
env[:ui].info(" -- CPU topology: sockets=#{@cpu_topology[:sockets]}, cores=#{@cpu_topology[:cores]}, threads=#{@cpu_topology[:threads]}")
end

View File

@ -68,7 +68,7 @@ module VagrantPlugins
end
# vCpu count
if config.cpus.to_i != libvirt_domain.vcpus.length
if config.cpus.to_i != libvirt_domain.num_vcpus(0)
descr_changed = true
REXML::XPath.first(xml_descr, '/domain/vcpu').text = config.cpus
end

View File

@ -72,6 +72,7 @@ module VagrantPlugins
attr_accessor :memory_backing
attr_accessor :channel
attr_accessor :cpus
attr_accessor :cpuset
attr_accessor :cpu_mode
attr_accessor :cpu_model
attr_accessor :cpu_fallback
@ -195,6 +196,7 @@ module VagrantPlugins
@memory = UNSET_VALUE
@memory_backing = UNSET_VALUE
@cpus = UNSET_VALUE
@cpuset = UNSET_VALUE
@cpu_mode = UNSET_VALUE
@cpu_model = UNSET_VALUE
@cpu_fallback = UNSET_VALUE
@ -672,6 +674,7 @@ module VagrantPlugins
@memory = 512 if @memory == UNSET_VALUE
@memory_backing = [] if @memory_backing == UNSET_VALUE
@cpus = 1 if @cpus == UNSET_VALUE
@cpuset = nil if @cpuset == UNSET_VALUE
@cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
@cpu_model = if (@cpu_model == UNSET_VALUE) && (@cpu_mode == 'custom')
'qemu64'

View File

@ -2,7 +2,7 @@
<name><%= @name %></name>
<uuid><%= @uuid %></uuid>
<memory><%= @memory_size %></memory>
<vcpu><%= @cpus %></vcpu>
<vcpu<% if @cpuset %> cpuset='<%= @cpuset %>'<% end %>><%= @cpus %></vcpu>
<cpu mode='<%= @cpu_mode %>'>

View File

@ -2,7 +2,7 @@
<name></name>
<uuid></uuid>
<memory></memory>
<vcpu>1</vcpu>
<vcpu cpuset='1-4,^3,6'>1</vcpu>
<cpu mode='custom'>

View File

@ -76,6 +76,7 @@ describe 'templates/domain' do
domain.qemuargs(value: '-device')
domain.qemuargs(value: 'dummy-device')
domain.cpuset = '1-4,^3,6'
end
let(:test_file) { 'domain_all_settings.xml' }
it 'renders template' do