Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: resources: Add gem5_bridge driver to x86-ubuntu build & boot #48

Draft
wants to merge 8 commits into
base: stable
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/arm-ubuntu/files/after_boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ else
# If we can't read the script exit the simulation. If we cannot exit the
# simulation, this probably means that we are running in QEMU. So, ignore
# future calls to gem5-bridge.
if ! gem5-bridge exit; then
if ! echo 0 > /dev/gem5/exit; then
# Useful for booting the disk image in (e.g.,) qemu for debugging
printf "gem5-bridge exit failed, dropping to shell.\n"
IGNORE_M5=1 /bin/bash
Expand Down
Binary file added src/arm-ubuntu/files/flash0.img
Binary file not shown.
20 changes: 18 additions & 2 deletions src/arm-ubuntu/files/gem5_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@ mount -t sysfs /sys /sys
cmdline=$(cat /proc/cmdline)
no_systemd=false

# Load gem5_bridge driver
## Default parameters (ARM64)
gem5_bridge_baseaddr=0x10010000
gem5_bridge_rangesize=0x10000
## Try to read overloads from kernel arguments
if [[ $cmdline =~ gem5_bridge_baseaddr=([[:alnum:]]+) ]]; then
gem5_bridge_baseaddr=${BASH_REMATCH[1]}
fi
if [[ $cmdline =~ gem5_bridge_rangesize=([[:alnum:]]+) ]]; then
gem5_bridge_rangesize=${BASH_REMATCH[1]}
fi
## Insert driver
modprobe gem5_bridge \
gem5_bridge_baseaddr=$gem5_bridge_baseaddr \
gem5_bridge_rangesize=$gem5_bridge_rangesize

# gem5-bridge exit signifying that kernel is booted
printf "Kernel booted, starting gem5 init...\n"
gem5-bridge exit
echo 0 > /dev/gem5/exit # TODO: Make this a specialized event.

if [[ $cmdline == *"no_systemd"* ]]; then
no_systemd=true
fi

# Run systemd via exec if not disabled
if [[ $no_systemd == false ]]; then
# gem5-bridge exit signifying that systemd will be booted
printf "Starting systemd...\n"
exec /lib/systemd/systemd
else
printf "Dropping to shell as gem5 user...\n"
exec su - gem5
fi
18 changes: 16 additions & 2 deletions src/arm-ubuntu/scripts/post-installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ apt-get install -y build-essential
echo "Installing serial service for autologin after systemd"
mv /home/gem5/[email protected] /lib/systemd/system/

# Make sure the headers are installed to extract the kernel that DKMS
# packages will be built against.
sudo apt -y install "linux-headers-$(uname -r)" "linux-modules-extra-$(uname -r)"

echo "Extracting linux kernel $(uname -r) to /home/gem5/vmlinux-arm-ubuntu"
sudo bash -c "/usr/src/linux-headers-$(uname -r)/scripts/extract-vmlinux /boot/vmlinuz-$(uname -r) > /home/gem5/vmlinux-arm-ubuntu"

