common: simplify set_common_vars, rename to common_setup

Don't pass all arguments explicitly, just use existing vars.

Prefix all common_setup inputs and outputs with common_ to avoid name conflicts.
This commit is contained in:
Ciro Santilli
2018-08-09 05:44:52 +01:00
parent b8abb15ca7
commit 1cb056a995
16 changed files with 192 additions and 200 deletions

View File

@@ -2340,7 +2340,7 @@ s
This is made possible by the GDB command:
....
set sysroot ${buildroot_out_dir}/staging
set sysroot ${common_buildroot_out_dir}/staging
....
which automatically finds unstripped shared libraries on the host for us.

View File

@@ -47,7 +47,7 @@ comment="${1:-}"
# Create output directory.
sha="$(git log -1 --format="%H")"
benchmark_repo="${root_dir}/../linux-kernel-module-cheat-regression"
benchmark_repo="${common_root_dir}/../linux-kernel-module-cheat-regression"
mkdir -p "$benchmark_repo"
last_dir="$(ls "$benchmark_repo" | grep -E '^[0-9]' | tail -n 1)"
if [ -n "$last_dir" ]; then
@@ -62,17 +62,17 @@ new_dir="${benchmark_repo}/${dir_basename}"
mkdir "$new_dir"
if "$bench_build"; then
arch="$default_arch"
suffix=bench
set_common_vars "$arch" false "$suffix"
rm -rf "$out_arch_dir"
./build -a "$arch" -B 'BR2_CCACHE=n' -s "$suffix"
cp "${build_dir}/build-time.log" "${new_dir}/build-time-${arch}.log"
rm -rf "$out_arch_dir"
common_arch="$default_arch"
common_suffix=bench
common_setup
rm -rf "$common_out_arch_dir"
./build -a "$common_arch" -B 'BR2_CCACHE=n' -s "$suffix"
cp "${common_build_dir}/build-time.log" "${new_dir}/build-time-${common_arch}.log"
rm -rf "$common_out_arch_dir"
fi
if "$bench_buildroot_baseline"; then
cd "${root_dir}/buildroot"
cd "${common_root_dir}/buildroot"
git clean -xdf
make "qemu_${default_arch}_defconfig"
printf '
@@ -90,27 +90,27 @@ fi
if "$bench_gem5_build"; then
arches='x86_64 arm'
for arch in $arches; do
set_common_vars "$arch"
cd "${root_dir}/gem5/gem5"
for common_arch in $arches; do
common_setup
cd "${common_root_dir}/gem5/gem5"
git clean -xdf
cd "${root_dir}/gem5"
cd "${common_root_dir}/gem5"
results_file="${common_gem5_out_dir}/bench-build.txt"
gem5_outdir="${out_dir}/bench_build"
gem5_outdir="${common_out_dir}/bench_build"
rm -fr "$results_file" "${gem5_outdir}"
# TODO understand better: --foreground required otherwise we cannot
# kill the build with Ctrl+C if something goes wrong, can be minimized to:
# bash -c "eval 'timeout 5 sleep 3'"
common_bench_cmd "timeout --foreground 900 ./build -a '$arch' -o '${gem5_outdir}'" "$results_file"
cp "$results_file" "${new_dir}/gem5-bench-build-${arch}.txt"
cd "${root_dir}/gem5/gem5"
common_bench_cmd "timeout --foreground 900 ./build -a '$common_arch' -o '${gem5_outdir}'" "$results_file"
cp "$results_file" "${new_dir}/gem5-bench-build-${common_arch}.txt"
cd "${common_root_dir}/gem5/gem5"
git clean -xdf
rm -fr "${gem5_outdir}"
done
fi
if "$bench_linux_boot"; then
cd "${root_dir}"
cd "${common_root_dir}"
./build-all
./bench-boot
cp "$common_bench_boot" "$new_dir"

View File

@@ -9,9 +9,9 @@ gem5_insts() (
printf "instructions $(./gem5-stat -a "$1" sim_insts)\n" >> "$common_bench_boot"
)
qemu_insts() (
arch="$1"
./qemu-trace2txt -a "$arch"
set_common_vars "$arch"
common_arch="$1"
./qemu-trace2txt -a "$common_arch"
common_setup
printf "instructions $(wc -l "${common_trace_txt_file}" | cut -d' ' -f1)\n" >> "$common_bench_boot"
)
rm -f "${common_bench_boot}"

45
build
View File

