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)
17 actions=${actions:-"write read"}
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 # multiple threads per region simulates a deeper request queue
33 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
37 #####################################################################
38 # leave the rest of this alone unless you know what you're doing...
40 # and max # threads one instance will spawn
43 # map given device names into SG device names
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]$//'`
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"
63 elif [ "$rawdevs" ]; then
70 echo "Raw device $r not set up"
75 echo "Must specify scsidevs or rawdevs"
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}'`))
85 echo "sg_readcap failed, setting block size to 512"
94 if [ "$1" = "-n" ]; then
99 echo $minusn "$*" >> $rsltf
103 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
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
113 blocks=$((size*((1024*1024)/bs)/crg))
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"
128 for action in $actions; do
129 print_summary -n "$action "
130 echo "=====> $action" >> $workf
134 for ((i=0;i<ndevs;i++)); do
136 if [ $action = read ]; then
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&
153 # collect/check individual stats
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
165 cat ${rtmp} >> $workf
169 if ((ok != ndevs*crg)); then
170 print_summary -n "$((ndevs*crg - ok)) failed "
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
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 "