Skip to content

Commit

Permalink
Add systemd for binding dpdk port after reboot
Browse files Browse the repository at this point in the history
- Add dpdkbind.service for systemd
- Update kernel module from uio to igb_uio
cc linkernetworks/vortex#212
  • Loading branch information
sufuf3 committed Aug 7, 2018
1 parent 9f64815 commit 80a2a70
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion inventory/group_vars/network-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ovs_tar_path: /tmp/openvswitch-2.9.2.tar.gz
ovs_folder_name: openvswitch-2.9.2

### Kernel module ###
kernel_module: uio
kernel_module: igb_uio
2 changes: 1 addition & 1 deletion network-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- hosts: network-setup
become: yes
roles:
- { role: network-setup/dpdk, when: kernel_module == 'uio' or ovs_type == 'dpdk', tags: dpdk }
- { role: network-setup/dpdk, when: kernel_module == 'igb_uio' or ovs_type == 'dpdk', tags: dpdk }
- { role: network-setup/ovs, when: ovs_type == 'ovs', tags: ovs }
- { role: network-setup/dpdk-ovs, when: ovs_type == 'dpdk', tags: dpdk-ovs }
- { role: network-setup/setup-dpdk-ovs, when: ovs_type == 'dpdk', tags: dpdk-ovs }
Expand Down
31 changes: 21 additions & 10 deletions roles/network-setup/dpdk/tasks/bind-network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,30 @@

# Bind secondary network adapter
# ifconfig DPDK interface down
- name: Make DPDK interface down
command: ifconfig {{ item.name }} down
ignore_errors: True
with_items:
- "{{ dpdk_ifaces }}"
# NIC setup will binding dpdk port after reboot
- name: Copy dpdkbind.service file
template:
src: dpdkbind.service.j2
dest: "/etc/systemd/system/dpdkbind.service"
owner: root
group: root
mode: 0755
when: ovs_type == 'dpdk'

# Bind port
- name: Bind port
shell: cd ~/ && {{ DPDK_DIR }}/usertools/dpdk-devbind.py --bind=igb_uio {{ item.name }}
ignore_errors: True
- name: Copy dpdkbind file
template:
src: dpdkbind.j2
dest: "/etc/default/dpdkbind"
owner: root
group: root
mode: 0755
when: ovs_type == 'dpdk'

- name: Enable dpdkbind.service
command: "{{ item }}"
with_items:
- "{{ dpdk_ifaces }}"
- systemctl enable dpdkbind
- systemctl start dpdkbind
when: ovs_type == 'dpdk'

# Check port
Expand Down
1 change: 0 additions & 1 deletion roles/network-setup/dpdk/tasks/dpdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@
- name: Setting environment values
command: sed -i 's/CONFIG_RTE_BUILD_SHARED_LIB=n/CONFIG_RTE_BUILD_SHARED_LIB=y/g' {{ DPDK_DIR }}/config/common_base
when: ovs_type == 'dpdk'

8 changes: 4 additions & 4 deletions roles/network-setup/dpdk/tasks/setting-kmod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
# Add the kernel module of driver, like UIO
- name: Add the kernel module of driver
modprobe:
name: "{{ kernel_module }}"
name: uio
state: present
when: ovs_type == 'dpdk'
when: kernel_module == 'igb_uio' and ovs_type == 'dpdk'

# Insert igb_uio when kernal_module is UIO
- name: Insert igb_uio when kernal_module is UIO
command: insmod {{ DPDK_DIR }}/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
ignore_errors: True
when: kernel_module == 'uio' and ovs_type == 'dpdk'
when: kernel_module == 'igb_uio' and ovs_type == 'dpdk'

# Make uio and igb_uio installations persist across reboots
- name: Insert igb_uio when kernal_module is UIO
Expand All @@ -25,5 +25,5 @@
- depmod -a
- echo "uio" | sudo tee -a /etc/modules
- echo "igb_uio" | sudo tee -a /etc/modules
when: kernel_module == 'uio' and ovs_type == 'dpdk'
when: kernel_module == 'igb_uio' and ovs_type == 'dpdk'

4 changes: 4 additions & 0 deletions roles/network-setup/dpdk/templates/dpdkbind.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# eg, NET_IF_NAME=enp0s16,enp0s17
{% for item in dpdk_ifaces %}
NET_IF_NAME={{ item.name }}
{%- endfor -%}
13 changes: 13 additions & 0 deletions roles/network-setup/dpdk/templates/dpdkbind.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Binding dpdk port after reboot
After=multi-user.target

[Install]
WantedBy=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=true
EnvironmentFile=-/etc/default/dpdkbind
ExecStart=/bin/bash -c 'echo "$NET_IF_NAME" | tr "," "\n" | awk \'{system("/sbin/ifconfig " $1 " down")}\''
ExecStart=/bin/bash -c 'echo "$NET_IF_NAME" | tr "," "\n" | awk \'{system("/usr/src/dpdk-stable-{{ dpdk_version }}/usertools/dpdk-devbind.py --bind={{ kernel_module }} " $1 )}\''
2 changes: 1 addition & 1 deletion roles/network-setup/reset/tasks/dpdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
- name: Remove IGB UIO module
shell: /sbin/rmmod igb_uio
ignore_errors: True
when: kernel_module == 'uio' and ovs_type == 'dpdk'
when: kernel_module == 'igb_uio' and ovs_type == 'dpdk'

# Unbind devices from VFIO driver
- name: Remove VFIO module
Expand Down

0 comments on commit 80a2a70

Please sign in to comment.