Skip to content

Commit

Permalink
Change cpuType map value to string pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed May 5, 2024
1 parent 8bfb214 commit 7aa660e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
13 changes: 5 additions & 8 deletions examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
24 changes: 12 additions & 12 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type (
VMType = string
)

type CPUType = map[Arch]string
type CPUType = map[Arch]*string

const (
LINUX OS = "Linux"
Expand Down
2 changes: 1 addition & 1 deletion pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/vz/vz_driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/wsl2/wsl_driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 7aa660e

Please sign in to comment.