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

Commit

Permalink
qemu: arm64: Set defaultGICVersion to 3 to limit the max vCPU number
Browse files Browse the repository at this point in the history
After removing dectect of host gic version, we need to limit the max vCPU
in different cases.

Given that in most cases, Kata is running on gicv3 host, set it as default
value. If the user really want to run Kata on gicv2 host, he/she need to
set default_maxvcpus in toml file to 8 instead of 0.

In summary, If the user uses host gicv3 gicv4, everything is fine
            If the user uses host gicv2, set default_maxvcpus=8

Fixes: #2614
Signed-off-by: Jia He <[email protected]>
  • Loading branch information
justin-he committed Apr 21, 2020
1 parent 4d4a153 commit ee985a6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 48 deletions.
1 change: 1 addition & 0 deletions cli/config/configuration-fc.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ default_vcpus = 1
# `default_maxvcpus = 8` the memory footprint will be small, but 8 will be the maximum number of
# vCPUs supported by the SB/VM. In general, we recommend that you do not edit this variable,
# unless you know what are you doing.
# NOTICE: on arm platform with gicv2 interrupt controller, set it to 8.
default_maxvcpus = @DEFMAXVCPUS@

# Bridges can be used to hot plug devices.
Expand Down
1 change: 1 addition & 0 deletions cli/config/configuration-qemu-virtiofs.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ default_vcpus = 1
# `default_maxvcpus = 8` the memory footprint will be small, but 8 will be the maximum number of
# vCPUs supported by the SB/VM. In general, we recommend that you do not edit this variable,
# unless you know what are you doing.
# NOTICE: on arm platform with gicv2 interrupt controller, set it to 8.
default_maxvcpus = @DEFMAXVCPUS@

# Bridges can be used to hot plug devices.
Expand Down
1 change: 1 addition & 0 deletions cli/config/configuration-qemu.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ default_vcpus = 1
# `default_maxvcpus = 8` the memory footprint will be small, but 8 will be the maximum number of
# vCPUs supported by the SB/VM. In general, we recommend that you do not edit this variable,
# unless you know what are you doing.
# NOTICE: on arm platform with gicv2 interrupt controller, set it to 8.
default_maxvcpus = @DEFMAXVCPUS@

# Bridges can be used to hot plug devices.
Expand Down
5 changes: 3 additions & 2 deletions virtcontainers/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package virtcontainers

import (
"context"
"runtime"
"time"

govmmQemu "github.com/intel/govmm/qemu"
Expand All @@ -26,6 +25,8 @@ const qmpMigrationWaitTimeout = 10 * time.Second

const defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=host"

var defaultGICVersion = uint32(3)

var qemuPaths = map[string]string{
QemuVirt: defaultQemuPath,
}
Expand Down Expand Up @@ -56,7 +57,7 @@ var gicList = map[uint32]uint32{

// MaxQemuVCPUs returns the maximum number of vCPUs supported
func MaxQemuVCPUs() uint32 {
return uint32(runtime.NumCPU())
return gicList[defaultGICVersion]
}

func newQemuArch(config HypervisorConfig) qemuArch {
Expand Down
48 changes: 2 additions & 46 deletions virtcontainers/qemu_arm64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

govmmQemu "github.com/intel/govmm/qemu"
Expand Down Expand Up @@ -57,50 +55,8 @@ func TestQemuArm64MemoryTopology(t *testing.T) {
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)
}
vCPUs := MaxQemuVCPUs()
assert.Equal(uint32(123), vCPUs)
}

func TestQemuArm64AppendBridges(t *testing.T) {
Expand Down

0 comments on commit ee985a6

Please sign in to comment.