gem5 v24.1.0.1
Loading...
Searching...
No Matches
dist_etherlink.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38/* @file
39 * Device module for a full duplex ethernet link for dist gem5 simulations.
40 */
41
43
44#include <arpa/inet.h>
45#include <sys/socket.h>
46#include <unistd.h>
47
48#include <cmath>
49#include <deque>
50#include <string>
51#include <vector>
52
53#include "base/trace.hh"
54#include "debug/DistEthernet.hh"
55#include "debug/DistEthernetPkt.hh"
56#include "debug/EthernetData.hh"
57#include "dev/net/dist_iface.hh"
58#include "dev/net/etherdump.hh"
59#include "dev/net/etherint.hh"
60#include "dev/net/etherlink.hh"
61#include "dev/net/etherpkt.hh"
62#include "dev/net/tcp_iface.hh"
63#include "params/EtherLink.hh"
64#include "sim/cur_tick.hh"
65#include "sim/serialize.hh"
66#include "sim/system.hh"
67
68namespace gem5
69{
70
72 : SimObject(p), linkDelay(p.delay)
73{
74 DPRINTF(DistEthernet,"DistEtherLink::DistEtherLink() "
75 "link delay:%llu ticksPerByte:%f\n", p.delay, p.speed);
76
77 txLink = new TxLink(name() + ".link0", this, p.speed, p.delay_var,
78 p.dump);
79 rxLink = new RxLink(name() + ".link1", this, p.delay, p.dump);
80
81 Tick sync_repeat;
82 if (p.sync_repeat != 0) {
83 if (p.sync_repeat != p.delay)
84 warn("DistEtherLink(): sync_repeat is %lu and linkdelay is %lu",
85 p.sync_repeat, p.delay);
86 sync_repeat = p.sync_repeat;
87 } else {
88 sync_repeat = p.delay;
89 }
90
91 // create the dist (TCP) interface to talk to the peer gem5 processes.
92 distIface = new TCPIface(p.server_name, p.server_port,
93 p.dist_rank, p.dist_size,
94 p.sync_start, sync_repeat, this,
95 p.dist_sync_on_pseudo_op, p.is_switch,
96 p.num_nodes);
97
98 localIface = new LocalIface(name() + ".int0", txLink, rxLink, distIface);
99}
100
102{
103 delete txLink;
104 delete rxLink;
105 delete localIface;
106 delete distIface;
107}
108
109Port &
110DistEtherLink::getPort(const std::string &if_name, PortID idx)
111{
112 if (if_name == "int0")
113 return *localIface;
114 return SimObject::getPort(if_name, idx);
115}
116
117void
119{
120 distIface->serializeSection(cp, "distIface");
121 txLink->serializeSection(cp, "txLink");
122 rxLink->serializeSection(cp, "rxLink");
123}
124
125void
127{
128 distIface->unserializeSection(cp, "distIface");
129 txLink->unserializeSection(cp, "txLink");
130 rxLink->unserializeSection(cp, "rxLink");
131}
132
133void
135{
136 DPRINTF(DistEthernet,"DistEtherLink::init() called\n");
138}
139
140void
142{
143 DPRINTF(DistEthernet,"DistEtherLink::startup() called\n");
145}
146
147void
153
154void
156{
157 assert(!busy());
158
159 // retrieve the packet that triggered the receive done event
160 packet = distIface->packetIn();
161
162 if (dump)
163 dump->dump(packet);
164
165 DPRINTF(DistEthernetPkt, "DistEtherLink::DistLink::rxDone() "
166 "packet received: len=%d\n", packet->length);
167 DDUMP(EthernetData, packet->data, packet->length);
168
169 localIface->sendPacket(packet);
170
171 packet = nullptr;
172}
173
174void
176{
177 if (dump)
178 dump->dump(packet);
179
180 packet = nullptr;
181 assert(!busy());
182
184}
185
186bool
188{
189 if (busy()) {
190 DPRINTF(DistEthernet, "packet not sent, link busy\n");
191 return false;
192 }
193
194 packet = pkt;
195 Tick delay = (Tick)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
196 if (delayVar != 0)
197 delay += rng->random<Tick>(0, delayVar);
198
199 // send the packet to the peers
200 assert(distIface);
201 distIface->packetOut(pkt, delay);
202
203 // schedule the send done event
204 parent->schedule(doneEvent, curTick() + delay);
205
206 return true;
207}
208
209void
211{
212 bool packet_exists = (packet != nullptr);
213 SERIALIZE_SCALAR(packet_exists);
214 if (packet_exists)
215 packet->serialize("packet", cp);
216
217 bool event_scheduled = event->scheduled();
218 SERIALIZE_SCALAR(event_scheduled);
219 if (event_scheduled) {
220 Tick event_time = event->when();
221 SERIALIZE_SCALAR(event_time);
222 }
223}
224
225void
227{
228 bool packet_exists;
229 UNSERIALIZE_SCALAR(packet_exists);
230 if (packet_exists) {
231 packet = std::make_shared<EthPacketData>();
232 packet->unserialize("packet", cp);
233 }
234
235 bool event_scheduled;
236 UNSERIALIZE_SCALAR(event_scheduled);
237 if (event_scheduled) {
238 Tick event_time;
239 UNSERIALIZE_SCALAR(event_time);
240 parent->schedule(*event, event_time);
241 }
242}
243
245 TxLink *tx,
246 RxLink *rx,
247 DistIface *m) :
248 EtherInt(name), txLink(tx)
249{
250 tx->setLocalInt(this);
251 rx->setLocalInt(this);
252 tx->setDistInt(m);
253 rx->setDistInt(m);
254}
255
256} // namespace gem5
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition trace.hh:203
#define DPRINTF(x,...)
Definition trace.hh:209
The interface class to talk to peer gem5 processes.
void init(const Event *e, Tick link_delay)
EthPacketPtr packetIn()
Fetch the packet scheduled to be received next by the simulated network link.
void packetOut(EthPacketPtr pkt, Tick send_delay)
Send out an Ethernet packet.
bool sendPacket(EthPacketPtr packet)
Definition etherint.hh:73
virtual std::string name() const
Definition named.hh:47
Ports are used to interface objects to each other.
Definition port.hh:62
Abstract superclass for simulation objects.
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition serialize.cc:74
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition serialize.cc:81
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
#define warn(...)
Definition logging.hh:256
Bitfield< 0 > m
Bitfield< 10, 5 > event
Bitfield< 0 > p
void dump()
Dump all statistics data to the registered outputs.
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
std::ostream CheckpointOut
Definition serialize.hh:66
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
std::shared_ptr< EthPacketData > EthPacketPtr
Definition etherpkt.hh:90
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Mon Jan 13 2025 04:28:34 for gem5 by doxygen 1.9.8