# Kubernetes CNI SRIOV# 时间:20210827-[20:00-22:00]# 主题:MUTUS SRIOV DPDK# 文档:# 作业:MUTUS SRIOV DPDK
CPU Pin
#设置cpu pin:export LC_ALL="en_US.UTF-8"systemctl stop irqbalance; systemctl disable irqbalancetuna --cpus=4-51,56-103 --isolatetuna --irqs='*' --cpus=0-3,52-55 --spread# 1.systemctl stop irqbalance; systemctl disable irqbalancehttps://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_for_real_time/7/html/tuning_guide/interrupt_and_process_bindingThis daemon is enabled by default and periodically forces interrupts to be handled by CPUs in an even, fair manner. However in real-time deployments, applications are typically dedicated and bound to specific CPUs, so the irqbalance daemon is not required.// 这个守护进程在默认情况下是启用的,它会定期强制中断由 CPU 以均匀、公平的方式处理。然而,在实时部署中,应用程序通常是专用的并绑定到特定的 CPU,因此irqbalance不需要守护程序。# 2.设置cpu pin:# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/performance_tuning_guide/sec-tuna-cpu-tuningIsolating a CPU causes all tasks currently running on that CPU to move to the next available CPU. To isolate a CPU。# tuna --cpus=cpu_list --isolatetuna --cpus=4-51,56-103 --isolate# 3.tuna --irqs='*' --cpus=0-3,52-55 --spread# yum -y install tuna[root@k8s-2 ~]# tuna --helpUsage: tuna [OPTIONS]-h, --help Give this help list-a, --config_file_apply=profilename Apply changes described in profile-l, --config_file_list List preloaded profiles-g, --gui Start the GUI-G, --cgroup Display the processes with the type of cgroups they are in-c, --cpus=CPU-LIST CPU-LIST affected by commands # 由 Tuna 控制的 CPU。该列表将一直有效,直到指定新列表-C, --affect_children Operation will affect children threads-f, --filter Display filter the selected entities-i, --isolate Move all threads away from CPU-LIST # 将所有线程从指定的 CPU 移开-I, --include Allow all threads to run on CPU-LIST-K, --no_kthreads Operations will not affect kernel threads-m, --move Move selected entities to CPU-LIST-N, --nohz_full CPUs in nohz_full= kernel command line will be affected by operations-p, --priority=[POLICY:]RTPRIO Set thread scheduler tunables: POLICY and RTPRIO-P, --show_threads Show thread list-Q, --show_irqs Show IRQ list-q, --irqs=IRQ-LIST IRQ-LIST affected by commands # 指定受命令影响的 IRQ 列表。在指定新列表之前,该列表将一直有效。IRQ 可以通过使用添加到列表中,也可以通过使用+从列表中删除--r, --run=COMMAND fork a new process and run the COMMAND-s, --save=FILENAME Save kthreads sched tunables to FILENAME-S, --sockets=CPU-SOCKET-LIST CPU-SOCKET-LIST affected by commands-t, --threads=THREAD-LIST THREAD-LIST affected by commands-U, --no_uthreads Operations will not affect user threads-v, --version Show version-W, --what_is Provides help about selected entities-x, --spread Spread selected entities over CPU-LIST # 在选定的 CPU 之间均匀分布指定的线程[root@k8s-2 ~]## 为了使得此配置能在重启的时候不丢失,我们可以把其配置成service的形式:Like:# systemctl cat cpu-pinning.service# /usr/lib/systemd/system/cpu-pinning.service[Unit]Description=CPU pinningBefore=basic.targetAfter=local-fs.target sysinit.targetDefaultDependencies=no[Service]Type=oneshotRemainAfterExit=yesExecStart=/etc/cpu-pinning.sh[Install]WantedBy=sysinit.target
Config SRIOV
Setting up Virtual Functions
The SR-IOV Network Device Plugin requires SR-IOV virtual functions (VFs) to be created on the host ahead of startup. The device plugin does not manage the creation of virtual functions, and it does not automatically update when there is a change in the virtual functions. Each time the number of VFs or the driver used by the VF change the SR-IOV Network Device Plugin needs to be restarted.
This guide gives an overview for setting up SR-IOV virtual functions on a linux host for various NICs.
- Intel
-
Intel
The below works on Intel SR-IOV enabled cards including those from the Gigabit Ethernet, X710 and X722 families of Network Interface Cards. Note not all Gigabit Ethernet NICs are enabled with SR-IOV.
Cards from the following families can be enabled through the sysfs endpoint as described below: Intel i40e Driver
- Intel® Ethernet Controller X722
- Intel® Ethernet Controller X710
- Intel ixgbe Driver
- Intel® Ethernet Controller 82599
- Intel® Ethernet Controller X520
- Intel® Ethernet Controller X540
- Intel® Ethernet Controller x550
- Intel® Ethernet Controller X552
- Intel® Ethernet Controller X553
Creating VFs with sysfs
First select a compatible NIC on which to create VFs and record its name (shown as PF_NAME below).
To create 8 virtual functions run:
echo 8 > /sys/class/net/${PF_NAME}/device/sriov_numvfs
To check that the VFs have been successfully created run:
lspci | grep "Virtual Function"
This method requires the creation of VFs each time the node resets. This can be handled automatically by placing the above command in a script that is run on startup such as /etc/rc.local.
Common issues
Cannot allocate memory
Some cards using the ixgbe may require additional configuration. This is likely the case if the message write error: Cannot allocate memory is returned when creating VFs using the above method. This issue has been observed on the X552 NIC.
To resolve this issue, try setting the maximum allowed VFs in the driver config:
modprobe -r ixgbe; modprobe ixgbe max_vfs=8
Next set the VFs as above
echo 8 > /sys/class/net/${PF_NAME}/device/sriov_numvfs
Device or resource busy
The message write error: device or resource busy in response to an attempt to create virtual functions can mean that some virtual functions have already been created. In order to change the number of VFs the number may first need to be set to zero:
echo 0 > /sys/class/net/${PF_NAME}/device/sriov_numvfsecho 8 > /sys/class/net/${PF_NAME}/device/sriov_numvfs
Mellanox
SRIOV-CNI support Mellanox ConnectX®-4 Lx and ConnectX®-5 adapter cards.
To enable SR-IOV functionality the following steps are required:
1- Enable SR-IOV in the NIC’s Firmware.
Installing Mellanox Management Tools (MFT) or mstflint is a pre-requisite, MFT can be downloaded from here, mstflint package available in the various distros and can be downloaded from here.
Use Mellanox Firmware Tools package to enable and configure SR-IOV in firmware
# mst startStarting MST (Mellanox Software Tools) driver setLoading MST PCI module - SuccessLoading MST PCI configuration module - SuccessCreate devices
Locate the HCA device on the desired PCI slot
# mst statusMST modules:------------MST PCI module loadedMST PCI configuration module loadedMST devices:------------/dev/mst/mt4115_pciconf0 - PCI configuration cycles access....
Enable SR-IOV
# mlxconfig -d /dev/mst/mt4115_pciconf0 q set SRIOV_EN=1 NUM_OF_VFS=8...Apply new Configuration? ? (y/n) [n] : yApplying... Done!-I- Please reboot machine to load new configurations.
Alternatively, use mstconfig from mstflint package
# mstconfig -d 04:00.0 set SRIOV_EN=1 NUM_OF_VFS=8...Apply new Configuration ? (y/n) [n] : yApplying... Done!-I- Please reboot machine to load new configurations.
Where 04:00.0 is the NIC’s PCI address.
Reboot the machine
# reboot
2- Enable SR-IOV in the NIC’s Driver.
# ibdev2netdevmlx5_0 port 1 ==> enp2s0f0 (Up)mlx5_1 port 1 ==> enp2s0f1 (Up)# echo 4 > /sys/class/net/enp2s0f0/device/sriov_numvfs# ibdev2netdev -v0000:02:00.0 mlx5_0 (MT4115 - MT1523X04353) CX456A - ConnectX-4 QSFP fw 12.23.1020 port 1 (ACTIVE) ==> enp2s0f0 (Up)0000:02:00.1 mlx5_1 (MT4115 - MT1523X04353) CX456A - ConnectX-4 QSFP fw 12.23.1020 port 1 (ACTIVE) ==> enp2s0f1 (Up)0000:02:00.5 mlx5_2 (MT4116 - NA) fw 12.23.1020 port 1 (DOWN ) ==> enp2s0f2 (Down)0000:02:00.6 mlx5_3 (MT4116 - NA) fw 12.23.1020 port 1 (DOWN ) ==> enp2s0f3 (Down)0000:02:00.7 mlx5_4 (MT4116 - NA) fw 12.23.1020 port 1 (DOWN ) ==> enp2s0f4 (Down)0000:02:00.2 mlx5_5 (MT4116 - NA) fw 12.23.1020 port 1 (DOWN ) ==> enp2s0f5 (Down)# lspci | grep Mellanox02:00.0 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4]02:00.1 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4]02:00.2 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4 Virtual Function]02:00.3 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4 Virtual Function]02:00.4 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4 Virtual Function]02:00.5 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4 Virtual Function]# ip link show...enp2s0f2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000link/ether c6:6d:7d:dd:2a:d5 brd ff:ff:ff:ff:ff:ffenp2s0f3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000link/ether 42:3e:07:68:da:fb brd ff:ff:ff:ff:ff:ffenp2s0f4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000link/ether 42:68:f2:aa:c2:27 brd ff:ff:ff:ff:ff:ffenp2s0f5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000...
To change the number of VFs reset the number to 0 then set the needed number
echo 0 > /sys/class/net/enp2s0f0/device/sriov_numvfs
配置解说
# X710 网卡配置说明:#!/bin/bash -x# 3b:00.0 3 eth4 3c:fd:fe:92:d6:40 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For SRIOV Kernel# 3b:00.1 7 eth5 3c:fd:fe:92:d6:41 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For SRIOV Kernel# 3b:00.2 8 eth6 3c:fd:fe:92:d6:42 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For SRIOV DPDK# 3b:00.3 9 eth7 3c:fd:fe:92:d6:43 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For SRIOV DPDK# d8:00.0 10 eth8 3c:fd:fe:92:d6:50 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For MACVLAN# d8:00.1 11 eth9 3c:fd:fe:92:d6:51 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For MACVLAN# d8:00.2 12 eth10 3c:fd:fe:92:d6:52 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For MACVLAN# d8:00.3 13 eth11 3c:fd:fe:92:d6:53 Down i40e Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T (rev 02) # For MACVLAN# For SRIOV Kernelecho 0 > /sys/class/net/eth4/device/sriov_numvfsecho 0 > /sys/class/net/eth5/device/sriov_numvfsecho 32 > /sys/class/net/eth4/device/sriov_numvfsecho 32 > /sys/class/net/eth5/device/sriov_numvfs# For SRIOV DPDKecho 0 > /sys/class/net/eth6/device/sriov_numvfsecho 0 > /sys/class/net/eth7/device/sriov_numvfsecho 32 > /sys/class/net/eth6/device/sriov_numvfsecho 32 > /sys/class/net/eth7/device/sriov_numvfs#modprobe vfio_pci#for intf in eth6 eth7; do# for pci_id in `ls -l /sys/class/net/$intf/device/virtfn* | cut -d '/' -f8`; do# /opt/rowan/dpdk-devbind.py -u $pci_id# /opt/rowan/dpdk-devbind.py -b vfio_pci $pci_id# done#donemodprobe uioinsmod /opt/rowan/igb_uio.kofor intf in eth6 eth7; dofor pci_id in `ls -l /sys/class/net/$intf/device/virtfn* | cut -d '/' -f8`; do/opt/rowan/dpdk-devbind.py -u $pci_id/opt/rowan/dpdk-devbind.py -b igb_uio $pci_id#/opt/rowan/dpdk-devbind.py -b vfio-pci $pci_iddonedone#可以通过 ip link show 去查看:8: eth6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000link/ether 3c:fd:fe:92:d6:42 brd ff:ff:ff:ff:ff:ffvf 0 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 1 MAC 00:00:00:00:00:00, vlan 2310, spoof checking on, link-state auto, trust onvf 2 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 3 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 4 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 5 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 6 MAC 00:00:00:00:00:00, vlan 2320, spoof checking on, link-state auto, trust onvf 7 MAC 00:00:00:00:00:00, vlan 2330, spoof checking on, link-state auto, trust onvf 8 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 9 MAC 00:00:00:00:00:00, vlan 2340, spoof checking on, link-state auto, trust onvf 10 MAC 00:00:00:00:00:00, vlan 2320, spoof checking on, link-state auto, trust onvf 11 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 12 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 13 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust offvf 14 MAC 00:00:00:00:00:00, vlan 2310, spoof checking on, link-state auto, trust onvf 15 MAC 00:00:00:00:00:00, spoof checking on, link-state auto, trust off# kubectl describe nodes k8s-2Capacity:cpu: 88ephemeral-storage: 3900337424Kihugepages-1Gi: 64Giintel.com/sriov_dpdk_3: 16intel.com/sriov_dpdk_4: 16intel.com/sriov_kern_1: 32intel.com/sriov_kern_2: 32memory: 791009936Kipods: 200Allocatable:cpu: 80ephemeral-storage: 3594550964007hugepages-1Gi: 64Giintel.com/sriov_dpdk_3: 16intel.com/sriov_dpdk_4: 16intel.com/sriov_kern_1: 32intel.com/sriov_kern_2: 32memory: 723798672Kipods: 200# ./dpdk-devbind.py -s # 去查看绑定情况
整体配置案例
SRIOV and DPDK
SRI-IOV WorkerNode Prerequisites
In order for the cni-sriov-plugin to start reading Virtual Functions resources as well HostNetworkTemplate objects can configure virtual functions you need to perform the following steps.
Enable** VT-D** at BIOS level.
Enable SRIOV feature globally and/or per nic according to the nic you are working with, for example Intel x710 should be enabled per nic at BIOS level.
Upgrade Kernel boot line to enable intel_iommu=on and iommu=pt
$ grubby --update-kernel=ALL --args="iommu=pt intel_iommu=on"
$ reboot
Copy
Huge page Support
Most network applications use huge pages, so you may want to enable that. Please edit /etc/default/grub and add huge-ages
Bash
GRUB_CMDLINE_LINUX="nofb nomodeset vga=normal iommu=pt intel_iommu=on default_hugepagesz=1G hugepagesz=1G hugepages=16"
#Rebuild grub.cfg
grub2-mkconfig -o /boot/grub2/grub.cfg && reboot
Copy
Create SR-IOV ConfigMap
SR-IOV ConfigMap
Please copy paste the following definition update the values of your Physical Functions and ranges or Virtual Functions as well as Drivers and apply it to our cluster, in case that you have multiple nics, that each one uses different kernels drivers please omit the drivers section and just mentioned pfName within the selectors section.
SR-IOV Kernel Driver plus DPDK ConfigMap
YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: sriovdp-config
namespace: kube-system
data:
config.json: |
{
"resourceList": [
{
"resourceName": "intel_sriov_dpdk0",
"selectors": {
"drivers": ["vfio-pci"],
"pfNameis": ["enp3s0f0#0-7"]
}
},
{
"resourceName": "intel_sriov_kernel0",
"selectors": {
"drivers": ["ixgbevf"],
"pfNames": ["enp3s0f0#8-15"]
}
},
{
"resourceName": "intel_sriov_dpdk1",
"selectors": {
"drivers": ["vfio-pci"],
"pfNames": ["enp3s0f1#0-7"]
}
},
{
"resourceName": "intel_sriov_kernel1",
"selectors": {
"drivers": ["ixgbevf"],
"pfNames": ["enp3s0f1#8-15"]
}
}
]
}
Copy
Create NetworkAttachDefinition of DPDK type
YAML
kind: NetworkAttachmentDefinition
metadata:
name: sriov-net-a
annotations:
k8s.v1.cni.cncf.io/resourceName: intel.com/intel_sriov_dpdk_a
spec:
config: '{
"type": "sriov",
"cniVersion": "0.3.1",
"name": "sriov-network-a",
"vlan": 100,
"vlanQoS": 1,
"max_tx_rate": 100,
"spoofchk": "off",
"trust": "on"
}'
Copy
Network Attach Definition Validation SR-IOV-DPDK type
Let’s validate our work by listing and describing our new Network Attach Definition
Bash
$ kubectl get net-attach-def
NAME AGE
sriov-dpdk0 15s
Copy
Bash
$ kubectl describe net-attach-def sriov-dpdk0
Name: sriov-dpdk0
Namespace: default
Labels: <none>
Annotations: k8s.v1.cni.cncf.io/resourceName: intel.com/intel_sriov_dpdk0
kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"k8s.cni.cncf.io/v1","kind":"NetworkAttachmentDefinition","metadata":{"annotations":{"k8s.v1.cni.cncf.io/resourceName":"inte...
API Version: k8s.cni.cncf.io/v1
Kind: NetworkAttachmentDefinition
Metadata:
Creation Timestamp: 2020-10-05T20:25:57Z
Generation: 1
Resource Version: 2310115
Self Link: /apis/k8s.cni.cncf.io/v1/namespaces/default/network-attachment-definitions/sriov-dpdk0
UID: 5307140a-3771-41b4-845e-1aa8460acffc
Spec:
Config: { "cniVersion": "0.3.1", "name": "sriov-dpdk0", "type": "sriov", "vlan": 90 }
Events: <none>
Copy
Create Pods with SR-IOV interfaces (DPDK Driver - vfio-pci)
YAML
# cat sriov-pod-2.yaml
apiVersion: v1
kind: Pod
metadata:
name: sriov-pod-2
annotations:
k8s.v1.cni.cncf.io/networks: sriov-net-a
spec:
containers:
- name: sriov-example
image: rparikh/dpdk-app-centos
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/podnetinfo
name: podnetinfo
readOnly: false
- mountPath: /dev/hugepages
name: hugepage
resources:
requests:
memory: 1Gi
#cpu: "4"
intel.com/intel_sriov_dpdk_a: '1'
limits:
hugepages-1Gi: 2Gi
#cpu: "4"
intel.com/intel_sriov_dpdk_a: '1'
# Uncomment to control which DPDK App is running in container.
# If not provided, l3fwd is default.
# Options: l2fwd l3fwd testpmd
env:
- name: DPDK_SAMPLE_APP
value: "testpmd"
#
# Uncomment to debug DPDK App or to run manually to change
# DPDK command line options.
command: ["sleep", "infinity"]
volumes:
- name: podnetinfo
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- path: "annotations"
fieldRef:
fieldPath: metadata.annotations
- name: hugepage
emptyDir:
medium: HugePages
Copy
Deploy the new pods
Bash
$ kubectl apply -f sriov-pod-2.yaml
Copy
Validate Pods Creation with SR-IOV interfaces (DPDK - Driver vfio-pci)
Let’s validate your work by confirming that the created pods got successfully created by doing the following commands:
Bash
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
sriov-pod-2 1/1 Running 0 5d21h 10.167.181.11 10.128.237.204 <none> <none>
Copy
SR-IOV DPDK Driver - vfio-pci Validation
Bash
$ kubectl exec -it sriov-pod-2 -- sh
sh-4.4# dpdk-app
ENTER dpdk-app:
argc=1
dpdk-app
cpuRsp.CPUSet = 0-31
Interface[0]:
IfName="" Name="" Type=SR-IOV
MAC="" IP="10.143.181.4"
PCIAddress=0000:03:10.7
myArgc=14
dpdk-app -n 4 -l 1 --master-lcore 1 -w 0000:03:10.7 -- -p 0x1 -P --config="(0,0,1)" --parse-ptype
