12 #ifndef SST_CORE_ACTIVITY_H
13 #define SST_CORE_ACTIVITY_H
15 #include "sst/core/mempool.h"
16 #include "sst/core/output.h"
17 #include "sst/core/serialization/serializable.h"
18 #include "sst/core/sst_types.h"
19 #include "sst/core/warnmacros.h"
25 #include <unordered_map>
28 #define STOPACTIONPRIORITY 01
29 #define THREADSYNCPRIORITY 20
30 #define SYNCPRIORITY 25
31 #define INTROSPECTPRIORITY 30
32 #define CLOCKPRIORITY 40
33 #define EVENTPRIORITY 50
34 #define MEMEVENTPRIORITY 50
35 #define BARRIERPRIORITY 75
36 #define ONESHOTPRIORITY 80
37 #define STATISTICCLOCKPRIORITY 85
38 #define FINALEVENTPRIORITY 98
39 #define EXITPRIORITY 99
41 extern int main(
int argc,
char** argv);
49 Activity() : delivery_time(0), priority_order(0), queue_order(0) {}
59 template <
bool T,
bool P,
bool Q>
65 if ( T && lhs->delivery_time != rhs->delivery_time )
return lhs->delivery_time < rhs->delivery_time;
66 if ( P && lhs->priority_order != rhs->priority_order )
return lhs->priority_order < rhs->priority_order;
67 return Q && lhs->queue_order < rhs->queue_order;
102 template <
bool T,
bool P,
bool Q>
108 if ( T && lhs->delivery_time != rhs->delivery_time )
return lhs->delivery_time > rhs->delivery_time;
109 if ( P && lhs->priority_order != rhs->priority_order )
return lhs->priority_order > rhs->priority_order;
110 return Q && lhs->queue_order > rhs->queue_order;
139 virtual void execute(
void) = 0;
148 inline int getPriority()
const {
return (
int)(priority_order >> 32); }
151 inline void setOrderTag(uint32_t tag) { priority_order = (priority_order & 0xFFFFFFFF00000000ul) | (uint64_t)tag; }
154 inline uint32_t
getOrderTag()
const {
return (uint32_t)(priority_order & 0xFFFFFFFFul); }
170 std::stringstream buf;
184 #ifdef __SST_DEBUG_EVENT_TRACKING__
185 virtual void printTrackingInfo(
const std::string& header,
Output& out)
const {}
190 void setPriority(uint64_t priority) { priority_order = (priority_order & 0x00000000FFFFFFFFul) | (priority << 32); }
199 std::stringstream buf;
225 SimTime_t delivery_time;
228 uint64_t priority_order;
231 uint64_t queue_order;
235 friend int ::main(
int argc,
char** argv);
243 PoolInfo_t(std::thread::id tid,
size_t size,
Core::MemPool* pool) : tid(tid), size(size), pool(pool) {}
245 static std::mutex poolMutex;
246 static std::vector<PoolInfo_t> memPools;
250 void*
operator new(std::size_t size) noexcept
257 Core::MemPool* pool =
nullptr;
258 size_t nPools = memPools.size();
259 std::thread::id tid = std::this_thread::get_id();
260 for (
size_t i = 0; i < nPools; i++ ) {
261 PoolInfo_t& p = memPools[i];
262 if ( p.tid == tid && p.size == size ) {
267 if (
nullptr == pool ) {
269 pool =
new Core::MemPool(size +
sizeof(PoolData_t));
271 std::lock_guard<std::mutex> lock(poolMutex);
272 memPools.emplace_back(tid, size, pool);
275 PoolData_t* ptr = (PoolData_t*)pool->malloc();
277 fprintf(stderr,
"Memory Pool failed to allocate a new object. Error: %s\n", strerror(errno));
281 return (
void*)(ptr + 1);
285 void operator delete(
void* ptr)
292 PoolData_t* ptr8 = ((PoolData_t*)ptr) - 1;
293 Core::MemPool* pool = *ptr8;
298 void operator delete(
void* ptr, std::size_t UNUSED(sz))
305 PoolData_t* ptr8 = ((PoolData_t*)ptr) - 1;
306 Core::MemPool* pool = *ptr8;
312 static void getMemPoolUsage(uint64_t& bytes, uint64_t& active_activities)
315 active_activities = 0;
316 for (
auto&& entry : Activity::memPools ) {
317 bytes += entry.pool->getBytesMemUsed();
318 active_activities += entry.pool->getUndeletedEntries();
322 static void printUndeletedActivities(
const std::string& header, Output& out, SimTime_t before = MAX_SIMTIME_T)
324 for (
auto&& entry : Activity::memPools ) {
325 const std::list<uint8_t*>& arenas = entry.pool->getArenas();
326 size_t arenaSize = entry.pool->getArenaSize();
327 size_t elemSize = entry.pool->getElementSize();
328 size_t nelem = arenaSize / elemSize;
329 for (
auto iter = arenas.begin(); iter != arenas.end(); ++iter ) {
330 for (
size_t j = 0; j < nelem; j++ ) {
331 PoolData_t* ptr = (PoolData_t*)((*iter) + (elemSize * j));
332 if ( *ptr !=
nullptr ) {
333 Activity* act = (Activity*)(ptr + 1);
334 if ( act->delivery_time <= before ) {
335 act->print(header, out);
336 #ifdef __SST_DEBUG_EVENT_TRACKING__
337 act->printTrackingInfo(header +
" ", out);
351 #endif // SST_CORE_ACTIVITY_H
virtual std::string toString() const
Get a string represenation of the event.
Definition: activity.h:168
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:51
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:34
void setDeliveryTime(SimTime_t time)
Set the time for which this Activity should be delivered.
Definition: activity.h:142
void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition: activity.h:218
Base class for all Activities in the SST Event Queue.
Definition: activity.h:46
uint32_t getOrderTag() const
Return the order tag associated with this activity.
Definition: activity.h:154
void setOrderTag(uint32_t tag)
Sets the order tag.
Definition: activity.h:151
virtual void execute(void)=0
Function which will be called when the time for this Activity comes to pass.
uint64_t getQueueOrder() const
Returns the queue order associated with this activity.
Definition: activity.h:157
void setPriority(uint64_t priority)
Set the priority of the Activity.
Definition: activity.h:190
Definition: serializable.h:118
std::string getDeliveryTimeInfo() const
Gets the delivery time info as a string.
Definition: activity.h:197
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition: activity.h:145
void output(uint32_t line, const char *file, const char *func, const char *format,...) const
Output the message with formatting as specified by the format parameter.
Definition: output.h:182
virtual void print(const std::string &header, Output &out) const
Generic print-print function for this Activity.
Definition: activity.h:179
int getPriority() const
Return the Priority of this Activity.
Definition: activity.h:148
Class to use as the greater than operator for STL functions or sorting algorithms (used if you want t...
Definition: activity.h:103
Simple Memory Pool class.
Definition: mempool.h:32
Class to use as the less than operator for STL functions or sorting algorithms.
Definition: activity.h:60