Whamcloud - gitweb
b=10329
[fs/lustre-release.git] / lustre-iokit / sgpdd-survey / sgpdd-survey
1 #!/bin/bash
2
3 ######################################################################
4 # customize per survey
5
6 # CHOOSE EITHER scsidevs or rawdevs
7 # the SCSI devices to measure - WARNING: will be erased.
8 #scsidevs="/dev/sde /dev/sdh"
9 # The raw devices to use
10 #rawdevs="/dev/raw/raw1"
11 #scsidevs=`ls /dev/sd[a-z] /dev/sd[a-z][a-z]` # all devices, if you use udev
12
13 # result file prefix.  date/time+hostname makes unique
14 # NB ensure the path exists if it includes subdirs
15 rslt=${rslt:-"/tmp/sgpdd_survey_`date +%F@%R`_`uname -n`"}
16
17 # what to do (read or write)
18 actions="write read"
19
20 # total size per device (MBytes)
21 # NB bigger than device cache is good
22 size=8192
23
24 # record size (KBytes)
25 rszlo=1024
26 rszhi=1024
27
28 # Concurrent regions per device
29 crglo=${crglo:-1}
30 crghi=${crghi:-256}
31
32 # threads to share between concurrent regions per device
33 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
34 thrlo=${thrlo:-1}
35 thrhi=${thrhi:-4096}
36
37 #####################################################################
38 # leave the rest of this alone unless you know what you're doing...
39
40 # sgp_dd's idea of disk sector size (Bytes)
41 bs=512
42 # and max # threads one instance will spawn
43 SG_MAX_QUEUE=16
44
45 # map given device names into SG device names
46 i=0
47 devs=()
48 if [ $scsidevs ]; then
49         # we will test for a LUN, the test for a partition
50         # if the partition number is > 9 this will fail
51     for d in $scsidevs; do
52         devs[$i]=`sg_map | awk "{if ($ 2 == \"$d\") print $ 1}"`
53         if [ -z "${devs[i]}" ]; then
54             echo "Can't find SG device for $d, testing for partition"
55             pt=`echo $d | sed 's/[0-9]$//'`
56             # Try again
57             devs[$i]=`sg_map | awk "{if ($ 2 == \"$pt\") print $ 1}"`
58             if [ -z "${devs[i]}" ]; then
59                 echo "Can't find SG device $pt"
60                 exit 1
61            fi
62         fi
63         i=$((i+1))
64     done
65 elif [ $rawdevs ]; then
66     for r in $rawdevs; do
67         RES=`raw -q $r`
68         if [ $? -eq 0 ];then
69             devs[$i]=$r
70             i=$((i+1))
71         else
72             echo "Raw device $r not set up"
73             exit 1
74         fi
75     done
76 else
77     echo "Must specify scsidevs or rawdevs"
78     exit 1
79 fi
80
81 ndevs=${#devs[@]}
82
83 rsltf=${rslt}.summary
84 workf=${rslt}.detail
85 echo -n > $rsltf
86 echo -n > $workf
87
88 print_summary () {
89     if [ "$1" = "-n" ]; then
90         minusn=$1; shift
91     else
92         minusn=""
93     fi
94     echo $minusn "$*" >> $rsltf
95     echo $minusn "$*"
96 }
97
98 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
99     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
100         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
101             if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
102                 continue
103             fi
104             # compute parameters
105             bpt=$((rsz*1024/bs))
106             blocks=$((size*((1024*1024)/bs)/crg))
107             count=$blocks
108             # show computed parameters
109             actual_rsz=$((bpt*bs/1024))
110             actual_size=$((bs*count*crg/1024))
111             str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
112                          $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
113             echo "==============> $str" >> $workf
114             print_summary -n "$str"
115             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
116             if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
117                 print_summary "ENOMEM"
118                 continue
119             fi
120             # run tests
121             for action in $actions; do
122                 print_summary -n "$action "
123                 echo "=====> $action" >> $workf
124                 tmpf=${workf}_tmp
125                 # start test
126                 t0=`date +%s.%N`
127                 for ((i=0;i<ndevs;i++)); do
128                     dev=${devs[i]}
129                     if [ $action = read ]; then
130                         inf="if=$dev"
131                         outf="of=/dev/null"
132                         skip=skip
133                     else
134                         inf="if=/dev/zero"
135                         outf="of=$dev"
136                         skip=seek
137                     fi
138                     for ((j=0;j<crg;j++)); do 
139                         sgp_dd 2> ${tmpf}_${i}_${j} \
140                             $inf $outf ${skip}=$((1024+j*blocks)) \
141                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
142                     done
143                 done 
144                 wait
145                 t1=`date +%s.%N`
146                 # collect/check individual stats
147                 echo > $tmpf
148                 ok=0
149                 for ((i=0;i<ndevs;i++)); do
150                     for ((j=0;j<crg;j++)); do
151                         rtmp=${tmpf}_${i}_${j}
152                         if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
153                             ok=$((ok + 1))
154                         fi
155                         cat ${rtmp} >> $tmpf
156                         cat ${rtmp} >> $workf
157                         rm  ${rtmp}
158                     done
159                 done
160                 if ((ok != ndevs*crg)); then
161                     print_summary -n "$((ndevs*crg - ok)) failed "
162                 else
163                     # compute MB/sec from elapsed
164                     bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
165                     # compute MB/sec from nregions*slowest
166                     check=`awk < $tmpf \
167                         '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
168                         END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
169                     print_summary -n "$bw $check "
170                 fi
171                 rm $tmpf
172             done
173             print_summary ""
174         done
175     done
176 done