echo "Installing the gem5 init script in /sbin"
mv /home/gem5/gem5_init.sh /sbin
mv /sbin/init /sbin/init.old
Expand All @@ -31,10 +38,11 @@ rm /etc/update-motd.d/*
echo "Building and installing gem5-bridge (m5) and libm5"

# Just get the files we need
git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=stable
git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge
pushd gem5
# Checkout just the files we need
git sparse-checkout add util/m5
git sparse-checkout add util/gem5_bridge
git sparse-checkout add include
git checkout
# Install the headers globally so that other benchmarks can use them
Expand All @@ -46,6 +54,12 @@ scons build/arm64/out/m5
cp build/arm64/out/m5 /usr/local/bin/
cp build/arm64/out/libm5.a /usr/local/lib/
popd

# Build and insert the gem5-bridge driver
pushd util/gem5_bridge
make build install
depmod --quick
popd
popd

# rename the m5 binary to gem5-bridge
Expand All @@ -58,7 +72,7 @@ chmod u+s /usr/local/bin/gem5-bridge
ln -s /usr/local/bin/gem5-bridge /usr/local/bin/m5

# delete the git repo for gem5
rm -rf gem5
#rm -rf gem5
echo "Done building and installing gem5-bridge (m5) and libm5"

# You can extend this script to install your own packages here.
Expand Down
2 changes: 1 addition & 1 deletion src/x86-ubuntu/files/after_boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fi
printf "Interactive mode: $interactive\n"

if [[ $interactive == true ]]; then
printf "Interactive mode enabled, dropping to shell."
printf "Interactive mode enabled, dropping to shell.\n"
/bin/bash
else
# Try to read the file from the host when running with gem5
Expand Down
2 changes: 1 addition & 1 deletion src/x86-ubuntu/files/exit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Copyright (c) 2020 The Regents of the University of California.
# SPDX-License-Identifier: BSD 3-Clause

m5 exit
gem5-bridge exit
16 changes: 16 additions & 0 deletions src/x86-ubuntu/files/gem5_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ mount -t sysfs /sys /sys
cmdline=$(cat /proc/cmdline)
no_systemd=false

# Load gem5_bridge driver
## Default parameters (x86_64)
gem5_bridge_baseaddr=0xffff0000
gem5_bridge_rangesize=0x10000
## Try to read overloads from kernel arguments
if [[ $cmdline =~ gem5_bridge_baseaddr=([[:alnum:]]+) ]]; then
gem5_bridge_baseaddr=${BASH_REMATCH[1]}
fi
if [[ $cmdline =~ gem5_bridge_rangesize=([[:alnum:]]+) ]]; then
gem5_bridge_rangesize=${BASH_REMATCH[1]}
fi
## Insert driver
modprobe gem5_bridge \
gem5_bridge_baseaddr=$gem5_bridge_baseaddr \
gem5_bridge_rangesize=$gem5_bridge_rangesize

# gem5-bridge exit signifying that kernel is booted
# This will cause the simulation to exit. Note that this will
# cause qemu to fail.
Expand Down
27 changes: 17 additions & 10 deletions src/x86-ubuntu/scripts/post-installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ rm /etc/update-motd.d/*
echo "Building and installing gem5-bridge (m5) and libm5"

# Just get the files we need
git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=stable
git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge
pushd gem5
# Checkout just the files we need
git sparse-checkout add util/m5
git sparse-checkout add util/gem5_bridge
git sparse-checkout add include
git checkout
# Install the headers globally so that other benchmarks can use them
Expand All @@ -56,6 +57,12 @@ scons build/x86/out/m5
cp build/x86/out/m5 /usr/local/bin/
cp build/x86/out/libm5.a /usr/local/lib/
popd

# Build and insert the gem5-bridge driver
pushd util/gem5_bridge
make build install
depmod --quick
popd
popd

# rename the m5 binary to gem5-bridge
Expand All @@ -68,22 +75,22 @@ chmod u+s /usr/local/bin/gem5-bridge
ln -s /usr/local/bin/gem5-bridge /usr/local/bin/m5

# delete the git repo for gem5
rm -rf gem5
# rm -rf gem5
echo "Done building and installing gem5-bridge (m5) and libm5"

# You can extend this script to install your own packages here or by modifying the `x86-ubuntu.pkr.hcl` file.

# Disable network by default
echo "Disabling network by default"
echo "See README.md for instructions on how to enable network"
if [ -f /etc/netplan/50-cloud-init.yaml ]; then
mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
elif [ -f /etc/netplan/00-installer-config.yaml ]; then
mv /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
netplan apply
fi
# if [ -f /etc/netplan/50-cloud-init.yaml ]; then
# mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
# elif [ -f /etc/netplan/00-installer-config.yaml ]; then
# mv /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
# netplan apply
# fi
# Disable systemd service that waits for network to be online
systemctl disable systemd-networkd-wait-online.service
systemctl mask systemd-networkd-wait-online.service
# systemctl disable systemd-networkd-wait-online.service
# systemctl mask systemd-networkd-wait-online.service

echo "Post Installation Done"
6 changes: 3 additions & 3 deletions src/x86-ubuntu/x86-ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ build {
}

provisioner "file" {
source = "/home/gem5/vmlinux-x86-ubuntu"
destination = "./disk-image/vmlinux-x86-ubuntu"
direction = "download"
source = "/home/gem5/vmlinux-x86-ubuntu"
destination = "./disk-image/vmlinux-x86-ubuntu"
direction = "download"
}
}