Skip to content

Commit 1cb056a

Browse files
committed
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.
1 parent b8abb15 commit 1cb056a

16 files changed

+192
-200
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ s
23402340
This is made possible by the GDB command:
23412341

23422342
....
2343-
set sysroot ${buildroot_out_dir}/staging
2343+
set sysroot ${common_buildroot_out_dir}/staging
23442344
....
23452345

23462346
which automatically finds unstripped shared libraries on the host for us.

bench-all

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ comment="${1:-}"
4747

4848
# Create output directory.
4949
sha="$(git log -1 --format="%H")"
50-
benchmark_repo="${root_dir}/../linux-kernel-module-cheat-regression"
50+
benchmark_repo="${common_root_dir}/../linux-kernel-module-cheat-regression"
5151
mkdir -p "$benchmark_repo"
5252
last_dir="$(ls "$benchmark_repo" | grep -E '^[0-9]' | tail -n 1)"
5353
if [ -n "$last_dir" ]; then
@@ -62,17 +62,17 @@ new_dir="${benchmark_repo}/${dir_basename}"
6262
mkdir "$new_dir"
6363

6464
if "$bench_build"; then
65-
arch="$default_arch"
66-
suffix=bench
67-
set_common_vars "$arch" false "$suffix"
68-
rm -rf "$out_arch_dir"
69-
./build -a "$arch" -B 'BR2_CCACHE=n' -s "$suffix"
70-
cp "${build_dir}/build-time.log" "${new_dir}/build-time-${arch}.log"
71-
rm -rf "$out_arch_dir"
65+
common_arch="$default_arch"
66+
common_suffix=bench
67+
common_setup
68+
rm -rf "$common_out_arch_dir"
69+
./build -a "$common_arch" -B 'BR2_CCACHE=n' -s "$suffix"
70+
cp "${common_build_dir}/build-time.log" "${new_dir}/build-time-${common_arch}.log"
71+
rm -rf "$common_out_arch_dir"
7272
fi
7373

7474
if "$bench_buildroot_baseline"; then
75-
cd "${root_dir}/buildroot"
75+
cd "${common_root_dir}/buildroot"
7676
git clean -xdf
7777
make "qemu_${default_arch}_defconfig"
7878
printf '
@@ -90,27 +90,27 @@ fi
9090

9191
if "$bench_gem5_build"; then
9292
arches='x86_64 arm'
93-
for arch in $arches; do
94-
set_common_vars "$arch"
95-
cd "${root_dir}/gem5/gem5"
93+
for common_arch in $arches; do
94+
common_setup
95+
cd "${common_root_dir}/gem5/gem5"
9696
git clean -xdf
97-
cd "${root_dir}/gem5"
97+
cd "${common_root_dir}/gem5"
9898
results_file="${common_gem5_out_dir}/bench-build.txt"
99-
gem5_outdir="${out_dir}/bench_build"
99+
gem5_outdir="${common_out_dir}/bench_build"
100100
rm -fr "$results_file" "${gem5_outdir}"
101101
# TODO understand better: --foreground required otherwise we cannot
102102
# kill the build with Ctrl+C if something goes wrong, can be minimized to:
103103
# bash -c "eval 'timeout 5 sleep 3'"
104-
common_bench_cmd "timeout --foreground 900 ./build -a '$arch' -o '${gem5_outdir}'" "$results_file"
105-
cp "$results_file" "${new_dir}/gem5-bench-build-${arch}.txt"
106-
cd "${root_dir}/gem5/gem5"
104+
common_bench_cmd "timeout --foreground 900 ./build -a '$common_arch' -o '${gem5_outdir}'" "$results_file"
105+
cp "$results_file" "${new_dir}/gem5-bench-build-${common_arch}.txt"
106+
cd "${common_root_dir}/gem5/gem5"
107107
git clean -xdf
108108
rm -fr "${gem5_outdir}"
109109
done
110110
fi
111111

112112
if "$bench_linux_boot"; then
113-
cd "${root_dir}"
113+
cd "${common_root_dir}"
114114
./build-all
115115
./bench-boot
116116
cp "$common_bench_boot" "$new_dir"

