1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
|
#!/bin/bash
#
# Copyright 2015, 2016, International Business Machines
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Test-script to measure and tune performance of zlib soft- or hardware
# implementation. Use the data to figure out the #threads required to
# get best throughput and when adding more threads does not help.
#
# For the hardware implementation, it will show how many threads in parallel
# are needed to saturate the hardware.
#
# The buffersize test shows the influence of buffering and small buffers
# on throughput. Hardware implementation will normally work best with large
# buffers.
#
export ZLIB_ACCELERATOR=GENWQE
export ZLIB_CARD=0
export ZLIB_DEFLATE_IMPL=0x01 # Use hardware by default
export ZLIB_INFLATE_IMPL=0x01
threads=160
version="https://github.com/ibm-genwqe/genwqe-user"
verbose=""
test_data="/tmp/test_data.bin"
logging=0
sadc=/usr/lib/sysstat/sadc
# sadc is unfortunately at different location for different distributions
# We try to figure out the location in the code below, if your sadc is at
# a different spot, you might need to adopt the script.
# Print usage message helper function
function usage() {
echo "Usage of $PROGRAM:"
echo " [-A] <accelerator> use either GENWQE for the PCIe and CAPI for"
echo " CAPI based solution available only on System p"
echo " Use SW to use software compress/decompression"
echo " [-C] <card> set the compression card to use (0, 1, ... )."
echo " RED (or -1) drive work to all available cards."
echo " [-P] Use polling to detect work-request completion/only CAPI."
echo " [-t] <test_data.bin>"
echo " [-l] Enable system load logging"
echo " sadc - System activity data collector and gnuplot"
echo " must be installed"
echo " [-M] <threads> Maximum number of threads to be used."
echo " [-v] Print status and informational output."
echo " [-V] Print program version (${version})"
echo " [-h] Print this help message."
echo
echo "Input data is to be placed in ${test_data}."
echo "If it does not exist, the script will generate random example data."
echo "Using random data will cause performance to suffer, since it"
echo "will not compress nicely. So using something more realistic is"
echo "certainly a good idea."
echo
echo "Note that the path needs to be setup to find the zlib_mt_perf tool."
echo
echo "E.g. run as follows:"
echo " Use GenWQE accelerator card 0:"
echo " PATH=tools:\$PATH tools/zlib_mt_perf.sh -A GENWQE -C0"
echo
echo " Use CAPI accelerator card 0:"
echo " PATH=tools:\$PATH tools/zlib_mt_perf.sh -A CAPI -C0"
echo
echo " Use software zlib:"
echo " PATH=tools:\$PATH tools/zlib_mt_perf.sh -A SW"
echo
}
###############################################################################
# System Load Logging
###############################################################################
function system_load_find_sadc() {
if [ -x /usr/lib64/sa/sadc ]; then
sadc=/usr/lib64/sa/sadc
elif [ -x /usr/lib/sysstat/sadc ]; then
sadc=/usr/lib/sysstat/sadc
else
echo "Cannot find sadc tool for CPU load measurement!"
exit 1
fi
}
function system_load_logging_start() {
rm -f system_load.sar system_load.pid
${sadc} 1 system_load.sar &
echo $! > system_load.pid
}
function system_load_logging_stop() {
kill -9 `cat system_load.pid`
# Skip the 1st 4 lines, since they container some header information
cp system_load.sar system_load.$ZLIB_ACCELERATOR.sar
LC_TIME=posix sar -u -f system_load.sar | tail -n +4 > system_load.txt
grep -v Average system_load.txt > system_load.csv
LC_TIME=posix sar -u -f system_load.sar > system_load.$ZLIB_ACCELERATOR.csv
start=`head -n1 system_load.csv | cut -f1 -d' '`
end=`tail -n1 system_load.csv | cut -f1 -d' '`
cat <<EOF > system_load.gnuplot
# Gnuplot Config
#
set terminal pdf size 16,8
set output "system_load.pdf"
set autoscale
set title "System Load using $ZLIB_ACCELERATOR"
set xdata time
set timefmt "%H:%M:%S"
set xlabel "Time"
set xrange ["$start":"$end"]
set ylabel "CPU Utilization"
set yrange ["0.00":"100.00"]
set style data lines
set grid
# set datafile separator " "
plot "system_load.csv" using 1:3 title "%user" with lines lw 4, '' using 1:5 title "%system" with lines lw 4
EOF
# Instructing gnuplot to generate a png with out CPU load statistics
cat system_load.gnuplot | gnuplot
# Safe it under an accelerator unique name
mv system_load.pdf system_load.${ZLIB_ACCELERATOR}.pdf
}
# Parse any options given on the command line
while getopts "M:A:C:t:PvVhl" opt; do
case ${opt} in
A)
ZLIB_ACCELERATOR=${OPTARG};
;;
C)
ZLIB_CARD=${OPTARG};
;;
P)
export ZLIB_DEFLATE_IMPL=0x81;
export ZLIB_INFLATE_IMPL=0x81;
;;
M)
threads=${OPTARG};
;;
t)
test_data=${OPTARG};
;;
l)
logging=1;
;;
v)
verbose="-v";
;;
V)
echo "${version}"
exit 0;
;;
h)
usage;
exit 0;
;;
\?)
echo "ERROR: Invalid option: -$OPTARG" >&2
exit 1;
;;
esac
done
if [ $ZLIB_ACCELERATOR = "SW" ]; then
export ZLIB_DEFLATE_IMPL=0x00;
export ZLIB_INFLATE_IMPL=0x00;
fi
# Random data cannot being compressed. Performance values might be poor.
# Text data e.g. logfiles work pretty well. Use those if available.
# Download linux.tar.gz which is mainly text. That should perform well.
#
echo -n "Checking if example data is available ... "
if [ ! -f ${test_data} ]; then
echo "no"
if [ ! -f cantrbry.tar.gz ]; then
wget http://corpus.canterbury.ac.nz/resources/cantrbry.tar.gz
if [ $? -ne 0 ]; then
echo "cantrbry.tar.gz is missing. Please download it first.";
echo
echo "E.g.:";
echo " wget http://corpus.canterbury.ac.nz/resources/cantrbry.tar.gz";
echo
exit -1;
fi
fi
echo -n "Duplicating test_data "
touch ${test_data}
for ((i=0; i<16; i++)); do
gzip -f -d -c cantrbry.tar.gz >> ${test_data}
echo -n "."
done
echo " ok"
# dd if=/dev/urandom of=${test_data} count=1024 bs=4096
else
echo "yes, ${test_data} is there"
fi
echo -n "Compressing ${test_data} if needed ... "
if [ ! -f ${test_data}.gz ]; then
gzip -f -c ${test_data} > ${test_data}.gz
echo "ok"
else
echo "no"
fi
export PATH=./tools:./genwqe-user/tools:/sbin:/usr/sbin:$PATH
cpus=`cat /proc/cpuinfo | grep processor | wc -l`
bufsize=1MiB
count=1
# Generate core dumps, in case something needs debug
ulimit -c unlimited
echo
uname -a
echo "Accelerator: ${ZLIB_ACCELERATOR}"
echo "Processors: $cpus"
echo -n "Raw data: "
du -h ${test_data}
echo -n "Compressed data: "
du -h ${test_data}.gz
echo "IBM Processing accelerators:"
lspci | grep "Processing accelerators: IBM"
if [ $logging -eq 1 ]; then
system_load_find_sadc
system_load_logging_start
fi
echo
echo "DEFLATE Figure out maximum throughput and #threads which work best"
print_hdr=""
for (( t=1; t<=$threads; t*=2 )); do
zlib_mt_perf $verbose -i$bufsize -o$bufsize -D -f ${test_data} \
-c$count -t$t $print_hdr;
if [ $? -ne 0 ]; then
echo "ERROR Failed with $t Threads"
echo -n "Version: "
zlib_mt_perf --version
echo " Called with:"
echo " export ZLIB_ACCELERATOR=${ZLIB_ACCELERATOR}"
echo " export ZLIB_CARD=${ZLIB_CARD}"
echo " export ZLIB_DEFLATE_IMPL=${ZLIB_DEFLATE_IMPL}"
echo " export ZLIB_INFLATE_IMPL=${ZLIB_INFLATE_IMPL}"
echo " zlib_mt_perf $verbose -i$bufsize -o$bufsize -D -f ${test_data} -c$count -t$t $print_hdr"
exit 1
fi
# sleep 1 ;
print_hdr="-N";
done
echo
echo "DEFLATE Use optimal #threads, guessing $cpus, influence of buffer size"
print_hdr=""
t=$cpus # FIXME ;-)
for b in 1KiB 4KiB 64KiB 128KiB 1MiB 4MiB 8MiB ; do
zlib_mt_perf $verbose -i$b -o$b -D -f ${test_data} -c$count -t$t \
$print_hdr;
# sleep 1 ;
print_hdr="-N";
done
echo
echo "INFLATE Figure out maximum throughput and #threads which work best"
print_hdr=""
for (( t=1; t<=$threads; t*=2 )); do
zlib_mt_perf $verbose -i$bufsize -o$bufsize -f ${test_data}.gz \
-c$count -t$t $print_hdr;
# sleep 1 ;
print_hdr="-N";
done
echo
echo "INFLATE Use optimal #threads, guessing $cpus, influence of buffer size"
t=$cpus # FIXME ;-)
print_hdr=""
for b in 1KiB 4KiB 64KiB 128KiB 1MiB 4MiB 8MiB ; do
zlib_mt_perf $verbose -i$b -o$b -f ${test_data}.gz -c$count -t$t \
$print_hdr;
# sleep 1 ;
print_hdr="-N";
done
if [ $logging -eq 1 ]; then
system_load_logging_stop
fi
# Cleanup
rm -f ${test_data} ${test_data}.gz
exit 0
|