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>
33 #define STOPACTIONPRIORITY 01
34 #define THREADSYNCPRIORITY 20
35 #define SYNCPRIORITY 25
36 #define INTROSPECTPRIORITY 30
37 #define CLOCKPRIORITY 40
38 #define EVENTPRIORITY 50
39 #define MEMEVENTPRIORITY 50
40 #define BARRIERPRIORITY 75
41 #define ONESHOTPRIORITY 80
42 #define STATISTICCLOCKPRIORITY 85
43 #define FINALEVENTPRIORITY 98
44 #define EXITPRIORITY 99
46 #define SST_ENFORCE_EVENT_ORDERING
48 extern int main(
int argc,
char **argv);
62 #ifdef SST_ENFORCE_EVENT_ORDERING
69 if ( lhs->delivery_time == rhs->delivery_time ) {
70 if ( lhs->priority == rhs->priority ) {
72 return lhs->enforce_link_order > rhs->enforce_link_order;
74 return lhs->priority > rhs->priority;
77 return lhs->delivery_time > rhs->delivery_time;
83 if ( lhs.delivery_time == rhs.delivery_time ) {
84 if ( lhs.priority == rhs.priority ) {
86 return lhs.enforce_link_order > rhs.enforce_link_order;
88 return lhs.priority > rhs.priority;
91 return lhs.delivery_time > rhs.delivery_time;
101 if ( lhs->delivery_time == rhs->delivery_time ) {
102 if ( lhs->priority == rhs->priority ) {
103 if ( lhs->enforce_link_order == rhs->enforce_link_order ) {
105 return lhs->queue_order > rhs->queue_order;
108 return lhs->enforce_link_order > rhs->enforce_link_order;
111 return lhs->priority > rhs->priority;
114 return lhs->delivery_time > rhs->delivery_time;
120 if ( lhs.delivery_time == rhs.delivery_time ) {
121 if ( lhs.priority == rhs.priority ) {
122 if ( lhs.enforce_link_order == rhs.enforce_link_order ) {
123 return lhs.queue_order > rhs.queue_order;
126 return lhs.enforce_link_order > rhs.enforce_link_order;
129 return lhs.priority > rhs.priority;
132 return lhs.delivery_time > rhs.delivery_time;
144 if (lhs->delivery_time == rhs->delivery_time )
return lhs->priority < rhs->priority;
145 else return lhs->delivery_time < rhs->delivery_time;
150 if (lhs.delivery_time == rhs.delivery_time )
return lhs.priority < rhs.priority;
151 else return lhs.delivery_time < rhs.delivery_time;
160 if ( lhs->delivery_time == rhs->delivery_time ) {
161 if ( lhs->priority == rhs->priority ) {
163 return lhs->queue_order > rhs->queue_order;
165 return lhs->priority > rhs->priority;
168 return lhs->delivery_time > rhs->delivery_time;
174 if ( lhs.delivery_time == rhs.delivery_time ) {
175 if ( lhs.priority == rhs.priority ) {
177 return lhs.queue_order > rhs.queue_order;
179 return lhs.priority > rhs.priority;
182 return lhs.delivery_time > rhs.delivery_time;
192 return lhs->delivery_time < rhs->delivery_time;
197 return lhs.delivery_time < rhs.delivery_time;
203 delivery_time = time;
208 return delivery_time;
219 virtual void print(
const std::string& header,
Output &out)
const {
220 out.
output(
"%s Generic Activity to be delivered at %" PRIu64
" with priority %d\n",
221 header.c_str(), delivery_time, priority);
224 #ifdef __SST_DEBUG_EVENT_TRACKING__
225 virtual void printTrackingInfo(
const std::string& header,
Output &out)
const {
236 void*
operator new(std::size_t size)
throw()
244 size_t nPools = memPools.size();
245 std::thread::id tid = std::this_thread::get_id();
246 for (
size_t i = 0 ; i < nPools ; i++ ) {
247 PoolInfo_t &p = memPools[i];
248 if ( p.tid == tid && p.size == size ) {
253 if ( NULL == pool ) {
255 pool =
new Core::MemPool(size+
sizeof(PoolData_t));
257 std::lock_guard<std::mutex> lock(poolMutex);
258 memPools.emplace_back(tid, size, pool);
261 PoolData_t *ptr = (PoolData_t*)pool->
malloc();
263 fprintf(stderr,
"Memory Pool failed to allocate a new object. Error: %s\n", strerror(errno));
267 return (
void*)(ptr+1);
272 void operator delete(
void* ptr)
279 PoolData_t *ptr8 = ((PoolData_t*)ptr) - 1;
280 Core::MemPool* pool = *ptr8;
285 void operator delete(
void* ptr, std::size_t UNUSED(sz)){
291 PoolData_t *ptr8 = ((PoolData_t*)ptr) - 1;
292 Core::MemPool* pool = *ptr8;
298 static void getMemPoolUsage(uint64_t& bytes, uint64_t& active_activities) {
300 active_activities = 0;
301 for (
auto && entry : Activity::memPools ) {
302 bytes += entry.pool->getBytesMemUsed();
303 active_activities += entry.pool->getUndeletedEntries();
307 static void printUndeletedActivites(
const std::string& header, Output &out, SimTime_t before = MAX_SIMTIME_T) {
308 for (
auto && entry : Activity::memPools ) {
309 const std::list<uint8_t*>& arenas = entry.pool->getArenas();
310 size_t arenaSize = entry.pool->getArenaSize();
311 size_t elemSize = entry.pool->getElementSize();
312 size_t nelem = arenaSize / elemSize;
313 for (
auto iter = arenas.begin(); iter != arenas.end(); ++iter ) {
314 for (
size_t j = 0; j < nelem; j++ ) {
315 PoolData_t* ptr = (PoolData_t*)((*iter) + (elemSize*j));
316 if ( *ptr != NULL ) {
317 Activity* act = (Activity*)(ptr + 1);
318 if ( act->delivery_time <= before ) {
319 act->print(header, out);
320 #ifdef __SST_DEBUG_EVENT_TRACKING__
321 act->printTrackingInfo(header +
" ", out);
341 this->priority = priority;
351 #ifdef SST_ENFORCE_EVENT_ORDERING
352 ser & enforce_link_order;
356 #ifdef SST_ENFORCE_EVENT_ORDERING
357 int32_t enforce_link_order;
361 uint64_t queue_order;
362 SimTime_t delivery_time;
365 friend int ::main(
int argc,
char **argv);
367 typedef Core::MemPool* PoolData_t;
372 PoolInfo_t(std::thread::id tid,
size_t size, Core::MemPool *pool) : tid(tid), size(size), pool(pool)
375 static std::mutex poolMutex;
376 static std::vector<PoolInfo_t> memPools;
384 #endif // SST_CORE_ACTIVITY_H
Output object provides consistant method for outputing 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:140
void setDeliveryTime(SimTime_t time)
Set the time for which this Activity should be delivered.
Definition: activity.h:202
void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition: activity.h:230
Base class for all Activities in the SST Event Queue.
Definition: activity.h:54
To use with STL container classes.
Definition: activity.h:65
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:173
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:100
bool operator()(const Activity &lhs, const Activity &rhs)
Compare references.
Definition: activity.h:196
void free(void *ptr)
Return an element to the memory pool.
Definition: mempool.h:92
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:68
Definition: serializable.h:109
bool operator()(const Activity &lhs, const Activity &rhs)
Compare based off references.
Definition: activity.h:149
void * malloc()
Allocate a new element from the memory pool.
Definition: mempool.h:78
void setPriority(int priority)
Set the priority of the Activity.
Definition: activity.h:340
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition: activity.h:207
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:159
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:184
To use with STL priority queues, that order in reverse.
Definition: activity.h:97
bool operator()(const Activity *lhs, const Activity *rhs)
Compare pointers.
Definition: activity.h:191
bool operator()(const Activity *lhs, const Activity *rhs)
Compare based off pointers.
Definition: activity.h:143
virtual void print(const std::string &header, Output &out) const
Generic print-print function for this Activity.
Definition: activity.h:219
int getPriority() const
Return the Priority of this Activity.
Definition: activity.h:212
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:82
Simple Memory Pool class.
Definition: mempool.h:33
To use with STL priority queues, that order in reverse.
Definition: activity.h:156
Comparator class to use with STL container classes.
Definition: activity.h:188
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:119