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 # boundary blocks between concurrent regions per device
33 boundary=${boundary:-1024}
35 # threads to share between concurrent regions per device
36 # multiple threads per region simulates a deeper request queue
37 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
41 #####################################################################
42 # leave the rest of this alone unless you know what you're doing...
44 # and max # threads one instance will spawn
47 # is the sg module loaded?
48 sg_is_loaded=$(grep -q "^sg " /proc/modules && echo true || echo false)
53 # map given device names into SG device names
56 if [ "$scsidevs" ]; then
57 # we will test for a LUN, the test for a partition
58 # if the partition number is > 9 this will fail
60 # make sure sg kernel module is loaded
61 if ! $sg_is_loaded; then
62 echo "loading the sg kernel module"
63 modprobe sg && sg_was_loaded=true
67 for d in $scsidevs; do
68 if [[ -L "$d" ]]; then
69 echo "Device $d specified by alias. Will 'readlink' for device name"
72 devs[$i]=`sg_map | awk "{if (\\\$2 == \"$d\") print \\\$1}"`
73 if [ -z "${devs[i]}" ]; then
74 echo "Can't find SG device for $d, testing for partition"
75 pt=`echo $d | sed 's/[0-9]*$//'`
77 devs[$i]=`sg_map | awk "{if (\\\$2 == \"$pt\") print \\\$1}"`
78 if [ -z "${devs[i]}" ]; then
79 echo -e "Can't find SG device $pt.\nDo you have the sg module configured for your kernel?"
85 elif [ "$rawdevs" ]; then
92 echo "Raw device $r not set up"
97 echo "Must specify scsidevs or rawdevs"
103 # determine block size. This should also work for raw devices
104 # If it fails, set to 512
105 bs=$((`sg_readcap -lb ${devs[0]} | awk '{print $2}'`))
107 echo "sg_readcap failed, setting block size to 512"
110 rsltf=${rslt}.summary
116 if [ "$1" = "-n" ]; then
121 echo $minusn "$*" >> $rsltf
125 print_summary "$(date) sgpdd-survey on $rawdevs$scsidevs from $(hostname)"
127 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
128 for ((crg=$crglo;crg<=$crghi;crg*=2)); do
129 for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
130 if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
135 blocks=$((size*((1024*1024)/bs)/crg))
137 # show computed parameters
138 actual_rsz=$((bpt*bs/1024))
139 actual_size=$((bs*count*crg/1024))
140 str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
141 $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
142 echo "==============> $str" >> $workf
143 print_summary -n "$str"
144 freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
145 if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
146 print_summary "ENOMEM"
150 for action in $actions; do
151 print_summary -n "$action "
152 echo "=====> $action" >> $workf
156 for ((i=0;i<ndevs;i++)); do
158 devsize=$((bs*`sg_readcap -lb ${dev} | awk '{print $1}'`/1024))
159 if [ $devsize -lt $actual_size ]; then
160 _dev=$(sg_map | grep $dev | awk '{ print $2; }')
161 echo -e "device $_dev not big enough: $devsize <" \
162 "$actual_size.\nConsider reducing \$size"
165 if [ $action = read ]; then
174 for ((j=0;j<crg;j++)); do
175 sgp_dd 2> ${tmpf}_${i}_${j} \
176 $inf $outf ${skip}=$((boundary+j*blocks)) \
177 thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
182 # collect/check individual stats
185 for ((i=0;i<ndevs;i++)); do
186 for ((j=0;j<crg;j++)); do
187 rtmp=${tmpf}_${i}_${j}
188 if grep 'error' $rtmp > /dev/null 2>&1; then
189 echo "Error found in $rtmp"
190 elif grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
194 cat ${rtmp} >> $workf
198 if ((ok != ndevs*crg)); then
199 print_summary -n "$((ndevs*crg - ok)) failed "
201 # compute MB/sec from elapsed
202 bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
203 # compute MB/sec from nregions*slowest
205 '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
206 END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
207 print_summary -n "$bw $check "
216 if $sg_was_loaded; then
217 echo "unloading sg module"