gem5  v22.1.0.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
gem5::FDArray Class Reference

#include <fd_array.hh>

Inheritance diagram for gem5::FDArray:
gem5::Serializable

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< FDEntryoperator[] (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...
 
- 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. 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< FDEntrygetFDEntry (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 Public Member Functions inherited from gem5::Serializable
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...
 

Detailed Description

Definition at line 46 of file fd_array.hh.

Constructor & Destructor Documentation

◆ FDArray()

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.

Parameters
inputUsed to initialize the stdin file descriptor
outputUsed to initialize the stdout file descriptor
erroutUsed 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.

Member Function Documentation

◆ allocFD()

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.

Parameters
fdpAllocated 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 fatal, and gem5::ArmISA::i.

◆ closeFDEntry()

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.

Parameters
tgt_fdUse target file descriptors to index the array.

Definition at line 333 of file fd_array.cc.

References gem5::ArmISA::status.

◆ getFDEntry()

std::shared_ptr< FDEntry > gem5::FDArray::getFDEntry ( int  tgt_fd)
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.)

Parameters
tgt_fdUse target file descriptors to index the array.

Definition at line 319 of file fd_array.cc.

Referenced by operator[]().

◆ getSize()

int gem5::FDArray::getSize ( ) const
inline

Return the size of the _fdArray field.

Definition at line 94 of file fd_array.hh.

References _fdArray.

◆ openFile()

int gem5::FDArray::openFile ( std::string const &  file_name,
int  flags,
mode_t  mode 
) const
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.

◆ openInputFile()

int gem5::FDArray::openInputFile ( std::string const &  file_name) const
private

Definition at line 306 of file fd_array.cc.

◆ openOutputFile()

int gem5::FDArray::openOutputFile ( std::string const &  file_name) const
private

Definition at line 312 of file fd_array.cc.

References gem5::OutputDirectory::resolve(), and gem5::simout.

◆ operator[]()

std::shared_ptr<FDEntry> gem5::FDArray::operator[] ( int  tgt_fd)
inline

Treat this object like a normal array in using the subscript operator to pull entries out of it.

Parameters
tgt_fdUse target file descriptors to index the array.

Definition at line 86 of file fd_array.hh.

References getFDEntry().

◆ restoreFileOffsets()

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 fatal, and warn.

◆ serialize()

void gem5::FDArray::serialize ( CheckpointOut cp) const
overridevirtual

Serialize an object.

Output an object's state into the current checkpoint section.

Parameters
cpCheckpoint state

Implements gem5::Serializable.

Definition at line 354 of file fd_array.cc.

References gem5::csprintf(), gem5::ArmISA::fd, and gem5::paramOut().

◆ setFDEntry()

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.

Parameters
tgt_fdUse target file descriptors to index the array.
fdepIncoming pointer used to set the entry pointed to by tgt_fd.

Definition at line 326 of file fd_array.cc.

◆ unserialize()

void gem5::FDArray::unserialize ( CheckpointIn cp)
overridevirtual

Unserialize an object.

Read an object's state from the current checkpoint section.

Parameters
cpCheckpoint state

Implements gem5::Serializable.

Definition at line 370 of file fd_array.cc.

References gem5::csprintf(), flags, gem5::ArmISA::mode, panic, and gem5::paramIn().

◆ updateFileOffsets()

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.

Member Data Documentation

◆ _errout

std::string gem5::FDArray::_errout
private

Definition at line 154 of file fd_array.hh.

◆ _fdArray

std::array<std::shared_ptr<FDEntry>, _numFDs> gem5::FDArray::_fdArray
private

Definition at line 145 of file fd_array.hh.

Referenced by getSize().

◆ _imap

std::map<std::string, int> gem5::FDArray::_imap
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.

◆ _input

std::string gem5::FDArray::_input
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.

◆ _numFDs

constexpr size_t gem5::FDArray::_numFDs {1024}
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.

◆ _oemap

std::map<std::string, int> gem5::FDArray::_oemap
private

Definition at line 163 of file fd_array.hh.

◆ _output

std::string gem5::FDArray::_output
private

Definition at line 153 of file fd_array.hh.


The documentation for this class was generated from the following files:

Generated on Wed Dec 21 2022 10:23:29 for gem5 by doxygen 1.9.1