dist_etherlink.cc (11290:1640dd68b0a4) dist_etherlink.cc (11701:5e7599457b97)
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 * Authors: Gabor Dozsa
38 */
39
40/* @file
41 * Device module for a full duplex ethernet link for dist gem5 simulations.
42 */
43
44#include "dev/net/dist_etherlink.hh"
45
46#include <arpa/inet.h>
47#include <sys/socket.h>
48#include <unistd.h>
49
50#include <cmath>
51#include <deque>
52#include <string>
53#include <vector>
54
55#include "base/random.hh"
56#include "base/trace.hh"
57#include "debug/DistEthernet.hh"
58#include "debug/DistEthernetPkt.hh"
59#include "debug/EthernetData.hh"
60#include "dev/net/dist_iface.hh"
61#include "dev/net/etherdump.hh"
62#include "dev/net/etherint.hh"
63#include "dev/net/etherlink.hh"
64#include "dev/net/etherobject.hh"
65#include "dev/net/etherpkt.hh"
66#include "dev/net/tcp_iface.hh"
67#include "params/EtherLink.hh"
68#include "sim/core.hh"
69#include "sim/serialize.hh"
70#include "sim/system.hh"
71
72using namespace std;
73
74DistEtherLink::DistEtherLink(const Params *p)
75 : EtherObject(p), linkDelay(p->delay)
76{
77 DPRINTF(DistEthernet,"DistEtherLink::DistEtherLink() "
78 "link delay:%llu ticksPerByte:%f\n", p->delay, p->speed);
79
80 txLink = new TxLink(name() + ".link0", this, p->speed, p->delay_var,
81 p->dump);
82 rxLink = new RxLink(name() + ".link1", this, p->delay, p->dump);
83
84 Tick sync_repeat;
85 if (p->sync_repeat != 0) {
86 if (p->sync_repeat != p->delay)
87 warn("DistEtherLink(): sync_repeat is %lu and linkdelay is %lu",
88 p->sync_repeat, p->delay);
89 sync_repeat = p->sync_repeat;
90 } else {
91 sync_repeat = p->delay;
92 }
93
94 // create the dist (TCP) interface to talk to the peer gem5 processes.
95 distIface = new TCPIface(p->server_name, p->server_port,
96 p->dist_rank, p->dist_size,
97 p->sync_start, sync_repeat, this, p->is_switch,
98 p->num_nodes);
99
100 localIface = new LocalIface(name() + ".int0", txLink, rxLink, distIface);
101}
102
103DistEtherLink::~DistEtherLink()
104{
105 delete txLink;
106 delete rxLink;
107 delete localIface;
108 delete distIface;
109}
110
111EtherInt*
112DistEtherLink::getEthPort(const std::string &if_name, int idx)
113{
114 if (if_name != "int0") {
115 return nullptr;
116 } else {
117 panic_if(localIface->getPeer(), "interface already connected to");
118 }
119 return localIface;
120}
121
122void
123DistEtherLink::serialize(CheckpointOut &cp) const
124{
125 distIface->serializeSection(cp, "distIface");
126 txLink->serializeSection(cp, "txLink");
127 rxLink->serializeSection(cp, "rxLink");
128}
129
130void
131DistEtherLink::unserialize(CheckpointIn &cp)
132{
133 distIface->unserializeSection(cp, "distIface");
134 txLink->unserializeSection(cp, "txLink");
135 rxLink->unserializeSection(cp, "rxLink");
136}
137
138void
139DistEtherLink::init()
140{
141 DPRINTF(DistEthernet,"DistEtherLink::init() called\n");
142 distIface->init(rxLink->doneEvent(), linkDelay);
143}
144
145void
146DistEtherLink::startup()
147{
148 DPRINTF(DistEthernet,"DistEtherLink::startup() called\n");
149 distIface->startup();
150}
151
152void
153DistEtherLink::RxLink::setDistInt(DistIface *m)
154{
155 assert(!distIface);
156 distIface = m;
157}
158
159void
160DistEtherLink::RxLink::rxDone()
161{
162 assert(!busy());
163
164 // retrieve the packet that triggered the receive done event
165 packet = distIface->packetIn();
166
167 if (dump)
168 dump->dump(packet);
169
170 DPRINTF(DistEthernetPkt, "DistEtherLink::DistLink::rxDone() "
171 "packet received: len=%d\n", packet->length);
172 DDUMP(EthernetData, packet->data, packet->length);
173
174 localIface->sendPacket(packet);
175
176 packet = nullptr;
177}
178
179void
180DistEtherLink::TxLink::txDone()
181{
182 if (dump)
183 dump->dump(packet);
184
185 packet = nullptr;
186 assert(!busy());
187
188 localIface->sendDone();
189}
190
191bool
192DistEtherLink::TxLink::transmit(EthPacketPtr pkt)
193{
194 if (busy()) {
195 DPRINTF(DistEthernet, "packet not sent, link busy\n");
196 return false;
197 }
198
199 packet = pkt;
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 * Authors: Gabor Dozsa
38 */
39
40/* @file
41 * Device module for a full duplex ethernet link for dist gem5 simulations.
42 */
43
44#include "dev/net/dist_etherlink.hh"
45
46#include <arpa/inet.h>
47#include <sys/socket.h>
48#include <unistd.h>
49
50#include <cmath>
51#include <deque>
52#include <string>
53#include <vector>
54
55#include "base/random.hh"
56#include "base/trace.hh"
57#include "debug/DistEthernet.hh"
58#include "debug/DistEthernetPkt.hh"
59#include "debug/EthernetData.hh"
60#include "dev/net/dist_iface.hh"
61#include "dev/net/etherdump.hh"
62#include "dev/net/etherint.hh"
63#include "dev/net/etherlink.hh"
64#include "dev/net/etherobject.hh"
65#include "dev/net/etherpkt.hh"
66#include "dev/net/tcp_iface.hh"
67#include "params/EtherLink.hh"
68#include "sim/core.hh"
69#include "sim/serialize.hh"
70#include "sim/system.hh"
71
72using namespace std;
73
74DistEtherLink::DistEtherLink(const Params *p)
75 : EtherObject(p), linkDelay(p->delay)
76{
77 DPRINTF(DistEthernet,"DistEtherLink::DistEtherLink() "
78 "link delay:%llu ticksPerByte:%f\n", p->delay, p->speed);
79
80 txLink = new TxLink(name() + ".link0", this, p->speed, p->delay_var,
81 p->dump);
82 rxLink = new RxLink(name() + ".link1", this, p->delay, p->dump);
83
84 Tick sync_repeat;
85 if (p->sync_repeat != 0) {
86 if (p->sync_repeat != p->delay)
87 warn("DistEtherLink(): sync_repeat is %lu and linkdelay is %lu",
88 p->sync_repeat, p->delay);
89 sync_repeat = p->sync_repeat;
90 } else {
91 sync_repeat = p->delay;
92 }
93
94 // create the dist (TCP) interface to talk to the peer gem5 processes.
95 distIface = new TCPIface(p->server_name, p->server_port,
96 p->dist_rank, p->dist_size,
97 p->sync_start, sync_repeat, this, p->is_switch,
98 p->num_nodes);
99
100 localIface = new LocalIface(name() + ".int0", txLink, rxLink, distIface);
101}
102
103DistEtherLink::~DistEtherLink()
104{
105 delete txLink;
106 delete rxLink;
107 delete localIface;
108 delete distIface;
109}
110
111EtherInt*
112DistEtherLink::getEthPort(const std::string &if_name, int idx)
113{
114 if (if_name != "int0") {
115 return nullptr;
116 } else {
117 panic_if(localIface->getPeer(), "interface already connected to");
118 }
119 return localIface;
120}
121
122void
123DistEtherLink::serialize(CheckpointOut &cp) const
124{
125 distIface->serializeSection(cp, "distIface");
126 txLink->serializeSection(cp, "txLink");
127 rxLink->serializeSection(cp, "rxLink");
128}
129
130void
131DistEtherLink::unserialize(CheckpointIn &cp)
132{
133 distIface->unserializeSection(cp, "distIface");
134 txLink->unserializeSection(cp, "txLink");
135 rxLink->unserializeSection(cp, "rxLink");
136}
137
138void
139DistEtherLink::init()
140{
141 DPRINTF(DistEthernet,"DistEtherLink::init() called\n");
142 distIface->init(rxLink->doneEvent(), linkDelay);
143}
144
145void
146DistEtherLink::startup()
147{
148 DPRINTF(DistEthernet,"DistEtherLink::startup() called\n");
149 distIface->startup();
150}
151
152void
153DistEtherLink::RxLink::setDistInt(DistIface *m)
154{
155 assert(!distIface);
156 distIface = m;
157}
158
159void
160DistEtherLink::RxLink::rxDone()
161{
162 assert(!busy());
163
164 // retrieve the packet that triggered the receive done event
165 packet = distIface->packetIn();
166
167 if (dump)
168 dump->dump(packet);
169
170 DPRINTF(DistEthernetPkt, "DistEtherLink::DistLink::rxDone() "
171 "packet received: len=%d\n", packet->length);
172 DDUMP(EthernetData, packet->data, packet->length);
173
174 localIface->sendPacket(packet);
175
176 packet = nullptr;
177}
178
179void
180DistEtherLink::TxLink::txDone()
181{
182 if (dump)
183 dump->dump(packet);
184
185 packet = nullptr;
186 assert(!busy());
187
188 localIface->sendDone();
189}
190
191bool
192DistEtherLink::TxLink::transmit(EthPacketPtr pkt)
193{
194 if (busy()) {
195 DPRINTF(DistEthernet, "packet not sent, link busy\n");
196 return false;
197 }
198
199 packet = pkt;
200 Tick delay = (Tick)ceil(((double)pkt->length * ticksPerByte) + 1.0);
200 Tick delay = (Tick)ceil(((double)pkt->simLength * ticksPerByte) + 1.0);
201 if (delayVar != 0)
202 delay += random_mt.random<Tick>(0, delayVar);
203
204 // send the packet to the peers
205 assert(distIface);
206 distIface->packetOut(pkt, delay);
207
208 // schedule the send done event
209 parent->schedule(doneEvent, curTick() + delay);
210
211 return true;
212}
213
214void
215DistEtherLink::Link::serialize(CheckpointOut &cp) const
216{
217 bool packet_exists = (packet != nullptr);
218 SERIALIZE_SCALAR(packet_exists);
219 if (packet_exists)
220 packet->serialize("packet", cp);
221
222 bool event_scheduled = event->scheduled();
223 SERIALIZE_SCALAR(event_scheduled);
224 if (event_scheduled) {
225 Tick event_time = event->when();
226 SERIALIZE_SCALAR(event_time);
227 }
228}
229
230void
231DistEtherLink::Link::unserialize(CheckpointIn &cp)
232{
233 bool packet_exists;
234 UNSERIALIZE_SCALAR(packet_exists);
235 if (packet_exists) {
201 if (delayVar != 0)
202 delay += random_mt.random<Tick>(0, delayVar);
203
204 // send the packet to the peers
205 assert(distIface);
206 distIface->packetOut(pkt, delay);
207
208 // schedule the send done event
209 parent->schedule(doneEvent, curTick() + delay);
210
211 return true;
212}
213
214void
215DistEtherLink::Link::serialize(CheckpointOut &cp) const
216{
217 bool packet_exists = (packet != nullptr);
218 SERIALIZE_SCALAR(packet_exists);
219 if (packet_exists)
220 packet->serialize("packet", cp);
221
222 bool event_scheduled = event->scheduled();
223 SERIALIZE_SCALAR(event_scheduled);
224 if (event_scheduled) {
225 Tick event_time = event->when();
226 SERIALIZE_SCALAR(event_time);
227 }
228}
229
230void
231DistEtherLink::Link::unserialize(CheckpointIn &cp)
232{
233 bool packet_exists;
234 UNSERIALIZE_SCALAR(packet_exists);
235 if (packet_exists) {
236 packet = make_shared<EthPacketData>(16384);
236 packet = make_shared();
237 packet->unserialize("packet", cp);
238 }
239
240 bool event_scheduled;
241 UNSERIALIZE_SCALAR(event_scheduled);
242 if (event_scheduled) {
243 Tick event_time;
244 UNSERIALIZE_SCALAR(event_time);
245 parent->schedule(*event, event_time);
246 }
247}
248
249DistEtherLink::LocalIface::LocalIface(const std::string &name,
250 TxLink *tx,
251 RxLink *rx,
252 DistIface *m) :
253 EtherInt(name), txLink(tx)
254{
255 tx->setLocalInt(this);
256 rx->setLocalInt(this);
257 tx->setDistInt(m);
258 rx->setDistInt(m);
259}
260
261DistEtherLink *
262DistEtherLinkParams::create()
263{
264 return new DistEtherLink(this);
265}
266
267
237 packet->unserialize("packet", cp);
238 }
239
240 bool event_scheduled;
241 UNSERIALIZE_SCALAR(event_scheduled);
242 if (event_scheduled) {
243 Tick event_time;
244 UNSERIALIZE_SCALAR(event_time);
245 parent->schedule(*event, event_time);
246 }
247}
248
249DistEtherLink::LocalIface::LocalIface(const std::string &name,
250 TxLink *tx,
251 RxLink *rx,
252 DistIface *m) :
253 EtherInt(name), txLink(tx)
254{
255 tx->setLocalInt(this);
256 rx->setLocalInt(this);
257 tx->setDistInt(m);
258 rx->setDistInt(m);
259}
260
261DistEtherLink *
262DistEtherLinkParams::create()
263{
264 return new DistEtherLink(this);
265}
266
267