Whamcloud - gitweb
Branch HEAD
[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 time_v=`date`
99 hostname=`hostname`
100 if [ "$rawdevs" ]; then
101         print_summary "$time_v sgpdd-survey on $rawdevs from $hostname"
102 fi
103 if [ "$scsidevs" ]; then
104         print_summary "$time_v sgpdd-survey on $scsidevs from $hostname"
105 fi
106
107 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
108     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
109         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
110             if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
111                 continue
112             fi
113             # compute parameters
114             bpt=$((rsz*1024/bs))
115             blocks=$((size*((1024*1024)/bs)/crg))
116             count=$blocks
117             # show computed parameters
118             actual_rsz=$((bpt*bs/1024))
119             actual_size=$((bs*count*crg/1024))
120             str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
121                          $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
122             echo "==============> $str" >> $workf
123             print_summary -n "$str"
124             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
125             if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
126                 print_summary "ENOMEM"
127                 continue
128             fi
129             # run tests
130             for action in $actions; do
131                 print_summary -n "$action "
132                 echo "=====> $action" >> $workf
133                 tmpf=${workf}_tmp
134                 # start test
135                 t0=`date +%s.%N`
136                 for ((i=0;i<ndevs;i++)); do
137                     dev=${devs[i]}
138                     if [ $action = read ]; then
139                         inf="if=$dev"
140                         outf="of=/dev/null"
141                         skip=skip
142                     else
143                         inf="if=/dev/zero"
144                         outf="of=$dev"
145                         skip=seek
146                     fi
147                     for ((j=0;j<crg;j++)); do 
148                         sgp_dd 2> ${tmpf}_${i}_${j} \
149                             $inf $outf ${skip}=$((1024+j*blocks)) \
150                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
151                     done
152                 done 
153                 wait
154                 t1=`date +%s.%N`
155                 # collect/check individual stats
156                 echo > $tmpf
157                 ok=0
158                 for ((i=0;i<ndevs;i++)); do
159                     for ((j=0;j<crg;j++)); do
160                         rtmp=${tmpf}_${i}_${j}
161                         if 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