Skip to content

Commit

Permalink
New configuration script for component models
Browse files Browse the repository at this point in the history
Simple configuration script that leverages the gem5
component models.
- Upgrade to gem5 v24
- New gem5init which works also for arm

Signed-off-by: David Schall <[email protected]>
  • Loading branch information
dhschall committed Jul 5, 2024
1 parent a03223a commit ad3f33d
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 80 deletions.
62 changes: 33 additions & 29 deletions configs/disk-image-configs/gem5init
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/bin/bash -


if [ $(uname -i) == "aarch64" ];
then
echo "On Arm machine"
M5_ADDR="--addr=0x10010000"
else
echo "On x86 machine"
M5_ADDR=0xffff0000
M5_ADDR=""
fi


function gem5_run() {
# ====
# gem5 init service
Expand All @@ -8,19 +20,11 @@ function gem5_run() {
# Try to read in a run script from the host system.
# For gem5 use the special magic instruction `m5 readfile`
#
/sbin/m5 readfile > /tmp/script
chmod 755 /tmp/script
if [ -s /tmp/script ]
then
# If there is a script, execute the script and then exit the simulation
su root -c '/tmp/script' # gives script full privileges as root user in multi-user mode
sync
sleep 10
/sbin/m5 exit
else
echo "No script found"
fi
echo "Gem5 init done"
/tmp/script || true
echo "Done running script, exiting."
rm -f /tmp/script
/sbin/m5 $M5_ADDR exit
}


Expand All @@ -36,35 +40,35 @@ function qemu_run() {
#

curl "http://10.0.2.2:3003/run.sh" -f -o /tmp/script
chmod 755 /tmp/script

if [ 0 -eq $? ];
then
echo "Found file server in qemu."
echo "Run script found... run it."
chmod 755 /tmp/script

# If there is a script, execute the script and then shutdown the machine
su root -c '/tmp/script' # gives script full privileges as root user in multi-user mode
sync
sleep 10
/tmp/script || true
echo "Done running script, exiting."
rm -f /tmp/script
else
echo "No script found"
echo "No file server found"
fi
}


##
## Check if we are in gem5 or qemu
##
CPU=`cat /proc/cpuinfo | grep vendor_id | head -n 1 | cut -d ' ' -f2-`
echo "Got CPU type: $CPU"

if [ "$CPU" == "M5 Simulator" ];
then
printf "Starting gem5 init... trying to read run script file via readfile.\n"

if ! m5 $M5_ADDR readfile > /tmp/script; then

printf "Failed to run m5 readfile. Try QEMU read.\n"
rm -f /tmp/script

# Read was not successful
# Try to read script from file server
qemu_run
else
echo "In gem5. Try loading script"
gem5_run
else
echo "Not in gem5. Try to load script from http server"
qemu_run
fi
exit 0

48 changes: 48 additions & 0 deletions docs/simulation/simple_component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
layout: default
title: Simple Simulation with gem5 Component Library
parent: Simulation
nav_order: 1
---

# Simulation Methodology
{: .no_toc }

<details open markdown="block">
<summary>
Table of contents
</summary>
{: .text-delta }
1. TOC
{:toc}
</details>

<!-- ## Table of contents
{: .no_toc .text-delta }
1. TOC
{:toc} -->


---

Gem5 offers a wide range of prebuild configurations, aka. standard library, for cpus, boards, caches, etc. To simplify the configuration process we provide a configuration script that is mostly constructed out the component models provided by gem5. This script is called `vswarm_simple.py` and will be copied into your working directory.

After installing the functions on the disk you can perform the *setup* step with the following command:

```bash
<gem5_root>/build/<ALL/X86>/gem5.opt vswarm_simple.py --kernel kernel --disk disk.img --mode setup --atomic-warming=50 --num-invocations=20
```

This will boot the kernel, function, invoke the function for 50 times and then create a checkpoint. The simulation will exit or can be killed otherwise

Once the checkpoint is created the simulation can be performed with:

```bash
<gem5_root>/build/<ALL/X86>/gem5.opt vswarm_simple.py --kernel kernel --disk disk.img --mode evaluation --atomic-warming=50 --num-invocations=20
```

The script was tested with ATOMIC,TIMING and O3 core which can be configured commenting the corresponding lines in the script
```
eval_core = CPUTypes.<TIMING/ATOMIC/O3>
```
6 changes: 3 additions & 3 deletions gem5utils/systems/simple/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class SimpleSystem(System):

def __init__(self, kernel, disk, num_cpus=2, CPUModel=AtomicSimpleCPU, kvm=True):
def __init__(self, kernel, disk, num_cpus=2, CPUModel=X86AtomicSimpleCPU, kvm=True):
super(SimpleSystem, self).__init__()

self._host_parallel = True if kvm and num_cpus > 1 else False
Expand Down Expand Up @@ -115,15 +115,15 @@ def __init__(self, kernel, disk, num_cpus=2, CPUModel=AtomicSimpleCPU, kvm=True)
def getHostParallel(self):
return self._host_parallel

def createCPU(self, num_cpus=2, CPUModel=AtomicSimpleCPU):
def createCPU(self, num_cpus=2, CPUModel=X86AtomicSimpleCPU):
""" Create the CPUs for the system """

# Beside the CPU we use for simulation we will use
# KVM booting linux and spinning up the function.
# Note KVM needs a VM and atomic_noncaching
print("Create CPU: ", CPUModel)
self.cpu = [CPUModel(cpu_id = i) for i in range(num_cpus)]
self.atomic_cpu = [AtomicSimpleCPU(
self.atomic_cpu = [X86AtomicSimpleCPU(
cpu_id = i,
switched_out=True) for i in range(num_cpus)]

Expand Down
9 changes: 3 additions & 6 deletions gem5utils/systems/skylake/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,13 @@ class LTAGE_BP(LTAGE_TAGE):
logUResetPeriod = 19

class BranchPred(LTAGE):
BTBEntries = 512
BTBTagSize = 19
RASSize = 32
indirectBranchPred = IndirectPred() # use NULL to disable

tage = LTAGE_BP()

depth = 3
width = 4
class SklVerbatimCPU(DerivO3CPU):
class SklVerbatimCPU(X86O3CPU):
""" Uncalibrated: Configured based on micro-architecture documentation """

branchPred = BranchPred()
Expand Down Expand Up @@ -222,7 +219,7 @@ class SklVerbatimCPU(DerivO3CPU):

depth = 3
width = 4
class SklTunedCPU(DerivO3CPU):
class SklTunedCPU(X86O3CPU):
""" Calibrated Skylake: configured to match the performance of hardware """

branchPred = BranchPred()
Expand Down Expand Up @@ -269,7 +266,7 @@ class SklTunedCPU(DerivO3CPU):

depth = 3
width = 32
class UnconstrainedCPU(DerivO3CPU):
class UnconstrainedCPU(X86O3CPU):
""" Configuration with maximum pipeline widths and mininum delays """

branchPred = BranchPred()
Expand Down
8 changes: 4 additions & 4 deletions setup/disk.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ CPUS := 4
UBUNTU_VERSION ?= focal

ifeq ($(UBUNTU_VERSION), focal)
CLOUD_IMAGE_FILE := ubuntu-20.04.5-live-server-amd64.iso
CLOUD_IMAGE_FILE := ubuntu-20.04.6-live-server-amd64.iso
CLOUD_IMAGE_BASE_URL := https://releases.ubuntu.com/20.04/
CLOUD_IMAGE_HASH := 5035be37a7e9abbdc09f0d257f3e33416c1a0fb322ba860d42d74aa75c3468d4
CLOUD_IMAGE_HASH := b8f31413336b9393ad5d8ef0282717b2ab19f007df2e9ed5196c13d8f9153c8b
KERNEL_CUSTOM ?= $(RESOURCES)/vmlinux-focal-amd64
else ifeq ($(UBUNTU_VERSION), jammy)
CLOUD_IMAGE_FILE := ubuntu-22.04.1-live-server-amd64.iso
CLOUD_IMAGE_FILE := ubuntu-22.04.4-live-server-amd64.iso
CLOUD_IMAGE_BASE_URL := https://releases.ubuntu.com/22.04/
CLOUD_IMAGE_HASH := 10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb
CLOUD_IMAGE_HASH := 45f873de9f8cb637345d6e66a583762730bbea30277ef7b32c9c3bd6700a32b2
KERNEL_CUSTOM ?= $(RESOURCES)/vmlinux-jammy-amd64
else
@echo "Unsupported ubuntu version $(UBUNTU_VERSION)"
Expand Down
4 changes: 2 additions & 2 deletions setup/disk_arm.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ ifeq ($(UBUNTU_VERSION), focal)
CLOUD_IMAGE_HASH := e42d6373dd39173094af5c26cbf2497770426f42049f8b9ea3e60ce35bebdedf
KERNEL_CUSTOM ?= $(RESOURCES)/vmlinux-focal-arm64
else ifeq ($(UBUNTU_VERSION), jammy)
CLOUD_IMAGE_FILE := ubuntu-22.04.1-live-server-arm64.iso
CLOUD_IMAGE_FILE := ubuntu-22.04.4-live-server-arm64.iso
CLOUD_IMAGE_BASE_URL := https://cdimage.ubuntu.com/releases/22.04/release/
CLOUD_IMAGE_HASH := bc5a8015651c6f8699ab262d333375d3930b824f03d14ae51e551d89d9bb571c
CLOUD_IMAGE_HASH := 74b8a9f71288ae0ac79075c2793a0284ef9b9729a3dcf41b693d95d724622b65
KERNEL_CUSTOM ?= $(RESOURCES)/vmlinux-jammy-arm64
else
@echo "Unsupported ubuntu version $(UBUNTU_VERSION)"
Expand Down
6 changes: 3 additions & 3 deletions setup/gem5.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ ROOT := $(abspath $(dir $(mkfile_path))/../)

## User specific inputs
RESOURCES ?=$(ROOT)/resources/
ARCH := X86
VERSION := v22.0.0.1
ARCH := ALL
VERSION := v24.0.0.0

GEM5_DIR ?= $(RESOURCES)/gem5/
GEM5 := $(GEM5_DIR)/build/$(ARCH)/gem5.opt
Expand All @@ -53,7 +53,7 @@ dep_install:

## Clone repo --
$(GEM5_DIR):
git clone https://github.com/ease-lab/gem5.git $@
git clone https://github.com/gem5/gem5.git $@
cd $@; git checkout $(VERSION)


Expand Down
3 changes: 2 additions & 1 deletion simulation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ SERVE := $(WORKING_DIR)/server.pid
FUNCTIONS_YAML := $(WORKING_DIR)/functions.yaml
FUNCTIONS_LIST := $(WORKING_DIR)/functions.list
GEM5_CONFIG := $(WORKING_DIR)/run_sim.py
GEM5_SIMPLE_CONFIG := $(WORKING_DIR)/vswarm_simple.py
SETUP_ALL_SCRIPT := $(WORKING_DIR)/setup_all_functions.sh
SETUP_FN_SCRIPT := $(WORKING_DIR)/setup_function.sh
SIM_ALL_SCRIPT := $(WORKING_DIR)/sim_all_functions.sh
SIM_FN_SCRIPT := $(WORKING_DIR)/sim_function.sh

templates: $(SETUP_ALL_SCRIPT) $(SETUP_FN_SCRIPT) $(SIM_ALL_SCRIPT) $(SIM_FN_SCRIPT) $(GEM5_CONFIG) $(FUNCTIONS_YAML) $(FUNCTIONS_LIST)
templates: $(SETUP_ALL_SCRIPT) $(SETUP_FN_SCRIPT) $(SIM_ALL_SCRIPT) $(SIM_FN_SCRIPT) $(GEM5_CONFIG) $(GEM5_SIMPLE_CONFIG) $(FUNCTIONS_YAML) $(FUNCTIONS_LIST)


$(WORKING_DIR)/functions.%: $(ROOT)/simulation/functions/functions.%
Expand Down
Loading

0 comments on commit ad3f33d

Please sign in to comment.