@@ -2,16 +2,16 @@
set -eu
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
set -- ${cli_build:-} "$@"
mkdir -p "${out_dir}"
br2_cli_file="${out_dir}/br2_cli"
mkdir -p "${common_out_dir}"
br2_cli_file="${common_out_dir}/br2_cli"
rm -f "$br2_cli_file"
touch "$br2_cli_file"
kernel_config_fragment_cli_file="${out_dir}/kernel_config_fragment_cli"
kernel_config_fragment_cli_file="${common_out_dir}/kernel_config_fragment_cli"
kernel_config_fragment_cli_file_tmp="${kernel_config_fragment_cli_file}_tmp"
rm -f "$kernel_config_fragment_cli_file_tmp"
touch "$kernel_config_fragment_cli_file_tmp"
configure=true
config_fragments="${root_dir}/br2/default"
config_fragments="${common_root_dir}/br2/default"
extra_make_args=
j="$(nproc)"
linux_reconfigure=false
@@ -19,12 +19,11 @@ linux_kernel_custom_config_file=
kernel_config_fragments=
post_script_args=
qemu_sdl='--enable-sdl --with-sdlabi=2.0'
suffix=
v=0
while getopts 'a:B:b:C:c:fGgj:hIiK:kL:lM:p:Q:qSst::v' OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
B)
echo "$OPTARG" >> "$br2_cli_file"
@@ -44,7 +43,7 @@ while getopts 'a:B:b:C:c:fGgj:hIiK:kL:lM:p:Q:qSst::v' OPT; do
g)
extra_make_args="${extra_make_args} gem5-reconfigure \\
"
gem5=true
common_gem5=true
;;
h)
cat build-usage.adoc 1>&2
@@ -99,7 +98,7 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
qemu_sdl=
;;
s)
suffix="$OPTARG"
common_suffix="$OPTARG"
;;
t)
common_gem5_build_type="$OPTARG"
@@ -114,9 +113,9 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
done
shift $(($OPTIND - 1))
extra_make_args="${extra_make_args} $@"
set_common_vars -L "$common_linux_variant" -M "$common_gem5_variant" "$arch" "$gem5" "$suffix"
config_file="${buildroot_out_dir}/.config"
case "$arch" in
common_setup
config_file="${common_buildroot_out_dir}/.config"
case "$common_arch" in
x86_64)
defconfig=qemu_x86_64_defconfig
;;
@@ -130,7 +129,7 @@ case "$arch" in
defconfig=qemu_mips64r6_malta_defconfig
;;
esac
config_fragments="${config_fragments} ${root_dir}/br2/qemu ${br2_cli_file}"
config_fragments="${config_fragments} ${common_root_dir}/br2/qemu ${br2_cli_file}"
time {
# Configure.
@@ -139,16 +138,16 @@ if "$configure"; then
# Only copy if modified, otherwise the kernel always rebuilds.
cp "${kernel_config_fragment_cli_file_tmp}" "${kernel_config_fragment_cli_file}"
fi
cd "${buildroot_dir}"
for p in $(find "${root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
cd "${common_buildroot_dir}"
for p in $(find "${common_root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
patch -N -r - -p 1 < "$p" || :
done
br2_external='../kernel_module:../gem5:../parsec-benchmark'
packages_dir="${root_dir}/packages"
packages_dir="${common_root_dir}/packages"
for package_dir in "${packages_dir}"/*/; do
br2_external="${br2_external}:../packages/$(basename "${package_dir}")"
done
make O="$buildroot_out_dir" BR2_EXTERNAL="$br2_external" "$defconfig"
make O="$common_buildroot_out_dir" BR2_EXTERNAL="$br2_external" "$defconfig"
# TODO Can't get rid of these for now.
# http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
for config_fragment in $config_fragments; do
@@ -159,7 +158,7 @@ BR2_JLEVEL=${j}
BR2_DL_DIR=\"${common_dir}/dl\"
BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
" >> "$config_file"
if "$gem5"; then
if "$common_gem5"; then
printf "BR2_PACKAGE_GEM5=y\n" >> "${config_file}"
fi
kernel_config_fragment_dir=../kernel_config_fragment
@@ -182,11 +181,11 @@ BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
# https://stackoverflow.com/questions/49260466/why-when-i-change-br2-linux-kernel-custom-config-file-and-run-make-linux-reconfi
touch "${kernel_config_fragment_dir}/min"
fi
if [ "$arch" = 'mips64' ]; then
if [ "$common_arch" = 'mips64' ]; then
# Workaround for: https://bugs.busybox.net/show_bug.cgi?id=10276
sed -Ei 's/^BR2_PACKAGE_LINUX_TOOLS_GPIO/BR2_PACKAGE_LINUX_TOOLS_GPIO=n/' "$config_file"
fi
make O="$buildroot_out_dir" olddefconfig
make O="$common_buildroot_out_dir" olddefconfig
fi
echo 'config time:'
}
@@ -214,13 +213,13 @@ symlink_buildroot_variant "$common_qemu_custom_dir" "$common_qemu_variant_dir"
#symlink_buildroot_variant "$common_qemu_guest_custom_dir" "$common_qemu_guest_variant_dir"
# Manage gem5 variants.
if "$gem5"; then
if "$common_gem5"; then
if [ ! -e "${common_gem5_src_dir}/.git" ]; then
git -C "$common_gem5_default_src_dir" worktree add -b "wt/${common_gem5_variant}" "${common_gem5_src_dir}"
fi
fi
cd "$buildroot_dir"
cd "$common_buildroot_dir"
# HOST_QEMU_OPTS is a hack that happens to work because the QEMU package luckly uses += at all times.
# It shouldn't be necessary in the first place: https://bugs.busybox.net/show_bug.cgi?id=9936
#
@@ -233,7 +232,7 @@ cmd="time \\
env \\
-u LD_LIBRARY_PATH \\
make \\
O='${buildroot_out_dir}' \\
O='${common_buildroot_out_dir}' \\
HOST_QEMU_OPTS='--enable-debug --enable-trace-backends=simple ${qemu_sdl}' \\
GEM5_LKMC_GEM5_BUILD_TYPE="$common_gem5_build_type" \\
GEM5_LKMC_OUTDIR="$common_gem5_out_dir" \\
@@ -242,4 +241,4 @@ V='${v}' \\
${extra_make_args} \
all \\
"
"${root_dir}/eeval" "$cmd" "${out_arch_dir}/build.sh"
"${common_root_dir}/eeval" "$cmd" "${common_out_arch_dir}/build.sh"

143
common
View File

@@ -1,8 +1,9 @@
#!/usr/bin/env bash
common_abspath() (
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
)
common_bench_cmd() (
# Benchmark a command.
#
# $1: command to benchmark
@@ -13,92 +14,76 @@ common_bench_cmd() (
# cmd <command run>
# time <time in seconds to finish>
# exit_status <exit status>
common_bench_cmd() (
cmd="$1"
results_file="${2:-/dev/null}"
printf 'cmd ' >> "$results_file"
env time --append -f 'time %e' --output="$results_file" "${root_dir}/eeval" -a "$cmd" "$results_file"
env time --append -f 'time %e' --output="$results_file" "${common_root_dir}/eeval" -a "$cmd" "$results_file"
printf "exit_status $?\n" >> "$results_file"
)
set_common_vars() {
linux_variant=
gem5_variant=
OPTIND=1
while getopts L:M:n: OPT; do
case "$OPT" in
L)
linux_variant="$OPTARG"
;;
M)
gem5_variant="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
esac
done
shift "$(($OPTIND - 1))"
arch="$1"
gem5="${2:-false}"
case "$arch" in
# Setup several variables and do other initialization common to most scripts.
# Typically done after getting inputs from the command line arguments.
common_setup() {
case "$common_arch" in
a|arm)
arch=arm
common_arch=arm
;;
A|aarch64)
arch=aarch64
common_arch=aarch64
;;
m|mips64)
arch=mips64
common_arch=mips64
;;
x|x86_64)
arch=x86_64
common_arch=x86_64
;;
*)
printf "unknown arch: ${arch}\n" 1>&2
printf "unknown arch: ${common_arch}\n" 1>&2
exit 2
;;
esac
common_suffix="${3:-}"
buildroot_dir="${root_dir}/buildroot"
arch_dir="$arch"
common_buildroot_dir="${common_root_dir}/buildroot"
common_arch_dir="$common_arch"
if [ -n "$common_suffix" ]; then
arch_dir="${arch_dir}-${common_suffix}"
common_arch_dir="${arch_dir}-${common_suffix}"
fi
out_arch_dir="${out_dir}/${arch_dir}"
buildroot_out_dir="${out_arch_dir}/buildroot"
build_dir="${buildroot_out_dir}/build"
common_images_dir="${buildroot_out_dir}/images"
host_dir="${buildroot_out_dir}/host"
common_qemu_run_dir="${out_arch_dir}/qemu/${common_run_id}"
common_out_arch_dir="${common_out_dir}/${common_arch_dir}"
common_buildroot_out_dir="${common_out_arch_dir}/buildroot"
common_build_dir="${common_buildroot_out_dir}/build"
common_linux_custom_dir="${common_build_dir}/linux-custom"
common_linux_variant_dir="${common_linux_custom_dir}.${common_linux_variant}"
common_vmlinux="${common_linux_variant_dir}/vmlinux"
common_qemu_custom_dir="${common_build_dir}/host-qemu-custom"
common_qemu_guest_variant_dir="${common_qemu_custom_dir}.${common_qemu_variant}"
common_qemu_variant_dir="${common_qemu_custom_dir}.${common_qemu_variant}"
common_qemu_guest_custom_dir="${common_build_dir}/qemu-custom"
common_host_dir="${common_buildroot_out_dir}/host"
common_images_dir="${common_buildroot_out_dir}/images"
common_gem5_run_dir="${common_out_arch_dir}/gem5/${common_run_id}"
common_m5out_dir="${common_gem5_run_dir}/m5out"
common_trace_txt_file="${common_m5out_dir}/trace.txt"
common_gem5_termout_file="${common_gem5_run_dir}/termout.txt"
common_qemu_run_dir="${common_out_arch_dir}/qemu/${common_run_id}"
common_qemu_termout_file="${common_qemu_run_dir}/termout.txt"
common_qemu_rrfile="${common_qemu_run_dir}/rrfile"
common_linux_custom_dir="${build_dir}/linux-custom"
common_linux_variant_dir="${common_linux_custom_dir}.${linux_variant}"
common_qemu_custom_dir="${build_dir}/host-qemu-custom"
common_qemu_variant_dir="${common_qemu_custom_dir}.${common_qemu_variant}"
common_qemu_guest_custom_dir="${build_dir}/qemu-custom"
common_qemu_guest_variant_dir="${common_qemu_custom_dir}.${common_qemu_variant}"
common_vmlinux="${common_linux_variant_dir}/vmlinux"
if [ -n "$common_gem5_worktree" ]; then
common_gem5_src_dir="${common_gem5_non_default_src_root_dir}/${common_gem5_worktree}"
else
common_gem5_src_dir="${root_dir}/gem5/gem5"
fi
common_gem5_out_dir="${common_dir}/gem5/${gem5_variant}"
common_gem5_out_dir="${common_dir}/gem5/${common_gem5_variant}"
common_gem5_m5term="${common_gem5_out_dir}/m5term"
common_gem5_build_dir="${common_gem5_out_dir}/build"
common_gem5_system_dir="${common_gem5_out_dir}/system"
common_gem5_run_dir="${out_arch_dir}/gem5/${common_run_id}"
common_gem5_termout_file="${common_gem5_run_dir}/termout.txt"
common_m5out_dir="${common_gem5_run_dir}/m5out"
if "$gem5"; then
if [ -n "$common_gem5_worktree" ]; then
common_gem5_src_dir="${common_gem5_non_default_src_root_dir}/${common_gem5_worktree}"
else
common_gem5_src_dir="${common_root_dir}/gem5/gem5"
fi
if "$common_gem5"; then
common_run_dir="$common_gem5_run_dir"
common_termout_file="$common_gem5_termout_file"
else
common_run_dir="$common_qemu_run_dir"
common_termout_file="$common_qemu_termout_file"
fi
common_trace_txt_file="${common_m5out_dir}/trace.txt"
case "$arch" in
case "$common_arch" in
arm)
common_linux_image=arch/arm/boot/zImage
;;
@@ -116,7 +101,7 @@ set_common_vars() {
# Ports.
common_run_id_number="$(echo "$common_run_id" | cut -d . -f 2)"
if "$gem5"; then
if "$common_gem5"; then
common_gem5_telnet_port="$((3456 + $common_run_id_number))"
common_gdb_port="$((7000 + $common_run_id_number))"
else
@@ -128,34 +113,40 @@ set_common_vars() {
common_gdb_port="$common_qemu_gdb_port"
fi
}
common_mkdir() (
mkdir -p \
"$build_dir" \
"$common_build_dir" \
"$common_gem5_out_dir" \
"$common_gem5_run_dir" \
"$common_qemu_run_dir" \
"$p9_dir" \
"$common_9p_dir" \
;
)
# Default paths.
common_root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
common_data_dir="${common_root_dir}/data"
common_9p_dir="${common_data_dir}/9p"
common_gem5_non_default_src_root_dir="${common_data_dir}/gem5"
common_gem5_readfile_file="${common_data_dir}/readfile"
common_gem5_default_src_dir="${common_root_dir}/gem5/gem5"
common_out_dir="${common_root_dir}/out"
common_bench_boot="${common_out_dir}/bench-boot.txt"
common_dir="${common_out_dir}/common"
# Other default variables.
common_arch=x86_64
common_gem5=false
common_gem5_build_type=opt
common_gem5_variant=default
common_gem5_worktree=
common_linux_variant=default
common_qemu_variant=default
root_dir="$(pwd)"
out_dir="${root_dir}/out"
common_bench_boot="${out_dir}/bench-boot.txt"
data_dir="${root_dir}/data"
p9_dir="${data_dir}/9p"
readfile_file="${data_dir}/readfile"
common_dir="${out_dir}/common"
common_gem5_build_type=opt
common_gem5_default_src_dir="${root_dir}/gem5/gem5"
common_gem5_non_default_src_root_dir="${data_dir}/gem5"
common_gem5_worktree=
common_gem5_variant=default
common_run_id=0
f="${data_dir}/cli"
common_suffix=
f="${common_data_dir}/cli"
if [ -f "$f" ]; then
. "$f"
fi
# Default arch.
arch=x86_64
gem5=false

View File

@@ -1,11 +1,12 @@
#!/usr/bin/env bash
set -eu
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true
generate_checkpoints=true
while getopts a:C OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
C)
generate_checkpoints=false
@@ -15,8 +16,8 @@ done
shift "$(($OPTIND - 1))"
# Vars
set_common_vars "$arch" true
cmd="./run -a $arch -g"
common_setup
cmd="./run -a ${common_arch} -g"
cache_small='--caches --l2cache --l1d_size=1024 --l1i_size=1024 --l2_size=1024 --l3_size=1024 '
cache_large='--caches --l2cache --l1d_size=1024kB --l1i_size=1024kB --l2_size=1024kB --l3_size=1024kB'
results_file="${common_gem5_run_dir}/bench-cache.txt"
@@ -25,11 +26,11 @@ bench() (
common_bench_cmd "$1" "$results_file"
{
printf 'cycles '
./gem5-stat -a "$arch"
./gem5-stat -a "$common_arch"
printf 'instructions '
./gem5-stat -a "$arch" sim_insts
./gem5-stat -a "$common_arch" sim_insts
# RESTORE_INVESTIGATION
#cycles_switch="$(./gem5-stat -a "$arch" system.switch_cpus.numCycles)"
#cycles_switch="$(./gem5-stat -a "$common_arch" system.switch_cpus.numCycles)"
#if [ -n "$cycles_switch" ]; then
# printf "cycles_switch ${cycles_switch}\n"
#fi
@@ -67,7 +68,7 @@ bench-all() (
if "$generate_checkpoints"; then
# Create the checkpoints after the kernel boot.
rm -rf "${common_m5out_dir}"/cpt.*;
printf 'm5 exit' > "${readfile_file}"
printf 'm5 exit' > "${common_gem5_readfile_file}"
cpt_cmd="-E '/gem5.sh'"
# 1
./eeval "$cmd $cpt_cmd"
@@ -88,10 +89,10 @@ printf '#!/bin/sh
m5 resetstats
dhrystone XXX
m5 exit
' >"${readfile_file}"
' >"${common_gem5_readfile_file}"
for n in 1000 10000 100000; do
printf "n ${n}\n" >> "$results_file"
sed -Ei "s/^dhrystone .*/dhrystone ${n}/" "${readfile_file}"
sed -Ei "s/^dhrystone .*/dhrystone ${n}/" "${common_gem5_readfile_file}"
bench-all
printf "\n" >> "$results_file"
done

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true
while getopts M:n: OPT; do
case "$OPT" in
M)
@@ -14,5 +15,5 @@ while getopts M:n: OPT; do
esac
done
shift "$(($OPTIND - 1))"
set_common_vars -M "$common_gem5_variant" -n "$common_run_id" "$arch" true
common_setup
"${common_gem5_m5term}" localhost "$common_gem5_telnet_port"

View File

@@ -1,10 +1,11 @@
#!/usr/bin/env bash
set -eu
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true
while getopts a:hs: OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
h)
printf "\
@@ -21,5 +22,5 @@ if [ $# -gt 0 ]; then
else
stat=system.cpu[0-9]*.numCycles
fi
set_common_vars "$arch" true
common_setup
awk "/^$stat /{ print \$2 }" "${common_m5out_dir}/stats.txt"

View File

@@ -5,12 +5,12 @@ set -- ${cli_qemu_trace2txt:-} "$@"
while getopts a: OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
esac
done
set_common_vars "$arch" false
common_setup
./qemu/scripts/simpletrace.py \
"${build_dir}/host-qemu-custom/trace-events-all" \
"${common_build_dir}/host-qemu-custom/trace-events-all" \
"${common_qemu_run_dir}/trace.bin" \
> "${common_trace_txt_file}"

39
run
View File

@@ -18,7 +18,6 @@ extra_append_after_dash=
extra_flags=
extra_flags_qemu=
extra_opts=
gem5=false
gem5opts=
gem5_fsbiglittle=false
lkmc_eval=
@@ -39,7 +38,7 @@ vnc=
while getopts a:c:DdE:e:F:f:G:ghIiKkL:M:m:N:n:PQ:RrT:t:U:uVX:x OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
c)
cpus="$OPTARG"
@@ -70,7 +69,7 @@ while getopts a:c:DdE:e:F:f:G:ghIiKkL:M:m:N:n:PQ:RrT:t:U:uVX:x OPT; do
"
;;
g)
gem5=true
common_gem5=true
;;
h)
cat build-usage.adoc 1>&2
@@ -161,7 +160,7 @@ if [ -n "$extra_opts" ]; then
esac
done
fi
set_common_vars -L "$common_linux_variant" -M "$common_gem5_variant" -n "$common_run_id" "$arch" "$gem5"
common_setup
if "$debug" && "$kvm"; then
echo 'error: -d and -K are incompatible' 1>&2
exit 1
@@ -181,7 +180,7 @@ if [ -n "$lkmc_eval" ]; then
extra_append_after_dash="${extra_append_after_dash} lkmc_eval=\"$(printf "$lkmc_eval" | base64)\""
fi
if "$nographic"; then
if [ "$arch" = x86_64 ]; then
if [ "$common_arch" = x86_64 ]; then
extra_append="${extra_append} console=ttyS0"
fi
extra_flags_qemu="${extra_flags_qemu} -nographic \\
@@ -191,9 +190,9 @@ if [ -n "$extra_append_after_dash" ]; then
extra_append="${extra_append} - ${extra_append_after_dash}"
fi
if "$gem5"; then
if "$common_gem5"; then
memory="${memory}B"
if [ "$arch" = x86_64 ]; then
if [ "$common_arch" = x86_64 ]; then
gem5_arch=X86
else
gem5_arch=ARM
@@ -229,9 +228,9 @@ ${gem5_common} \
--kernel='${common_vmlinux}' \\
--mem-size='${memory}' \\
--num-cpus='${cpus}' \\
--script='${readfile_file}' \\
--script='${common_gem5_readfile_file}' \\
"
if [ "$arch" = x86_64 ]; then
if [ "$common_arch" = x86_64 ]; then
if "$kvm"; then
extra_flags="$extra_flags --cpu-type=X86KvmCPU"
fi
@@ -240,12 +239,12 @@ ${gem5_common} \
--command-line='earlyprintk=ttyS0 console=ttyS0 lpj=7999923 root=/dev/sda ${extra_append}' \\
${extra_flags} \
"
elif [ "$arch" = arm ] || [ "$arch" = aarch64 ]; then
elif [ "$common_arch" = arm ] || [ "$common_arch" = aarch64 ]; then
# TODO why is it mandatory to pass mem= here? Not true for QEMU.
# Anything smaller than physical blows up as expected, but why can't it auto-detect the right value?
cmd="${gem5_common} \
--command-line='earlyprintk=pl011,0x1c090000 console=ttyAMA0 lpj=19988480 rw loglevel=8 mem=${memory} root=/dev/sda ${extra_append}' \\
--dtb-file='${common_gem5_system_dir}/arm/dt/$([ "$arch" = arm ] && echo "armv7_gem5_v1_${cpus}cpu" || echo "armv8_gem5_v1_${cpus}cpu").dtb' \\
--dtb-file='${common_gem5_system_dir}/arm/dt/$([ "$common_arch" = arm ] && echo "armv7_gem5_v1_${cpus}cpu" || echo "armv8_gem5_v1_${cpus}cpu").dtb' \\
--machine-type=VExpress_GEM5_V1 \\
${extra_flags} \
"
@@ -268,9 +267,9 @@ else
fi
if "$prebuilt"; then
common_mkdir
qemu_executable="qemu-system-${arch}"
qemu_executable="qemu-system-${common_arch}"
else
qemu_executable="${common_qemu_variant_dir}/${arch}-softmmu/qemu-system-${arch}"
qemu_executable="${common_qemu_variant_dir}/${common_arch}-softmmu/qemu-system-${common_arch}"
fi
extra_flags="${extra_flags_qemu} ${extra_flags}"
qemu_common="\
@@ -285,8 +284,8 @@ ${qemu_executable} \\
${serial_monitor} \
-smp '${cpus}' \\
-trace 'enable=${trace_type},file=${common_qemu_run_dir}/trace.bin' \\
-virtfs 'local,path=${p9_dir},mount_tag=host_scratch,security_model=mapped,id=host_scratch' \\
-virtfs 'local,path=${buildroot_out_dir}/build,mount_tag=host_out,security_model=mapped,id=host_out' \\
-virtfs 'local,path=${common_9p_dir},mount_tag=host_scratch,security_model=mapped,id=host_scratch' \\
-virtfs 'local,path=${common_buildroot_out_dir}/build,mount_tag=host_out,security_model=mapped,id=host_out' \\
${vnc}"
if "$initrd"; then
extra_flags="${extra_flags} -initrd '${common_images_dir}/rootfs.cpio' \\
@@ -298,7 +297,7 @@ ${vnc}"
# TODO why is this needed, and why any string works.
root='root=/dev/anything'
else
if [ ! "$arch" = mips64 ]; then
if [ ! "$common_arch" = mips64 ]; then
if [ -n "$rr" ]; then
driveif=none
rrid=',id=img-direct'
@@ -331,7 +330,7 @@ ${vnc}"
virtio_gpu_pci="-device virtio-gpu-pci \\
"
fi
case "$arch" in
case "$common_arch" in
x86_64)
if "$kgdb"; then
extra_append="${extra_append} kgdboc=ttyS0,115200"
@@ -390,10 +389,10 @@ ${extra_flags} \
esac
fi
if "$tmux"; then
if "$gem5"; then
if "$common_gem5"; then
eval "./tmu 'sleep 2;./gem5-shell -n ${common_run_id} ${tmux_args};'"
elif "$debug"; then
eval "./tmu ./rungdb -a '${arch} -L ${common_linux_variant}' -n ${common_run_id} ${tmux_args}"
eval "./tmu ./rungdb -a '${common_arch} -L ${common_linux_variant}' -n ${common_run_id} ${tmux_args}"
fi
fi
cmd="time ${cmd}"
@@ -402,4 +401,4 @@ if [ -z "$debug_vm" ]; then
|& tee >(ts -s %.s > ${common_termout_file}) \
"
fi
"${root_dir}/eeval" "$cmd" "${common_run_dir}/run.sh"
"${common_root_dir}/eeval" "$cmd" "${common_run_dir}/run.sh"

