Skip to content

Commit

Permalink
Clean up the memory benchmark scripts and add a couple more for conve…
Browse files Browse the repository at this point in the history
…nience.

In general we make the scripts a bit more flexible, removing fixed names
and adding some more output formats.  There are also two more scripts to
run full sets of profiling and memory copying benchmarks.

memcpy-benchmarks/

	* count-top-funcs.sh: Give flexibility in the variants to be
	counted and add a cutoff option; allow a raw output format, so the
	results can be used in profile-all-funcs.sh.
	* extract-top-level-funcs.sh: Add some more sorting of results.
	* profile-all-funcs.sh: Sort results by function name.
	* run-all.sh: Created.
	* run-memcpy.sh: Small cleanups.
	* run-perf.sh: Likewise.
	* run-sequence-all.sh: Created.
	* run-sequence.sh: More options to configure sequence, scale
	iterations by size of block, output number of iterations used.
	* vmemcpy-main.c: Remove a blank line.

Signed-off-by: Jeremy Bennett <[email protected]>
  • Loading branch information
jeremybennett committed Sep 19, 2024
1 parent ccc9dd1 commit 67750ca
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 222 deletions.
81 changes: 61 additions & 20 deletions memcpy-benchmarks/count-top-funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,36 @@ set -u

usage () {
cat <<EOF
Usage ./count-top-funcs.sh : Count frequency of most use functions
[--resdir <dir>] : Directory with the results. Default
"res-baseline"
[--total|--self] : Select results based on total (self + children)
or just self. Default "total"`
[--md | --csv] : Output results in Markdown (default) or CSV
Usage ./count-top-funcs.sh : Count frequency of most use functions
[--resdir <dir>] : Directory with the results. Default
"res-baseline"
[--total|--self] : Select results based on total (self +
children) or just self. Default "total"
[--types <list>] : List of result file types, default
"scalar vector-small vector-large"
[--cutoff <val>] : Cutoff for count to be presented. Default 0
[--md | --csv | --raw] : Output results in Markdown, CSV or as a raw
string for use as the --funclist argument
of profile-all-funcs.sh
The results to be analysed will be in files of the form
"prof-<type>-<size>.res", where type is one of "scalar", "vector-small" or
"vector-large", and size, is the size of the data block in bytes copied on
"prof-<type>-<size>.res", where type is one of the types listed in the
--types argument, and size, is the size of the data block in bytes copied on
each iteration.
EOF
}

topdir="$(cd $(dirname $(dirname $(dirname $(readlink -f $0)))) ; pwd)"
memcpydir="${topdir}/tooling/memcpy-benchmarks"
# Directories
tooldir="$(cd $(dirname $(dirname $(readlink -f $0))) ; pwd)"
topdir="$(cd $(dirname ${tooldir}) ; pwd)"
memcpydir="${tooldir}/memcpy-benchmarks"

# Defaults
resdir="${memcpydir}/res-baseline"
dototal="--total"
format="--md"
types="scalar vector-small vector-large"
cutoff="0"
format="--raw"

set +u
until
Expand All @@ -43,7 +54,15 @@ until
--total|--self)
dototal=$1
;;
--md|--csv)
--types)
shift
types="$1"
;;
--cutoff)
shift
cutoff="$1"
;;
--md|--csv|--raw)
format="$1"
;;
--help)
Expand All @@ -66,25 +85,28 @@ set -u
# We create a lot of temporaries!
tmpdir="$(mktemp -d count-top-funcs-XXXXXX)"

# Find out the sizes
dlens="$(ls -1 ${resdir}/prof-scalar-*.res | \
sed -e 's/^.*prof-scalar-//' -e 's/\.res$//' | sort -n)"
cd ${memcpydir}
for tp in "scalar" "vector-small" "vector-large"
for tp in ${types}
do
echo
echo "${tp}"
echo
tmpf1="${tmpdir}/all-${tp}.res"
tmpf2="${tmpdir}/table-${tp}.res"
rm -f "${tmpf1}"
touch "${tmpf1}"

# Find out the sizes
dlens=$(ls -1 ${resdir}/prof-${tp}-*.res | \
sed -e "s/^.*prof-${tp}-//" -e 's/\.res$//' | sort -n)
nlens=$(echo "${dlens}" | wc -l)
printf "%s %d results\n" "${tp}" "${nlens}"

# Extract all the desired data
for l in ${dlens}
do
echo -n "."
./extract-top-level-funcs.sh --resfile ${resdir}/prof-${tp}-${l}.res \
${dototal} --omit-empty >> ${tmpf1}
done
echo
sed -n < ${tmpf1} -e 's/`//gp' | \
sed -e 's/^|[^|]*|[^|]*| //' -e 's/[[:space:]]*|$//' | \
sort | uniq -c | sort -nr > ${tmpf2}
Expand All @@ -100,9 +122,15 @@ do
printf '"%s","%s"\n' "Count" "Function/address"
esac

funclist=
while IFS='' read -r line
do
cnt=$(echo "${line}" | sed -e 's/^[[:space:]]\+//' -e 's/ .*$//')
if [[ "${cnt}" -lt "${cutoff}" ]]
then
break
fi

func=$(echo "${line}" | \
sed -e 's/^[[:space:]]\+[[:digit:]]\+[[:space:]]\+//')

Expand All @@ -114,8 +142,21 @@ do
;;
--csv)
printf '"%s","%s"\n' "${cnt}" "${func}"
;;
--raw)
if [[ "x${funclist}" == "x" ]]
then
funclist="${func}"
else
funclist="${funclist} ${func}"
fi
esac
done < ${tmpf2}

