gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dist_iface.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015-2016 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 * The interface class for dist gem5 simulations.
40 *
41 * dist-gem5 is an extension to gem5 to enable parallel simulation of a
42 * distributed system (e.g. simulation of a pool of machines
43 * connected by Ethernet links). A dist gem5 run consists of seperate gem5
44 * processes running in parallel. Each gem5 process executes
45 * the simulation of a component of the simulated distributed system.
46 * (An example component can be a dist-core board with an Ethernet NIC.)
47 * The DistIface class below provides services to transfer data and
48 * control messages among the gem5 processes. The main such services are
49 * as follows.
50 *
51 * 1. Send a data packet coming from a simulated Ethernet link. The packet
52 * will be transferred to (all) the target(s) gem5 processes. The send
53 * operation is always performed by the simulation thread, i.e. the gem5
54 * thread that is processing the event queue associated with the simulated
55 * Ethernet link.
56 *
57 * 2. Spawn a receiver thread to process messages coming in from the
58 * from other gem5 processes. Each simulated Ethernet link has its own
59 * associated receiver thread. The receiver thread saves the incoming packet
60 * and schedule an appropriate receive event in the event queue.
61 *
62 * 3. Schedule a global barrier event periodically to keep the gem5
63 * processes in sync.
64 * Periodic barrier event to keep peer gem5 processes in sync. The basic idea
65 * is that no gem5 process can go ahead further than the simulated link
66 * transmission delay to ensure that a corresponding receive event can always
67 * be scheduled for any message coming in from a peer gem5 process.
68 *
69 *
70 *
71 * This interface is an abstract class. It can work with various low level
72 * send/receive service implementations (e.g. TCP/IP, MPI,...). A TCP
73 * stream socket version is implemented in src/dev/net/tcp_iface.[hh,cc].
74 */
75#ifndef __DEV_DIST_IFACE_HH__
76#define __DEV_DIST_IFACE_HH__
77
78#include <array>
79#include <mutex>
80#include <queue>
81#include <thread>
82#include <utility>
83
84#include "base/logging.hh"
85#include "base/random.hh"
87#include "dev/net/etherpkt.hh"
88#include "sim/drain.hh"
89#include "sim/global_event.hh"
90#include "sim/serialize.hh"
91
92namespace gem5
93{
94
95class EventManager;
96class System;
97class ThreadContext;
98
102class DistIface : public Drainable, public Serializable
103{
104 public:
106
107 protected:
110
111 private:
112 class SyncEvent;
119 class Sync : public Serializable
120 {
121 protected:
125 std::mutex lock;
131 std::condition_variable cv;
136 unsigned waitNum;
140 bool doExit;
144 bool doCkpt;
161
162 friend class SyncEvent;
163
164 public:
172 void init(Tick start, Tick repeat);
178 virtual bool run(bool same_tick) = 0;
185 virtual bool progress(Tick send_tick,
186 Tick next_repeat,
187 ReqType do_ckpt,
188 ReqType do_exit,
189 ReqType do_stop_sync) = 0;
194 void abort();
195
196 virtual void requestCkpt(ReqType req) = 0;
197 virtual void requestExit(ReqType req) = 0;
198 virtual void requestStopSync(ReqType req) = 0;
199
200 void drainComplete();
201
202 virtual void serialize(CheckpointOut &cp) const override = 0;
203 virtual void unserialize(CheckpointIn &cp) override = 0;
204 };
205
206 class SyncNode: public Sync
207 {
208 private:
221
222 public:
223
224 SyncNode();
226 bool run(bool same_tick) override;
227 bool progress(Tick max_req_tick,
228 Tick next_repeat,
229 ReqType do_ckpt,
230 ReqType do_exit,
231 ReqType do_stop_sync) override;
232
233 void requestCkpt(ReqType req) override;
234 void requestExit(ReqType req) override;
235 void requestStopSync(ReqType req) override;
236
237 void serialize(CheckpointOut &cp) const override;
238 void unserialize(CheckpointIn &cp) override;
239 };
240
241 class SyncSwitch: public Sync
242 {
243 private:
247 unsigned numExitReq;
251 unsigned numCkptReq;
259 unsigned numNodes;
260
261 public:
262 SyncSwitch(int num_nodes);
264
265 bool run(bool same_tick) override;
266 bool progress(Tick max_req_tick,
267 Tick next_repeat,
268 ReqType do_ckpt,
269 ReqType do_exit,
270 ReqType do_stop_sync) override;
271
272 void requestCkpt(ReqType) override {
273 panic("Switch requested checkpoint");
274 }
275 void requestExit(ReqType) override {
276 panic("Switch requested exit");
277 }
278 void requestStopSync(ReqType) override {
279 panic("Switch requested stop sync");
280 }
281
282 void serialize(CheckpointOut &cp) const override;
283 void unserialize(CheckpointIn &cp) override;
284 };
285
299 {
300 private:
305 public:
311
316 void start();
322 void process() override;
323
324 bool draining() const { return _draining; }
325 void draining(bool fl) { _draining = fl; }
326 };
335 {
336 private:
342 struct Desc : public Serializable
343 {
347
348 Desc() : sendTick(0), sendDelay(0) {}
353
354 void serialize(CheckpointOut &cp) const override;
355 void unserialize(CheckpointIn &cp) override;
356 };
360 std::queue<Desc> descQueue;
402 Tick calcReceiveTick(Tick send_tick,
403 Tick send_delay,
404 Tick prev_recv_tick);
405
411
412 public:
422
429 void init(Event *recv_done, Tick link_delay);
441 void pushPacket(EthPacketPtr new_packet,
442 Tick send_tick,
443 Tick send_delay);
444
445 void serialize(CheckpointOut &cp) const override;
446 void unserialize(CheckpointIn &cp) override;
453 void resumeRecvTicks();
454 };
469 std::thread *recvThread;
478
480
481 protected:
485 unsigned rank;
489 unsigned size;
493 static unsigned distIfaceNum;
497 unsigned distIfaceId;
498
500
501 private:
505 static unsigned recvThreadsNum;
509 static Sync *sync;
522 static System *sys;
526 static bool isSwitch;
527
528 private:
535 virtual void sendPacket(const Header &header, const EthPacketPtr &packet) = 0;
540 virtual void sendCmd(const Header &header) = 0;
546 virtual bool recvHeader(Header &header) = 0;
553 virtual void recvPacket(const Header &header, EthPacketPtr &packet) = 0;
557 virtual void initTransport() = 0;
564 void spawnRecvThread(const Event *recv_done, Tick link_delay);
568 void recvThreadFunc(Event *recv_done, Tick link_delay);
569
570 public:
571
579 DistIface(unsigned dist_rank,
580 unsigned dist_size,
581 Tick sync_start,
582 Tick sync_repeat,
584 bool use_pseudo_op,
585 bool is_switch,
586 int num_nodes);
587
588 virtual ~DistIface();
594 void packetOut(EthPacketPtr pkt, Tick send_delay);
604
605 DrainState drain() override;
606 void drainResume() override;
607 void init(const Event *e, Tick link_delay);
608 void startup();
609
610 void serialize(CheckpointOut &cp) const override;
611 void unserialize(CheckpointIn &cp) override;
622 static bool readyToExit(Tick delay);
633 static bool readyToCkpt(Tick delay, Tick period);
637 static uint64_t rankParam();
641 static uint64_t sizeParam();
645 static void toggleSync(ThreadContext *tc);
646 };
647
648} // namespace gem5
649
650#endif // __DEV_DIST_IFACE_HH__
MsgType
The msg type defines what information a dist header packet carries.
Class to encapsulate information about data packets received.
Tick prevRecvTick
The tick when the most recent receive event was processed.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
bool ckptRestore
Flag to set if receive ticks for pending packets need to be recalculated due to changed link latencie...
std::queue< Desc > descQueue
The queue to store the receive descriptors.
Tick linkDelay
The link delay in ticks for the simulated Ethernet link.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void resumeRecvTicks()
Adjust receive ticks for pending packets when restoring from a checkpoint.
RecvScheduler(EventManager *em)
Scheduler for the incoming data packets.
EthPacketPtr popPacket()
Fetch the next packet that is to be received by the simulated network link.
void pushPacket(EthPacketPtr new_packet, Tick send_tick, Tick send_delay)
Push a newly arrived packet into the desc queue.
Tick calcReceiveTick(Tick send_tick, Tick send_delay, Tick prev_recv_tick)
Calculate the tick to schedule the next receive done event.
EventManager * eventManager
The event manager associated with the simulated Ethernet link.
Event * recvDone
The receive done event for the simulated Ethernet link.
The global event to schedule periodic dist sync.
bool _draining
Flag to set when the system is draining.
void start()
Schedule the first periodic sync event.
SyncEvent()
Only the firstly instantiated DistIface object will call this constructor.
void process() override
This is a global event so process() will only be called by exactly one simulation thread.
void requestExit(ReqType req) override
void serialize(CheckpointOut &cp) const override
Serialize an object.
ReqType needStopSync
Sync stop requested.
bool progress(Tick max_req_tick, Tick next_repeat, ReqType do_ckpt, ReqType do_exit, ReqType do_stop_sync) override
Callback when the receiver thread gets a sync ack message.
void requestCkpt(ReqType req) override
bool run(bool same_tick) override
Core method to perform a full dist sync.
ReqType needCkpt
Ckpt requested.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void requestStopSync(ReqType req) override
ReqType needExit
Exit requested.
bool run(bool same_tick) override
Core method to perform a full dist sync.
unsigned numExitReq
Counter for recording exit requests.
void requestExit(ReqType) override
void requestStopSync(ReqType) override
void serialize(CheckpointOut &cp) const override
Serialize an object.
void requestCkpt(ReqType) override
void unserialize(CheckpointIn &cp) override
Unserialize an object.
unsigned numCkptReq
Counter for recording ckpt requests.
bool progress(Tick max_req_tick, Tick next_repeat, ReqType do_ckpt, ReqType do_exit, ReqType do_stop_sync) override
Callback when the receiver thread gets a sync ack message.
unsigned numStopSyncReq
Counter for recording stop sync requests.
unsigned numNodes
Number of connected simulated nodes.
This class implements global sync operations among gem5 peer processes.
bool isAbort
Flag is set if the sync is aborted (e.g.
Tick nextRepeat
The repeat value for the next periodic sync.
bool doStopSync
Flag is set if sync is to stop upon sync completion.
unsigned waitNum
Number of receiver threads that not yet completed the current global synchronisation.
Tick nextAt
Tick for the next periodic sync (if the event is not scheduled yet)
bool doExit
Flag is set if exit is permitted upon sync completion.
virtual void requestStopSync(ReqType req)=0
virtual bool run(bool same_tick)=0
Core method to perform a full dist sync.
virtual void requestExit(ReqType req)=0
virtual void requestCkpt(ReqType req)=0
std::mutex lock
The lock to protect access to the Sync object.
std::condition_variable cv
Condition variable for the simulation thread to wait on until all receiver threads completes the curr...
virtual bool progress(Tick send_tick, Tick next_repeat, ReqType do_ckpt, ReqType do_exit, ReqType do_stop_sync)=0
Callback when the receiver thread gets a sync ack message.
virtual void serialize(CheckpointOut &cp) const override=0
Serialize an object.
void abort()
Abort processing an on-going sync event (in case of an error, e.g.
Definition dist_iface.cc:87
bool doCkpt
Flag is set if taking a ckpt is permitted upon sync completion.
virtual void unserialize(CheckpointIn &cp) override=0
Unserialize an object.
The interface class to talk to peer gem5 processes.
static uint64_t rankParam()
Getter for the dist rank param.
virtual void initTransport()=0
Init hook for the underlaying transport.
RecvScheduler recvScheduler
Meta information about data packets received.
static bool readyToExit(Tick delay)
Initiate the exit from the simulation.
bool syncStartOnPseudoOp
Use pseudoOp to start synchronization.
static void toggleSync(ThreadContext *tc)
Trigger the primary to start/stop synchronization.
static bool readyToCkpt(Tick delay, Tick period)
Initiate taking a checkpoint.
unsigned rank
The rank of this process among the gem5 peers.
unsigned distIfaceId
Unique id for the dist link.
static DistIface * primary
The very first DistIface object created becomes the primary interface.
DistHeaderPkt::MsgType MsgType
Random::RandomPtr rng
static uint64_t sizeParam()
Getter for the dist size param.
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
std::thread * recvThread
Receiver thread pointer.
static SyncEvent * syncEvent
The singleton SyncEvent object to schedule periodic dist sync.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static System * sys
System pointer used to wakeup sleeping threads when stopping sync.
EthPacketPtr packetIn()
Fetch the packet scheduled to be received next by the simulated network link.
void recvThreadFunc(Event *recv_done, Tick link_delay)
The function executed by a receiver thread.
virtual void sendCmd(const Header &header)=0
Send out a control command to the remote end.
virtual bool recvHeader(Header &header)=0
Receive a header (i.e.
static Sync * sync
The singleton Sync object to perform dist synchronisation.
virtual void sendPacket(const Header &header, const EthPacketPtr &packet)=0
Send out a data packet to the remote end.
static unsigned distIfaceNum
Number of DistIface objects (i.e.
void drainResume() override
Resume execution after a successful drain.
virtual ~DistIface()
void spawnRecvThread(const Event *recv_done, Tick link_delay)
spawn the receiver thread.
static bool isSwitch
Is this node a switch?
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual void recvPacket(const Header &header, EthPacketPtr &packet)=0
Receive a packet from the remote end.
Tick syncRepeat
Frequency of dist sync events in ticks.
Tick syncStart
Tick to schedule the first dist sync event.
DistHeaderPkt::Header Header
static unsigned recvThreadsNum
Number of receiver threads (in this gem5 process)
void packetOut(EthPacketPtr pkt, Tick send_delay)
Send out an Ethernet packet.
unsigned size
The number of gem5 processes comprising this dist simulation.
DistHeaderPkt::ReqType ReqType
Interface for objects that might require draining before checkpointing.
Definition drain.hh:235
A special global event that synchronizes all threads and forces them to process asynchronously enqueu...
std::shared_ptr< Random > RandomPtr
Definition random.hh:65
static RandomPtr genRandom()
Definition random.hh:68
Basic support for object serialization.
Definition serialize.hh:170
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Global events and related declarations.
DrainState
Object drain/handover states.
Definition drain.hh:75
static const Priority Sim_Exit_Pri
If we want to exit on this cycle, it's the very last thing we do.
Definition eventq.hh:237
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 4 > s
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 9 > d
Definition misc_types.hh:64
Bitfield< 0 > p
Bitfield< 2 > em
Definition misc.hh:617
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Tick
Tick count type.
Definition types.hh:58
std::shared_ptr< EthPacketData > EthPacketPtr
Definition etherpkt.hh:90
output header
Definition nop.cc:36
Received packet descriptor.
Desc(EthPacketPtr p, Tick s, Tick d)
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.

Generated on Mon Jan 13 2025 04:28:34 for gem5 by doxygen 1.9.8