From 1cb056a995a68ce871ebb53fac6be7349f10bb32 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Thu, 9 Aug 2018 05:44:52 +0100 Subject: [PATCH] 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. --- README.adoc | 2 +- bench-all | 36 +++++------ bench-boot | 6 +- build | 45 +++++++------ common | 163 ++++++++++++++++++++++------------------------- gem5-bench-cache | 19 +++--- gem5-shell | 3 +- gem5-stat | 5 +- qemu-trace2txt | 6 +- run | 39 ++++++------ rungdb | 10 +-- rungdb-user | 12 ++-- rungdbserver | 12 ++-- runtc | 6 +- trace-boot | 16 ++--- trace2line | 12 ++-- 16 files changed, 192 insertions(+), 200 deletions(-) diff --git a/README.adoc b/README.adoc index cd070bb..e07c5e3 100644 --- a/README.adoc +++ b/README.adoc @@ -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. diff --git a/bench-all b/bench-all index 53fc109..eeffeb6 100755 --- a/bench-all +++ b/bench-all @@ -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" diff --git a/bench-boot b/bench-boot index d30e0af..361abba 100755 --- a/bench-boot +++ b/bench-boot @@ -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}" diff --git a/build b/build index 679947f..1dcc528 100755 --- a/build +++ b/build @@ -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" diff --git a/common b/common index f0b9c64..d0ba00e 100644 --- a/common +++ b/common @@ -1,104 +1,89 @@ #!/usr/bin/env bash + common_abspath() ( echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" ) + +# Benchmark a command. +# +# $1: command to benchmark +# $2: where to append write results to. Default: /dev/null. +# +# Result format: +# +# cmd +# time