1 #if !defined(_MEMORYMANAGER_H_) 2 #define _MEMORYMANAGER_H_ 4 #include "MemoryController.h" 6 #include "ThreadManager.h" 7 #include "DataMessage.h" 11 #define PSYCLONE_STATUS_NONE 0 12 #define PSYCLONE_STATUS_ENDED 1 13 #define PSYCLONE_STATUS_INIT 2 14 #define PSYCLONE_STATUS_READY 3 16 #define DRAFTMSGSIZE 4096 32 #define PSYCLONE_INDEX_MAXCOUNT 128 33 #define PSYCLONE_INDEX_SIZE (sizeof(PsycloneIndexStruct) + (PSYCLONE_INDEX_MAXCOUNT * sizeof(PsycloneIndexEntry))) 37 static bool GetStatus(uint16 port, uint8& status, uint64& heartbeat);
41 bool init(uint16 port, uint64 instID);
42 bool setStatus(uint8 status);
56 uint64 currentCPUTicks;
58 uint64 currentMemoryBytes;
60 uint64 totalInputBytes;
61 uint64 totalInputCount;
62 uint64 totalOutputBytes;
63 uint64 totalOutputCount;
66 uint64 totalQueueBytes;
67 uint32 totalQueueCount;
69 uint64 firstRunStartTime;
70 uint64 currentRunStartTime;
71 uint64 totalCycleCount;
73 uint32 migrationCount;
82 double percentOfSystemCPU[3];
83 double percentOfOSCPU[3];
84 double localSystemCPUUsage[3];
85 double localSystemMemoryUsage[3];
86 double computerCPUUsage[3];
87 double computerMemoryUsage[3];
89 uint64 maxMemoryBytes;
90 double memoryBytesAverage[3];
92 double dataInputBytesPerSec[3];
93 double dataInputCountPerSec[3];
94 double dataOutputBytesPerSec[3];
95 double dataOutputCountPerSec[3];
97 double dataQueueBytesAverage[3];
98 uint64 dataQueueCountAverage[3];
100 double cycleCountPerSec[3];
102 std::string toXML() {
103 return utils::StringFormat(
"<performance time=\"%llu\" ms1=\"%u\" ms2=\"%u\" ms3=\"%u\" maxmemory=\"%llu\" " 104 "percentofsystemcpu1=\"%f\" percentofsystemcpu2=\"%f\" percentofsystemcpu3=\"%f\" " 105 "percentofoscpu1=\"%f\" percentofoscpu2=\"%f\" percentofoscpu3=\"%f\" " 106 "memorybytesaverage1=\"%f\" memorybytesaverage2=\"%f\" memorybytesaverage3=\"%f\" " 107 "datainputbytespersec1=\"%f\" datainputbytespersec2=\"%f\" datainputbytespersec3=\"%f\" " 108 "datainputcountpersec1=\"%f\" datainputcountpersec2=\"%f\" datainputcountpersec3=\"%f\" " 109 "dataoutputbytespersec1=\"%f\" dataoutputbytespersec2=\"%f\" dataoutputbytespersec3=\"%f\" " 110 "dataoutputcountpersec1=\"%f\" dataoutputcountpersec2=\"%f\" dataoutputcountpersec3=\"%f\" " 111 "dataqueuebytesaverage1=\"%f\" dataqueuebytesaverage2=\"%f\" dataqueuebytesaverage3=\"%f\" " 112 "dataqueuecountaverage1=\"%f\" dataqueuecountaverage2=\"%f\" dataqueuecountaverage3=\"%f\" " 113 "cyclecountpersec1=\"%f\" cyclecountpersec2=\"%f\" cyclecountpersec3=\"%f\" " 114 "localsystemcpuusage1=\"%f\" localsystemcpuusage2=\"%f\" localsystemcpuusage3=\"%f\" " 115 "localsystemmemoryusage1=\"%f\" localsystemmemoryusage2=\"%f\" localsystemmemoryusage3=\"%f\" " 116 "computercpuusage1=\"%f\" computercpuusage2=\"%f\" computercpuusage3=\"%f\" " 117 "computermemoryusage1=\"%f\" computermemoryusage2=\"%f\" computermemoryusage3=\"%f\" " 119 time, periodsMS[0], periodsMS[1], periodsMS[2], maxMemoryBytes,
120 percentOfSystemCPU[0], percentOfSystemCPU[1], percentOfSystemCPU[2],
121 percentOfOSCPU[0], percentOfOSCPU[1], percentOfOSCPU[2],
122 memoryBytesAverage[0], memoryBytesAverage[1], memoryBytesAverage[2],
123 dataInputBytesPerSec[0], dataInputBytesPerSec[1], dataInputBytesPerSec[2],
124 dataInputCountPerSec[0], dataInputCountPerSec[1], dataInputCountPerSec[2],
125 dataOutputBytesPerSec[0], dataOutputBytesPerSec[1], dataOutputBytesPerSec[2],
126 dataOutputCountPerSec[0], dataOutputCountPerSec[1], dataOutputCountPerSec[2],
127 dataQueueBytesAverage[0], dataQueueBytesAverage[1], dataQueueBytesAverage[2],
128 dataQueueCountAverage[0], dataQueueCountAverage[1], dataQueueCountAverage[2],
129 cycleCountPerSec[0], cycleCountPerSec[1], cycleCountPerSec[2],
130 localSystemCPUUsage[0], localSystemCPUUsage[1], localSystemCPUUsage[2],
131 localSystemMemoryUsage[0], localSystemMemoryUsage[1], localSystemMemoryUsage[2],
132 computerCPUUsage[0], computerCPUUsage[1], computerCPUUsage[2],
133 computerMemoryUsage[0], computerMemoryUsage[1], computerMemoryUsage[2]
147 int64 localSyncAdjustment;
150 uint64 currentCPUTicks;
151 uint32 componentCount;
152 uint32 throughputCount;
153 uint64 throughputSize;
154 uint32 dynamicShmemSerial;
155 uint32 processShmemSerial;
156 uint32 componentShmemSerial;
157 uint32 datamapsShmemSerial;
158 uint32 dynamicShmemLocks;
159 uint32 processShmemLocks;
160 uint32 componentShmemLocks;
162 uint64 dynamicShmemSize;
163 uint64 processShmemSize;
164 uint64 componentShmemSize;
165 uint64 datamapsShmemSize;
174 bool create(uint16 port);
175 bool open(uint16 port);
178 bool setNodeID(uint16
id);
179 uint64 getCreatedTime();
181 uint32 getDynamicShmemSerial();
182 uint32 getProcessShmemSerial();
183 uint32 getComponentShmemSerial();
184 uint32 getDataMapsShmemSerial();
185 uint32 incrementDynamicShmemSerial();
186 uint32 incrementProcessShmemSerial();
187 uint32 incrementComponentShmemSerial();
188 uint32 incrementDataMapsShmemSerial();
190 uint64 getDynamicShmemSize();
191 uint64 getProcessShmemSize();
192 uint64 getComponentShmemSize();
193 uint64 getDataMapsShmemSize();
194 bool setDynamicShmemSize(uint64 size);
195 bool setProcessShmemSize(uint64 size);
196 bool setComponentShmemSize(uint64 size);
197 bool setDataMapsShmemSize(uint64 size);
199 bool setID(uint16
id);
225 static bool UnitTest();
226 static bool ShmUnitTest();
228 friend THREAD_RET THREAD_FUNCTION_CALL MemoryManagement(THREAD_ARG arg);
233 bool getMemoryUsage(uint64& sysAlloc, uint64& sysUsage, uint64& dataAlloc, uint64& dataUsage);
235 uint8 getNodeStatus(uint64& lastseen, uint64& createdTime);
238 bool connect(uint16 sysID,
bool isMaster);
241 bool create(uint16 sysID, uint32 slotCount = 100000, uint16 binCount = 2, uint32 minBlockSize = 1024, uint32 maxBlockSize = 64*1024, uint64 initSize = 50000000L, uint64 maxSize = 1000000000L,
bool force =
false);
249 std::string typeToText(
PsyType type);
250 std::string subTypeToText(uint16 subtype);
251 std::string contextToText(
PsyContext context);
252 std::string subContextToText(uint16 subcontext);
253 std::string getComponentName(uint32 compID);
256 bool setNodeID(uint16
id);
261 bool getTimeSyncData(uint64& tmc, int64& adjust);
262 bool setTimeSyncData(uint64 tmc, int64 adjust);
274 bool resizeEOLPage(uint32 slotCount, uint32 pagesPerSlot, uint32 slotDuration);
283 uint32 managementThreadID;
300 #define MAXREGISTERCOUNT 64 308 THREAD_RET THREAD_FUNCTION_CALL MemoryManagement(THREAD_ARG arg);
310 #define NODE_PROCESS_ID 1 311 #define MAXINSTANCES 256 351 #define MP_GetBlockIndexStartLoc(p) ((char*)p + sizeof(MemoryPage)) 352 #define MP_GetBlockDataStartLoc(p) (MP_GetBlockIndexStartLoc(p) + (p->blockTableSize*sizeof(uint32)) ) 363 uint16 blockTableSize;
392 #define MP_SYSMEMID MP_CalcID(0, 0, pageMaster->nodeID) 393 #define MP_CalcID(pid,bid,nid) ((uint64)pid | (((uint64)bid) << 32) | (((uint64)nid) << 48)) 394 #define MP_SetBlockID(id,var) var |= (((uint64)id) << 32) 395 #define MP_SetNodeID(id,var) var |= (((uint64)id) << 48) 396 #define MP_SetPageID(id,var) var |= ((uint64)id) 397 #define MP_GetBlockID(id) (*(uint16*)((char*)&id + sizeof(uint32))) 398 #define MP_GetNodeID(id) (*(uint16*)((char*)&id + sizeof(uint32) + sizeof(uint16))) 399 #define MP_GetPageID(id) (*(uint32*)(char*)&id) 400 #define MP_GetBitFieldLoc(m) ((char*)m + sizeof(MemoryPageMaster)) 401 #define MP_GetPageTableLoc(m) (MP_GetBitFieldLoc(m) + m->bitFieldSize ) 402 #define MP_GetPageEntryLoc(m,pid) (MP_GetPageTableLoc(m) + (pid * sizeof(MemoryPageEntry)) ) 403 #define MP_GetPageLoc(m,pid) ((MemoryPageEntry*)MP_GetPageEntryLoc(m,pid))->page 405 #define MP_SYSTEMPAGE 0 406 #define MP_STATICPAGE 1 407 #define MP_DYNAMICPAGE 2 408 #define MP_GetPageType(id,eol) ( ((id < RESERVEDPAGECOUNT) ? MP_SYSTEMPAGE : (eol > 0 ? MP_DYNAMICPAGE : MP_STATICPAGE) ) ) 421 uint32 lastCreatedStaticPage;
423 uint32 pageTableSize;
436 static char* GetAndLockSystemBlock(uint32 pageID, uint32& size);
437 static bool UnlockSystemBlock(uint32 pageID);
439 static char* CreateAndLockNewSystemPage(uint32 size, uint32&
id);
441 static char* ResizeSystemPage(uint32 pageID, uint32 newSize);
442 static bool GetMemoryUsage(uint32& total, uint32& usage, uint32& sysTotal, uint32& sysUsage, uint32& staticTotal, uint32& staticUsage, uint32& dynamicTotal, uint32& dynamicUsage);
444 static bool DestroySystemPage(uint32 pageID);
446 static bool InsertMemoryBlock(
const char* data, uint32 size, uint64 eol, uint64&
id);
447 static bool OverwriteMemoryBlock(uint64
id,
const char* data, uint32 size, uint64 eol);
448 static char* GetAndLockMemoryBlock(uint64
id, uint32& size, uint64& eol);
449 static bool UnlockMemoryBlock(uint64
id);
450 static char* GetCopyMemoryBlock(uint64
id, uint32& size, uint64& eol);
452 static bool UnitTest();
454 friend THREAD_RET THREAD_FUNCTION_CALL MemoryManagement(THREAD_ARG arg);
460 bool connect(uint16 sysID);
463 bool create(uint16 sysID, uint32 staticPageTableSize = 100, uint32 slotCount = 360, uint32 slotDuration = 60000000, uint32 pagesPerSlot = 10,
bool force =
false);
469 bool insertMemoryBlock(
const char* data, uint32 size, uint64 eol, uint64&
id);
472 bool overwriteMemoryBlock(uint64
id,
const char* data, uint32 size, uint64 eol);
474 char* getAndLockMemoryBlock(uint64
id, uint32& size, uint64& eol);
475 char* getLockedMemoryBlock(
MemoryPage* page, uint64
id, uint32& size, uint64& eol);
476 bool unlockMemoryBlock(uint64
id);
477 char* getCopyMemoryBlock(uint64
id, uint32& size, uint64& eol);
480 char* getSystemBlock(uint32 pageID, uint32& size);
483 char* getAndLockSystemBlock(uint32 pageID, uint32& size);
484 char* getLockedSystemBlock(uint32 pageID, uint32& size);
485 char* getLockedSystemBlock(
MemoryPage* page, uint32& size);
488 bool unlockSystemBlock(uint32 pageID);
491 char* createAndLockNewSystemPage(uint32 size, uint32&
id);
493 char* resizeSystemPage(uint32 pageID, uint32 size);
497 MemoryPage* createPage(uint32 size, uint16 tableSize, uint64 eol, uint32& pageID);
500 bool insertMemoryBlockIntoPage(uint32 pageID,
const char* data, uint32 size, uint64 eol, uint64&
id);
512 bool lockPage(uint32 pageID);
513 bool unlockPage(uint32 pageID);
520 MemoryPage* findPageForBlock(uint32 size, uint64 eol, uint32&
id);
523 bool freePageIntoPool(uint32 pageID);
526 bool removePageFromStats(uint32 pageID, uint32& dataSize);
529 bool insertPageIntoPool(uint32 pageID, uint32 dataSize);
532 bool getPageFromPool(uint32 size, uint32& pageID);
535 bool destroyAllPages();
538 bool destroyPage(uint32 pageID,
bool updateStats =
true);
544 char* getBitFieldAsString(uint32& size);
546 bool printBitFieldAsString(
char* title);
549 bool getPageUsage(uint32 pageID,
double& val);
551 double getPageUsage(uint32 pageID);
553 bool getPageFree(uint32 pageID, uint32& bytes);
555 bool getPageSize(uint32 pageID, uint32& bytes);
558 char* createSystemPage(uint32
id, uint32 size, uint64& memID);
561 bool createSystemPages();
564 bool initSystemPage(
char* data, uint32 size);
567 bool initPagePool(
char* data, uint32 size);
570 bool resizeEOLPage(uint32 slotCount, uint32 pagesPerSlot, uint32 slotDuration, uint32 bufferSlots);
573 bool insertPageIntoEOL(uint32 pageID, uint64 eol, uint64& slotEOL);
576 bool initQueuePage(
char* data, uint32 size);
579 static uint16 CalcBlockTableSize(uint32 size);
591 uint32 managementThreadID;
597 #include "TemporalMemory.h" 598 #include "ComponentMemory.h" 599 #include "DataMapsMemory.h" 600 #include "ProcessMemory.h" 602 #endif //_MEMORYMANAGER_H_ Definition: MemoryManager.h:320
Definition: MemoryManager.h:384
Definition: MemoryManager.h:169
Definition: MemoryManager.h:432
Definition: MemoryController.h:9
Definition: MemoryManager.h:139
Definition: DataMapsMemory.h:190
Definition: MemoryManager.h:330
Definition: MemoryManager.h:35
Definition: MemoryManager.h:302
Definition: MemoryManager.h:314
Definition: MemoryManager.h:410
Definition: MemoryManager.h:357
Definition: MemoryManager.h:214
Definition: MemoryManager.h:368
Definition: MemoryManager.h:378
Definition: MemoryManager.h:48
Definition: ProcessMemory.h:125
Definition: TemporalMemory.h:67
Definition: MemoryManager.h:18
Definition: ComponentMemory.h:184
Definition: MemoryManager.h:25
Definition: MemoryManager.h:346
Definition: MemoryManager.h:76
Definition: DataMessage.h:95