<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>l3fwd &#8211; richliu&#039;s blog</title>
	<atom:link href="https://blog.richliu.com/tag/l3fwd/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Thu, 12 Sep 2019 02:29:58 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>Ubuntu 18.04 ARM64 DPDK in VM (QEMU)</title>
		<link>https://blog.richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/</link>
					<comments>https://blog.richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Mon, 19 Aug 2019 08:17:56 +0000</pubDate>
				<category><![CDATA[ARM]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[18.04]]></category>
		<category><![CDATA[aarch64]]></category>
		<category><![CDATA[arm64]]></category>
		<category><![CDATA[dpdk]]></category>
		<category><![CDATA[hugepages]]></category>
		<category><![CDATA[l3fwd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://blog.richliu.com/?p=4057</guid>

					<description><![CDATA[<p>DPDK is a very popular infrastructure in high speed pac [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/">Ubuntu 18.04 ARM64 DPDK in VM (QEMU)</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>DPDK is a very popular infrastructure in high speed packet process domain, some applications will used the same architecture to process packet, like EPC. <br /><br />For Ubuntu 18.04, it used dpdk 17.11, it not good for some other application like dpdk pktgen, but enough for testpmd and l3fwd test. here is some personal note for setup whole environment. </p>



<figure class="wp-block-image is-resized"><img fetchpriority="high" decoding="async" src="https://blog.richliu.com/wp-content/uploads/2019/08/image-3.png" alt="" class="wp-image-4076" width="363" height="257" srcset="https://blog.richliu.com/wp-content/uploads/2019/08/image-3.png 634w, https://blog.richliu.com/wp-content/uploads/2019/08/image-3-300x213.png 300w" sizes="(max-width: 363px) 100vw, 363px" /><figcaption>DPDK in QEMU archeticture</figcaption></figure>



<span id="more-4057"></span>



<p>Hardware : Ampere eMag Server with 128GB Memory <br />                      Network Card: Intel i210 Gigabit NIC Card * 2 <br /><br />HOST means commands and instructions on host machines <br />VM means commands and instructions inside VM</p>



<h2 class="wp-block-heading">Prepare Environment</h2>



<h4 class="wp-block-heading">Apt source</h4>



<p>First, please add deb-src to your database, edit file /etc/apt/source.list and removed all &#8220;#&#8221; before deb-src, then, run follow commands to update apt database (suppose all commands run with sudo or root in this article)</p>



<pre class="wp-block-preformatted">sed -i 's/# deb-src/deb-src/g' sources.list
apt update</pre>



<h4 class="wp-block-heading">Install Packages</h4>



<p>It needs to install relative packages in host </p>



<pre class="wp-block-preformatted">sudo apt install -y dpdk dpdk-dev dpdk-doc </pre>



<p>Only needs to install on HOST.</p>



<pre class="wp-block-preformatted">sudo apt install -y qemu-efi bridge-utils</pre>



<p>It will install all necessary dpdk packages in host.</p>



<h4 class="wp-block-heading">Preload Module</h4>



<p>It needs to preload vfio-pci modules by default, run following command</p>



<pre class="wp-block-preformatted">echo "vfio-pci" &gt;&gt; /etc/modules</pre>



<h4 class="wp-block-heading">Configure Line Kernel boot command</h4>



<p>It needs to reserve hugepages memory space for Linux kernel, it reserves 32 pages and each pages 1GB, total 32GB. Please modify  /etc/default/grub , and  add hugepagesz=1GB hugepages=32 to GRUB_CMDLINE_LINUX, ex:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>GRUB_CMDLINE_LINUX=&#8221;console=tty0 hugepagesz=1GB hugepages=32&#8243;</p></blockquote>



<p>then run foloowing command to update grub.cfg</p>



<pre class="wp-block-preformatted">update-grub</pre>



<p>Mount hugetlbfs by default</p>



<p>If wants to use hugepage, it needs to mount hugetlbfs somewhere, we can create a directory, ex: /mnt/hugepages and mount hugetblsfs there by default. </p>



<pre class="wp-block-preformatted">mkdir -p /mnt/hugepages
echo "nodev   /mnt/hugepages                  hugetlbfs       defaults,pagesize=1G    0 0 none" &gt;&gt; /etc/fstab</pre>



<h2 class="wp-block-heading">Bind Network Card for DPDK</h2>



<p>It wants to let DPDK use current network card, it needs to bind the network card with dpdk. dpdk-devbind command is a useful command. <br />List current command </p>



<pre class="wp-block-preformatted"> $ dpdk-devbind --status
 Network devices using kernel driver
 0001:01:00.0 'I210 Gigabit Network Connection 1533' if=enP1p1s0 drv=igb unused=vfio-pci
 0002:01:00.0 'I210 Gigabit Network Connection 1533' if=enP2p1s0 drv=igb unused=vfio-pci
 0006:01:00.0 'I210 Gigabit Network Connection 1533' if=enP6p1s0 drv=igb unused=vfio-pci <em>Active</em> </pre>



<p>There are three network card in the machine, we would like to bind 1:1:0.0 and 2:1:0.0 to vfio-pci driver. please used following command to bind those network cards. </p>



<pre class="wp-block-preformatted">dpdk-devbind -b vfio-pci 0001:01:00.0 0002:01:00.0</pre>



<p>and check status again</p>



<pre class="wp-block-preformatted"> $ dpdk-devbind --status

Network devices using DPDK-compatible driver
============================================
0001:01:00.0 'I210 Gigabit Network Connection 1533' drv=vfio-pci unused=igb
0002:01:00.0 'I210 Gigabit Network Connection 1533' drv=vfio-pci unused=igb

Network devices using kernel driver
============================================
0006:01:00.0 'I210 Gigabit Network Connection 1533' if=enP6p1s0 drv=igb unused=vfio-pci <em>Active</em> </pre>



<p>Both network cards would be under  Network devices using DPDK-compatible driver  . </p>



<h2 class="wp-block-heading">Prepare QEMU environment </h2>



<h4 class="wp-block-heading">Set up bridge devices  </h4>



<p>We already install bridge-utils before, now, it should configure bridge devices. </p>



<pre class="wp-block-preformatted">mkdir -p /etc/qemu
echo "allow br0" &gt; /etc/qemu/bridge.conf</pre>



<p>Because there is only one network interface on machine, we should use this interface as bridge device, save text below and modify it to fit your environment. </p>



<pre class="wp-block-preformatted"> ORIGNIC=enP6p1s0

 ip addr flush enP6p1s0


 brctl addbr br0
 brctl addif br0 enP6p1s0
 ifconfig br0 up
 ifconfig br0 192.168.110.1 netmask 255.255.0.0
 route add default gw 192.168.1.1


 echo nameserver 8.8.8.8 >> /etc/resolv.conf </pre>



<p>Run script, command brctl show will show how whether it configure property or not. </p>



<h2 class="wp-block-heading">Prepare QEMU image</h2>



<p>Ubuntu 18.04 cloud image is here</p>



<pre class="wp-block-preformatted">wget http://ftp.yzu.edu.tw/Linux/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-arm64.img</pre>



<p>and please refer this article to change cloud image&#8217;s password <br />Change Ubuntu Cloud Image Password, before use it, don&#8217;t forget to increase cloud image size. 20G is enough for test.</p>



<pre class="wp-block-preformatted">qemu-img resize bionic-server-cloudimg-arm64.img +20G</pre>



<p>Next step is to create bios and nvram for qemu image boot. </p>



<pre class="wp-block-preformatted">dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=/usr/share/qemu-efi/QEMU_EFI.fd of=flash0.img conv=notrunc
dd if=/dev/zero of=flash1.img bs=1M count=64</pre>



<h2 class="wp-block-heading">Run Qemu</h2>



<p>Here is qemu command, save text below and run it </p>



<pre class="wp-block-preformatted"> IMAGE=bionic-server-cloudimg-arm64.img
 sudo qemu-system-aarch64 -name vm1 \
         -machine virt,gic_version=3,accel=kvm,usb=off \
         -cpu host -m 8192 \
         -smp 12,sockets=1,cores=12,threads=1 \
         -nographic -nodefaults \
         -pflash flash0.img -pflash flash1.img \
         -device vfio-pci,host=0001:01:00.0 \
         -device vfio-pci,host=0002:01:00.0 \
         -drive file=$IMAGE,if=none,id=disk1 \
         -device virtio-blk-device,scsi=off,drive=disk1,id=virtio-disk1,bootindex=1 \
         -netdev tap,id=net0,ifname=tap0 \
         -device virtio-net-device,netdev=net0 \
         -mem-path /mnt/hugepages \
         -serial telnet::9001,server,nowait > guest1_log.txt 2>> guest1_log.txt &amp;
 sleep 5
 brctl addif br0 tap0 </pre>



<p>-m 8192 : use 8G RAM for VM<br />&#8211;mem-path will use /mnt/hugepages for VM memory<br /><br />it will create a network device tap0 for bridge device interface between VM and host.  and create a telnet server on port 9001, it can use &#8220;telnet 9001&#8221; to get console, I would like to suggest to use ssh if it can access console. </p>



<h2 class="wp-block-heading">Remove cloudinit service</h2>



<p>it needs to remove cloud-initramfs-copymods, it will copy modules from ramdisk to harddriver, and cloud-init, it&#8217;s for some cloud service like aws(?)<br /><br />removed them would help system runs better. </p>



<pre class="wp-block-preformatted">apt remove cloud-initramfs-copymods cloud-init </pre>



<h2 class="wp-block-heading">Disable Services</h2>



<p>After boot, it needs to disable some default service to improve speed, here is some services can be disabled. (needs run those command with root)</p>



<pre class="wp-block-preformatted">systemctl disable ufw
systemctl disable lxcfs
systemctl disable atd
systemctl disable cron
systemctl disable irqbalance
systemctl disable apparmor
systemctl disable apport
systemctl disable ebtables
systemctl disable grub-common
systemctl disable unattended-upgrades
systemctl disable iscsid</pre>



<p>Most import service is irqbalance, without disable it, performance will be drop down. <br /><br />Now, it can reboot VM now. </p>



<h2 class="wp-block-heading">Prepare QEMU environment </h2>



<p>Prepare QEMU environment and prepare host almost the same, only differences are</p>



<ol class="wp-block-list"><li>in QEMU, apt install doesn&#8217;t needs to install qemu-efi and bridge-utils</li><li>in QEMU, before call dpdk-devbind command, it needs to configure enable_unsafe_noiommu_mode for ARM64 platform </li><li>Hugepage size is different , in HOST it uses 32G, in VM we uses 4G</li></ol>



<p>Enable unsafe noiommu </p>



<pre class="wp-block-preformatted">echo 1 &gt; /sys/module/vfio/parameters/enable_unsafe_*</pre>



<p> To permanently enable the no-IOMMU mode, add it to modprobe.d: (<a href="https://dpdk-guide.gitlab.io/dpdk-guide/setup/binding.html" target="_blank" rel="noopener">ref</a>) </p>



<pre class="wp-block-preformatted">echo "options vfio enable_unsafe_noiommu_mode=1" &gt; /etc/modprobe.d/vfio-noiommu.conf</pre>



<p>It also needs to reserve hugepages memory space for Linux kernel for VM, it reserves 4 pages and each pages 1GB, total 4GB. Please modify  /etc/default/grub , and  add hugepagesz=1GB hugepages=4 to GRUB_CMDLINE_LINUX, ex:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>GRUB_CMDLINE_LINUX=&#8221;console=tty0 hugepagesz=1GB hugepages=4&#8243;</p></blockquote>



<p>then run foloowing command to update grub.cfg</p>



<pre class="wp-block-preformatted">update-grub</pre>



<h2 class="wp-block-heading">Run DPDK  l3fwd</h2>



<p>Before run l3fwd, we need to recompile it. </p>



<pre class="wp-block-preformatted">. /usr/share/dpdk/dpdk-sdk-env.sh
make -C /usr/share/dpdk/examples/l3fwd</pre>



<p>Bind network interface</p>



<pre class="wp-block-preformatted">dpdk-devbind -b vfio-pci  enp0s1
dpdk-devbind -b vfio-pci  enp0s2</pre>



<p>Run l3fwd example</p>



<pre class="wp-block-preformatted">cd /usr/share/dpdk/examples/l3fwd/build
./l3fwd -c 1 -- -p 0x3 --config="(0,0,0),(1,0,0)"</pre>



<figure class="wp-block-image"><img decoding="async" width="1024" height="639" src="https://blog.richliu.com/wp-content/uploads/2019/08/image-1024x639.png" alt="" class="wp-image-4072" srcset="https://blog.richliu.com/wp-content/uploads/2019/08/image-1024x639.png 1024w, https://blog.richliu.com/wp-content/uploads/2019/08/image-300x187.png 300w, https://blog.richliu.com/wp-content/uploads/2019/08/image-768x479.png 768w, https://blog.richliu.com/wp-content/uploads/2019/08/image.png 1440w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Multi Queue example</p>



<pre class="wp-block-preformatted">./l3fwd -l 1,2,3,4 -n 4 -- -p 0x3 --config="(0,0,1),(1,0,2),(0,1,3),(1,1,4)"</pre>



<figure class="wp-block-image"><img decoding="async" width="1024" height="715" src="https://blog.richliu.com/wp-content/uploads/2019/08/image-1-1024x715.png" alt="" class="wp-image-4073" srcset="https://blog.richliu.com/wp-content/uploads/2019/08/image-1-1024x715.png 1024w, https://blog.richliu.com/wp-content/uploads/2019/08/image-1-300x209.png 300w, https://blog.richliu.com/wp-content/uploads/2019/08/image-1-768x536.png 768w, https://blog.richliu.com/wp-content/uploads/2019/08/image-1.png 1438w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">Other</h2>



<p>There is good tool to get hugepage information </p>



<pre class="wp-block-preformatted">apt install hugepages
hugeadm --pool-list</pre>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="865" height="130" src="https://blog.richliu.com/wp-content/uploads/2019/08/image-2.png" alt="" class="wp-image-4074" srcset="https://blog.richliu.com/wp-content/uploads/2019/08/image-2.png 865w, https://blog.richliu.com/wp-content/uploads/2019/08/image-2-300x45.png 300w, https://blog.richliu.com/wp-content/uploads/2019/08/image-2-768x115.png 768w" sizes="(max-width: 865px) 100vw, 865px" /></figure>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/">Ubuntu 18.04 ARM64 DPDK in VM (QEMU)</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.richliu.com/2019/08/19/4057/ubuntu-18-04-arm64-dpdk-in-vm-qemu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
