gem5 v24.0.0.0
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/random.hh"
54#include "base/trace.hh"
55#include "debug/DistEthernet.hh"
56#include "debug/DistEthernetPkt.hh"
57#include "debug/EthernetData.hh"
58#include "dev/net/dist_iface.hh"
59#include "dev/net/etherdump.hh"
60#include "dev/net/etherint.hh"
61#include "dev/net/etherlink.hh"
62#include "dev/net/etherpkt.hh"
63#include "dev/net/tcp_iface.hh"
64#include "params/EtherLink.hh"
65#include "sim/cur_tick.hh"
66#include "sim/serialize.hh"
67#include "sim/system.hh"
68
69namespace gem5
70{
71
73 : SimObject(p), linkDelay(p.delay)
74{
75 DPRINTF(DistEthernet,"DistEtherLink::DistEtherLink() "
76 "link delay:%llu ticksPerByte:%f\n", p.delay, p.speed);
77
78 txLink = new TxLink(name() + ".link0", this, p.speed, p.delay_var,
79 p.dump);
80 rxLink = new RxLink(name() + ".link1", this, p.delay, p.dump);
81
82 Tick sync_repeat;
83 if (p.sync_repeat != 0) {
84 if (p.sync_repeat != p.delay)
85 warn("DistEtherLink(): sync_repeat is %lu and linkdelay is %lu",
86 p.sync_repeat, p.delay);
87 sync_repeat = p.sync_repeat;
88 } else {
89 sync_repeat = p.delay;
90 }
91
92 // create the dist (TCP) interface to talk to the peer gem5 processes.
93 distIface = new TCPIface(p.server_name, p.server_port,
94 p.dist_rank, p.dist_size,
95 p.sync_start, sync_repeat, this,
96 p.dist_sync_on_pseudo_op, p.is_switch,
97 p.num_nodes);
98
99 localIface = new LocalIface(name() + ".int0", txLink, rxLink, distIface);
100}
101
103{
104 delete txLink;
105 delete rxLink;
106 delete localIface;
107 delete distIface;
108}
109
110Port &
111DistEtherLink::getPort(const std::string &if_name, PortID idx)
112{
113 if (if_name == "int0")
114 return *localIface;
115 return SimObject::getPort(if_name, idx);
116}
117
118void
120{
121 distIface->serializeSection(cp, "distIface");
122 txLink->serializeSection(cp, "txLink");
123 rxLink->serializeSection(cp, "rxLink");
124}
125
126void
128{
129 distIface->unserializeSection(cp, "distIface");
130 txLink->unserializeSection(cp, "txLink");
131 rxLink->unserializeSection(cp, "rxLink");
132}
133
134void
136{
137 DPRINTF(DistEthernet,"DistEtherLink::init() called\n");
139}
140
141void
143{
144 DPRINTF(DistEthernet,"DistEtherLink::startup() called\n");
146}
147
148void
154
155void
157{
158 assert(!busy());
159
160 // retrieve the packet that triggered the receive done event
161 packet = distIface->packetIn();
162
163 if (dump)
164 dump->dump(packet);
165
166 DPRINTF(DistEthernetPkt, "DistEtherLink::DistLink::rxDone() "
167 "packet received: len=%d\n", packet->length);
168 DDUMP(EthernetData, packet->data, packet->length);
169
170 localIface->sendPacket(packet);
171
172 packet = nullptr;
173}
174
175void
177{
178 if (dump)
179 dump->dump(packet);
180
181 packet = nullptr;
182 assert(!busy());
183
185}
186
187bool
189{
190 if (busy()) {
191 DPRINTF(DistEthernet, "packet not sent, link busy\n");
192 return false;
193 }
194
195 packet = pkt;
196 Tick delay = (Tick)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
197 if (delayVar != 0)
198 delay += random_mt.random<Tick>(0, delayVar);
199
200 // send the packet to the peers
201 assert(distIface);
202 distIface->packetOut(pkt, delay);
203
204 // schedule the send done event
205 parent->schedule(doneEvent, curTick() + delay);
206
207 return true;
208}
209
210void
212{
213 bool packet_exists = (packet != nullptr);
214 SERIALIZE_SCALAR(packet_exists);
215 if (packet_exists)
216 packet->serialize("packet", cp);
217
218 bool event_scheduled = event->scheduled();
219 SERIALIZE_SCALAR(event_scheduled);
220 if (event_scheduled) {
221 Tick event_time = event->when();
222 SERIALIZE_SCALAR(event_time);
223 }
224}
225
226void
228{
229 bool packet_exists;
230 UNSERIALIZE_SCALAR(packet_exists);
231 if (packet_exists) {
232 packet = std::make_shared<EthPacketData>();
233 packet->unserialize("packet", cp);
234 }
235
236 bool event_scheduled;
237 UNSERIALIZE_SCALAR(event_scheduled);
238 if (event_scheduled) {
239 Tick event_time;
240 UNSERIALIZE_SCALAR(event_time);
241 parent->schedule(*event, event_time);
242 }
243}
244
246 TxLink *tx,
247 RxLink *rx,
248 DistIface *m) :
249 EtherInt(name), txLink(tx)
250{
251 tx->setLocalInt(this);
252 rx->setLocalInt(this);
253 tx->setDistInt(m);
254 rx->setDistInt(m);
255}
256
257} // namespace gem5
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition trace.hh:204
#define DPRINTF(x,...)
Definition trace.hh:210
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.
Random random_mt
Definition random.cc:99
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition random.hh:90
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 - Pranith Kumar Copyright (c) 2020 Inria 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 Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0