bench-boot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ gem5_insts() (
99
printf "instructions $(./gem5-stat -a "$1" sim_insts)\n" >> "$common_bench_boot"
1010
)
1111
qemu_insts() (
12-
arch="$1"
13-
./qemu-trace2txt -a "$arch"
14-
set_common_vars "$arch"
12+
common_arch="$1"
13+
./qemu-trace2txt -a "$common_arch"
14+
common_setup
1515
printf "instructions $(wc -l "${common_trace_txt_file}" | cut -d' ' -f1)\n" >> "$common_bench_boot"
1616
)
1717
rm -f "${common_bench_boot}"

build

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@
22
set -eu
33
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
44
set -- ${cli_build:-} "$@"
5-
mkdir -p "${out_dir}"
6-
br2_cli_file="${out_dir}/br2_cli"
5+
mkdir -p "${common_out_dir}"
6+
br2_cli_file="${common_out_dir}/br2_cli"
77
rm -f "$br2_cli_file"
88
touch "$br2_cli_file"
9-
kernel_config_fragment_cli_file="${out_dir}/kernel_config_fragment_cli"
9+
kernel_config_fragment_cli_file="${common_out_dir}/kernel_config_fragment_cli"
1010
kernel_config_fragment_cli_file_tmp="${kernel_config_fragment_cli_file}_tmp"
1111
rm -f "$kernel_config_fragment_cli_file_tmp"
1212
touch "$kernel_config_fragment_cli_file_tmp"
1313
configure=true
14-
config_fragments="${root_dir}/br2/default"
14+
config_fragments="${common_root_dir}/br2/default"
1515
extra_make_args=
1616
j="$(nproc)"
1717
linux_reconfigure=false
1818
linux_kernel_custom_config_file=
1919
kernel_config_fragments=
2020
post_script_args=
2121
qemu_sdl='--enable-sdl --with-sdlabi=2.0'
22-
suffix=
2322
v=0
2423
while getopts 'a:B:b:C:c:fGgj:hIiK:kL:lM:p:Q:qSst::v' OPT; do
2524
case "$OPT" in
2625
a)
27-
arch="$OPTARG"
26+
common_arch="$OPTARG"
2827
;;
2928
B)
3029
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
4443
g)
4544
extra_make_args="${extra_make_args} gem5-reconfigure \\
4645
"
47-
gem5=true
46+
common_gem5=true
4847
;;
4948
h)
5049
cat build-usage.adoc 1>&2
@@ -99,7 +98,7 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
9998
qemu_sdl=
10099
;;
101100
s)
102-
suffix="$OPTARG"
101+
common_suffix="$OPTARG"
103102
;;
104103
t)
105104
common_gem5_build_type="$OPTARG"
@@ -114,9 +113,9 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
114113
done
115114
shift $(($OPTIND - 1))
116115
extra_make_args="${extra_make_args} $@"
117-
set_common_vars -L "$common_linux_variant" -M "$common_gem5_variant" "$arch" "$gem5" "$suffix"
118-
config_file="${buildroot_out_dir}/.config"
119-
case "$arch" in
116+
common_setup
117+
config_file="${common_buildroot_out_dir}/.config"
118+
case "$common_arch" in
120119
x86_64)
121120
defconfig=qemu_x86_64_defconfig
122121
;;
@@ -130,7 +129,7 @@ case "$arch" in
130129
defconfig=qemu_mips64r6_malta_defconfig
131130
;;
132131
esac
133-
config_fragments="${config_fragments} ${root_dir}/br2/qemu ${br2_cli_file}"
132+
config_fragments="${config_fragments} ${common_root_dir}/br2/qemu ${br2_cli_file}"
134133

