Skip to content

Commit 3c7c164

Browse files
committed
Merge remote-tracking branch 'origin/dramsim'
2 parents f236cfa + 8258bed commit 3c7c164

25 files changed

+824
-116
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/DRAMSim2"]
2+
path = src/DRAMSim2
3+
url = https://github.com/umd-memsys/DRAMSim2.git

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Version 2.0a
2+
- Added [DRAMSim2](https://github.com/umd-memsys/DRAMSim2) support
3+
- Flush all the CPU caches and DRAM models for every new simulation run
4+
- Fixed Issue #8: useless cleaning of local variables
5+
16
# Version 1.1a
27
- Added 16550A UART support (thanks to Marc Gauthier)
38
- Reworked the dram latency parameters to match the Sifive HiFive U540 Board

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/bucaps/marss-riscv/blob/master/src/MIT-LICENSE.txt) [![GitHub issues](https://img.shields.io/github/issues/Naereen/StrapDown.js.svg)](https://github.com/bucaps/marss-riscv/issues/)
44

5-
MARSS-RISCV (Micro-ARchitectural System Simulator - RISCV) is a open source, **cycle-accurate single core full-system (Linux) micro-architectural simulator** for the [RISC-V](https://riscv.org/specifications/) ISA built upon [TinyEMU emulator (https://bellard.org/tinyemu)](https://bellard.org/tinyemu) by Fabrice Bellard and uses its code for all the device emulation and configuration. It consists of detailed cycle accurate models of a modern RISC-V In-order and Out-of-order processor with branch prediction unit and a complete memory hierarchy. It is currently being developed and maintained by [CAPS](https://github.com/bucaps/) (Computer Architecture and Power Aware Systems Research Group) at the State University of New York at Binghamton. Being a true full system simulator, MARSS-RISCV can simulate all of the system in a cycle accurate fashion including OS code, libraries, interrupt handlers etc.
5+
MARSS-RISCV (Micro-ARchitectural System Simulator - RISCV) is a open source, **cycle-accurate single core full-system (Linux) micro-architectural simulator** for the [RISC-V](https://riscv.org/specifications/) ISA built upon [TinyEMU emulator (https://bellard.org/tinyemu)](https://bellard.org/tinyemu) by Fabrice Bellard and uses its code for all the device emulation and configuration. It consists of detailed cycle accurate models of a modern RISC-V In-order and Out-of-order processor with branch prediction unit and a complete memory hierarchy including TLBs, caches and DRAM. It comes integrated with [DRAMSim2](https://github.com/umd-memsys/DRAMSim2), a cycle accurate memory system simulator. It is currently being developed and maintained by [CAPS](https://github.com/bucaps/) (Computer Architecture and Power Aware Systems Research Group) at the State University of New York at Binghamton. Being a true full system simulator, MARSS-RISCV can simulate all of the system in a cycle accurate fashion including OS code, libraries, interrupt handlers etc.
66

7-
Currently, our simulator is in alpha status as we are validating the cycle accuracy using various development boards. The simulated in-order core is tested and operational, however, the simulated out-of-order core is in microarchitectural testing phase.
7+
Currently, our simulator is in alpha status as we are validating the cycle accuracy using various development boards. The simulated in-order core is tested and operational, however, the simulated out-of-order core is in micro-architectural testing phase.
88

99
## Table of contents
1010
- [Features](#features)
@@ -23,7 +23,7 @@ Currently, our simulator is in alpha status as we are validating the cycle accur
2323
- Fully configurable, cycle-accurate, in-order and out-of-order single-core RISC-V CPU
2424
- Multiple execution units with configurable latencies (execution units can be configured to be pipelined)
2525
- 2-level cache hierarchy with various allocation and miss handling policies
26-
- A simple DIMM based DRAM model that simulates row-buffer (open-page) hits
26+
- 2 DRAM memory models: Simple DIMM based basic DRAM model that simulates row-buffer (open-page) hits and [DRAMSim2](https://github.com/umd-memsys/DRAMSim2)
2727
- Bi-modal and 2-level adaptive (Gshare, Gselect, GAg, GAp, PAg, PAp) branch prediction support
2828
- Supports `RV32GC` and `RV64GC` (user level ISA version `2.2`, privileged architecture version `1.10`)
2929
- VirtIO console, network, block device, input and 9P filesystem
@@ -55,12 +55,12 @@ First, clone the simulator repository:
5555

5656
```console
5757
$ git clone https://github.com/bucaps/marss-riscv
58-
5958
```
6059
Then, `cd` into the simulator source directory:
6160

6261
```console
6362
$ cd marss-riscv/src/
63+
$ git submodule update --init --recursive
6464
```
6565
Modify `CONFIG_XLEN` and `CONFIG_FLEN` options in the Makefile as required. Supported `XLEN` values are `32` and `64`. Supported `FLEN` values are `0`, `32` and `64`.
6666

@@ -88,12 +88,14 @@ $ xz -d -k -T 0 riscv32.img.xz
8888
When decompression finishes, launch the simulator with:
8989

9090
```console
91-
$ ../../marss-riscv riscvemu.cfg
91+
$ ../../marss-riscv -mem-model base riscvemu.cfg
9292
```
9393

9494
Simulation parameters can be configured using `riscvemu.cfg`, RISCVEMU JSON configuration file.
9595

96-
By default, the simulator will boot in "snapshot" mode, meaning it will **not** retain the file system changes after it is shut down. In order to persist the changes, pass `-rw` command line argument to the simulator. In that case, it may also be desirable to grow the userland image (has roughly 200MB of available free space by default). More information about how to grow it can be found [here](https://github.com/bucaps/marss-riscv-images#how-to-use).
96+
By default, the simulator will boot in "snapshot" mode, meaning it will **not** retain the file system changes after it is shut down. In order to persist the changes, pass `-rw` command line argument to the simulator. MARSS-RISCV comes with 2 DRAM memory models: Basic and DRAMSim2. To specify which memory model to use, run MARSS-RISCV with command line option `-mem-model` and specify either `base` or `dramsim2`. For DRAMSim2, the paths to `ini` and `system ini file` can be specified in `riscvemu.cfg` file.
97+
98+
It may also be desirable to grow the userland image (has roughly 200MB of available free space by default). More information about how to grow it can be found [here](https://github.com/bucaps/marss-riscv-images#how-to-use).
9799

98100
By default, guest boots in emulation mode. To start in simulation mode run with `-simstart` command line option.
99101

@@ -162,7 +164,6 @@ cycle = 115 pc = 0x6aaaadfc insn = 0xfa842503 lw a0,s0,-88 mode = PRV_U sta
162164
* Support for return address stack
163165
* Support for branch prediction unit, speculative execution and age-ordered instruction issue logic in the out-of-order core
164166
* Cycle accuracy validation using various RISC-V development boards
165-
* Integrating DRAM simulator (like DRAMSim2) with MARSS-RISCV, to get accurate memory stats
166167

167168
## Technical notes
168169

@@ -231,8 +232,11 @@ the JSON blk.txt file must be provided as disk image filename.
231232
## Acknowledgment
232233
This work was supported in part by DARPA through an award from the SSITH program. We would like to thank Gokturk Yuksek, Ravi Theja Gollapudi and Kanad Ghose for assistance with the internal details of TinyEMU and the development of the MARSS-RISCV.
233234

235+
For DRAMSim2, see [here](https://github.com/umd-memsys/DRAMSim2).
236+
234237
## License
235238
This project is licensed under the MIT License - see the
236239
src/MIT-LICENSE.txt file for details.
237240

238241
The SLIRP library has its own license (two clause BSD license).
242+
DRAMSim2 has its own license (two clause BSD license).

src/DRAMSim2

Submodule DRAMSim2 added at 753819a

src/Makefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ EXE=
5656
endif
5757
CC=$(CROSS_PREFIX)gcc
5858
STRIP=$(CROSS_PREFIX)strip
59-
CFLAGS=-O3 -g -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -MMD
59+
CFLAGS=-O3 -g -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -MMD -I./DRAMSim2
6060
CFLAGS+=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell cat VERSION)\"
6161
LDFLAGS=
62-
62+
EXT_LIB+= libdramsim.so libdramsim_wrapper_cpp_lib.so libdramsim_wrapper_c_connector.so
6363
bindir=/usr/local/bin
6464
INSTALL=install
6565

@@ -80,7 +80,7 @@ endif
8080

8181
PROGS+=
8282

83-
all: clean $(PROGS)
83+
all: clean $(EXT_LIB) $(PROGS)
8484

8585
stats-display:
8686
$(CC) stats_display.c -o stats-display -lrt
@@ -122,11 +122,23 @@ EMU_LIBS+=-lrt -lpthread -lm
122122

123123
RISCVEMU_OBJS:=$(EMU_OBJS) riscvemu.o riscv_machine.o softfp.o
124124

125+
libdramsim_wrapper_c_connector.so:
126+
$(CXX) -g -DRV$(CONFIG_XLEN) -DSIM_FLEN=$(CONFIG_FLEN) -fpic -shared -o libdramsim_wrapper_c_connector.so riscvsim/dramsim_wrapper_c_connector.cpp -I./DRAMSim2 -L. -ldramsim_wrapper_cpp_lib -Wl,-rpath=. -std=c++11
127+
128+
libdramsim_wrapper_cpp_lib.so:
129+
$(CXX) -g -DRV$(CONFIG_XLEN) -DSIM_FLEN=$(CONFIG_FLEN) -fpic -shared -o libdramsim_wrapper_cpp_lib.so riscvsim/dramsim_wrapper.cpp -I./DRAMSim2 -L./DRAMSim2 -ldramsim -Wl,-rpath=./DRAMSim2 -std=c++11
130+
131+
libdramsim.so:
132+
@echo "Building DRAMSim2 shared library:"
133+
@cd DRAMSim2/ && $(MAKE) libdramsim.so
134+
@cd ..
135+
@echo "Building MARSS-RISCV Simulator:"
136+
125137
riscvsim.o: $(RISCV_SIM_OBJS)
126138
$(LD) -r -o $@ $^ $(SIM_LIBS)
127139

128140
marss-riscv$(EXE): $(RISCVSIM_OBJ_FILE) riscv_cpu.o $(RISCVEMU_OBJS)
129-
$(CC) $(LDFLAGS) -o $@ $^ $(EMU_LIBS)
141+
$(CC) $(LDFLAGS) -o $@ $^ $(EMU_LIBS) -L. -ldramsim_wrapper_c_connector -Wl,-rpath=.
130142

131143
riscvemu.o: riscvemu.c
132144
$(COMPILE_DEBUG)$(CC) $(CFLAGS) -DCONFIG_XLEN=\"$(CONFIG_XLEN)\" -DCONFIG_FLEN=\"$(CONFIG_FLEN)\" -c -o $@ $<
@@ -150,7 +162,9 @@ install: $(PROGS)
150162
$(COMPILE_DEBUG)echo "CC $<"
151163

152164
clean:
153-
rm -f *.o *.d *~ $(PROGS) slirp/*.o slirp/*.d slirp/*~ riscvsim/*.o riscvsim/*.d riscvsim/*~
165+
rm -f *.o *.d *.so *~ $(PROGS) slirp/*.o slirp/*.d slirp/*~ riscvsim/*.o riscvsim/*.d riscvsim/*~
166+
cd DRAMSim2 && $(MAKE) clean
167+
cd ..
154168

155169
-include $(wildcard *.d)
156170
-include $(wildcard slirp/*.d)

src/machine.c

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ static void parse_stage_latency_str(int **dest, int max_stage_count, char *str)
193193
}
194194
}
195195

196+
static unsigned next_high_power_of_2(unsigned n)
197+
{
198+
n--;
199+
200+
n |= n >> 1;
201+
n |= n >> 2;
202+
n |= n >> 4;
203+
n |= n >> 8;
204+
n |= n >> 16;
205+
206+
return ++n;
207+
}
208+
196209
static int virt_machine_parse_config(VirtMachineParams *p,
197210
char *config_file_str, int len)
198211
{
@@ -899,40 +912,82 @@ static int virt_machine_parse_config(VirtMachineParams *p,
899912
}
900913
}
901914

902-
tag_name = "dram_burst_size";
903-
if (vm_get_int(cfg, tag_name, (int *)&p->sim_params.dram_burst_size) < 0) {
904-
fprintf(stderr, "%s not found, selecting default value: %u\n", tag_name,
905-
p->sim_params.dram_burst_size);
906-
}
907915

908-
tag_name = "mem_bus_access_rtt_latency";
909-
if (vm_get_int(cfg, tag_name, &p->sim_params.mem_bus_access_rtt_latency) < 0) {
910-
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
911-
p->sim_params.mem_bus_access_rtt_latency);
912-
}
916+
switch (p->sim_params.mem_model_type)
917+
{
918+
case MEM_MODEL_BASE:
919+
{
920+
tag_name = "mem_bus_access_rtt_latency";
921+
if (vm_get_int(cfg, tag_name, &p->sim_params.mem_bus_access_rtt_latency) < 0) {
922+
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
923+
p->sim_params.mem_bus_access_rtt_latency);
924+
}
913925

914-
tag_name = "tCL";
915-
if (vm_get_int(cfg, tag_name, &p->sim_params.tCL) < 0) {
916-
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
917-
p->sim_params.tCL);
918-
}
926+
tag_name = "tCL";
927+
if (vm_get_int(cfg, tag_name, &p->sim_params.tCL) < 0) {
928+
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
929+
p->sim_params.tCL);
930+
}
919931

920-
tag_name = "tRCD";
921-
if (vm_get_int(cfg, tag_name, &p->sim_params.tRCD) < 0) {
922-
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
923-
p->sim_params.tRCD);
924-
}
932+
tag_name = "tRCD";
933+
if (vm_get_int(cfg, tag_name, &p->sim_params.tRCD) < 0) {
934+
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
935+
p->sim_params.tRCD);
936+
}
925937

926-
tag_name = "tRP";
927-
if (vm_get_int(cfg, tag_name, &p->sim_params.tRP) < 0) {
928-
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
929-
p->sim_params.tRP);
930-
}
938+
tag_name = "tRP";
939+
if (vm_get_int(cfg, tag_name, &p->sim_params.tRP) < 0) {
940+
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
941+
p->sim_params.tRP);
942+
}
931943

932-
tag_name = "row_buffer_write_latency";
933-
if (vm_get_int(cfg, tag_name, &p->sim_params.row_buffer_write_latency) < 0) {
934-
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
935-
p->sim_params.row_buffer_write_latency);
944+
tag_name = "row_buffer_write_latency";
945+
if (vm_get_int(cfg, tag_name, &p->sim_params.row_buffer_write_latency) < 0) {
946+
fprintf(stderr, "%s not found, selecting default value: %d\n", tag_name,
947+
p->sim_params.row_buffer_write_latency);
948+
}
949+
tag_name = "dram_burst_size";
950+
if (vm_get_int(cfg, tag_name, (int *)&p->sim_params.dram_burst_size) < 0) {
951+
fprintf(stderr, "%s not found, selecting default value: %u\n", tag_name,
952+
p->sim_params.dram_burst_size);
953+
}
954+
break;
955+
}
956+
case MEM_MODEL_DRAMSIM:
957+
{
958+
tag_name = "dramsim_ini_file";
959+
if (vm_get_str(cfg, tag_name, &str) < 0) {
960+
fprintf(stderr, "%s not found, selecting default value: %s\n", tag_name,
961+
p->sim_params.dramsim_ini_file);
962+
} else {
963+
free(p->sim_params.dramsim_ini_file);
964+
p->sim_params.dramsim_ini_file = strdup(str);
965+
}
966+
967+
tag_name = "dramsim_system_ini_file";
968+
if (vm_get_str(cfg, tag_name, &str) < 0) {
969+
fprintf(stderr, "%s not found, selecting default value: %s\n", tag_name,
970+
p->sim_params.dramsim_system_ini_file);
971+
} else {
972+
free(p->sim_params.dramsim_system_ini_file);
973+
p->sim_params.dramsim_system_ini_file = strdup(str);
974+
}
975+
976+
tag_name = "dramsim_stats_dir";
977+
if (vm_get_str(cfg, tag_name, &str) < 0) {
978+
fprintf(stderr, "%s not found, selecting default value: %s\n", tag_name,
979+
p->sim_params.dramsim_stats_dir);
980+
} else {
981+
free(p->sim_params.dramsim_stats_dir);
982+
p->sim_params.dramsim_stats_dir = strdup(str);
983+
}
984+
break;
985+
}
986+
default:
987+
{
988+
fprintf(stderr, "error: invalid memory model\n");
989+
exit(1);
990+
}
936991
}
937992

938993
/**
@@ -945,8 +1000,18 @@ static int virt_machine_parse_config(VirtMachineParams *p,
9451000
p->sim_params.enable_bpu = FALSE;
9461001
}
9471002

948-
/* Setup remaining params */
949-
p->sim_params.guest_ram_size = p->ram_size;
1003+
/* Set RAM size to be used by simulated memory model */
1004+
/**
1005+
*
1006+
* NOTE: TinyEMU reserves 2GB of physical address space for its devices and
1007+
* internal implementation. Guest RAM size taken as user input is mapped
1008+
* starting at 2GB. Hence for simulated memory model, the total guest ram
1009+
* size becomes (2GB + guest RAM size) rounded to next highest power of 2.
1010+
* This guest_ram_size is passed to either the base memory model or
1011+
* DRAMSim2, depending on which is being used.
1012+
*/
1013+
p->sim_params.guest_ram_size
1014+
= next_high_power_of_2(2048 + (p->ram_size >> 20));
9501015

9511016
json_free(cfg);
9521017
return 0;

src/riscv_cpu.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "iomem.h"
4646
#include "riscv_cpu.h"
4747
#include "sim_params_stats.h"
48+
#include "riscvsim/dramsim_wrapper_c_connector.h"
4849

4950
static no_inline int target_read_slow(RISCVCPUState *s, mem_uint_t *pval,
5051
target_ulong addr, int size_log2);
@@ -320,7 +321,12 @@ stop_system_simulation(RISCVCPUState *s, target_ulong pc, uint64_t icount)
320321
fprintf(stderr, "(marss-riscv): Time elapsed on host-machine %lu ms\n",
321322
sim_time);
322323

323-
dump_simulation_stats(s);
324+
if (s->simcpu->mmu->mem_controller->mem_model_type == MEM_MODEL_DRAMSIM)
325+
{
326+
dramsim_wrapper_print_stats();
327+
}
328+
329+
dump_simulation_stats(s);
324330

325331
#if defined(CONFIG_SIM_TRACE)
326332
fclose(s->sim_trace);

src/riscvemu.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ static struct option options[] = {
616616
{ "no-accel", no_argument },
617617
{ "simstart", no_argument },
618618
{ "stats-display", no_argument },
619+
{ "mem-model", required_argument },
619620
{ NULL },
620621
};
621622

@@ -629,13 +630,14 @@ void help(void)
629630
#ifdef CONFIG_CPU_RISCV
630631
"-b [32|64] set the integer register width in bits\n"
631632
#endif
632-
"-m ram_size set the RAM size in MB\n"
633-
"-rw allow write access to the disk image (default=snapshot)\n"
634-
"-ctrlc the C-c key stops the emulator instead of being sent to the\n"
635-
" emulated software\n"
636-
"-append cmdline append cmdline to the kernel command line\n"
637-
"-simstart start (boot kernel) in simulation mode\n"
638-
"-stats-display dump simulation performance stats to a shared memory location, read by sim-display tool\n"
633+
"-m ram_size set the RAM size in MB\n"
634+
"-rw allow write access to the disk image (default=snapshot)\n"
635+
"-ctrlc the C-c key stops the emulator instead of being sent to the\n"
636+
" emulated software\n"
637+
"-append cmdline append cmdline to the kernel command line\n"
638+
"-simstart start (boot kernel) in simulation mode\n"
639+
"-stats-display dump simulation performance stats to a shared memory location, read by sim-display tool\n"
640+
"-mem-model [base|dramsim2] type of simulated memory model\n"
639641
"\n"
640642
"Console keys:\n"
641643
"Press C-a x to exit the emulator, C-a h to get some help.\n");
@@ -699,6 +701,7 @@ int main(int argc, char **argv)
699701
VirtMachineParams p_s, *p = &p_s;
700702
int marss_start_in_sim = 0;
701703
int marss_stats_display = 0;
704+
int marss_mem_model = MEM_MODEL_BASE;
702705

703706
ram_size = -1;
704707
allow_ctrlc = FALSE;
@@ -734,6 +737,21 @@ int main(int argc, char **argv)
734737
case 7: /* stats-display */
735738
marss_stats_display = 1;
736739
break;
740+
case 8: /* mem-model */
741+
if (strcmp(optarg, "base") == 0)
742+
{
743+
marss_mem_model = MEM_MODEL_BASE;
744+
}
745+
else if (strcmp(optarg, "dramsim2") == 0)
746+
{
747+
marss_mem_model = MEM_MODEL_DRAMSIM;
748+
}
749+
else
750+
{
751+
fprintf(stderr, "unknown mem-model type, see help\n");
752+
exit(1);
753+
}
754+
break;
737755
default:
738756
fprintf(stderr, "unknown option index: %d\n", option_index);
739757
exit(1);
@@ -772,6 +790,7 @@ int main(int argc, char **argv)
772790
path = argv[optind++];
773791

774792
virt_machine_set_defaults(p);
793+
p->sim_params.mem_model_type = marss_mem_model;
775794
#ifdef CONFIG_FS_NET
776795
fs_wget_init();
777796
#endif

0 commit comments

Comments
 (0)