聲明:此文檔只做學(xué)習(xí)交流使用,請勿用作其他商業(yè)用途
author:朝陽_tony
E-mail : linzhaolover@gmail.com
Create Date: 2013-12-28 23:38:47 Saturday
Last Change: 2014-1-1 22:33:42 Wednesday
轉(zhuǎn)載請注明出處:http://blog.csdn.net/linzhaolover
intel DPDK交流群希望大家加入互相學(xué)習(xí),QQ群號:289784125
此文請結(jié)合intel dpdk源碼去閱讀,基于dpdk-1.5.1 版本源碼講解,源碼可以去http://dpdk.org/dev網(wǎng)頁中下載征候;更多官方文檔請訪問http://dpdk.org/
假如你沒有intel的網(wǎng)卡,沒有相應(yīng)的linux系統(tǒng)洒忧,只是想簡單的使用了解一下dpdk葵孤,那么你可以選擇在vmware中部署一套簡單的dpdk環(huán)境;
1刀脏、在vmware中安裝配置適合dpdk運行的虛擬機蟀淮;
1)最住、虛擬機的配置要求,
vcpu = 2 ? 最少兩個cpu怠惶,因為dpdk是需要綁定core涨缚,一個是沒辦正常運行dpdk的,如你電腦運行甚疟,最好多配置幾個仗岖;
memory=1024 ? 也就是1G 逃延,當(dāng)然越多越好,因為要配置hugepage轧拄,還是多分點吧揽祥;
系統(tǒng),我裝的是rhel6.1 檩电,當(dāng)然你可以選擇更高版本拄丰,但不能選擇低版本,怕不支持俐末;http://blog.csdn.net/linzhaolover/article/details/8223568這有 RHEL6.3 6.4 6.5的下載地址料按;
系統(tǒng)的在裝好后要更新一下kernel,我目前虛擬機里使用的是 linux-3.3.2卓箫,你最好選擇3.0 至3.8之間的载矿,這之間的kernel有些人用過,是可以跑起dpdk的烹卒;
網(wǎng)卡闷盔, 給兩個吧,
vmware裝虛擬機系統(tǒng)我在這就不多說了旅急,網(wǎng)上有很多的教程逢勾;
2)、添加dpdk支持的網(wǎng)卡
同學(xué)們虛擬網(wǎng)卡藐吮,大家就不要吝嗇了溺拱,至少添加兩塊intel 網(wǎng)卡吧;因為一塊會報錯誤谣辞;
dpdk是intel出的迫摔,目前似乎只支持intel的網(wǎng)卡,在裝好虛擬機好潦闲,我們看一下當(dāng)前虛擬機的網(wǎng)卡是什么樣的攒菠;用lspci命令查看;
[cpp]view plaincopy
#?lspci??|?grep?Ethernet
02:01.0?Ethernet?controller:?Advanced?Micro?Devices?[AMD]?79c970?[PCnet32?LANCE]?(rev?10)
02:05.0?Ethernet?controller:?Advanced?Micro?Devices?[AMD]?79c970?[PCnet32?LANCE]?(rev?10)
vmware安裝虛擬機歉闰,默認(rèn)的網(wǎng)卡是amd的,我們該怎樣正確添加intel的網(wǎng)卡呢卓起?和敬??戏阅?昼弟??
好吧奕筐,先將虛擬機shutdown舱痘;
再添加一塊網(wǎng)卡变骡,這時別急,先不啟動虛擬機芭逝;我們還需要去修改一下當(dāng)前虛擬機的配置文件塌碌,
我的配置文件時在E:\Users\adm\Documents\Virtual Machines\Red Hat Enterprise Linux 5\Red Hat 6.vmx
你在安裝虛擬機時,應(yīng)該選擇了其工作目錄旬盯,自己將鼠標(biāo)放在VMware左側(cè)欄你創(chuàng)建的虛擬機名字處台妆,就會自動顯示它的工作目錄的了;
用記事本打開配置文件胖翰,然后添加一行
[cpp]view plaincopy
ethernet2.virtualDev?="e1000"
由于我的是添加的第3塊網(wǎng)卡了接剩,如果從0開始數(shù),剛好是eth2萨咳,添加后的樣子是
[cpp]view plaincopy
ethernet2.virtualDev?="e1000"
ethernet2.present?="TRUE"
e1000是intel的網(wǎng)卡中的一個千兆網(wǎng)卡懊缺;
好了,在重新啟動虛擬機培他,查看一下網(wǎng)卡鹃两,多了一個82545em 的網(wǎng)卡,
[cpp]view plaincopy
#?lspci??|?grep?Ethernet
02:01.0?Ethernet?controller:?Advanced?Micro?Devices?[AMD]?79c970?[PCnet32?LANCE]?(rev?10)
02:05.0?Ethernet?controller:?Advanced?Micro?Devices?[AMD]?79c970?[PCnet32?LANCE]?(rev?10)
02:06.0?Ethernet?controller:?Intel?Corporation?82545EM?Gigabit?Ethernet?Controller?(Copper)?(rev?01)
2靶壮、部署dpdk
1)怔毛、下載源碼
在開啟虛擬機后,從dpdk官網(wǎng)下載最新的code
[cpp]view plaincopy
git?clone?git://dpdk.org/dpdk
2)腾降、設(shè)置環(huán)境變量
進(jìn)入dpdk目錄拣度;編輯一個環(huán)境變量文件,然后source螃壤;
[cpp]view plaincopy
export?RTE_SDK=`pwd`
#export?RTE_TARGET=x86_64-default-linuxapp-gcc
export?RTE_TARGET=i686-default-linuxapp-gcc
由于我的是32虛擬機抗果,所以我選擇i686,將x86_64那行環(huán)境變量注釋掉奸晴;
我將上面3行放在dpdkrc文件中冤馏,然后用source啟用這幾個環(huán)境變量;
[cpp]view plaincopy
source??dpkdrc
注意寄啼,你以后如果從新登陸終端逮光,進(jìn)入這個目錄,都要source一下這個文件墩划,才能正常運行dpdk的程序涕刚;
3)、用dpdk的腳本運行dpdk乙帮;
運行腳本進(jìn)行dpdk測試杜漠;
然后再運行腳本
[cpp]view plaincopy
./tools/setup.sh
[html]view plaincopy
----------------------------------------------------------
Step?1:?Select?the?DPDK?environment?to?build
----------------------------------------------------------
[1]?i686-default-linuxapp-gcc
[2]?i686-default-linuxapp-icc
[3]?x86_64-default-linuxapp-gcc
[4]?x86_64-default-linuxapp-icc
選擇 ? ?1
我的是32位系統(tǒng),所以我選擇 ? ?1 ? , 采用gcc編譯32位源碼驾茴;如果你是64位虛擬機盼樟,請選擇 ?3
[cpp]view plaincopy
----------------------------------------------------------
Step?2:?Setup?linuxapp?environment
----------------------------------------------------------
[5]?Insert?IGB?UIO?module
[6]?Insert?KNI?module
[7]?Setup?hugepage?mappingsfornon-NUMA?systems
[8]?Setup?hugepage?mappingsforNUMA?systems
[9]?Display?current?Ethernet?device?settings
[10]?Bind?Ethernet?device?to?IGB?UIO?module
編譯ok后,
選擇 ?5
進(jìn)行igb_uio.ko驅(qū)動的安裝锈至,這個驅(qū)動在編譯后是晨缴,在i686-default-linuxapp-gcc/kmod/ 目錄中;其實在安裝igb_uio.ko之前裹赴,腳本先安裝了uio模塊喜庞,uio是一種用戶態(tài)驅(qū)動的實現(xiàn)機制,dpdk有些東西時基于uio實現(xiàn)的棋返;有興趣的可以了解一下uio的驅(qū)動使用http://blog.csdn.net/wenwuge_topsec/article/details/9628409
選擇 7
設(shè)置hugepage延都,
[cpp]view plaincopy
Removing?currently?reserved?hugepages
.echo_tmp:?line?2:?/sys/devices/system/node/node?/hugepages/hugepages-2048kB/nr_hugepages:?沒有那個文件或目錄
Unmounting?/mnt/huge?and?removing?directory
Input?the?number?of?2MB?pages
Example:?to?have?128MB?of?hugepages?available,?enter'64'to
reserve?64?*?2MB?pages
Number?of?pages:?64
Reserving?hugepages
Creating?/mnt/huge?and?mounting?as?hugetlbfs
提示沒有nr_hugepage文件,我沒有理它睛竣,暫且不知道起原因晰房;
有讓你輸入預(yù)留內(nèi)存大小的 我輸入的是 ?64 ?, ? 64 ?乘以 2M ?可以128M 做個簡單的測試夠了射沟,
選 9
看一下你當(dāng)前的設(shè)備
[cpp]view plaincopy
Option:?9
Network?devicesusingIGB_UIO?driver
====================================
Network?devicesusingkernel?driver
===================================
0000:02:01.0'79c970?[PCnet32?LANCE]'if=eth0?drv=pcnet32?unused=?*Active*
0000:02:05.0'79c970?[PCnet32?LANCE]'if=eth1?drv=pcnet32?unused=?*Active*
0000:02:06.0'82545EM?Gigabit?Ethernet?Controller?(Copper)'if=eth2?drv=e1000?unused=igb_uio
Other?network?devices
=====================
我有3塊虛擬網(wǎng)卡殊者,只有最后一個是intel的網(wǎng)卡,看他已經(jīng)提示當(dāng)前的網(wǎng)卡驅(qū)動而是 e1000而沒有用igb_uio , 接下來就是讓你去綁定它验夯;
選擇10
進(jìn)行 網(wǎng)卡bind
[cpp]view plaincopy
Option:?10
Network?devicesusingIGB_UIO?driver
====================================
Network?devicesusingkernel?driver
===================================
0000:02:01.0'79c970?[PCnet32?LANCE]'if=eth0?drv=pcnet32?unused=?*Active*
0000:02:05.0'79c970?[PCnet32?LANCE]'if=eth1?drv=pcnet32?unused=?*Active*
0000:02:06.0'82545EM?Gigabit?Ethernet?Controller?(Copper)'if=eth2?drv=e1000?unused=igb_uio
Other?network?devices
=====================
Enter?PCI?address?of?device?to?bind?to?IGB?UIO?driver:?02:06.0
OK
讓你輸入pci的地址猖吴, 你只要將0000:02:06.0 ?中的,0000冒號后面的幾位輸入就行了挥转, ?如 ?02:06.0 ? 記得標(biāo)點也要輸入啊海蔽,
注意綁定的時候可以能有個錯誤的提示如下;
[cpp]view plaincopy
Enter?PCI?address?of?device?to?bind?to?IGB?UIO?driver:?02:06.0?02:07.0
Routing?table?indicates?that?interface?0000:02:06.0?is?active.?Not?modifying
OK
is active 绑谣,可能是你當(dāng)前的對應(yīng)的網(wǎng)卡處于up狀態(tài)党窜,所以你要執(zhí)行down命令將其關(guān)閉;
例如我的網(wǎng)卡是eth2借宵;
[cpp]view plaincopy
ifconfig?eth2?down
關(guān)閉后再重新執(zhí)行一下上面的綁定操作幌衣;
再選擇 9
就看一下當(dāng)前的網(wǎng)卡狀態(tài);
[cpp]view plaincopy
Option:?9
Network?devicesusingIGB_UIO?driver
====================================
0000:02:06.0'82545EM?Gigabit?Ethernet?Controller?(Copper)'drv=igb_uio?unused=e1000
Network?devicesusingkernel?driver
===================================
0000:02:01.0'79c970?[PCnet32?LANCE]'if=eth0?drv=pcnet32?unused=?*Active*
0000:02:05.0'79c970?[PCnet32?LANCE]'if=eth1?drv=pcnet32?unused=?*Active*
Other?network?devices
=====================
看 ?drv=igb_uio ?驅(qū)動已經(jīng)幫過去了壤玫,現(xiàn)在intel網(wǎng)卡的去的是igb_uio;
選擇 ?12
測試一下dpdk程序
[cpp]view plaincopy
Option:?12
Enter?hex?bitmask?of?cores?to?execute?testpmd?app?on
Example:?to?execute?app?on?cores?0?to?7,?enter?0xff
bitmask:?0x3
由于我的虛擬機只有2個cpu 豁护,所以按照16進(jìn)制掩碼就選擇了 0x3 ?,回車運行一下試試 欲间;
再輸入 ?start發(fā)一下包
[cpp]view plaincopy
Interactive-mode?selected
Configuring?Port?0?(socket?-1)
Checking?link?statuses...
Port?0?Link?Up?-?speed?1000?Mbps?-?full-duplex
Done
testpmd>
testpmd>?start
Warning!?Cannot?handle?an?odd?number?of?ports?with?the?current?port?topology.?Configuration?must?be?changed?to?have?an?even?number?of?ports,?or?relaunch?application?with?--port-topology=chained
io?packet?forwarding?-?CRC?stripping?disabled?-?packets/burst=16
nb?forwarding?cores=1?-?nb?forwarding?ports=1
RX?queues=1?-?RX?desc=128?-?RX?free?threshold=0
RX?threshold?registers:?pthresh=8?hthresh=8?wthresh=4
TX?queues=1?-?TX?desc=512?-?TX?free?threshold=0
TX?threshold?registers:?pthresh=36?hthresh=0?wthresh=0
TX?RS?bit?threshold=0?-?TXQ?flags=0x0
有警告择镇,是什么意思,括改???嘱能?吝梅??惹骂?苏携?
2014年1月1日22:32:10 星期三
上面這個錯誤,經(jīng)由同樣學(xué)習(xí)dpdk 的同學(xué)frank解決了对粪,是因為我只添加了1塊intel的網(wǎng)卡右冻,你在再添加一塊就ok了
輸入stop 停止;
[cpp]view plaincopy
Telling?cores?to?stop...
Waitingforlcores?to?finish...
----------------------?Forward?statisticsforport?0??----------------------
RX-packets:?0??????????????RX-dropped:?0?????????????RX-total:?0
TX-packets:?0??????????????TX-dropped:?0?????????????TX-total:?0
----------------------------------------------------------------------------
+++++++++++++++?Accumulated?forward?statisticsforall?ports+++++++++++++++
RX-packets:?0??????????????RX-dropped:?0?????????????RX-total:?0
TX-packets:?0??????????????TX-dropped:?0?????????????TX-total:?0
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Done.
為什么沒有數(shù)據(jù)包呢著拭?纱扭??儡遮?乳蛾??鄙币?肃叶?? ? ? 誰知道十嘿,告訴我一下因惭;
2014年1月1日22:38:16 ?星期三
上面沒有數(shù)據(jù)的問題解決了,O(∩_∩)O~绩衷,原始是我將網(wǎng)卡模式添加時用的NAT模式蹦魔,給修改成了HOSTONLY模式,哎唇聘,但我還是有疑問版姑,只兩個模式有什么重要區(qū)別嗎?迟郎?剥险??
[cpp]view plaincopy
----------------------?Forward?statisticsforport?0??----------------------
RX-packets:?8890???????????RX-dropped:?0?????????????RX-total:?8890
TX-packets:?8894???????????TX-dropped:?0?????????????TX-total:?8894
----------------------------------------------------------------------------
----------------------?Forward?statisticsforport?1??----------------------
RX-packets:?8895???????????RX-dropped:?0?????????????RX-total:?8895
TX-packets:?8889???????????TX-dropped:?0?????????????TX-total:?8889
----------------------------------------------------------------------------
+++++++++++++++?Accumulated?forward?statisticsforall?ports+++++++++++++++
RX-packets:?17785??????????RX-dropped:?0?????????????RX-total:?17785
TX-packets:?17783??????????TX-dropped:?0?????????????TX-total:?17783
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++