Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 1 | # Copyright 2020-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | --- |
| 16 | # Fail if VT-d is not enabled |
| 17 | - name: Ensure VT-d is enabled in BIOS |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 18 | shell: "set -o pipefail && dmesg | grep DMAR-IR" |
| 19 | args: |
| 20 | executable: /bin/bash |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 21 | register: check_vt_d |
| 22 | changed_when: check_vt_d.rc != 0 |
| 23 | failed_when: check_vt_d.rc != 0 |
| 24 | tags: sriov-dpdk |
| 25 | |
| 26 | - name: Add kernel boot parameters to the grub for SRIOV |
| 27 | lineinfile: |
| 28 | dest: /etc/default/grub |
| 29 | regexp: '^GRUB_CMDLINE_LINUX="(?!.* {{ item.regex }})(.*)"' |
| 30 | line: 'GRUB_CMDLINE_LINUX="\1 {{ item.context }}"' |
| 31 | state: present |
| 32 | backrefs: yes |
| 33 | loop: |
| 34 | - { regex: 'intel_iommu=on', context: 'intel_iommu=on' } |
Hyunsun Moon | e4237f8 | 2020-04-14 10:37:39 -0700 | [diff] [blame] | 35 | - { regex: 'hugepagesz=', context: 'transparent_hugepage=never hugepagesz=1G default_hugepagesz=1G hugepages=32' } |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 36 | register: grub |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 37 | notify: update grub |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 38 | tags: sriov-dpdk |
| 39 | |
| 40 | - name: Load vfio_pci module to the kernel |
| 41 | modprobe: |
| 42 | name: vfio_pci |
| 43 | state: present |
| 44 | tags: sriov-dpdk |
| 45 | |
| 46 | - name: Set the vfio_pci module to load on boot |
| 47 | lineinfile: |
| 48 | dest: /etc/modules-load.d/vfio_pci.conf |
| 49 | create: yes |
| 50 | regexp: "^vfio_pci" |
| 51 | line: "vfio_pci" |
| 52 | tags: sriov-dpdk |
| 53 | |
| 54 | - name: Check VFIO bind devices for DPDK |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 55 | shell: "set -o pipefail && ls -l /dev/vfio | wc -l" |
| 56 | args: |
| 57 | executable: /bin/bash |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 58 | register: check_dpdk_bind |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 59 | changed_when: False |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 60 | tags: sriov-dpdk |
| 61 | |
| 62 | - name: Create SRIOV-DPDK service |
| 63 | template: |
| 64 | src: "{{ item.src }}" |
| 65 | dest: "{{ item.dest }}" |
| 66 | mode: "{{ item.mode }}" |
| 67 | loop: |
| 68 | - { src: 'usr/bin/sriov.sh.j2', dest: '/usr/bin/sriov.sh', mode: 'a+x' } |
| 69 | - { src: 'etc/systemd/system/sriov.service.j2', dest: '/etc/systemd/system/sriov.service', mode: 644 } |
| 70 | register: bind_dpdk |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 71 | notify: enable sriov |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 72 | when: check_dpdk_bind.stdout | int < 4 |
| 73 | tags: sriov-dpdk |
| 74 | |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 75 | - meta: flush_handlers |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 76 | tags: sriov-dpdk |
| 77 | |
| 78 | - name: Reboot machine |
| 79 | shell: sleep 2 && shutdown -r now "Ansible updates triggered" |
| 80 | async: 1 |
| 81 | poll: 0 |
| 82 | ignore_errors: true |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 83 | when: grub.changed or bind_dpdk.changed # noqa 503 |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 84 | tags: sriov-dpdk |
| 85 | |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 86 | - name: Wait for server to restart |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 87 | wait_for: |
| 88 | host: "{{ ansible_host }}" |
| 89 | search_regex: "OpenSSH" |
| 90 | port: 22 |
| 91 | timeout: 300 |
| 92 | connect_timeout: 50 |
| 93 | delay: 5 |
| 94 | delegate_to: localhost |
| 95 | become: false |
| 96 | tags: sriov-dpdk |
| 97 | |
| 98 | - name: Ensure enough VFIO bind devices |
Hyunsun Moon | 6c6db95 | 2020-03-04 20:50:51 -0800 | [diff] [blame] | 99 | shell: "set -o pipefail && ls -l /dev/vfio | wc -l" |
| 100 | args: |
| 101 | executable: /bin/bash |
Hyunsun Moon | e484834 | 2020-02-16 04:28:55 -0800 | [diff] [blame] | 102 | register: confirm_dpdk_bind |
| 103 | changed_when: confirm_dpdk_bind.stdout | int < 4 |
| 104 | failed_when: confirm_dpdk_bind.stdout | int < 4 |
| 105 | tags: sriov-dpdk |