10
rungdb
View File

@@ -14,7 +14,7 @@ while getopts A:a:b:CgkL:n:X OPT; do
after="$OPTARG"
;;
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
b)
before="$OPTARG"
@@ -24,7 +24,7 @@ while getopts A:a:b:CgkL:n:X OPT; do
docontinue=false
;;
g)
gem5=true
common_gem5=true
;;
k)
kgdb=true
@@ -51,8 +51,8 @@ if [ "$#" -gt 0 ]; then
else
brk=
fi
set_common_vars -L "$common_linux_variant" -n "$common_run_id" "$arch" "$gem5"
gdb="${host_dir}/usr/bin/${arch}-linux-gdb \\
common_setup
gdb="${common_host_dir}/usr/bin/${common_arch}-linux-gdb \\
${before}"
if "$kgdb"; then
cmd="\
@@ -98,5 +98,5 @@ if "$docontinue"; then
${lx_symbols} \
"
fi
"${root_dir}/eeval" "cd '${common_linux_variant_dir}' && \\
"${common_root_dir}/eeval" "cd '${common_linux_variant_dir}' && \\
$cmd $after" "${common_run_dir}/rungdb.sh"

View File

@@ -7,10 +7,10 @@ gem5_opt=
while getopts a:gh OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
g)
gem5=true
common_gem5=true
gem5_opt=-g
;;
h)
@@ -31,15 +31,15 @@ if [ "$#" -gt 0 ]; then
else
brk=
fi
set_common_vars "$arch" "$gem5"
executable="${build_dir}/${executable_rel}"
addr="$("${root_dir}/runtc" readelf -h "$executable" | awk '/Entry/{ print $NF }' )"
common_setup
executable="${common_build_dir}/${executable_rel}"
addr="$("${common_root_dir}/runtc" readelf -h "$executable" | awk '/Entry/{ print $NF }' )"
ex="-ex \"add-symbol-file $executable $addr\""
# -X or else lx-symbols throws for arm:
# gdb.MemoryError: Cannot access memory at address 0xbf0040cc
# TODO understand better.
#
# Also, lx-symbols overrides the add-symbol-file commands.
cmd="./rungdb -a '${arch}' -b '${ex}' ${gem5_opt} -X ${brk}"
cmd="./rungdb -a '${common_arch}' -b '${ex}' ${gem5_opt} -X ${brk}"
echo "$cmd"
eval "$cmd"

