gem5  v22.0.0.2
fd_array.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef __FD_ARRAY_HH__
33 #define __FD_ARRAY_HH__
34 
35 #include <array>
36 #include <map>
37 #include <memory>
38 #include <string>
39 
40 #include "sim/fd_entry.hh"
41 #include "sim/serialize.hh"
42 
43 namespace gem5
44 {
45 
46 class FDArray : public Serializable
47 {
48  public:
57  FDArray(std::string const& input, std::string const& output,
58  std::string const& errout);
59 
64  void updateFileOffsets();
65 
70  void restoreFileOffsets();
71 
78  void setFDEntry(int tgt_fd, std::shared_ptr<FDEntry> fdep);
79 
85  std::shared_ptr<FDEntry>
86  operator[](int tgt_fd)
87  {
88  return getFDEntry(tgt_fd);
89  }
90 
94  int getSize() const { return _fdArray.size(); }
95 
106  int allocFD(std::shared_ptr<FDEntry> fdp);
107 
114  int closeFDEntry(int tgt_fd);
115 
116  /*
117  * Serialization methods for file descriptors
118  */
119  void serialize(CheckpointOut &cp) const override;
120  void unserialize(CheckpointIn &cp) override;
121 
122  private:
128  int openFile(std::string const& file_name, int flags, mode_t mode) const;
129  int openInputFile(std::string const& file_name) const;
130  int openOutputFile(std::string const& file_name) const;
131 
138  std::shared_ptr<FDEntry> getFDEntry(int tgt_fd);
139 
144  static constexpr size_t _numFDs {1024};
145  std::array<std::shared_ptr<FDEntry>, _numFDs> _fdArray;
146 
152  std::string _input;
153  std::string _output;
154  std::string _errout;
155 
162  std::map<std::string, int> _imap;
163  std::map<std::string, int> _oemap;
164 };
165 
166 } // namespace gem5
167 
168 #endif // __FD_ARRAY_HH__
gem5::FDArray::restoreFileOffsets
void restoreFileOffsets()
Restore all offsets for currently open files during the unserialize phase for the owning process clas...
Definition: fd_array.cc:125
gem5::FDArray::allocFD
int allocFD(std::shared_ptr< FDEntry > fdp)
Step through the file descriptor array and find the first available entry which is denoted as being f...
Definition: fd_array.cc:284
gem5::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 pass...
Definition: fd_array.cc:49
fd_entry.hh
serialize.hh
gem5::output
static void output(const char *filename)
Definition: debug.cc:60
gem5::FDArray::_imap
std::map< std::string, int > _imap
Hold strings which represent the default values which are checked against to initialize the standard ...
Definition: fd_array.hh:162
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::FDArray::setFDEntry
void setFDEntry(int tgt_fd, std::shared_ptr< FDEntry > fdep)
Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd.
Definition: fd_array.cc:326
gem5::FDArray::_output
std::string _output
Definition: fd_array.hh:153
gem5::FDArray::openOutputFile
int openOutputFile(std::string const &file_name) const
Definition: fd_array.cc:312
gem5::FDArray::openFile
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.
Definition: fd_array.cc:297
gem5::FDArray::getSize
int getSize() const
Return the size of the _fdArray field.
Definition: fd_array.hh:94
gem5::FDArray::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: fd_array.cc:370
gem5::Serializable
Basic support for object serialization.
Definition: serialize.hh:169
gem5::FDArray::_fdArray
std::array< std::shared_ptr< FDEntry >, _numFDs > _fdArray
Definition: fd_array.hh:145
gem5::FDArray::_input
std::string _input
Hold param strings passed from the Process class which indicate the filename for each of the correspo...
Definition: fd_array.hh:152
gem5::FDArray::closeFDEntry
int closeFDEntry(int tgt_fd)
Try to close the host file descriptor.
Definition: fd_array.cc:333
gem5::FDArray::_oemap
std::map< std::string, int > _oemap
Definition: fd_array.hh:163
flags
uint8_t flags
Definition: helpers.cc:66
gem5::FDArray::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: fd_array.cc:354
gem5::FDArray::updateFileOffsets
void updateFileOffsets()
Figure out the file offsets for all currently open files and save them the offsets during the calls t...
Definition: fd_array.cc:102
gem5::FDArray::_numFDs
static constexpr size_t _numFDs
Hold pointers to the file descriptor entries.
Definition: fd_array.hh:144
gem5::FDArray
Definition: fd_array.hh:46
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::FDArray::getFDEntry
std::shared_ptr< FDEntry > getFDEntry(int tgt_fd)
Return the file descriptor entry object associated with the index provided.
Definition: fd_array.cc:319
gem5::FDArray::openInputFile
int openInputFile(std::string const &file_name) const
Definition: fd_array.cc:306
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::FDArray::_errout
std::string _errout
Definition: fd_array.hh:154
gem5::FDArray::operator[]
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.
Definition: fd_array.hh:86
gem5::ArmISA::mode
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74

Generated on Thu Jul 28 2022 13:32:36 for gem5 by doxygen 1.8.17