Whamcloud - gitweb
b=10958
[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=${actions:-"write read"}
18
19 # total size per device (MBytes)
20 # NB bigger than device cache is good
21 size=${size:-8192}
22
23 # record size (KBytes)
24 rszlo=${rszlo:-1024}
25 rszhi=${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 # multiple threads per region simulates a deeper request queue
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 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
99
100 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
101     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
102         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
103             if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
104                 continue
105             fi
106             # compute parameters
107             bpt=$((rsz*1024/bs))
108             blocks=$((size*((1024*1024)/bs)/crg))
109             count=$blocks
110             # show computed parameters
111             actual_rsz=$((bpt*bs/1024))
112             actual_size=$((bs*count*crg/1024))
113             str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
114                          $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
115             echo "==============> $str" >> $workf
116             print_summary -n "$str"
117             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
118             if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
119                 print_summary "ENOMEM"
120                 continue
121             fi
122             # run tests
123             for action in $actions; do
124                 print_summary -n "$action "
125                 echo "=====> $action" >> $workf
126                 tmpf=${workf}_tmp
127                 # start test
128                 t0=`date +%s.%N`
129                 for ((i=0;i<ndevs;i++)); do
130                     dev=${devs[i]}
131                     if [ $action = read ]; then
132                         inf="if=$dev"
133                         outf="of=/dev/null"
134                         skip=skip
135                     else
136                         inf="if=/dev/zero"
137                         outf="of=$dev"
138                         skip=seek
139                     fi
140                     for ((j=0;j<crg;j++)); do 
141                         sgp_dd 2> ${tmpf}_${i}_${j} \
142                             $inf $outf ${skip}=$((1024+j*blocks)) \
143                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
144                     done
145                 done 
146                 wait
147                 t1=`date +%s.%N`
148                 # collect/check individual stats
149                 echo > $tmpf
150                 ok=0
151                 for ((i=0;i<ndevs;i++)); do
152                     for ((j=0;j<crg;j++)); do
153                         rtmp=${tmpf}_${i}_${j}
154                         if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
155                             ok=$((ok + 1))
156                         fi
157                         cat ${rtmp} >> $tmpf
158                         cat ${rtmp} >> $workf
159                         rm  ${rtmp}
160                     done
161                 done
162                 if ((ok != ndevs*crg)); then
163                     print_summary -n "$((ndevs*crg - ok)) failed "
164                 else
165                     # compute MB/sec from elapsed
166                     bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
167                     # compute MB/sec from nregions*slowest
168                     check=`awk < $tmpf \
169                         '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
170                         END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
171                     print_summary -n "$bw $check "
172                 fi
173                 rm $tmpf
174             done
175             print_summary ""
176         done
177     done
178 done