Skip to content

Commit

Permalink
qemu: avoid Property 'host-arm-cpu.sme' not found
Browse files Browse the repository at this point in the history
Close issue 3032

SME is available since Apple M4 running macOS 15.2.
However, QEMU is not ready to handle SME yet.
- https://gitlab.com/qemu-project/qemu/-/issues/2665
- https://gitlab.com/qemu-project/qemu/-/issues/2721

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Dec 24, 2024
1 parent 5fb9353 commit 0138e9b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
42 changes: 39 additions & 3 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"slices"
"strconv"
"strings"
"sync"
"text/template"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -1173,9 +1174,44 @@ func IsAccelOS() bool {
return false
}

var (
hasSMEDarwin bool
hasSMEDarwinOnce sync.Once
)

func init() {
hasSMEDarwinOnce.Do(func() {
hasSMEDarwin = hasSMEDarwinFn()
})
}

func hasSMEDarwinFn() bool {
if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
return false
}
// golang.org/x/sys/cpu does not support inspecting the availability of SME yet

Check failure on line 1192 in pkg/limayaml/defaults.go

View workflow job for this annotation

GitHub Actions / Spell check

SME ==> SAME, SEME, SOME, SMS
s, err := osutil.Sysctl("hw.optional.arm.FEAT_SME")
if err != nil {
logrus.WithError(err).Debug("failed to check hw.optional.arm.FEAT_SME")
}
return s == "1"
}

func HasHostCPU() bool {
switch runtime.GOOS {
case "darwin", "linux":
case "darwin":
if hasSMEDarwin {
// SME is available since Apple M4 running macOS 15.2.

Check failure on line 1204 in pkg/limayaml/defaults.go

View workflow job for this annotation

GitHub Actions / Spell check

SME ==> SAME, SEME, SOME, SMS
//
// However, QEMU is not ready to handle SME yet.

Check failure on line 1206 in pkg/limayaml/defaults.go

View workflow job for this annotation

GitHub Actions / Spell check

SME ==> SAME, SEME, SOME, SMS
//
// https://github.com/lima-vm/lima/issues/3032
// https://gitlab.com/qemu-project/qemu/-/issues/2665
// https://gitlab.com/qemu-project/qemu/-/issues/2721
return false
}
return true
case "linux":
return true
case "netbsd", "windows":
return false
Expand All @@ -1185,8 +1221,8 @@ func HasHostCPU() bool {
}

func HasMaxCPU() bool {
// WHPX: Unexpected VP exit code 4
return runtime.GOOS != "windows"
// windows: WHPX: Unexpected VP exit code 4
return HasHostCPU()
}

func IsNativeArch(arch Arch) bool {
Expand Down
16 changes: 16 additions & 0 deletions pkg/osutil/osutil_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
package osutil

import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"
"syscall"

"golang.org/x/sys/unix"
Expand All @@ -16,3 +20,15 @@ func Dup2(oldfd, newfd int) (err error) {
func SignalName(sig os.Signal) string {
return unix.SignalName(sig.(syscall.Signal))
}

func Sysctl(name string) (string, error) {
var stderrBuf bytes.Buffer
cmd := exec.Command("sysctl", "-n", name)
cmd.Stderr = &stderrBuf
stdout, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to run %v: %w (stdout=%q, stderr=%q)", cmd.Args, err,
string(stdout), stderrBuf.String())
}
return strings.TrimSuffix(string(stdout), "\n"), nil
}
5 changes: 5 additions & 0 deletions pkg/osutil/osutil_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package osutil

import (
"errors"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -48,3 +49,7 @@ func SignalName(sig os.Signal) string {
return fmt.Sprintf("Signal(%d)", sig)
}
}

func Sysctl(name string) (string, error) {
return errors.New("sysctl: unimplemented on Windows")

Check failure on line 54 in pkg/osutil/osutil_windows.go

View workflow job for this annotation

GitHub Actions / Windows tests

not enough return values
}

0 comments on commit 0138e9b

Please sign in to comment.