Whamcloud - gitweb
Introduce .gitignore files.
[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_loc=${rslt_loc:-"/tmp"}
15 rslt=${rslt:-"$rslt_loc/sgpdd_survey_`date +%F@%R`_`uname -n`"}
16
17 # what to do (read or write)
18 actions=${actions:-"write read"}
19
20 # total size per device (MBytes)
21 # NB bigger than device cache is good
22 size=${size:-8192}
23
24 # record size (KBytes)
25 rszlo=${rszlo:-1024}
26 rszhi=${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 # multiple threads per region simulates a deeper request queue
34 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
35 thrlo=${thrlo:-1}
36 thrhi=${thrhi:-4096}
37
38 #####################################################################
39 # leave the rest of this alone unless you know what you're doing...
40
41 # and max # threads one instance will spawn
42 SG_MAX_QUEUE=16
43
44 # is the sg module loaded?
45 sg_is_loaded=$(grep -q "^sg " /proc/modules && echo true || echo false)
46
47 # did we load it?
48 sg_was_loaded=false
49
50 # map given device names into SG device names
51 i=0
52 devs=()
53 if [ "$scsidevs" ]; then
54         # we will test for a LUN, the test for a partition
55         # if the partition number is > 9 this will fail
56
57     # make sure sg kernel module is loaded
58     if ! $sg_is_loaded; then
59         echo "loading the sg kernel module"
60         modprobe sg && sg_was_loaded=true
61         sg_is_loaded=true
62     fi
63
64     for d in $scsidevs; do
65         devs[$i]=`sg_map | awk "{if (\\\$2 == \"$d\") print \\\$1}"`
66         if [ -z "${devs[i]}" ]; then
67             echo "Can't find SG device for $d, testing for partition"
68             pt=`echo $d | sed 's/[0-9]$//'`
69             # Try again
70             devs[$i]=`sg_map | awk "{if (\\\$2 == \"$pt\") print \\\$1}"`
71             if [ -z "${devs[i]}" ]; then
72                 echo -e "Can't find SG device $pt.\nDo you have the sg module configured for your kernel?"
73                 exit 1
74            fi
75         fi
76         i=$((i+1))
77     done
78 elif [ "$rawdevs" ]; then
79     for r in $rawdevs; do
80         RES=`raw -q $r`
81         if [ $? -eq 0 ];then
82             devs[$i]=$r
83             i=$((i+1))
84         else
85             echo "Raw device $r not set up"
86             exit 1
87         fi
88     done
89 else
90     echo "Must specify scsidevs or rawdevs"
91     exit 1
92 fi
93
94 ndevs=${#devs[@]}
95
96 # determine block size. This should also work for raw devices
97 # If it fails, set to 512
98 bs=$((`sg_readcap -b ${devs[0]} | awk '{print $2}'`))
99 if [ $bs == 0  ];then
100         echo "sg_readcap failed, setting block size to 512"
101         bs=512
102 fi
103 rsltf=${rslt}.summary
104 workf=${rslt}.detail
105 echo -n > $rsltf
106 echo -n > $workf
107
108 print_summary () {
109     if [ "$1" = "-n" ]; then
110         minusn=$1; shift
111     else
112         minusn=""
113     fi
114     echo $minusn "$*" >> $rsltf
115     echo $minusn "$*"
116 }
117
118 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
119
120 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
121     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
122         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
123             if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
124                 continue
125             fi
126             # compute parameters
127             bpt=$((rsz*1024/bs))
128             blocks=$((size*((1024*1024)/bs)/crg))
129             count=$blocks
130             # show computed parameters
131             actual_rsz=$((bpt*bs/1024))
132             actual_size=$((bs*count*crg/1024))
133             str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
134                          $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
135             echo "==============> $str" >> $workf
136             print_summary -n "$str"
137             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
138             if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
139                 print_summary "ENOMEM"
140                 continue
141             fi
142             # run tests
143             for action in $actions; do
144                 print_summary -n "$action "
145                 echo "=====> $action" >> $workf
146                 tmpf=${workf}_tmp
147                 # start test
148                 t0=`date +%s.%N`
149                 for ((i=0;i<ndevs;i++)); do
150                     dev=${devs[i]}
151                     devsize=$((bs*`sg_readcap -b ${dev} | awk '{print $1}'`/1024))
152                     if [ $devsize -lt $actual_size ]; then
153                         _dev=$(sg_map | grep $dev | awk '{ print $2; }')
154                         echo -e "device $_dev not big enough: $devsize <" \
155                                 "$actual_size.\nConsider reducing \$size"
156                         exit 1
157                     fi
158                     if [ $action = read ]; then
159                         inf="if=$dev"
160                         outf="of=/dev/null"
161                         skip=skip
162                     else
163                         inf="if=/dev/zero"
164                         outf="of=$dev"
165                         skip=seek
166                     fi
167                     for ((j=0;j<crg;j++)); do 
168                         sgp_dd 2> ${tmpf}_${i}_${j} \
169                             $inf $outf ${skip}=$((1024+j*blocks)) \
170                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
171                     done
172                 done 
173                 wait
174                 t1=`date +%s.%N`
175                 # collect/check individual stats
176                 echo > $tmpf
177                 ok=0
178                 for ((i=0;i<ndevs;i++)); do
179                     for ((j=0;j<crg;j++)); do
180                         rtmp=${tmpf}_${i}_${j}
181                         if grep 'error' $rtmp > /dev/null 2>&1; then
182                                 echo "Error found in $rtmp"
183                         elif grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
184                             ok=$((ok + 1))
185                         fi
186                         cat ${rtmp} >> $tmpf
187                         cat ${rtmp} >> $workf
188                         rm  ${rtmp}
189                     done
190                 done
191                 if ((ok != ndevs*crg)); then
192                     print_summary -n "$((ndevs*crg - ok)) failed "
193                 else
194                     # compute MB/sec from elapsed
195                     bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
196                     # compute MB/sec from nregions*slowest
197                     check=`awk < $tmpf \
198                         '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
199                         END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
200                     print_summary -n "$bw $check "
201                 fi
202                 rm $tmpf
203             done
204             print_summary ""
205         done
206     done
207 done
208
209 if $sg_was_loaded; then
210     echo "unloading sg module"
211     rmmod sg
212 fi