mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 18:25:57 +01:00
162 lines
4.6 KiB
Bash
162 lines
4.6 KiB
Bash
#!/usr/bin/env bash
|
|
common_abspath() (
|
|
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
|
)
|
|
common_bench_cmd() (
|
|
# Benchmark a command.
|
|
#
|
|
# $1: command to benchmark
|
|
# $2: where to append write results to. Default: /dev/null.
|
|
#
|
|
# Result format:
|
|
#
|
|
# cmd <command run>
|
|
# time <time in seconds to finish>
|
|
# exit_status <exit status>
|
|
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"
|
|
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
|
|
a|arm)
|
|
arch=arm
|
|
;;
|
|
A|aarch64)
|
|
arch=aarch64
|
|
;;
|
|
m|mips64)
|
|
arch=mips64
|
|
;;
|
|
x|x86_64)
|
|
arch=x86_64
|
|
;;
|
|
*)
|
|
printf "unknown arch: ${arch}\n" 1>&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
common_suffix="${3:-}"
|
|
buildroot_dir="${root_dir}/buildroot"
|
|
arch_dir="$arch"
|
|
if [ -n "$common_suffix" ]; then
|
|
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_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_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
|
|
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
|
|
arm)
|
|
common_linux_image=arch/arm/boot/zImage
|
|
;;
|
|
aarch64)
|
|
common_linux_image=arch/arm64/boot/Image
|
|
;;
|
|
mips64)
|
|
common_linux_image=vmlinux
|
|
;;
|
|
x86_64)
|
|
common_linux_image=arch/x86/boot/bzImage
|
|
;;
|
|
esac
|
|
common_linux_image="${common_linux_variant_dir}/${common_linux_image}"
|
|
|
|
# Ports.
|
|
common_run_id_number="$(echo "$common_run_id" | cut -d . -f 2)"
|
|
if "$gem5"; then
|
|
common_gem5_telnet_port="$((3456 + $common_run_id_number))"
|
|
common_gdb_port="$((7000 + $common_run_id_number))"
|
|
else
|
|
common_qemu_base_port="$((45454 + 10 * $common_run_id_number))"
|
|
common_qemu_monitor_port="$(($common_qemu_base_port + 0))"
|
|
common_qemu_hostfwd_generic_port="$(($common_qemu_base_port + 1))"
|
|
common_qemu_hostfwd_ssh_port="$(($common_qemu_base_port + 2))"
|
|
common_qemu_gdb_port="$(($common_qemu_base_port + 3))"
|
|
common_gdb_port="$common_qemu_gdb_port"
|
|
fi
|
|
}
|
|
common_mkdir() (
|
|
mkdir -p \
|
|
"$build_dir" \
|
|
"$common_gem5_out_dir" \
|
|
"$common_gem5_run_dir" \
|
|
"$common_qemu_run_dir" \
|
|
"$p9_dir" \
|
|
;
|
|
)
|
|
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"
|
|
if [ -f "$f" ]; then
|
|
. "$f"
|
|
fi
|
|
# Default arch.
|
|
arch=x86_64
|
|
gem5=false
|