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 # sgp_dd's idea of disk sector size (Bytes)
42 # and max # threads one instance will spawn
45 # map given device names into SG device names
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]$//'`
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"
65 elif [ "$rawdevs" ]; then
72 echo "Raw device $r not set up"
77 echo "Must specify scsidevs or rawdevs"
89 if [ "$1" = "-n" ]; then
94 echo $minusn "$*" >> $rsltf
98 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
100 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
101 for ((crg=$crglo;crg<=$crghi;crg*=2)); do
102 for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
103 if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
108 blocks=$((size*((1024*1024)/bs)/crg))
110 # show computed parameters
111 actual_rsz=$((bpt*bs/1024))
112 actual_size=$((bs*count*crg/1024))
113 str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
114 $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
115 echo "==============> $str" >> $workf
116 print_summary -n "$str"
117 freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
118 if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
119 print_summary "ENOMEM"
123 for action in $actions; do
124 print_summary -n "$action "
125 echo "=====> $action" >> $workf
129 for ((i=0;i<ndevs;i++)); do
131 if [ $action = read ]; then
140 for ((j=0;j<crg;j++)); do
141 sgp_dd 2> ${tmpf}_${i}_${j} \
142 $inf $outf ${skip}=$((1024+j*blocks)) \
143 thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
148 # collect/check individual stats
151 for ((i=0;i<ndevs;i++)); do
152 for ((j=0;j<crg;j++)); do
153 rtmp=${tmpf}_${i}_${j}
154 if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
158 cat ${rtmp} >> $workf
162 if ((ok != ndevs*crg)); then
163 print_summary -n "$((ndevs*crg - ok)) failed "
165 # compute MB/sec from elapsed
166 bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
167 # compute MB/sec from nregions*slowest
169 '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
170 END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
171 print_summary -n "$bw $check "