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

AARCH64 support use host memory size and cpu number as maxmem and max… #689

Open
wants to merge 1 commit into
base: runv-1.0.y
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions hypervisor/qemu/qemu_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ package qemu
import (
"fmt"
"os"
"runtime"
"syscall"

"github.com/golang/glog"
"github.com/hyperhq/hypercontainer-utils/hlog"
"github.com/hyperhq/runv/hypervisor"
)

Expand All @@ -18,7 +15,7 @@ const (
X86_64_CONFIG_NR_CPUS = 64
)

func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
if ctx.Boot == nil {
ctx.Boot = &hypervisor.BootConfig{
CPU: 1,
Expand All @@ -30,15 +27,6 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
boot := ctx.Boot
qc.cpus = boot.CPU

maxmem := hypervisor.DefaultMaxMem
var sysInfo syscall.Sysinfo_t
err := syscall.Sysinfo(&sysInfo)
if err == nil {
maxmem = int(sysInfo.Totalram / 1024 / 1024)
} else {
ctx.Log(hlog.DEBUG, "syscall.Sysinfo got error %v, use hypervisor.DefaultMaxMem", err)
}
maxcpus := runtime.NumCPU()
if maxcpus > X86_64_CONFIG_NR_CPUS {
maxcpus = X86_64_CONFIG_NR_CPUS
}
Expand Down
15 changes: 10 additions & 5 deletions hypervisor/qemu/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

const (
QEMU_SYSTEM_EXE = "qemu-system-aarch64"
VM_MIN_MEMORY_SIZE = 128
QEMU_SYSTEM_EXE = "qemu-system-aarch64"
VM_MIN_MEMORY_SIZE = 128
AARCH64_CONFIG_NR_CPUS = 8
)

func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
if ctx.Boot == nil {
ctx.Boot = &hypervisor.BootConfig{
CPU: 1,
Expand All @@ -27,13 +28,17 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
boot := ctx.Boot
qc.cpus = boot.CPU

if maxcpus > AARCH64_CONFIG_NR_CPUS {
maxcpus = AARCH64_CONFIG_NR_CPUS
}

// Currently the default memory size is fixed to 128 MiB.
if boot.Memory < VM_MIN_MEMORY_SIZE {
boot.Memory = VM_MIN_MEMORY_SIZE
}

memParams := fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, hypervisor.DefaultMaxMem)
cpuParams := fmt.Sprintf("cpus=%d,maxcpus=%d", boot.CPU, hypervisor.DefaultMaxCpus)
memParams := fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, maxmem)
cpuParams := fmt.Sprintf("cpus=%d,maxcpus=%d", boot.CPU, maxcpus)

params := []string{"-machine", "virt,accel=kvm,gic-version=host,usb=off", "-global", "kvm-pit.lost_tick_policy=discard", "-cpu", "host"}
if _, err := os.Stat("/dev/kvm"); os.IsNotExist(err) {
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/qemu/qemu_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
VM_MIN_MEMORY_SIZE = 256 // On ppc64le the minimum memory size of a VM is 256 MiB
)

func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
if ctx.Boot == nil {
ctx.Boot = &hypervisor.BootConfig{
CPU: 1,
Expand Down
17 changes: 15 additions & 2 deletions hypervisor/qemu/qemu_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
"io"
"os"
"os/exec"
"runtime"
"strings"
"syscall"
"time"

"github.com/golang/glog"
"github.com/hyperhq/hypercontainer-utils/hlog"
"github.com/hyperhq/runv/hypervisor"
)

Expand Down Expand Up @@ -126,7 +129,17 @@ func launchQemu(qc *QemuContext, ctx *hypervisor.VmContext) {
return
}

args := qc.arguments(ctx)
maxmem := hypervisor.DefaultMaxMem
var sysInfo syscall.Sysinfo_t
err := syscall.Sysinfo(&sysInfo)
if err == nil {
maxmem = int(sysInfo.Totalram / 1024 / 1024)
} else {
ctx.Log(hlog.ERROR, "syscall.Sysinfo got error %v, use hypervisor.DefaultMaxMem", err)
}
maxcpus := runtime.NumCPU()

args := qc.arguments(ctx, maxmem, maxcpus)
args = append(args, "-daemonize", "-pidfile", qc.qemuPidFile, "-D", qc.qemuLogFile.Name)
if ctx.GDBTCPPort != 0 {
args = append(args, "-gdb", fmt.Sprintf("tcp::%d", ctx.GDBTCPPort))
Expand All @@ -150,7 +163,7 @@ func launchQemu(qc *QemuContext, ctx *hypervisor.VmContext) {
cmd.Stdout = stdout
cmd.Stderr = stderr

err := cmd.Run()
err = cmd.Run()

if stdout.Len() != 0 {
glog.V(1).Info(stdout.String())
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/qemu/qemu_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
QEMU_SYSTEM_EXE = "qemu-system-s390x"
)

func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
if ctx.Boot == nil {
ctx.Boot = &hypervisor.BootConfig{
CPU: 1,
Expand Down