Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
config: don't exceed the number of physical cores
Browse files Browse the repository at this point in the history
the maximum number of vCPUs per VM shouldn't not exceed
the number of physical cores, otherwise we could face issues
with KVM and other architectures

fixes #1028

Signed-off-by: Julio Montes <[email protected]>
  • Loading branch information
Julio Montes committed Feb 23, 2018
1 parent 7067e6d commit f6da537
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
9 changes: 4 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,14 @@ func (h hypervisor) machineType() string {
}

func (h hypervisor) defaultVCPUs() uint32 {
if h.DefaultVCPUs < 0 {
return uint32(goruntime.NumCPU())
numCPUs := goruntime.NumCPU()

if h.DefaultVCPUs < 0 || h.DefaultVCPUs > int32(numCPUs) {
return uint32(numCPUs)
}
if h.DefaultVCPUs == 0 { // or unspecified
return defaultVCPUCount
}
if h.DefaultVCPUs > 255 { // qemu supports max 255
return 255
}

return uint32(h.DefaultVCPUs)
}
Expand Down
8 changes: 4 additions & 4 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ firmware = "@FIRMWAREPATH@"
machine_accelerators="@MACHINEACCELERATORS@"

# Default number of vCPUs per POD/VM:
# unspecified or 0 --> will be set to @DEFVCPUS@
# < 0 --> will be set to the actual number of physical cores
# > 0 <= 255 --> will be set to the specified number
# > 255 --> will be set to 255
# unspecified or 0 --> will be set to @DEFVCPUS@
# < 0 --> will be set to the actual number of physical cores
# > 0 <= number of physical cores --> will be set to the specified number
# > number of physical cores --> will be set to the actual number of physical cores
default_vcpus = -1


Expand Down
8 changes: 4 additions & 4 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,9 @@ func TestHypervisorDefaults(t *testing.T) {
h.DefaultVCPUs = 2
assert.Equal(h.defaultVCPUs(), uint32(2), "default vCPU number is wrong")

// qemu supports max 255
h.DefaultVCPUs = 8086
assert.Equal(h.defaultVCPUs(), uint32(255), "default vCPU number is wrong")
numCPUs := goruntime.NumCPU()
h.DefaultVCPUs = int32(numCPUs) + 1
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")

h.DefaultMemSz = 1024
assert.Equal(h.defaultMemSz(), uint32(1024), "default memory size is wrong")
Expand Down Expand Up @@ -1017,7 +1017,7 @@ func TestUpdateRuntimeConfiguration(t *testing.T) {
func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
assert := assert.New(t)

vcpus := uint(8)
vcpus := uint(2)
mem := uint(2048)

config := oci.RuntimeConfig{}
Expand Down

0 comments on commit f6da537

Please sign in to comment.