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

#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< 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...
 

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...
 

Detailed Description

Definition at line 43 of file fd_array.hh.

Constructor & Destructor Documentation

◆ FDArray()

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 48 of file fd_array.cc.

Member Function Documentation

◆ allocFD()

int 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 283 of file fd_array.cc.

References _fdArray, fatal, and ArmISA::i.

◆ closeFDEntry()

int 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 332 of file fd_array.cc.

References _fdArray, and ArmISA::status.

◆ getFDEntry()

std::shared_ptr< FDEntry > 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 318 of file fd_array.cc.

References _fdArray.

Referenced by operator[]().

◆ getSize()

int FDArray::getSize ( ) const
inline

Return the size of the _fdArray field.

Definition at line 91 of file fd_array.hh.

References _fdArray.

◆ openFile()

int 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 296 of file fd_array.cc.

References fatal, and ArmISA::mode.

Referenced by openInputFile(), openOutputFile(), and restoreFileOffsets().

◆ openInputFile()

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

Definition at line 305 of file fd_array.cc.

References openFile().

Referenced by restoreFileOffsets().

◆ openOutputFile()

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

Definition at line 311 of file fd_array.cc.

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

Referenced by restoreFileOffsets().

◆ operator[]()

std::shared_ptr<FDEntry> 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 83 of file fd_array.hh.

References getFDEntry().

◆ restoreFileOffsets()

void 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 124 of file fd_array.cc.

References _errout, _fdArray, _imap, _input, _oemap, _output, fatal, openFile(), openInputFile(), openOutputFile(), and warn.

◆ setFDEntry()

void 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 325 of file fd_array.cc.

References _fdArray.

◆ updateFileOffsets()

void 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 101 of file fd_array.cc.

References _fdArray.

Member Data Documentation

◆ _errout

std::string FDArray::_errout
private

Definition at line 145 of file fd_array.hh.

Referenced by restoreFileOffsets().

◆ _fdArray

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

◆ _imap

std::map<std::string, int> 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 153 of file fd_array.hh.

Referenced by restoreFileOffsets().

◆ _input

std::string 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 143 of file fd_array.hh.

Referenced by restoreFileOffsets().

◆ _numFDs

constexpr size_t FDArray::_numFDs {1024}
staticconstexprprivate

Hold pointers to the file descriptor entries.

The array size is statically defined by the operating system.

Definition at line 135 of file fd_array.hh.

◆ _oemap

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

Definition at line 154 of file fd_array.hh.

Referenced by restoreFileOffsets().

◆ _output

std::string FDArray::_output
private

Definition at line 144 of file fd_array.hh.

Referenced by restoreFileOffsets().


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

Generated on Wed Sep 30 2020 14:02:24 for gem5 by doxygen 1.8.17