續前節,
測試小程序
1. 想編譯測試程序首先需要設置兩個環境變量,為什么呢,因為測試程序的Makefile里用了。。。 rpm裝了打包好的devel包,這個rpm也會自帶這兩個環境變量。就是說寫第三方程序的時候,習慣上,約定了這兩個環境變量。
[root@dpdk tools]# cat ~/env.sh export RTE_SDK=/root/dpdk-16.07 export RTE_TARGET=x86_64-native-linuxapp-gcc [root@dpdk tools]#
2. 文檔里說:The UIO drivers and hugepages must be setup prior to running an application.
UIO包括:uio_pci_generic, uio, igb_uio, vfio_pci
vfio_pci 在host里我已經學會怎么玩了。uio不知道是啥,好想要和igb_uio放在一起用
sudo modprobe uio
sudo insmod kmod/igb_uio.ko
[root@dpdk tools]# locate igb_uio.ko /root/dpdk-16.07/build/build/lib/librte_eal/linuxapp/igb_uio/.igb_uio.ko.cmd /root/dpdk-16.07/build/build/lib/librte_eal/linuxapp/igb_uio/igb_uio.ko /root/dpdk-16.07/build/kmod/igb_uio.ko /root/dpdk-16.07/x86_64-native-linuxapp-gcc/build/lib/librte_eal/linuxapp/igb_uio/.igb_uio.ko.cmd /root/dpdk-16.07/x86_64-native-linuxapp-gcc/build/lib/librte_eal/linuxapp/igb_uio/igb_uio.ko /root/dpdk-16.07/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko [root@dpdk tools]#
我覺得弄一下 uio_pci_generic
首先,有一個非常好用的工具 tools/dpdk-devbind.sh . (我就是客氣一下,我並沒有覺得特別好用,當然也覺得難用,因為我根本就沒怎么用)
(1) 現運行這個命令,看一看
[root@dpdk tools]# ./dpdk-devbind.py --status Network devices using DPDK-compatible driver ============================================ <none> Network devices using kernel driver =================================== 0000:00:03.0 'Virtio network device' if= drv=virtio-pci unused= 0000:00:04.0 'Ethernet Connection (3) I218-V' if=ens4 drv=e1000e unused= *Active* Other network devices ===================== <none>
(2)加載驅動 uio_pci_generic
[root@dpdk tools]# modprobe uio_pci_generic
(3) 再運行看一下,然后發現unused發生了變化,可是也沒什么大不了的。
[root@dpdk tools]# ./dpdk-devbind.py --status Network devices using DPDK-compatible driver ============================================ <none> Network devices using kernel driver =================================== 0000:00:03.0 'Virtio network device' if= drv=virtio-pci unused=uio_pci_generic 0000:00:04.0 'Ethernet Connection (3) I218-V' if=ens4 drv=e1000e unused=uio_pci_generic *Active* Other network devices ===================== <none>
(4)把網卡從原驅動e1000e上面解綁,和vfio_pci的操作沒有區別。
[root@dpdk tools]# lspci -nn -s 00:04.0 00:04.0 Ethernet controller [0200]: Intel Corporation Ethernet Connection (3) I218-V [8086:15a3] (rev 03) [root@dpdk tools]# echo 0000:00:04.0 > /sys/bus/pci/devices/0000\:00\:04.0/driver/unbind
[root@dpdk tools]# ./dpdk-devbind.py --status Network devices using DPDK-compatible driver ============================================ <none> Network devices using kernel driver =================================== 0000:00:03.0 'Virtio network device' if= drv=virtio-pci unused=uio_pci_generic Other network devices ===================== 0000:00:04.0 'Ethernet Connection (3) I218-V' unused=uio_pci_generic
(5) 綁到 uio_pci_generic 上面去。
[root@dpdk tools]# echo '0000:00:04.0' > /sys/bus/pci/drivers/uio_pci_generic/bind
[root@dpdk tools]# ./dpdk-devbind.py --status Network devices using DPDK-compatible driver ============================================ 0000:00:04.0 'Ethernet Connection (3) I218-V' drv=uio_pci_generic unused= Network devices using kernel driver =================================== 0000:00:03.0 'Virtio network device' if= drv=virtio-pci unused=uio_pci_generic Other network devices ===================== <none>
(6) 至此,綁完了就。就文檔說(4)和(5)可以用一條命令搞定。並沒有測試。
./tools/dpdk-devbind.py --bind=uio_pci_generic 04:00.1
大頁,我早已經在虛擬機里設置好了。
3. EAL庫。
(1) 就是dpdk的程序都可以接受命令行參數。其他是可選的,只有一個-c mask是比較主要的,用掩碼覺得運行程序的邏輯核。
[root@dpdk build]# ./helloworld -c 1 |grep hello hello from core 0 [root@dpdk build]# ./helloworld -c 2 |grep hello hello from core 1 [root@dpdk build]# ./helloworld -c 4 |grep hello hello from core 2 [root@dpdk build]# ./helloworld -c 3 |grep hello hello from core 0 hello from core 1 [root@dpdk build]# ./helloworld -c 6 |grep hello hello from core 2 hello from core 1 [root@dpdk build]#
給mask參數之前,你必須知道你的cpu結構。
這么多年都是這樣的。
[root@dpdk build]# cat /proc/cpuinfo
后來覺得可視性不好,於是寫了個腳本整理了一下輸出結果。可是那又怎么樣呢? 依然很土。
然后,對,剛剛,dpdk的文檔里介紹了這個:lstopo (pkg: hwloc). 輸出結果是醬紫的!
牛逼的!我還能說什么。。。 還有nographic版本:
[tong@T7 ~]$ lstopo-no-graphics Machine (7927MB) Package L#0 + L3 L#0 (4096KB) L2 L#0 (256KB) + L1d L#0 (32KB) + L1i L#0 (32KB) + Core L#0 PU L#0 (P#0) PU L#1 (P#1) L2 L#1 (256KB) + L1d L#1 (32KB) + L1i L#1 (32KB) + Core L#1 PU L#2 (P#2) PU L#3 (P#3) HostBridge L#0 PCI 8086:1616 GPU L#0 "card1" GPU L#1 "renderD129" GPU L#2 "controlD65" PCI 8086:15a3 PCIBridge PCI 8086:095b Net L#3 "wlan0" PCIBridge PCI 10de:1347 GPU L#4 "card0" GPU L#5 "renderD128" GPU L#6 "controlD64" PCI 8086:9c83 Block(Disk) L#7 "sda" Block(Disk) L#8 "sdb" [tong@T7 ~]$
(2) 內存參數。可以申請在hugepage中預申請內存,並決定node。
使用參數 -m ,或 --socket-mem
(3) 測試程序。test, testpmd
4. HPET (High Precision Event Timer) 高精度定時器。
(1)查看硬件支持與BOIS狀態,如下有輸出,代表啟用,沒有任何輸入代表沒有啟用或不支持:
[root@dpdk ~]# grep hpet /proc/timer_list
Clock Event Device: hpet
set_next_event: hpet_legacy_next_event
set_mode: hpet_legacy_set_mode
[root@dpdk ~]#
(2)內核支持。內核參數 HPET_MMAP 可以將計數器映射近用戶態進程地址空間。
(3)dpdk支持。CONFIG_RTE_LIBEAL_USE_HPET 編譯時設置編譯選項,默認為n。
5. 使用非超級用戶運行。
6. 電源管理。
7. Isolation Core。指定的CPU將不參加系統內核任務調度,從而可以單獨被專用。
支持內核參數如下:
isolcpus=2,4,6
8. KNI kernel Mode (Dpdk Kernel NIC Interface) 並不知道是干嘛的。
9. IOMMU。與之前的類似。
10. 40G網卡。 i40e驅動
確保 firmware 支持。我也不知道怎么確保。。。
快速設置腳本 dpdk-setup.sh
自動化工具用於完成前邊提到的大部分內容。
獲取最佳網卡性能
內存:
查看通道數,頻率之類的,不太懂。先這么地把。(下圖例子為host主機 T450 板載4G,外插4G。均為DDR3 1600 ;我還看了我的台式機輸出,台式機DDR2 800 X 4 雙通道。然而並不能通過輸出很顯然的反饋出上述信息,所以這部分知識還是需要仔細學習的。)
[tong@T7 ~]$ sudo dmidecode -t memory |grep Locator Locator: ChannelA-DIMM0 Bank Locator: BANK 0 Locator: ChannelB-DIMM0 Bank Locator: BANK 2 [tong@T7 ~]$ sudo dmidecode -t memory |grep Speed Speed: 1600 MHz Configured Clock Speed: 1600 MHz Speed: 1600 MHz Configured Clock Speed: 1600 MHz [tong@T7 ~]$
網卡:
設備相關的內容。最近無業,手上都是家庭環境,沒有專有設備。略。
BOIS:
硬件 passthrough 啟用 vt-d。前文介紹過了。
Kernel設置:
大頁 / isolation core / iommu
dpdk設置:
基於硬件編譯庫 / 掛載大頁 / 查看cpu node 相關信息
[root@dpdk tools]# lstopo-no-graphics
查看網卡在哪個Node上:
[root@dpdk tools]# cat /sys/bus/pci/devices/0000\:00\:04.0/numa_node -1 [root@dpdk tools]#
很顯然這個輸出結果證明沒有node綁定。那么這玩意應該怎么綁上去啊???願意分享的請留言 : )
網卡綁定到用戶態驅動 vfio uio 等:
略,跟前邊一樣。
l3fwd
就是個check list。看源文檔。
至此,入門指南讀完,下一節讀開發指南 : )