5 # Copyright(c) 2010-2012 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.
36 # Run with "source /path/to/setup.sh"
40 # Change to DPDK directory ( <this-script's-dir>/.. ), and export it as RTE_SDK
42 cd $(dirname ${BASH_SOURCE[0]})/..
44 echo "------------------------------------------------------------------------------"
45 echo " RTE_SDK exported as $RTE_SDK"
46 echo "------------------------------------------------------------------------------"
49 # Application EAL parameters for setting memory options (amount/channels/ranks).
54 # Sets QUIT variable so script will finish.
62 # Sets up environmental variables for ICC.
66 DEFAULT_PATH=/opt/intel/bin/iccvars.sh
68 shpath=`which iccvars.sh 2> /dev/null`
69 if [ $? -eq 0 ] ; then
70 echo "Loading iccvars.sh from $shpath for $param"
72 elif [ -f $DEFAULT_PATH ] ; then
73 echo "Loading iccvars.sh from $DEFAULT_PATH for $param"
74 source $DEFAULT_PATH $param
76 echo "## ERROR: cannot find 'iccvars.sh' script to set up ICC."
77 echo "## To fix, please add the directory that contains"
78 echo "## iccvars.sh to your 'PATH' environment variable."
84 # Sets RTE_TARGET and does a "make install".
89 export RTE_TARGET=${TARGETS[option]}
91 compiler=${RTE_TARGET##*-}
92 if [ "$compiler" == "icc" ] ; then
93 platform=${RTE_TARGET%%-*}
94 if [ "$platform" == "x86_64" ] ; then
100 if [ "$QUIT" == "0" ] ; then
101 make install T=${RTE_TARGET}
103 echo "------------------------------------------------------------------------------"
104 echo " RTE_TARGET exported as $RTE_TARGET"
105 echo "------------------------------------------------------------------------------"
109 # Uninstall all targets.
117 # Creates hugepage filesystem.
121 echo "Creating /mnt/huge and mounting as hugetlbfs"
122 sudo mkdir -p /mnt/huge
124 grep -s '/mnt/huge' /proc/mounts > /dev/null
125 if [ $? -ne 0 ] ; then
126 sudo mount -t hugetlbfs nodev /mnt/huge
131 # Removes hugepage filesystem.
135 echo "Unmounting /mnt/huge and removing directory"
136 grep -s '/mnt/huge' /proc/mounts > /dev/null
137 if [ $? -eq 0 ] ; then
138 sudo umount /mnt/huge
141 if [ -d /mnt/huge ] ; then
147 # Unloads igb_uio.ko.
149 remove_igb_uio_module()
151 echo "Unloading any existing DPDK UIO module"
152 /sbin/lsmod | grep -s igb_uio > /dev/null
153 if [ $? -eq 0 ] ; then
154 sudo /sbin/rmmod igb_uio
159 # Loads new igb_uio.ko (and uio module if needed).
161 load_igb_uio_module()
163 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko ];then
164 echo "## ERROR: Target does not have the DPDK UIO Kernel Module."
165 echo " To fix, please try to rebuild target."
169 remove_igb_uio_module
171 /sbin/lsmod | grep -s uio > /dev/null
172 if [ $? -ne 0 ] ; then
173 if [ -f /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko ] ; then
174 echo "Loading uio module"
175 sudo /sbin/modprobe uio
179 # UIO may be compiled into kernel, so it may not be an error if it can't
182 echo "Loading DPDK UIO module"
183 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko
184 if [ $? -ne 0 ] ; then
185 echo "## ERROR: Could not load kmod/igb_uio.ko."
191 # Unloads the rte_kni.ko module.
195 echo "Unloading any existing DPDK KNI module"
196 /sbin/lsmod | grep -s rte_kni > /dev/null
197 if [ $? -eq 0 ] ; then
198 sudo /sbin/rmmod rte_kni
203 # Loads the rte_kni.ko module.
207 # Check that the KNI module is already built.
208 if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko ];then
209 echo "## ERROR: Target does not have the DPDK KNI Module."
210 echo " To fix, please try to rebuild target."
214 # Unload existing version if present.
217 # Now try load the KNI module.
218 echo "Loading DPDK KNI module"
219 sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko
220 if [ $? -ne 0 ] ; then
221 echo "## ERROR: Could not load kmod/rte_kni.ko."
227 # Removes all reserved hugepages.
232 for d in /sys/devices/system/node/node? ; do
233 echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
235 echo "Removing currently reserved hugepages"
250 echo " Input the number of 2MB pages"
251 echo " Example: to have 128MB of hugepages available, enter '64' to"
252 echo " reserve 64 * 2MB pages"
253 echo -n "Number of pages: "
256 echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
258 echo "Reserving hugepages"
266 # Creates hugepages on specific NUMA nodes.
273 echo " Input the number of 2MB pages for each node"
274 echo " Example: to have 128MB of hugepages available per node,"
275 echo " enter '64' to reserve 64 * 2MB pages on each node"
278 for d in /sys/devices/system/node/node? ; do
280 echo -n "Number of pages for $node: "
282 echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
284 echo "Reserving hugepages"
292 # Run unit test application.
297 echo " Enter hex bitmask of cores to execute test app on"
298 echo " Example: to execute app on cores 0 to 7, enter 0xff"
302 sudo ${RTE_TARGET}/app/test -c $Bitmask $EAL_PARAMS
306 # Run unit testpmd application.
311 echo " Enter hex bitmask of cores to execute testpmd app on"
312 echo " Example: to execute app on cores 0 to 7, enter 0xff"
316 sudo ${RTE_TARGET}/app/testpmd -c $Bitmask $EAL_PARAMS -- -i
320 # Print hugepage information.
324 grep -i huge /proc/meminfo
328 # List all hugepage file references
336 # Options for building a target. Note that this step MUST be first as it sets
337 # up TARGETS[] starting from 1, and this is accessed in setup_target using the
338 # user entered option.
342 TITLE="Select the DPDK environment to build"
344 for cfg in config/defconfig_* ; do
345 cfg=${cfg/config\/defconfig_/}
346 TEXT[$CONFIG_NUM]="$cfg"
347 TARGETS[$CONFIG_NUM]=$cfg
348 FUNC[$CONFIG_NUM]="setup_target"
354 # Options for setting up environment.
358 TITLE="Setup linuxapp environment"
360 TEXT[1]="Insert IGB UIO module"
361 FUNC[1]="load_igb_uio_module"
363 TEXT[2]="Insert KNI module"
364 FUNC[2]="load_kni_module"
366 TEXT[3]="Setup hugepage mappings for non-NUMA systems"
367 FUNC[3]="set_non_numa_pages"
369 TEXT[4]="Setup hugepage mappings for NUMA systems"
370 FUNC[4]="set_numa_pages"
374 # Options for running applications.
378 TITLE="Run test application for linuxapp environment"
380 TEXT[1]="Run test application (\$RTE_TARGET/app/test)"
381 FUNC[1]="run_test_app"
383 TEXT[2]="Run testpmd application in interactive mode (\$RTE_TARGET/app/testpmd)"
384 FUNC[2]="run_testpmd_app"
394 TEXT[1]="List hugepage info from /proc/meminfo"
395 FUNC[1]="grep_meminfo"
397 TEXT[2]="List hugepage files in /mnt/huge"
398 FUNC[2]="ls_mnt_huge"
402 # Options for cleaning up the system
406 TITLE="Uninstall and system cleanup"
408 TEXT[1]="Uninstall all targets"
409 FUNC[1]="uninstall_targets"
411 TEXT[2]="Remove IGB UIO module"
412 FUNC[2]="remove_igb_uio_module"
414 TEXT[3]="Remove KNI module"
415 FUNC[3]="remove_kni_module"
417 TEXT[4]="Remove hugepage mappings"
418 FUNC[4]="clear_huge_pages"
421 STEPS[1]="step1_func"
422 STEPS[2]="step2_func"
423 STEPS[3]="step3_func"
424 STEPS[4]="step4_func"
425 STEPS[5]="step5_func"
429 while [ "$QUIT" == "0" ]; do
432 for s in $(seq ${#STEPS[@]}) ; do
435 echo "----------------------------------------------------------"
436 echo " Step $s: ${TITLE}"
437 echo "----------------------------------------------------------"
439 for i in $(seq ${#TEXT[@]}) ; do
440 echo "[$OPTION_NUM] ${TEXT[i]}"
441 OPTIONS[$OPTION_NUM]=${FUNC[i]}
445 # Clear TEXT and FUNC arrays before next step
452 echo "[$OPTION_NUM] Exit Script"
453 OPTIONS[$OPTION_NUM]="quit"
458 ${OPTIONS[our_entry]} ${our_entry}
460 echo -n "Press enter to continue ..."; read