View File

@@ -5,21 +5,21 @@ set -- ${cli_rungdbserver:-} "$@"
while getopts a:g OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
g)
gem5=true
common_gem5=true
;;
esac
done
shift "$(($OPTIND - 1))"
executable="$1"
set_common_vars "$arch" "$gem5"
"${host_dir}/usr/bin/${arch}-linux-gdb" \
common_setup
"${common_host_dir}/usr/bin/${common_arch}-linux-gdb" \
-q \
-ex "set sysroot ${buildroot_out_dir}/staging" \
-ex "set sysroot ${common_buildroot_out_dir}/staging" \
-ex "target remote localhost:${common_qemu_hostfwd_generic_port}" \
-ex 'tb main' \
-ex 'c' \
"${build_dir}/${executable}" \
"${common_build_dir}/${executable}" \
;

6
runtc
View File

@@ -5,7 +5,7 @@ set -- ${cli_runtc:-} "$@"
while getopts a:gh OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
h)
printf "Usage: $0 TOOL [TOOL_ARGS]...
@@ -20,6 +20,6 @@ done
shift "$(($OPTIND - 1))"
tool="$1"
shift
set_common_vars "$arch"
"${buildroot_out_dir}/host/bin/"*-buildroot-*"${tool}" "$@"
common_setup
"${common_buildroot_out_dir}/host/bin/"*-buildroot-*"${tool}" "$@"
exit "$?"

