5 # Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in
16 # the documentation and/or other materials provided with the
18 # * Neither the name of Intel Corporation nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 # Run with "source /path/to/setup.sh"
39 # Change to DPDK directory ( <this-script's-dir>/.. ), and export it as RTE_SDK
41 cd $(dirname ${BASH_SOURCE[0]})/..
43 echo "------------------------------------------------------------------------------"
44 echo " RTE_SDK exported as $RTE_SDK"
45 echo "------------------------------------------------------------------------------"
48 # Application EAL parameters for setting memory options (amount/channels/ranks).
53 # Sets QUIT variable so script will finish.
61 # Sets up environmental variables for ICC.
65 DEFAULT_PATH=/opt/intel/bin/iccvars.sh
67 shpath=`which iccvars.sh 2> /dev/null`
68 if [ $? -eq 0 ] ; then
69 echo "Loading iccvars.sh from $shpath for $param"
71 elif [ -f $DEFAULT_PATH ] ; then
72 echo "Loading iccvars.sh from $DEFAULT_PATH for $param"
73 source $DEFAULT_PATH $param
75 echo "## ERROR: cannot find 'iccvars.sh' script to set up ICC."
76 echo "## To fix, please add the directory that contains"
77 echo "## iccvars.sh to your 'PATH' environment variable."
83 # Sets RTE_TARGET and does a "make install".
88 export RTE_TARGET=${TARGETS[option]}
90 compiler=${RTE_TARGET##*-}
91 if [ "$compiler" == "icc" ] ; then
92 platform=${RTE_TARGET%%-*}
93 if [ "$platform" == "x86_64" ] ; then
99 if [ "$QUIT" == "0" ] ; then
100 make install T=${RTE_TARGET}
102 echo "------------------------------------------------------------------------------"
103 echo " RTE_TARGET exported as $RTE_TARGET"
104 echo "------------------------------------------------------------------------------"
108 # Uninstall all targets.
116 # Creates hugepage filesystem.
120 echo "Creating /mnt/huge and mounting as hugetlbfs"
121 sudo mkdir -p /mnt/huge
123 grep -s '/mnt/huge' /proc/mounts > /dev/null
124 if [ $? -ne 0 ] ; then
125 sudo mount -t hugetlbfs nodev /mnt/huge
130 # Removes hugepage filesystem.
134 echo "Unmounting /mnt/huge and removing directory"
135 grep -s '/mnt/huge' /proc/mounts > /dev/null
136 if [ $? -eq 0 ] ; then
137 sudo umount /mnt/huge
140 if [ -d /mnt/huge ] ; then
146 # Unloads igb_uio.ko.
148 remove_igb_uio_module()
150 echo "Unloading any existing DPDK UIO module"
151 /sbin/lsmod | grep -s igb_uio > /dev/null
152 if [ $? -eq 0 ] ; then
153 sudo /sbin/rmmod igb_uio
158 # Loads new igb_uio.ko (and uio module if needed).
160 load_igb_uio_module()
162 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko ];then
163 echo "## ERROR: Target does not have the DPDK UIO Kernel Module."
164 echo " To fix, please try to rebuild target."
168 remove_igb_uio_module
170 /sbin/lsmod | grep -s uio > /dev/null
171 if [ $? -ne 0 ] ; then
172 if [ -f /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko ] ; then
173 echo "Loading uio module"
174 sudo /sbin/modprobe uio
178 # UIO may be compiled into kernel, so it may not be an error if it can't
181 echo "Loading DPDK UIO module"
182 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko
183 if [ $? -ne 0 ] ; then
184 echo "## ERROR: Could not load kmod/igb_uio.ko."
190 # Unloads VFIO modules.
194 echo "Unloading any existing VFIO module"
195 /sbin/lsmod | grep -s vfio > /dev/null
196 if [ $? -eq 0 ] ; then
197 sudo /sbin/rmmod vfio-pci
198 sudo /sbin/rmmod vfio_iommu_type1
199 sudo /sbin/rmmod vfio
204 # Loads new vfio-pci (and vfio module if needed).
210 VFIO_PATH="kernel/drivers/vfio/pci/vfio-pci.ko"
212 echo "Loading VFIO module"
213 /sbin/lsmod | grep -s vfio_pci > /dev/null
214 if [ $? -ne 0 ] ; then
215 if [ -f /lib/modules/$(uname -r)/$VFIO_PATH ] ; then
216 sudo /sbin/modprobe vfio-pci
220 # make sure regular users can read /dev/vfio
221 echo "chmod /dev/vfio"
222 sudo /usr/bin/chmod a+x /dev/vfio
223 if [ $? -ne 0 ] ; then
229 # check if /dev/vfio/vfio exists - that way we
230 # know we either loaded the module, or it was
231 # compiled into the kernel
232 if [ ! -e /dev/vfio/vfio ] ; then
233 echo "## ERROR: VFIO not found!"
238 # Unloads the rte_kni.ko module.
242 echo "Unloading any existing DPDK KNI module"
243 /sbin/lsmod | grep -s rte_kni > /dev/null
244 if [ $? -eq 0 ] ; then
245 sudo /sbin/rmmod rte_kni
250 # Loads the rte_kni.ko module.
254 # Check that the KNI module is already built.
255 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko ];then
256 echo "## ERROR: Target does not have the DPDK KNI Module."
257 echo " To fix, please try to rebuild target."
261 # Unload existing version if present.
264 # Now try load the KNI module.
265 echo "Loading DPDK KNI module"
266 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko
267 if [ $? -ne 0 ] ; then
268 echo "## ERROR: Could not load kmod/rte_kni.ko."
274 # Sets appropriate permissions on /dev/vfio/* files
276 set_vfio_permissions()
278 # make sure regular users can read /dev/vfio
279 echo "chmod /dev/vfio"
280 sudo /usr/bin/chmod a+x /dev/vfio
281 if [ $? -ne 0 ] ; then
287 # make sure regular user can access everything inside /dev/vfio
288 echo "chmod /dev/vfio/*"
289 sudo /usr/bin/chmod 0666 /dev/vfio/*
290 if [ $? -ne 0 ] ; then
296 # since permissions are only to be set when running as
297 # regular user, we only check ulimit here
299 # warn if regular user is only allowed
300 # to memlock <64M of memory
301 MEMLOCK_AMNT=`ulimit -l`
303 if [ "$MEMLOCK_AMNT" != "unlimited" ] ; then
304 MEMLOCK_MB=`expr $MEMLOCK_AMNT / 1024`
306 echo "Current user memlock limit: ${MEMLOCK_MB} MB"
308 echo "This is the maximum amount of memory you will be"
309 echo "able to use with DPDK and VFIO if run as current user."
310 echo -n "To change this, please adjust limits.conf memlock "
311 echo "limit for current user."
313 if [ $MEMLOCK_AMNT -lt 65536 ] ; then
315 echo "## WARNING: memlock limit is less than 64MB"
316 echo -n "## DPDK with VFIO may not be able to initialize "
317 echo "if run as current user."
323 # Removes all reserved hugepages.
328 for d in /sys/devices/system/node/node? ; do
329 echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
331 echo "Removing currently reserved hugepages"
346 echo " Input the number of 2MB pages"
347 echo " Example: to have 128MB of hugepages available, enter '64' to"
348 echo " reserve 64 * 2MB pages"
349 echo -n "Number of pages: "
352 echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
354 echo "Reserving hugepages"
362 # Creates hugepages on specific NUMA nodes.
369 echo " Input the number of 2MB pages for each node"
370 echo " Example: to have 128MB of hugepages available per node,"
371 echo " enter '64' to reserve 64 * 2MB pages on each node"
374 for d in /sys/devices/system/node/node? ; do
376 echo -n "Number of pages for $node: "
378 echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
380 echo "Reserving hugepages"
388 # Run unit test application.
393 echo " Enter hex bitmask of cores to execute test app on"
394 echo " Example: to execute app on cores 0 to 7, enter 0xff"
398 sudo ${RTE_TARGET}/app/test -c $Bitmask $EAL_PARAMS
402 # Run unit testpmd application.
407 echo " Enter hex bitmask of cores to execute testpmd app on"
408 echo " Example: to execute app on cores 0 to 7, enter 0xff"
412 sudo ${RTE_TARGET}/app/testpmd -c $Bitmask $EAL_PARAMS -- -i
416 # Print hugepage information.
420 grep -i huge /proc/meminfo
424 # Calls dpdk_nic_bind.py --status to show the NIC and what they
425 # are all bound to, in terms of drivers.
429 if /sbin/lsmod | grep -q igb_uio ; then
430 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
432 echo "# Please load the 'igb_uio' kernel module before querying or "
433 echo "# adjusting NIC device bindings"
438 # Uses dpdk_nic_bind.py to move devices to work with igb_uio
442 if /sbin/lsmod | grep -q vfio_pci ; then
443 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
445 echo -n "Enter PCI address of device to bind to VFIO driver: "
447 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b vfio-pci $PCI_PATH &&
450 echo "# Please load the 'vfio-pci' kernel module before querying or "
451 echo "# adjusting NIC device bindings"
456 # Uses dpdk_nic_bind.py to move devices to work with igb_uio
458 bind_nics_to_igb_uio()
460 if /sbin/lsmod | grep -q igb_uio ; then
461 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
463 echo -n "Enter PCI address of device to bind to IGB UIO driver: "
465 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b igb_uio $PCI_PATH && echo "OK"
467 echo "# Please load the 'igb_uio' kernel module before querying or "
468 echo "# adjusting NIC device bindings"
473 # Uses dpdk_nic_bind.py to move devices to work with kernel drivers again
477 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
479 echo -n "Enter PCI address of device to bind to IGB UIO driver: "
482 echo -n "Enter name of kernel driver to bind the device to: "
484 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b $DRV $PCI_PATH && echo "OK"
488 # Options for building a target. Note that this step MUST be first as it sets
489 # up TARGETS[] starting from 1, and this is accessed in setup_target using the
490 # user entered option.
494 TITLE="Select the DPDK environment to build"
496 for cfg in config/defconfig_* ; do
497 cfg=${cfg/config\/defconfig_/}
498 TEXT[$CONFIG_NUM]="$cfg"
499 TARGETS[$CONFIG_NUM]=$cfg
500 FUNC[$CONFIG_NUM]="setup_target"
506 # Options for setting up environment.
510 TITLE="Setup linuxapp environment"
512 TEXT[1]="Insert IGB UIO module"
513 FUNC[1]="load_igb_uio_module"
515 TEXT[2]="Insert VFIO module"
516 FUNC[2]="load_vfio_module"
518 TEXT[3]="Insert KNI module"
519 FUNC[3]="load_kni_module"
521 TEXT[4]="Setup hugepage mappings for non-NUMA systems"
522 FUNC[4]="set_non_numa_pages"
524 TEXT[5]="Setup hugepage mappings for NUMA systems"
525 FUNC[5]="set_numa_pages"
527 TEXT[6]="Display current Ethernet device settings"
530 TEXT[7]="Bind Ethernet device to IGB UIO module"
531 FUNC[7]="bind_nics_to_igb_uio"
533 TEXT[8]="Bind Ethernet device to VFIO module"
534 FUNC[8]="bind_nics_to_vfio"
536 TEXT[9]="Setup VFIO permissions"
537 FUNC[9]="set_vfio_permissions"
541 # Options for running applications.
545 TITLE="Run test application for linuxapp environment"
547 TEXT[1]="Run test application (\$RTE_TARGET/app/test)"
548 FUNC[1]="run_test_app"
550 TEXT[2]="Run testpmd application in interactive mode (\$RTE_TARGET/app/testpmd)"
551 FUNC[2]="run_testpmd_app"
561 TEXT[1]="List hugepage info from /proc/meminfo"
562 FUNC[1]="grep_meminfo"
567 # Options for cleaning up the system
571 TITLE="Uninstall and system cleanup"
573 TEXT[1]="Uninstall all targets"
574 FUNC[1]="uninstall_targets"
576 TEXT[2]="Unbind NICs from IGB UIO driver"
577 FUNC[2]="unbind_nics"
579 TEXT[3]="Remove IGB UIO module"
580 FUNC[3]="remove_igb_uio_module"
582 TEXT[4]="Remove VFIO module"
583 FUNC[4]="remove_vfio_module"
585 TEXT[5]="Remove KNI module"
586 FUNC[5]="remove_kni_module"
588 TEXT[6]="Remove hugepage mappings"
589 FUNC[6]="clear_huge_pages"
592 STEPS[1]="step1_func"
593 STEPS[2]="step2_func"
594 STEPS[3]="step3_func"
595 STEPS[4]="step4_func"
596 STEPS[5]="step5_func"
600 while [ "$QUIT" == "0" ]; do
603 for s in $(seq ${#STEPS[@]}) ; do
606 echo "----------------------------------------------------------"
607 echo " Step $s: ${TITLE}"
608 echo "----------------------------------------------------------"
610 for i in $(seq ${#TEXT[@]}) ; do
611 echo "[$OPTION_NUM] ${TEXT[i]}"
612 OPTIONS[$OPTION_NUM]=${FUNC[i]}
616 # Clear TEXT and FUNC arrays before next step
623 echo "[$OPTION_NUM] Exit Script"
624 OPTIONS[$OPTION_NUM]="quit"
629 ${OPTIONS[our_entry]} ${our_entry}
631 echo -n "Press enter to continue ..."; read