Whamcloud - gitweb
b=12741
[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 # and max # threads one instance will spawn
41 SG_MAX_QUEUE=16
42
43 # map given device names into SG device names
44 i=0
45 devs=()
46 if [ "$scsidevs" ]; then
47         # we will test for a LUN, the test for a partition
48         # if the partition number is > 9 this will fail
49     for d in $scsidevs; do
50         devs[$i]=`sg_map | awk "{if ($ 2 == \"$d\") print $ 1}"`
51         if [ -z "${devs[i]}" ]; then
52             echo "Can't find SG device for $d, testing for partition"
53             pt=`echo $d | sed 's/[0-9]$//'`
54             # Try again
55             devs[$i]=`sg_map | awk "{if ($ 2 == \"$pt\") print $ 1}"`
56             if [ -z "${devs[i]}" ]; then
57                 echo "Can't find SG device $pt"
58                 exit 1
59            fi
60         fi
61         i=$((i+1))
62     done
63 elif [ "$rawdevs" ]; then
64     for r in $rawdevs; do
65         RES=`raw -q $r`
66         if [ $? -eq 0 ];then
67             devs[$i]=$r
68             i=$((i+1))
69         else
70             echo "Raw device $r not set up"
71             exit 1
72         fi
73     done
74 else
75     echo "Must specify scsidevs or rawdevs"
76     exit 1
77 fi
78
79 ndevs=${#devs[@]}
80
81 # determine block size. This should also work for raw devices
82 # If it fails, set to 512
83 bs=$((`sg_readcap -b ${devs[0]}  |awk '{print $2}'`))
84 if [ $bs == 0  ];then
85         echo "sg_readcap failed, setting block size to 512"
86         bs=512
87 fi
88 rsltf=${rslt}.summary
89 workf=${rslt}.detail
90 echo -n > $rsltf
91 echo -n > $workf
92
93 print_summary () {
94     if [ "$1" = "-n" ]; then
95         minusn=$1; shift
96     else
97         minusn=""
98     fi
99     echo $minusn "$*" >> $rsltf
100     echo $minusn "$*"
101 }
102
103 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
104
105 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
106     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
107         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
108             if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
109                 continue
110             fi
111             # compute parameters
112             bpt=$((rsz*1024/bs))
113             blocks=$((size*((1024*1024)/bs)/crg))
114             count=$blocks
115             # show computed parameters
116             actual_rsz=$((bpt*bs/1024))
117             actual_size=$((bs*count*crg/1024))
118             str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
119                          $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
120             echo "==============> $str" >> $workf
121             print_summary -n "$str"
122             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
123             if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
124                 print_summary "ENOMEM"
125                 continue
126             fi
127             # run tests
128             for action in $actions; do
129                 print_summary -n "$action "
130                 echo "=====> $action" >> $workf
131                 tmpf=${workf}_tmp
132                 # start test
133                 t0=`date +%s.%N`
134                 for ((i=0;i<ndevs;i++)); do
135                     dev=${devs[i]}
136                     if [ $action = read ]; then
137                         inf="if=$dev"
138                         outf="of=/dev/null"
139                         skip=skip
140                     else
141                         inf="if=/dev/zero"
142                         outf="of=$dev"
143                         skip=seek
144                     fi
145                     for ((j=0;j<crg;j++)); do 
146                         sgp_dd 2> ${tmpf}_${i}_${j} \
147                             $inf $outf ${skip}=$((1024+j*blocks)) \
148                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
149                     done
150                 done 
151                 wait
152                 t1=`date +%s.%N`
153                 # collect/check individual stats
154                 echo > $tmpf
155                 ok=0
156                 for ((i=0;i<ndevs;i++)); do
157                     for ((j=0;j<crg;j++)); do
158                         rtmp=${tmpf}_${i}_${j}
159                         if grep 'error' $rtmp > /dev/null 2>&1; then
160                                 echo "Error found in $rtmp"
161                         elif grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
162                             ok=$((ok + 1))
163                         fi
164                         cat ${rtmp} >> $tmpf
165                         cat ${rtmp} >> $workf
166                         rm  ${rtmp}
167                     done
168                 done
169                 if ((ok != ndevs*crg)); then
170                     print_summary -n "$((ndevs*crg - ok)) failed "
171                 else
172                     # compute MB/sec from elapsed
173                     bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
174                     # compute MB/sec from nregions*slowest
175                     check=`awk < $tmpf \
176                         '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
177                         END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
178                     print_summary -n "$bw $check "
179                 fi
180                 rm $tmpf
181             done
182             print_summary ""
183         done
184     done
185 done