Whamcloud - gitweb
b1_4_xattr don't need special requirement for lnet since it's re-based
[fs/lustre-release.git] / lustre-iokit / sgpdd-survey / sgpdd-survey
1 #!/bin/bash
2
3 ######################################################################
4 # customize per survey
5
6 # the SCSI devices to measure
7 scsidevs="/dev/sde /dev/sdh"
8
9 # result file prefix.  date/time+hostname makes unique
10 # NB ensure the path exists if it includes subdirs
11 rslt=/tmp/sgpdd_survey_`date +%F@%R`_`uname -n`
12
13 # what to do (read or write)
14 actions="write read"
15
16 # total size per device (MBytes)
17 # NB bigger than device cache is good
18 size=8192
19
20 # record size (KBytes)
21 rszlo=1024
22 rszhi=1024
23
24 # Concurrent regions per device
25 crglo=1
26 crghi=256
27
28 # threads to share between concurrent regions per device
29 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
30 thrlo=1
31 thrhi=4096
32
33 #####################################################################
34 # leave the rest of this alone unless you know what you're doing...
35
36 # sgp_dd's idea of disk sector size (Bytes)
37 bs=512
38 # and max # threads one instance will spawn
39 SG_MAX_QUEUE=16
40
41 # map given device names into SG device names
42 i=0
43 devs=()
44 for d in $scsidevs; do
45     devs[$i]=`sg_map | awk "{if ($ 2 == \"$d\") print $ 1}"`
46     if [ -z "$devs[$i]" ]; then
47         echo "Can't find SG device for $d"
48         exit 1
49     fi
50     i=$((i+1))
51 done
52 ndevs=${#devs[@]}
53
54 rsltf=${rslt}.summary
55 workf=${rslt}.detail
56 echo -n > $rsltf
57 echo -n > $workf
58
59 print_summary () {
60     if [ "$1" = "-n" ]; then
61         minusn=$1; shift
62     else
63         minusn=""
64     fi
65     echo $minusn "$*" >> $rsltf
66     echo $minusn "$*"
67 }
68
69 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
70     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
71         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
72             if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
73                 continue
74             fi
75             # compute parameters
76             bpt=$((rsz*1024/bs))
77             blocks=$((size*((1024*1024)/bs)/crg))
78             count=$blocks
79             # show computed parameters
80             actual_rsz=$((bpt*bs/1024))
81             actual_size=$((bs*count*crg/1024))
82             str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
83                          $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
84             echo "==============> $str" >> $workf
85             print_summary -n "$str"
86             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
87             if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
88                 print_summary "ENOMEM"
89                 continue
90             fi
91             # run tests
92             for action in $actions; do
93                 print_summary -n "$action "
94                 echo "=====> $action" >> $workf
95                 tmpf=${workf}_tmp
96                 # start test
97                 t0=`date +%s.%N`
98                 for ((i=0;i<ndevs;i++)); do
99                     dev=${devs[i]}
100                     if [ $action = read ]; then
101                         inf="if=$dev"
102                         outf="of=/dev/null"
103                         skip=skip
104                     else
105                         inf="if=/dev/zero"
106                         outf="of=$dev"
107                         skip=seek
108                     fi
109                     for ((j=0;j<crg;j++)); do 
110                         sgp_dd 2> ${tmpf}_${i}_${j} \
111                             $inf $outf ${skip}=$((1024+j*blocks)) \
112                             thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
113                     done
114                 done 
115                 wait
116                 t1=`date +%s.%N`
117                 # collect/check individual stats
118                 echo > $tmpf
119                 ok=0
120                 for ((i=0;i<ndevs;i++)); do
121                     for ((j=0;j<crg;j++)); do
122                         rtmp=${tmpf}_${i}_${j}
123                         if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
124                             ok=$((ok + 1))
125                         fi
126                         cat ${rtmp} >> $tmpf
127                         cat ${rtmp} >> $workf
128                         rm  ${rtmp}
129                     done
130                 done
131                 if ((ok != ndevs*crg)); then
132                     print_summary -n "$((ndevs*crg - ok)) failed "
133                 else
134                     # compute MB/sec from elapsed
135                     bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
136                     # compute MB/sec from nregions*slowest
137                     check=`awk < $tmpf \
138                         '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
139                         END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
140                     print_summary -n "$bw $check "
141                 fi
142                 rm $tmpf
143             done
144             print_summary ""
145         done
146     done
147 done