diff options
author | Paul E. McKenney <paulmck@kernel.org> | 2023-10-17 14:41:00 -0700 |
---|---|---|
committer | Paul E. McKenney <paulmck@kernel.org> | 2023-10-17 14:42:04 -0700 |
commit | 0ecdabe67aae15f616e4a6ffeda8c4f76ff385ae (patch) | |
tree | 48e577c50693908e83f68a1436a14b0990e360ce | |
parent | f401fc42b5062e491a62f03af4584fd3beb7a180 (diff) | |
download | perfbook-0ecdabe67aae15f616e4a6ffeda8c4f76ff385ae.tar.gz |
cpu: Add scripts to overview system cache latencies
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
-rw-r--r-- | CodeSamples/cpu/overview.sh | 58 | ||||
-rw-r--r-- | CodeSamples/cpu/plots.sh | 75 |
2 files changed, 133 insertions, 0 deletions
diff --git a/CodeSamples/cpu/overview.sh b/CodeSamples/cpu/overview.sh new file mode 100644 index 00000000..f27b6a3b --- /dev/null +++ b/CodeSamples/cpu/overview.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# +# Gather and plot an overview of cache behavior from the viewpoint +# of CPU 0. +# +# Usage: bash reduce.sh [ destdir [ tag ] ] +# +# The "destdir" is the destination directory, defaulting to "data" +# in the temporary directory, which will be created if it does not +# already exist. The "tag" identifies the data, and defaults to +# the basename of "destdir". The tag given to reduce.sh will be +# of the form "tag.yyyy.mm.dda", unless "tag" contains a period +# character, in which case it will be used verbatim. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# Copyright (C) Facebook, 2023 +# +# Authors: Paul E. McKenney <paulmck@kernel.org> + +tmpdir=${TMPDIR-/tmp} +destdir="${1-$tmpdir/data}" +defaulttag="`basename $destdir`" +tagstem="${2-$defaulttag}" +if echo ${tagstem} | grep -q '\.' > /dev/null 2>&1 +then + tag="${tagstem}" +else + tag="${tagstem}.`date +%Y.%m.%da`" +fi + +mkdir -p "${destdir}" + +echo Starting cachetorture.sh at `date` +bash cachetorture.sh > ${destdir}/cachetorture.sh.out +echo Finished cachetorture.sh at `date` + +wd="`pwd`" +cd "${destdir}" +bash "${wd}"/reduce.sh "${tag}" < cachetorture.sh.out +fmt << ---EOF--- +Rough plot, for publication quality, copy the gnuplot command from +${wd}/plots.sh to ${destdir} and edit as needed. Please feel free to +refer to other perfbook plots.sh files for guidance. +---EOF--- +bash "${wd}"/plots.sh diff --git a/CodeSamples/cpu/plots.sh b/CodeSamples/cpu/plots.sh new file mode 100644 index 00000000..c95c9918 --- /dev/null +++ b/CodeSamples/cpu/plots.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# +# Plot the data reduced by reduce.sh. Run in the directory where +# reduce.sh deposited the data. +# +# Usage: bash plots.sh +# +# This script plots only the CAS and local data, though it preps all +# of the data that reduce.sh currently produces. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you can access it online at +# http://www.gnu.org/licenses/gpl-2.0.html. +# +# Copyright (C) Facebook, 2023 +# +# Authors: Paul E. McKenney <paulmck@kernel.org> + +T="`mktemp -d ${TMPDIR-/tmp}/plots.sh.XXXXXX`" +trap 'rm -rf $T' 0 2 + +tag="`ls *.atomicinc.sctr.dat | sed -e 's/.atomicinc.sctr.dat$//'`" + +# Copy over the multi-valued scatter data +cp "${tag}.atomicinc.sctr.dat" $T/"Atomic increment" +awk < "${tag}.blindcmpxchg.sctr.dat" > $T/"Blind cmpxchg" '{ print $1 + 0.25, $2; }' +awk < "${tag}.cmpxchg.sctr.dat" > $T/"cmpxchg" '{ print $1 + 0.5, $2; }' +awk < "${tag}.write.sctr.dat" > $T/"Write" '{ print $1 + 0.75, $2; }' + +# Just average values for the local data +lastcpu="`tail -1 ${tag}.atomicinc.dat | awk '{print $1; }'`" +for i in localcmpxchg locallock +do + label="`echo ${i} | sed -e 's/^local/Local /'`" + value="`tail -1 ${tag}.${i}.dat | awk '{print $2; }'`" + awk -v "lastcpu=${lastcpu}" -v "value=${value}" < /dev/null ' + BEGIN { + for (i = 0; i <= lastcpu; i++) + print i, value; + }' > "$T/${label}" +done + +awk -v "lastcpu=${lastcpu}" ' +BEGIN { + if (lastcpu >= 128) { + print "w dots"; + } else { + print "w points pt 6 ps 1" + } +}' > $T/withstring +ws="`cat $T/withstring`" + +resdir="`pwd`" +pushd $T > /dev/null + +gnuplot << ---EOF--- +set term png size 2000,800 +set output "${resdir}/latencies.png" +set key tmargin +set xlabel "CPU Number (${tag})" +set ylabel "Latency (ns)" +plot "Atomic increment" ${ws}, "Blind cmpxchg" ${ws}, "cmpxchg" ${ws}, "Write" ${ws}, "Local cmpxchg" w l, "Local lock" w l +---EOF--- + +display "${resdir}/latencies.png" |