gem5  v20.1.0.0
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 
69 using namespace std;
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 
109 Port &
110 DistEtherLink::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 
117 void
119 {
120  distIface->serializeSection(cp, "distIface");
121  txLink->serializeSection(cp, "txLink");
122  rxLink->serializeSection(cp, "rxLink");
123 }
124 
125 void
127 {
128  distIface->unserializeSection(cp, "distIface");
129  txLink->unserializeSection(cp, "txLink");
130  rxLink->unserializeSection(cp, "rxLink");
131 }
132 
133 void
135 {
136  DPRINTF(DistEthernet,"DistEtherLink::init() called\n");
138 }
139 
140 void
142 {
143  DPRINTF(DistEthernet,"DistEtherLink::startup() called\n");
144  distIface->startup();
145 }
146 
147 void
149 {
150  assert(!distIface);
151  distIface = m;
152 }
153 
154 void
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 
174 void
176 {
177  if (dump)
178  dump->dump(packet);
179 
180  packet = nullptr;
181  assert(!busy());
182 
183  localIface->sendDone();
184 }
185 
186 bool
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 += random_mt.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 
209 void
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 
225 void
227 {
228  bool packet_exists;
229  UNSERIALIZE_SCALAR(packet_exists);
230  if (packet_exists) {
231  packet = 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 
257 DistEtherLinkParams::create()
258 {
259  return new DistEtherLink(this);
260 }
261 
262 
Serializable::unserializeSection
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition: serialize.cc:178
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:797
EtherInt
Definition: etherint.hh:47
random.hh
etherint.hh
etherdump.hh
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
Serializable::serializeSection
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition: serialize.cc:171
random_mt
Random random_mt
Definition: random.cc:96
DistIface::init
void init(const Event *e, Tick link_delay)
Definition: dist_iface.cc:783
cp
Definition: cprintf.cc:40
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:123
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
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:790
DDUMP
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:233
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:87
tcp_iface.hh
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Stats::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:560
etherpkt.hh
Random::random
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...
Definition: random.hh:86
DistIface::startup
void startup()
Definition: dist_iface.cc:810
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
EtherInt::sendPacket
bool sendPacket(EthPacketPtr packet)
Definition: etherint.hh:70
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
CheckpointIn
Definition: serialize.hh:67
DistIface::packetOut
void packetOut(EthPacketPtr pkt, Tick send_delay)
Send out an Ethernet packet.
Definition: dist_iface.cc:647
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
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17