gem5  v21.1.0.2
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 
69 namespace 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 
110 Port &
111 DistEtherLink::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 
118 void
120 {
121  distIface->serializeSection(cp, "distIface");
122  txLink->serializeSection(cp, "txLink");
123  rxLink->serializeSection(cp, "rxLink");
124 }
125 
126 void
128 {
129  distIface->unserializeSection(cp, "distIface");
130  txLink->unserializeSection(cp, "txLink");
131  rxLink->unserializeSection(cp, "rxLink");
132 }
133 
134 void
136 {
137  DPRINTF(DistEthernet,"DistEtherLink::init() called\n");
139 }
140 
141 void
143 {
144  DPRINTF(DistEthernet,"DistEtherLink::startup() called\n");
145  distIface->startup();
146 }
147 
148 void
150 {
151  assert(!distIface);
152  distIface = m;
153 }
154 
155 void
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 
175 void
177 {
178  if (dump)
179  dump->dump(packet);
180 
181  packet = nullptr;
182  assert(!busy());
183 
184  localIface->sendDone();
185 }
186 
187 bool
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 
210 void
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 
226 void
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
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:252
gem5::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:126
warn
#define warn(...)
Definition: logging.hh:245
system.hh
serialize.hh
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:575
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::DistIface::packetIn
EthPacketPtr packetIn()
Fetch the packet scheduled to be received next by the simulated network link.
Definition: dist_iface.hh:600
gem5::MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:300
gem5::Serializable::serializeSection
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition: serialize.cc:74
cur_tick.hh
random.hh
etherint.hh
etherdump.hh
gem5::EtherInt::sendPacket
bool sendPacket(EthPacketPtr packet)
Definition: etherint.hh:73
gem5::DistIface::packetOut
void packetOut(EthPacketPtr pkt, Tick send_delay)
Send out an Ethernet packet.
Definition: dist_iface.cc:650
gem5::EtherInt
Definition: etherint.hh:50
gem5::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:90
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::Serializable::unserializeSection
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition: serialize.cc:81
gem5::EthPacketPtr
std::shared_ptr< EthPacketData > EthPacketPtr
Definition: etherpkt.hh:90
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::statistics::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:295
dist_iface.hh
gem5::DistIface::init
void init(const Event *e, Tick link_delay)
Definition: dist_iface.cc:786
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::DistIface::startup
void startup()
Definition: dist_iface.cc:813
gem5::TCPIface
Definition: tcp_iface.hh:62
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:568
DDUMP
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:180
gem5::ArmISA::m
Bitfield< 0 > m
Definition: misc_types.hh:394
gem5::DistIface
The interface class to talk to peer gem5 processes.
Definition: dist_iface.hh:101
tcp_iface.hh
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
etherpkt.hh
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
trace.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::random_mt
Random random_mt
Definition: random.cc:99

Generated on Tue Sep 21 2021 12:25:17 for gem5 by doxygen 1.8.17