Skip to content

Commit

Permalink
Merge pull request #30 from andreygubarev/qemu-machine
Browse files Browse the repository at this point in the history
Fix ARM performance on Apple Silicon
  • Loading branch information
andreygubarev authored Oct 13, 2023
2 parents b5326f5 + ee16507 commit 81bdb1b
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions molecule_qemu/playbooks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@
ansible.builtin.set_fact:
qemu_cap_kvm: "{{ kvm_support.rc == 0 }}"

- name: Set QEMU machine (x86_64)
when: ansible_machine == 'x86_64'
ansible.builtin.set_fact:
qemu_machine: "x86_64"

- name: Set QEMU machine (arm64)
when: ansible_machine == 'arm64'
ansible.builtin.set_fact:
qemu_machine: "aarch64"

- name: Assert QEMU machine
ansible.builtin.assert:
that:
- qemu_machine is defined
fail_msg: "QEMU machine is not supported"
success_msg: "QEMU machine is supported"

### prerequisites #########################################################

- name: Create driver directory
Expand Down Expand Up @@ -267,38 +284,48 @@
ansible.builtin.command: >-
qemu-system-{{ item.image_arch }}
-name {{ item.name }}
-daemonize
-pidfile {{ item.path_pid }}
-display none
-m {{ item.vm_memory }}
-smp {{ item.vm_cpus }}
-boot d
-cdrom {{ molecule_ephemeral_directory }}/run/cloud-init/{{ item.name }}.iso
-drive if=virtio,file={{ item.path_disk }}
-m {{ item.vm_memory }}
-smp {{ item.vm_cpus }}
{% if item.network_mode == 'vmnet-shared' %}
-nic vmnet-shared,model=virtio-net-pci,mac={{ item.network_mac }}
-nic vmnet-shared,model=virtio-net-pci,mac={{ item.network_mac }}
{% endif %}
{% if item.network_mode == 'user' %}
{% if item.network_extra_args == '' %}
-nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22
{% else %}
-nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22,{{ item.network_extra_args }}
{% if item.network_extra_args == '' %}
-nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22
{% else %}
-nic user,model=virtio-net-pci,hostfwd=tcp::{{ item.network_ssh_port }}-:22,{{ item.network_extra_args }}
{% endif %}
{% endif %}
{% endif %}
-display none
-daemonize
-pidfile {{ item.path_pid }}
-bios {{ molecule_driver_directory }}/edk2-{{ item.image_arch }}.fd
{% if item.image_arch == 'aarch64' %}
-machine virt
{% if qemu_cap_hvf and item.image_arch == ansible_machine %}
-cpu host
-accel hvf
{% else %}
-cpu cortex-a72
-machine virt
{% if item.image_arch == qemu_machine and qemu_cap_hvf %}
-cpu host
-accel hvf
{% else %}
-cpu cortex-a72
{% endif %}
{% endif %}
{% if item.image_arch == 'x86_64' %}
{% if item.image_arch == qemu_machine and qemu_cap_kvm %}
-cpu host
-enable-kvm
{% endif %}
{% endif %}
{% if qemu_cap_kvm and item.image_arch == ansible_machine %}
-cpu host
-enable-kvm
{% endif %}
{{ item.vm_extra_args }}
args:
creates: "{{ item.path_pid }}"
Expand Down

0 comments on commit 81bdb1b

Please sign in to comment.