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 # Uninstall all targets.
122 # Creates hugepage filesystem.
126 echo "Creating /mnt/huge and mounting as hugetlbfs"
127 sudo mkdir -p /mnt/huge
129 grep -s '/mnt/huge' /proc/mounts > /dev/null
130 if [ $? -ne 0 ] ; then
131 sudo mount -t hugetlbfs nodev /mnt/huge
136 # Removes hugepage filesystem.
140 echo "Unmounting /mnt/huge and removing directory"
141 grep -s '/mnt/huge' /proc/mounts > /dev/null
142 if [ $? -eq 0 ] ; then
143 sudo umount /mnt/huge
146 if [ -d /mnt/huge ] ; then
152 # Unloads igb_uio.ko.
154 remove_igb_uio_module()
156 echo "Unloading any existing DPDK UIO module"
157 /sbin/lsmod | grep -s igb_uio > /dev/null
158 if [ $? -eq 0 ] ; then
159 sudo /sbin/rmmod igb_uio
164 # Loads new igb_uio.ko (and uio module if needed).
166 load_igb_uio_module()
168 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko ];then
169 echo "## ERROR: Target does not have the DPDK UIO Kernel Module."
170 echo " To fix, please try to rebuild target."
174 remove_igb_uio_module
176 /sbin/lsmod | grep -s uio > /dev/null
177 if [ $? -ne 0 ] ; then
178 modinfo uio > /dev/null
179 if [ $? -eq 0 ]; then
180 echo "Loading uio module"
181 sudo /sbin/modprobe uio
185 # UIO may be compiled into kernel, so it may not be an error if it can't
188 echo "Loading DPDK UIO module"
189 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko
190 if [ $? -ne 0 ] ; then
191 echo "## ERROR: Could not load kmod/igb_uio.ko."
197 # Unloads VFIO modules.
201 echo "Unloading any existing VFIO module"
202 /sbin/lsmod | grep -s vfio > /dev/null
203 if [ $? -eq 0 ] ; then
204 sudo /sbin/rmmod vfio-pci
205 sudo /sbin/rmmod vfio_iommu_type1
206 sudo /sbin/rmmod vfio
211 # Loads new vfio-pci (and vfio module if needed).
217 VFIO_PATH="kernel/drivers/vfio/pci/vfio-pci.ko"
219 echo "Loading VFIO module"
220 /sbin/lsmod | grep -s vfio_pci > /dev/null
221 if [ $? -ne 0 ] ; then
222 if [ -f /lib/modules/$(uname -r)/$VFIO_PATH ] ; then
223 sudo /sbin/modprobe vfio-pci
227 # make sure regular users can read /dev/vfio
228 echo "chmod /dev/vfio"
229 sudo chmod a+x /dev/vfio
230 if [ $? -ne 0 ] ; then
236 # check if /dev/vfio/vfio exists - that way we
237 # know we either loaded the module, or it was
238 # compiled into the kernel
239 if [ ! -e /dev/vfio/vfio ] ; then
240 echo "## ERROR: VFIO not found!"
245 # Unloads the rte_kni.ko module.
249 echo "Unloading any existing DPDK KNI module"
250 /sbin/lsmod | grep -s rte_kni > /dev/null
251 if [ $? -eq 0 ] ; then
252 sudo /sbin/rmmod rte_kni
257 # Loads the rte_kni.ko module.
261 # Check that the KNI module is already built.
262 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko ];then
263 echo "## ERROR: Target does not have the DPDK KNI Module."
264 echo " To fix, please try to rebuild target."
268 # Unload existing version if present.
271 # Now try load the KNI module.
272 echo "Loading DPDK KNI module"
273 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko
274 if [ $? -ne 0 ] ; then
275 echo "## ERROR: Could not load kmod/rte_kni.ko."
281 # Sets appropriate permissions on /dev/vfio/* files
283 set_vfio_permissions()
285 # make sure regular users can read /dev/vfio
286 echo "chmod /dev/vfio"
287 sudo chmod a+x /dev/vfio
288 if [ $? -ne 0 ] ; then
294 # make sure regular user can access everything inside /dev/vfio
295 echo "chmod /dev/vfio/*"
296 sudo chmod 0666 /dev/vfio/*
297 if [ $? -ne 0 ] ; then
303 # since permissions are only to be set when running as
304 # regular user, we only check ulimit here
306 # warn if regular user is only allowed
307 # to memlock <64M of memory
308 MEMLOCK_AMNT=`ulimit -l`
310 if [ "$MEMLOCK_AMNT" != "unlimited" ] ; then
311 MEMLOCK_MB=`expr $MEMLOCK_AMNT / 1024`
313 echo "Current user memlock limit: ${MEMLOCK_MB} MB"
315 echo "This is the maximum amount of memory you will be"
316 echo "able to use with DPDK and VFIO if run as current user."
317 echo -n "To change this, please adjust limits.conf memlock "
318 echo "limit for current user."
320 if [ $MEMLOCK_AMNT -lt 65536 ] ; then
322 echo "## WARNING: memlock limit is less than 64MB"
323 echo -n "## DPDK with VFIO may not be able to initialize "
324 echo "if run as current user."
330 # Removes all reserved hugepages.
335 for d in /sys/devices/system/node/node? ; do
336 echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
338 echo "Removing currently reserved hugepages"
353 echo " Input the number of 2MB pages"
354 echo " Example: to have 128MB of hugepages available, enter '64' to"
355 echo " reserve 64 * 2MB pages"
356 echo -n "Number of pages: "
359 echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
361 echo "Reserving hugepages"
369 # Creates hugepages on specific NUMA nodes.
376 echo " Input the number of 2MB pages for each node"
377 echo " Example: to have 128MB of hugepages available per node,"
378 echo " enter '64' to reserve 64 * 2MB pages on each node"
381 for d in /sys/devices/system/node/node? ; do
383 echo -n "Number of pages for $node: "
385 echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
387 echo "Reserving hugepages"
395 # Run unit test application.
400 echo " Enter hex bitmask of cores to execute test app on"
401 echo " Example: to execute app on cores 0 to 7, enter 0xff"
405 sudo ${RTE_TARGET}/app/test -c $Bitmask $EAL_PARAMS
409 # Run unit testpmd application.
414 echo " Enter hex bitmask of cores to execute testpmd app on"
415 echo " Example: to execute app on cores 0 to 7, enter 0xff"
419 sudo ${RTE_TARGET}/app/testpmd -c $Bitmask $EAL_PARAMS -- -i
423 # Print hugepage information.
427 grep -i huge /proc/meminfo
431 # Calls dpdk_nic_bind.py --status to show the NIC and what they
432 # are all bound to, in terms of drivers.
436 if /sbin/lsmod | grep -q -e igb_uio -e vfio_pci; then
437 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
439 echo "# Please load the 'igb_uio' or 'vfio-pci' kernel module before "
440 echo "# querying or adjusting NIC device bindings"
445 # Uses dpdk_nic_bind.py to move devices to work with vfio-pci
449 if /sbin/lsmod | grep -q vfio_pci ; then
450 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
452 echo -n "Enter PCI address of device to bind to VFIO driver: "
454 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b vfio-pci $PCI_PATH &&
457 echo "# Please load the 'vfio-pci' kernel module before querying or "
458 echo "# adjusting NIC device bindings"
463 # Uses dpdk_nic_bind.py to move devices to work with igb_uio
465 bind_nics_to_igb_uio()
467 if /sbin/lsmod | grep -q igb_uio ; then
468 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
470 echo -n "Enter PCI address of device to bind to IGB UIO driver: "
472 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b igb_uio $PCI_PATH && echo "OK"
474 echo "# Please load the 'igb_uio' kernel module before querying or "
475 echo "# adjusting NIC device bindings"
480 # Uses dpdk_nic_bind.py to move devices to work with kernel drivers again
484 ${RTE_SDK}/tools/dpdk_nic_bind.py --status
486 echo -n "Enter PCI address of device to unbind: "
489 echo -n "Enter name of kernel driver to bind the device to: "
491 sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b $DRV $PCI_PATH && echo "OK"
495 # Options for building a target. Note that this step MUST be first as it sets
496 # up TARGETS[] starting from 1, and this is accessed in setup_target using the
497 # user entered option.
501 TITLE="Select the DPDK environment to build"
503 for cfg in config/defconfig_* ; do
504 cfg=${cfg/config\/defconfig_/}
505 TEXT[$CONFIG_NUM]="$cfg"
506 TARGETS[$CONFIG_NUM]=$cfg
507 FUNC[$CONFIG_NUM]="setup_target"
513 # Options for setting up environment.
517 TITLE="Setup linuxapp environment"
519 TEXT[1]="Insert IGB UIO module"
520 FUNC[1]="load_igb_uio_module"
522 TEXT[2]="Insert VFIO module"
523 FUNC[2]="load_vfio_module"
525 TEXT[3]="Insert KNI module"
526 FUNC[3]="load_kni_module"
528 TEXT[4]="Setup hugepage mappings for non-NUMA systems"
529 FUNC[4]="set_non_numa_pages"
531 TEXT[5]="Setup hugepage mappings for NUMA systems"
532 FUNC[5]="set_numa_pages"
534 TEXT[6]="Display current Ethernet device settings"
537 TEXT[7]="Bind Ethernet device to IGB UIO module"
538 FUNC[7]="bind_nics_to_igb_uio"
540 TEXT[8]="Bind Ethernet device to VFIO module"
541 FUNC[8]="bind_nics_to_vfio"
543 TEXT[9]="Setup VFIO permissions"
544 FUNC[9]="set_vfio_permissions"
548 # Options for running applications.
552 TITLE="Run test application for linuxapp environment"
554 TEXT[1]="Run test application (\$RTE_TARGET/app/test)"
555 FUNC[1]="run_test_app"
557 TEXT[2]="Run testpmd application in interactive mode (\$RTE_TARGET/app/testpmd)"
558 FUNC[2]="run_testpmd_app"
568 TEXT[1]="List hugepage info from /proc/meminfo"
569 FUNC[1]="grep_meminfo"
574 # Options for cleaning up the system
578 TITLE="Uninstall and system cleanup"
580 TEXT[1]="Uninstall all targets"
581 FUNC[1]="uninstall_targets"
583 TEXT[2]="Unbind NICs from IGB UIO or VFIO driver"
584 FUNC[2]="unbind_nics"
586 TEXT[3]="Remove IGB UIO module"
587 FUNC[3]="remove_igb_uio_module"
589 TEXT[4]="Remove VFIO module"
590 FUNC[4]="remove_vfio_module"
592 TEXT[5]="Remove KNI module"
593 FUNC[5]="remove_kni_module"
595 TEXT[6]="Remove hugepage mappings"
596 FUNC[6]="clear_huge_pages"
599 STEPS[1]="step1_func"
600 STEPS[2]="step2_func"
601 STEPS[3]="step3_func"
602 STEPS[4]="step4_func"
603 STEPS[5]="step5_func"
607 while [ "$QUIT" == "0" ]; do
610 for s in $(seq ${#STEPS[@]}) ; do
613 echo "----------------------------------------------------------"
614 echo " Step $s: ${TITLE}"
615 echo "----------------------------------------------------------"
617 for i in $(seq ${#TEXT[@]}) ; do
618 echo "[$OPTION_NUM] ${TEXT[i]}"
619 OPTIONS[$OPTION_NUM]=${FUNC[i]}
623 # Clear TEXT and FUNC arrays before next step
630 echo "[$OPTION_NUM] Exit Script"
631 OPTIONS[$OPTION_NUM]="quit"
636 ${OPTIONS[our_entry]} ${our_entry}
638 if [ "$QUIT" == "0" ] ; then
640 echo -n "Press enter to continue ..."; read