From 0bb9160f3af5e8d53006060274a7cd4f649f9d71 Mon Sep 17 00:00:00 2001 From: xyyy1420 Date: Tue, 14 Jan 2025 16:21:53 +0800 Subject: [PATCH] feat: add --store-cpt-in-flash option (#778) This commit introduces the `--using-flash-store-checkpoint` option, which is intended to enable saving checkpoints directly to flash storage. Currently, this option is not yet implemented in the workflow. Future updates will integrate this feature into the relevant checkpoint handling logic. Signed-off-by: jiaxiaoyu --- include/checkpoint/serializer.h | 3 ++- src/checkpoint/serializer.cpp | 8 +++++--- src/monitor/monitor.c | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/checkpoint/serializer.h b/include/checkpoint/serializer.h index 9045e4c67..cbda1bf48 100644 --- a/include/checkpoint/serializer.h +++ b/include/checkpoint/serializer.h @@ -36,7 +36,7 @@ class Serializer explicit Serializer(); - void init(); + void init(bool store_cpt_in_flash); bool shouldTakeCpt(uint64_t num_insts); bool instrsCouldTakeCpt(uint64_t num_insts); @@ -68,6 +68,7 @@ class Serializer const uint32_t MISCDoneFlag; bool regDumped{false}; + bool store_cpt_in_flash{false}; std::map simpoint2Weights; diff --git a/src/checkpoint/serializer.cpp b/src/checkpoint/serializer.cpp index ec13e5920..2d77d924a 100644 --- a/src/checkpoint/serializer.cpp +++ b/src/checkpoint/serializer.cpp @@ -282,7 +282,9 @@ void Serializer::serialize(uint64_t inst_count) { #endif } -void Serializer::init() { +void Serializer::init(bool store_cpt_in_flash) { + this->store_cpt_in_flash = store_cpt_in_flash; + if (checkpoint_state == SimpointCheckpointing) { assert(checkpoint_interval); intervalSize = checkpoint_interval; @@ -382,8 +384,8 @@ uint64_t Serializer::next_index(){ extern "C" { -void init_serializer() { - serializer.init(); +void init_serializer(bool store_cpt_in_flash) { + serializer.init(store_cpt_in_flash); } bool try_take_cpt(uint64_t icount) { diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index 7325c4f37..8295a206e 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -44,6 +44,7 @@ static char *flash_image = NULL; static int batch_mode = false; static int difftest_port = 1234; char *max_instr = NULL; +static bool store_cpt_in_flash = false; char compress_file_format = 0; // default is gz extern char *mapped_cpt_file; // defined in paddr.c @@ -115,6 +116,7 @@ static inline int parse_args(int argc, char *argv[]) { {"cpt-mmode" , no_argument , NULL, 7}, {"map-cpt" , required_argument, NULL, 10}, {"checkpoint-format" , required_argument, NULL, 12}, + {"store-cpt-in-flash", no_argument, NULL, 17}, // profiling {"simpoint-profile" , no_argument , NULL, 3}, @@ -154,6 +156,14 @@ static inline int parse_args(int argc, char *argv[]) { flash_image = optarg; break; + case 17: + #ifdef CONFIG_HAS_FLASH + store_cpt_in_flash = true; + #else + assert(0); + #endif + break; + case 'r': restorer = optarg; break; @@ -271,6 +281,7 @@ static inline int parse_args(int argc, char *argv[]) { printf("\t--manual-oneshot-cpt Manually take one-shot cpt by send signal.\n"); printf("\t--manual-uniform-cpt Manually take uniform cpt by send signal.\n"); printf("\t--checkpoint-format=FORMAT Specify the checkpoint format('gz' or 'zstd'), default: 'gz'.\n"); + printf("\t--store-cpt-in-flash Use this option to save the checkpoint to flash storage.\n"); // printf("\t--map-cpt map to this file as pmem, which can be treated as a checkpoint.\n"); //comming back soon printf("\t--flash-image=FLASH_IMAGE image path of flash\n"); @@ -315,14 +326,14 @@ void init_monitor(int argc, char *argv[]) { extern void init_path_manager(); extern void simpoint_init(); - extern void init_serializer(); + extern void init_serializer(bool store_cpt_in_flash); //checkpoint and profiling set output bool output_features_enabled = checkpoint_state != NoCheckpoint || profiling_state == SimpointProfiling; if (output_features_enabled) { init_path_manager(); simpoint_init(); - init_serializer(); + init_serializer(store_cpt_in_flash); } /* Initialize memory. */