diff --git a/src/npb-24.04-imgs/README.md b/src/npb-24.04-imgs/README.md index 21579a78b..9c1d83df4 100644 --- a/src/npb-24.04-imgs/README.md +++ b/src/npb-24.04-imgs/README.md @@ -47,6 +47,50 @@ dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc **Note**: The `build-arm.sh` will make this file for you. +### RISC-V Specific Notes + +If you are building a RISC-V disk image on an **Ubuntu 24.04** host, you need to install `pipewire` to enable the QEMU plugin to boot the disk: + +```bash +sudo apt-get install pipewire pipewire-audio-client-libraries +``` + +If you prefer to use a Docker container, you can use the preconfigured environment provided here: + + +This container is set up to build the disk image. You can create the disk image inside the container and then copy it to the host system using `docker cp`. + +For example: + +```bash +docker run --rm -it \ + -v $(pwd):/workspace \ + ghcr.io/gem5/qemu-riscv-env:latest \ + bash -c "/workspace/build-disk.sh" +``` + +An example bash script for `build-disk.sh` could look like: + +```sh +#!/bin/bash +apt-get install -y xz-utils # Example in case you want to install extra packages +# Clone the repository +git clone https://github.com/gem5/gem5-resources.git +cd /gem5-resources/src/npb-24.04-imgs +# Run the build process +PACKER_LOG=INFO ./build-riscv.sh +``` + +If you need to copy the disk image out of the container, you can use the following command. + +``` bash +docker cp :/workspace/output/disk.img ./output/disk.img +``` + +Replace `` with the actual container ID. + +### Build commands + Assuming that you are in the `src/npb-24.04-imgs/` directory, run ```sh @@ -59,7 +103,12 @@ to build the x86 disk image or ./build-arm.sh ``` -to run the arm disk image. +to build the arm disk image or + +```sh +./build-riscv.sh +``` + After this process succeeds, the disk image can be found on the `npb-24.04-imgs/disk-image-x86-npb/disk-image-x86-npb` or `npb-24.04-imgs/disk-image-arm-npb/disk-image-arm-npb` repectively. This npb image uses the prebuilt ubuntu 24.04 image as a base image. The npb image also throws the same exit events as the base image. diff --git a/src/npb-24.04-imgs/arm-npb.pkr.hcl b/src/npb-24.04-imgs/arm-npb.pkr.hcl index 4c3463633..ebb06931f 100644 --- a/src/npb-24.04-imgs/arm-npb.pkr.hcl +++ b/src/npb-24.04-imgs/arm-npb.pkr.hcl @@ -67,6 +67,11 @@ build { destination = "/home/gem5/" } + 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-with-roi/NPB/NPB3.4-OMP/common/hooks.c b/src/npb-24.04-imgs/npb-hook-files/addr-version/hooks.c similarity index 100% rename from src/npb-24.04-imgs/npb-with-roi/NPB/NPB3.4-OMP/common/hooks.c rename to src/npb-24.04-imgs/npb-hook-files/addr-version/hooks.c 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..3f4f13232 --- /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_work_begin(0,0); +} + +void m5_work_end_interface_() +{ + m5_work_end(0,0); + 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..04f580e1d --- /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:c72784107683f1b1d703fa4fef6d3f52ecf95c9c930a77931f8ab69465869fc1" + iso_urls = ["./riscv-ubuntu-24-04"] + 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 c14e3404d..ed5d4d8e4 100644 --- a/src/npb-24.04-imgs/x86-npb.pkr.hcl +++ b/src/npb-24.04-imgs/x86-npb.pkr.hcl @@ -57,6 +57,12 @@ build { source = "npb-with-roi/NPB/NPB3.4-OMP" destination = "/home/gem5/" } + + 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"]