From 0dab27f24a9476a91aa57fc07ef78a318cbf6ded Mon Sep 17 00:00:00 2001 From: studyztp Date: Wed, 23 Aug 2023 14:47:01 -0700 Subject: [PATCH 1/4] sim: check redirect path when unserialize for cpt Change-Id: I55b8ce1770b0580d52b8dfa782572d492c1bf727 --- src/sim/fd_array.cc | 19 +++++++++++++++++-- src/sim/fd_array.hh | 8 ++++++-- src/sim/process.cc | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/sim/fd_array.cc b/src/sim/fd_array.cc index 5ca9370054..d8cb981a93 100644 --- a/src/sim/fd_array.cc +++ b/src/sim/fd_array.cc @@ -42,6 +42,7 @@ #include "base/output.hh" #include "params/Process.hh" #include "sim/fd_entry.hh" +#include "sim/process.hh" namespace gem5 { @@ -367,7 +368,7 @@ FDArray::serialize(CheckpointOut &cp) const { } void -FDArray::unserialize(CheckpointIn &cp) { +FDArray::unserialize(CheckpointIn &cp, SimObject* process_ptr) { ScopedCheckpointSection sec(cp, "fdarray"); uint64_t size; paramIn(cp, "size", size); @@ -418,11 +419,25 @@ FDArray::unserialize(CheckpointIn &cp) { setFDEntry(tgt_fd, fdep); mode_t mode = this_ffd->getFileMode(); + std::string const& path = this_ffd->getFileName(); + int flags = this_ffd->getFlags(); // Re-open the file and assign a new sim_fd - int sim_fd = openFile(path, flags, mode); + int sim_fd; + if (process_ptr) + { + Process* ptr = static_cast(process_ptr); + std::string const& host_path = + ptr->checkPathRedirect(this_ffd->getFileName()); + sim_fd = openFile(host_path, flags, mode); + } + else + { + sim_fd = openFile(path, flags, mode); + } + this_ffd->setSimFD(sim_fd); // Restore the file offset to the proper value diff --git a/src/sim/fd_array.hh b/src/sim/fd_array.hh index d6d1b3cfbe..79e5a4b92e 100644 --- a/src/sim/fd_array.hh +++ b/src/sim/fd_array.hh @@ -36,9 +36,9 @@ #include #include #include - #include "sim/fd_entry.hh" #include "sim/serialize.hh" +#include "sim/sim_object.hh" namespace gem5 { @@ -117,7 +117,11 @@ class FDArray : public Serializable * Serialization methods for file descriptors */ void serialize(CheckpointOut &cp) const override; - void unserialize(CheckpointIn &cp) override; + void unserialize(CheckpointIn &cp, SimObject* process_ptr ); + void unserialize(CheckpointIn &cp) override { + unserialize(cp, nullptr); + }; + private: /** diff --git a/src/sim/process.cc b/src/sim/process.cc index a348b450b0..f47dbd59c6 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -387,7 +387,7 @@ Process::unserialize(CheckpointIn &cp) { memState->unserialize(cp); pTable->unserialize(cp); - fds->unserialize(cp); + fds->unserialize(cp, this); /** * Checkpoints for pipes, device drivers or sockets currently From 2a4f3f206bf3e86f139b4cd2b7a379da25647e38 Mon Sep 17 00:00:00 2001 From: studyztp Date: Wed, 23 Aug 2023 16:27:45 -0700 Subject: [PATCH 2/4] sim: modifed the type of path Change-Id: I56be3b62b1804371b9b9e0f84ee1ec49cbedf553 --- src/sim/fd_array.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/sim/fd_array.cc b/src/sim/fd_array.cc index d8cb981a93..f3605a5b7d 100644 --- a/src/sim/fd_array.cc +++ b/src/sim/fd_array.cc @@ -420,23 +420,23 @@ FDArray::unserialize(CheckpointIn &cp, SimObject* process_ptr) { mode_t mode = this_ffd->getFileMode(); - std::string const& path = this_ffd->getFileName(); + std::string path; + + if (process_ptr) + { + Process* ptr = static_cast(process_ptr); + path = ptr->checkPathRedirect(this_ffd->getFileName()); + } + else + { + path = this_ffd->getFileName(); + } int flags = this_ffd->getFlags(); // Re-open the file and assign a new sim_fd int sim_fd; - if (process_ptr) - { - Process* ptr = static_cast(process_ptr); - std::string const& host_path = - ptr->checkPathRedirect(this_ffd->getFileName()); - sim_fd = openFile(host_path, flags, mode); - } - else - { - sim_fd = openFile(path, flags, mode); - } + sim_fd = openFile(path, flags, mode); this_ffd->setSimFD(sim_fd); From 377c875733b38865ca22ef5232f2ad25c6d054c9 Mon Sep 17 00:00:00 2001 From: studyztp Date: Thu, 31 Aug 2023 11:33:45 -0700 Subject: [PATCH 3/4] sim: check redirect path when unserialize for cpt sim/fd_array.hh: Add "class Process;" to forward declare Process for unserialize function to pass in a Process object pointer. Fix the styling issue with include files. sim/fd_array.cc" Add comments. Change-Id: Ifb21eb1c7bad119028b8fd8e610a125100fde696 --- src/sim/fd_array.cc | 7 ++++--- src/sim/fd_array.hh | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sim/fd_array.cc b/src/sim/fd_array.cc index f3605a5b7d..1ce46a1e33 100644 --- a/src/sim/fd_array.cc +++ b/src/sim/fd_array.cc @@ -368,7 +368,7 @@ FDArray::serialize(CheckpointOut &cp) const { } void -FDArray::unserialize(CheckpointIn &cp, SimObject* process_ptr) { +FDArray::unserialize(CheckpointIn &cp, Process* process_ptr) { ScopedCheckpointSection sec(cp, "fdarray"); uint64_t size; paramIn(cp, "size", size); @@ -424,8 +424,9 @@ FDArray::unserialize(CheckpointIn &cp, SimObject* process_ptr) { if (process_ptr) { - Process* ptr = static_cast(process_ptr); - path = ptr->checkPathRedirect(this_ffd->getFileName()); + // Check if it is needed to redirect the app path to another host + // path + path = process_ptr->checkPathRedirect(this_ffd->getFileName()); } else { diff --git a/src/sim/fd_array.hh b/src/sim/fd_array.hh index 79e5a4b92e..c2a6b64dea 100644 --- a/src/sim/fd_array.hh +++ b/src/sim/fd_array.hh @@ -36,13 +36,15 @@ #include #include #include + #include "sim/fd_entry.hh" #include "sim/serialize.hh" -#include "sim/sim_object.hh" namespace gem5 { +class Process; + class FDArray : public Serializable { public: @@ -117,7 +119,7 @@ class FDArray : public Serializable * Serialization methods for file descriptors */ void serialize(CheckpointOut &cp) const override; - void unserialize(CheckpointIn &cp, SimObject* process_ptr ); + void unserialize(CheckpointIn &cp, Process* process_ptr ); void unserialize(CheckpointIn &cp) override { unserialize(cp, nullptr); }; From e206b16f734630fae3c047adba82c34444ad660b Mon Sep 17 00:00:00 2001 From: studyztp Date: Tue, 5 Sep 2023 18:25:33 -0700 Subject: [PATCH 4/4] sim:fixed some style issues Change-Id: I0832a8b68e802e9671b755d3a71fd9c8f17e1648 --- src/sim/fd_array.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sim/fd_array.cc b/src/sim/fd_array.cc index 1ce46a1e33..ea58299587 100644 --- a/src/sim/fd_array.cc +++ b/src/sim/fd_array.cc @@ -422,14 +422,12 @@ FDArray::unserialize(CheckpointIn &cp, Process* process_ptr) { std::string path; - if (process_ptr) - { + if (process_ptr) { // Check if it is needed to redirect the app path to another host // path path = process_ptr->checkPathRedirect(this_ffd->getFileName()); } - else - { + else { path = this_ffd->getFileName(); }