Skip to content

Commit

Permalink
feat: replace fixed get_pmem with serialize_base_addr for checkpoint …
Browse files Browse the repository at this point in the history
…storage (#780)

Replaced the hardcoded `get_pmem` with `serialize_base_addr` to enable specifying the checkpoint storage location via the `--using-flash-store-checkpoint` option. While this change lays the groundwork for saving checkpoints to flash, the functionality is not yet fully implemented and will be completed in future updates.

Signed-off-by: jiaxiaoyu <[email protected]>
  • Loading branch information
xyyy1420 authored Jan 14, 2025
1 parent e243fbe commit d4f558f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/checkpoint/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Serializer

void serializePMem(uint64_t inst_count);

void serializeRegs();
void serializeRegs(uint8_t* serialize_base_addr);

explicit Serializer();

Expand Down
33 changes: 20 additions & 13 deletions src/checkpoint/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ uint8_t *get_pmem();
word_t paddr_read(paddr_t addr, int len, int type, int trap_type, int mode, vaddr_t vaddr);
uint8_t *guest_to_host(paddr_t paddr);
#include <debug.h>
#include <device/flash.h>
extern void log_buffer_flush();
extern void log_file_flush();
extern unsigned long MEMORY_SIZE;
Expand Down Expand Up @@ -168,16 +169,16 @@ void Serializer::serializePMem(uint64_t inst_count) {}
#ifdef CONFIG_MEM_COMPRESS
extern void csr_writeback();

void Serializer::serializeRegs() {
auto *intRegCpt = (uint64_t *) (get_pmem() + IntRegStartAddr);
void Serializer::serializeRegs(uint8_t* serialize_base_addr) {
auto *intRegCpt = (uint64_t *) (serialize_base_addr + IntRegStartAddr);
for (unsigned i = 0; i < 32; i++) {
*(intRegCpt + i) = cpu.gpr[i]._64;
}
Log("Writing int registers to checkpoint memory @[0x%x, 0x%x) [0x%x, 0x%x)", INT_REG_CPT_ADDR,
INT_REG_CPT_ADDR + 32 * 8, IntRegStartAddr, IntRegStartAddr + 32 * 8);

#ifndef CONFIG_FPU_NONE
auto *floatRegCpt = (uint64_t *)(get_pmem() + FloatRegStartAddr);
auto *floatRegCpt = (uint64_t *)(serialize_base_addr + FloatRegStartAddr);
for (unsigned i = 0; i < 32; i++) {
*(floatRegCpt + i) = cpu.fpr[i]._64;
}
Expand All @@ -186,7 +187,7 @@ void Serializer::serializeRegs() {
#endif // CONFIG_FPU_NONE

#ifdef CONFIG_RVV
auto *vectorRegCpt = (uint64_t *) (get_pmem() + VecRegStartAddr);
auto *vectorRegCpt = (uint64_t *) (serialize_base_addr + VecRegStartAddr);
for (unsigned i = 0; i < 32; i++) {
for (unsigned j = 0; j < VENUM64; j++) {
*(vectorRegCpt + (i * VENUM64) + j)=cpu.vr[i]._64[j];
Expand All @@ -199,13 +200,13 @@ void Serializer::serializeRegs() {
#endif // CONFIG_RVV


auto *pc = (uint64_t *) (get_pmem() + PCAddr);
auto *pc = (uint64_t *) (serialize_base_addr + PCAddr);
*pc = cpu.pc;
Log("Writing PC: 0x%lx at addr 0x%x", cpu.pc, PC_CPT_ADDR);


// csr_writeback();
auto *csrCpt = (uint64_t *)(get_pmem() + CSRStartAddr);
auto *csrCpt = (uint64_t *)(serialize_base_addr + CSRStartAddr);
// Log("csrCpt: %p\n",csrCpt);
// Log("Mstatus: 0x%x", mstatus->val);
// Log("CSR array mstatus: 0x%x", csr_array[0x300]);
Expand Down Expand Up @@ -249,34 +250,40 @@ void Serializer::serializeRegs() {
);


auto *flag = (uint64_t *)(get_pmem() + CptFlagAddr);
auto *flag = (uint64_t *)(serialize_base_addr + CptFlagAddr);
*flag = CPT_MAGIC_BUMBER;
Log("Touching Flag: 0x%x at addr 0x%x", CPT_MAGIC_BUMBER, BOOT_FLAG_ADDR);

auto *mode_flag = (uint64_t *) (get_pmem() + MODEAddr);
auto *mode_flag = (uint64_t *) (serialize_base_addr + MODEAddr);
*mode_flag = cpu.mode;
Log("Record mode flag: 0x%lx at addr 0x%x", cpu.mode, MODE_CPT_ADDR);

auto *mtime = (uint64_t *) (get_pmem() + MTIMEAddr);
auto *mtime = (uint64_t *) (serialize_base_addr + MTIMEAddr);
extern word_t paddr_read(paddr_t addr, int len, int type, int mode, vaddr_t vaddr);
*mtime = ::paddr_read(CLINT_MMIO+0xBFF8, 8, MEM_TYPE_READ, MEM_TYPE_READ, MODE_M, CLINT_MMIO+0xBFF8);
Log("Record time: 0x%lx at addr 0x%x", cpu.mode, MTIME_CPT_ADDR);

auto *mtime_cmp = (uint64_t *) (get_pmem() + MTIMECMPAddr);
auto *mtime_cmp = (uint64_t *) (serialize_base_addr + MTIMECMPAddr);
*mtime_cmp = ::paddr_read(CLINT_MMIO+0x4000, 8, MEM_TYPE_READ, MEM_TYPE_READ, MODE_M, CLINT_MMIO+0x4000);
Log("Record time: 0x%lx at addr 0x%x", cpu.mode, MTIME_CMP_CPT_ADDR);

regDumped = true;
}
#else
void Serializer::serializeRegs() {}
void Serializer::serializeRegs(uint8_t* serialize_base_addr) { }
#endif

void Serializer::serialize(uint64_t inst_count) {

#ifdef CONFIG_MEM_COMPRESS
serializeRegs();
uint8_t* serialize_reg_base_addr = NULL;

serialize_reg_base_addr = get_pmem();
assert(serialize_reg_base_addr);

serializeRegs(serialize_reg_base_addr);
serializePMem(inst_count);

#else
xpanic("You should enable CONFIG_MEM_COMPRESS in menuconfig");
#endif
Expand Down Expand Up @@ -399,7 +406,7 @@ bool try_take_cpt(uint64_t icount) {
}

void serialize_reg_to_mem() {
serializer.serializeRegs();
serializer.serializeRegs(get_pmem());
}

}

0 comments on commit d4f558f

Please sign in to comment.