remove version in all files
[dpdk.git] / tools / setup.sh
1 #! /bin/bash
2
3 #   BSD LICENSE
4
5 #   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
6 #   All rights reserved.
7
8 #   Redistribution and use in source and binary forms, with or without 
9 #   modification, are permitted provided that the following conditions 
10 #   are met:
11
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 
17 #       distribution.
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.
21
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.
33
34
35 #
36 # Run with "source /path/to/setup.sh"
37 #
38
39 #
40 # Change to DPDK directory ( <this-script's-dir>/.. ), and export it as RTE_SDK
41 #
42 cd $(dirname ${BASH_SOURCE[0]})/..
43 export RTE_SDK=$PWD
44 echo "------------------------------------------------------------------------------"
45 echo " RTE_SDK exported as $RTE_SDK"
46 echo "------------------------------------------------------------------------------"
47
48 #
49 # Application EAL parameters for setting memory options (amount/channels/ranks).
50 #
51 EAL_PARAMS='-n 4'
52
53 #
54 # Sets QUIT variable so script will finish.
55 #
56 quit()
57 {
58         QUIT=$1
59 }
60
61 #
62 # Sets up envronment variables for ICC.
63 #
64 setup_icc()
65 {
66         DEFAULT_PATH=/opt/intel/bin/iccvars.sh
67         param=$1
68         shpath=`which iccvars.sh 2> /dev/null`
69         if [ $? -eq 0 ] ; then
70                 echo "Loading iccvars.sh from $shpath for $param"
71                 source $shpath $param
72         elif [ -f $DEFAULT_PATH ] ; then
73                 echo "Loading iccvars.sh from $DEFAULT_PATH for $param"
74                 source $DEFAULT_PATH $param
75         else
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."
79                 quit
80         fi
81 }
82
83 #
84 # Sets RTE_TARGET and does a "make install".
85 #
86 setup_target()
87 {
88         option=$1
89         export RTE_TARGET=${TARGETS[option]}
90
91         compiler=${RTE_TARGET##*-}
92         if [ "$compiler" == "icc" ] ; then
93                 platform=${RTE_TARGET%%-*}
94                 if [ "$platform" == "x86_64" ] ; then
95                         setup_icc intel64
96                 else
97                         setup_icc ia32
98                 fi
99         fi
100         if [ "$QUIT" == "0" ] ; then
101                 make install T=${RTE_TARGET}
102         fi
103         echo "------------------------------------------------------------------------------"
104         echo " RTE_TARGET exported as $RTE_TARGET"
105         echo "------------------------------------------------------------------------------"
106 }
107
108 #
109 # Uninstall all targets.
110 #
111 uninstall_targets()
112 {
113         make uninstall
114 }
115
116 #
117 # Creates hugepage filesystem.
118 #
119 create_mnt_huge()
120 {
121         echo "Creating /mnt/huge and mounting as hugetlbfs"
122         sudo mkdir -p /mnt/huge
123
124         grep -s '/mnt/huge' /proc/mounts > /dev/null
125         if [ $? -ne 0 ] ; then
126                 sudo mount -t hugetlbfs nodev /mnt/huge
127         fi
128 }
129
130 #
131 # Removes hugepage filesystem.
132 #
133 remove_mnt_huge()
134 {
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
139         fi
140
141         if [ -d /mnt/huge ] ; then
142                 sudo rm -R /mnt/huge
143         fi
144 }
145
146 #
147 # Unloads igb_uio.ko.
148 #
149 remove_igb_uio_module()
150 {
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
155         fi
156 }
157
158 #
159 # Loads new igb_uio.ko (and uio module if needed).
160 #
161 load_igb_uio_module()
162 {
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."
166                 return
167         fi
168
169         remove_igb_uio_module
170
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
176                 fi
177         fi
178
179         # UIO may be compiled into kernel, so it may not be an error if it can't
180         # be loaded.
181
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."
186                 quit
187         fi
188 }
189
190 #
191 # Removes all reserved hugepages.
192 #
193 clear_huge_pages()
194 {
195         echo > .echo_tmp
196         for d in /sys/devices/system/node/node? ; do
197                 echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
198         done
199         echo "Removing currently reserved hugepages"
200         sudo sh .echo_tmp
201         rm -f .echo_tmp
202
203         remove_mnt_huge
204 }
205
206 #
207 # Creates hugepages.
208 #
209 set_non_numa_pages()
210 {
211         clear_huge_pages
212
213         echo ""
214         echo "  Input the number of 2MB pages"
215         echo "  Example: to have 128MB of hugepages available, enter '64' to"
216         echo "  reserve 64 * 2MB pages"
217         echo -n "Number of pages: "
218         read Pages
219
220         echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
221
222         echo "Reserving hugepages"
223         sudo sh .echo_tmp
224         rm -f .echo_tmp
225
226         create_mnt_huge
227 }
228
229 #
230 # Creates hugepages on specific NUMA nodes.
231 #
232 set_numa_pages()
233 {
234         clear_huge_pages
235
236         echo ""
237         echo "  Input the number of 2MB pages for each node"
238         echo "  Example: to have 128MB of hugepages available per node,"
239         echo "  enter '64' to reserve 64 * 2MB pages on each node"
240
241         echo > .echo_tmp
242         for d in /sys/devices/system/node/node? ; do
243                 node=$(basename $d)
244                 echo -n "Number of pages for $node: "
245                 read Pages
246                 echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
247         done
248         echo "Reserving hugepages"
249         sudo sh .echo_tmp
250         rm -f .echo_tmp
251
252         create_mnt_huge
253 }
254
255 #
256 # Run unit test application.
257 #
258 run_test_app()
259 {
260         echo ""
261         echo "  Enter hex bitmask of cores to execute test app on"
262         echo "  Example: to execute app on cores 0 to 7, enter 0xff"
263         echo -n "bitmask: "
264         read Bitmask
265         echo "Launching app"
266         sudo ${RTE_TARGET}/app/test -c $Bitmask $EAL_PARAMS
267 }
268
269 #
270 # Run unit testpmd application.
271 #
272 run_testpmd_app()
273 {
274         echo ""
275         echo "  Enter hex bitmask of cores to execute testpmd app on"
276         echo "  Example: to execute app on cores 0 to 7, enter 0xff"
277         echo -n "bitmask: "
278         read Bitmask
279         echo "Launching app"
280         sudo ${RTE_TARGET}/app/testpmd -c $Bitmask $EAL_PARAMS -- -i
281 }
282
283 #
284 # Print hugepage information.
285 #
286 grep_meminfo()
287 {
288         grep -i huge /proc/meminfo
289 }
290
291 #
292 # List all hugepage file references
293 #
294 ls_mnt_huge()
295 {
296         ls -lh /mnt/huge
297 }
298
299 #
300 # Options for building a target. Note that this step MUST be first as it sets
301 # up TARGETS[] starting from 1, and this is accessed in setup_target using the
302 # user entered option.
303 #
304 step1_func()
305 {
306         TITLE="Select the DPDK environment to build"
307         CONFIG_NUM=1
308         for cfg in config/defconfig_* ; do
309                 cfg=${cfg/config\/defconfig_/}
310                 TEXT[$CONFIG_NUM]="$cfg"
311                 TARGETS[$CONFIG_NUM]=$cfg
312                 FUNC[$CONFIG_NUM]="setup_target"
313                 let "CONFIG_NUM+=1"
314         done
315 }
316
317 #
318 # Options for setting up environment.
319 #
320 step2_func()
321 {
322         TITLE="Setup linuxapp environment"
323
324         TEXT[1]="Insert IGB UIO module"
325         FUNC[1]="load_igb_uio_module"
326
327         TEXT[2]="Setup hugepage mappings for non-NUMA systems"
328         FUNC[2]="set_non_numa_pages"
329
330         TEXT[3]="Setup hugepage mappings for NUMA systems"
331         FUNC[3]="set_numa_pages"
332 }
333
334 #
335 # Options for running applications.
336 #
337 step3_func()
338 {
339         TITLE="Run test application for linuxapp environment"
340
341         TEXT[1]="Run test application (\$RTE_TARGET/app/test)"
342         FUNC[1]="run_test_app"
343
344         TEXT[2]="Run testpmd application in interactive mode (\$RTE_TARGET/app/testpmd)"
345         FUNC[2]="run_testpmd_app"
346 }
347
348 #
349 # Other options
350 #
351 step4_func()
352 {
353         TITLE="Other tools"
354
355         TEXT[1]="List hugepage info from /proc/meminfo"
356         FUNC[1]="grep_meminfo"
357
358         TEXT[2]="List hugepage files in /mnt/huge"
359         FUNC[2]="ls_mnt_huge"
360 }
361
362 #
363 # Options for cleaning up the system
364 #
365 step5_func()
366 {
367         TITLE="Uninstall and system cleanup"
368
369         TEXT[1]="Uninstall all targets"
370         FUNC[1]="uninstall_targets"
371
372         TEXT[2]="Remove IGB UIO module"
373         FUNC[2]="remove_igb_uio_module"
374
375         TEXT[3]="Remove hugepage mappings"
376         FUNC[3]="clear_huge_pages"
377 }
378
379 STEPS[1]="step1_func"
380 STEPS[2]="step2_func"
381 STEPS[3]="step3_func"
382 STEPS[4]="step4_func"
383 STEPS[5]="step5_func"
384
385 QUIT=0
386
387 while [ "$QUIT" == "0" ]; do
388         OPTION_NUM=1
389
390         for s in $(seq ${#STEPS[@]}) ; do
391                 ${STEPS[s]}
392
393                 echo "----------------------------------------------------------"
394                 echo " Step $s: ${TITLE}"
395                 echo "----------------------------------------------------------"
396
397                 for i in $(seq ${#TEXT[@]}) ; do
398                         echo "[$OPTION_NUM] ${TEXT[i]}"
399                         OPTIONS[$OPTION_NUM]=${FUNC[i]}
400                         let "OPTION_NUM+=1"
401                 done
402
403                 # Clear TEXT and FUNC arrays before next step
404                 unset TEXT
405                 unset FUNC
406
407                 echo ""
408         done
409
410         echo "[$OPTION_NUM] Exit Script"
411         OPTIONS[$OPTION_NUM]="quit"
412         echo ""
413         echo -n "Option: "
414         read our_entry
415         echo ""
416         ${OPTIONS[our_entry]} ${our_entry}
417         echo
418         echo -n "Press enter to continue ..."; read
419 done