cmd/qemu: Better handling of arch

- When executing on aarch64, use it as the default arch
- When selecting aarch64 on a non aarch64 system set the
  CPU flag to a default value (not 'host').

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-08-04 13:27:36 +01:00
parent d7caf92708
commit 7c3f9690d5

View File

@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
@ -54,6 +55,19 @@ const (
qemuNetworkingDefault = qemuNetworkingUser
)
var (
defaultArch string
)
func init() {
switch runtime.GOARCH {
case "arm64":
defaultArch = "aarch64"
case "amd64":
defaultArch = "x86_64"
}
}
func haveKVM() bool {
_, err := os.Stat("/dev/kvm")
return !os.IsNotExist(err)
@ -123,7 +137,7 @@ func runQemu(args []string) {
// VM configuration
enableKVM := flags.Bool("kvm", haveKVM(), "Enable KVM acceleration")
arch := flags.String("arch", "x86_64", "Type of architecture to use, e.g. x86_64, aarch64")
arch := flags.String("arch", defaultArch, "Type of architecture to use, e.g. x86_64, aarch64")
cpus := flags.String("cpus", "1", "Number of CPUs")
mem := flags.String("mem", "1024", "Amount of memory in MB")
@ -459,7 +473,11 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
// Need to specify the vcpu type when running qemu on arm64 platform, for security reason,
// the vcpu should be "host" instead of other names such as "cortex-a53"...
if config.Arch == "aarch64" {
qemuArgs = append(qemuArgs, "-cpu", "host")
if runtime.GOARCH == "arm64" {
qemuArgs = append(qemuArgs, "-cpu", "host")
} else {
qemuArgs = append(qemuArgs, "-cpu", "cortex-a57")
}
}
if config.KVM {