gem5
[DEVELOP-FOR-23.0]
|
#include <fd_array.hh>
Public Member Functions | |
FDArray (std::string const &input, std::string const &output, std::string const &errout) | |
Initialize the file descriptor array and set the standard file descriptors to defaults or values passed in with the process params. More... | |
void | updateFileOffsets () |
Figure out the file offsets for all currently open files and save them the offsets during the calls to drain by the owning process. More... | |
void | restoreFileOffsets () |
Restore all offsets for currently open files during the unserialize phase for the owning process class. More... | |
void | setFDEntry (int tgt_fd, std::shared_ptr< FDEntry > fdep) |
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd. More... | |
std::shared_ptr< FDEntry > | operator[] (int tgt_fd) |
Treat this object like a normal array in using the subscript operator to pull entries out of it. More... | |
int | getSize () const |
Return the size of the _fdArray field. More... | |
int | allocFD (std::shared_ptr< FDEntry > fdp) |
Step through the file descriptor array and find the first available entry which is denoted as being free by being a 'nullptr'. More... | |
int | closeFDEntry (int tgt_fd) |
Try to close the host file descriptor. More... | |
void | serialize (CheckpointOut &cp) const override |
Serialize an object. More... | |
void | unserialize (CheckpointIn &cp) override |
Unserialize an object. More... | |
![]() | |
Serializable () | |
virtual | ~Serializable () |
void | serializeSection (CheckpointOut &cp, const char *name) const |
Serialize an object into a new section. More... | |
void | serializeSection (CheckpointOut &cp, const std::string &name) const |
void | unserializeSection (CheckpointIn &cp, const char *name) |
Unserialize an a child object. More... | |
void | unserializeSection (CheckpointIn &cp, const std::string &name) |
Private Member Functions | |
int | openFile (std::string const &file_name, int flags, mode_t mode) const |
Help clarify our intention when opening files in the init and restoration code. More... | |
int | openInputFile (std::string const &file_name) const |
int | openOutputFile (std::string const &file_name) const |
std::shared_ptr< FDEntry > | getFDEntry (int tgt_fd) |
Return the file descriptor entry object associated with the index provided. More... | |
Private Attributes | |
std::array< std::shared_ptr< FDEntry >, _numFDs > | _fdArray |
std::string | _input |
Hold param strings passed from the Process class which indicate the filename for each of the corresponding files or some keyword indicating the use of standard file descriptors. More... | |
std::string | _output |
std::string | _errout |
std::map< std::string, int > | _imap |
Hold strings which represent the default values which are checked against to initialize the standard file descriptors. More... | |
std::map< std::string, int > | _oemap |
Static Private Attributes | |
static constexpr size_t | _numFDs {1024} |
Hold pointers to the file descriptor entries. More... | |
Additional Inherited Members | |
![]() | |
static const std::string & | currentSection () |
Gets the fully-qualified name of the active section. More... | |
static void | generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream) |
Generate a checkpoint file so that the serialization can be routed to it. More... | |
Definition at line 46 of file fd_array.hh.
gem5::FDArray::FDArray | ( | std::string const & | input, |
std::string const & | output, | ||
std::string const & | errout | ||
) |
Initialize the file descriptor array and set the standard file descriptors to defaults or values passed in with the process params.
input | Used to initialize the stdin file descriptor |
output | Used to initialize the stdout file descriptor |
errout | Used to initialize the stderr file descriptor |
Search through the input options and setup the default fd if match is found; otherwise, open an input file and seek to location.
Search through the output/error options and setup the default fd if match is found; otherwise, open an output file and seek to location.
Definition at line 49 of file fd_array.cc.
int gem5::FDArray::allocFD | ( | std::shared_ptr< FDEntry > | fdp | ) |
Step through the file descriptor array and find the first available entry which is denoted as being free by being a 'nullptr'.
That file descriptor entry is the new target file descriptor entry that we return as the return parameter.
fdp | Allocated beforehand and passed into this method; the fdp is meant to be a generic pointer capable of pointing to different types of file descriptors. Must cast the pointer to the correct type before dereferencing to access the needed fields. |
Definition at line 284 of file fd_array.cc.
References _fdArray, fatal, and gem5::ArmISA::i.
int gem5::FDArray::closeFDEntry | ( | int | tgt_fd | ) |
Try to close the host file descriptor.
If successful, set the specified file descriptor entry object pointer to nullptr. Used to "close" the target file descriptor.
tgt_fd | Use target file descriptors to index the array. |
Definition at line 333 of file fd_array.cc.
References _fdArray, and gem5::ArmISA::status.
|
private |
Return the file descriptor entry object associated with the index provided.
(The index is protected with bounds checking on the array size without the use of the array's at operator.)
tgt_fd | Use target file descriptors to index the array. |
Definition at line 319 of file fd_array.cc.
References _fdArray.
Referenced by operator[]().
|
inline |
Return the size of the _fdArray field.
Definition at line 94 of file fd_array.hh.
References _fdArray.
|
private |
Help clarify our intention when opening files in the init and restoration code.
These are helper functions which are not meant to be exposed to other objects or files.
Definition at line 297 of file fd_array.cc.
References fatal, flags, and gem5::ArmISA::mode.
Referenced by openInputFile(), openOutputFile(), restoreFileOffsets(), and unserialize().
|
private |
Definition at line 306 of file fd_array.cc.
References openFile().
Referenced by restoreFileOffsets().
|
private |
Definition at line 312 of file fd_array.cc.
References openFile(), gem5::OutputDirectory::resolve(), and gem5::simout.
Referenced by restoreFileOffsets().
|
inline |
Treat this object like a normal array in using the subscript operator to pull entries out of it.
tgt_fd | Use target file descriptors to index the array. |
Definition at line 86 of file fd_array.hh.
References getFDEntry().
void gem5::FDArray::restoreFileOffsets | ( | ) |
Restore all offsets for currently open files during the unserialize phase for the owning process class.
Use this lambda to highlight what we mean to do with the seek. Notice that this either seeks correctly (sets the file location on the host) or it fails with a fatal. The error is fatal because it's not possible to guarantee that the simulation will proceed as it should have in the same way that it would have proceeded sans checkpoints.
Search through the input options and set fd if match is found; otherwise, open an input file and seek to location. Check if user has specified a different input file, and if so, use it instead of the file specified in the checkpoint. This also resets the file offset from the checkpointed value
Search through the output options and set fd if match is found; otherwise, open an output file and seek to location. Check if user has specified a different output file, and if so, use it instead of the file specified in the checkpoint. This also resets the file offset from the checkpointed value
Search through the error options and set fd if match is found; otherwise, open an error file and seek to location. Check if user has specified a different error file, and if so, use it instead of the file specified in the checkpoint. This also resets the file offset from the checkpointed value
Check which end of the pipe we are looking at; we only want to setup the pipe once so we arbitrarily choose the read end to be the end that sets up the pipe.
Reconstruct the ends of the pipe by reassigning the pipe that we created on the host. This one is the read end.
Grab the write end by referencing the read ends source and using that tgt_fd to index the array.
Yeah, how does one retain the entire driver state from this particular set of code? If you figure it out, add some code here to rectify the issue.
Assume that this has the mode of an output file so there's no need to worry about properly recording the mode. If you're reading this and this happens to be your issue, at least be happy that you've discovered the issue (and not mad at me). Onward ho!
Definition at line 125 of file fd_array.cc.
References _errout, _fdArray, _imap, _input, _oemap, _output, fatal, openFile(), openInputFile(), openOutputFile(), and warn.
|
overridevirtual |
Serialize an object.
Output an object's state into the current checkpoint section.
cp | Checkpoint state |
Implements gem5::Serializable.
Definition at line 354 of file fd_array.cc.
References _fdArray, gem5::csprintf(), gem5::ArmISA::fd, and gem5::paramOut().
void gem5::FDArray::setFDEntry | ( | int | tgt_fd, |
std::shared_ptr< FDEntry > | fdep | ||
) |
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd.
tgt_fd | Use target file descriptors to index the array. |
fdep | Incoming pointer used to set the entry pointed to by tgt_fd. |
Definition at line 326 of file fd_array.cc.
References _fdArray.
Referenced by unserialize().
|
overridevirtual |
Unserialize an object.
Read an object's state from the current checkpoint section.
cp | Checkpoint state |
Implements gem5::Serializable.
Definition at line 370 of file fd_array.cc.
References _fdArray, gem5::csprintf(), flags, gem5::ArmISA::mode, openFile(), panic, gem5::paramIn(), gem5::Serializable::path, and setFDEntry().
void gem5::FDArray::updateFileOffsets | ( | ) |
Figure out the file offsets for all currently open files and save them the offsets during the calls to drain by the owning process.
It only makes sense to check the offsets if the file descriptor type is 'File' (which indicates that this file is backed by a file on the host). If the type is File, then record the offset.
Use lseek with SEEK_CUR with offset 0 to figure out where the offset currently resides and pass that back to our setter.
Definition at line 102 of file fd_array.cc.
References _fdArray.
|
private |
Definition at line 154 of file fd_array.hh.
Referenced by restoreFileOffsets().
Definition at line 145 of file fd_array.hh.
Referenced by allocFD(), closeFDEntry(), getFDEntry(), getSize(), restoreFileOffsets(), serialize(), setFDEntry(), unserialize(), and updateFileOffsets().
|
private |
Hold strings which represent the default values which are checked against to initialize the standard file descriptors.
If the string provided doesn't hit against these maps, then a file is opened on the host instead of using the host's standard file descriptors.
Definition at line 162 of file fd_array.hh.
Referenced by restoreFileOffsets().
|
private |
Hold param strings passed from the Process class which indicate the filename for each of the corresponding files or some keyword indicating the use of standard file descriptors.
Definition at line 152 of file fd_array.hh.
Referenced by restoreFileOffsets().
|
staticconstexprprivate |
Hold pointers to the file descriptor entries.
The array size is statically defined by the operating system.
Definition at line 144 of file fd_array.hh.
|
private |
Definition at line 163 of file fd_array.hh.
Referenced by restoreFileOffsets().
|
private |
Definition at line 153 of file fd_array.hh.
Referenced by restoreFileOffsets().