-
Notifications
You must be signed in to change notification settings - Fork 244
Added snapshot and checkpoint system for Sail RISC-V emulator #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Did you write this PR description entirely by yourself? |
Hi, I wrote a rough implementation design based on the feature requested and formatted it with the help of AI. |
|
The code itself was written by an LLM too, not just the PR description? |
|
Yeah the AI definitely lowers my expectations, and my desire to review it. In any case this is a ton of code and I'm not sure the approach is the best option. I was thinking we'd just have Sail auto-generate functions to save/restore the model state. Much easier and probably less error-prone. |
|
Some communities have jumped onboard the vibe-coding hype train, but you should really disclose your use of generative AI unless you know the community in question does not expect it. |
The implementation design and the code was written by me but I did took help in few areas like error solving or syntax help. I apologize if I violated the community guidelines in any way, that was not my intention. |
|
Hey @tanishkaa08, regardless of whether you used AI or not and to what extent, thank you for your contribution! I will definitely check your submitted code in the next days. We can still figure out what the best approach is to implement this feature, since we did not discuss different approaches publicly and only in our Monday weekly meeting, and to what extent AI tools can be used or not is a separate topic even though as the others have said we should avoid heavy usage of it or at least disclose its use. When it comes to formatting, I think it is totally fine and to be honest, I wish that some would pipe their (sail) code into some tool to at least format it before submitting. |
|
Hello, we discussed this in the meeting (there's a weekly meeting for this project btw) and we're going to go with the approach of having the Sail compiler automatically generate snapshotting functions for the mode. I made a very initial start on this here: rems-project/sail#1602 Basically how it will work:
Sorry that's probably not what you wanted to hear after making a big PR 😬 |
Hi, Thank you for the follow up message. Please let me know if I could somehow contribute further and also make it to the weekly meetings if it is open for new contributors. I believe that understanding the community would help me make a much more meaningful contribution. |
|
It's the "RV-LFX Golden Model" meeting on Monday on this calendar - open to everyone! |
Implements #1400
This PR implements a comprehensive snapshot and checkpoint system for the Sail RISC-V emulator, enabling users to save and restore complete architectural state at any point during simulation. This feature significantly improves workflow efficiency by allowing users to skip lengthy boot processes and resume simulations from saved states.
Features Implemented
Snapshot System
--snapshot-save <file>saves state at end of simulation--snapshot-restore <file>restores simulation from saved stateCheckpoint System
Automatic snapshot creation based on configurable conditions:
--checkpoint-interval <N>creates checkpoint every N instructions--checkpoint-pc <hex>creates checkpoint when PC reaches specified value--checkpoint-memory-read <addr>and--checkpoint-memory-write <addr>trigger on memory access--checkpoint-register-write <reg>triggers when integer register is written--checkpoint-freg-write <reg>triggers when FP register is written--checkpoint-csr-read <csr>and--checkpoint-csr-write <csr>trigger on CSR accessTechnical Implementation
Architecture
snapshot_manager.h/cpp)checkpoint_manager.h/cpp)callbacks_ifinterface to monitor simulation eventssnapshot_sail_interface.h/cpp)snapshot_memory.h/c)rts.c)snapshot_format.h/cpp)model/postlude/snapshot.sail)State Capture Details
Registers:
model.zxNmembersmodel.zfNmembersCSRs:
model.zmstatus.zbits,model.zmepc)Memory:
Platform State:
Integration Points
riscv_model_impl.h/cpp)SnapshotManagerandCheckpointManageras membersriscv_sim.cpp)finish()andinit_sail()init_sail()CMakeLists.txt)riscv_modellibraryriscv.sail_project)postlude/snapshot.sailto buildFD_coreandV_coreto requirements for register accessDesign Decisions
zread_CSR()API (which can crash for non-existent CSRs), we directly access model members for safety and reliability.Files Changed
c_emulator/snapshot_format.h/cpp- JSON serialization/deserializationc_emulator/snapshot_sail_interface.h/cpp- Sail model state accessc_emulator/snapshot_manager.h/cpp- Snapshot orchestrationc_emulator/checkpoint_manager.h/cpp- Checkpoint systemc_emulator/snapshot_memory.h/c- Memory dump/restore functionsmodel/postlude/snapshot.sail- Sail state access functionsc_emulator/riscv_model_impl.h/cpp- Added snapshot/checkpoint managersc_emulator/riscv_sim.cpp- Added CLI options and integrationc_emulator/CMakeLists.txt- Added new source files to buildmodel/riscv.sail_project- Added snapshot.sail to Sail buildTesting
The feature has been tested with:
Known Limitations