diff --git a/examples/default.yaml b/examples/default.yaml index 788b414f1616..bc188d7bd2e7 100644 --- a/examples/default.yaml +++ b/examples/default.yaml @@ -252,15 +252,12 @@ containerd: # Specify desired QEMU CPU type for each arch. # You can see what options are available for host emulation with: `qemu-system-$(arch) -cpu help`. # Setting of instructions is supported like this: "qemu64,+ssse3". +# 🟢 Builtin default: hard-coded arch map with type (see the output of `limactl info | jq .defaultTemplate.cpuType`) cpuType: - # 🟢 Builtin default: "cortex-a72" (or "host" when running on aarch64 host) - aarch64: "" - # 🟢 Builtin default: "cortex-a7" (or "host" when running on armv7l host) - armv7l: "" - # 🟢 Builtin default: "qemu64" (or "host,-pdpe1gb" when running on x86_64 host) - x86_64: "" - # 🟢 Builtin default: "rv64" (or "host" when running on riscv64 host) - riscv64: "" + # aarch64: "cortex-a72" # (or "host" when running on aarch64 host) + # armv7l: "cortex-a7" # (or "host" when running on armv7l host) + # riscv64: "rv64" # (or "host" when running on riscv64 host) + # x86_64: "qemu64" # (or "host,-pdpe1gb" when running on x86_64 host) rosetta: # Enable Rosetta for Linux (EXPERIMENTAL). diff --git a/pkg/limayaml/defaults.go b/pkg/limayaml/defaults.go index 209d0af9eddb..823564193f2d 100644 --- a/pkg/limayaml/defaults.go +++ b/pkg/limayaml/defaults.go @@ -39,28 +39,28 @@ const ( var IPv4loopback1 = net.IPv4(127, 0, 0, 1) func defaultCPUType() CPUType { - cpuType := map[Arch]string{ - AARCH64: "cortex-a72", - ARMV7L: "cortex-a7", + cpuType := map[Arch]*string{ + AARCH64: ptr.Of("cortex-a72"), + ARMV7L: ptr.Of("cortex-a7"), // Since https://github.com/lima-vm/lima/pull/494, we use qemu64 cpu for better emulation of x86_64. - X8664: "qemu64", - RISCV64: "rv64", // FIXME: what is the right choice for riscv64? + X8664: ptr.Of("qemu64"), + RISCV64: ptr.Of("rv64"), // FIXME: what is the right choice for riscv64? } for arch := range cpuType { if IsNativeArch(arch) && IsAccelOS() { if HasHostCPU() { - cpuType[arch] = "host" + cpuType[arch] = ptr.Of("host") } else if HasMaxCPU() { - cpuType[arch] = "max" + cpuType[arch] = ptr.Of("max") } } if arch == X8664 && runtime.GOOS == "darwin" { - switch cpuType[arch] { + switch *cpuType[arch] { case "host", "max": // Disable pdpe1gb on Intel Mac // https://github.com/lima-vm/lima/issues/1485 // https://stackoverflow.com/a/72863744/5167443 - cpuType[arch] += ",-pdpe1gb" + *cpuType[arch] += ",-pdpe1gb" } } } @@ -217,19 +217,19 @@ func FillDefault(y, d, o *LimaYAML, filePath string) { cpuType := defaultCPUType() var overrideCPUType bool for k, v := range d.CPUType { - if len(v) > 0 { + if v != nil && len(*v) > 0 { overrideCPUType = true cpuType[k] = v } } for k, v := range y.CPUType { - if len(v) > 0 { + if v != nil && len(*v) > 0 { overrideCPUType = true cpuType[k] = v } } for k, v := range o.CPUType { - if len(v) > 0 { + if v != nil && len(*v) > 0 { overrideCPUType = true cpuType[k] = v } diff --git a/pkg/limayaml/defaults_test.go b/pkg/limayaml/defaults_test.go index 1d4a5c37103b..742773181654 100644 --- a/pkg/limayaml/defaults_test.go +++ b/pkg/limayaml/defaults_test.go @@ -281,10 +281,10 @@ func TestFillDefault(t *testing.T) { OS: ptr.Of("unknown"), Arch: ptr.Of("unknown"), CPUType: CPUType{ - AARCH64: "arm64", - ARMV7L: "armhf", - X8664: "amd64", - RISCV64: "riscv64", + AARCH64: ptr.Of("arm64"), + ARMV7L: ptr.Of("armhf"), + X8664: ptr.Of("amd64"), + RISCV64: ptr.Of("riscv64"), }, CPUs: ptr.Of(7), Memory: ptr.Of("5GiB"), @@ -470,10 +470,10 @@ func TestFillDefault(t *testing.T) { OS: ptr.Of(LINUX), Arch: ptr.Of(arch), CPUType: CPUType{ - AARCH64: "uber-arm", - ARMV7L: "armv8", - X8664: "pentium", - RISCV64: "sifive-u54", + AARCH64: ptr.Of("uber-arm"), + ARMV7L: ptr.Of("armv8"), + X8664: ptr.Of("pentium"), + RISCV64: ptr.Of("sifive-u54"), }, CPUs: ptr.Of(12), Memory: ptr.Of("7GiB"), diff --git a/pkg/limayaml/limayaml.go b/pkg/limayaml/limayaml.go index d1c890022cd0..89d72bf550e1 100644 --- a/pkg/limayaml/limayaml.go +++ b/pkg/limayaml/limayaml.go @@ -51,7 +51,7 @@ type ( VMType = string ) -type CPUType = map[Arch]string +type CPUType = map[Arch]*string const ( LINUX OS = "Linux" diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go index 33657c8606ba..9179def85be1 100644 --- a/pkg/qemu/qemu.go +++ b/pkg/qemu/qemu.go @@ -511,7 +511,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er } // CPU - cpu := y.CPUType[*y.Arch] + cpu := *y.CPUType[*y.Arch] if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" { switch { case strings.HasPrefix(cpu, "host"), strings.HasPrefix(cpu, "max"): diff --git a/pkg/store/instance.go b/pkg/store/instance.go index e01610320c87..102f05d3b0da 100644 --- a/pkg/store/instance.go +++ b/pkg/store/instance.go @@ -95,7 +95,7 @@ func Inspect(instName string) (*Instance, error) { inst.Config = y inst.Arch = *y.Arch inst.VMType = *y.VMType - inst.CPUType = y.CPUType[*y.Arch] + inst.CPUType = *y.CPUType[*y.Arch] inst.SSHAddress = "127.0.0.1" inst.SSHLocalPort = *y.SSH.LocalPort // maybe 0 inst.SSHConfigFile = filepath.Join(instDir, filenames.SSHConfig) diff --git a/pkg/vz/vz_driver_darwin.go b/pkg/vz/vz_driver_darwin.go index a92fe86744a1..06a91a67918d 100644 --- a/pkg/vz/vz_driver_darwin.go +++ b/pkg/vz/vz_driver_darwin.go @@ -98,8 +98,8 @@ func (l *LimaVzDriver) Validate() error { } for k, v := range l.Yaml.CPUType { - if v != "" { - logrus.Warnf("vmType %s: ignoring cpuType[%q]: %q", *l.Yaml.VMType, k, v) + if v != nil { + logrus.Warnf("vmType %s: ignoring cpuType[%q]: %q", *l.Yaml.VMType, k, *v) } } diff --git a/pkg/wsl2/wsl_driver_windows.go b/pkg/wsl2/wsl_driver_windows.go index 13b2c4b93858..4189cc04fdbc 100644 --- a/pkg/wsl2/wsl_driver_windows.go +++ b/pkg/wsl2/wsl_driver_windows.go @@ -64,8 +64,8 @@ func (l *LimaWslDriver) Validate() error { } for k, v := range l.Yaml.CPUType { - if v != "" { - logrus.Warnf("Ignoring: vmType %s: cpuType[%q]: %q", *l.Yaml.VMType, k, v) + if v != nil { + logrus.Warnf("Ignoring: vmType %s: cpuType[%q]: %q", *l.Yaml.VMType, k, *v) } }