Skip to content

Commit 56738a1

Browse files
committed
lkmc v2-rc
Unsquashed version at v2-rc-unsquashed, but that cannot be merged as it breaks bisects at several points. All bugs will not bisect to this humongous change. It all started with a conversion of the Bash scripts to Python, mainly because I couldn't stand not being able to properly use --options for run which has a million options. Then since that required a full testing, I decided to do all the refactorings that I had in mind at once, and so I did and it became v2-rc. This is the largest patch I have ever done! OMG a few weeks of extra time. I'm never writing a Bash script for anything that starts getting big again. Some of the features are: * separate build-qemu and build-gem5 commands * common: convert scripts to python. Add --option for everything * rename build to build-buildroot now that we are splitting all the build commands, Linux kernel to follow * move all git submodules to submodules/ and all buildroot packages to packages/ * refactor the out/ structure. Keep projects on toplevel, because guest projects separate archs and host ones don't, making a toplevel arch wrong * do-release: rename to just release https://stackoverflow.com/questions/16174992/cant-get-argparse-to-read-quoted-string-with-dashes-in-it * run: add --terminal and explain gem5 pdb * just track the lvimrc * store CLI kernel config fragment inside buildlroot to avoid conflicts * gem5: document m5 initparam * readme: make a bunch of things awesomer * readme: fix broken refs * parsec-benchmark: update to 75d55ac446a43c47efb1044844a108c6c330184c Could not fetch otherwise. * gem5: M5_OVERRIDE_PY_SOURCE
1 parent 83b3686 commit 56738a1

File tree

162 files changed

+4897
-3828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+4897
-3828
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ gitignore*
1111
/images-*.zip
1212
/out
1313
/out.*
14+
15+
# Python trash.
16+
*.pyc
17+
__pycache__

.gitmodules

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
[submodule "buildroot"]
2-
path = buildroot
1+
[submodule "submodules/buildroot"]
2+
path = submodules/buildroot
33
url = https://github.com/cirosantilli/buildroot
44
ignore = dirty
5-
[submodule "qemu"]
6-
path = qemu
5+
[submodule "submodules/qemu"]
6+
path = submodules/qemu
77
url = https://github.com/cirosantilli/qemu
8-
[submodule "linux"]
9-
path = linux
8+
# The true upstream does not accept git submodule update --init --depth 1
9+
# git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
10+
# But git clone --branch --depth 1 worked weirdly:
11+
# https://unix.stackexchange.com/questions/338578/linux-kernel-source-code-size-difference
12+
[submodule "submodules/linux"]
13+
path = submodules/linux
1014
url = https://github.com/cirosantilli/linux
11-
[submodule "gem5/gem5"]
12-
path = gem5/gem5
15+
[submodule "submodules/gem5"]
16+
path = submodules/gem5
1317
url = https://gem5.googlesource.com/public/gem5
14-
[submodule "parsec-benchmark/parsec-benchmark"]
15-
path = parsec-benchmark/parsec-benchmark
18+
[submodule "submodules/parsec-benchmark"]
19+
path = submodules/parsec-benchmark
1620
url = https://github.com/cirosantilli/parsec-benchmark

.lvimrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
" Use this automatically with:
2+
"
3+
" Plugin 'embear/vim-localvimrc'
4+
" let g:localvimrc_ask = 0
5+
" let g:localvimrc_sandbox = 0
6+
7+
if &filetype ==# 'c' || &filetype ==# 'cpp'
8+
setlocal noexpandtab
9+
endif

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ script: |
2121
# The following packages have unmet dependencies:
2222
# libsdl2-dev : Depends: libegl1-mesa-dev
2323
# Depends: libgles2-mesa-dev
24+
bash -x ./build-qemu -j 16 -S |& awk 'NR % 1000 == 0'
2425
bash -x ./build -j 16 -S |& awk 'NR % 1000 == 0'
2526
bash -x ./run -e 'init=/poweroff.out'

