chipsalliance / dromajo

RISC-V RV64GC emulator designed for RTL co-simulation
Apache License 2.0
210 stars 63 forks source link

Fixing issues #73 and #75 #76

Closed kabylkas closed 1 year ago

kabylkas commented 1 year ago

@tommythorn, @renau, I would appreciate your comments 😊

Overview

This PR addresses issues #73 and #75.

Issue 73 is fixed simply by changing the type of maxinsns variable from unsigned to signed. This ensures the variable does not overflow when 0 is decremented.

Issue 75 is fixed by placing the serialization functions into loop and dumping the register state per core (n register states). The main memory is dumped per system (one memory dump). Same is done for deserialization logic.

Try it out

To test the feature try the following:

./dromajo --maxinsns 1000000 --ncpus 2 --trace 0 [multicore-bin.riscv] --save snapshots/multicore

After the execution completes, the following files should be generated in the snapshots directory:

.
├── shared_mem_conf.mainram
├── shared_mem_conf0.bootram
├── shared_mem_conf0.re_regs
├── shared_mem_conf1.bootram
└── shared_mem_conf1.re_regs

As you can see, *.bootram dumps get generated per core and *.mainram is still a single file.

To proceed the simulation from the checkpoint, create the following json config file in the snapshots directory, let's name it multicore_conf.json:

{
  "version":1,
  "machine":"riscv64",
  "bios": "[absolute-path-to-bin-dir/multicore-bin.riscv]",
  "load": "[absolute-path-to-dromajo-repo]/build/snapshots/multicore",
  "memory_base_addr": 0x80000000,
  "maxinsns": 1000000000,
  "ncpus": 2,
  "memory_size":256,
  "clint_base_addr": 0x02000000,
  "clint_size": 0xC0000,
  "plic_base_addr": 0x0C000000,
  "plic_size": 0x3FFFFFF,
  "uart_base_addr": 0x10000000,
  "uart_size": 0x1000
}

Finally, run dromajo again pointing it to the config file:

./dromajo --trace 0 ./snapshots/multicore_conf.json

The simulation should proceed from the checkpoint.

renau commented 1 year ago

Nice, this addresses several of the multicore issues.

et-tommythorn commented 1 year ago

Thanks Professor Kabylkas, much appreciated!

et-tommythorn commented 5 months ago

Sorry, I had to revert it immediately as it broke our workflow, but I didn't have time to understand why it broke