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