Whamcloud - gitweb
* Debugged sgpdd-survey multi-device support on Bull server
[fs/lustre-release.git] / lustre-iokit / sgpdd-survey / sgpdd-survey
1 #!/bin/bash
2
3 ######################################################################
4 # customize per survey
5
6 # the SCSI devices to measure
7 scsidevs="/dev/sde /dev/sdh"
8
9 # result file prefix
10 # NB ensure the path exists if it includes subdirs
11 rslt=/tmp/sg_dd_rslt
12
13 # what to do (read or write)
14 actions="write read"
15
16 # total size per device (MBytes)
17 # NB bigger than device cache is good
18 size=8192
19
20 # record size (KBytes)
21 rszlo=1024
22 rszhi=1024
23
24 # Concurrent regions per device
25 crglo=1
26 crghi=128
27
28 # threads to share between concurrent regions per device
29 # NB survey skips over #thr < #regions
30 thrlo=1
31 thrhi=128
32
33 #####################################################################
34
35 # disk block size (Bytes)
36 bs=512
37
38 # max # threads per individual sgp_dd instance
39 SG_MAX_QUEUE=16
40
41 i=0
42 devs=()
43 for d in $scsidevs; do
44     devs[$i]=`sg_map | awk "{if ($ 2 == \"$d\") print $ 1}"`
45     if [ -z "$devs[$i]" ]; then
46         echo "Can't find SG device for $d"
47         exit 1
48     fi
49     i=$((i+1))
50 done
51 ndevs=${#devs[@]}
52
53 start=`date +%F@%R`
54 rsltf=${rslt}_${start}.summary
55 echo -n > $rsltf
56 workf=${rslt}_${start}.detail
57 echo -n > $workf
58 tmpf=${rslt}_${start}.tmp
59
60 print_summary () {
61     if [ "$1" = "-n" ]; then
62         minusn=$1; shift
63     else
64         minusn=""
65     fi
66     echo $minusn "$*" >> $rsltf
67     echo $minusn "$*"
68 }
69
70 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
71     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
72         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
73             if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
74                 continue
75             fi
76             # compute parameters
77             bpt=$((rsz*1024/bs))
78             blocks=$((size*((1024*1024)/bs)/crg))
79             count=$blocks
80             # show computed parameters
81             actual_rsz=$((bpt*bs/1024))
82             actual_size=$((bs*count*crg/1024))
83             str=`printf 'total_size %8dK rsz %4d crg %5d thr %3d ' \
84                          $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
85             echo "==============> $str" >> $workf
86             print_summary -n "$str"
87             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
88             if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
89                 print_summary "ENOMEM"
90                 continue
91             fi
92             for action in $actions; do
93                 print_summary -n "$action "
94                 echo "=====> $action" >> $workf
95                 # start test
96                 t0=`date +%s.%N`
97                 for ((i=0;i<ndevs;i++)); do
98                     dev=${devs[i]}
99                     if [ $action = read ]; then
100                         inf="if=$dev"
101                         outf="of=/dev/null"
102                         skip=skip
103                     else
104                         inf="if=/dev/zero"
105                         outf="of=$dev"
106                         skip=seek
107                     fi
108                     for ((j=0;j<crg;j++)); do 
109                         sgp_dd 2> ${tmpf}_${i}_${j} \
110                             $inf $outf ${skip}=$((1024+j*blocks)) \
111                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
112                     done
113                 done 
114                 wait
115                 t1=`date +%s.%N`
116                 # collect all results in 1 file
117                 echo > $tmpf
118                 ok=0
119                 for ((i=0;i<ndevs;i++)); do
120                     for ((j=0;j<crg;j++)); do
121                         rtmp=${tmpf}_${i}_${j}
122                         if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
123                             ok=$((ok + 1))
124                         fi
125                         cat ${rtmp} >> $tmpf
126                         cat ${rtmp} >> $workf
127                         rm  ${rtmp}
128                     done
129                 done
130                 if ((ok != ndevs*crg)); then
131                     print_summary -n "$((ndevs*crg - ok)) failed "
132                 else
133                     # compute MB/sec from elapsed
134                     bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size / (( $t1 - $t0 ) * 1024); exit}"`
135                     # compute MB/sec from nregions*slowest
136                     check=`awk < $tmpf \
137                         '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
138                         END {printf "%3d x %6.2f = %7.2f MB/s", n, min, min * n}'`
139                     print_summary -n "$bw $check "
140                 fi
141                 rm $tmpf
142             done
143             print_summary ""
144         done
145     done
146 done