README.adoc

Lines changed: 2710 additions & 2349 deletions
Large diffs are not rendered by default.

bench-all

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
#!/usr/bin/env bash
2-
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
3-
set -x
4-
bench_build=false
5-
bench_buildroot_baseline=false
2+
set -eux
3+
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
4+
bench_all=false
5+
bench_buildroot_build=false
6+
bench_buildroot_baseline_build=false
67
bench_gem5_build=false
78
bench_linux_boot=false
89
default_arch=x86_64
910
update_repo=false
1011
while getopts Aa:Bbglu OPT; do
1112
case "$OPT" in
1213
A)
13-
bench_build=true
14-
bench_buildroot_baseline=true
15-
bench_gem5_build=true
16-
bench_linux_boot=true
14+
bench_all=true
1715
;;
1816
a)
1917
default_arch="$OPTARG"
2018
;;
2119
b)
22-
bench_build=true
20+
bench_buildroot_build=true
2321
;;
2422
B)
25-
bench_buildroot_baseline=true
23+
bench_buildroot_baseline_build=true
2624
;;
2725
g)
2826
bench_gem5_build=true
@@ -40,9 +38,24 @@ while getopts Aa:Bbglu OPT; do
4038
done
4139
shift "$(($OPTIND - 1))"
4240
comment="${1:-}"
41+
if \
42+
! "$bench_buildroot_build" && \
43+
! "$bench_buildroot_baseline_build" && \
44+
! "$bench_gem5_build" && \
45+
! "$bench_linux_boot" \
46+
; then
47+
bench_all=true
48+
fi
49+
if "$bench_all"; then
50+
bench_buildroot_build=true
51+
bench_buildroot_baseline_build=true
52+
bench_gem5_build=true
53+
bench_linux_boot=true
54+
fi
55+
getvar="${root_dir}/getvar"
4356

4457
# Create output directory.
45-
benchmark_repo="${common_root_dir}/../linux-kernel-module-cheat-regression"
58+
benchmark_repo="${root_dir}/../linux-kernel-module-cheat-regression"
4659
mkdir -p "$benchmark_repo"
4760
last_dir="$(ls "$benchmark_repo" | grep -E '^[0-9]' | tail -n 1)"
4861
if [ -n "$last_dir" ]; then
@@ -51,62 +64,61 @@ else
5164
seq_id=0
5265
fi
5366
seq_id="$(printf '%0.4d' "$seq_id")"
54-
dir_basename="${seq_id}_${common_sha}"
67+
dir_basename="${seq_id}_$("$getvar" sha)"
5568
new_dir="${benchmark_repo}/${dir_basename}"
5669
mkdir "$new_dir"
5770

58-
if "$bench_build"; then
59-
common_arch="$default_arch"
60-
common_suffix=bench
61-
common_setup
62-
rm -rf "$common_out_arch_dir"
63-
./build -a "$common_arch" -B 'BR2_CCACHE=n' -s "$common_suffix"
64-
cp "${common_build_dir}/build-time.log" "${new_dir}/build-time-${common_arch}.log"
65-
rm -rf "$common_out_arch_dir"
71+
do_bench_buildroot_build() (
72+
arch="$default_arch"
73+
build_id=bench
74+
if [ "${1:-}" = baseline ]; then
75+
baseline=--baseline
76+
baseline_suffix=-baseline
77+
else
78+
baseline=
79+
baseline_suffix=
80+
fi
81+
common_build_dir="$("$getvar" --arch "$arch" --buildroot-build-id "$build_id" build_dir)"
82+
common_images_dir="$("$getvar" --arch "$arch" --buildroot-build-id "$build_id" images_dir)"
83+
"${root_dir}/build-buildroot" --arch "$arch" $baseline --buildroot-build-id "$build_id" --clean
84+
"${root_dir}/build-buildroot" --arch "$arch" $baseline --buildroot-build-id "$build_id" --no-all -- source
85+
"${root_dir}/build-buildroot" --arch "$arch" $baseline --buildroot-build-id "$build_id"
86+
cp "${common_build_dir}/build-time.log" "${new_dir}/buildroot-build-time-${baseline_suffix}${arch}.log"
87+
wc -c "${images_dir}/"* > "${new_dir}/buildroot-image-size-${baseline_suffix}${arch}.log"
88+
"${root_dir}/build-buildroot" --arch "$arch" $baseline --buildroot-build-id "$build_id" --clean
89+
)
90+
91+
if "$bench_buildroot_build"; then
92+
do_bench_buildroot_build
6693
fi
6794

