Skip to content

Commit

Permalink
qemu: refactor maximum vcpus supported in aarch64
Browse files Browse the repository at this point in the history
on aarch64, we support different gic interrupt controllers.
The maximum number of vCPUs depends on the GIC version, or on how
many redistributors we can fit into the memory map.

Fixes: kata-containers#584

Signed-off-by: Penny Zheng <[email protected]>
igned-off-by: Wei Chen <[email protected]>
  • Loading branch information
Pennyzct committed Aug 15, 2018
1 parent dd2acd2 commit f79e99e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions virtcontainers/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
package virtcontainers

import (
"io/ioutil"
"regexp"
"runtime"

govmmQemu "github.com/intel/govmm/qemu"
"github.com/sirupsen/logrus"
)

type qemuArm64 struct {
Expand Down Expand Up @@ -38,15 +41,41 @@ var kernelRootParams = []Param{
{"root", "/dev/vda1"},
}

// variables rather than consts to allow tests to modify them
var interruptFile = "/proc/interrupts"
//on aarch64, we support different gic interrupt controllers
//maximum number of vCPUs depends on the GIC version, or on how
//many redistributors we can fit into the memory map.
var gicList = map[string]uint32{
"GICv2": uint32(8),
"GICv3": uint32(123),
"GICv4": uint32(123),
}

var supportedQemuMachines = []govmmQemu.Machine{
{
Type: QemuVirt,
Options: defaultQemuMachineOptions,
},
}

// Logger returns a logrus logger appropriate for logging qemu-aarch64 messages
func qemuArmLogger() *logrus.Entry {
return virtLog.WithField("subsystem", "qemu-aarch64")
}

// MaxQemuVCPUs returns the maximum number of vCPUs supported
func MaxQemuVCPUs() uint32 {
bytes, err := ioutil.ReadFile(interruptFile)
if err != nil {
qemuArmLogger().WithError(err).Error("Failed to read /proc/interrrupts")
}
for gicType, vCPUs := range gicList {
pattern := regexp.MustCompile(`\b` + gicType + `\b`)
if pattern.MatchString(string(bytes)) {
return vCPUs
}
}
return uint32(runtime.NumCPU())
}

Expand Down

0 comments on commit f79e99e

Please sign in to comment.