55#include "debug/Ethernet.hh"
56#include "debug/EthernetData.hh"
60#include "params/EtherLink.hh"
72 p.delay,
p.delay_var,
p.dump);
74 p.delay,
p.delay_var,
p.dump);
93 if (if_name ==
"int0")
95 else if (if_name ==
"int1")
110 : objName(
name), parent(
p), number(num), txint(NULL), rxint(NULL),
111 ticksPerByte(rate), linkDelay(delay), delayVar(delay_var),
dump(
d),
113 txQueueEvent([
this]{ processTxQueue(); },
name)
133 DPRINTF(Ethernet,
"packet received: len=%d\n", packet->length);
134 DDUMP(EthernetData, packet->data, packet->length);
135 rxint->sendPacket(packet);
145 DPRINTF(Ethernet,
"packet delayed: delay=%d\n", linkDelay);
146 txQueue.emplace_back(std::make_pair(
curTick() + linkDelay, packet));
147 if (!txQueueEvent.scheduled())
148 parent->schedule(txQueueEvent, txQueue.front().first);
150 assert(txQueue.empty());
163 auto cur(txQueue.front());
167 if (!txQueue.empty()) {
168 auto next(txQueue.front());
169 assert(next.first >
curTick());
170 parent->schedule(txQueueEvent, next.first);
173 assert(cur.first ==
curTick());
174 txComplete(cur.second);
181 DPRINTF(Ethernet,
"packet not sent, link busy\n");
185 DPRINTF(Ethernet,
"packet sent: len=%d\n", pkt->length);
186 DDUMP(EthernetData, pkt->data, pkt->length);
189 Tick delay = (
Tick)ceil(((
double)pkt->simLength * ticksPerByte) + 1.0);
191 delay += rng->random<
Tick>(0, delayVar);
193 DPRINTF(Ethernet,
"scheduling packet: delay=%d, (rate=%f)\n",
194 delay, ticksPerByte);
195 parent->schedule(doneEvent,
curTick() + delay);
203 bool packet_exists = packet !=
nullptr;
206 packet->serialize(
base +
".packet", cp);
208 bool event_scheduled = doneEvent.scheduled();
209 paramOut(cp,
base +
".event_scheduled", event_scheduled);
210 if (event_scheduled) {
211 Tick event_time = doneEvent.when();
215 const size_t tx_queue_size(txQueue.size());
218 for (
const auto &
pe : txQueue) {
220 pe.second->serialize(
csprintf(
"%s.txQueue[%i].packet",
base, idx), cp);
230 paramIn(cp,
base +
".packet_exists", packet_exists);
232 packet = std::make_shared<EthPacketData>();
233 packet->unserialize(
base +
".packet", cp);
236 bool event_scheduled;
237 paramIn(cp,
base +
".event_scheduled", event_scheduled);
238 if (event_scheduled) {
241 parent->schedule(doneEvent, event_time);
244 size_t tx_queue_size = 0;
246 for (
size_t idx = 0; idx < tx_queue_size; ++idx) {
248 EthPacketPtr delayed_packet = std::make_shared<EthPacketData>();
251 delayed_packet->unserialize(
254 fatal_if(!txQueue.empty() && txQueue.back().first > tick,
255 "Invalid txQueue packet order in EtherLink!\n");
256 txQueue.emplace_back(std::make_pair(tick, delayed_packet));
259 if (!txQueue.empty())
260 parent->schedule(txQueueEvent, txQueue.front().first);
265 warn(
"Old-style EtherLink serialization format detected, "
266 "in-flight packets may have been dropped.\n");
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Interface(const std::string &name, Link *txlink, Link *rxlink)
void unserialize(const std::string &base, CheckpointIn &cp)
void serialize(const std::string &base, CheckpointOut &cp) const
Link(const std::string &name, EtherLink *p, int num, double rate, Tick delay, Tick delay_var, EtherDump *dump)
bool transmit(EthPacketPtr packet)
void setRxInt(Interface *i)
void setTxInt(Interface *i)
void txComplete(EthPacketPtr packet)
EtherLink(const Params &p)
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual std::string name() const
Ports are used to interface objects to each other.
Abstract superclass for simulation objects.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
bool optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, bool do_warn=true)
This function is used for restoring optional parameters from the checkpoint.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
void dump()
Dump all statistics data to the registered outputs.
Copyright (c) 2024 Arm Limited All rights reserved.
Tick curTick()
The universal simulation clock.
std::ostream CheckpointOut
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
uint64_t Tick
Tick count type.
std::string csprintf(const char *format, const Args &...args)
std::shared_ptr< EthPacketData > EthPacketPtr
const std::string & name()