mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-21 08:14:19 +01:00
runtime: current vcpu number should be limited
The physical current vcpu number should not be used directly as the largest vcpu number is limited to defaultMaxQemuVCPUs. Here, a new helper is introduced in pkg/katautils/config.go to get current vcpu number. Fixes: #2809 Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
@@ -307,11 +307,24 @@ func (h hypervisor) GetEntropySource() string {
|
||||
return h.EntropySource
|
||||
}
|
||||
|
||||
// Current cpu number should not larger than defaultMaxVCPUs()
|
||||
func getCurrentCpuNum() uint32 {
|
||||
var cpu uint32
|
||||
h := hypervisor{}
|
||||
|
||||
cpu = uint32(goruntime.NumCPU())
|
||||
if cpu > h.defaultMaxVCPUs() {
|
||||
cpu = h.defaultMaxVCPUs()
|
||||
}
|
||||
|
||||
return cpu
|
||||
}
|
||||
|
||||
func (h hypervisor) defaultVCPUs() uint32 {
|
||||
numCPUs := goruntime.NumCPU()
|
||||
numCPUs := getCurrentCpuNum()
|
||||
|
||||
if h.NumVCPUs < 0 || h.NumVCPUs > int32(numCPUs) {
|
||||
return uint32(numCPUs)
|
||||
return numCPUs
|
||||
}
|
||||
if h.NumVCPUs == 0 { // or unspecified
|
||||
return defaultVCPUCount
|
||||
|
||||
Reference in New Issue
Block a user