68-
if "$bench_buildroot_baseline"; then
69-
cd "${common_root_dir}/buildroot"
70-
git clean -xdf
71-
make "qemu_${default_arch}_defconfig"
72-
printf '
73-
BR2_CCACHE=y
74-
BR2_TARGET_ROOTFS_CPIO=y
75-
BR2_TARGET_ROOTFS_EXT2=n
76-
' >>.config
77-
make olddefconfig
78-
make source
79-
time env -u LD_LIBRARY_PATH make BR2_JLEVEL="$(nproc)"
80-
cp output/build/build-time.log "${new_dir}/baseline-build-time-${default_arch}.log"
81-
wc -c output/images/* > "${new_dir}/baseline-image-size-${default_arch}.log"
82-
git clean -xdf
95+
if "$bench_buildroot_baseline_build"; then
96+
do_bench_buildroot_build baseline
8397
fi
8498

8599
if "$bench_gem5_build"; then
86-
arches='x86_64 arm'
87-
for common_arch in $arches; do
88-
common_setup
89-
cd "${common_gem5_src_dir}"
90-
git clean -xdf
91-
results_file="${common_gem5_out_dir}/bench-build.txt"
92-
gem5_outdir="${common_out_dir}/bench_build"
93-
rm -fr "$results_file" "${gem5_outdir}"
94-
# TODO understand better: --foreground required otherwise we cannot
95-
# kill the build with Ctrl+C if something goes wrong, can be minimized to:
96-
# bash -c "eval 'timeout 5 sleep 3'"
97-
common_bench_cmd "timeout --foreground 900 ../build -a '$common_arch' -o '${gem5_outdir}'" "$results_file"
98-
cp "$results_file" "${new_dir}/gem5-bench-build-${common_arch}.txt"
99-
cd "${common_root_dir}/gem5/gem5"
100-
git clean -xdf
101-
rm -fr "${gem5_outdir}"
102-
done
100+
common_arch="$default_arch"
101+
gem5_build_id=bench-build
102+
common_gem5_build_dir="$("$getvar" --arch "$common_arch" --gem5-build-id "$gem5_build_id" gem5_out_dir)"
103+
common_gem5_src_dir="$("$getvar" --arch "$common_arch" --gem5-build-id "$gem5_build_id" gem5_src_dir)"
104+
results_file="${common_gem5_build_dir}/bench-build.txt"
105+
git -C "${common_gem5_src_dir}" clean -xdf
106+
rm -f "$results_file"
107+
"${root_dir}/build-gem5" --arch "$common_arch" --clean --gem5-build-id "$gem5_build_id"
108+
# TODO understand better: --foreground required otherwise we cannot
109+
# kill the build with Ctrl+C if something goes wrong, can be minimized to:
110+
# bash -c "eval 'timeout 5 sleep 3'"
111+
"${root_dir}/bench-cmd" "timeout --foreground 900 ./build-gem5 --arch '$common_arch' --gem5-build-id '$gem5_build_id'" "$results_file"
112+
cp "$results_file" "${new_dir}/gem5-bench-build-${common_arch}.txt"
113+
git -C "${common_gem5_src_dir}" clean -xdf
114+
"${root_dir}/build-gem5" --arch "$common_arch" --clean --gem5-build-id "$gem5_build_id"
103115
fi
104116

105117
if "$bench_linux_boot"; then
106-
cd "${common_root_dir}"
107-
./build-all
108-
./bench-boot
109-
cp "$common_bench_boot" "$new_dir"
118+
cd "${root_dir}"
119+
"${root_dir}/build-all"
120+
"${root_dir}/bench-boot" -t 3
121+
cp "$(${root_dir}/getvar bench_boot)" "$new_dir"
110122
fi
111123

112124
if "$update_repo"; then

bench-boot

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
2+
set -eu
3+
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
34
test_size=1
45
OPTIND=1
56
while getopts t: OPT; do
@@ -16,56 +17,83 @@ while getopts t: OPT; do
1617
esac
1718
done
1819
shift "$(($OPTIND - 1))"
19-
extra_args="$*"
20-
20+
if [ $# -gt 1 ]; then
21+
extra_args=" $*"
22+
else
23+
extra_args=
24+
fi
25+
getvar="${root_dir}/getvar"
26+
common_bench_boot="$("$getvar" bench_boot)"
2127
caches='--caches --l2cache --l1d_size=1024kB --l1i_size=1024kB --l2_size=1024kB --l3_size=1024kB'
28+
2229
bench() (
23-
common_bench_cmd "./run -a ${1} ${extra_args}" "$common_bench_boot"
24-
echo >> "$common_bench_boot"
30+
"${root_dir}/bench-cmd" "./run --arch ${1}${extra_args}" "$common_bench_boot"
2531
)
32+
2633
gem5_insts() (
27-
printf "instructions $(./gem5-stat -a "$1" sim_insts)\n" >> "$common_bench_boot"
34+
printf "instructions $(./gem5-stat --arch "$1" sim_insts)\n" >> "$common_bench_boot"
2835
)
36+
2937
qemu_insts() (
3038
common_arch="$1"
31-
./qemu-trace2txt -a "$common_arch"
32-
common_setup
33-
printf "instructions $(wc -l "${common_trace_txt_file}" | cut -d' ' -f1)\n" >> "$common_bench_boot"
39+
./qemu-trace2txt --arch "$common_arch"
40+
common_qemu_trace_txt_file="$("$getvar" --arch "$common_arch" qemu_trace_txt_file)"
41+
printf "instructions $(wc -l "${common_qemu_trace_txt_file}" | cut -d' ' -f1)\n" >> "$common_bench_boot"
3442
)
43+
44+
newline() (
45+
echo >> "$common_bench_boot"
46+
)
47+
3548
rm -f "${common_bench_boot}"
3649

3750
arch=x86_64
38-
bench "$arch -E '/poweroff.out'"
39-
bench "$arch -E '/poweroff.out' -K"
51+
bench "${arch} --eval '/poweroff.out'"
52+
newline
53+
bench "${arch} --eval '/poweroff.out' --kvm"
54+
newline
4055
if [ "$test_size" -ge 2 ]; then
41-
bench "$arch -E '/poweroff.out' -T exec_tb"
56+
bench "${arch} --eval '/poweroff.out' --trace exec_tb"
4257
qemu_insts "$arch"
43-
fi
44-
if [ "$test_size" -ge 2 ]; then
45-
bench "$arch -E 'm5 exit' -g"
58+
newline
59+
bench "$arch --eval 'm5 exit' --gem5"
4660
gem5_insts "$arch"
61+
newline
4762
fi
48-
#bench "$arch -E 'm5 exit' -g -- --cpu-type=DerivO3CPU ${caches}"
63+
#bench "$arch --eval 'm5 exit' --gem5 -- --cpu-type=DerivO3CPU ${caches}"
4964
#gem5_insts "$arch"
65+
#newline
5066

5167
arch=arm
52-
bench "$arch -E '/poweroff.out'"
68+
bench "$arch --eval '/poweroff.out'"
69+
newline
5370
if [ "$test_size" -ge 2 ]; then
54-
bench "$arch -E '/poweroff.out' -T exec_tb"
71+
bench "$arch --eval '/poweroff.out' --trace exec_tb"
5572
qemu_insts "$arch"
73+
newline
74+
#bench "$arch --eval 'm5 exit' --gem5"
75+
#gem5_insts "$arch"
76+
#newline
5677
fi
57-
#bench "$arch -E 'm5 exit' -g"
58-
#gem5_insts "$arch"
59-
#bench "$arch -E 'm5 exit' -g -- --cpu-type=HPI ${caches}"
60-
#gem5_insts "$arch"
78+
#if [ "$test_size" -ge 3 ]; then
79+
# bench "$arch --eval 'm5 exit' --gem5 -- --cpu-type=HPI ${caches}"
80+
# gem5_insts "$arch"
81+
# newline
82+
#fi
6183

6284
arch=aarch64
63-
bench "$arch -E '/poweroff.out'"
85+
bench "$arch --eval '/poweroff.out'"
86+
newline
6487
if [ "$test_size" -ge 2 ]; then
65-
bench "$arch -E '/poweroff.out' -T exec_tb"
88+
bench "$arch --eval '/poweroff.out' --trace exec_tb"
6689
qemu_insts "$arch"
90+
newline
91+
bench "$arch --eval 'm5 exit' --gem5"
92+
gem5_insts "$arch"
93+
newline
94+
fi
95+
if [ "$test_size" -ge 3 ]; then
96+
bench "$arch --eval 'm5 exit' --gem5 -- --cpu-type=HPI ${caches}"
97+
gem5_insts "$arch"
98+
newline
6799
fi
68-
#bench "$arch -E 'm5 exit' -g"
69-
#gem5_insts "$arch"
70-
#bench "$arch -E 'm5 exit' -g -- --cpu-type=HPI ${caches}"
71-
#gem5_insts "$arch"

bench-cmd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# Benchmark a command as a string and output results
3+
# to a file with format:
4+
#
5+
# cmd <command run>
6+
# time <time in seconds to finish>
7+
# exit_status <exit status>
8+
set -eu
9+
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
10+
# Command to benchmark
11+
cmd="$1"
12+
shift
13+
# Where to append write results to. Default: /dev/null.
14+
results_file="${1:-/dev/null}"
15+
printf 'cmd ' >> "$results_file"
16+
env time --append -f 'time %e' --output="$results_file" "${root_dir}/eeval" -a "$cmd" "$results_file"
17+
printf "exit_status $?\n" >> "$results_file"

bisect-linux-boot-gem5

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
3+
import imp
4+
import os
5+
import shutil
6+
import sys
7+
8+
import common
9+
build = imp.load_source('build', os.path.join(common.root_dir, 'build'))
10+
run = imp.load_source('run', os.path.join(common.root_dir, 'run'))
11+
12+
parser = common.get_argparse(
13+
argparse_args={
14+
'description': '''Bisect the Linux kernel on gem5 boots.
15+
16+
More information at: https://github.com/cirosantilli/linux-kernel-module-cheat#bisection
17+
'''},
18+
default_args={
19+
'gem5': True,
20+
'linux_build_id': 'bisect',
21+
},
22+
)
23+
args = common.setup(parser)
24+
# We need a clean rebuild because rebuilds at different revisions:
25+
# - may fail
26+
# - may not actually rebuild all files, e.g. on header changes
27+
common.rmrf(common.linux_variant_dir)
28+
assert build.main(args) == 0
29+
status = run.main(args, {
30+
'eval': 'm5 exit',
31+
})
32+
if status == 125 or status == 127:
33+
status = 1
34+
sys.exit(status)

0 commit comments

Comments
 (0)