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.
67 # Sets up environmental variables for ICC.
71 DEFAULT_PATH=/opt/intel/bin/iccvars.sh
73 shpath=`which iccvars.sh 2> /dev/null`
74 if [ $? -eq 0 ] ; then
75 echo "Loading iccvars.sh from $shpath for $param"
77 elif [ -f $DEFAULT_PATH ] ; then
78 echo "Loading iccvars.sh from $DEFAULT_PATH for $param"
79 source $DEFAULT_PATH $param
81 echo "## ERROR: cannot find 'iccvars.sh' script to set up ICC."
82 echo "## To fix, please add the directory that contains"
83 echo "## iccvars.sh to your 'PATH' environment variable."
89 # Sets RTE_TARGET and does a "make install".
94 export RTE_TARGET=${TARGETS[option]}
96 compiler=${RTE_TARGET##*-}
97 if [ "$compiler" == "icc" ] ; then
98 platform=${RTE_TARGET%%-*}
99 if [ "$platform" == "x86_64" ] ; then
105 if [ "$QUIT" == "0" ] ; then
106 make install T=${RTE_TARGET}
108 echo "------------------------------------------------------------------------------"
109 echo " RTE_TARGET exported as $RTE_TARGET"
110 echo "------------------------------------------------------------------------------"
114 # Creates hugepage filesystem.
118 echo "Creating /mnt/huge and mounting as hugetlbfs"
119 sudo mkdir -p /mnt/huge
121 grep -s '/mnt/huge' /proc/mounts > /dev/null
122 if [ $? -ne 0 ] ; then
123 sudo mount -t hugetlbfs nodev /mnt/huge
128 # Removes hugepage filesystem.
132 echo "Unmounting /mnt/huge and removing directory"
133 grep -s '/mnt/huge' /proc/mounts > /dev/null
134 if [ $? -eq 0 ] ; then
135 sudo umount /mnt/huge
138 if [ -d /mnt/huge ] ; then
144 # Unloads igb_uio.ko.
146 remove_igb_uio_module()
148 echo "Unloading any existing DPDK UIO module"
149 /sbin/lsmod | grep -s igb_uio > /dev/null
150 if [ $? -eq 0 ] ; then
151 sudo /sbin/rmmod igb_uio
156 # Loads new igb_uio.ko (and uio module if needed).
158 load_igb_uio_module()
160 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko ];then
161 echo "## ERROR: Target does not have the DPDK UIO Kernel Module."
162 echo " To fix, please try to rebuild target."
166 remove_igb_uio_module
168 /sbin/lsmod | grep -s uio > /dev/null
169 if [ $? -ne 0 ] ; then
170 modinfo uio > /dev/null
171 if [ $? -eq 0 ]; then
172 echo "Loading uio module"
173 sudo /sbin/modprobe uio
177 # UIO may be compiled into kernel, so it may not be an error if it can't
180 echo "Loading DPDK UIO module"
181 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko
182 if [ $? -ne 0 ] ; then
183 echo "## ERROR: Could not load kmod/igb_uio.ko."
189 # Unloads VFIO modules.
193 echo "Unloading any existing VFIO module"
194 /sbin/lsmod | grep -s vfio > /dev/null
195 if [ $? -eq 0 ] ; then
196 sudo /sbin/rmmod vfio-pci
197 sudo /sbin/rmmod vfio_iommu_type1
198 sudo /sbin/rmmod vfio
203 # Loads new vfio-pci (and vfio module if needed).
209 VFIO_PATH="kernel/drivers/vfio/pci/vfio-pci.ko"
211 echo "Loading VFIO module"
212 /sbin/lsmod | grep -s vfio_pci > /dev/null
213 if [ $? -ne 0 ] ; then
214 if [ -f /lib/modules/$(uname -r)/$VFIO_PATH ] ; then
215 sudo /sbin/modprobe vfio-pci
219 # make sure regular users can read /dev/vfio
220 echo "chmod /dev/vfio"
221 sudo chmod a+x /dev/vfio
222 if [ $? -ne 0 ] ; then
228 # check if /dev/vfio/vfio exists - that way we
229 # know we either loaded the module, or it was
230 # compiled into the kernel
231 if [ ! -e /dev/vfio/vfio ] ; then
232 echo "## ERROR: VFIO not found!"
237 # Unloads the rte_kni.ko module.
241 echo "Unloading any existing DPDK KNI module"
242 /sbin/lsmod | grep -s rte_kni > /dev/null
243 if [ $? -eq 0 ] ; then
244 sudo /sbin/rmmod rte_kni
249 # Loads the rte_kni.ko module.
253 # Check that the KNI module is already built.
254 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko ];then
255 echo "## ERROR: Target does not have the DPDK KNI Module."
256 echo " To fix, please try to rebuild target."
260 # Unload existing version if present.
263 # Now try load the KNI module.
264 echo "Loading DPDK KNI module"
265 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko
266 if [ $? -ne 0 ] ; then
267 echo "## ERROR: Could not load kmod/rte_kni.ko."
273 # Sets appropriate permissions on /dev/vfio/* files
275 set_vfio_permissions()
277 # make sure regular users can read /dev/vfio
278 echo "chmod /dev/vfio"
279 sudo chmod a+x /dev/vfio
280 if [ $? -ne 0 ] ; then
286 # make sure regular user can access everything inside /dev/vfio
287 echo "chmod /dev/vfio/*"
288 sudo chmod 0666 /dev/vfio/*
289 if [ $? -ne 0 ] ; then
295 # since permissions are only to be set when running as
296 # regular user, we only check ulimit here
298 # warn if regular user is only allowed
299 # to memlock <64M of memory
300 MEMLOCK_AMNT=`ulimit -l`
302 if [ "$MEMLOCK_AMNT" != "unlimited" ] ; then
303 MEMLOCK_MB=`expr $MEMLOCK_AMNT / 1024`
305 echo "Current user memlock limit: ${MEMLOCK_MB} MB"
307 echo "This is the maximum amount of memory you will be"
308 echo "able to use with DPDK and VFIO if run as current user."
309 echo -n "To change this, please adjust limits.conf memlock "
310 echo "limit for current user."
312 if [ $MEMLOCK_AMNT -lt 65536 ] ; then
314 echo "## WARNING: memlock limit is less than 64MB"
315 echo -n "## DPDK with VFIO may not be able to initialize "
316 echo "if run as current user."
322 # Removes all reserved hugepages.
327 for d in /sys/devices/system/node/node? ; do
328 echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
330 echo "Removing currently reserved hugepages"
345 echo " Input the number of 2MB pages"
346 echo " Example: to have 128MB of hugepages available, enter '64' to"
347 echo " reserve 64 * 2MB pages"
348 echo -n "Number of pages: "
351 echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
353 echo "Reserving hugepages"
361 # Creates hugepages on specific NUMA nodes.
368 echo " Input the number of 2MB pages for each node"
369 echo " Example: to have 128MB of hugepages available per node,"
370 echo " enter '64' to reserve 64 * 2MB pages on each node"
373 for d in /sys/devices/system/node/node? ; do
375 echo -n "Number of pages for $node: "
377 echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
379 echo "Reserving hugepages"
387 # Run unit test application.
392 echo " Enter hex bitmask of cores to execute test app on"
393 echo " Example: to execute app on cores 0 to 7, enter 0xff"
397 sudo ${RTE_TARGET}/app/test -c $Bitmask $EAL_PARAMS
401 # Run unit testpmd application.
406 echo " Enter hex bitmask of cores to execute testpmd app on"
407 echo " Example: to execute app on cores 0 to 7, enter 0xff"
411 sudo ${RTE_TARGET}/app/testpmd -c $Bitmask $EAL_PARAMS -- -i
415 # Print hugepage information.
419 grep -i huge /proc/meminfo
423 # Calls dpdk_nic_bind.py --status to show the NIC and what they
424 # are all bound to, in terms of drivers.
428 if /sbin/lsmod | grep -q -e igb_uio -e vfio_pci; then
429 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
431 echo "# Please load the 'igb_uio' or 'vfio-pci' kernel module before "
432 echo "# querying or adjusting NIC device bindings"
437 # Uses dpdk_nic_bind.py to move devices to work with vfio-pci
441 if /sbin/lsmod | grep -q vfio_pci ; then
442 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
444 echo -n "Enter PCI address of device to bind to VFIO driver: "
446 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b vfio-pci $PCI_PATH &&
449 echo "# Please load the 'vfio-pci' kernel module before querying or "
450 echo "# adjusting NIC device bindings"
455 # Uses dpdk_nic_bind.py to move devices to work with igb_uio
457 bind_nics_to_igb_uio()
459 if /sbin/lsmod | grep -q igb_uio ; then
460 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
462 echo -n "Enter PCI address of device to bind to IGB UIO driver: "
464 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b igb_uio $PCI_PATH && echo "OK"
466 echo "# Please load the 'igb_uio' kernel module before querying or "
467 echo "# adjusting NIC device bindings"
472 # Uses dpdk_nic_bind.py to move devices to work with kernel drivers again
476 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
478 echo -n "Enter PCI address of device to unbind: "
481 echo -n "Enter name of kernel driver to bind the device to: "
483 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b $DRV $PCI_PATH && echo "OK"
487 # Options for building a target. Note that this step MUST be first as it sets
488 # up TARGETS[] starting from 1, and this is accessed in setup_target using the
489 # user entered option.
493 TITLE="Select the DPDK environment to build"
495 for cfg in config/defconfig_* ; do
496 cfg=${cfg/config\/defconfig_/}
497 TEXT[$CONFIG_NUM]="$cfg"
498 TARGETS[$CONFIG_NUM]=$cfg
499 FUNC[$CONFIG_NUM]="setup_target"
505 # Options for setting up environment.
509 TITLE="Setup linuxapp environment"
511 TEXT[1]="Insert IGB UIO module"
512 FUNC[1]="load_igb_uio_module"
514 TEXT[2]="Insert VFIO module"
515 FUNC[2]="load_vfio_module"
517 TEXT[3]="Insert KNI module"
518 FUNC[3]="load_kni_module"
520 TEXT[4]="Setup hugepage mappings for non-NUMA systems"
521 FUNC[4]="set_non_numa_pages"
523 TEXT[5]="Setup hugepage mappings for NUMA systems"
524 FUNC[5]="set_numa_pages"
526 TEXT[6]="Display current Ethernet device settings"
529 TEXT[7]="Bind Ethernet device to IGB UIO module"
530 FUNC[7]="bind_nics_to_igb_uio"
532 TEXT[8]="Bind Ethernet device to VFIO module"
533 FUNC[8]="bind_nics_to_vfio"
535 TEXT[9]="Setup VFIO permissions"
536 FUNC[9]="set_vfio_permissions"
540 # Options for running applications.
544 TITLE="Run test application for linuxapp environment"
546 TEXT[1]="Run test application (\$RTE_TARGET/app/test)"
547 FUNC[1]="run_test_app"
549 TEXT[2]="Run testpmd application in interactive mode (\$RTE_TARGET/app/testpmd)"
550 FUNC[2]="run_testpmd_app"
560 TEXT[1]="List hugepage info from /proc/meminfo"
561 FUNC[1]="grep_meminfo"
566 # Options for cleaning up the system
570 TITLE="Uninstall and system cleanup"
572 TEXT[1]="Unbind NICs from IGB UIO or VFIO driver"
573 FUNC[1]="unbind_nics"
575 TEXT[2]="Remove IGB UIO module"
576 FUNC[2]="remove_igb_uio_module"
578 TEXT[3]="Remove VFIO module"
579 FUNC[3]="remove_vfio_module"
581 TEXT[4]="Remove KNI module"
582 FUNC[4]="remove_kni_module"
584 TEXT[5]="Remove hugepage mappings"
585 FUNC[5]="clear_huge_pages"
588 STEPS[1]="step1_func"
589 STEPS[2]="step2_func"
590 STEPS[3]="step3_func"
591 STEPS[4]="step4_func"
592 STEPS[5]="step5_func"
596 while [ "$QUIT" == "0" ]; do
599 for s in $(seq ${#STEPS[@]}) ; do
602 echo "----------------------------------------------------------"
603 echo " Step $s: ${TITLE}"
604 echo "----------------------------------------------------------"
606 for i in $(seq ${#TEXT[@]}) ; do
607 echo "[$OPTION_NUM] ${TEXT[i]}"
608 OPTIONS[$OPTION_NUM]=${FUNC[i]}
612 # Clear TEXT and FUNC arrays before next step
619 echo "[$OPTION_NUM] Exit Script"
620 OPTIONS[$OPTION_NUM]="quit"
625 ${OPTIONS[our_entry]} ${our_entry}
627 if [ "$QUIT" == "0" ] ; then
629 echo -n "Press enter to continue ..."; read