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