View File

@@ -5,25 +5,25 @@ set -- ${cli_trace_boot:-} "$@"
while getopts a:g OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
g)
gem5=true
common_gem5=true
;;
esac
done
shift "$(($OPTIND - 1))"
set_common_vars "$arch" "$gem5"
if "$gem5"; then
time ./run -a "$arch" -E 'm5 exit' -g -T 'Exec,-ExecSymbol,-ExecMicro' "$@"
common_setup
if "$common_gem5"; then
time ./run -a "$common_arch" -E 'm5 exit' -g -T 'Exec,-ExecSymbol,-ExecMicro' "$@"
else
time ./run -a "$arch" -e 'init=/poweroff.out' -T exec_tb "$@"
time ./qemu-trace2txt -a "$arch"
time ./run -a "$common_arch" -e 'init=/poweroff.out' -T exec_tb "$@"
time ./qemu-trace2txt -a "$common_arch"
# Instruction count.
# We could put this on a separate script, but it just adds more arch boilerplate to a new script.
# So let's just leave it here for now since it did not add a significant processing time.
echo "instructions $(wc -l "${common_trace_txt_file}" | cut -d' ' -f1)"
entry_addr=$("${root_dir}/runtc" readelf -h "${build_dir}/linux-custom/vmlinux" | grep 'Entry point address' | sed -E 's/.*: *//')
entry_addr=$("${common_root_dir}/runtc" readelf -h "${common_build_dir}/linux-custom/vmlinux" | grep 'Entry point address' | sed -E 's/.*: *//')
echo "entry_address ${entry_addr}"
sed "/${entry_addr}/q" "${common_trace_txt_file}" >"${common_qemu_run_dir}/trace-boot.txt"
echo "instructions_firmware $(wc -l "${common_qemu_run_dir}/trace-boot.txt" | cut -d' ' -f1)"

View File

@@ -5,23 +5,23 @@ set -- ${cli_trace2line:-} "$@"
while getopts a:g OPT; do
case "$OPT" in
a)
arch="$OPTARG"
common_arch="$OPTARG"
;;
g)
gem5=true
common_gem5=true
;;
esac
done
set_common_vars "$arch" "$gem5"
kernel_dir="${build_dir}/linux-custom"
common_setup
kernel_dir="${common_build_dir}/linux-custom"
(
if "$gem5"; then
if "$common_gem5"; then
sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file"
else
sed -r 's/.*pc=//' "$common_trace_txt_file"
fi
) | \
xargs "${host_dir}/bin/${arch}-linux-addr2line" -e "${kernel_dir}/vmlinux" -fp | \
xargs "${common_host_dir}/bin/${common_arch}-linux-addr2line" -e "${common_vmlinux}" -fp | \
sed -E "s|at ${kernel_dir}/(\./\|)||" | \
uniq -c \
> "${common_run_dir}/trace-lines.txt"