Whamcloud - gitweb
LU-5396 lov: (and ldlm) make some functions static
[fs/lustre-release.git] / lustre-iokit / obdfilter-survey / obdfilter-survey
1 #!/bin/bash
2 set -e
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 # allow these to be passed in via string...
13 # OR
14 # one can specify only case=disk or case=network or case=netdisk through
15 # command line.
16
17 # Perquisite: For "disk" case and "netdisk" case you need to have lustre setup
18 #             with one or more ost's. For "network" case  you need to have all
19 #             modules (those llmount.sh loades) loaded in kernel. And the
20 #             'lctl dl' output must be blank.
21
22 # How to run test:
23 # case 1 (local disk):
24 #   $ nobjhi=2 thrhi=2 size=1024 case=disk sh obdfilter-survey
25 #   one can also run test with user defined targets as follows,
26 #   $ nobjhi=2 thrhi=2 size=1024 targets="lustre-OST0000 lustre-OST0001 ..." sh obdfilter-survey
27 # case 2 (network):
28 #   $ nobjhi=2 thrhi=2 size=1024 targets="<name/ip_of_server>" case=network sh obdfilter-survey
29 #   where, targets is name or ip address of system, which you want to
30 #   set as server.
31 # case 3 (network and disk):
32 #   $ nobjhi=2 thrhi=2 size=1024 case=netdisk sh obdfilter-survey
33 #   one can also run test with user defined targets as follows,
34 #   $ nobjhi=2 thrhi=2 size=1024 targets="<osc_name> ..." sh obdfilter-survey
35 #[ NOTE: It is advised to have automated login (passwordless entry) between server and
36 #  client systems on which this test runs.]
37
38 # include library
39 source $(dirname $0)/iokit-libecho
40
41 # The following variables can be set in the environment, or on the
42 # command line
43 # result file prefix (date/time + hostname makes unique)
44 # NB ensure path to it exists
45 rslt_loc=${rslt_loc:-"/tmp"}
46 rslt=${rslt:-"$rslt_loc/obdfilter_survey_$(date +%F@%R)_$(uname -n)"}
47
48 # Set this true to check file contents
49 verify=${verify:-0}
50
51 # test targets
52 targets=${targets:-""}
53 # test case
54 case=${case:-"disk"}
55
56 # total size (MBytes) per obd instance
57 # large enough to avoid cache effects
58 # and to make test startup/shutdown overhead insignificant
59 size=${size:-16384}
60
61 # record size (KBytes) ( 7168 max)
62 rszlo=${rszlo:-1024}
63 rszhi=${rszhi:-1024}
64 rszmax=${rszmax:-4096}
65
66 # number of objects per OST
67 nobjlo=${nobjlo:-1}
68 #was nobjhi=${nobjhi:-512}
69 nobjhi=${nobjhi:-16}
70
71 # threads per OST (1024 max)
72 thrlo=${thrlo:-1}
73 thrhi=${thrhi:-16}
74
75 export LC_ALL=POSIX
76
77 # End of variables
78
79 # create a set of objects, check there are 'n' contiguous ones and
80 # echo out the first or 'ERROR'
81 # parameter: 1. hostname
82 #            2. device number
83 #            3. number of object to be created (specified by user)
84 #            4. tempfile name
85 create_objects () {
86         local host=$1
87         local devno=$2
88         local nobj=$3
89         local rfile=$4
90
91         remote_shell $host $lctl --device $devno create $nobj > $rfile 2>&1
92         first=0
93         prev=0
94         count=0
95         error=0
96
97         # Count number of objects (lines containing " is object id "), and
98         # ensure that the objects numbers are sequential.
99         #
100         exec 3< $rfile
101         while read -u3 line; do
102                 case "$line" in
103                 ( *' is object id '* )
104                 set -- $line
105                 if test $(( count += 1 )) -gt 1 ; then
106                         (( $6 != prev + 1 )) && error=1
107                 else
108                         first=$(( $6 + 0 ))
109                 fi
110                 prev=$6
111                 ;;
112                 esac
113         done
114         exec 3<&-
115
116         if [ $nobj -ne $count ]; then
117                 echo "ERROR: $nobj != $count" >&2
118                 cat $rfile >&2
119                 echo "ERROR"
120         elif [ $error -ne 0 ]; then
121                 echo "ERROR: non contiguous objs found" >&2
122                 echo ERROR
123         else
124                 echo $first
125         fi
126         return $error
127 }
128
129 # destroys all objects created in create_objects routine
130 # parameter: 3. start obj id.
131 destroy_objects () {
132         local host=$1
133         local devno=$2
134         local obj0=$3
135         local nobj=$4
136         local rfile=$5
137
138         remote_shell $host $lctl --device $devno destroy $obj0 $nobj > $rfile 2>&1
139 }
140
141 get_stats () {
142         local rfile=$1
143
144         gawk < $rfile                                                   \
145         '/^Selected device [0-9]+$/ {                                   \
146                 n = 0;                                                  \
147                 next;                                                   \
148         }                                                               \
149         /error/ {                                                       \
150                 n = -1;                                                 \
151                 exit;                                                   \
152         }                                                               \
153         /^Total/ {                                                      \
154                 next;                                                   \
155         }                                                               \
156         /^[0-9]+\/[0-9]+ Total: [0-9]+\.[0-9]+\/second$/ {              \
157                 n++;                                                    \
158                 v=strtonum($3);                                         \
159                 if (n == 1 || v < min)                                  \
160                         min = v;                                        \
161                 if (n == 1 || v > max)                                  \
162                         max = v;                                        \
163                 next;                                                   \
164         }                                                               \
165         {                                                               \
166                 if (n != 0) {                                           \
167                         n = -1;                                         \
168                         exit;                                           \
169                 }                                                       \
170         }                                                               \
171         END {                                                           \
172                 printf "%d %f %f\n", n, min, max                        \
173         }'
174 }
175
176 get_global_stats () {
177         local rfile=$1
178
179         awk < $rfile                                                    \
180         'BEGIN {                                                        \
181                 n = 0;                                                  \
182         }                                                               \
183         {                                                               \
184                 n++;                                                    \
185                 if (n == 1) {                                           \
186                         err = $1;                                       \
187                         min = $2;                                       \
188                         max = $3;                                       \
189                 } else {                                                \
190                         if ($1 < err)                                   \
191                                 err = $1;                               \
192                         if ($2 < min)                                   \
193                                 min = $2;                               \
194                         if ($3 > max)                                   \
195                                 max = $3;                               \
196                 }                                                       \
197         }                                                               \
198         END {                                                           \
199                 if (n == 0)                                             \
200                         err = 0;                                        \
201                 printf "%d %f %f\n", err, min, max                      \
202         }'
203 }
204
205 # enable or disable data check.
206 # parameter: 1. read/write
207 testname2type () {
208         # 'x' disables data check
209         if ((verify)); then
210                 x=""
211         else
212                 x="x"
213         fi
214         case $1 in
215         *write*)  echo "w$x";;
216         *)        echo "r$x";;
217         esac
218 }
219
220 # for "echo_client + obdfilter" case, "prep + commit" mode should be used
221 # for "echo_client + osc" case, "BRW" mode should be used
222 testcase2mode() {
223         case $case in
224         disk)   echo "p";;
225         *)      echo "g";;
226         esac
227 }
228
229 print_summary () {
230         if [ "$1" = "-n" ]; then
231                 minusn=$1; shift
232         else
233                 minusn=""
234         fi
235         echo $minusn "$*" >> $rsltf
236         echo $minusn "$*"
237 }
238
239 version_code() {
240         # split arguments like "2.3.61" into "2", "3", "61"
241         eval set -- $(tr "[:punct:]" " " <<< $*)
242         echo -n "$((($1 << 16) | ($2 << 8) | $3))"
243 }
244
245 get_lustre_version() {
246         local host=${1:-${unique_hosts[0]}}
247         remote_shell $host $lctl get_param -n version |
248                 awk '/^lustre:/ {print $2}'
249 }
250
251 # Check whether the record size (KBytes) exceeds the maximum bulk I/O RPC size
252 # or not.
253 check_record_size() {
254         [ $(version_code $(get_lustre_version)) -lt $(version_code 2.3.61) ] &&
255                 rszmax=1024
256
257         if [ "$rszhi" -gt "$rszmax" ]; then
258                 echo "Test disk case support maximum ${rszmax}KB IO data" \
259                      "(rszhi=$rszhi is too big), please use a smaller value."
260                 return 1
261         fi
262         return 0
263 }
264
265 # Customisation variables
266 #####################################################################
267 # One can change variable values in this section as per requirements
268
269 if [ -n "$targets" ]; then
270         declare -a ost_names
271         declare -a client_names
272         count=0
273         for name in $targets; do
274                 if [ $case == "disk" ]; then
275                 ost_names[$count]=$name
276                 else
277                 client_names[$count]=$name
278                 fi
279                 count=$((count + 1))
280         done
281 fi
282
283 # what tests to run (first must be write)
284 tests_str=${tests_str:-""}
285 if [ -n "$tests_str" ]; then
286         declare -a tests
287         count=0
288         for name in $tests_str; do
289                 tests[$count]=$name
290                 count=$((count + 1))
291         done
292 else
293         #tests=(write rewrite read reread rewrite_again)
294         tests=(write rewrite read)
295 fi
296
297 # restart from here iff all are defined
298 restart_rsz=
299 restart_thr=1
300 restart_nobj=1
301
302 # machine's page size (KB)
303 PAGE_SIZE=${PAGE_SIZE:-$(($(getconf PAGE_SIZE) / 1024))}
304 PAGE_SIZE=${PAGE_SIZE:-4}
305
306 # max buffer_mem (total_threads * buffer size)
307 # (to avoid lctl ENOMEM problems)
308 max_buffer_mem=$((1024 * 1024))
309 snap=1
310 clean_srv_OSS=0
311 # Customisation variables ends here.
312 #####################################################################
313 # leave the rest of this alone unless you know what you're doing...
314
315 # check and insert obdecho module
316 if ! lsmod | grep obdecho > /dev/null; then
317         modprobe obdecho
318 fi
319 if [ ${#tests[@]} -eq 0 -o "${tests[0]}" != "write" ]; then
320         echo "tests: ${tests[@]}"
321         echo "First test must be 'write'" 1>&2
322         exit 1
323 fi
324
325 rsltf="${rslt}.summary"
326 workf="${rslt}.detail"
327 cmdsf="${rslt}.script"
328 vmstatf="${rslt}.vmstat"
329 echo -n > $rsltf
330 echo -n > $workf
331
332 # hide a little trick to unset this from the command line
333 if [ "$lustre_root" == " " ]; then
334         unset lustre_root
335 fi
336
337 if [ -z "$lustre_root" ]; then
338         lctl=lctl
339 else
340         lctl=${lustre_root}/utils/lctl
341 fi
342
343 # split out hostnames from client/ost names
344 ndevs=0
345 for trgt in $targets; do
346         str=($(split_hostname $trgt))
347         host_names[$ndevs]=${str[0]}
348         client_names[$ndevs]=${str[1]}
349         ndevs=$((ndevs + 1))
350 done
351 if [ $case == "disk" ]; then
352         for ((i = 0; i < $ndevs; i++)); do
353                 ost_names[$i]=${client_names[$i]}
354         done
355 fi
356 if [ $case == "netdisk" ]; then
357         if [ "$targets" ]; then
358                 for ((i = 0; i < $ndevs; i++)); do
359                         setup_osc_for_remote_ost ${host_names[$i]} \
360                                                  ${client_names[$i]} $i
361                         osc_name=${client_names[$i]}_osc
362                         ec_using_osc $osc_name
363                         cleanup_oscs="$cleanup_oscs $osc_name"
364                 done
365         else
366                 client_names_str=$($lctl dl | grep -v mdt |
367                         awk '{if ($2 == "UP" && $3 == "osc") {print $4} }')
368                 count=0;
369                 for name in $client_names_str; do
370                         client_names[$count]=$(echo $name | sed 's/-osc-.*$//')
371                         count=$((count + 1))
372                 done
373
374                 host_names_str=$($lctl dl -t | grep -v mdt |
375                         awk '{if ($2 == "UP" && $3 == "osc") {print $7} }')
376                 count=0;
377                 for name in $host_names_str; do
378                         host_names[$count]=$(echo $name | sed 's/@.*$//')
379                         count=$((count + 1))
380                 done
381
382                 for (( i = 0; i < $count; i++ )) do
383                         setup_osc_for_remote_ost ${host_names[$i]} \
384                                                  ${client_names[$i]} $i
385                         osc_name=${client_names[$i]}_osc
386                         ec_using_osc $osc_name
387                         cleanup_oscs="$cleanup_oscs $osc_name"
388                 done
389         fi
390
391         echo_clients=$($lctl dl | grep echo_client |
392                        awk "{if (\$2 == \"UP\" && \$3 == \"echo_client\") { \
393                                 print \$4} }")
394         cnt=0;
395         for name in $echo_clients; do
396                 client_names[$cnt]=$name
397                 host_names[$cnt]=localhost
398                 cnt=$((cnt + 1))
399         done
400         ndevs=${#client_names[@]}
401 fi
402 if [ $case == "network" ]; then
403         server_nid=$targets
404         if [ -z "$server_nid" ]; then
405                 echo "Specify hostname or ip-address of server"
406                 exit 1;
407         fi
408         # check for obdecho module on server
409         if ! dsh $server_nid root "lsmod | grep obdecho > /dev/null"; then
410                 dsh $server_nid root "modprobe obdecho"
411         fi
412         # Now do the server setup
413         setup_srv_obd $server_nid "echo_srv"
414         oss_on_srv=$(dsh $server_nid root "$lctl dl | grep OSS" |
415                      awk '{ print $4 }')
416         if [ -z $oss_on_srv ]; then
417                 setup_OSS $server_nid
418                 clean_srv_OSS=1
419         fi
420         if ! dsh $server_nid root "$lctl dl | grep obdecho > /dev/null 2>&1"; then
421                 echo "obdecho not setup on server"
422                 exit 1
423         fi
424         if ! dsh $server_nid root "$lctl dl | grep ost > /dev/null 2>&1"; then
425                 echo "ost not setup on server"
426                 exit 1
427         fi
428         # Now start client setup
429         osc_names_str=$($lctl dl| grep osc | grep -v mdt | grep UP)
430         if [ -n "$osc_names_str" ]; then
431                 echo "The existing setup must be cleaned";
432                 exit 0;
433         fi
434         ec_using_srv_nid $server_nid "echotmp" "echotmp_UUID"
435         client_names[0]="echotmp_ecc"
436 fi
437 if [ -z "$targets" ]; then
438         if [ $case == "disk" ]; then
439                 get_targets
440                 ndevs=${#ost_names[@]}
441         fi
442 fi
443 # get vmstat started
444 # disable portals debug and get obdecho loaded on all relevant hosts
445 unique_hosts=($(unique ${host_names[@]}))
446 load_obdechos
447
448 if [ $case == "disk" ]; then
449         check_record_size || cleanup ${PIPESTATUS[0]}
450 fi
451
452 pidcount=0
453 for host in ${unique_hosts[@]}; do
454         host_vmstatf=${vmstatf}_${host}
455         echo -n > $host_vmstatf
456         remote_shell $host "vmstat 5 >> $host_vmstatf" &> /dev/null &
457         pid=$!
458         vmstatpids[$pidcount]=$pid
459         pidcount=$((pidcount + 1))
460 done
461 # get all the echo_client device numbers and names
462 for ((i=0; i < $ndevs; i++)); do
463         host=${host_names[$i]}
464         devno=($(get_ec_devno $host "${client_names[$i]}" "${ost_names[$i]}"))
465         if ((${#devno[@]} != 3)); then
466                 exit 1
467         fi
468         devnos[$i]=${devno[0]}
469         client_names[$i]=${devno[1]}
470         do_teardown_ec[$i]=${devno[2]}
471 done
472 if (($ndevs <= 0 || ${#host_names[@]} <= 0)); then
473         echo "no devices or hosts specified"
474         cleanup 0 $clean_srv_OSS $cleanup_oscs
475 fi
476 # Buffers will be spread out among all hosts, so allow for that
477 max_buffer_mem=$(( ${max_buffer_mem} * ${#unique_hosts[@]} ))
478 print_summary "$(date) Obdfilter-survey for case=$case from $(hostname)"
479 for ((rsz = $rszlo; rsz <= $rszhi; rsz*=2)); do
480         for ((nobj = $nobjlo; nobj <= $nobjhi; nobj*=2)); do
481                 for ((thr = $thrlo; thr <= $thrhi; thr*=2)); do
482                         if ((thr % nobj)); then
483                                 continue
484                         fi
485                         # restart?
486                         if [ -n "$restart_rsz" -a \
487                              -n "$restart_nobj" -a \
488                              -n "$restart_thr" ]; then
489                                 if ((rsz < restart_rsz ||
490                                      (rsz == restart_rsz &&
491                                       (nobj < restart_nobj ||
492                                        (nobj == restart_nobj &&
493                                         thr < restart_thr))))); then
494                                         continue;
495                                 fi
496                         fi
497
498                         # compute parameters
499                         total_thr=$((ndevs * thr))
500                         total_nobj=$((ndevs * nobj))
501                         pages=$((rsz / PAGE_SIZE))
502                         actual_rsz=$((pages * PAGE_SIZE))
503                         count=$((size * 1024 / (actual_rsz * thr)))
504                         actual_size=$((actual_rsz * count * thr))
505                         total_size=$((actual_size * ndevs))
506
507                         # show computed parameters
508                         str=$(printf 'ost %2d sz %8dK rsz %4dK obj %4d thr %4d ' \
509                               $ndevs $total_size $actual_rsz $total_nobj $total_thr)
510                         echo "=======================> $str" >> $workf
511                         print_summary -n "$str"
512                         if ((total_thr * actual_rsz > max_buffer_mem)); then
513                                 print_summary "Too much buffer space"
514                                 continue
515                         fi
516
517                         # create the objects
518                         tmpf="${workf}_tmp"
519                         for ((idx = 0; idx < $ndevs; idx++)); do
520                                 host=${host_names[$idx]}
521                                 devno=${devnos[$idx]}
522                                 client_name="${host}:${client_names[$idx]}"
523                                 echo "=============> Create $nobj on $client_name" >> $workf
524                                 first_obj=$(create_objects $host $devno $nobj $tmpf)
525                                 cat $tmpf >> $workf
526                                 rm $tmpf
527                                 if [ $first_obj = "ERROR" ]; then
528                                         print_summary "created object #s on $client_name not contiguous"
529                                         exit 1
530                                 fi
531                                 first_objs[$idx]=$first_obj
532                         done # $ndevs
533
534                         # run tests
535                         for test in ${tests[@]}; do
536                                 declare -a pidarray
537                                 for host in ${unique_hosts[@]}; do
538                                         echo "starting run for test: $test rsz: $rsz " \
539                                         "threads: $thr objects: $nobj" >> ${vmstatf}_${host}
540                                 done
541                                 print_summary -n "$test "
542
543                                 # create per-host script files
544                                 for host in ${unique_hosts[@]}; do
545                                         echo -n > ${cmdsf}_${host}
546                                 done
547                                 for ((idx = 0; idx < $ndevs; idx++)); do
548                                         host=${host_names[$idx]}
549                                         devno=${devnos[$idx]}
550                                         tmpfi="${tmpf}_$idx"
551                                         first_obj=${first_objs[$idx]}
552                                         thr_per_obj=$((${thr}/${nobj}))
553                                         echo >> ${cmdsf}_${host} \
554                                         "$lctl > $tmpfi 2>&1 \\
555                                         --threads $thr -$snap $devno \\
556                                         test_brw $count $(testname2type $test) q $pages \\
557                                         ${thr_per_obj}t${first_obj} $(testcase2mode)$pages &"
558                                 done # $ndevs
559                                 pidcount=0
560                                 for host in ${unique_hosts[@]}; do
561                                         echo "wait" >> ${cmdsf}_${host}
562                                         pidarray[$pidcount]=0
563                                         pidcount=$((pidcount + 1))
564                                 done
565                                 # timed run of all the per-host script files
566                                 t0=$(date +%s.%N)
567                                 pidcount=0
568                                 for host in ${unique_hosts[@]}; do
569                                         remote_shell $host bash < ${cmdsf}_${host} &
570                                         pidarray[$pidcount]=$!
571                                         pidcount=$((pidcount + 1))
572                                 done
573                                 pidcount=0
574                                 for host in ${unique_hosts[@]}; do
575                                         wait ${pidarray[$pidcount]}
576                                         pidcount=$((pidcount + 1))
577                                 done
578                                 #wait
579                                 t1=$(date +%s.%N)
580                                 # clean up per-host script files
581                                 for host in ${unique_hosts[@]}; do
582                                         rm ${cmdsf}_${host}
583                                 done
584
585                                 # compute bandwidth from total data / elapsed time
586                                 str=$(awk "BEGIN {printf \"%7.2f \",\
587                                 $total_size / (( $t1 - $t0 ) * 1024)}")
588                                 print_summary -n "$str"
589                                 # collect/check individual OST stats
590                                 echo -n > $tmpf
591                                 for ((idx = 0; idx < $ndevs; idx++)); do
592                                         client_name="${host_names[$idx]}:${client_names[$idx]}"
593                                         tmpfi="${tmpf}_$idx"
594                                         echo "=============> $test $client_name" >> $workf
595                                         host="${host_names[$idx]}"
596                                         remote_shell $host cat $tmpfi > ${tmpfi}_local
597                                         cat ${tmpfi}_local >> $workf
598                                         get_stats ${tmpfi}_local >> $tmpf
599                                         rm -f $tmpfi ${tmpfi}_local
600                                 done # $ndevs
601
602                                 # compute/display global min/max stats
603                                 echo "=============> $test global" >> $workf
604                                 cat $tmpf >> $workf
605                                 stats=($(get_global_stats $tmpf))
606                                 rm $tmpf
607                                 if ((stats[0] <= 0)); then
608                                         if ((stats[0] < 0)); then
609                                                 str=$(printf "%17s " ERROR)
610                                         else
611                                                 str=$(printf "%17s " SHORT)
612                                         fi
613                                 else
614                                         str=$(awk "BEGIN {printf \"[%7.2f,%7.2f] \",\
615                                         (${stats[1]} * $actual_rsz)/1024,\
616                                         (${stats[2]} * $actual_rsz)/1024; exit}")
617                                 fi
618                                 print_summary -n "$str"
619                         done # $tests[]
620                         print_summary ""
621
622                         # destroy objects we created
623                         for ((idx = 0; idx < $ndevs; idx++)); do
624                                 host=${host_names[$idx]}
625                                 devno=${devnos[$idx]}
626                                 client_name="${host}:${client_names[$idx]}"
627                                 first_obj=${first_objs[$idx]}
628                                 echo "=============> Destroy $nobj on $client_name" >> $workf
629                                 destroy_objects $host $devno $first_obj $nobj $tmpf
630                                 cat $tmpf >> $workf
631                                 rm $tmpf
632                         done # $ndevs
633                 done # $thr
634         done # $nobj
635 done # $rsz
636 cleanup 0 $clean_srv_OSS $cleanup_oscs
637 exit 0