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 if [[ -L "$d" ]]; then
66 echo "Device $d specified by alias. Will 'readlink' for device name"
69 devs[$i]=`sg_map | awk "{if (\\\$2 == \"$d\") print \\\$1}"`
70 if [ -z "${devs[i]}" ]; then
71 echo "Can't find SG device for $d, testing for partition"
72 pt=`echo $d | sed 's/[0-9]*$//'`
74 devs[$i]=`sg_map | awk "{if (\\\$2 == \"$pt\") print \\\$1}"`
75 if [ -z "${devs[i]}" ]; then
76 echo -e "Can't find SG device $pt.\nDo you have the sg module configured for your kernel?"
82 elif [ "$rawdevs" ]; then
89 echo "Raw device $r not set up"
94 echo "Must specify scsidevs or rawdevs"
100 # determine block size. This should also work for raw devices
101 # If it fails, set to 512
102 bs=$((`sg_readcap -b ${devs[0]} | awk '{print $2}'`))
104 echo "sg_readcap failed, setting block size to 512"
107 rsltf=${rslt}.summary
113 if [ "$1" = "-n" ]; then
118 echo $minusn "$*" >> $rsltf
122 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
124 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
125 for ((crg=$crglo;crg<=$crghi;crg*=2)); do
126 for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
127 if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
132 blocks=$((size*((1024*1024)/bs)/crg))
134 # show computed parameters
135 actual_rsz=$((bpt*bs/1024))
136 actual_size=$((bs*count*crg/1024))
137 str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
138 $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
139 echo "==============> $str" >> $workf
140 print_summary -n "$str"
141 freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
142 if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
143 print_summary "ENOMEM"
147 for action in $actions; do
148 print_summary -n "$action "
149 echo "=====> $action" >> $workf
153 for ((i=0;i<ndevs;i++)); do
155 devsize=$((bs*`sg_readcap -b ${dev} | awk '{print $1}'`/1024))
156 if [ $devsize -lt $actual_size ]; then
157 _dev=$(sg_map | grep $dev | awk '{ print $2; }')
158 echo -e "device $_dev not big enough: $devsize <" \
159 "$actual_size.\nConsider reducing \$size"
162 if [ $action = read ]; then
171 for ((j=0;j<crg;j++)); do
172 sgp_dd 2> ${tmpf}_${i}_${j} \
173 $inf $outf ${skip}=$((1024+j*blocks)) \
174 thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
179 # collect/check individual stats
182 for ((i=0;i<ndevs;i++)); do
183 for ((j=0;j<crg;j++)); do
184 rtmp=${tmpf}_${i}_${j}
185 if grep 'error' $rtmp > /dev/null 2>&1; then
186 echo "Error found in $rtmp"
187 elif grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
191 cat ${rtmp} >> $workf
195 if ((ok != ndevs*crg)); then
196 print_summary -n "$((ndevs*crg - ok)) failed "
198 # compute MB/sec from elapsed
199 bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
200 # compute MB/sec from nregions*slowest
202 '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
203 END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
204 print_summary -n "$bw $check "
213 if $sg_was_loaded; then
214 echo "unloading sg module"