gem5  v21.1.0.2
pktfifo.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Regents of The University of Michigan
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
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __DEV_NET_PKTFIFO_HH__
30 #define __DEV_NET_PKTFIFO_HH__
31 
32 #include <iosfwd>
33 #include <list>
34 #include <string>
35 
36 #include "base/logging.hh"
37 #include "dev/net/etherpkt.hh"
38 #include "sim/serialize.hh"
39 
40 namespace gem5
41 {
42 
43 class Checkpoint;
44 
46 {
48  uint64_t number;
49  unsigned slack;
50  int priv;
51 
53  {
54  clear();
55  }
56 
59  {
60  }
61 
63  : packet(p), number(n), slack(0), priv(-1)
64  {
65  }
66 
67  void clear()
68  {
69  packet = NULL;
70  number = 0;
71  slack = 0;
72  priv = -1;
73  }
74 
75  void serialize(const std::string &base, CheckpointOut &cp) const;
76  void unserialize(const std::string &base, CheckpointIn &cp);
77 };
78 
80 {
81  public:
82 
84  typedef fifo_list::iterator iterator;
85  typedef fifo_list::const_iterator const_iterator;
86 
87  protected:
89  uint64_t _counter;
90  unsigned _maxsize;
91  unsigned _size;
92  unsigned _reserved;
93 
94  public:
95  explicit PacketFifo(int max)
96  : _counter(0), _maxsize(max), _size(0), _reserved(0) {}
97  virtual ~PacketFifo() {}
98 
99  unsigned packets() const { return fifo.size(); }
100  unsigned maxsize() const { return _maxsize; }
101  unsigned size() const { return _size; }
102  unsigned reserved() const { return _reserved; }
103  unsigned avail() const { return _maxsize - _size - _reserved; }
104  bool empty() const { return size() <= 0; }
105  bool full() const { return avail() <= 0; }
106 
107  unsigned
108  reserve(unsigned len = 0)
109  {
110  assert(avail() >= len);
111  _reserved += len;
112  return _reserved;
113  }
114 
115  iterator begin() { return fifo.begin(); }
116  iterator end() { return fifo.end(); }
117 
118  const_iterator begin() const { return fifo.begin(); }
119  const_iterator end() const { return fifo.end(); }
120 
121  EthPacketPtr front() { return fifo.begin()->packet; }
122 
123  bool push(EthPacketPtr ptr)
124  {
125  assert(ptr->length);
126  assert(_reserved <= ptr->length);
127  if (avail() < ptr->length - _reserved)
128  return false;
129 
130  _size += ptr->length;
131 
132  PacketFifoEntry entry;
133  entry.packet = ptr;
134  entry.number = _counter++;
135  fifo.push_back(entry);
136  _reserved = 0;
137  return true;
138  }
139 
140  void pop()
141  {
142  if (empty())
143  return;
144 
145  iterator entry = fifo.begin();
146  _size -= entry->packet->length;
147  _size -= entry->slack;
148  entry->packet = NULL;
149  fifo.pop_front();
150  }
151 
152  void clear()
153  {
154  for (iterator i = begin(); i != end(); ++i)
155  i->clear();
156  fifo.clear();
157  _size = 0;
158  _reserved = 0;
159  }
160 
162  {
163  if (i != fifo.begin()) {
164  iterator prev = i;
165  --prev;
166  assert(prev != fifo.end());
167  prev->slack += i->packet->length;
168  prev->slack += i->slack;
169  } else {
170  _size -= i->packet->length;
171  _size -= i->slack;
172  }
173 
174  i->clear();
175  fifo.erase(i);
176  }
177 
178  bool copyout(void *dest, unsigned offset, unsigned len);
179 
181  {
182  if (i == fifo.end())
183  return 0;
184  return i->number - fifo.begin()->number;
185  }
186 
188  {
189  auto end = fifo.end();
190  if (i == end)
191  return 0;
192  return (--end)->number - i->number;
193  }
194 
195  void check() const
196  {
197  unsigned total = 0;
198  for (auto i = begin(); i != end(); ++i)
199  total += i->packet->length + i->slack;
200 
201  if (total != _size)
202  panic("total (%d) is not == to size (%d)\n", total, _size);
203  }
204 
208  public:
209  void serialize(const std::string &base, CheckpointOut &cp) const;
210  void unserialize(const std::string &base, CheckpointIn &cp);
211 };
212 
213 } // namespace gem5
214 
215 #endif // __DEV_NET_PKTFIFO_HH__
gem5::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:444
gem5::PacketFifo::fifo_list
std::list< PacketFifoEntry > fifo_list
Definition: pktfifo.hh:83
gem5::PacketFifo::fifo
std::list< PacketFifoEntry > fifo
Definition: pktfifo.hh:88
gem5::PacketFifo::~PacketFifo
virtual ~PacketFifo()
Definition: pktfifo.hh:97
serialize.hh
gem5::PacketFifoEntry
Definition: pktfifo.hh:45
gem5::PacketFifo::const_iterator
fifo_list::const_iterator const_iterator
Definition: pktfifo.hh:85
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::PacketFifo::end
const_iterator end() const
Definition: pktfifo.hh:119
gem5::PacketFifoEntry::priv
int priv
Definition: pktfifo.hh:50
gem5::X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
gem5::PacketFifo::packets
unsigned packets() const
Definition: pktfifo.hh:99
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::PacketFifoEntry::PacketFifoEntry
PacketFifoEntry()
Definition: pktfifo.hh:52
gem5::PacketFifoEntry::PacketFifoEntry
PacketFifoEntry(const PacketFifoEntry &s)
Definition: pktfifo.hh:57
gem5::PacketFifo::begin
iterator begin()
Definition: pktfifo.hh:115
gem5::PacketFifo::size
unsigned size() const
Definition: pktfifo.hh:101
gem5::PacketFifo::_size
unsigned _size
Definition: pktfifo.hh:91
gem5::PacketFifoEntry::PacketFifoEntry
PacketFifoEntry(EthPacketPtr p, uint64_t n)
Definition: pktfifo.hh:62
gem5::PacketFifo::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: pktfifo.cc:100
gem5::PacketFifoEntry::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Definition: pktfifo.cc:68
gem5::PacketFifo::end
iterator end()
Definition: pktfifo.hh:116
gem5::PacketFifo::clear
void clear()
Definition: pktfifo.hh:152
gem5::PacketFifo::_maxsize
unsigned _maxsize
Definition: pktfifo.hh:90
gem5::EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::PacketFifo::reserved
unsigned reserved() const
Definition: pktfifo.hh:102
gem5::PacketFifo::begin
const_iterator begin() const
Definition: pktfifo.hh:118
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:561
gem5::PacketFifoEntry::packet
EthPacketPtr packet
Definition: pktfifo.hh:47
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::PacketFifo::remove
void remove(iterator i)
Definition: pktfifo.hh:161
gem5::PacketFifo::front
EthPacketPtr front()
Definition: pktfifo.hh:121
gem5::PacketFifo::push
bool push(EthPacketPtr ptr)
Definition: pktfifo.hh:123
gem5::PacketFifo::full
bool full() const
Definition: pktfifo.hh:105
gem5::PacketFifo::iterator
fifo_list::iterator iterator
Definition: pktfifo.hh:84
gem5::PacketFifoEntry::number
uint64_t number
Definition: pktfifo.hh:48
gem5::PacketFifoEntry::clear
void clear()
Definition: pktfifo.hh:67
gem5::PacketFifo::PacketFifo
PacketFifo(int max)
Definition: pktfifo.hh:95
gem5::PacketFifo::maxsize
unsigned maxsize() const
Definition: pktfifo.hh:100
gem5::PacketFifo::_counter
uint64_t _counter
Definition: pktfifo.hh:89
gem5::PacketFifoEntry::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: pktfifo.cc:77
gem5::ArmISA::n
Bitfield< 31 > n
Definition: misc_types.hh:455
gem5::PacketFifo::countPacketsBefore
int countPacketsBefore(const_iterator i) const
Definition: pktfifo.hh:180
gem5::PacketFifo::avail
unsigned avail() const
Definition: pktfifo.hh:103
gem5::PacketFifo::reserve
unsigned reserve(unsigned len=0)
Definition: pktfifo.hh:108
logging.hh
etherpkt.hh
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::PacketFifo::countPacketsAfter
int countPacketsAfter(const_iterator i) const
Definition: pktfifo.hh:187
std::list
STL list class.
Definition: stl.hh:51
gem5::PacketFifo
Definition: pktfifo.hh:79
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::statistics::total
const FlagsType total
Print the total.
Definition: info.hh:60
gem5::PacketFifo::pop
void pop()
Definition: pktfifo.hh:140
gem5::PacketFifo::copyout
bool copyout(void *dest, unsigned offset, unsigned len)
Definition: pktfifo.cc:37
gem5::PacketFifo::empty
bool empty() const
Definition: pktfifo.hh:104
gem5::PacketFifo::check
void check() const
Definition: pktfifo.hh:195
gem5::PacketFifo::_reserved
unsigned _reserved
Definition: pktfifo.hh:92
gem5::PacketFifo::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialization stuff.
Definition: pktfifo.cc:87
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::PacketFifoEntry::slack
unsigned slack
Definition: pktfifo.hh:49

Generated on Tue Sep 21 2021 12:25:17 for gem5 by doxygen 1.8.17