Whamcloud - gitweb
- allow most everything to be overridden on the command line
[fs/lustre-release.git] / lustre-iokit / obdfilter-survey / obdfilter-survey
1 #!/bin/bash
2
3 ######################################################################
4 # customize per survey
5
6 # specify obd instances to exercise
7 # these can be either...
8 # obdfilter instances (set 'ost_names')
9 # ...or...
10 # echo_client instances (set 'client_names')
11 # ... use 'host:name' for obd instances on other nodes.
12
13 # allow these to be passed in via string...
14 ost_names_str=${ost_names_str:-""}
15 if [ -n "$ost_names_str" ]; then
16     declare -a ost_names
17     count=0
18     for name in $ost_names_str; do
19         ost_names[$count]=$name
20         count=$((count+1))
21     done
22 else
23     ost_names=(ost{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16})
24 fi
25
26 #client_names=(ns8:ECHO_ns8 ns9:ECHO_ns9)
27 client_names_str=${client_names_str:-""}
28 if [ -n "$client_names_str" ]; then
29     # make sure we unset ost_names so that our client_names get noticed... 
30     unset ost_names
31     declare -a client_names
32     count=0
33     for name in $client_names_str; do
34         client_names[$count]=$name
35         count=$((count+1))
36     done
37 fi
38
39 # result file prefix (date/time + hostname makes unique)
40 # NB ensure path to it exists
41 rslt=${rslt:-"/home_nfs/eeb/obdfilter_survey_`date +%F@%R`_`uname -n`"}
42
43 # lustre root (if running with own source tree)
44 lustre_root=${lustre_root:-"/home_nfs/eeb/lustre"}
45
46 # what tests to run (first must be write)
47 tests_str=${tests_str:-""}
48 if [ -n "$tests_str" ]; then
49     declare -a tests
50     count=0
51     for name in $tests_str; do
52         tests[$count]=$name
53         count=$((count+1))
54     done
55 else
56     #tests=(write rewrite read reread rewrite_again)
57     tests=(write rewrite read)
58 fi
59
60 # total size (MBytes) per obd instance
61 # large enough to avoid cache effects 
62 # and to make test startup/shutdown overhead insignificant
63 size=${size:-16384}
64
65 # record size (KBytes)
66 rszlo=${rszlo:-1024}
67 rszhi=${rszhi:-1024}
68
69 # number of objects per OST
70 nobjlo=${nobjlo:-1}
71 nobjhi=${nobjhi:-512}
72
73 # threads per OST (1024 max)
74 thrlo=${thrlo:-1}
75 thrhi=${thrhi:-64}
76
77 # restart from here iff all are defined
78 restart_rsz=
79 restart_thr=1
80 restart_nobj=1
81
82 # machine's page size (K)
83 PAGE_SIZE=${PAGE_SIZE:-16}
84
85 # max buffer_mem (total_threads * buffer size)
86 # (to avoid lctl ENOMEM problems)
87 max_buffer_mem=$((1024*1024))
88
89 # how to run commands on other nodes
90 # You need to make this work on your cluster if you have specified
91 # non-local obd instances above
92 custom_remote_shell () {
93     host=$1
94     shift
95     cmds="$*"
96     here=`pwd`
97     # Hop on to the remote node, chdir to 'here' and run the given
98     # commands. One of the following will probably work.
99     #ssh $host "cd $here; $cmds"
100     #rsh $host "cd $here; $cmds"
101     # we have to remove the leading `uname -n`: from pdsh output lines
102     pdsh -w $host "cd $here; $cmds" | sed 's/^[^:]*://'
103 }
104
105 #####################################################################
106 # leave the rest of this alone unless you know what you're doing...
107
108 # binaries
109 lsmod="/sbin/lsmod"
110 modprobe="/sbin/modprobe"
111 insmod="/sbin/insmod"
112 rmmod="/sbin/rmmod"
113
114 # lctl::test_brw bandwidth snapshot interval (seconds)
115 snap=1
116 # check file contents?
117 verify=1
118
119 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
120     echo "tests: ${tests[@]}"
121     echo "First test must be 'write'" 1>&2
122     exit 1
123 fi
124
125 rsltf="${rslt}.summary"
126 workf="${rslt}.detail"
127 cmdsf="${rslt}.script"
128 echo -n > $rsltf
129 echo -n > $workf
130
131
132 # hide a little trick to unset this from the command line
133 if [ "$lustre_root" == " " ]; then
134     unset lustre_root
135 fi
136
137 if [ -z "$lustre_root" ]; then
138     lctl=$(which lctl)
139 else
140     lctl=${lustre_root}/utils/lctl
141 fi
142
143 remote_shell () {
144     host=$1
145     shift
146     cmds="$*"
147     if [ "$host" = "localhost" -o "$host" = `uname -n` ]; then
148         eval "$cmds"
149     else
150         custom_remote_shell $host "$cmds"
151     fi
152 }
153
154 obdecho_loaded() {
155     local host=$1
156     remote_shell $host $lsmod | grep obdecho > /dev/null 2>&1
157 }
158
159 load_obdecho () {
160     local host=$1
161     if [ -z "$lustre_root" ]; then
162         remote_shell $host $modprobe obdecho
163     elif [ -f ${lustre_root}/obdecho/obdecho.ko ]; then
164         remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.ko
165     else
166         remote_shell $host $insmod ${lustre_root}/obdecho/obdecho.o
167     fi
168 }
169
170 unload_obdecho () {
171     local host=$1
172     remote_shell $host $rmmod obdecho
173 }
174
175 get_devno () {
176     local host=$1
177     local type=$2
178     local name=$3
179     remote_shell $host $lctl device_list | \
180         awk "{if (\$2 == \"UP\" && \$3 == \"$type\" && \$4 == \"$name\") {\
181                   print \$1; exit}}"
182 }
183
184 get_ec_devno () {
185     local host=$1
186     local client_name="$2"
187     local ost_name="$3"
188     if [ -z "$client_name" ]; then
189         if [ -z "$ost_name" ]; then
190             echo "client and ost name both null" 1>&2
191             return
192         fi
193         client_name=${ost_name}_echo_client
194     fi
195     ec=`get_devno $host echo_client $client_name`
196     if [ -n "$ec" ]; then
197         echo $ec $client_name 0
198         return
199     fi
200     if [ -z "$ost_name" ]; then
201         echo "no echo client and ost_name not set" 1>&2
202         return
203     fi
204     ost=`get_devno $host obdfilter $ost_name`
205     if [ -z "$ost" ]; then
206         echo "OST $ost_name not setup" 1>&2
207         return
208     fi
209     remote_shell $host "$lctl <<EOF
210         attach echo_client $client_name ${client_name}_UUID
211         setup $ost_name
212 EOF"
213     ec=`get_devno $host echo_client $client_name`
214     if [ -z "$ec" ]; then
215         echo "Can't setup echo client" 1>&2
216         return
217     fi
218     echo $ec $client_name 1
219 }
220
221 teardown_ec_devno () {
222     local host=$1
223     local client_name=$2
224     remote_shell $host "$lctl <<EOF
225         cfg $client_name
226         cleanup
227         detach
228 EOF"
229 }
230
231 create_objects () {
232     # create a set of objects, check there are 'n' contiguous ones and
233     # return the first or 'ERROR'
234     local host=$1
235     local devno=$2
236     local nobj=$3
237     local rfile=$4
238     remote_shell $host $lctl --device $devno create $nobj > $rfile 2>&1
239     first=0
240     prev=0
241     count=0
242     error=0
243     while read line; do
244         echo "$line" | grep -q 'is object id'
245         if [ $?  -ne 0 ]; then
246             continue
247         fi
248         if [ $first -eq 0 ]; then
249             first=$(echo $line | awk '{print $6}')
250             first=$(printf "%d" $first)
251             prev=$first
252             count=1
253         else
254             obj=$(echo $line | awk '{print $6}') 
255             obj=$(printf "%d" $obj) 
256             diff=$((obj - (prev+1))) 
257             if [ $diff -ne 0 ]; then 
258                 error=1 
259             fi 
260             prev=$obj 
261             count=$((count+1)) 
262         fi 
263     done < $rfile 
264     if [ $nobj -ne $count ]; then 
265         echo "ERROR: $nobj != $count" >&2 
266         cat $rfile >&2 
267         echo "ERROR" 
268     elif [ $error -ne 0 ]; then 
269         echo "ERROR: non contiguous objs found" >&2 
270         echo "ERROR" 
271     else 
272         echo $first 
273     fi
274 }
275
276 destroy_objects () {
277     local host=$1
278     local devno=$2
279     local obj0=$3
280     local nobj=$4
281     local rfile=$5
282     remote_shell $host $lctl --device $devno destroy $obj0 $nobj > $rfile 2>&1
283 }
284
285 get_stats () {
286     local rfile=$1
287     awk < $rfile \
288         '/^Selected device [0-9]+$/ {n = 0; next}\
289         /error/ {n = -1; exit}\
290         /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ {n++; v=strtonum($3); \
291                                                           if (n == 1 || v < min) min = v;\
292                                                           if (n == 1 || v > max) max = v;\
293                                                           next}\
294         {if (n != 0) {n = -1; exit}}\
295         END {printf "%d %f %f\n", n, min, max}'
296 }
297
298 get_global_stats () {
299     local rfile=$1
300     awk < $rfile 'BEGIN {n = 0;}\
301                   {n++; if (n == 1) {err = $1; min = $2; max = $3} else\
302                                     {if ($1 < err) err = $1;\
303                                      if ($2 < min) min = $2;\
304                                      if ($3 > max) max = $3}}\
305                   END {if (n == 0) err = 0;\
306                        printf "%d %f %f\n", err, min, max}'
307 }
308
309 testname2type () {
310     # 'x' disables data check
311     if ((verify)); then
312         x=""
313     else
314         x="x"
315     fi
316     case $1 in
317         *write*)  echo "w$x";;
318         *)        echo "r$x";;
319     esac
320 }
321
322 print_summary () {
323     if [ "$1" = "-n" ]; then
324         minusn=$1; shift
325     else
326         minusn=""
327     fi
328     echo $minusn "$*" >> $rsltf
329     echo $minusn "$*"
330 }
331
332 unique () {
333     echo "$@" | xargs -n1 echo | sort -u
334 }
335
336 split_hostname () {
337     local name=$1
338     case $name in
339     *:*) host=`echo $name | sed 's/:.*$//'`
340          name=`echo $name | sed 's/[^:]*://'`
341          ;;
342     *)   host=localhost
343          ;;
344     esac
345     echo "$host $name"
346 }
347
348 # split out hostnames from client/ost names
349 ndevs=${#client_names[@]}
350 if ((ndevs != 0)); then
351     if ((${#ost_names[@]} != 0)); then
352         echo "Please specify client_names or ost_names, but not both" 1>&2
353         exit 1
354     fi
355     for ((i=0; i<ndevs;i++)); do
356         str=(`split_hostname ${client_names[$i]}`)
357         host_names[$i]=${str[0]}
358         client_names[$i]=${str[1]}
359     done
360 else
361     ndevs=${#ost_names[@]}
362     if ((ndevs == 0)); then
363         echo "Please specify either client_names or ost_names" 1>&2
364         exit 1
365     fi
366     for ((i=0; i<ndevs;i++)); do
367         str=(`split_hostname ${ost_names[$i]}`)
368         host_names[$i]=${str[0]}
369         ost_names[$i]=${str[1]}
370     done
371 fi
372
373 # disable portals debug and get obdecho loaded on all relevant hosts
374 unique_hosts=(`unique ${host_names[@]}`)
375 for host in ${unique_hosts[@]}; do
376     remote_shell $host "echo 0 > /proc/sys/portals/debug"
377     do_unload_obdecho[$host]=0
378     if obdecho_loaded $host; then
379         continue
380     fi
381     load_obdecho $host
382     if obdecho_loaded $host; then
383         do_unload_obdecho[$host]=1
384         continue
385     fi
386     echo "Can't load obdecho on $host" 1>&2
387     exit 1
388 done
389
390 # get all the echo_client device numbers and names
391 for ((i=0; i<ndevs; i++)); do
392     host=${host_names[$i]}
393     devno=(`get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"`)
394     if ((${#devno[@]} != 3)); then
395         exit 1
396     fi
397     devnos[$i]=${devno[0]}
398     client_names[$i]=${devno[1]}
399     do_teardown_ec[$i]=${devno[2]}
400 done
401
402 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
403     for ((nobj=$nobjlo;nobj<=$nobjhi;nobj*=2)); do 
404         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
405             if ((thr < nobj)); then
406                 continue
407             fi
408             # restart?
409             if [ -n "$restart_rsz" -a\
410                  -n "$restart_nobj" -a\
411                  -n "$restart_thr" ]; then
412                 if ((rsz < restart_rsz ||\
413                      (rsz == restart_rsz &&\
414                       (nobj < restart_nobj ||\
415                        (nobj == restart_nobj &&\
416                         thr < restart_thr))))); then
417                     continue;
418                 fi
419             fi
420             # compute parameters
421             total_thr=$((ndevs*thr))
422             total_nobj=$((ndevs*nobj))
423             pages=$((rsz/PAGE_SIZE))
424             actual_rsz=$((pages*PAGE_SIZE))
425             count=$((size*1024/(actual_rsz*thr)))
426             actual_size=$((actual_rsz*count*thr))
427             total_size=$((actual_size*ndevs))
428             # show computed parameters
429             str=`printf 'ost %2d sz %8dK rsz %4d obj %4d thr %4d ' \
430                      $ndevs $total_size $actual_rsz $total_nobj $total_thr`
431             echo "=======================> $str" >> $workf
432             print_summary -n "$str"
433             if ((total_thr * actual_rsz > max_buffer_mem)); then
434                 print_summary "Too much buffer space"
435                 continue
436             fi
437             # create the objects
438             tmpf="${workf}_tmp"
439             for ((idx=0; idx < ndevs; idx++)); do
440                 host=${host_names[$idx]}
441                 devno=${devnos[$idx]}
442                 client_name="${host}:${client_names[$idx]}"
443                 echo "=============> Create $nobj on $client_name" >> $workf
444                 first_obj=`create_objects $host $devno $nobj $tmpf`
445                 cat $tmpf >> $workf
446                 rm $tmpf
447                 if [ $first_obj = "ERROR" ]; then
448                     print_summary "created object #s on $client_name not contiguous"
449                     exit 1
450                 fi
451                 first_objs[$idx]=$first_obj
452             done
453             # run tests
454             for test in ${tests[@]}; do
455                 print_summary -n "$test "
456                 # create per-host script files
457                 for host in ${unique_hosts[@]}; do
458                     echo -n > ${cmdsf}_${host}
459                 done
460                 for ((idx=0; idx < ndevs; idx++)); do
461                     host=${host_names[$idx]}
462                     devno=${devnos[$idx]}
463                     tmpfi="${tmpf}_$idx"
464                     first_obj=${first_objs[$idx]}
465                     echo >> ${cmdsf}_${host} \
466                         "$lctl > $tmpfi 2>&1 \\
467                          --threads $thr -$snap $devno \\
468                          test_brw $count `testname2type $test` q $pages ${thr}t${first_obj} &"
469                 done
470                 for host in ${unique_hosts[@]}; do
471                     echo "wait" >> ${cmdsf}_${host}
472                 done
473                 # timed run of all the per-host script files
474                 t0=`date +%s.%N`
475                 for host in ${unique_hosts[@]}; do
476                     remote_shell $host bash ${cmdsf}_${host}&
477                 done
478                 wait
479                 t1=`date +%s.%N`
480                 # clean up per-host script files
481                 for host in ${unique_hosts[@]}; do
482                     rm ${cmdsf}_${host}
483                 done
484                 # compute bandwidth from total data / elapsed time
485                 str=`awk "BEGIN {printf \"%7.2f \",\
486                          $total_size / (( $t1 - $t0 ) * 1024)}"`
487                 print_summary -n "$str"
488                 # collect/check individual OST stats
489                 echo -n > $tmpf
490                 for ((idx=0; idx < ndevs; idx++)); do
491                     client_name="${host_names[$idx]}:${client_names[$idx]}"
492                     tmpfi="${tmpf}_$idx"
493                     echo "=============> $test $client_name" >> $workf
494                     cat $tmpfi >> $workf
495                     get_stats $tmpfi >> $tmpf
496                     rm $tmpfi
497                 done
498                 # compute/display global min/max stats
499                 echo "=============> $test global" >> $workf
500                 cat $tmpf >> $workf
501                 stats=(`get_global_stats $tmpf`)
502                 rm $tmpf
503                 if ((stats[0] <= 0)); then
504                     if ((stats[0] < 0)); then
505                         str=`printf "%17s " ERROR`
506                     else
507                         str=`printf "%17s " SHORT`
508                     fi
509                 else
510                     str=`awk "BEGIN {printf \"[%7.2f,%7.2f] \",\
511                              (${stats[1]} * $actual_rsz)/1024,\
512                              (${stats[2]} * $actual_rsz)/1024; exit}"`
513                 fi
514                 print_summary -n "$str"
515             done
516             print_summary ""
517             # destroy objects we created
518             for ((idx=0; idx < ndevs; idx++)); do
519                 host=${host_names[$idx]}
520                 devno=${devnos[$idx]}
521                 client_name="${host}:${client_names[$idx]}"
522                 first_obj=${first_objs[$idx]}
523                 echo "=============> Destroy $nobj on $client_name" >> $workf
524                 destroy_objects $host $devno $first_obj $nobj $tmpf
525                 cat $tmpf >> $workf
526                 rm $tmpf
527             done
528         done
529     done
530 done
531
532 # tear down any echo clients we created
533 for ((i=0; i<ndevs; i++)); do
534     host=${host_names[$i]}
535     if ((${do_teardown_ec[$i]})); then
536         teardown_ec_devno $host ${client_names[$i]}
537     fi
538 done
539
540 # unload any obdecho modules we loaded
541 for host in ${unique_hosts[@]}; do
542     if ((${do_unload_obdecho[$host]})); then
543         unload_obdecho $host
544     fi
545 done