From 977630ed74cbeb6bbd8d2513ee1641b6066fe84c Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Fri, 17 Jan 2025 14:27:38 -0800 Subject: [PATCH 1/6] resources: Add files to make 6.8.12 riscv kernel and gem5 bridge driver --- .../24.04-dockerfile/Dockerfile | 44 +++++++++++++++++++ .../files/gem5_init.sh | 17 +++++++ .../make-riscv-kernel.sh | 29 ++++++++++++ .../riscv-ubuntu.pkr.hcl | 6 ++- .../scripts/post-installation.sh | 8 +++- 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile create mode 100755 src/riscv-fs/riscv-ubuntu-22.04-24.04/make-riscv-kernel.sh diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile b/src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile new file mode 100644 index 000000000..ed2ab9108 --- /dev/null +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile @@ -0,0 +1,44 @@ +# Start from Ubuntu 24.04 base image +FROM ubuntu:24.04 AS stage1 + +# Install necessary packages for kernel and module build +RUN apt update && apt install -y \ + build-essential \ + libncurses-dev \ + bison \ + flex \ + libssl-dev \ + libelf-dev \ + bc \ + wget \ + git \ + kmod \ + gcc-riscv64-linux-gnu + + +RUN sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources +RUN apt update +RUN mkdir /workspace +RUN cd /workspace && apt source linux-image-unsigned-6.8.0-47-generic + +RUN cd /workspace/linux-6.8.0 && \ + make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- defconfig && \ + make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j 32 && \ + make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- INSTALL_MOD_PATH=/workspace/output modules_install + +RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ + cd gem5 && \ + git sparse-checkout add util/m5 && \ + git sparse-checkout add util/gem5_bridge && \ + git sparse-checkout add include && \ + git checkout + +RUN cd gem5/util/gem5_bridge && \ + make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- KMAKEDIR=/workspace/linux-6.8.0 INSTALL_MOD_PATH=/workspace/output build install + +RUN cd /workspace/output/lib/modules/6.8.12 && \ + rm -rf build + +FROM scratch AS export-stage +COPY --from=stage1 /workspace/output/lib/modules . +COPY --from=stage1 /workspace/linux-6.8.0/vmlinux . diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh b/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh index 553531732..6532427f9 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh @@ -14,7 +14,24 @@ mount -t sysfs /sys /sys # Read /proc/cmdline and parse options 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 +# see if this modprode fails or not +# print warning if it fails, gem5-bridge module is not going to work, you will need sudo for running exit events # gem5-bridge exit signifying that kernel is booted # This will cause the simulation to exit. Note that this will # cause qemu to fail. diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/make-riscv-kernel.sh b/src/riscv-fs/riscv-ubuntu-22.04-24.04/make-riscv-kernel.sh new file mode 100755 index 000000000..560728760 --- /dev/null +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/make-riscv-kernel.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Ensure an argument is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + echo "Example: $0 24.04" + echo " $0 22.04" + exit 1 +fi + +# Set variables based on the argument +if [ "$1" == "24.04" ]; then + DOCKERFILE="./24.04-dockerfile/Dockerfile" + OUTPUT="my-riscv-6.8.12-kernel" +elif [ "$1" == "22.04" ]; then + DOCKERFILE="./22.04-dockerfile/Dockerfile" + OUTPUT="my-riscv-5.15.167-kernel" +else + echo "Invalid version: $1" + echo "Supported versions: 24.04, 22.04" + exit 1 +fi + +# Build the Docker image +DOCKER_BUILDKIT=1 docker build --no-cache \ + --file "$DOCKERFILE" \ + --output "$OUTPUT" . + +echo "Build completed for $1: Output directory is $OUTPUT" diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/riscv-ubuntu.pkr.hcl b/src/riscv-fs/riscv-ubuntu-22.04-24.04/riscv-ubuntu.pkr.hcl index 9ffb1907d..6d8456386 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/riscv-ubuntu.pkr.hcl +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/riscv-ubuntu.pkr.hcl @@ -53,7 +53,7 @@ source "qemu" "initialize" { headless = "true" disk_image = "true" boot_command = [ - "", + "", "ubuntu", "ubuntu", "ubuntu", @@ -106,6 +106,10 @@ build { source = "files/serial-getty@.service" } + provisioner "file" { + destination = "/home/gem5" + source = "my-riscv-6.8.12-kernel/6.8.12" + } provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" scripts = ["scripts/post-installation.sh"] diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh b/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh index 3ccf163d0..cff53e57d 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh @@ -20,6 +20,11 @@ systemctl disable boot-efi.mount systemctl mask boot-efi.mount systemctl daemon-reload + +mv /home/gem5/6.8.12 /lib/modules/6.8.12 +depmod --quick -a 6.8.12 +update-initramfs -u -k 6.8.12 + # Giving execute permissions to the after_boot.sh script chmod 4577 /home/gem5/after_boot.sh chmod u+s /home/gem5/after_boot.sh @@ -40,10 +45,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 From dd7cf0a64655a87ea799d8f0253988abc86ed667 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 19 Feb 2025 10:17:34 -0800 Subject: [PATCH 2/6] resources: Update riscv disk image to use hypercall --- src/riscv-fs/riscv-ubuntu-22.04-24.04/files/after_boot.sh | 4 ++-- src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh | 6 +++--- .../riscv-ubuntu-22.04-24.04/scripts/post-installation.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/after_boot.sh b/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/after_boot.sh index c503c0f1f..db281d0c9 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/after_boot.sh +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/after_boot.sh @@ -14,7 +14,7 @@ # gem5-bridge exit signifying that after_boot.sh is running printf "In after_boot.sh...\n" -gem5-bridge exit # TODO: Make this a specialized event. +gem5-bridge hypercall 2 # Read /proc/cmdline and parse options @@ -51,7 +51,7 @@ else /tmp/script printf "Done running script from gem5-bridge, exiting.\n" rm -f /tmp/script - gem5-bridge exit + gem5-bridge hypercall 3 fi fi fi diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh b/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh index 6532427f9..064879e87 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/files/gem5_init.sh @@ -15,8 +15,8 @@ mount -t sysfs /sys /sys cmdline=$(cat /proc/cmdline) no_systemd=false # Load gem5_bridge driver -## Default parameters (ARM64) -gem5_bridge_baseaddr=0x10010000 +## Default parameters (RISCV) +gem5_bridge_baseaddr=0x40000000 # Using address of 1GB as gem5-bridge does not use address mode for riscv gem5_bridge_rangesize=0x10000 ## Try to read overloads from kernel arguments if [[ $cmdline =~ gem5_bridge_baseaddr=([[:alnum:]]+) ]]; then @@ -36,7 +36,7 @@ modprobe gem5_bridge \ # This will cause the simulation to exit. Note that this will # cause qemu to fail. printf "Kernel booted, In gem5 init...\n" -gem5-bridge exit # TODO: Make this a specialized event. +gem5-bridge hypercall 1 if [[ $cmdline == *"no_systemd"* ]]; then no_systemd=true diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh b/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh index cff53e57d..21b61ba87 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh @@ -45,7 +45,7 @@ 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/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge +git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 pushd gem5 # Checkout just the files we need git sparse-checkout add util/m5 From 72ea968af63535bceb9856ccd7d37ade0f28b8cc Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 19 Feb 2025 10:18:36 -0800 Subject: [PATCH 3/6] resources: Add riscv npb disk image --- src/npb-24.04-imgs/arm-npb.pkr.hcl | 5 + src/npb-24.04-imgs/build-riscv.sh | 20 +++ src/npb-24.04-imgs/makefiles/riscv/make.def | 168 ++++++++++++++++++ .../npb-hook-files/addr-version/hooks.c | 61 +++++++ .../npb-hook-files/non-addr-version/hooks.c | 61 +++++++ src/npb-24.04-imgs/riscv-npb.pkr.hcl | 82 +++++++++ src/npb-24.04-imgs/x86-npb.pkr.hcl | 5 + 7 files changed, 402 insertions(+) create mode 100755 src/npb-24.04-imgs/build-riscv.sh create mode 100644 src/npb-24.04-imgs/makefiles/riscv/make.def create mode 100644 src/npb-24.04-imgs/npb-hook-files/addr-version/hooks.c create mode 100644 src/npb-24.04-imgs/npb-hook-files/non-addr-version/hooks.c create mode 100644 src/npb-24.04-imgs/riscv-npb.pkr.hcl diff --git a/src/npb-24.04-imgs/arm-npb.pkr.hcl b/src/npb-24.04-imgs/arm-npb.pkr.hcl index e26db4e7d..3726dbca1 100644 --- a/src/npb-24.04-imgs/arm-npb.pkr.hcl +++ b/src/npb-24.04-imgs/arm-npb.pkr.hcl @@ -72,6 +72,11 @@ build { destination = "/home/gem5/NPB3.4-OMP/config/" } + provisioner "file" { + source = "npb-hook-files/addr-version/hooks.c" + destination = "/home/gem5/NPB3.4-OMP/common/" + } + provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" scripts = ["scripts/post-installation.sh"] diff --git a/src/npb-24.04-imgs/build-riscv.sh b/src/npb-24.04-imgs/build-riscv.sh new file mode 100755 index 000000000..dfb4a48a8 --- /dev/null +++ b/src/npb-24.04-imgs/build-riscv.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright (c) 2024 The Regents of the University of California. +# SPDX-License-Identifier: BSD 3-Clause + +PACKER_VERSION="1.10.0" + +if [ ! -f ./packer ]; then + wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip; + unzip packer_${PACKER_VERSION}_linux_amd64.zip; + rm packer_${PACKER_VERSION}_linux_amd64.zip; +fi + +if [ ! -f riscv-ubuntu-24-04 ]; then +wget https://storage.googleapis.com/dist.gem5.org/dist/develop/images/riscv/ubuntu-24-04/riscv-ubuntu-24-04.gz; +gunzip riscv-ubuntu-24-04.gz; +fi + +./packer init riscv-npb.pkr.hcl +./packer build riscv-npb.pkr.hcl \ No newline at end of file diff --git a/src/npb-24.04-imgs/makefiles/riscv/make.def b/src/npb-24.04-imgs/makefiles/riscv/make.def new file mode 100644 index 000000000..63797f626 --- /dev/null +++ b/src/npb-24.04-imgs/makefiles/riscv/make.def @@ -0,0 +1,168 @@ +#--------------------------------------------------------------------------- +# +# SITE- AND/OR PLATFORM-SPECIFIC DEFINITIONS. +# +#--------------------------------------------------------------------------- + +#--------------------------------------------------------------------------- +# This config is specific for gem5. +#--------------------------------------------------------------------------- + + +#--------------------------------------------------------------------------- +# Items in this file will need to be changed for each platform. +#--------------------------------------------------------------------------- + +#--------------------------------------------------------------------------- +# Parallel Fortran: +# +# For CG, EP, FT, MG, LU, SP, BT and UA, which are in Fortran, the following +# must be defined: +# +# FC - Fortran compiler +# FFLAGS - Fortran compilation arguments +# F_INC - any -I arguments required for compiling Fortran +# FLINK - Fortran linker +# FLINKFLAGS - Fortran linker arguments +# F_LIB - any -L and -l arguments required for linking Fortran +# +# compilations are done with $(FC) $(F_INC) $(FFLAGS) or +# $(FC) $(FFLAGS) +# linking is done with $(FLINK) $(F_LIB) $(FLINKFLAGS) +#--------------------------------------------------------------------------- + +#--------------------------------------------------------------------------- +# This is the fortran compiler used for Fortran programs +#--------------------------------------------------------------------------- +FC = gfortran +# This links fortran programs; usually the same as ${FC} +FLINK = $(FC) + +#--------------------------------------------------------------------------- +# These macros are passed to the linker +#--------------------------------------------------------------------------- +F_LIB = -lm5 -lm + +#--------------------------------------------------------------------------- +# These macros are passed to the compiler +#--------------------------------------------------------------------------- +F_INC = + +#--------------------------------------------------------------------------- +# Global *compile time* flags for Fortran programs +#--------------------------------------------------------------------------- +FFLAGS = -O3 -fopenmp -cpp -mcmodel=medany -fcommon -no-pie -DM5_ANNOTATION + +#--------------------------------------------------------------------------- +# Global *link time* flags. Flags for increasing maximum executable +# size usually go here. +#--------------------------------------------------------------------------- +# Using no-pie here as m5 is compiled with the no-pie flash and cant no be build +# as a position independent executable. +FLINKFLAGS = -O3 -fopenmp -no-pie + + +#--------------------------------------------------------------------------- +# Parallel C: +# +# For IS and DC, which are in C, the following must be defined: +# +# CC - C compiler +# CFLAGS - C compilation arguments +# C_INC - any -I arguments required for compiling C +# CLINK - C linker +# CLINKFLAGS - C linker flags +# C_LIB - any -L and -l arguments required for linking C +# +# compilations are done with $(CC) $(C_INC) $(CFLAGS) or +# $(CC) $(CFLAGS) +# linking is done with $(CLINK) $(C_LIB) $(CLINKFLAGS) +#--------------------------------------------------------------------------- + +#--------------------------------------------------------------------------- +# This is the C compiler used for C programs +#--------------------------------------------------------------------------- +CC = gcc +# This links C programs; usually the same as ${CC} +CLINK = $(CC) + +#--------------------------------------------------------------------------- +# These macros are passed to the linker +#--------------------------------------------------------------------------- +C_LIB = -lm5 -lm + +#--------------------------------------------------------------------------- +# These macros are passed to the compiler +#--------------------------------------------------------------------------- +C_INC = + +#--------------------------------------------------------------------------- +# Global *compile time* flags for C programs +# DC inspects the following flags (preceded by "-D"): +# +# IN_CORE - computes all views and checksums in main memory (if there is +# enough memory) +# +# VIEW_FILE_OUTPUT - forces DC to write the generated views to disk +# +# OPTIMIZATION - turns on some nonstandard DC optimizations +# +# _FILE_OFFSET_BITS=64 +# _LARGEFILE64_SOURCE - are standard compiler flags which allow to work with +# files larger than 2GB. +#--------------------------------------------------------------------------- +CFLAGS = -O3 -fopenmp -mcmodel=medany -fcommon -no-pie -DM5_ANNOTATION + +#--------------------------------------------------------------------------- +# Global *link time* flags. Flags for increasing maximum executable +# size usually go here. +#--------------------------------------------------------------------------- +# Using no-pie here as m5 is compiled with the no-pie flash and cant no be build +# as a position independent executable. +CLINKFLAGS = -O3 -fopenmp -no-pie + + +#--------------------------------------------------------------------------- +# Utilities C: +# +# This is the C compiler used to compile C utilities. Flags required by +# this compiler go here also; typically there are few flags required; hence +# there are no separate macros provided for such flags. +#--------------------------------------------------------------------------- +UCC = gcc + + +#--------------------------------------------------------------------------- +# Destination of executables, relative to subdirs of the main directory. . +#--------------------------------------------------------------------------- +BINDIR = ../bin + + +#--------------------------------------------------------------------------- +# The variable RAND controls which random number generator +# is used. It is described in detail in README.install. +# Use "randi8" unless there is a reason to use another one. +# Other allowed values are "randi8_safe", "randdp" and "randdpvec" +#--------------------------------------------------------------------------- +RAND = randi8 +# The following is highly reliable but may be slow: +# RAND = randdp + + +#--------------------------------------------------------------------------- +# The variable WTIME is the name of the wtime source code module in the +# common directory. +# For most machines, use wtime.c +# For SGI power challenge: use wtime_sgi64.c +#--------------------------------------------------------------------------- +WTIME = wtime.c + + +#--------------------------------------------------------------------------- +# Enable if either Cray (not Cray-X1) or IBM: +# (no such flag for most machines: see common/wtime.h) +# This is used by the C compiler to pass the machine name to common/wtime.h, +# where the C/Fortran binding interface format is determined +#--------------------------------------------------------------------------- +# MACHINE = -DCRAY +# MACHINE = -DIBM diff --git a/src/npb-24.04-imgs/npb-hook-files/addr-version/hooks.c b/src/npb-24.04-imgs/npb-hook-files/addr-version/hooks.c new file mode 100644 index 000000000..c070fd21d --- /dev/null +++ b/src/npb-24.04-imgs/npb-hook-files/addr-version/hooks.c @@ -0,0 +1,61 @@ +/* +Copyright (c) 2024 The Regents of the University of California +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer; +redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution; +neither the name of the copyright holders nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#include +#include + + +void init_() __attribute__((constructor)); +void map_m5_mem(); + +void init_() { + + //__attribute__ makes this function get called before main() + // need to mmap /dev/mem + printf(" --------------------- M5 INIT --------------------- \n"); + map_m5_mem(); +} + +void m5_exit_interface_() +{ + printf(" --------------------- M5 EXIT --------------------- \n"); + // this function calls m5_exit + m5_exit_addr(0); +} + +void m5_work_begin_interface_() +{ + + printf(" -------------------- ROI BEGIN -------------------- \n"); + m5_hypercall_addr(4); +} + +void m5_work_end_interface_() +{ + m5_hypercall_addr(5); + printf(" -------------------- ROI END -------------------- \n"); +} diff --git a/src/npb-24.04-imgs/npb-hook-files/non-addr-version/hooks.c b/src/npb-24.04-imgs/npb-hook-files/non-addr-version/hooks.c new file mode 100644 index 000000000..167b538f8 --- /dev/null +++ b/src/npb-24.04-imgs/npb-hook-files/non-addr-version/hooks.c @@ -0,0 +1,61 @@ +/* +Copyright (c) 2024 The Regents of the University of California +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer; +redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution; +neither the name of the copyright holders nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#include +#include + + +void init_() __attribute__((constructor)); +void map_m5_mem(); + +void init_() { + + //__attribute__ makes this function get called before main() + // need to mmap /dev/mem + printf(" --------------------- M5 INIT --------------------- \n"); + map_m5_mem(); +} + +void m5_exit_interface_() +{ + printf(" --------------------- M5 EXIT --------------------- \n"); + // this function calls m5_exit + m5_exit(0); +} + +void m5_work_begin_interface_() +{ + + printf(" -------------------- ROI BEGIN -------------------- \n"); + m5_hypercall(4); +} + +void m5_work_end_interface_() +{ + m5_hypercall(5); + printf(" -------------------- ROI END -------------------- \n"); +} diff --git a/src/npb-24.04-imgs/riscv-npb.pkr.hcl b/src/npb-24.04-imgs/riscv-npb.pkr.hcl new file mode 100644 index 000000000..173ec82f4 --- /dev/null +++ b/src/npb-24.04-imgs/riscv-npb.pkr.hcl @@ -0,0 +1,82 @@ +packer { + required_plugins { + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1" + } + } +} + +variable "image_name" { + type = string + default = "riscv-ubuntu" +} + +variable "ssh_password" { + type = string + default = "12345" +} + +variable "ssh_username" { + type = string + default = "gem5" +} + +source "qemu" "initialize" { + cpus = "4" + disk_size = "5000" + format = "raw" + headless = "true" + disk_image = "true" + boot_command = ["", + "gem5", + "12345", + "sudo mount -o remount,rw /", // remounting system as read-write as qemu does not like that we have m5 exits in the boot process so it mounts system as read ony. + "12345", + "sudo mv /etc/netplan/50-cloud-init.yaml.bak /etc/netplan/50-cloud-init.yaml", + "sudo netplan apply", + "" + ] + iso_checksum = "sha256:ddf1ebb56454ef37e88d6de8aefdef7180fc9a2328a3bf8cff02f7a043e7127b" + iso_urls = ["/home/harshilp/gem5-resources-worktrees/make-riscv-kernel/src/riscv-fs/riscv-ubuntu-22.04-24.04/disk-image-24.04/riscv-ubuntu"] + memory = "8192" + output_directory = "riscv-disk-image-ubuntu-24-04" + qemu_binary = "/usr/bin/qemu-system-riscv64" + + qemuargs = [ ["-bios", "/usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf"], + ["-machine", "virt"], + ["-kernel","/usr/lib/u-boot/qemu-riscv64_smode/uboot.elf"], + ["-device", "virtio-vga"], + ["-device", "qemu-xhci"], + ["-device", "usb-kbd"] + ] + shutdown_command = "echo '${var.ssh_password}'|sudo -S shutdown -P now" + ssh_password = "${var.ssh_password}" + ssh_username = "${var.ssh_username}" + ssh_wait_timeout = "60m" + vm_name = "${var.image_name}" + ssh_handshake_attempts = "1000" +} + +build { + sources = ["source.qemu.initialize"] + provisioner "file" { + source = "npb-with-roi/NPB/NPB3.4-OMP" + destination = "/home/gem5/" + } + + provisioner "file" { + source = "makefiles/riscv/make.def" + destination = "/home/gem5/NPB3.4-OMP/config/" + } + + provisioner "file" { + source = "npb-hook-files/non-addr-version/hooks.c" + destination = "/home/gem5/NPB3.4-OMP/common/" + } + + provisioner "shell" { + execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" + scripts = ["scripts/post-installation.sh"] + } +} \ No newline at end of file diff --git a/src/npb-24.04-imgs/x86-npb.pkr.hcl b/src/npb-24.04-imgs/x86-npb.pkr.hcl index e14670671..bf01d2f4e 100644 --- a/src/npb-24.04-imgs/x86-npb.pkr.hcl +++ b/src/npb-24.04-imgs/x86-npb.pkr.hcl @@ -63,6 +63,11 @@ build { destination = "/home/gem5/NPB3.4-OMP/config/" } + provisioner "file" { + source = "npb-hook-files/addr-version/hooks.c" + destination = "/home/gem5/NPB3.4-OMP/common/" + } + provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" scripts = ["scripts/post-installation.sh"] From c21bcea4179ac00cc5eec68800810afca62d2c09 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Thu, 20 Nov 2025 13:59:21 -0800 Subject: [PATCH 4/6] resources: updated documentation and base disk image --- src/npb-24.04-imgs/build-riscv.sh | 6 +- .../NPB/NPB3.4-OMP/common/hooks.c | 61 ------------------- src/npb-24.04-imgs/riscv-npb.pkr.hcl | 6 +- .../riscv-ubuntu-22.04-24.04/BUILING.md | 7 ++- 4 files changed, 11 insertions(+), 69 deletions(-) delete mode 100644 src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c diff --git a/src/npb-24.04-imgs/build-riscv.sh b/src/npb-24.04-imgs/build-riscv.sh index dfb4a48a8..33667c2c3 100755 --- a/src/npb-24.04-imgs/build-riscv.sh +++ b/src/npb-24.04-imgs/build-riscv.sh @@ -11,9 +11,9 @@ if [ ! -f ./packer ]; then rm packer_${PACKER_VERSION}_linux_amd64.zip; fi -if [ ! -f riscv-ubuntu-24-04 ]; then -wget https://storage.googleapis.com/dist.gem5.org/dist/develop/images/riscv/ubuntu-24-04/riscv-ubuntu-24-04.gz; -gunzip riscv-ubuntu-24-04.gz; +if [ ! -f riscv-ubuntu-24.04-20250515 ]; then +wget https://dist.gem5.org/dist/develop/images/riscv/ubuntu-24-04/riscv-ubuntu-24.04-20250515.gz +gunzip riscv-ubuntu-24.04-20250515.gz; fi ./packer init riscv-npb.pkr.hcl diff --git a/src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c b/src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c deleted file mode 100644 index c070fd21d..000000000 --- a/src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright (c) 2024 The Regents of the University of California -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer; -redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution; -neither the name of the copyright holders nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#include -#include - - -void init_() __attribute__((constructor)); -void map_m5_mem(); - -void init_() { - - //__attribute__ makes this function get called before main() - // need to mmap /dev/mem - printf(" --------------------- M5 INIT --------------------- \n"); - map_m5_mem(); -} - -void m5_exit_interface_() -{ - printf(" --------------------- M5 EXIT --------------------- \n"); - // this function calls m5_exit - m5_exit_addr(0); -} - -void m5_work_begin_interface_() -{ - - printf(" -------------------- ROI BEGIN -------------------- \n"); - m5_hypercall_addr(4); -} - -void m5_work_end_interface_() -{ - m5_hypercall_addr(5); - printf(" -------------------- ROI END -------------------- \n"); -} diff --git a/src/npb-24.04-imgs/riscv-npb.pkr.hcl b/src/npb-24.04-imgs/riscv-npb.pkr.hcl index 173ec82f4..02116dc9c 100644 --- a/src/npb-24.04-imgs/riscv-npb.pkr.hcl +++ b/src/npb-24.04-imgs/riscv-npb.pkr.hcl @@ -9,7 +9,7 @@ packer { variable "image_name" { type = string - default = "riscv-ubuntu" + default = "riscv-ubuntu-npb-24.04" } variable "ssh_password" { @@ -38,7 +38,7 @@ source "qemu" "initialize" { "" ] iso_checksum = "sha256:ddf1ebb56454ef37e88d6de8aefdef7180fc9a2328a3bf8cff02f7a043e7127b" - iso_urls = ["/home/harshilp/gem5-resources-worktrees/make-riscv-kernel/src/riscv-fs/riscv-ubuntu-22.04-24.04/disk-image-24.04/riscv-ubuntu"] + iso_urls = ["./riscv-ubuntu-24.04-20250515"] memory = "8192" output_directory = "riscv-disk-image-ubuntu-24-04" qemu_binary = "/usr/bin/qemu-system-riscv64" @@ -64,7 +64,7 @@ build { source = "npb-with-roi/NPB/NPB3.4-OMP" destination = "/home/gem5/" } - + provisioner "file" { source = "makefiles/riscv/make.def" destination = "/home/gem5/NPB3.4-OMP/config/" diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/BUILING.md b/src/riscv-fs/riscv-ubuntu-22.04-24.04/BUILING.md index e0b7e8ef1..479e9ca9c 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/BUILING.md +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/BUILING.md @@ -15,7 +15,7 @@ This document provides instructions to create the "riscv-ubuntu" image. This ima ## Disk Image -Run `./build.sh` in the `riscv-ubuntu-22.04` directory to build the disk image. +Run `./build.sh` in the `riscv-ubuntu-22.04-24.04` directory to build the disk image. This will download the packer binary, initialize packer, and build the disk image. Note: This can take a while to run. @@ -23,7 +23,7 @@ You will see `qemu.initialize: Waiting for SSH to become available...` while the You can watch the installation with a VNC viewer. See [Troubleshooting](#troubleshooting) for more information. -## Changes from the base Ubuntu 22.04 image +## Changes from the base Ubuntu 22.04 and 24.04 image - The default user is `gem5` with password `12345`. - The `m5` utility is renamed to `gem5-bridge`. @@ -89,6 +89,9 @@ To avoid its infinite execution, we incorporated a conditional check in `post-in To see what `packer` is doing, you can use the environment variable `PACKER_LOG=INFO` when running `./build.sh`. +The login process is automated by packer. +If the build process is hanging during login, check if the "wait" command in the boot_command section is actually waiting for the image to boot. + Packer seems to have a bug that aborts the VM build after 2-5 minutes regardless of the ssh_timeout setting. As a workaround, set ssh_handshake_attempts to a high value. Thus, I have `ssh_handshake_attempts = 1000`. From 91eb0566d0451d97f95f658c8d46fca5560c8f96 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 1 Dec 2025 12:27:58 -0800 Subject: [PATCH 5/6] resources: Update m5ops installation to point to stable gem5 --- .../riscv-ubuntu-22.04-24.04/scripts/post-installation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh b/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh index 21b61ba87..48209ea8c 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/scripts/post-installation.sh @@ -45,7 +45,7 @@ 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=release-staging-v24-1-1-0 +git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=stable pushd gem5 # Checkout just the files we need git sparse-checkout add util/m5 From cfb8735e979b5f5ce17c00ca08c6379bd66b0c92 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 2 Dec 2025 11:00:44 -0800 Subject: [PATCH 6/6] resources: Update m5ops installation to point to stable in dockerfile --- .../riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile b/src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile index ed2ab9108..f050d2d77 100644 --- a/src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile +++ b/src/riscv-fs/riscv-ubuntu-22.04-24.04/24.04-dockerfile/Dockerfile @@ -18,7 +18,7 @@ RUN apt update && apt install -y \ RUN sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources RUN apt update -RUN mkdir /workspace +RUN mkdir /workspace RUN cd /workspace && apt source linux-image-unsigned-6.8.0-47-generic RUN cd /workspace/linux-6.8.0 && \ @@ -26,7 +26,7 @@ RUN cd /workspace/linux-6.8.0 && \ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j 32 && \ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- INSTALL_MOD_PATH=/workspace/output modules_install -RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ +RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=stable && \ cd gem5 && \ git sparse-checkout add util/m5 && \ git sparse-checkout add util/gem5_bridge && \