mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
GEM5 checkpoint
Add gem5 as buildroot package to cross compile m5. Add gem5 as a submodule. Split gem5 from arch on CLI with "-a arm -g" instead of "-a arm-gem5".
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -13,6 +13,4 @@ modules.order
|
|||||||
trace*
|
trace*
|
||||||
|
|
||||||
# GEM5
|
# GEM5
|
||||||
/gem5
|
|
||||||
/gem5-system
|
|
||||||
/m5out
|
/m5out
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -8,3 +8,6 @@
|
|||||||
[submodule "linux"]
|
[submodule "linux"]
|
||||||
path = linux
|
path = linux
|
||||||
url = https://github.com/cirosantilli/linux
|
url = https://github.com/cirosantilli/linux
|
||||||
|
[submodule "gem5/gem5"]
|
||||||
|
path = gem5/gem5
|
||||||
|
url = https://gem5.googlesource.com/public/gem5
|
||||||
|
|||||||
56
README.adoc
56
README.adoc
@@ -1208,8 +1208,8 @@ Instead, we have only chip makers, who keep everything that really works closed,
|
|||||||
==== GEM5 ARM
|
==== GEM5 ARM
|
||||||
|
|
||||||
....
|
....
|
||||||
./configure && ./build -a arm-gem5
|
./configure && ./build -a arm -g
|
||||||
./rungem5 -a arm-gem5
|
./rungem5 -a arm
|
||||||
....
|
....
|
||||||
|
|
||||||
On another shell:
|
On another shell:
|
||||||
@@ -1223,7 +1223,7 @@ On another shell:
|
|||||||
E.g., to add `printk.time=y`, run:
|
E.g., to add `printk.time=y`, run:
|
||||||
|
|
||||||
....
|
....
|
||||||
./rungem5 -a arm-gem5 -- --command-line='earlyprintk=pl011,0x1c090000 console=ttyAMA0 lpj=19988480 norandmaps rw loglevel=8 mem=512MB root=/dev/sda printk.time=y'
|
./rungem5 -a arm -- --command-line='earlyprintk=pl011,0x1c090000 console=ttyAMA0 lpj=19988480 norandmaps rw loglevel=8 mem=512MB root=/dev/sda printk.time=y'
|
||||||
....
|
....
|
||||||
|
|
||||||
When you use `--command-line=`, it overrides default command lines, which are required to boot properly.
|
When you use `--command-line=`, it overrides default command lines, which are required to boot properly.
|
||||||
@@ -1233,7 +1233,7 @@ So if you pass just `--command-line='printk.time=y'`, it removes the required op
|
|||||||
An easy way to find the other options is to to an initial boot:
|
An easy way to find the other options is to to an initial boot:
|
||||||
|
|
||||||
....
|
....
|
||||||
./rungem5 -a arm-gem5
|
./rungem5 -a arm
|
||||||
....
|
....
|
||||||
|
|
||||||
and then look at the line of the linux kernel that starts with
|
and then look at the line of the linux kernel that starts with
|
||||||
@@ -1295,6 +1295,54 @@ Escape character is '^]'.
|
|||||||
|
|
||||||
I have also tried to copy the exact same kernel command line options used by QEMU, but nothing changed.
|
I have also tried to copy the exact same kernel command line options used by QEMU, but nothing changed.
|
||||||
|
|
||||||
|
===== GEM5 checkpoint
|
||||||
|
|
||||||
|
Analogous to QEMU's <<snapshot>>.
|
||||||
|
|
||||||
|
Documentation: http://gem5.org/Checkpoints
|
||||||
|
|
||||||
|
....
|
||||||
|
./rungem5 -a arm
|
||||||
|
....
|
||||||
|
|
||||||
|
In guest, wait for the boot to end and run:
|
||||||
|
|
||||||
|
....
|
||||||
|
/m5 checkpoint
|
||||||
|
....
|
||||||
|
|
||||||
|
To restore the checkpoint, kill the VM and run:
|
||||||
|
|
||||||
|
....
|
||||||
|
./rungem5 -a arm -- -r 1
|
||||||
|
....
|
||||||
|
|
||||||
|
Let's create a second checkpoint to see how it works, in guest:
|
||||||
|
|
||||||
|
....
|
||||||
|
date >f
|
||||||
|
/m5 checkpoint
|
||||||
|
....
|
||||||
|
|
||||||
|
Kill the VM, and try it out:
|
||||||
|
|
||||||
|
....
|
||||||
|
./rungem5 -a arm -- -r 2
|
||||||
|
....
|
||||||
|
|
||||||
|
and now in the guest:
|
||||||
|
|
||||||
|
....
|
||||||
|
cat f
|
||||||
|
....
|
||||||
|
|
||||||
|
contains the `date`. The file `f` wouldn't exist had we used the first checkpoint with `-r 1`.
|
||||||
|
|
||||||
|
Internals:
|
||||||
|
|
||||||
|
- the checkpoints are stored under `m5out/cpt.*`
|
||||||
|
- `m5` is a guest utility present inside the GEM5 tree which we cross-compiled and installed into the guest
|
||||||
|
|
||||||
==== GEM5 x86
|
==== GEM5 x86
|
||||||
|
|
||||||
TODO didn't get it working yet.
|
TODO didn't get it working yet.
|
||||||
|
|||||||
45
build
45
build
@@ -2,16 +2,20 @@
|
|||||||
set -e
|
set -e
|
||||||
arch=x86_64
|
arch=x86_64
|
||||||
extra_targets=''
|
extra_targets=''
|
||||||
qemu_sdl='--enable-sdl --with-sdlabi=2.0'
|
gem5=false
|
||||||
j="$(($(nproc) - 2))"
|
j="$(($(nproc) - 2))"
|
||||||
post_script_args=''
|
post_script_args=''
|
||||||
|
qemu_sdl='--enable-sdl --with-sdlabi=2.0'
|
||||||
x11=false
|
x11=false
|
||||||
v=0
|
v=0
|
||||||
while getopts 'a:j:lp:qSt:v' OPT; do
|
while getopts 'a:gj:lp:qSt:v' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
a)
|
a)
|
||||||
arch="$OPTARG"
|
arch="$OPTARG"
|
||||||
;;
|
;;
|
||||||
|
g)
|
||||||
|
gem5=true
|
||||||
|
;;
|
||||||
j)
|
j)
|
||||||
j="$OPTARG"
|
j="$OPTARG"
|
||||||
;;
|
;;
|
||||||
@@ -43,19 +47,17 @@ case "$arch" in
|
|||||||
x86_64)
|
x86_64)
|
||||||
defconfig=qemu_x86_64_defconfig
|
defconfig=qemu_x86_64_defconfig
|
||||||
;;
|
;;
|
||||||
x86_64-gem5)
|
|
||||||
defconfig=qemu_x86_64_defconfig
|
|
||||||
;;
|
|
||||||
arm)
|
arm)
|
||||||
# qemu_arm_vexpress_defconfig required a newer QEMU than 2.0.0 on a Ubuntu host.
|
if "$gem5"; then
|
||||||
# so let's stick to versatile for now.
|
# Ideally we should use a custom clean config here.
|
||||||
defconfig=qemu_arm_versatile_defconfig
|
# But let's just use this one as a starting point for now.
|
||||||
;;
|
defconfig=qemu_arm_versatile_defconfig
|
||||||
arm-gem5)
|
post_script_args="$post_script_args -n"
|
||||||
# Ideally we should use a custom clean config here.
|
else
|
||||||
# But let's just use this one as a starting point for now.
|
# qemu_arm_vexpress_defconfig required a newer QEMU than 2.0.0 on a Ubuntu host.
|
||||||
defconfig=qemu_arm_versatile_defconfig
|
# so let's stick to versatile for now.
|
||||||
post_script_args="$post_script_args -n"
|
defconfig=qemu_arm_versatile_defconfig
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
aarch64)
|
aarch64)
|
||||||
defconfig=qemu_aarch64_virt_defconfig
|
defconfig=qemu_aarch64_virt_defconfig
|
||||||
@@ -64,6 +66,10 @@ case "$arch" in
|
|||||||
defconfig=qemu_mips64r6_malta_defconfig
|
defconfig=qemu_mips64r6_malta_defconfig
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
arch_dir="$arch"
|
||||||
|
if "$gem5"; then
|
||||||
|
arch_dir="${arch}-gem5"
|
||||||
|
fi
|
||||||
|
|
||||||
cd kernel_module
|
cd kernel_module
|
||||||
./make-host.sh -j "$j" clean
|
./make-host.sh -j "$j" clean
|
||||||
@@ -71,14 +77,14 @@ cd ../buildroot
|
|||||||
for p in $(find '../buildroot_patches/' -maxdepth 1 -name '*.patch' -print); do
|
for p in $(find '../buildroot_patches/' -maxdepth 1 -name '*.patch' -print); do
|
||||||
patch -N -r - -p 1 <"$p" || :
|
patch -N -r - -p 1 <"$p" || :
|
||||||
done
|
done
|
||||||
outdir="output.${arch}~"
|
outdir="output.${arch_dir}~"
|
||||||
make O="$outdir" BR2_EXTERNAL="$(pwd)/../kernel_module" "$defconfig"
|
make O="$outdir" BR2_EXTERNAL="$(pwd)/../kernel_module:$(pwd)/../gem5" "$defconfig"
|
||||||
# TODO Can't get rid of this for now.
|
# TODO Can't get rid of this for now.
|
||||||
# http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
|
# http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
|
||||||
cat ../buildroot_config_fragment >> "${outdir}/.config"
|
cat ../buildroot_config_fragment >> "${outdir}/.config"
|
||||||
if echo "$arch" | grep -Eq -- '-gem5$'; then
|
if "$gem5"; then
|
||||||
echo "\
|
echo "\
|
||||||
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"../kernel_config_${arch}\"
|
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"../kernel_config_${arch_dir}\"
|
||||||
" >> "${outdir}/.config"
|
" >> "${outdir}/.config"
|
||||||
else
|
else
|
||||||
echo "\
|
echo "\
|
||||||
@@ -105,6 +111,7 @@ time \
|
|||||||
make \
|
make \
|
||||||
O="$outdir" \
|
O="$outdir" \
|
||||||
BR2_JLEVEL="$j" \
|
BR2_JLEVEL="$j" \
|
||||||
|
BR2_PACKAGE_GEM5="$("$gem5" && echo y || echo n)" \
|
||||||
BR2_ROOTFS_POST_SCRIPT_ARGS="$post_script_args" \
|
BR2_ROOTFS_POST_SCRIPT_ARGS="$post_script_args" \
|
||||||
HOST_QEMU_OPTS="--enable-debug --extra-cflags='-DDEBUG_PL061=1' --enable-trace-backends=simple $qemu_sdl" \
|
HOST_QEMU_OPTS="--enable-debug --extra-cflags='-DDEBUG_PL061=1' --enable-trace-backends=simple $qemu_sdl" \
|
||||||
V="$v" \
|
V="$v" \
|
||||||
@@ -113,6 +120,6 @@ time \
|
|||||||
all \
|
all \
|
||||||
;
|
;
|
||||||
cd ..
|
cd ..
|
||||||
if echo "$arch" | grep -Eq -- '-gem5$'; then
|
if "$gem5"; then
|
||||||
./build-gem5 -a "$arch"
|
./build-gem5 -a "$arch"
|
||||||
fi
|
fi
|
||||||
|
|||||||
17
build-gem5
17
build-gem5
@@ -1,6 +1,6 @@
|
|||||||
#/usr/bin/env bash
|
#/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
arch='arm-gem5'
|
arch=arm
|
||||||
while getopts 'a:' OPT; do
|
while getopts 'a:' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
a)
|
a)
|
||||||
@@ -9,16 +9,13 @@ while getopts 'a:' OPT; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift "$(($OPTIND - 1))"
|
shift "$(($OPTIND - 1))"
|
||||||
if [ ! -d 'gem5' ]; then
|
top="$(pwd)/gem5"
|
||||||
git clone https://gem5.googlesource.com/public/gem5
|
system_dir="${top}/gem5-system"
|
||||||
fi
|
|
||||||
cd gem5
|
|
||||||
git checkout da79d6c6cde0fbe5473ce868c9be4771160a003b
|
|
||||||
system_dir='../gem5-system'
|
|
||||||
binaries_dir="${system_dir}/binaries"
|
binaries_dir="${system_dir}/binaries"
|
||||||
disks_dir="${system_dir}/disks"
|
disks_dir="${system_dir}/disks"
|
||||||
mkdir -p "$binaries_dir" "$disks_dir"
|
mkdir -p "$binaries_dir" "$disks_dir"
|
||||||
if [ "$arch" = 'x86_64-gem5' ]; then
|
cd "${top}/gem5"
|
||||||
|
if [ "$arch" = x86_64 ]; then
|
||||||
CC=gcc-6 CXX=g++-6 scons -j"$(nproc)" --ignore-style build/X86/gem5.opt
|
CC=gcc-6 CXX=g++-6 scons -j"$(nproc)" --ignore-style build/X86/gem5.opt
|
||||||
f="${disks_dir}/linux-bigswap2.img"
|
f="${disks_dir}/linux-bigswap2.img"
|
||||||
dd if=/dev/zero of="$f" bs=1024 count=65536
|
dd if=/dev/zero of="$f" bs=1024 count=65536
|
||||||
@@ -26,7 +23,7 @@ if [ "$arch" = 'x86_64-gem5' ]; then
|
|||||||
# This file must always be present, despite --kernel overriding that default and selecting the kernel.
|
# This file must always be present, despite --kernel overriding that default and selecting the kernel.
|
||||||
# I'm not even joking. No one has ever built x86 gem5 without the magic dist dir present.
|
# I'm not even joking. No one has ever built x86 gem5 without the magic dist dir present.
|
||||||
touch "${binaries_dir}/x86_64-vmlinux-2.6.22.9"
|
touch "${binaries_dir}/x86_64-vmlinux-2.6.22.9"
|
||||||
elif [ "$arch" = 'arm-gem5' ]; then
|
elif [ "$arch" = arm ]; then
|
||||||
# Compilation fails with gcc 7 on that commit.
|
# Compilation fails with gcc 7 on that commit.
|
||||||
# There were some recent portability patches, so it will likely get there soon.
|
# There were some recent portability patches, so it will likely get there soon.
|
||||||
CC=gcc-6 CXX=g++-6 scons -j"$(nproc)" --ignore-style build/ARM/gem5.opt
|
CC=gcc-6 CXX=g++-6 scons -j"$(nproc)" --ignore-style build/ARM/gem5.opt
|
||||||
@@ -37,4 +34,4 @@ elif [ "$arch" = 'arm-gem5' ]; then
|
|||||||
cp ./system/arm/aarch64_bootloader/boot_emm.arm64 "$binaries_dir"
|
cp ./system/arm/aarch64_bootloader/boot_emm.arm64 "$binaries_dir"
|
||||||
fi
|
fi
|
||||||
# TODO vs telnet?
|
# TODO vs telnet?
|
||||||
make -C gem5/util/term
|
make -C util/term
|
||||||
|
|||||||
1
gem5/.gitignore
vendored
Normal file
1
gem5/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/gem5-system
|
||||||
4
gem5/Config.in
Normal file
4
gem5/Config.in
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
config BR2_PACKAGE_GEM5
|
||||||
|
bool "gem5"
|
||||||
|
help
|
||||||
|
GEM5
|
||||||
1
gem5/external.desc
Normal file
1
gem5/external.desc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
name: GEM5
|
||||||
19
gem5/external.mk
Normal file
19
gem5/external.mk
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# GEM5
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
GEM5_VERSION = 1.0
|
||||||
|
GEM5_SITE = $(BR2_EXTERNAL_GEM5_PATH)
|
||||||
|
GEM5_SITE_METHOD = local
|
||||||
|
|
||||||
|
define GEM5_BUILD_CMDS
|
||||||
|
cd '$(@D)/gem5/util/m5' && $(MAKE) -f 'Makefile.$(ARCH)' CC='$(TARGET_CC)' LD='$(TARGET_LD)'
|
||||||
|
endef
|
||||||
|
|
||||||
|
define GEM5_INSTALL_TARGET_CMDS
|
||||||
|
$(INSTALL) -D -m 0755 '$(@D)/gem5/util/m5/m5' '$(TARGET_DIR)'
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(generic-package))
|
||||||
1
gem5/gem5
Submodule
1
gem5/gem5
Submodule
Submodule gem5/gem5 added at da79d6c6cd
38
rungem5
38
rungem5
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
arch='arm-gem5'
|
arch=arm
|
||||||
while getopts 'a:' OPT; do
|
while getopts 'a:' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
a)
|
a)
|
||||||
@@ -8,27 +8,27 @@ while getopts 'a:' OPT; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift "$(($OPTIND - 1))"
|
shift "$(($OPTIND - 1))"
|
||||||
outdir="$(pwd)/buildroot/output.${arch}~"
|
outdir="$(pwd)/buildroot/output.${arch}-gem5~"
|
||||||
echo $arch
|
gem5_dir="$(pwd)/gem5/gem5"
|
||||||
if echo "$arch" | grep -Eq '^x86_64(-|$)'; then
|
if [ "$arch" = x86_64 ]; then
|
||||||
cmd="\
|
cmd="\
|
||||||
M5_PATH=\"$(pwd)/gem5-system\" \
|
M5_PATH='$(pwd)/gem5/gem5-system' \
|
||||||
./gem5/build/X86/gem5.opt \
|
'${gem5_dir}/build/X86/gem5.opt' \
|
||||||
gem5/configs/example/fs.py \
|
'${gem5_dir}/configs/example/fs.py' \
|
||||||
--disk-image=\"${outdir}/images/rootfs.ext2\" \
|
--disk-image='${outdir}/images/rootfs.ext2' \
|
||||||
--kernel=\"${outdir}/build/linux-custom/vmlinux\" \
|
--kernel='${outdir}/build/linux-custom/vmlinux' \
|
||||||
--root-device='/dev/sda' \
|
--root-device=/dev/sda \
|
||||||
"
|
"
|
||||||
elif echo "$arch" | grep -Eq '^arm(-|$)'; then
|
elif [ "$arch" = arm ]; then
|
||||||
cmd="\
|
cmd="\
|
||||||
M5_PATH=\"$(pwd)/gem5-system\" \
|
M5_PATH='$(pwd)/gem5/gem5-system' \
|
||||||
./gem5/build/ARM/gem5.opt \
|
'${gem5_dir}/build/ARM/gem5.opt' \
|
||||||
gem5/configs/example/fs.py \
|
'${gem5_dir}/configs/example/fs.py' \
|
||||||
--disk-image=\"${outdir}/images/rootfs.ext2\" \
|
--disk-image='${outdir}/images/rootfs.ext2' \
|
||||||
--dtb-file=\"$(pwd)/gem5/system/arm/dt/armv7_gem5_v1_1cpu.dtb\" \
|
--dtb-file='${gem5_dir}/system/arm/dt/armv7_gem5_v1_1cpu.dtb' \
|
||||||
--kernel=\"${outdir}/build/linux-custom/vmlinux\" \
|
--kernel='${outdir}/build/linux-custom/vmlinux' \
|
||||||
--machine-type='VExpress_GEM5_V1' \
|
--machine-type=VExpress_GEM5_V1 \
|
||||||
--root-device='/dev/sda' \
|
--root-device=/dev/sda \
|
||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
cmd="$cmd \"\$@\""
|
cmd="$cmd \"\$@\""
|
||||||
|
|||||||
Reference in New Issue
Block a user