Whamcloud - gitweb
b7612d2e90c69fba2629b2490f59db4cf0c2b905
[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 - WARNING: will be erased.
7 #scsidevs=`ls /dev/sd[a-z] /dev/sd[a-z][a-z]` # all devices, if you use udev
8 scsidevs=${scsidevs:-"/dev/sde /dev/sdh"}
9
10 # result file prefix.  date/time+hostname makes unique
11 # NB ensure the path exists if it includes subdirs
12 rslt=${rslt:-"/tmp/sgpdd_survey_`date +%F@%R`_`uname -n`"}
13
14 # what to do (read or write)
15 actions="write read"
16
17 # total size per device (MBytes)
18 # NB bigger than device cache is good
19 size=8192
20
21 # record size (KBytes)
22 rszlo=1024
23 rszhi=1024
24
25 # Concurrent regions per device
26 crglo=${crglo:-1}
27 crghi=${crghi:-256}
28
29 # threads to share between concurrent regions per device
30 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
31 thrlo=${thrlo:-1}
32 thrhi=${thrhi:-4096}
33
34 #####################################################################
35 # leave the rest of this alone unless you know what you're doing...
36
37 # sgp_dd's idea of disk sector size (Bytes)
38 bs=512
39 # and max # threads one instance will spawn
40 SG_MAX_QUEUE=16
41
42 # map given device names into SG device names
43 i=0
44 devs=()
45 for d in $scsidevs; do
46     devs[$i]=`sg_map | awk "{if ($ 2 == \"$d\") print $ 1}"`
47     if [ -z "$devs[$i]" ]; then
48         echo "Can't find SG device for $d"
49         exit 1
50     fi
51     i=$((i+1))
52 done
53 ndevs=${#devs[@]}
54
55 rsltf=${rslt}.summary
56 workf=${rslt}.detail
57 echo -n > $rsltf
58 echo -n > $workf
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 %5d ' \
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             # run tests
93             for action in $actions; do
94                 print_summary -n "$action "
95                 echo "=====> $action" >> $workf
96                 tmpf=${workf}_tmp
97                 # start test
98                 t0=`date +%s.%N`
99                 for ((i=0;i<ndevs;i++)); do
100                     dev=${devs[i]}
101                     if [ $action = read ]; then
102                         inf="if=$dev"
103                         outf="of=/dev/null"
104                         skip=skip
105                     else
106                         inf="if=/dev/zero"
107                         outf="of=$dev"
108                         skip=seek
109                     fi
110                     for ((j=0;j<crg;j++)); do 
111                         sgp_dd 2> ${tmpf}_${i}_${j} \
112                             $inf $outf ${skip}=$((1024+j*blocks)) \
113                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
114                     done
115                 done 
116                 wait
117                 t1=`date +%s.%N`
118                 # collect/check individual stats
119                 echo > $tmpf
120                 ok=0
121                 for ((i=0;i<ndevs;i++)); do
122                     for ((j=0;j<crg;j++)); do
123                         rtmp=${tmpf}_${i}_${j}
124                         if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
125                             ok=$((ok + 1))
126                         fi
127                         cat ${rtmp} >> $tmpf
128                         cat ${rtmp} >> $workf
129                         rm  ${rtmp}
130                     done
131                 done
132                 if ((ok != ndevs*crg)); then
133                     print_summary -n "$((ndevs*crg - ok)) failed "
134                 else
135                     # compute MB/sec from elapsed
136                     bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
137                     # compute MB/sec from nregions*slowest
138                     check=`awk < $tmpf \
139                         '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
140                         END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
141                     print_summary -n "$bw $check "
142                 fi
143                 rm $tmpf
144             done
145             print_summary ""
146         done
147     done
148 done