Skip to content

Commit

Permalink
QEMU: refactor selecting hardware selection into func
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Jul 15, 2024
1 parent b08324a commit 3f865e4
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/drivers/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,7 @@ func (d *Driver) Start() error {
}

// hardware acceleration is important, it increases performance by 10x
var accel string
if detect.IsAmd64M1Emulation() {
accel = "tcg"
} else if runtime.GOOS == "darwin" {
// On macOS, enable the Hypervisor framework accelerator.
accel = "hvf"
} else if _, err := os.Stat("/dev/kvm"); err == nil && runtime.GOOS == "linux" {
// On Linux, enable the Kernel Virtual Machine accelerator.
accel = "kvm"
}
accel := hardwareAcceleration()
if accel != "" {
startCmd = append(startCmd,
"-accel", accel)
Expand Down Expand Up @@ -552,6 +543,21 @@ func (d *Driver) Start() error {
return WaitForTCPWithDelay(fmt.Sprintf("%s:%d", d.IPAddress, d.SSHPort), time.Second)
}

func hardwareAcceleration() string {
if detect.IsAmd64M1Emulation() {
return "tcg"
}
if runtime.GOOS == "darwin" {
// On macOS, enable the Hypervisor framework accelerator.
return "hvf"
}
if _, err := os.Stat("/dev/kvm"); err == nil && runtime.GOOS == "linux" {
// On Linux, enable the Kernel Virtual Machine accelerator.
return "kvm"
}
return ""
}

func isBootpdError(err error) bool {
if runtime.GOOS != "darwin" {
return false
Expand Down

0 comments on commit 3f865e4

Please sign in to comment.