13 #ifndef SST_CORE_ACTIVITY_H
14 #define SST_CORE_ACTIVITY_H
16 #include <sst/core/sst_types.h>
18 #include <sst/core/serialization/serializable.h>
20 #include <sst/core/output.h>
21 #include <sst/core/mempool.h>
23 #include <unordered_map>
32 #define STOPACTIONPRIORITY 01
33 #define THREADSYNCPRIORITY 20
34 #define SYNCPRIORITY 25
35 #define INTROSPECTPRIORITY 30
36 #define CLOCKPRIORITY 40
37 #define EVENTPRIORITY 50
38 #define MEMEVENTPRIORITY 50
39 #define BARRIERPRIORITY 75
40 #define ONESHOTPRIORITY 80
41 #define STATISTICCLOCKPRIORITY 85
42 #define FINALEVENTPRIORITY 98
43 #define EXITPRIORITY 99
45 #define SST_ENFORCE_EVENT_ORDERING
47 extern int main(
int argc,
char **argv);
61 #ifdef SST_ENFORCE_EVENT_ORDERING
68 if ( lhs->delivery_time == rhs->delivery_time ) {
69 if ( lhs->priority == rhs->priority ) {
71 return lhs->enforce_link_order > rhs->enforce_link_order;
73 return lhs->priority > rhs->priority;
76 return lhs->delivery_time > rhs->delivery_time;
82 if ( lhs.delivery_time == rhs.delivery_time ) {
83 if ( lhs.priority == rhs.priority ) {
85 return lhs.enforce_link_order > rhs.enforce_link_order;
87 return lhs.priority > rhs.priority;
90 return lhs.delivery_time > rhs.delivery_time;
100 if ( lhs->delivery_time == rhs->delivery_time ) {
101 if ( lhs->priority == rhs->priority ) {
102 if ( lhs->enforce_link_order == rhs->enforce_link_order ) {
104 return lhs->queue_order > rhs->queue_order;
107 return lhs->enforce_link_order > rhs->enforce_link_order;
110 return lhs->priority > rhs->priority;
113 return lhs->delivery_time > rhs->delivery_time;
119 if ( lhs.delivery_time == rhs.delivery_time ) {
120 if ( lhs.priority == rhs.priority ) {
121 if ( lhs.enforce_link_order == rhs.enforce_link_order ) {
122 return lhs.queue_order > rhs.queue_order;
125 return lhs.enforce_link_order > rhs.enforce_link_order;
128 return lhs.priority > rhs.priority;
131 return lhs.delivery_time > rhs.delivery_time;
143 if (lhs->delivery_time == rhs->delivery_time )
return lhs->priority < rhs->priority;
144 else return lhs->delivery_time < rhs->delivery_time;
149 if (lhs.delivery_time == rhs.delivery_time )
return lhs.priority < rhs.priority;
150 else return lhs.delivery_time < rhs.delivery_time;
159 if ( lhs->delivery_time == rhs->delivery_time ) {
160 if ( lhs->priority == rhs->priority ) {
162 return lhs->queue_order > rhs->queue_order;
164 return lhs->priority > rhs->priority;
167 return lhs->delivery_time > rhs->delivery_time;
173 if ( lhs.delivery_time == rhs.delivery_time ) {
174 if ( lhs.priority == rhs.priority ) {
176 return lhs.queue_order > rhs.queue_order;
178 return lhs.priority > rhs.priority;
181 return lhs.delivery_time > rhs.delivery_time;
191 return lhs->delivery_time < rhs->delivery_time;
196 return lhs.delivery_time < rhs.delivery_time;
202 delivery_time = time;
207 return delivery_time;
218 virtual void print(
const std::string& header,
Output &out)
const {
219 out.
output(
"%s Generic Activity to be delivered at %" PRIu64
" with priority %d\n",
220 header.c_str(), delivery_time, priority);
223 #ifdef __SST_DEBUG_EVENT_TRACKING__
224 virtual void printTrackingInfo(
const std::string& header,
Output &out)
const {
235 void*
operator new(std::size_t size)
throw()
243 size_t nPools = memPools.size();
244 std::thread::id tid = std::this_thread::get_id();
245 for (
size_t i = 0 ; i < nPools ; i++ ) {
246 PoolInfo_t &p = memPools[i];
247 if ( p.tid == tid && p.size == size ) {
252 if ( NULL == pool ) {
254 pool =
new Core::MemPool(size+
sizeof(PoolData_t));
256 std::lock_guard<std::mutex> lock(poolMutex);
257 memPools.emplace_back(tid, size, pool);
260 PoolData_t *ptr = (PoolData_t*)pool->
malloc();
262 fprintf(stderr,
"Memory Pool failed to allocate a new object. Error: %s\n", strerror(errno));
266 return (
void*)(ptr+1);
271 void operator delete(
void* ptr)
278 PoolData_t *ptr8 = ((PoolData_t*)ptr) - 1;
279 Core::MemPool* pool = *ptr8;
284 void operator delete(
void* ptr, std::size_t sz){
290 PoolData_t *ptr8 = ((PoolData_t*)ptr) - 1;
291 Core::MemPool* pool = *ptr8;
297 static void getMemPoolUsage(uint64_t& bytes, uint64_t& active_activities) {
299 active_activities = 0;
300 for (
auto && entry : Activity::memPools ) {
301 bytes += entry.pool->getBytesMemUsed();
302 active_activities += entry.pool->getUndeletedEntries();
306 static void printUndeletedActivites(
const std::string& header, Output &out, SimTime_t before = MAX_SIMTIME_T) {
307 for (
auto && entry : Activity::memPools ) {
308 const std::list<uint8_t*>& arenas = entry.pool->getArenas();
309 size_t arenaSize = entry.pool->getArenaSize();
310 size_t elemSize = entry.pool->getElementSize();
311 size_t nelem = arenaSize / elemSize;
312 for (
auto iter = arenas.begin(); iter != arenas.end(); ++iter ) {
313 for (
size_t j = 0; j < nelem; j++ ) {
314 PoolData_t* ptr = (PoolData_t*)((*iter) + (elemSize*j));
315 if ( *ptr != NULL ) {
316 Activity* act = (Activity*)(ptr + 1);
317 if ( act->delivery_time <= before ) {
318 act->print(header, out);
319 #ifdef __SST_DEBUG_EVENT_TRACKING__
320 act->printTrackingInfo(header +
" ", out);
340 this->priority = priority;
350 #ifdef SST_ENFORCE_EVENT_ORDERING
351 ser & enforce_link_order;
355 #ifdef SST_ENFORCE_EVENT_ORDERING
356 int32_t enforce_link_order;
360 uint64_t queue_order;
361 SimTime_t delivery_time;
364 friend int ::main(
int argc,
char **argv);
366 typedef Core::MemPool* PoolData_t;
371 PoolInfo_t(std::thread::id tid,
size_t size, Core::MemPool *pool) : tid(tid), size(size), pool(pool)
374 static std::mutex poolMutex;
375 static std::vector<PoolInfo_t> memPools;
383 #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:139
void setDeliveryTime(SimTime_t time)
Set the time for which this Activity should be delivered.
Definition: activity.h:201
void setQueueOrder(uint64_t order)
Set a new Queue order.
Definition: activity.h:229
Base class for all Activities in the SST Event Queue.
Definition: activity.h:53
To use with STL container classes.
Definition: activity.h:64
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:172
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:99
bool operator()(const Activity &lhs, const Activity &rhs)
Compare references.
Definition: activity.h:195
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:67
Definition: serializable.h:108
bool operator()(const Activity &lhs, const Activity &rhs)
Compare based off references.
Definition: activity.h:148
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:339
SimTime_t getDeliveryTime() const
Return the time at which this Activity will be delivered.
Definition: activity.h:206
bool operator()(const Activity *lhs, const Activity *rhs) const
Compare based off pointers.
Definition: activity.h:158
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:96
bool operator()(const Activity *lhs, const Activity *rhs)
Compare pointers.
Definition: activity.h:190
bool operator()(const Activity *lhs, const Activity *rhs)
Compare based off pointers.
Definition: activity.h:142
virtual void print(const std::string &header, Output &out) const
Generic print-print function for this Activity.
Definition: activity.h:218
int getPriority() const
Return the Priority of this Activity.
Definition: activity.h:211
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:81
Simple Memory Pool class.
Definition: mempool.h:33
To use with STL priority queues, that order in reverse.
Definition: activity.h:155
Comparator class to use with STL container classes.
Definition: activity.h:187
bool operator()(const Activity &lhs, const Activity &rhs) const
Compare based off references.
Definition: activity.h:118