SST 12.1.0
Structural Simulation Toolkit
link.h
1// Copyright 2009-2022 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2022, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_LINK_H
13#define SST_CORE_LINK_H
14
15#include "sst/core/event.h"
16#include "sst/core/sst_types.h"
17#include "sst/core/timeConverter.h"
18
19namespace SST {
20
21#define _LINK_DBG(fmt, args...) __DBG(DBG_LINK, Link, fmt, ##args)
22
23class ActivityQueue;
24class BaseComponent;
25class TimeConverter;
26class LinkPair;
27class Simulation_impl;
28
29class UnitAlgebra;
30class LinkSendProfileToolList;
31
32namespace Profile {
33class EventHandlerProfileTool;
34}
35
36/** Link between two components. Carries events */
37class alignas(64) Link
38{
39 enum Type_t : uint16_t { POLL, HANDLER, SYNC, UNINITIALIZED };
40 enum Mode_t : uint16_t { INIT, RUN, COMPLETE };
41
42public:
43 friend class LinkPair;
44 friend class RankSync;
45 friend class ThreadSync;
46 friend class Simulation_impl;
47 friend class SyncManager;
48 friend class ComponentInfo;
49
50 ~Link();
51
52 /** Set additional Latency to be added to events being sent out of this link
53 * @param cycles Number of Cycles to be added
54 * @param timebase Base Units of cycles
55 */
56 void addSendLatency(int cycles, const std::string& timebase);
57
58 /** Set additional Latency to be added to events being sent out of this link
59 * @param cycles Number of Cycles to be added
60 * @param timebase Base Units of cycles
61 */
62 void addSendLatency(SimTime_t cycles, TimeConverter* timebase);
63
64 /** Set additional Latency to be added on to events coming in on this link.
65 * @param cycles Number of Cycles to be added
66 * @param timebase Base Units of cycles
67 */
68 void addRecvLatency(int cycles, const std::string& timebase);
69
70 /** Set additional Latency to be added on to events coming in on this link.
71 * @param cycles Number of Cycles to be added
72 * @param timebase Base Units of cycles
73 */
74 void addRecvLatency(SimTime_t cycles, TimeConverter* timebase);
75
76 /** Set the callback function to be called when a message is
77 * delivered. Not available for Polling links.
78 * @param functor Functor to call when message is delivered
79 */
80 void setFunctor(Event::HandlerBase* functor);
81
82 /** Replace the callback function to be called when a message is
83 * delivered. Any previous handler will be deleted.
84 * Not available for Polling links.
85 * @param functor Functor to call when message is delivered
86 */
88
89 /** Send an event over the link with additional delay. Sends an event
90 * over a link with an additional delay specified with a
91 * TimeConverter. I.e. the total delay is the link's delay + the
92 * additional specified delay.
93 * @param delay - additional delay
94 * @param tc - time converter to specify units for the additional delay
95 * @param event - the Event to send
96 */
97 inline void send(SimTime_t delay, TimeConverter* tc, Event* event)
98 {
99 send_impl(tc->convertToCoreTime(delay), event);
100 }
101
102 /** Send an event with additional delay. Sends an event over a link
103 * with additional delay specified by the Link's default
104 * timebase.
105 * @param delay The additional delay, in units of the default Link timebase
106 * @param event The event to send
107 */
108 inline void send(SimTime_t delay, Event* event) { send_impl(delay * defaultTimeBase, event); }
109
110 /** Send an event with the Link's default delay
111 * @param event The event to send
112 */
113 inline void send(Event* event) { send_impl(0, event); }
114
115
116 /** Retrieve a pending event from the Link. For links which do not
117 * have a set event handler, they can be polled with this function.
118 * Returns nullptr if there is no pending event.
119 * Not available for HANDLER-type links.
120 * @return Event if one is available
121 * @return nullptr if no Event is available
122 */
123 Event* recv();
124
125 /** Manually set the default detaulTimeBase
126 * @param tc TimeConverter object for the timebase
127 */
129
130 /** Return the default Time Base for this link
131 * @return the default Time Base for this link
132 */
134
135 /** Return the default Time Base for this link
136 * @return the default Time Base for this link
137 */
138 const TimeConverter* getDefaultTimeBase() const;
139
140 /** Return the ID of this link
141 * @return the unique ID for this link
142 */
143 LinkId_t getId() { return tag; }
144
145 /** Send data during the init() or complete() phase.
146 * @param data event to send
147 */
148 void sendUntimedData(Event* data);
149
150 /** Receive an event (if any) during the init() or complete() phase.
151 * @return Event if one is available
152 * @return nullptr if no Event is available
153 */
155
156 /** Send data during the init() or complete() phase.
157 * Same as sendUntimedData()
158 * @param init_data data to send
159 */
160 void sendInitData(Event* init_data) { sendUntimedData(init_data); }
161
162 /** Receive an event (if any) during the init() or complete() phase.
163 * Same as recvUntimedData()
164 * @return Event if one is available
165 * @return nullptr if no Event is available
166 */
168
169 /** Return whether link has been configured
170 * @return whether link is configured
171 */
172 bool isConfigured() { return type != UNINITIALIZED; }
173
174#ifdef __SST_DEBUG_EVENT_TRACKING__
175 void setSendingComponentInfo(const std::string& comp_in, const std::string& type_in, const std::string& port_in)
176 {
177 comp = comp_in;
178 ctype = type_in;
179 port = port_in;
180 }
181
182 const std::string& getSendingComponentName() { return comp; }
183 const std::string& getSendingComponentType() { return ctype; }
184 const std::string& getSendingPort() { return port; }
185
186#endif
187
188protected:
189 Link();
190
191 void setAsSyncLink() { type = SYNC; }
192
193 /**
194 Set the delivery_info for the link
195 */
196 void setDeliveryInfo(uintptr_t info) { delivery_info = info; }
197
198 /** Send an event over the link with additional delay. Sends an event
199 * over a link with an additional delay specified with a
200 * TimeConverter. I.e. the total delay is the link's delay + the
201 * additional specified delay.
202 * @param delay - additional total delay to add
203 * @param event - the Event to send
204 */
205 void send_impl(SimTime_t delay, Event* event);
206
207 // Since Links are found in pairs, I will keep all the information
208 // needed for me to send and deliver an event to the other side of
209 // the link. That means, that I mostly keep my pair's
210 // information. The one consequence, is that polling links will
211 // have to pull the data from the pair, but since this is a less
212 // common case, that's okay (this decision makes the common case
213 // faster and the less common case slower).
214
215 /** Queue of events to be received by the owning component */
217
218 /** Holds the delivery information. This is stored as a
219 uintptr_t, but is actually a pointer converted using
220 reinterpret_cast. For links connected to a
221 Component/SubComponent, this holds a pointer to the delivery
222 functor. For links connected to a Sync object, this holds a
223 pointer to the remote link to send the event on after
224 synchronization.
225 */
226 uintptr_t delivery_info;
227
228 /** Timebase used if no other timebase is specified. Used to specify
229 the units for added delays when sending, such as in
230 Link::send(). Often set by the Component::registerClock()
231 function if the regAll argument is true.
232 */
234
235 /** Latency of the link. It is used by the partitioner as the
236 weight. This latency is added to the delay put on the event by
237 the component.
238 */
239 SimTime_t latency;
240
241 /** Pointer to the opposite side of this link */
243
244private:
245 friend class BaseComponent;
246
247 SimTime_t& current_time;
248 Type_t type;
249 Mode_t mode;
250 LinkId_t tag;
251
252 /** Create a new link with a given tag
253
254 The tag is used for two different things depending on where
255 this link sends data:
256
257 If it sends it to a Sync object, then it represents the
258 remote_tag used to lookup the correct link on the other side.
259
260 If it sends to a TimeVortex (or DirectLinkQueue), it is the
261 value used for enforce_link_order (if that feature is
262 enabled).
263 */
264 Link(LinkId_t tag);
265
266 Link(const Link& l);
267
268 /** Specifies that this link has no callback, and is poll-based only */
269 void setPolling();
270
271 /** Causes an event to be delivered to the registered callback */
272 inline void deliverEvent(Event* event) const { (*reinterpret_cast<Event::HandlerBase*>(delivery_info))(event); }
273
274 /** Set minimum link latency */
275 void setLatency(Cycle_t lat);
276
277 void sendUntimedData_sync(Event* data);
278 void finalizeConfiguration();
279 void prepareForComplete();
280
281 void addProfileTool(SST::Profile::EventHandlerProfileTool* tool, const EventHandlerMetaData& mdata);
282
283
284 LinkSendProfileToolList* profile_tools;
285
286
287#ifdef __SST_DEBUG_EVENT_TRACKING__
288 std::string comp;
289 std::string ctype;
290 std::string port;
291#endif
292};
293
294/** Self Links are links from a component to itself */
295class SelfLink : public Link
296{
297public:
298 SelfLink() : Link()
299 {
300 pair_link = this;
301 latency = 0;
302 }
303};
304
305
306} // namespace SST
307
308#endif // SST_CORE_LINK_H
Base Class for a queue of Activities.
Definition: activityQueue.h:22
Main component object for the simulation.
Definition: baseComponent.h:51
Definition: componentInfo.h:40
Definition: event.h:211
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:35
Defines a pair of links (to define a connected link)
Definition: linkPair.h:24
Definition: link.cc:56
Definition: eventHandlerProfileTool.h:30
Definition: syncManager.h:38
Handlers with 1 handler defined argument to callback from caller.
Definition: ssthandler.h:171
Main control class for a SST Simulation.
Definition: simulation_impl.h:77
Definition: syncManager.h:120
Definition: syncManager.h:81
A class to convert between a component's view of time and the core's view of time.
Definition: timeConverter.h:27
SimTime_t convertToCoreTime(SimTime_t time) const
Converts from the component's view to the core's view of time.
Definition: timeConverter.h:36