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 #define SST_ENFORCE_EVENT_ORDERING
43 extern int main(
int argc,
char** argv);
57 #ifdef SST_ENFORCE_EVENT_ORDERING
68 if ( lhs->priority == rhs->priority ) {
return lhs->enforce_link_order < rhs->enforce_link_order; }
70 return lhs->priority < rhs->priority;
77 if ( lhs.priority == rhs.priority ) {
return lhs.enforce_link_order < rhs.enforce_link_order; }
79 return lhs.priority < rhs.priority;
93 if ( lhs->priority == rhs->priority ) {
94 if ( lhs->enforce_link_order == rhs->enforce_link_order ) {
95 return lhs->queue_order > rhs->queue_order;
98 return lhs->enforce_link_order > rhs->enforce_link_order;
102 return lhs->priority > rhs->priority;
109 if ( lhs.priority == rhs.priority ) {
110 if ( lhs.enforce_link_order == rhs.enforce_link_order ) {
return lhs.queue_order > rhs.queue_order; }
112 return lhs.enforce_link_order > rhs.enforce_link_order;
116 return lhs.priority > rhs.priority;
128 if ( lhs->delivery_time == rhs->delivery_time ) {
129 if ( lhs->priority == rhs->priority ) {
131 return lhs->enforce_link_order < rhs->enforce_link_order;
134 return lhs->priority < rhs->priority;
138 return lhs->delivery_time < rhs->delivery_time;
145 if ( lhs.delivery_time == rhs.delivery_time ) {
146 if ( lhs.priority == rhs.priority ) {
148 return lhs.enforce_link_order < rhs.enforce_link_order;
151 return lhs.priority < rhs.priority;
155 return lhs.delivery_time < rhs.delivery_time;
167 if ( lhs->delivery_time == rhs->delivery_time ) {
168 if ( lhs->priority == rhs->priority ) {
169 if ( lhs->enforce_link_order == rhs->enforce_link_order ) {
171 return lhs->queue_order > rhs->queue_order;
174 return lhs->enforce_link_order > rhs->enforce_link_order;
178 return lhs->priority > rhs->priority;
182 return lhs->delivery_time > rhs->delivery_time;
189 if ( lhs.delivery_time == rhs.delivery_time ) {
190 if ( lhs.priority == rhs.priority ) {
191 if ( lhs.enforce_link_order == rhs.enforce_link_order ) {
192 return lhs.queue_order > rhs.queue_order;
195 return lhs.enforce_link_order > rhs.enforce_link_order;
199 return lhs.priority > rhs.priority;
203 return lhs.delivery_time > rhs.delivery_time;
230 if ( lhs->priority == rhs->priority ) {
return lhs->queue_order > rhs->queue_order; }
232 return lhs->priority > rhs->priority;
239 if ( lhs.priority == rhs.priority ) {
return lhs.queue_order > rhs.queue_order; }
241 return lhs.priority > rhs.priority;
253 if ( lhs->delivery_time == rhs->delivery_time )
254 return lhs->priority < rhs->priority;
256 return lhs->delivery_time < rhs->delivery_time;
262 if ( lhs.delivery_time == rhs.delivery_time )
263 return lhs.priority < rhs.priority;
265 return lhs.delivery_time < rhs.delivery_time;
276 if ( lhs->delivery_time == rhs->delivery_time ) {
277 if ( lhs->priority == rhs->priority ) {
279 return lhs->queue_order > rhs->queue_order;
282 return lhs->priority > rhs->priority;
286 return lhs->delivery_time > rhs->delivery_time;
293 if ( lhs.delivery_time == rhs.delivery_time ) {
294 if ( lhs.priority == rhs.priority ) {
296 return lhs.queue_order > rhs.queue_order;
299 return lhs.priority > rhs.priority;
303 return lhs.delivery_time > rhs.delivery_time;
315 return lhs->delivery_time < rhs->delivery_time;
321 return lhs.delivery_time < rhs.delivery_time;
334 std::string getDeliveryTimeInfo()
const
336 std::stringstream buf;
337 buf <<
"time: " << delivery_time <<
", priority: " << priority;
352 std::stringstream buf;
354 buf << cls_name() <<
" to be delivered at " << getDeliveryTimeInfo();
366 #ifdef __SST_DEBUG_EVENT_TRACKING__
367 virtual void printTrackingInfo(
const std::string& header,
Output& out)
const {}
373 uint64_t getQueueOrder() {
return queue_order; }
377 void*
operator new(std::size_t size) noexcept
384 Core::MemPool* pool =
nullptr;
385 size_t nPools = memPools.size();
386 std::thread::id tid = std::this_thread::get_id();
387 for (
size_t i = 0; i < nPools; i++ ) {
388 PoolInfo_t& p = memPools[i];
389 if ( p.tid == tid && p.size == size ) {
394 if (
nullptr == pool ) {
396 pool =
new Core::MemPool(size +
sizeof(PoolData_t));
398 std::lock_guard<std::mutex> lock(poolMutex);
399 memPools.emplace_back(tid, size, pool);
402 PoolData_t* ptr = (PoolData_t*)pool->malloc();
404 fprintf(stderr,
"Memory Pool failed to allocate a new object. Error: %s\n", strerror(errno));
408 return (
void*)(ptr + 1);
412 void operator delete(
void* ptr)
419 PoolData_t* ptr8 = ((PoolData_t*)ptr) - 1;
420 Core::MemPool* pool = *ptr8;
425 void operator delete(
void* ptr, std::size_t UNUSED(sz))
432 PoolData_t* ptr8 = ((PoolData_t*)ptr) - 1;
433 Core::MemPool* pool = *ptr8;
439 static void getMemPoolUsage(uint64_t& bytes, uint64_t& active_activities)
442 active_activities = 0;
443 for (
auto&& entry : Activity::memPools ) {
444 bytes += entry.pool->getBytesMemUsed();
445 active_activities += entry.pool->getUndeletedEntries();
449 static void printUndeletedActivities(
const std::string& header, Output& out, SimTime_t before = MAX_SIMTIME_T)
451 for (
auto&& entry : Activity::memPools ) {
452 const std::list<uint8_t*>& arenas = entry.pool->getArenas();
453 size_t arenaSize = entry.pool->getArenaSize();
454 size_t elemSize = entry.pool->getElementSize();
455 size_t nelem = arenaSize / elemSize;
456 for (
auto iter = arenas.begin(); iter != arenas.end(); ++iter ) {
457 for (
size_t j = 0; j < nelem; j++ ) {
458 PoolData_t* ptr = (PoolData_t*)((*iter) + (elemSize * j));
459 if ( *ptr !=
nullptr ) {
460 Activity* act = (Activity*)(ptr + 1);
461 if ( act->delivery_time <= before ) {
462 act->print(header, out);
463 #ifdef __SST_DEBUG_EVENT_TRACKING__
464 act->printTrackingInfo(header +
" ", out);
479 int32_t getEnforceLinkOrder() {
return enforce_link_order; }
493 #ifdef SST_ENFORCE_EVENT_ORDERING
494 ser& enforce_link_order;
498 #ifdef SST_ENFORCE_EVENT_ORDERING
499 int32_t enforce_link_order;
503 uint64_t queue_order;
504 SimTime_t delivery_time;
507 friend int ::main(
int argc,
char** argv);
509 typedef Core::MemPool* PoolData_t;
515 PoolInfo_t(std::thread::id tid,
size_t size, Core::MemPool* pool) : tid(tid), size(size), pool(pool) {}
517 static std::mutex poolMutex;
518 static std::vector<PoolInfo_t> memPools;
526 #endif // SST_CORE_ACTIVITY_H
virtual std::string toString() const
Get a string represenation of the event.
Definition: activity.h:350
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
Comparator class to use with STL container classes.
Definition: activity.h:247
void setDeliveryTime(SimTime_t time)
Set the time for which this Activity should be delivered.
Definition: activity.h:326
void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition: activity.h:371
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare pointers.
Definition: activity.h:313
Base class for all Activities in the SST Event Queue.
Definition: activity.h:48
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:237
To use with STL container classes.
Definition: activity.h:122
Comparator class to use with STL container classes.
Definition: activity.h:213
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:291
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:91
virtual void execute(void)=0
Function which will be called when the time for this Activity comes to pass.
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:165
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:66
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:126
Definition: serializable.h:118
bool operator()(const Activity &lhs, const Activity &rhs)
Compare based off references.
Definition: activity.h:260
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare references.
Definition: activity.h:319
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:107
void setPriority(int priority)
Set the priority of the Activity.
Definition: activity.h:483
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition: activity.h:329
To use with STL priority queues, that order in reverse.
Definition: activity.h:87
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:274
To use with STL priority queues, that order in reverse.
Definition: activity.h:224
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
To use with STL priority queues, that order in reverse.
Definition: activity.h:161
bool operator()(const Activity *lhs, const Activity *rhs)
Compare based off pointers.
Definition: activity.h:251
virtual void print(const std::string &header, Output &out) const
Generic print-print function for this Activity.
Definition: activity.h:361
To use with STL container classes.
Definition: activity.h:62
int getPriority() const
Return the Priority of this Activity.
Definition: activity.h:332
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:143
bool operator()(const Activity *lhs, const Activity *rhs)
Compare based off pointers.
Definition: activity.h:217
To use with STL priority queues, that order in reverse.
Definition: activity.h:270
Comparator class to use with STL container classes.
Definition: activity.h:309
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:187
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:228
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:75
bool operator()(const Activity &lhs, const Activity &rhs)
Compare based off references.
Definition: activity.h:220