135134
time {
136135
# Configure.
@@ -139,16 +138,16 @@ if "$configure"; then
139138
# Only copy if modified, otherwise the kernel always rebuilds.
140139
cp "${kernel_config_fragment_cli_file_tmp}" "${kernel_config_fragment_cli_file}"
141140
fi
142-
cd "${buildroot_dir}"
143-
for p in $(find "${root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
141+
cd "${common_buildroot_dir}"
142+
for p in $(find "${common_root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
144143
patch -N -r - -p 1 < "$p" || :
145144
done
146145
br2_external='../kernel_module:../gem5:../parsec-benchmark'
147-
packages_dir="${root_dir}/packages"
146+
packages_dir="${common_root_dir}/packages"
148147
for package_dir in "${packages_dir}"/*/; do
149148
br2_external="${br2_external}:../packages/$(basename "${package_dir}")"
150149
done
151-
make O="$buildroot_out_dir" BR2_EXTERNAL="$br2_external" "$defconfig"
150+
make O="$common_buildroot_out_dir" BR2_EXTERNAL="$br2_external" "$defconfig"
152151
# TODO Can't get rid of these for now.
153152
# http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
154153
for config_fragment in $config_fragments; do
@@ -159,7 +158,7 @@ BR2_JLEVEL=${j}
159158
BR2_DL_DIR=\"${common_dir}/dl\"
160159
BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
161160
" >> "$config_file"
162-
if "$gem5"; then
161+
if "$common_gem5"; then
163162
printf "BR2_PACKAGE_GEM5=y\n" >> "${config_file}"
164163
fi
165164
kernel_config_fragment_dir=../kernel_config_fragment
@@ -182,11 +181,11 @@ BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
182181
# https://stackoverflow.com/questions/49260466/why-when-i-change-br2-linux-kernel-custom-config-file-and-run-make-linux-reconfi
183182
touch "${kernel_config_fragment_dir}/min"
184183
fi
185-
if [ "$arch" = 'mips64' ]; then
184+
if [ "$common_arch" = 'mips64' ]; then
186185
# Workaround for: https://bugs.busybox.net/show_bug.cgi?id=10276
187186
sed -Ei 's/^BR2_PACKAGE_LINUX_TOOLS_GPIO/BR2_PACKAGE_LINUX_TOOLS_GPIO=n/' "$config_file"
188187
fi
189-
make O="$buildroot_out_dir" olddefconfig
188+
make O="$common_buildroot_out_dir" olddefconfig
190189
fi
191190
echo 'config time:'
192191
}
@@ -214,13 +213,13 @@ symlink_buildroot_variant "$common_qemu_custom_dir" "$common_qemu_variant_dir"
214213
#symlink_buildroot_variant "$common_qemu_guest_custom_dir" "$common_qemu_guest_variant_dir"
215214

216215
# Manage gem5 variants.
217-
if "$gem5"; then
216+
if "$common_gem5"; then
218217
if [ ! -e "${common_gem5_src_dir}/.git" ]; then
219218
git -C "$common_gem5_default_src_dir" worktree add -b "wt/${common_gem5_variant}" "${common_gem5_src_dir}"
220219
fi
221220
fi
222221

223-
cd "$buildroot_dir"
222+
cd "$common_buildroot_dir"
224223
# HOST_QEMU_OPTS is a hack that happens to work because the QEMU package luckly uses += at all times.
225224
# It shouldn't be necessary in the first place: https://bugs.busybox.net/show_bug.cgi?id=9936
226225
#
@@ -233,7 +232,7 @@ cmd="time \\
233232
env \\
234233
-u LD_LIBRARY_PATH \\
235234
make \\
236-
O='${buildroot_out_dir}' \\
235+
O='${common_buildroot_out_dir}' \\
237236
HOST_QEMU_OPTS='--enable-debug --enable-trace-backends=simple ${qemu_sdl}' \\
238237
GEM5_LKMC_GEM5_BUILD_TYPE="$common_gem5_build_type" \\
239238
GEM5_LKMC_OUTDIR="$common_gem5_out_dir" \\
@@ -242,4 +241,4 @@ V='${v}' \\
242241
${extra_make_args} \
243242
all \\
244243
"
245-
"${root_dir}/eeval" "$cmd" "${out_arch_dir}/build.sh"
244+
"${common_root_dir}/eeval" "$cmd" "${common_out_arch_dir}/build.sh"

0 commit comments

Comments
 (0)