Skip to content

Commit 8522c7a

Browse files
committed
Change cpuType map value to string pointer
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 8bfb214 commit 8522c7a

File tree

8 files changed

+30
-33
lines changed

8 files changed

+30
-33
lines changed

examples/default.yaml

+5-8
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,12 @@ containerd:
252252
# Specify desired QEMU CPU type for each arch.
253253
# You can see what options are available for host emulation with: `qemu-system-$(arch) -cpu help`.
254254
# Setting of instructions is supported like this: "qemu64,+ssse3".
255+
# 🟢 Builtin default: hard-coded arch map with type (see the output of `limactl info | jq .defaultTemplate.cpuType`)
255256
cpuType:
256-
# 🟢 Builtin default: "cortex-a72" (or "host" when running on aarch64 host)
257-
aarch64: ""
258-
# 🟢 Builtin default: "cortex-a7" (or "host" when running on armv7l host)
259-
armv7l: ""
260-
# 🟢 Builtin default: "qemu64" (or "host,-pdpe1gb" when running on x86_64 host)
261-
x86_64: ""
262-
# 🟢 Builtin default: "rv64" (or "host" when running on riscv64 host)
263-
riscv64: ""
257+
# aarch64: "cortex-a72" # (or "host" when running on aarch64 host)
258+
# armv7l: "cortex-a7" # (or "host" when running on armv7l host)
259+
# riscv64: "rv64" # (or "host" when running on riscv64 host)
260+
# x86_64: "qemu64" # (or "host,-pdpe1gb" when running on x86_64 host)
264261

265262
rosetta:
266263
# Enable Rosetta for Linux (EXPERIMENTAL).

pkg/limayaml/defaults.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ const (
3939
var IPv4loopback1 = net.IPv4(127, 0, 0, 1)
4040

4141
func defaultCPUType() CPUType {
42-
cpuType := map[Arch]string{
43-
AARCH64: "cortex-a72",
44-
ARMV7L: "cortex-a7",
42+
cpuType := map[Arch]*string{
43+
AARCH64: ptr.Of("cortex-a72"),
44+
ARMV7L: ptr.Of("cortex-a7"),
4545
// Since https://github.com/lima-vm/lima/pull/494, we use qemu64 cpu for better emulation of x86_64.
46-
X8664: "qemu64",
47-
RISCV64: "rv64", // FIXME: what is the right choice for riscv64?
46+
X8664: ptr.Of("qemu64"),
47+
RISCV64: ptr.Of("rv64"), // FIXME: what is the right choice for riscv64?
4848
}
4949
for arch := range cpuType {
5050
if IsNativeArch(arch) && IsAccelOS() {
5151
if HasHostCPU() {
52-
cpuType[arch] = "host"
52+
cpuType[arch] = ptr.Of("host")
5353
} else if HasMaxCPU() {
54-
cpuType[arch] = "max"
54+
cpuType[arch] = ptr.Of("max")
5555
}
5656
}
5757
if arch == X8664 && runtime.GOOS == "darwin" {
58-
switch cpuType[arch] {
58+
switch *cpuType[arch] {
5959
case "host", "max":
6060
// Disable pdpe1gb on Intel Mac
6161
// https://github.com/lima-vm/lima/issues/1485
6262
// https://stackoverflow.com/a/72863744/5167443
63-
cpuType[arch] += ",-pdpe1gb"
63+
*cpuType[arch] += ",-pdpe1gb"
6464
}
6565
}
6666
}
@@ -217,19 +217,19 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
217217
cpuType := defaultCPUType()
218218
var overrideCPUType bool
219219
for k, v := range d.CPUType {
220-
if len(v) > 0 {
220+
if v != nil && len(*v) > 0 {
221221
overrideCPUType = true
222222
cpuType[k] = v
223223
}
224224
}
225225
for k, v := range y.CPUType {
226-
if len(v) > 0 {
226+
if v != nil && len(*v) > 0 {
227227
overrideCPUType = true
228228
cpuType[k] = v
229229
}
230230
}
231231
for k, v := range o.CPUType {
232-
if len(v) > 0 {
232+
if v != nil && len(*v) > 0 {
233233
overrideCPUType = true
234234
cpuType[k] = v
235235
}

pkg/limayaml/defaults_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ func TestFillDefault(t *testing.T) {
281281
OS: ptr.Of("unknown"),
282282
Arch: ptr.Of("unknown"),
283283
CPUType: CPUType{
284-
AARCH64: "arm64",
285-
ARMV7L: "armhf",
286-
X8664: "amd64",
287-
RISCV64: "riscv64",
284+
AARCH64: ptr.Of("arm64"),
285+
ARMV7L: ptr.Of("armhf"),
286+
X8664: ptr.Of("amd64"),
287+
RISCV64: ptr.Of("riscv64"),
288288
},
289289
CPUs: ptr.Of(7),
290290
Memory: ptr.Of("5GiB"),
@@ -470,10 +470,10 @@ func TestFillDefault(t *testing.T) {
470470
OS: ptr.Of(LINUX),
471471
Arch: ptr.Of(arch),
472472
CPUType: CPUType{
473-
AARCH64: "uber-arm",
474-
ARMV7L: "armv8",
475-
X8664: "pentium",
476-
RISCV64: "sifive-u54",
473+
AARCH64: ptr.Of("uber-arm"),
474+
ARMV7L: ptr.Of("armv8"),
475+
X8664: ptr.Of("pentium"),
476+
RISCV64: ptr.Of("sifive-u54"),
477477
},
478478
CPUs: ptr.Of(12),
479479
Memory: ptr.Of("7GiB"),

pkg/limayaml/limayaml.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type (
5151
VMType = string
5252
)
5353

54-
type CPUType = map[Arch]string
54+
type CPUType = map[Arch]*string
5555

5656
const (
5757
LINUX OS = "Linux"

pkg/qemu/qemu.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
511511
}
512512

513513
// CPU
514-
cpu := y.CPUType[*y.Arch]
514+
cpu := *y.CPUType[*y.Arch]
515515
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
516516
switch {
517517
case strings.HasPrefix(cpu, "host"), strings.HasPrefix(cpu, "max"):

pkg/store/instance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Inspect(instName string) (*Instance, error) {
9595
inst.Config = y
9696
inst.Arch = *y.Arch
9797
inst.VMType = *y.VMType
98-
inst.CPUType = y.CPUType[*y.Arch]
98+
inst.CPUType = *y.CPUType[*y.Arch]
9999
inst.SSHAddress = "127.0.0.1"
100100
inst.SSHLocalPort = *y.SSH.LocalPort // maybe 0
101101
inst.SSHConfigFile = filepath.Join(instDir, filenames.SSHConfig)

pkg/vz/vz_driver_darwin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (l *LimaVzDriver) Validate() error {
9898
}
9999

100100
for k, v := range l.Yaml.CPUType {
101-
if v != "" {
101+
if v != nil {
102102
logrus.Warnf("vmType %s: ignoring cpuType[%q]: %q", *l.Yaml.VMType, k, v)
103103
}
104104
}

pkg/wsl2/wsl_driver_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (l *LimaWslDriver) Validate() error {
6464
}
6565

6666
for k, v := range l.Yaml.CPUType {
67-
if v != "" {
67+
if v != nil {
6868
logrus.Warnf("Ignoring: vmType %s: cpuType[%q]: %q", *l.Yaml.VMType, k, v)
6969
}
7070
}

0 commit comments

Comments
 (0)