mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-14 23:55:49 +00:00
Merge pull request #585 from Pennyzct/smp
qemu: refactor maximum vcpus supported in aarch64
This commit is contained in:
commit
2f7a60abfb
@ -107,8 +107,22 @@ func getGuestGICVersion() (version string) {
|
|||||||
return "host"
|
return "host"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//In qemu, maximum number of vCPUs depends on the GIC version, or on how
|
||||||
|
//many redistributors we can fit into the memory map.
|
||||||
|
//related codes are under github.com/qemu/qemu/hw/arm/virt.c(Line 135 and 1306 in stable-2.11)
|
||||||
|
//for now, qemu only supports v2 and v3, we treat v4 as v3 based on
|
||||||
|
//backward compatibility.
|
||||||
|
var gicList = map[uint32]uint32{
|
||||||
|
uint32(2): uint32(8),
|
||||||
|
uint32(3): uint32(123),
|
||||||
|
uint32(4): uint32(123),
|
||||||
|
}
|
||||||
|
|
||||||
// MaxQemuVCPUs returns the maximum number of vCPUs supported
|
// MaxQemuVCPUs returns the maximum number of vCPUs supported
|
||||||
func MaxQemuVCPUs() uint32 {
|
func MaxQemuVCPUs() uint32 {
|
||||||
|
if hostGICVersion != 0 {
|
||||||
|
return gicList[hostGICVersion]
|
||||||
|
}
|
||||||
return uint32(runtime.NumCPU())
|
return uint32(runtime.NumCPU())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,10 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
govmmQemu "github.com/intel/govmm/qemu"
|
govmmQemu "github.com/intel/govmm/qemu"
|
||||||
@ -50,3 +54,52 @@ func TestQemuArm64MemoryTopology(t *testing.T) {
|
|||||||
m := arm64.memoryTopology(mem, hostMem)
|
m := arm64.memoryTopology(mem, hostMem)
|
||||||
assert.Equal(expectedMemory, m)
|
assert.Equal(expectedMemory, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMaxQemuVCPUs(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
type testData struct {
|
||||||
|
contents string
|
||||||
|
expectedResult uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
data := []testData{
|
||||||
|
{"", uint32(runtime.NumCPU())},
|
||||||
|
{" 1: 0 0 GICv2 25 Level vgic \n", uint32(8)},
|
||||||
|
{" 1: 0 0 GICv3 25 Level vgic \n", uint32(123)},
|
||||||
|
{" 1: 0 0 GICv4 25 Level vgic \n", uint32(123)},
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
savedGicProfile := gicProfile
|
||||||
|
|
||||||
|
testGicProfile := filepath.Join(tmpdir, "interrupts")
|
||||||
|
|
||||||
|
// override
|
||||||
|
gicProfile = testGicProfile
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
gicProfile = savedGicProfile
|
||||||
|
}()
|
||||||
|
|
||||||
|
savedHostGICVersion := hostGICVersion
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
hostGICVersion = savedHostGICVersion
|
||||||
|
}()
|
||||||
|
|
||||||
|
for _, d := range data {
|
||||||
|
err := ioutil.WriteFile(gicProfile, []byte(d.contents), os.FileMode(0640))
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
hostGICVersion = getHostGICVersion()
|
||||||
|
vCPUs := MaxQemuVCPUs()
|
||||||
|
|
||||||
|
assert.Equal(d.expectedResult, vCPUs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user