gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/core.hh"
66 #include "sim/serialize.hh"
67 #include "sim/system.hh"
68 
70  : SimObject(p), linkDelay(p.delay)
71 {
72  DPRINTF(DistEthernet,"DistEtherLink::DistEtherLink() "
73  "link delay:%llu ticksPerByte:%f\n", p.delay, p.speed);
74 
75  txLink = new TxLink(name() + ".link0", this, p.speed, p.delay_var,
76  p.dump);
77  rxLink = new RxLink(name() + ".link1", this, p.delay, p.dump);
78 
79  Tick sync_repeat;
80  if (p.sync_repeat != 0) {
81  if (p.sync_repeat != p.delay)
82  warn("DistEtherLink(): sync_repeat is %lu and linkdelay is %lu",
83  p.sync_repeat, p.delay);
84  sync_repeat = p.sync_repeat;
85  } else {
86  sync_repeat = p.delay;
87  }
88 
89  // create the dist (TCP) interface to talk to the peer gem5 processes.
90  distIface = new TCPIface(p.server_name, p.server_port,
91  p.dist_rank, p.dist_size,
92  p.sync_start, sync_repeat, this,
93  p.dist_sync_on_pseudo_op, p.is_switch,
94  p.num_nodes);
95 
96  localIface = new LocalIface(name() + ".int0", txLink, rxLink, distIface);
97 }
98 
100 {
101  delete txLink;
102  delete rxLink;
103  delete localIface;
104  delete distIface;
105 }
106 
107 Port &
108 DistEtherLink::getPort(const std::string &if_name, PortID idx)
109 {
110  if (if_name == "int0")
111  return *localIface;
112  return SimObject::getPort(if_name, idx);
113 }
114 
115 void
117 {
118  distIface->serializeSection(cp, "distIface");
119  txLink->serializeSection(cp, "txLink");
120  rxLink->serializeSection(cp, "rxLink");
121 }
122 
123 void
125 {
126  distIface->unserializeSection(cp, "distIface");
127  txLink->unserializeSection(cp, "txLink");
128  rxLink->unserializeSection(cp, "rxLink");
129 }
130 
131 void
133 {
134  DPRINTF(DistEthernet,"DistEtherLink::init() called\n");
136 }
137 
138 void
140 {
141  DPRINTF(DistEthernet,"DistEtherLink::startup() called\n");
142  distIface->startup();
143 }
144 
145 void
147 {
148  assert(!distIface);
149  distIface = m;
150 }
151 
152 void
154 {
155  assert(!busy());
156 
157  // retrieve the packet that triggered the receive done event
158  packet = distIface->packetIn();
159 
160  if (dump)
161  dump->dump(packet);
162 
163  DPRINTF(DistEthernetPkt, "DistEtherLink::DistLink::rxDone() "
164  "packet received: len=%d\n", packet->length);
165  DDUMP(EthernetData, packet->data, packet->length);
166 
167  localIface->sendPacket(packet);
168 
169  packet = nullptr;
170 }
171 
172 void
174 {
175  if (dump)
176  dump->dump(packet);
177 
178  packet = nullptr;
179  assert(!busy());
180 
181  localIface->sendDone();
182 }
183 
184 bool
186 {
187  if (busy()) {
188  DPRINTF(DistEthernet, "packet not sent, link busy\n");
189  return false;
190  }
191 
192  packet = pkt;
193  Tick delay = (Tick)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
194  if (delayVar != 0)
195  delay += random_mt.random<Tick>(0, delayVar);
196 
197  // send the packet to the peers
198  assert(distIface);
199  distIface->packetOut(pkt, delay);
200 
201  // schedule the send done event
202  parent->schedule(doneEvent, curTick() + delay);
203 
204  return true;
205 }
206 
207 void
209 {
210  bool packet_exists = (packet != nullptr);
211  SERIALIZE_SCALAR(packet_exists);
212  if (packet_exists)
213  packet->serialize("packet", cp);
214 
215  bool event_scheduled = event->scheduled();
216  SERIALIZE_SCALAR(event_scheduled);
217  if (event_scheduled) {
218  Tick event_time = event->when();
219  SERIALIZE_SCALAR(event_time);
220  }
221 }
222 
223 void
225 {
226  bool packet_exists;
227  UNSERIALIZE_SCALAR(packet_exists);
228  if (packet_exists) {
229  packet = std::make_shared<EthPacketData>();
230  packet->unserialize("packet", cp);
231  }
232 
233  bool event_scheduled;
234  UNSERIALIZE_SCALAR(event_scheduled);
235  if (event_scheduled) {
236  Tick event_time;
237  UNSERIALIZE_SCALAR(event_time);
238  parent->schedule(*event, event_time);
239  }
240 }
241 
243  TxLink *tx,
244  RxLink *rx,
245  DistIface *m) :
246  EtherInt(name), txLink(tx)
247 {
248  tx->setLocalInt(this);
249  rx->setLocalInt(this);
250  tx->setDistInt(m);
251  rx->setDistInt(m);
252 }
253 
254 
Serializable::unserializeSection
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition: serialize.cc:177
warn
#define warn(...)
Definition: logging.hh:239
DistIface
The interface class to talk to peer gem5 processes.
Definition: dist_iface.hh:99
system.hh
serialize.hh
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:591
EtherInt
Definition: etherint.hh:47
random.hh
etherint.hh
etherdump.hh
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:243
Serializable::serializeSection
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition: serialize.cc:170
Random::random
std::enable_if_t< std::is_integral< T >::value, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:86
random_mt
Random random_mt
Definition: random.cc:96
DistIface::init
void init(const Event *e, Tick link_delay)
Definition: dist_iface.cc:782
cp
Definition: cprintf.cc:37
SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:120
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:297
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
dist_iface.hh
core.hh
TCPIface
Definition: tcp_iface.hh:59
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:584
DDUMP
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:236
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:87
tcp_iface.hh
Stats::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:290
etherpkt.hh
DistIface::startup
void startup()
Definition: dist_iface.cc:809
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
EtherInt::sendPacket
bool sendPacket(EthPacketPtr packet)
Definition: etherint.hh:70
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
CheckpointIn
Definition: serialize.hh:68
DistIface::packetOut
void packetOut(EthPacketPtr pkt, Tick send_delay)
Send out an Ethernet packet.
Definition: dist_iface.cc:646
DistIface::packetIn
EthPacketPtr packetIn()
Fetch the packet scheduled to be received next by the simulated network link.
Definition: dist_iface.hh:598
ArmISA::m
Bitfield< 0 > m
Definition: miscregs_types.hh:389
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Mar 23 2021 19:41:26 for gem5 by doxygen 1.8.17