gem5  v20.1.0.0
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 class Checkpoint;
41 
43 {
45  uint64_t number;
46  unsigned slack;
47  int priv;
48 
50  {
51  clear();
52  }
53 
56  {
57  }
58 
60  : packet(p), number(n), slack(0), priv(-1)
61  {
62  }
63 
64  void clear()
65  {
66  packet = NULL;
67  number = 0;
68  slack = 0;
69  priv = -1;
70  }
71 
72  void serialize(const std::string &base, CheckpointOut &cp) const;
73  void unserialize(const std::string &base, CheckpointIn &cp);
74 };
75 
77 {
78  public:
79 
81  typedef fifo_list::iterator iterator;
82  typedef fifo_list::const_iterator const_iterator;
83 
84  protected:
86  uint64_t _counter;
87  unsigned _maxsize;
88  unsigned _size;
89  unsigned _reserved;
90 
91  public:
92  explicit PacketFifo(int max)
93  : _counter(0), _maxsize(max), _size(0), _reserved(0) {}
94  virtual ~PacketFifo() {}
95 
96  unsigned packets() const { return fifo.size(); }
97  unsigned maxsize() const { return _maxsize; }
98  unsigned size() const { return _size; }
99  unsigned reserved() const { return _reserved; }
100  unsigned avail() const { return _maxsize - _size - _reserved; }
101  bool empty() const { return size() <= 0; }
102  bool full() const { return avail() <= 0; }
103 
104  unsigned
105  reserve(unsigned len = 0)
106  {
107  assert(avail() >= len);
108  _reserved += len;
109  return _reserved;
110  }
111 
112  iterator begin() { return fifo.begin(); }
113  iterator end() { return fifo.end(); }
114 
115  const_iterator begin() const { return fifo.begin(); }
116  const_iterator end() const { return fifo.end(); }
117 
118  EthPacketPtr front() { return fifo.begin()->packet; }
119 
120  bool push(EthPacketPtr ptr)
121  {
122  assert(ptr->length);
123  assert(_reserved <= ptr->length);
124  if (avail() < ptr->length - _reserved)
125  return false;
126 
127  _size += ptr->length;
128 
129  PacketFifoEntry entry;
130  entry.packet = ptr;
131  entry.number = _counter++;
132  fifo.push_back(entry);
133  _reserved = 0;
134  return true;
135  }
136 
137  void pop()
138  {
139  if (empty())
140  return;
141 
142  iterator entry = fifo.begin();
143  _size -= entry->packet->length;
144  _size -= entry->slack;
145  entry->packet = NULL;
146  fifo.pop_front();
147  }
148 
149  void clear()
150  {
151  for (iterator i = begin(); i != end(); ++i)
152  i->clear();
153  fifo.clear();
154  _size = 0;
155  _reserved = 0;
156  }
157 
159  {
160  if (i != fifo.begin()) {
161  iterator prev = i;
162  --prev;
163  assert(prev != fifo.end());
164  prev->slack += i->packet->length;
165  prev->slack += i->slack;
166  } else {
167  _size -= i->packet->length;
168  _size -= i->slack;
169  }
170 
171  i->clear();
172  fifo.erase(i);
173  }
174 
175  bool copyout(void *dest, unsigned offset, unsigned len);
176 
178  {
179  if (i == fifo.end())
180  return 0;
181  return i->number - fifo.begin()->number;
182  }
183 
185  {
186  auto end = fifo.end();
187  if (i == end)
188  return 0;
189  return (--end)->number - i->number;
190  }
191 
192  void check() const
193  {
194  unsigned total = 0;
195  for (auto i = begin(); i != end(); ++i)
196  total += i->packet->length + i->slack;
197 
198  if (total != _size)
199  panic("total (%d) is not == to size (%d)\n", total, _size);
200  }
201 
205  public:
206  void serialize(const std::string &base, CheckpointOut &cp) const;
207  void unserialize(const std::string &base, CheckpointIn &cp);
208 };
209 
210 #endif // __DEV_NET_PKTFIFO_HH__
PacketFifo::countPacketsBefore
int countPacketsBefore(const_iterator i) const
Definition: pktfifo.hh:177
PacketFifo::push
bool push(EthPacketPtr ptr)
Definition: pktfifo.hh:120
PacketFifo::~PacketFifo
virtual ~PacketFifo()
Definition: pktfifo.hh:94
length
uint8_t length
Definition: inet.hh:422
PacketFifo
Definition: pktfifo.hh:76
PacketFifo::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialization stuff.
Definition: pktfifo.cc:86
serialize.hh
PacketFifoEntry::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Definition: pktfifo.cc:67
PacketFifo::const_iterator
fifo_list::const_iterator const_iterator
Definition: pktfifo.hh:82
PacketFifo::pop
void pop()
Definition: pktfifo.hh:137
PacketFifo::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: pktfifo.cc:99
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
PacketFifo::remove
void remove(iterator i)
Definition: pktfifo.hh:158
PacketFifo::full
bool full() const
Definition: pktfifo.hh:102
X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
PacketFifo::begin
const_iterator begin() const
Definition: pktfifo.hh:115
PacketFifoEntry::clear
void clear()
Definition: pktfifo.hh:64
PacketFifo::end
iterator end()
Definition: pktfifo.hh:113
PacketFifoEntry
Definition: pktfifo.hh:42
PacketFifo::_maxsize
unsigned _maxsize
Definition: pktfifo.hh:87
PacketFifo::_counter
uint64_t _counter
Definition: pktfifo.hh:86
PacketFifo::_size
unsigned _size
Definition: pktfifo.hh:88
PacketFifo::copyout
bool copyout(void *dest, unsigned offset, unsigned len)
Definition: pktfifo.cc:36
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
cp
Definition: cprintf.cc:40
PacketFifo::_reserved
unsigned _reserved
Definition: pktfifo.hh:89
PacketFifo::size
unsigned size() const
Definition: pktfifo.hh:98
PacketFifoEntry::PacketFifoEntry
PacketFifoEntry(const PacketFifoEntry &s)
Definition: pktfifo.hh:54
PacketFifo::fifo
std::list< PacketFifoEntry > fifo
Definition: pktfifo.hh:85
PacketFifoEntry::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: pktfifo.cc:76
PacketFifoEntry::priv
int priv
Definition: pktfifo.hh:47
PacketFifo::check
void check() const
Definition: pktfifo.hh:192
PacketFifo::fifo_list
std::list< PacketFifoEntry > fifo_list
Definition: pktfifo.hh:80
PacketFifoEntry::slack
unsigned slack
Definition: pktfifo.hh:46
PacketFifoEntry::PacketFifoEntry
PacketFifoEntry(EthPacketPtr p, uint64_t n)
Definition: pktfifo.hh:59
PacketFifo::iterator
fifo_list::iterator iterator
Definition: pktfifo.hh:81
EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:87
PacketFifo::PacketFifo
PacketFifo(int max)
Definition: pktfifo.hh:92
PacketFifo::packets
unsigned packets() const
Definition: pktfifo.hh:96
PacketFifo::empty
bool empty() const
Definition: pktfifo.hh:101
PacketFifo::avail
unsigned avail() const
Definition: pktfifo.hh:100
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
PacketFifo::clear
void clear()
Definition: pktfifo.hh:149
logging.hh
etherpkt.hh
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
PacketFifo::front
EthPacketPtr front()
Definition: pktfifo.hh:118
PacketFifo::end
const_iterator end() const
Definition: pktfifo.hh:116
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
PacketFifo::maxsize
unsigned maxsize() const
Definition: pktfifo.hh:97
std::list< PacketFifoEntry >
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
PacketFifoEntry::packet
EthPacketPtr packet
Definition: pktfifo.hh:44
Stats::total
const FlagsType total
Print the total.
Definition: info.hh:49
CheckpointIn
Definition: serialize.hh:67
PacketFifo::reserve
unsigned reserve(unsigned len=0)
Definition: pktfifo.hh:105
PacketFifoEntry::PacketFifoEntry
PacketFifoEntry()
Definition: pktfifo.hh:49
PacketFifo::reserved
unsigned reserved() const
Definition: pktfifo.hh:99
PacketFifo::countPacketsAfter
int countPacketsAfter(const_iterator i) const
Definition: pktfifo.hh:184
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153
PacketFifoEntry::number
uint64_t number
Definition: pktfifo.hh:45
PacketFifo::begin
iterator begin()
Definition: pktfifo.hh:112

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