3 ######################################################################
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
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`"}
16 # what to do (read or write)
19 # total size per device (MBytes)
20 # NB bigger than device cache is good
23 # record size (KBytes)
27 # Concurrent regions per device
31 # threads to share between concurrent regions per device
32 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
36 #####################################################################
37 # leave the rest of this alone unless you know what you're doing...
39 # sgp_dd's idea of disk sector size (Bytes)
41 # and max # threads one instance will spawn
44 # map given device names into SG device names
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]$//'`
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"
64 elif [ "$rawdevs" ]; then
71 echo "Raw device $r not set up"
76 echo "Must specify scsidevs or rawdevs"
88 if [ "$1" = "-n" ]; then
93 echo $minusn "$*" >> $rsltf
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
105 blocks=$((size*((1024*1024)/bs)/crg))
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"
120 for action in $actions; do
121 print_summary -n "$action "
122 echo "=====> $action" >> $workf
126 for ((i=0;i<ndevs;i++)); do
128 if [ $action = read ]; then
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&
145 # collect/check individual stats
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
155 cat ${rtmp} >> $workf
159 if ((ok != ndevs*crg)); then
160 print_summary -n "$((ndevs*crg - ok)) failed "
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
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 "