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_loc=${rslt_loc:-"/tmp"}
15 rslt=${rslt:-"$rslt_loc/sgpdd_survey_`date +%F@%R`_`uname -n`"}
17 # what to do (read or write)
18 actions=${actions:-"write read"}
20 # total size per device (MBytes)
21 # NB bigger than device cache is good
24 # record size (KBytes)
28 # Concurrent regions per device
32 # threads to share between concurrent regions per device
33 # multiple threads per region simulates a deeper request queue
34 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
38 #####################################################################
39 # leave the rest of this alone unless you know what you're doing...
41 # and max # threads one instance will spawn
44 # is the sg module loaded?
45 sg_is_loaded=$(grep -q "^sg " /proc/modules && echo true || echo false)
50 # map given device names into SG device names
53 if [ "$scsidevs" ]; then
54 # we will test for a LUN, the test for a partition
55 # if the partition number is > 9 this will fail
57 # make sure sg kernel module is loaded
58 if ! $sg_is_loaded; then
59 echo "loading the sg kernel module"
60 modprobe sg && sg_was_loaded=true
64 for d in $scsidevs; do
65 devs[$i]=`sg_map | awk "{if (\\\$2 == \"$d\") print \\\$1}"`
66 if [ -z "${devs[i]}" ]; then
67 echo "Can't find SG device for $d, testing for partition"
68 pt=`echo $d | sed 's/[0-9]$//'`
70 devs[$i]=`sg_map | awk "{if (\\\$2 == \"$pt\") print \\\$1}"`
71 if [ -z "${devs[i]}" ]; then
72 echo -e "Can't find SG device $pt.\nDo you have the sg module configured for your kernel?"
78 elif [ "$rawdevs" ]; then
85 echo "Raw device $r not set up"
90 echo "Must specify scsidevs or rawdevs"
96 # determine block size. This should also work for raw devices
97 # If it fails, set to 512
98 bs=$((`sg_readcap -b ${devs[0]} | awk '{print $2}'`))
100 echo "sg_readcap failed, setting block size to 512"
103 rsltf=${rslt}.summary
109 if [ "$1" = "-n" ]; then
114 echo $minusn "$*" >> $rsltf
118 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
120 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
121 for ((crg=$crglo;crg<=$crghi;crg*=2)); do
122 for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
123 if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
128 blocks=$((size*((1024*1024)/bs)/crg))
130 # show computed parameters
131 actual_rsz=$((bpt*bs/1024))
132 actual_size=$((bs*count*crg/1024))
133 str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
134 $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
135 echo "==============> $str" >> $workf
136 print_summary -n "$str"
137 freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
138 if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
139 print_summary "ENOMEM"
143 for action in $actions; do
144 print_summary -n "$action "
145 echo "=====> $action" >> $workf
149 for ((i=0;i<ndevs;i++)); do
151 devsize=$((bs*`sg_readcap -b ${dev} | awk '{print $1}'`/1024))
152 if [ $devsize -lt $actual_size ]; then
153 _dev=$(sg_map | grep $dev | awk '{ print $2; }')
154 echo -e "device $_dev not big enough: $devsize <" \
155 "$actual_size.\nConsider reducing \$size"
158 if [ $action = read ]; then
167 for ((j=0;j<crg;j++)); do
168 sgp_dd 2> ${tmpf}_${i}_${j} \
169 $inf $outf ${skip}=$((1024+j*blocks)) \
170 thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
175 # collect/check individual stats
178 for ((i=0;i<ndevs;i++)); do
179 for ((j=0;j<crg;j++)); do
180 rtmp=${tmpf}_${i}_${j}
181 if grep 'error' $rtmp > /dev/null 2>&1; then
182 echo "Error found in $rtmp"
183 elif grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
187 cat ${rtmp} >> $workf
191 if ((ok != ndevs*crg)); then
192 print_summary -n "$((ndevs*crg - ok)) failed "
194 # compute MB/sec from elapsed
195 bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
196 # compute MB/sec from nregions*slowest
198 '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
199 END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
200 print_summary -n "$bw $check "
209 if $sg_was_loaded; then
210 echo "unloading sg module"