2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
6 # Run with "source /path/to/dpdk-setup.sh"
10 # Change to DPDK directory ( <this-script's-dir>/.. ), and export it as RTE_SDK
12 cd $(dirname ${BASH_SOURCE[0]})/..
14 echo "------------------------------------------------------------------------------"
15 echo " RTE_SDK exported as $RTE_SDK"
16 echo "------------------------------------------------------------------------------"
18 HUGEPGSZ=`cat /proc/meminfo | grep Hugepagesize | cut -d : -f 2 | tr -d ' '`
21 # Application EAL parameters for setting memory options (amount/channels/ranks).
26 # Sets QUIT variable so script will finish.
40 # Sets up environmental variables for ICC.
44 DEFAULT_PATH=/opt/intel/bin/iccvars.sh
46 shpath=`which iccvars.sh 2> /dev/null`
47 if [ $? -eq 0 ] ; then
48 echo "Loading iccvars.sh from $shpath for $param"
50 elif [ -f $DEFAULT_PATH ] ; then
51 echo "Loading iccvars.sh from $DEFAULT_PATH for $param"
52 source $DEFAULT_PATH $param
54 echo "## ERROR: cannot find 'iccvars.sh' script to set up ICC."
55 echo "## To fix, please add the directory that contains"
56 echo "## iccvars.sh to your 'PATH' environment variable."
62 # Sets RTE_TARGET and does a "make install".
67 export RTE_TARGET=${TARGETS[option]}
69 compiler=${RTE_TARGET##*-}
70 if [ "$compiler" == "icc" ] ; then
71 platform=${RTE_TARGET%%-*}
72 if [ "$platform" == "x86_64" ] ; then
78 if [ "$QUIT" == "0" ] ; then
79 make install T=${RTE_TARGET}
81 echo "------------------------------------------------------------------------------"
82 echo " RTE_TARGET exported as $RTE_TARGET"
83 echo "------------------------------------------------------------------------------"
87 # Creates hugepage filesystem.
91 echo "Creating /mnt/huge and mounting as hugetlbfs"
92 sudo mkdir -p /mnt/huge
94 grep -s '/mnt/huge' /proc/mounts > /dev/null
95 if [ $? -ne 0 ] ; then
96 sudo mount -t hugetlbfs nodev /mnt/huge
101 # Removes hugepage filesystem.
105 echo "Unmounting /mnt/huge and removing directory"
106 grep -s '/mnt/huge' /proc/mounts > /dev/null
107 if [ $? -eq 0 ] ; then
108 sudo umount /mnt/huge
111 if [ -d /mnt/huge ] ; then
117 # Unloads igb_uio.ko.
119 remove_igb_uio_module()
121 echo "Unloading any existing DPDK UIO module"
122 /sbin/lsmod | grep -s igb_uio > /dev/null
123 if [ $? -eq 0 ] ; then
124 sudo /sbin/rmmod igb_uio
129 # Loads new igb_uio.ko (and uio module if needed).
131 load_igb_uio_module()
133 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko ];then
134 echo "## ERROR: Target does not have the DPDK UIO Kernel Module."
135 echo " To fix, please try to rebuild target."
139 remove_igb_uio_module
141 /sbin/lsmod | grep -s uio > /dev/null
142 if [ $? -ne 0 ] ; then
143 modinfo uio > /dev/null
144 if [ $? -eq 0 ]; then
145 echo "Loading uio module"
146 sudo /sbin/modprobe uio
150 # UIO may be compiled into kernel, so it may not be an error if it can't
153 echo "Loading DPDK UIO module"
154 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko
155 if [ $? -ne 0 ] ; then
156 echo "## ERROR: Could not load kmod/igb_uio.ko."
162 # Unloads VFIO modules.
166 echo "Unloading any existing VFIO module"
167 /sbin/lsmod | grep -s vfio > /dev/null
168 if [ $? -eq 0 ] ; then
169 sudo /sbin/rmmod vfio-pci
170 sudo /sbin/rmmod vfio_iommu_type1
171 sudo /sbin/rmmod vfio
176 # Loads new vfio-pci (and vfio module if needed).
182 VFIO_PATH="kernel/drivers/vfio/pci/vfio-pci.ko"
184 echo "Loading VFIO module"
185 /sbin/lsmod | grep -s vfio_pci > /dev/null
186 if [ $? -ne 0 ] ; then
187 if [ -f /lib/modules/$(uname -r)/$VFIO_PATH ] ; then
188 sudo /sbin/modprobe vfio-pci
192 # make sure regular users can read /dev/vfio
193 echo "chmod /dev/vfio"
194 sudo chmod a+x /dev/vfio
195 if [ $? -ne 0 ] ; then
201 # check if /dev/vfio/vfio exists - that way we
202 # know we either loaded the module, or it was
203 # compiled into the kernel
204 if [ ! -e /dev/vfio/vfio ] ; then
205 echo "## ERROR: VFIO not found!"
210 # Unloads the rte_kni.ko module.
214 echo "Unloading any existing DPDK KNI module"
215 /sbin/lsmod | grep -s rte_kni > /dev/null
216 if [ $? -eq 0 ] ; then
217 sudo /sbin/rmmod rte_kni
222 # Loads the rte_kni.ko module.
226 # Check that the KNI module is already built.
227 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko ];then
228 echo "## ERROR: Target does not have the DPDK KNI Module."
229 echo " To fix, please try to rebuild target."
233 # Unload existing version if present.
236 # Now try load the KNI module.
237 echo "Loading DPDK KNI module"
238 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko
239 if [ $? -ne 0 ] ; then
240 echo "## ERROR: Could not load kmod/rte_kni.ko."
246 # Sets appropriate permissions on /dev/vfio/* files
248 set_vfio_permissions()
250 # make sure regular users can read /dev/vfio
251 echo "chmod /dev/vfio"
252 sudo chmod a+x /dev/vfio
253 if [ $? -ne 0 ] ; then
259 # make sure regular user can access everything inside /dev/vfio
260 echo "chmod /dev/vfio/*"
261 sudo chmod 0666 /dev/vfio/*
262 if [ $? -ne 0 ] ; then
268 # since permissions are only to be set when running as
269 # regular user, we only check ulimit here
271 # warn if regular user is only allowed
272 # to memlock <64M of memory
273 MEMLOCK_AMNT=`ulimit -l`
275 if [ "$MEMLOCK_AMNT" != "unlimited" ] ; then
276 MEMLOCK_MB=`expr $MEMLOCK_AMNT / 1024`
278 echo "Current user memlock limit: ${MEMLOCK_MB} MB"
280 echo "This is the maximum amount of memory you will be"
281 echo "able to use with DPDK and VFIO if run as current user."
282 echo -n "To change this, please adjust limits.conf memlock "
283 echo "limit for current user."
285 if [ $MEMLOCK_AMNT -lt 65536 ] ; then
287 echo "## WARNING: memlock limit is less than 64MB"
288 echo -n "## DPDK with VFIO may not be able to initialize "
289 echo "if run as current user."
295 # Removes all reserved hugepages.
300 for d in /sys/devices/system/node/node? ; do
301 echo "echo 0 > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
303 echo "Removing currently reserved hugepages"
318 echo " Input the number of ${HUGEPGSZ} hugepages"
319 echo " Example: to have 128MB of hugepages available in a 2MB huge page system,"
320 echo " enter '64' to reserve 64 * 2MB pages"
321 echo -n "Number of pages: "
324 echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" > .echo_tmp
326 echo "Reserving hugepages"
334 # Creates hugepages on specific NUMA nodes.
341 echo " Input the number of ${HUGEPGSZ} hugepages for each node"
342 echo " Example: to have 128MB of hugepages available per node in a 2MB huge page system,"
343 echo " enter '64' to reserve 64 * 2MB pages on each node"
346 for d in /sys/devices/system/node/node? ; do
348 echo -n "Number of pages for $node: "
350 echo "echo $Pages > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
352 echo "Reserving hugepages"
360 # Run unit test application.
365 echo " Enter hex bitmask of cores to execute test app on"
366 echo " Example: to execute app on cores 0 to 7, enter 0xff"
370 sudo ${RTE_TARGET}/app/test -c $Bitmask $EAL_PARAMS
374 # Run unit testpmd application.
379 echo " Enter hex bitmask of cores to execute testpmd app on"
380 echo " Example: to execute app on cores 0 to 7, enter 0xff"
384 sudo ${RTE_TARGET}/app/testpmd -c $Bitmask $EAL_PARAMS -- -i
388 # Print hugepage information.
392 grep -i huge /proc/meminfo
396 # Calls dpdk-devbind.py --status to show the devices and what they
397 # are all bound to, in terms of drivers.
401 if [ -d /sys/module/vfio_pci -o -d /sys/module/igb_uio ]; then
402 ${RTE_SDK}/usertools/dpdk-devbind.py --status
404 echo "# Please load the 'igb_uio' or 'vfio-pci' kernel module before "
405 echo "# querying or adjusting device bindings"
410 # Uses dpdk-devbind.py to move devices to work with vfio-pci
412 bind_devices_to_vfio()
414 if [ -d /sys/module/vfio_pci ]; then
415 ${RTE_SDK}/usertools/dpdk-devbind.py --status
417 echo -n "Enter PCI address of device to bind to VFIO driver: "
419 sudo ${RTE_SDK}/usertools/dpdk-devbind.py -b vfio-pci $PCI_PATH &&
422 echo "# Please load the 'vfio-pci' kernel module before querying or "
423 echo "# adjusting device bindings"
428 # Uses dpdk-devbind.py to move devices to work with igb_uio
430 bind_devices_to_igb_uio()
432 if [ -d /sys/module/igb_uio ]; then
433 ${RTE_SDK}/usertools/dpdk-devbind.py --status
435 echo -n "Enter PCI address of device to bind to IGB UIO driver: "
437 sudo ${RTE_SDK}/usertools/dpdk-devbind.py -b igb_uio $PCI_PATH && echo "OK"
439 echo "# Please load the 'igb_uio' kernel module before querying or "
440 echo "# adjusting device bindings"
445 # Uses dpdk-devbind.py to move devices to work with kernel drivers again
449 ${RTE_SDK}/usertools/dpdk-devbind.py --status
451 echo -n "Enter PCI address of device to unbind: "
454 echo -n "Enter name of kernel driver to bind the device to: "
456 sudo ${RTE_SDK}/usertools/dpdk-devbind.py -b $DRV $PCI_PATH && echo "OK"
460 # Options for building a target. Note that this step MUST be first as it sets
461 # up TARGETS[] starting from 1, and this is accessed in setup_target using the
462 # user entered option.
466 TITLE="Select the DPDK environment to build"
468 for cfg in config/defconfig_* ; do
469 cfg=${cfg/config\/defconfig_/}
470 TEXT[$CONFIG_NUM]="$cfg"
471 TARGETS[$CONFIG_NUM]=$cfg
472 FUNC[$CONFIG_NUM]="setup_target"
478 # Options for setting up environment.
482 TITLE="Setup linux environment"
484 TEXT[1]="Insert IGB UIO module"
485 FUNC[1]="load_igb_uio_module"
487 TEXT[2]="Insert VFIO module"
488 FUNC[2]="load_vfio_module"
490 TEXT[3]="Insert KNI module"
491 FUNC[3]="load_kni_module"
493 TEXT[4]="Setup hugepage mappings for non-NUMA systems"
494 FUNC[4]="set_non_numa_pages"
496 TEXT[5]="Setup hugepage mappings for NUMA systems"
497 FUNC[5]="set_numa_pages"
499 TEXT[6]="Display current Ethernet/Baseband/Crypto device settings"
500 FUNC[6]="show_devices"
502 TEXT[7]="Bind Ethernet/Baseband/Crypto device to IGB UIO module"
503 FUNC[7]="bind_devices_to_igb_uio"
505 TEXT[8]="Bind Ethernet/Baseband/Crypto device to VFIO module"
506 FUNC[8]="bind_devices_to_vfio"
508 TEXT[9]="Setup VFIO permissions"
509 FUNC[9]="set_vfio_permissions"
513 # Options for running applications.
517 TITLE="Run test application for linux environment"
519 TEXT[1]="Run test application (\$RTE_TARGET/app/test)"
520 FUNC[1]="run_test_app"
522 TEXT[2]="Run testpmd application in interactive mode (\$RTE_TARGET/app/testpmd)"
523 FUNC[2]="run_testpmd_app"
533 TEXT[1]="List hugepage info from /proc/meminfo"
534 FUNC[1]="grep_meminfo"
539 # Options for cleaning up the system
543 TITLE="Uninstall and system cleanup"
545 TEXT[1]="Unbind devices from IGB UIO or VFIO driver"
546 FUNC[1]="unbind_devices"
548 TEXT[2]="Remove IGB UIO module"
549 FUNC[2]="remove_igb_uio_module"
551 TEXT[3]="Remove VFIO module"
552 FUNC[3]="remove_vfio_module"
554 TEXT[4]="Remove KNI module"
555 FUNC[4]="remove_kni_module"
557 TEXT[5]="Remove hugepage mappings"
558 FUNC[5]="clear_huge_pages"
561 STEPS[1]="step1_func"
562 STEPS[2]="step2_func"
563 STEPS[3]="step3_func"
564 STEPS[4]="step4_func"
565 STEPS[5]="step5_func"
569 while [ "$QUIT" == "0" ]; do
572 for s in $(seq ${#STEPS[@]}) ; do
575 echo "----------------------------------------------------------"
576 echo " Step $s: ${TITLE}"
577 echo "----------------------------------------------------------"
579 for i in $(seq ${#TEXT[@]}) ; do
580 echo "[$OPTION_NUM] ${TEXT[i]}"
581 OPTIONS[$OPTION_NUM]=${FUNC[i]}
585 # Clear TEXT and FUNC arrays before next step
592 echo "[$OPTION_NUM] Exit Script"
593 OPTIONS[$OPTION_NUM]="quit"
598 ${OPTIONS[our_entry]} ${our_entry}
600 if [ "$QUIT" == "0" ] ; then
602 echo -n "Press enter to continue ..."; read