if [[ "${format}" == "--raw" ]]
then
printf '"%s"\n' "${funclist}"
fi
done

rm -r ${tmpdir}
66 changes: 34 additions & 32 deletions memcpy-benchmarks/extract-top-level-funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Usage ./extract-top-level-funcs.sh : Extract list of top level functions
EOF
}

topdir="$(cd $(dirname $(dirname $(dirname $(readlink -f $0)))) ; pwd)"
memcpydir=${topdir}/tooling/memcpy-benchmarks
tooldir="$(cd $(dirname $(dirname $(readlink -f $0))) ; pwd)"
topdir="$(cd $(dirname ${tooldir}) ; pwd)"
memcpydir="${tooldir}/memcpy-benchmarks"

# Default values
resfile=
Expand Down Expand Up @@ -85,17 +86,6 @@ fi
# Temporary file, so we can sort the results
tmpf=$(mktemp extract-top-level-funcs-XXXXXX)

case "${format}"
in
--md)
printf "| %8s | %8s | %-45s |\n" "Children" "Self" "Function/address"
printf "| %8s | %8s | %-45s |\n" "-------:" "-------:" \
":--------------------------------------------"
;;
--csv)
printf '"%s","%s","%s"\n' "Children" "Self" "Function/address"
esac

while IFS='' read -r line
do
if (echo "${line}" | grep -q '\[\.\] [^[:space:]]\+$')
Expand Down Expand Up @@ -139,25 +129,37 @@ do
# greater than pctot)
if [[ "$(echo "${pctot}" | sed -e 's/\...$//')" -lt ${cutoff} ]]
then
# Sort the results if necessary
if ${dototal}
then
cat < ${tmpf}
else
# Need to sort
case "${format}"
in
--md)
sort -nr -t'|' -k3 < ${tmpf}
;;
--csv)
sort -nr -t'"' -k4 < ${tmpf}
;;
esac
fi

rm ${tmpf}
exit 0
break
fi
fi
done < ${resfile}

# Print the results, sorting if necessary
case "${format}"
in
--md)
printf "| %8s | %8s | %-45s |\n" "Children" "Self" "Function/address"
printf "| %8s | %8s | %-45s |\n" "-------:" "-------:" \
":--------------------------------------------"
;;
--csv)
printf '"%s","%s","%s"\n' "Children" "Self" "Function/address"
esac

if ${dototal}
then
cat < ${tmpf}
else
# Need to sort
case "${format}"
in
--md)
sort -nr -t'|' -k3 < ${tmpf}
;;
--csv)
sort -nr -t'"' -k4 < ${tmpf}
;;
esac
fi

