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

Generated on Fri Jun 9 2017 13:03:46 for gem5 by doxygen 1.8.6