mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 19:51:35 +01:00
Rationale: previously we had archs on toplevel, e.g. out/x86_64 However, host tools like QEMU and gem5 can reuse a lot of the common build files across archs. Therefore, we save space and time by putting them into a single directory. Therefore, the toplevel out/x86_64 was inconsistent, better put arch inside guest tools that need separate build trees instead, e.g. out/buildroot/x86_64/ Also common was pretty obscure as a name to say the best.
134 lines
3.8 KiB
Bash
Executable File
134 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eux
|
|
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
|
|
bench_all=false
|
|
bench_build=false
|
|
bench_buildroot_baseline=false
|
|
bench_gem5_build=false
|
|
bench_linux_boot=false
|
|
default_arch=x86_64
|
|
update_repo=false
|
|
while getopts Aa:Bbglu OPT; do
|
|
case "$OPT" in
|
|
A)
|
|
bench_all=true
|
|
;;
|
|
a)
|
|
default_arch="$OPTARG"
|
|
;;
|
|
b)
|
|
bench_build=true
|
|
;;
|
|
B)
|
|
bench_buildroot_baseline=true
|
|
;;
|
|
g)
|
|
bench_gem5_build=true
|
|
;;
|
|
l)
|
|
bench_linux_boot=true
|
|
;;
|
|
u)
|
|
update_repo=true
|
|
;;
|
|
?)
|
|
exit 2
|
|
;;
|
|
esac
|
|
done
|
|
shift "$(($OPTIND - 1))"
|
|
comment="${1:-}"
|
|
if \
|
|
! "$bench_build" && \
|
|
! "$bench_buildroot_baseline" && \
|
|
! "$bench_gem5_build" && \
|
|
! "$bench_linux_boot" \
|
|
; then
|
|
bench_all=true
|
|
fi
|
|
if "$bench_all"; then
|
|
bench_build=true
|
|
bench_buildroot_baseline=true
|
|
bench_gem5_build=true
|
|
bench_linux_boot=true
|
|
fi
|
|
getvar="${root_dir}/getvar"
|
|
|
|
# Create output directory.
|
|
benchmark_repo="${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
|
|
seq_id="$(("$(echo "$last_dir" | sed -E -e 's/_.*//' -e 's/^0*//')" + 1))"
|
|
else
|
|
seq_id=0
|
|
fi
|
|
seq_id="$(printf '%0.4d' "$seq_id")"
|
|
dir_basename="${seq_id}_$("$getvar" sha)"
|
|
new_dir="${benchmark_repo}/${dir_basename}"
|
|
mkdir "$new_dir"
|
|
|
|
if "$bench_build"; then
|
|
common_arch="$default_arch"
|
|
common_suffix=bench
|
|
common_buildroot_build_dir="$("$getvar" --arch "$common_arch" --buildroot-build-id "$common_suffix" buildroot_build_dir)"
|
|
common_build_dir="$("$getvar" --arch "$common_arch" --buildroot-build-id "$common_suffix" build_dir)"
|
|
rm -rf "$common_buildroot_build_dir"
|
|
./build --arch "$common_arch" --buildroot-config 'BR2_CCACHE=n' --buildroot-build-id "$common_suffix"
|
|
cp "${common_build_dir}/build-time.log" "${new_dir}/build-time-${common_arch}.log"
|
|
rm -rf "$common_buildroot_build_dir"
|
|
fi
|
|
|
|
if "$bench_buildroot_baseline"; then
|
|
cd "${root_dir}/buildroot"
|
|
git clean -xdf
|
|
make "qemu_${default_arch}_defconfig"
|
|
printf '
|
|
BR2_CCACHE=y
|
|
BR2_TARGET_ROOTFS_CPIO=y
|
|
BR2_TARGET_ROOTFS_EXT2=n
|
|
' >>.config
|
|
make olddefconfig
|
|
make source
|
|
time env -u LD_LIBRARY_PATH make BR2_JLEVEL="$(nproc)"
|
|
cp output/build/build-time.log "${new_dir}/baseline-build-time-${default_arch}.log"
|
|
wc -c output/images/* > "${new_dir}/baseline-image-size-${default_arch}.log"
|
|
git clean -xdf
|
|
fi
|
|
|
|
if "$bench_gem5_build"; then
|
|
common_arch="$default_arch"
|
|
gem5_build_id=bench-build
|
|
common_gem5_build_dir="$("$getvar" --arch "$common_arch" --gem5-build-id "$gem5_build_id" gem5_out_dir)"
|
|
common_gem5_src_dir="$("$getvar" --arch "$common_arch" --gem5-build-id "$gem5_build_id" gem5_src_dir)"
|
|
results_file="${common_gem5_build_dir}/bench-build.txt"
|
|
git -C "${common_gem5_src_dir}" clean -xdf
|
|
rm -f "$results_file"
|
|
"${root_dir}/build-gem5" --arch "$common_arch" --clean --gem5-build-id "$gem5_build_id"
|
|
# 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'"
|
|
"${root_dir}/bench-cmd" "timeout --foreground 900 ./build-gem5 --arch '$common_arch' --gem5-build-id '$gem5_build_id'" "$results_file"
|
|
cp "$results_file" "${new_dir}/gem5-bench-build-${common_arch}.txt"
|
|
git -C "${common_gem5_src_dir}" clean -xdf
|
|
"${root_dir}/build-gem5" --arch "$common_arch" --clean --gem5-build-id "$gem5_build_id"
|
|
fi
|
|
|
|
if "$bench_linux_boot"; then
|
|
cd "${root_dir}"
|
|
./build-all
|
|
./bench-boot -t 3
|
|
cp "$(${root_dir}/getvar bench_boot)" "$new_dir"
|
|
fi
|
|
|
|
if "$update_repo"; then
|
|
if [ -n "$comment" ]; then
|
|
echo "$comment" > "${new_dir}/README.adoc"
|
|
fi
|
|
echo
|
|
cd "$benchmark_repo"
|
|
git add .
|
|
git commit -m "$dir_basename"
|
|
git push
|
|
fi
|