Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple accelerators #160

Open
lbajolet-hashicorp opened this issue Oct 5, 2023 · 1 comment
Open

Support multiple accelerators #160

lbajolet-hashicorp opened this issue Oct 5, 2023 · 1 comment

Comments

@lbajolet-hashicorp
Copy link
Contributor

lbajolet-hashicorp commented Oct 5, 2023

Qemu supports specifying several accelerators, in precedence order, so that one can specify a list of accelerators to use, and let qemu decide which is the one that can apply to the current context.
One such use-case would be for example templates that can be invoked in different contexts.

If using windows, we'd want to use WHPX, on Linux we'd want KVM, and something else (probably TCG) on other platforms.
Right now, the best way to support this would be to set the accelerator as an input variable, or to read it from the environment, then invoke Packer with the template, and use the appropriate accelerator for the platform.

What this issue suggests is adding a list of accelerators, in addition to the accelerator attribute we already have, in order to specify this list once, and have qemu pick which one applies to the current environment.

Example configuration

source "qemu" "test" {
  accelerators = ["whpx", "kvm", "tcg"]
}
[...]

This would yield a command such as qemu-system-x86_64 -accel "whpx" -accel "kvm" -accel "tcg" [...], which in turn would lead to qemu trying each accelerator in succession, and picking the first one it supports in the current environment.

For example on a Linux x86_64 system:

qemu-system-x86_64: -accel whpx: invalid accelerator whpx
qemu-system-x86_64: falling back to KVM
[...]

Discussed in PR #119

@jcrben
Copy link

jcrben commented Oct 15, 2024

Just a note: for now, you can use the qemuargs variable - and you can use a variable to flip between them.

Here's an example, altho I'm still iterating:

variable "is_windows" {
  type    = bool
  default = false
}

locals {
  qemuargs_windows = [
    ["-machine", "type=q35,kernel-irqchip=off"],
    ["-accel", "whpx"]
  ]
  qemuargs_default = []
}

source "qemu" "ubuntu" {
  accelerator = var.is_windows ? "whpx" : "kvm"
  qemuargs = var.is_windows ? local.qemuargs_windows : local.qemuargs_default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants