Go to the documentation of this file.
54 #include "debug/Ethernet.hh"
55 #include "debug/EthernetData.hh"
59 #include "params/EtherLink.hh"
70 p->delay,
p->delay_var,
p->dump);
72 p->delay,
p->delay_var,
p->dump);
91 if (if_name ==
"int0")
93 else if (if_name ==
"int1")
108 : objName(
name), parent(
p), number(num), txint(NULL), rxint(NULL),
109 ticksPerByte(rate), linkDelay(delay), delayVar(delay_var),
dump(
d),
111 txQueueEvent([
this]{ processTxQueue(); },
name)
131 DPRINTF(Ethernet,
"packet received: len=%d\n", packet->length);
132 DDUMP(EthernetData, packet->data, packet->length);
133 rxint->sendPacket(packet);
143 DPRINTF(Ethernet,
"packet delayed: delay=%d\n", linkDelay);
144 txQueue.emplace_back(std::make_pair(
curTick() + linkDelay, packet));
145 if (!txQueueEvent.scheduled())
146 parent->schedule(txQueueEvent, txQueue.front().first);
148 assert(txQueue.empty());
161 auto cur(txQueue.front());
165 if (!txQueue.empty()) {
166 auto next(txQueue.front());
167 assert(next.first >
curTick());
168 parent->schedule(txQueueEvent, next.first);
171 assert(cur.first ==
curTick());
172 txComplete(cur.second);
179 DPRINTF(Ethernet,
"packet not sent, link busy\n");
183 DPRINTF(Ethernet,
"packet sent: len=%d\n", pkt->length);
184 DDUMP(EthernetData, pkt->data, pkt->length);
187 Tick delay = (
Tick)ceil(((
double)pkt->simLength * ticksPerByte) + 1.0);
191 DPRINTF(Ethernet,
"scheduling packet: delay=%d, (rate=%f)\n",
192 delay, ticksPerByte);
193 parent->schedule(doneEvent,
curTick() + delay);
201 bool packet_exists = packet !=
nullptr;
204 packet->serialize(
base +
".packet",
cp);
206 bool event_scheduled = doneEvent.scheduled();
208 if (event_scheduled) {
209 Tick event_time = doneEvent.when();
213 const size_t tx_queue_size(txQueue.size());
216 for (
const auto &
pe : txQueue) {
230 packet = make_shared<EthPacketData>();
231 packet->unserialize(
base +
".packet",
cp);
234 bool event_scheduled;
236 if (event_scheduled) {
239 parent->schedule(doneEvent, event_time);
242 size_t tx_queue_size = 0;
244 for (
size_t idx = 0; idx < tx_queue_size; ++idx) {
246 EthPacketPtr delayed_packet = make_shared<EthPacketData>();
249 delayed_packet->unserialize(
252 fatal_if(!txQueue.empty() && txQueue.back().first > tick,
253 "Invalid txQueue packet order in EtherLink!\n");
254 txQueue.emplace_back(std::make_pair(tick, delayed_packet));
257 if (!txQueue.empty())
258 parent->schedule(txQueueEvent, txQueue.front().first);
263 warn(
"Old-style EtherLink serialization format detected, "
264 "in-flight packets may have been dropped.\n");
269 EtherLinkParams::create()
void unserialize(const std::string &base, CheckpointIn &cp)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Interface(const std::string &name, Link *txlink, Link *rxlink)
uint64_t Tick
Tick count type.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Link(const std::string &name, EtherLink *p, int num, double rate, Tick delay, Tick delay_var, EtherDump *dump)
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
bool optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, bool warn=true)
This function is used for restoring optional parameters from the checkpoint.
Ports are used to interface objects to each other.
const std::string & name()
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
virtual const std::string name() const
std::shared_ptr< EthPacketData > EthPacketPtr
Overload hash function for BasicBlockRange type.
bool transmit(EthPacketPtr packet)
void dump()
Dump all statistics data to the registered outputs.
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
std::ostream CheckpointOut
void setRxInt(Interface *i)
void setTxInt(Interface *i)
void serialize(CheckpointOut &cp) const override
Serialize an object.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
void serialize(const std::string &base, CheckpointOut &cp) const
std::string csprintf(const char *format, const Args &...args)
void txComplete(EthPacketPtr packet)
EtherLink(const Params *p)
Tick curTick()
The current simulated tick.
Abstract superclass for simulation objects.
Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17