gem5  v21.2.1.1
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
69  {
70  packet = NULL;
71  number = 0;
72  slack = 0;
73  priv = -1;
74  }
75 
76  void serialize(const std::string &base, CheckpointOut &cp) const;
77  void unserialize(const std::string &base, CheckpointIn &cp);
78 };
79 
81 {
82  public:
83 
85  typedef fifo_list::iterator iterator;
86  typedef fifo_list::const_iterator const_iterator;
87 
88  protected:
90  uint64_t _counter;
91  unsigned _maxsize;
92  unsigned _size;
93  unsigned _reserved;
94 
95  public:
96  explicit PacketFifo(int max)
97  : _counter(0), _maxsize(max), _size(0), _reserved(0) {}
98  virtual ~PacketFifo() {}
99 
100  unsigned packets() const { return fifo.size(); }
101  unsigned maxsize() const { return _maxsize; }
102  unsigned size() const { return _size; }
103  unsigned reserved() const { return _reserved; }
104  unsigned avail() const { return _maxsize - _size - _reserved; }
105  bool empty() const { return size() <= 0; }
106  bool full() const { return avail() <= 0; }
107 
108  unsigned
109  reserve(unsigned len = 0)
110  {
111  assert(avail() >= len);
112  _reserved += len;
113  return _reserved;
114  }
115 
116  iterator begin() { return fifo.begin(); }
117  iterator end() { return fifo.end(); }
118 
119  const_iterator begin() const { return fifo.begin(); }
120  const_iterator end() const { return fifo.end(); }
121 
122  EthPacketPtr front() { return fifo.begin()->packet; }
123 
124  bool
126  {
127  assert(ptr->length);
128  assert(_reserved <= ptr->length);
129  if (avail() < ptr->length - _reserved)
130  return false;
131 
132  _size += ptr->length;
133 
134  PacketFifoEntry entry;
135  entry.packet = ptr;
136  entry.number = _counter++;
137  fifo.push_back(entry);
138  _reserved = 0;
139  return true;
140  }
141 
142  void
143  pop()
144  {
145  if (empty())
146  return;
147 
148  iterator entry = fifo.begin();
149  _size -= entry->packet->length;
150  _size -= entry->slack;
151  entry->packet = NULL;
152  fifo.pop_front();
153  }
154 
155  void
157  {
158  for (iterator i = begin(); i != end(); ++i)
159  i->clear();
160  fifo.clear();
161  _size = 0;
162  _reserved = 0;
163  }
164 
165  void
167  {
168  if (i != fifo.begin()) {
169  iterator prev = i;
170  --prev;
171  assert(prev != fifo.end());
172  prev->slack += i->packet->length;
173  prev->slack += i->slack;
174  } else {
175  _size -= i->packet->length;
176  _size -= i->slack;
177  }
178 
179  i->clear();
180  fifo.erase(i);
181  }
182 
183  bool copyout(void *dest, unsigned offset, unsigned len);
184 
185  int
187  {
188  if (i == fifo.end())
189  return 0;
190  return i->number - fifo.begin()->number;
191  }
192 
193  int
195  {
196  auto end = fifo.end();
197  if (i == end)
198  return 0;
199  return (--end)->number - i->number;
200  }
201 
202  void
203  check() const
204  {
205  unsigned total = 0;
206  for (auto i = begin(); i != end(); ++i)
207  total += i->packet->length + i->slack;
208 
209  if (total != _size)
210  panic("total (%d) is not == to size (%d)\n", total, _size);
211  }
212 
216  public:
217  void serialize(const std::string &base, CheckpointOut &cp) const;
218  void unserialize(const std::string &base, CheckpointIn &cp);
219 };
220 
221 } // namespace gem5
222 
223 #endif // __DEV_NET_PKTFIFO_HH__
gem5::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:445
gem5::PacketFifo::fifo_list
std::list< PacketFifoEntry > fifo_list
Definition: pktfifo.hh:84
gem5::PacketFifo::fifo
std::list< PacketFifoEntry > fifo
Definition: pktfifo.hh:89
gem5::PacketFifo::~PacketFifo
virtual ~PacketFifo()
Definition: pktfifo.hh:98
serialize.hh
gem5::PacketFifoEntry
Definition: pktfifo.hh:45
gem5::PacketFifo::const_iterator
fifo_list::const_iterator const_iterator
Definition: pktfifo.hh:86
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::PacketFifo::end
const_iterator end() const
Definition: pktfifo.hh:120
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:100
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
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:116
gem5::PacketFifo::size
unsigned size() const
Definition: pktfifo.hh:102
gem5::PacketFifo::_size
unsigned _size
Definition: pktfifo.hh:92
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:117
gem5::PacketFifo::clear
void clear()
Definition: pktfifo.hh:156
gem5::PacketFifo::_maxsize
unsigned _maxsize
Definition: pktfifo.hh:91
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:103
gem5::PacketFifo::begin
const_iterator begin() const
Definition: pktfifo.hh:119
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:562
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:166
gem5::PacketFifo::front
EthPacketPtr front()
Definition: pktfifo.hh:122
gem5::PacketFifo::push
bool push(EthPacketPtr ptr)
Definition: pktfifo.hh:125
gem5::PacketFifo::full
bool full() const
Definition: pktfifo.hh:106
gem5::PacketFifo::iterator
fifo_list::iterator iterator
Definition: pktfifo.hh:85
gem5::PacketFifoEntry::number
uint64_t number
Definition: pktfifo.hh:48
gem5::PacketFifoEntry::clear
void clear()
Definition: pktfifo.hh:68
gem5::PacketFifo::PacketFifo
PacketFifo(int max)
Definition: pktfifo.hh:96
gem5::PacketFifo::maxsize
unsigned maxsize() const
Definition: pktfifo.hh:101
gem5::PacketFifo::_counter
uint64_t _counter
Definition: pktfifo.hh:90
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:456
gem5::PacketFifo::countPacketsBefore
int countPacketsBefore(const_iterator i) const
Definition: pktfifo.hh:186
gem5::PacketFifo::avail
unsigned avail() const
Definition: pktfifo.hh:104
gem5::PacketFifo::reserve
unsigned reserve(unsigned len=0)
Definition: pktfifo.hh:109
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:194
std::list
STL list class.
Definition: stl.hh:51
gem5::PacketFifo
Definition: pktfifo.hh:80
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::statistics::total
const FlagsType total
Print the total.
Definition: info.hh:60
gem5::PacketFifo::pop
void pop()
Definition: pktfifo.hh:143
gem5::PacketFifo::copyout
bool copyout(void *dest, unsigned offset, unsigned len)
Definition: pktfifo.cc:37
gem5::PacketFifo::empty
bool empty() const
Definition: pktfifo.hh:105
gem5::PacketFifo::check
void check() const
Definition: pktfifo.hh:203
gem5::PacketFifo::_reserved
unsigned _reserved
Definition: pktfifo.hh:93
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:178
gem5::PacketFifoEntry::slack
unsigned slack
Definition: pktfifo.hh:49

Generated on Wed May 4 2022 12:13:57 for gem5 by doxygen 1.8.17