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

Commit a355cc1

Browse files
committed
AARCH64 support use host memory size and cpu number as maxmem and maxcpus
Signed-off-by: Hui Zhu <[email protected]>
1 parent f1de9bf commit a355cc1

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

Diff for: hypervisor/qemu/qemu_amd64.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ package qemu
44

55
import (
66
"fmt"
7-
"os"
8-
"runtime"
9-
"syscall"
10-
117
"github.com/golang/glog"
12-
"github.com/hyperhq/hypercontainer-utils/hlog"
138
"github.com/hyperhq/runv/hypervisor"
9+
"os"
1410
)
1511

1612
const (
1713
QEMU_SYSTEM_EXE = "qemu-system-x86_64"
1814
X86_64_CONFIG_NR_CPUS = 64
1915
)
2016

21-
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
17+
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
2218
if ctx.Boot == nil {
2319
ctx.Boot = &hypervisor.BootConfig{
2420
CPU: 1,
@@ -30,15 +26,6 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
3026
boot := ctx.Boot
3127
qc.cpus = boot.CPU
3228

33-
maxmem := hypervisor.DefaultMaxMem
34-
var sysInfo syscall.Sysinfo_t
35-
err := syscall.Sysinfo(&sysInfo)
36-
if err == nil {
37-
maxmem = int(sysInfo.Totalram / 1024 / 1024)
38-
} else {
39-
ctx.Log(hlog.DEBUG, "syscall.Sysinfo got error %v, use hypervisor.DefaultMaxMem", err)
40-
}
41-
maxcpus := runtime.NumCPU()
4229
if maxcpus > X86_64_CONFIG_NR_CPUS {
4330
maxcpus = X86_64_CONFIG_NR_CPUS
4431
}

Diff for: hypervisor/qemu/qemu_arm64.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
)
1212

1313
const (
14-
QEMU_SYSTEM_EXE = "qemu-system-aarch64"
15-
VM_MIN_MEMORY_SIZE = 128
14+
QEMU_SYSTEM_EXE = "qemu-system-aarch64"
15+
VM_MIN_MEMORY_SIZE = 128
16+
AARCH64_CONFIG_NR_CPUS = 8
1617
)
1718

18-
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
19+
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
1920
if ctx.Boot == nil {
2021
ctx.Boot = &hypervisor.BootConfig{
2122
CPU: 1,
@@ -27,13 +28,17 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
2728
boot := ctx.Boot
2829
qc.cpus = boot.CPU
2930

31+
if maxcpus > AARCH64_CONFIG_NR_CPUS {
32+
maxcpus = AARCH64_CONFIG_NR_CPUS
33+
}
34+
3035
// Currently the default memory size is fixed to 128 MiB.
3136
if boot.Memory < VM_MIN_MEMORY_SIZE {
3237
boot.Memory = VM_MIN_MEMORY_SIZE
3338
}
3439

35-
memParams := fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, hypervisor.DefaultMaxMem)
36-
cpuParams := fmt.Sprintf("cpus=%d,maxcpus=%d", boot.CPU, hypervisor.DefaultMaxCpus)
40+
memParams := fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, maxmem)
41+
cpuParams := fmt.Sprintf("cpus=%d,maxcpus=%d", boot.CPU, maxcpus)
3742

3843
params := []string{"-machine", "virt,accel=kvm,gic-version=host,usb=off", "-global", "kvm-pit.lost_tick_policy=discard", "-cpu", "host"}
3944
if _, err := os.Stat("/dev/kvm"); os.IsNotExist(err) {

Diff for: hypervisor/qemu/qemu_ppc64le.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const (
1414
VM_MIN_MEMORY_SIZE = 256 // On ppc64le the minimum memory size of a VM is 256 MiB
1515
)
1616

17-
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
17+
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
1818
if ctx.Boot == nil {
1919
ctx.Boot = &hypervisor.BootConfig{
2020
CPU: 1,

Diff for: hypervisor/qemu/qemu_process.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import (
99
"io"
1010
"os"
1111
"os/exec"
12+
"runtime"
1213
"strings"
14+
"syscall"
1315
"time"
1416

1517
"github.com/golang/glog"
18+
"github.com/hyperhq/hypercontainer-utils/hlog"
1619
"github.com/hyperhq/runv/hypervisor"
1720
)
1821

@@ -126,7 +129,17 @@ func launchQemu(qc *QemuContext, ctx *hypervisor.VmContext) {
126129
return
127130
}
128131

129-
args := qc.arguments(ctx)
132+
maxmem := hypervisor.DefaultMaxMem
133+
var sysInfo syscall.Sysinfo_t
134+
err := syscall.Sysinfo(&sysInfo)
135+
if err == nil {
136+
maxmem = int(sysInfo.Totalram / 1024 / 1024)
137+
} else {
138+
ctx.Log(hlog.ERROR, "syscall.Sysinfo got error %v, use hypervisor.DefaultMaxMem", err)
139+
}
140+
maxcpus := runtime.NumCPU()
141+
142+
args := qc.arguments(ctx, maxmem, maxcpus)
130143
args = append(args, "-daemonize", "-pidfile", qc.qemuPidFile, "-D", qc.qemuLogFile.Name)
131144
if ctx.GDBTCPPort != 0 {
132145
args = append(args, "-gdb", fmt.Sprintf("tcp::%d", ctx.GDBTCPPort))
@@ -150,7 +163,7 @@ func launchQemu(qc *QemuContext, ctx *hypervisor.VmContext) {
150163
cmd.Stdout = stdout
151164
cmd.Stderr = stderr
152165

153-
err := cmd.Run()
166+
err = cmd.Run()
154167

155168
if stdout.Len() != 0 {
156169
glog.V(1).Info(stdout.String())

Diff for: hypervisor/qemu/qemu_s390x.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const (
1313
QEMU_SYSTEM_EXE = "qemu-system-s390x"
1414
)
1515

16-
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
16+
func (qc *QemuContext) arguments(ctx *hypervisor.VmContext, maxmem, maxcpus int) []string {
1717
if ctx.Boot == nil {
1818
ctx.Boot = &hypervisor.BootConfig{
1919
CPU: 1,

0 commit comments

Comments
 (0)