gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
40namespace gem5
41{
42
43class Checkpoint;
44
46{
48 uint64_t number;
49 unsigned slack;
50 int priv;
51
53 {
54 clear();
55 }
56
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
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__
void serialize(const std::string &base, CheckpointOut &cp) const
Serialization stuff.
Definition pktfifo.cc:87
unsigned _size
Definition pktfifo.hh:92
unsigned reserve(unsigned len=0)
Definition pktfifo.hh:109
std::list< PacketFifoEntry > fifo
Definition pktfifo.hh:89
unsigned _reserved
Definition pktfifo.hh:93
iterator begin()
Definition pktfifo.hh:116
PacketFifo(int max)
Definition pktfifo.hh:96
virtual ~PacketFifo()
Definition pktfifo.hh:98
unsigned avail() const
Definition pktfifo.hh:104
const_iterator end() const
Definition pktfifo.hh:120
void unserialize(const std::string &base, CheckpointIn &cp)
Definition pktfifo.cc:100
unsigned reserved() const
Definition pktfifo.hh:103
unsigned packets() const
Definition pktfifo.hh:100
unsigned maxsize() const
Definition pktfifo.hh:101
EthPacketPtr front()
Definition pktfifo.hh:122
bool push(EthPacketPtr ptr)
Definition pktfifo.hh:125
bool empty() const
Definition pktfifo.hh:105
int countPacketsBefore(const_iterator i) const
Definition pktfifo.hh:186
bool full() const
Definition pktfifo.hh:106
int countPacketsAfter(const_iterator i) const
Definition pktfifo.hh:194
fifo_list::iterator iterator
Definition pktfifo.hh:85
unsigned size() const
Definition pktfifo.hh:102
const_iterator begin() const
Definition pktfifo.hh:119
std::list< PacketFifoEntry > fifo_list
Definition pktfifo.hh:84
uint64_t _counter
Definition pktfifo.hh:90
void remove(iterator i)
Definition pktfifo.hh:166
iterator end()
Definition pktfifo.hh:117
unsigned _maxsize
Definition pktfifo.hh:91
bool copyout(void *dest, unsigned offset, unsigned len)
Definition pktfifo.cc:37
void check() const
Definition pktfifo.hh:203
fifo_list::const_iterator const_iterator
Definition pktfifo.hh:86
STL list class.
Definition stl.hh:51
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 31 > n
Bitfield< 18, 16 > len
Bitfield< 4 > s
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 0 > p
Bitfield< 51, 12 > base
Definition pagetable.hh:141
const FlagsType total
Print the total.
Definition info.hh:59
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
std::shared_ptr< EthPacketData > EthPacketPtr
Definition etherpkt.hh:90
void serialize(const std::string &base, CheckpointOut &cp) const
Definition pktfifo.cc:68
PacketFifoEntry(EthPacketPtr p, uint64_t n)
Definition pktfifo.hh:62
void unserialize(const std::string &base, CheckpointIn &cp)
Definition pktfifo.cc:77
EthPacketPtr packet
Definition pktfifo.hh:47
PacketFifoEntry(const PacketFifoEntry &s)
Definition pktfifo.hh:57

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0