rm ${tmpf}
25 changes: 16 additions & 9 deletions memcpy-benchmarks/profile-all-funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ Usage ./profile-all-funcs.sh : Extract function performance data
EOF
}

topdir="$(cd $(dirname $(dirname $(dirname $(readlink -f $0)))) ; pwd)"
memcpydir=${topdir}/tooling/memcpy-benchmarks
tooldir="$(cd $(dirname $(dirname $(readlink -f $0))) ; pwd)"
topdir="$(cd $(dirname ${tooldir}) ; pwd)"
memcpydir="${tooldir}/memcpy-benchmarks"

# Default values
resdir="${memcpydir}/res-baseline"
Expand Down Expand Up @@ -85,7 +86,8 @@ set -u

# Temporary file for intermediaries
tmpf="$(mktemp profile-all-funcs-XXXXXX)"
tmpcsv="$(mktemp profile-all-funcs-XXXXXX.csv)"
tmpcsv1="$(mktemp profile-all-funcs-XXXXXX-1.csv)"
tmpcsv2="$(mktemp profile-all-funcs-XXXXXX-2.csv)"

# Find out the sizes
cd ${resdir}
Expand All @@ -105,6 +107,7 @@ cd ${memcpydir}
for l in ${dlens}
do
res_title="${res_title}#${l}"
echo -n .
./extract-top-level-funcs.sh --md \
--resfile ${resdir}/prof-${restype}-${l}.res > ${tmpf}

Expand Down Expand Up @@ -137,17 +140,21 @@ do
reslist[${f}]="${reslist[${f}]}#${res}"
done
done
echo

# Print it all out
res_title="${res_title}%"
echo "${res_title}" | sed -e 's/%/"/g' -e 's/#/","/g' > ${tmpcsv}
# Print it all out. Prep the body of the CSV, sort it by function name, then
# transpose it.
for f in ${funclist}
do
reslist[${f}]="${reslist[${f}]}%"
echo "${reslist[${f}]}" | sed -e 's/%/"/g' -e 's/#/","/g' >> ${tmpcsv}
echo "${reslist[${f}]}" | sed -e 's/%/"/g' -e 's/#/","/g' >> ${tmpcsv1}
done

csvtool transpose ${tmpcsv}
res_title="${res_title}%"
echo "${res_title}" | sed -e 's/%/"/g' -e 's/#/","/g' > ${tmpcsv2}
sort -t, -k1 < ${tmpcsv1} >> ${tmpcsv2}
csvtool transpose ${tmpcsv2}

rm -f ${tmpf}
rm -f ${tmpcsv}
rm -f ${tmpcsv1}
rm -f ${tmpcsv2}
56 changes: 56 additions & 0 deletions memcpy-benchmarks/run-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Copyright (C) 2024 Embecosm Limited <www.embecosm.com>
# Contributor Jeremy Bennett <[email protected]>

# SPDX-License-Identifier: GPL-3.0-or-later

# A script to do multiple performance profiling runs

tooldir="$(cd $(dirname $(dirname $(readlink -f $0))) ; pwd)"
topdir="$(cd $(dirname ${tooldir}) ; pwd)"
memcpydir="${tooldir}/memcpy-benchmarks"
qemudir=${topdir}/qemu

logfile=${memcpydir}/run-all.log
rm -f ${logfile}
touch ${logfile}

ids="ef9e258b94376c5017b4df9fe061abcadc9661f2 \
7809b7fafbc24c557751a1845bb1ccc0b9376f90"

export PATH=${topdir}/install/bin:${PATH}
which qemu-riscv64 2>&1 | tee -a ${logfile}

# Build all the programs to benchmark
cd ${memcpydir}
make

# Now do the profiling
for c in ${ids}
do
resfile="${memcpydir}/results-${c}"
echo "Checking out QEMU commit ${c}..." 2>&1 | tee -a ${logfile}
date 2>&1 | tee -a ${logfile}
pushd ${qemudir} > /dev/null 2>&1
git checkout ${c} 2>&1 | tee -a ${logfile}
popd > /dev/null 2>&1

