gem5
v20.1.0.0
dev
net
pktfifo.cc
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
#include "
dev/net/pktfifo.hh
"
30
31
#include "
base/logging.hh
"
32
33
using namespace
std
;
34
35
bool
36
PacketFifo::copyout
(
void
*dest,
unsigned
offset
,
unsigned
len
)
37
{
38
char
*
data
= (
char
*)dest;
39
if
(
offset
+
len
>= size())
40
return
false
;
41
42
iterator
i
= fifo.begin();
43
iterator
end = fifo.end();
44
while
(
len
> 0) {
45
EthPacketPtr
&pkt =
i
->packet;
46
while
(
offset
>= pkt->length) {
47
offset
-= pkt->length;
48
++
i
;
49
}
50
51
if
(
i
== end)
52
panic
(
"invalid fifo"
);
53
54
unsigned
size = min(pkt->length -
offset
,
len
);
55
memcpy(
data
, pkt->data, size);
56
offset
= 0;
57
len
-= size;
58
data
+= size;
59
++
i
;
60
}
61
62
return
true
;
63
}
64
65
66
void
67
PacketFifoEntry::serialize
(
const
string
&
base
,
CheckpointOut
&
cp
)
const
68
{
69
packet->serialize(
base
+
".packet"
,
cp
);
70
paramOut
(
cp
,
base
+
".slack"
, slack);
71
paramOut
(
cp
,
base
+
".number"
, number);
72
paramOut
(
cp
,
base
+
".priv"
,
priv
);
73
}
74
75
void
76
PacketFifoEntry::unserialize
(
const
string
&
base
,
CheckpointIn
&
cp
)
77
{
78
packet = make_shared<EthPacketData>();
79
packet->unserialize(
base
+
".packet"
,
cp
);
80
paramIn
(
cp
,
base
+
".slack"
, slack);
81
paramIn
(
cp
,
base
+
".number"
, number);
82
paramIn
(
cp
,
base
+
".priv"
,
priv
);
83
}
84
85
void
86
PacketFifo::serialize
(
const
string
&
base
,
CheckpointOut
&
cp
)
const
87
{
88
paramOut
(
cp
,
base
+
".size"
, _size);
89
paramOut
(
cp
,
base
+
".maxsize"
, _maxsize);
90
paramOut
(
cp
,
base
+
".reserved"
, _reserved);
91
paramOut
(
cp
,
base
+
".packets"
, fifo.size());
92
93
int
i
= 0;
94
for
(
const
auto
&entry : fifo)
95
entry.serialize(
csprintf
(
"%s.entry%d"
,
base
,
i
++),
cp
);
96
}
97
98
void
99
PacketFifo::unserialize
(
const
string
&
base
,
CheckpointIn
&
cp
)
100
{
101
paramIn
(
cp
,
base
+
".size"
, _size);
102
// paramIn(cp, base + ".maxsize", _maxsize);
103
paramIn
(
cp
,
base
+
".reserved"
, _reserved);
104
int
fifosize;
105
paramIn
(
cp
,
base
+
".packets"
, fifosize);
106
107
fifo.clear();
108
109
for
(
int
i
= 0;
i
< fifosize; ++
i
) {
110
PacketFifoEntry
entry;
111
entry.
unserialize
(
csprintf
(
"%s.entry%d"
,
base
,
i
),
cp
);
112
fifo.push_back(entry);
113
}
114
}
data
const char data[]
Definition:
circlebuf.test.cc:42
PacketFifo::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Serialization stuff.
Definition:
pktfifo.cc:86
PacketFifoEntry::serialize
void serialize(const std::string &base, CheckpointOut &cp) const
Definition:
pktfifo.cc:67
PacketFifo::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Definition:
pktfifo.cc:99
ArmISA::i
Bitfield< 7 > i
Definition:
miscregs_types.hh:63
X86ISA::base
Bitfield< 51, 12 > base
Definition:
pagetable.hh:141
PacketFifoEntry
Definition:
pktfifo.hh:42
paramOut
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
Definition:
types.cc:38
PacketFifo::copyout
bool copyout(void *dest, unsigned offset, unsigned len)
Definition:
pktfifo.cc:36
SparcISA::priv
Bitfield< 2 > priv
Definition:
miscregs.hh:126
cp
Definition:
cprintf.cc:40
PacketFifoEntry::unserialize
void unserialize(const std::string &base, CheckpointIn &cp)
Definition:
pktfifo.cc:76
PacketFifo::iterator
fifo_list::iterator iterator
Definition:
pktfifo.hh:81
EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition:
etherpkt.hh:87
std
Overload hash function for BasicBlockRange type.
Definition:
vec_reg.hh:587
ArmISA::len
Bitfield< 18, 16 > len
Definition:
miscregs_types.hh:439
paramIn
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
Definition:
types.cc:69
logging.hh
pktfifo.hh
CheckpointOut
std::ostream CheckpointOut
Definition:
serialize.hh:63
CheckpointIn
Definition:
serialize.hh:67
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition:
cprintf.hh:158
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition:
logging.hh:171
ArmISA::offset
Bitfield< 23, 0 > offset
Definition:
types.hh:153
Generated on Wed Sep 30 2020 14:02:11 for gem5 by
doxygen
1.8.17