13 #ifndef SST_CORE_ACTIVITY_H
14 #define SST_CORE_ACTIVITY_H
16 #include "sst/core/sst_types.h"
17 #include "sst/core/warnmacros.h"
19 #include "sst/core/serialization/serializable.h"
21 #include "sst/core/output.h"
22 #include "sst/core/mempool.h"
24 #include <unordered_map>
31 #define STOPACTIONPRIORITY 01
32 #define THREADSYNCPRIORITY 20
33 #define SYNCPRIORITY 25
34 #define INTROSPECTPRIORITY 30
35 #define CLOCKPRIORITY 40
36 #define EVENTPRIORITY 50
37 #define MEMEVENTPRIORITY 50
38 #define BARRIERPRIORITY 75
39 #define ONESHOTPRIORITY 80
40 #define STATISTICCLOCKPRIORITY 85
41 #define FINALEVENTPRIORITY 98
42 #define EXITPRIORITY 99
44 #define SST_ENFORCE_EVENT_ORDERING
46 extern int main(
int argc,
char **argv);
60 #ifdef SST_ENFORCE_EVENT_ORDERING
67 if ( lhs->delivery_time == rhs->delivery_time ) {
68 if ( lhs->priority == rhs->priority ) {
70 return lhs->enforce_link_order > rhs->enforce_link_order;
72 return lhs->priority > rhs->priority;
75 return lhs->delivery_time > rhs->delivery_time;
81 if ( lhs.delivery_time == rhs.delivery_time ) {
82 if ( lhs.priority == rhs.priority ) {
84 return lhs.enforce_link_order > rhs.enforce_link_order;
86 return lhs.priority > rhs.priority;
89 return lhs.delivery_time > rhs.delivery_time;
99 if ( lhs->delivery_time == rhs->delivery_time ) {
100 if ( lhs->priority == rhs->priority ) {
101 if ( lhs->enforce_link_order == rhs->enforce_link_order ) {
103 return lhs->queue_order > rhs->queue_order;
106 return lhs->enforce_link_order > rhs->enforce_link_order;
109 return lhs->priority > rhs->priority;
112 return lhs->delivery_time > rhs->delivery_time;
118 if ( lhs.delivery_time == rhs.delivery_time ) {
119 if ( lhs.priority == rhs.priority ) {
120 if ( lhs.enforce_link_order == rhs.enforce_link_order ) {
121 return lhs.queue_order > rhs.queue_order;
124 return lhs.enforce_link_order > rhs.enforce_link_order;
127 return lhs.priority > rhs.priority;
130 return lhs.delivery_time > rhs.delivery_time;
142 if (lhs->delivery_time == rhs->delivery_time )
return lhs->priority < rhs->priority;
143 else return lhs->delivery_time < rhs->delivery_time;
148 if (lhs.delivery_time == rhs.delivery_time )
return lhs.priority < rhs.priority;
149 else return lhs.delivery_time < rhs.delivery_time;
158 if ( lhs->delivery_time == rhs->delivery_time ) {
159 if ( lhs->priority == rhs->priority ) {
161 return lhs->queue_order > rhs->queue_order;
163 return lhs->priority > rhs->priority;
166 return lhs->delivery_time > rhs->delivery_time;
172 if ( lhs.delivery_time == rhs.delivery_time ) {
173 if ( lhs.priority == rhs.priority ) {
175 return lhs.queue_order > rhs.queue_order;
177 return lhs.priority > rhs.priority;
180 return lhs.delivery_time > rhs.delivery_time;
190 return lhs->delivery_time < rhs->delivery_time;
195 return lhs.delivery_time < rhs.delivery_time;
201 delivery_time = time;
206 return delivery_time;
217 virtual void print(
const std::string& header,
Output &out)
const {
218 out.
output(
"%s Generic Activity to be delivered at %" PRIu64
" with priority %d\n",
219 header.c_str(), delivery_time, priority);
222 #ifdef __SST_DEBUG_EVENT_TRACKING__
223 virtual void printTrackingInfo(
const std::string& header,
Output &out)
const {
234 void*
operator new(std::size_t size) noexcept
242 size_t nPools = memPools.size();
243 std::thread::id tid = std::this_thread::get_id();
244 for (
size_t i = 0 ; i < nPools ; i++ ) {
245 PoolInfo_t &p = memPools[i];
246 if ( p.tid == tid && p.size == size ) {
251 if (
nullptr == pool ) {
253 pool =
new Core::MemPool(size+
sizeof(PoolData_t));
255 std::lock_guard<std::mutex> lock(poolMutex);
256 memPools.emplace_back(tid, size, pool);
259 PoolData_t *ptr = (PoolData_t*)pool->
malloc();
261 fprintf(stderr,
"Memory Pool failed to allocate a new object. Error: %s\n", strerror(errno));
265 return (
void*)(ptr+1);
270 void operator delete(
void* ptr)
277 PoolData_t *ptr8 = ((PoolData_t*)ptr) - 1;
278 Core::MemPool* pool = *ptr8;
283 void operator delete(
void* ptr, std::size_t UNUSED(sz)){
289 PoolData_t *ptr8 = ((PoolData_t*)ptr) - 1;
290 Core::MemPool* pool = *ptr8;
296 static void getMemPoolUsage(uint64_t& bytes, uint64_t& active_activities) {
298 active_activities = 0;
299 for (
auto && entry : Activity::memPools ) {
300 bytes += entry.pool->getBytesMemUsed();
301 active_activities += entry.pool->getUndeletedEntries();
305 static void printUndeletedActivities(
const std::string& header, Output &out, SimTime_t before = MAX_SIMTIME_T) {
306 for (
auto && entry : Activity::memPools ) {
307 const std::list<uint8_t*>& arenas = entry.pool->getArenas();
308 size_t arenaSize = entry.pool->getArenaSize();
309 size_t elemSize = entry.pool->getElementSize();
310 size_t nelem = arenaSize / elemSize;
311 for (
auto iter = arenas.begin(); iter != arenas.end(); ++iter ) {
312 for (
size_t j = 0; j < nelem; j++ ) {
313 PoolData_t* ptr = (PoolData_t*)((*iter) + (elemSize*j));
314 if ( *ptr !=
nullptr ) {
315 Activity* act = (Activity*)(ptr + 1);
316 if ( act->delivery_time <= before ) {
317 act->print(header, out);
318 #ifdef __SST_DEBUG_EVENT_TRACKING__
319 act->printTrackingInfo(header +
" ", out);
339 this->priority = priority;
349 #ifdef SST_ENFORCE_EVENT_ORDERING
350 ser & enforce_link_order;
354 #ifdef SST_ENFORCE_EVENT_ORDERING
355 int32_t enforce_link_order;
359 uint64_t queue_order;
360 SimTime_t delivery_time;
363 friend int ::main(
int argc,
char **argv);
365 typedef Core::MemPool* PoolData_t;
370 PoolInfo_t(std::thread::id tid,
size_t size, Core::MemPool *pool) : tid(tid), size(size), pool(pool)
373 static std::mutex poolMutex;
374 static std::vector<PoolInfo_t> memPools;
382 #endif // SST_CORE_ACTIVITY_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
Comparator class to use with STL container classes.
Definition: activity.h:138
void setDeliveryTime(SimTime_t time)
Set the time for which this Activity should be delivered.
Definition: activity.h:200
void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition: activity.h:228
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare pointers.
Definition: activity.h:189
Base class for all Activities in the SST Event Queue.
Definition: activity.h:52
To use with STL container classes.
Definition: activity.h:63
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:171
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:98
void free(void *ptr)
Return an element to the memory pool.
Definition: mempool.h:96
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:66
Definition: serializable.h:109
bool operator()(const Activity &lhs, const Activity &rhs)
Compare based off references.
Definition: activity.h:147
void * malloc()
Allocate a new element from the memory pool.
Definition: mempool.h:77
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare references.
Definition: activity.h:194
void setPriority(int priority)
Set the priority of the Activity.
Definition: activity.h:338
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition: activity.h:205
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:157
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:186
To use with STL priority queues, that order in reverse.
Definition: activity.h:95
bool operator()(const Activity *lhs, const Activity *rhs)
Compare based off pointers.
Definition: activity.h:141
virtual void print(const std::string &header, Output &out) const
Generic print-print function for this Activity.
Definition: activity.h:217
int getPriority() const
Return the Priority of this Activity.
Definition: activity.h:210
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:80
Simple Memory Pool class.
Definition: mempool.h:32
To use with STL priority queues, that order in reverse.
Definition: activity.h:154
Comparator class to use with STL container classes.
Definition: activity.h:186
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:117