echo "Building QEMU for commit ${c}..." 2>&1 | tee -a ${logfile}
date 2>&1 | tee -a ${logfile}
pushd ${tooldir} > /dev/null 2>&1
./build-all.sh --qemu-only --clean-qemu --qemu-cflags "-g" \
--qemu-configs "--disable-plugins" 2>&1 | tee -a ${logfile}
popd > /dev/null 2>&1

echo "Running perf for commit ${c}..." 2>&1 | tee -a ${logfile}
date 2>&1 | tee -a ${logfile}
pushd ${memcpydir} > /dev/null 2>&1
mkdir -p "${resfile}"
./run-perf.sh 2>&1 | tee -a ${logfile}

echo "Putting results in ${resfile}..." 2>&1 | tee -a ${logfile}
mv prof-*.res "${resfile}"
date 2>&1 | tee -a ${logfile}
popd > /dev/null 2>&1
done
24 changes: 12 additions & 12 deletions memcpy-benchmarks/run-memcpy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,26 @@ if [[ $lmul != "1" ]]
then
if [[ ${format} == "--md" ]]
then
printf "| %5d | %6d | %7.2f | %7.2f | %7.2f | %10.1f | %10.1f | %10.1f | %10.2f | %10.2f | %10.2f |\n" \
${vlen} $length $scalar_time $vector1_time $vectorM_time \
${scalar_micount} ${vector1_micount} ${vectorM_micount} \
${scalar_nspi} ${vector1_nspi} ${vectorM_nspi}
printf "| %10d | %5d | %6d | %7.2f | %7.2f | %7.2f | %10.1f | %10.1f | %10.1f | %10.2f | %10.2f | %10.2f |\n" \
${iterations} ${vlen} $length $scalar_time $vector1_time \
$vectorM_time ${scalar_micount} ${vector1_micount} \
${vectorM_micount} ${scalar_nspi} ${vector1_nspi} ${vectorM_nspi}
else
printf "\"%d\",\"%d\",\"%.2f\",\"%.2f\",\"%.2f\",\"%.1f\",\"%.1f\",\"%.1f\",\"%.2f\",\"%.2f\",\"%.2f\"\n" \
${vlen} $length $scalar_time $vector1_time $vectorM_time \
${scalar_micount} ${vector1_micount} ${vectorM_micount} \
${scalar_nspi} ${vector1_nspi} ${vectorM_nspi}
printf "\"%d\",\"%d\",\"%d\",\"%.2f\",\"%.2f\",\"%.2f\",\"%.1f\",\"%.1f\",\"%.1f\",\"%.2f\",\"%.2f\",\"%.2f\"\n" \
${iterations} ${vlen} $length $scalar_time $vector1_time \
$vectorM_time ${scalar_micount} ${vector1_micount} \
${vectorM_micount} ${scalar_nspi} ${vector1_nspi} ${vectorM_nspi}
fi
else
if [[ ${format} == "--md" ]]
then
printf "| %5d | %6d | %7.2f | %7.2f | %10.1f | %10.1f | %10.2f | %10.2f |\n" \
${vlen} $length $scalar_time $vector1_time \
printf "| %10d | %5d | %6d | %7.2f | %7.2f | %10.1f | %10.1f | %10.2f | %10.2f |\n" \
${iterations} ${vlen} $length $scalar_time $vector1_time \
${scalar_micount} ${vector1_micount} \
${scalar_nspi} ${vector1_nspi}
else
printf "\"%d\",\"%d\",\"%.2f\",\"%.2f\",\"%.1f\",\"%.1f\",\"%.2f\",\"%.2f\"\n" \
${vlen} $length $scalar_time $vector1_time \
printf "\"%d\",\"%d\",\"%d\",\"%.2f\",\"%.2f\",\"%.1f\",\"%.1f\",\"%.2f\",\"%.2f\"\n" \
${iterations} ${vlen} $length $scalar_time $vector1_time \
${scalar_micount} ${vector1_micount} \
${scalar_nspi} ${vector1_nspi}
fi
Expand Down
Loading

0 comments on commit 67750ca

Please sign in to comment.