gem5 v24.0.0.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. | |
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. | |
void | restoreFileOffsets () |
Restore all offsets for currently open files during the unserialize phase for the owning process class. | |
void | setFDEntry (int tgt_fd, std::shared_ptr< FDEntry > fdep) |
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd. | |
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. | |
int | getSize () const |
Return the size of the _fdArray field. | |
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'. | |
int | closeFDEntry (int tgt_fd) |
Try to close the host file descriptor. | |
void | serialize (CheckpointOut &cp) const override |
Serialize an object. | |
void | unserialize (CheckpointIn &cp, Process *process_ptr) |
void | unserialize (CheckpointIn &cp) override |
Unserialize an object. | |
Public Member Functions inherited from gem5::Serializable | |
Serializable () | |
virtual | ~Serializable () |
void | serializeSection (CheckpointOut &cp, const char *name) const |
Serialize an object into a new section. | |
void | serializeSection (CheckpointOut &cp, const std::string &name) const |
void | unserializeSection (CheckpointIn &cp, const char *name) |
Unserialize an a child object. | |
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. | |
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. | |
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. | |
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. | |
std::map< std::string, int > | _oemap |
Static Private Attributes | |
static constexpr size_t | _numFDs {1024} |
Hold pointers to the file descriptor entries. | |
Additional Inherited Members | |
Static Public Member Functions inherited from gem5::Serializable | |
static const std::string & | currentSection () |
Gets the fully-qualified name of the active section. | |
static void | generateCheckpointOut (const std::string &cpt_dir, std::ofstream &outstream) |
Generate a checkpoint file so that the serialization can be routed to it. | |
Definition at line 48 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 50 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 285 of file fd_array.cc.
References 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 334 of file fd_array.cc.
References 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 320 of file fd_array.cc.
Referenced by operator[]().
|
inline |
Return the size of the _fdArray field.
Definition at line 96 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 298 of file fd_array.cc.
References fatal, flags, and gem5::ArmISA::mode.
|
private |
Definition at line 307 of file fd_array.cc.
|
private |
Definition at line 313 of file fd_array.cc.
References gem5::OutputDirectory::resolve(), and gem5::simout.
|
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 88 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 126 of file fd_array.cc.
|
overridevirtual |
Serialize an object.
Output an object's state into the current checkpoint section.
cp | Checkpoint state |
Implements gem5::Serializable.
Definition at line 355 of file fd_array.cc.
References 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 327 of file fd_array.cc.
|
inlineoverridevirtual |
Unserialize an object.
Read an object's state from the current checkpoint section.
cp | Checkpoint state |
Implements gem5::Serializable.
Definition at line 123 of file fd_array.hh.
References unserialize().
void gem5::FDArray::unserialize | ( | CheckpointIn & | cp, |
Process * | process_ptr ) |
Definition at line 371 of file fd_array.cc.
References gem5::Process::checkPathRedirect(), gem5::csprintf(), flags, gem5::ArmISA::mode, panic, and gem5::paramIn().
Referenced by unserialize().
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 103 of file fd_array.cc.
|
private |
Definition at line 160 of file fd_array.hh.
Definition at line 151 of file fd_array.hh.
Referenced by getSize().
|
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 168 of file fd_array.hh.
|
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 158 of file fd_array.hh.
|
staticconstexprprivate |
Hold pointers to the file descriptor entries.
The array size is statically defined by the operating system.
Definition at line 150 of file fd_array.hh.
|
private |
Definition at line 169 of file fd_array.hh.
|
private |
Definition at line 159 of file fd_array.hh.