mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
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:
163
common
163
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 <command run>
|
||||
# time <time in seconds to finish>
|
||||
# exit_status <exit status>
|
||||
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"
|
||||
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_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"
|
||||
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_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"
|
||||
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"
|
||||
common_gem5_src_dir="${common_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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user