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 1261545
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
skip = .git,go.mod,go.sum,*.pb.desc,*/node_modules/*,*/public/js/*,*/public/scss/*

# Comma separated list of words to be ignored. Words must be lowercased.
ignore-words-list = ans,distroname,testof,hda,ststr,archtypes
ignore-words-list = ans,distroname,testof,hda,ststr,archtypes,sme

# Check file names as well.
check-filenames = true
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
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.
//
// However, QEMU is not ready to handle SME yet.
//
// 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")
}

0 comments on commit 1261545

Please sign in to comment.