CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
MemoryManager.h
Go to the documentation of this file.
1
92
93#if !defined(_MEMORYMANAGER_H_)
94#define _MEMORYMANAGER_H_
95
96#include "MemoryController.h"
97#include "Utils.h"
98#include "ThreadManager.h"
99#include "DataMessage.h"
100
101namespace cmlabs {
102
105#define PSYCLONE_STATUS_NONE 0
106#define PSYCLONE_STATUS_ENDED 1
107#define PSYCLONE_STATUS_INIT 2
108#define PSYCLONE_STATUS_READY 3
110
113#define DRAFTMSGSIZE 4096
114
123 uint32 size;
124 uint32 cid;
125 uint32 count;
126 // PsycloneIndexEntries
127};
128
132 uint16 port;
133 uint8 status;
134 uint64 heartbeat;
135 uint64 instanceID;
136};
137
139#define PSYCLONE_INDEX_MAXCOUNT 128
141#define PSYCLONE_INDEX_SIZE (sizeof(PsycloneIndexStruct) + (PSYCLONE_INDEX_MAXCOUNT * sizeof(PsycloneIndexEntry)))
142
152public:
158 static bool GetStatus(uint16 port, uint8& status, uint64& heartbeat);
159
165 bool init(uint16 port, uint64 instID);
168 bool setStatus(uint8 status);
169private:
170 PsycloneIndexStruct* index;
171 PsycloneIndexEntry* entry;
172};
173
179struct PerfStats {
180 uint32 compID;
181 uint16 spaceID;
182 uint16 nodeID;
183 uint32 osID;
184 uint8 type;
185 uint8 status; // Component status (idle, running, etc.)
186
188
190
195
196 uint64 runCount;
199
205};
206
214 uint64 time;
215 uint32 periodsMS[3];
216
218
220 double percentOfOSCPU[3];
225
228
233
236
238
241 std::string toXML() {
242 return utils::StringFormat("<performance time=\"%llu\" ms1=\"%u\" ms2=\"%u\" ms3=\"%u\" maxmemory=\"%llu\" "
243 "percentofsystemcpu1=\"%f\" percentofsystemcpu2=\"%f\" percentofsystemcpu3=\"%f\" "
244 "percentofoscpu1=\"%f\" percentofoscpu2=\"%f\" percentofoscpu3=\"%f\" "
245 "memorybytesaverage1=\"%f\" memorybytesaverage2=\"%f\" memorybytesaverage3=\"%f\" "
246 "datainputbytespersec1=\"%f\" datainputbytespersec2=\"%f\" datainputbytespersec3=\"%f\" "
247 "datainputcountpersec1=\"%f\" datainputcountpersec2=\"%f\" datainputcountpersec3=\"%f\" "
248 "dataoutputbytespersec1=\"%f\" dataoutputbytespersec2=\"%f\" dataoutputbytespersec3=\"%f\" "
249 "dataoutputcountpersec1=\"%f\" dataoutputcountpersec2=\"%f\" dataoutputcountpersec3=\"%f\" "
250 "dataqueuebytesaverage1=\"%f\" dataqueuebytesaverage2=\"%f\" dataqueuebytesaverage3=\"%f\" "
251 "dataqueuecountaverage1=\"%f\" dataqueuecountaverage2=\"%f\" dataqueuecountaverage3=\"%f\" "
252 "cyclecountpersec1=\"%f\" cyclecountpersec2=\"%f\" cyclecountpersec3=\"%f\" "
253 "localsystemcpuusage1=\"%f\" localsystemcpuusage2=\"%f\" localsystemcpuusage3=\"%f\" "
254 "localsystemmemoryusage1=\"%f\" localsystemmemoryusage2=\"%f\" localsystemmemoryusage3=\"%f\" "
255 "computercpuusage1=\"%f\" computercpuusage2=\"%f\" computercpuusage3=\"%f\" "
256 "computermemoryusage1=\"%f\" computermemoryusage2=\"%f\" computermemoryusage3=\"%f\" "
257 "/>\n",
273 );
274 }
275};
276
277
287 uint64 size;
288 uint32 cid;
289 uint16 nodeID;
290 uint16 status;
291 uint64 createdTime;
292 // uint64 timesync; // time sync
293 uint64 currentTMC;
295 uint64 memAlloc;
296 uint64 memUsage;
308 // uint32 datamapsShmemLocks; // nothing ever locks in here beyond the simple mutex
313};
314
315class MemoryManager;
325 friend class MemoryManager;
326public:
327 MasterMemory();
331 bool create(uint16 port);
334 bool open(uint16 port);
335
337 uint16 getNodeID();
339 bool setNodeID(uint16 id);
341 uint64 getCreatedTime();
342
348 uint32 getDynamicShmemSerial();
349 uint32 getProcessShmemSerial();
350 uint32 getComponentShmemSerial();
351 uint32 getDataMapsShmemSerial();
357
362 uint64 getDynamicShmemSize();
363 uint64 getProcessShmemSize();
364 uint64 getComponentShmemSize();
365 uint64 getDataMapsShmemSize();
366 bool setDynamicShmemSize(uint64 size);
367 bool setProcessShmemSize(uint64 size);
368 bool setComponentShmemSize(uint64 size);
369 bool setDataMapsShmemSize(uint64 size);
371
372 bool setID(uint16 id);
373 uint16 getID();
374
375 uint16 port;
376
377private:
378 utils::Mutex* mutex;
379 MemoryMasterStruct* master;
380};
381
382class TemporalMemory;
383class ProcessMemory;
384class ComponentMemory;
385class DataMapsMemory;
386
413public:
415
416 //static bool GetMemoryUsage(uint32& total, uint32& usage, uint32& sysTotal, uint32& sysUsage, uint32& staticTotal, uint32& staticUsage, uint32& dynamicTotal, uint32& dynamicUsage);
417 //static bool InsertMemoryBlock(const char* data, uint32 size, uint64 eol, uint64& id);
418 //static bool OverwriteMemoryBlock(uint64 id, const char* data, uint32 size, uint64 eol);
419 //static char* GetAndLockMemoryBlock(uint64 id, uint32& size, uint64& eol);
420 //static bool UnlockMemoryBlock(uint64 id);
421 //static char* GetCopyMemoryBlock(uint64 id, uint32& size, uint64& eol);
422
424 static bool UnitTest();
426 static bool ShmUnitTest();
427
429
432
439 bool getMemoryUsage(uint64& sysAlloc, uint64& sysUsage, uint64& dataAlloc, uint64& dataUsage);
440
445 uint8 getNodeStatus(uint64& lastseen, uint64& createdTime);
446
447 // Connect to existing PageMaster in shared memory
452 bool connect(uint16 sysID, bool isMaster);
453
454 // Create a new PageMaster in shared memory
466 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);
467 //uint16 sysID, uint32 slotCount = 100, uint32 slotDuration = 100000, uint64 initSize = 10000000, uint64 maxSize = 100000000, uint32 growSteps = 8, bool force = false);
468
469 // Insert new block of memory and return full id
474 bool insertMessage(DataMessage* msg, uint64& id);
475 // Get copy of block of memory
480 DataMessage* getCopyOfMessage(uint64 id);
481
482 std::string typeToText(PsyType type);
483 std::string subTypeToText(uint16 subtype);
484 std::string contextToText(PsyContext context);
485 std::string subContextToText(uint16 subcontext);
486 std::string getComponentName(uint32 compID);
487
488 uint16 getNodeID();
489 bool setNodeID(uint16 id);
490
494
495
499 bool getTimeSyncData(uint64& tmc, int64& adjust);
502 bool setTimeSyncData(uint64 tmc, int64 adjust);
503
508
509private:
510 // Continuous management of eol pages
513 uint32 runManager();
514
515 // Resize the EOL Page
517 bool resizeEOLPage(uint32 slotCount, uint32 pagesPerSlot, uint32 slotDuration);
518
519 PsycloneIndex* psycloneIndex;
520 MasterMemory* masterMemory;
521
522
523 bool shouldContinue;
524 bool isRunning;
525 bool isLocalMaster;
526 uint32 managementThreadID;
527 uint16 thisInstance;
528};
529
530
531
532
533
534
535
536
537
538
539
540
541
542
544#define MAXREGISTERCOUNT 64
545
551 uint16 size; // size of memory allocation
552 uint16 count; // number of entries
553 // MAXREGISTERCOUNT x uint16 sysIDs
554};
555
559
561#define NODE_PROCESS_ID 1
563#define MAXINSTANCES 256
564
565
570struct MemoryID {
571 uint32 pageID; // contains [8] PageSerial [24] PageLoc
572 uint16 blockID; // index containing block offset
573 uint16 sysID; // global node id
574};
575
579 uint32 size;
580// char* data;
581};
582
586 uint32 size; // total size of pool structure in bytes
587 // uint32 size, uint64 time, uint32 pageID
588};
589
593 uint32 dataSize; // page data size
594 uint64 time; // time of entry into pool
595 uint32 pageID; // ID of page
596};
597
602struct EOLHeader {
603 uint32 slotCount;
605 uint32 startSlot;
606 uint64 startTime;
608 // slot0: page0,eol0 , page1,eol1 ..., pageN,eolN
609 // slot1: page0,eol0 , page1,eol1 ..., pageN,eolN
610};
611
614struct EOLEntry {
615 uint32 pageID;
616 uint64 eol;
617};
618
623#define MP_GetBlockIndexStartLoc(p) ((char*)p + sizeof(MemoryPage))
624#define MP_GetBlockDataStartLoc(p) (MP_GetBlockIndexStartLoc(p) + (p->blockTableSize*sizeof(uint32)) )
625//#define MP_GetBlockOffsetLoc(p,n) (uint32*)(MP_GetBlockIndexStartLoc(p) + (n * sizeof(uint32)))
626//#define MP_GetBlockOffset(p,n) (*(MP_GetBlockOffsetLoc(p,n)))
627//#define MP_GetBlockLoc(p,n) MP_GetBlockDataStartLoc(p) + MP_GetBlockOffset(p,n)
629
635 uint32 size; // total size of page in bytes
636 uint64 eol; // current number of blocks in use -> first free location
637 uint32 dataSize; // total size of data space in bytes
638 uint32 dataUsage; // current usage of page in bytes
639 uint16 count; // current number of blocks in use -> first free location
640 uint16 blockTableSize; // maximum entries in index table
641// uint16 blockTable[1024]; // index table containing block offsets
642// char* data; // MemoryBlock0, MemoryBlock1, ..., MemoryBlockN
643};
644
648 uint8 pageSerial; // running serial number for this page location (0-255)
649 uint8 cacheSerial; // running serial number for this page cache (0-255)
650 uint32 pageSize;
651 uint32 pageID;
652 uint64 lockID;
653 uint64 lockTime;
654 uint16 lockCount;
655};
656
661 uint32 size; // total size of structure in bytes
662 uint32 count; // total number of cache entries allocated
663 // MemoryPageCacheEntries...
664};
665
668 uint8 pageSerial; // running serial number for this page location (0-255)
669 uint8 cacheSerial; // running serial number for this page cache (0-255)
670 uint32 pageSize;
671 uint32 pageID;
673};
674
679#define MP_SYSMEMID MP_CalcID(0, 0, pageMaster->nodeID)
680#define MP_CalcID(pid,bid,nid) ((uint64)pid | (((uint64)bid) << 32) | (((uint64)nid) << 48))
681#define MP_SetBlockID(id,var) var |= (((uint64)id) << 32)
682#define MP_SetNodeID(id,var) var |= (((uint64)id) << 48)
683#define MP_SetPageID(id,var) var |= ((uint64)id)
684#define MP_GetBlockID(id) (*(uint16*)((char*)&id + sizeof(uint32)))
685#define MP_GetNodeID(id) (*(uint16*)((char*)&id + sizeof(uint32) + sizeof(uint16)))
686#define MP_GetPageID(id) (*(uint32*)(char*)&id)
687#define MP_GetBitFieldLoc(m) ((char*)m + sizeof(MemoryPageMaster))
688#define MP_GetPageTableLoc(m) (MP_GetBitFieldLoc(m) + m->bitFieldSize )
689#define MP_GetPageEntryLoc(m,pid) (MP_GetPageTableLoc(m) + (pid * sizeof(MemoryPageEntry)) )
690#define MP_GetPageLoc(m,pid) ((MemoryPageEntry*)MP_GetPageEntryLoc(m,pid))->page
692
695#define MP_SYSTEMPAGE 0
696#define MP_STATICPAGE 1
697#define MP_DYNAMICPAGE 2
699#define MP_GetPageType(id,eol) ( ((id < RESERVEDPAGECOUNT) ? MP_SYSTEMPAGE : (eol > 0 ? MP_DYNAMICPAGE : MP_STATICPAGE) ) )
701
707 uint32 size; // total size of PageMaster in bytes
708 uint16 sysID; // global node id
709 uint16 status; // 0-10, where 10 means ready
710 uint64 createdTime; // time of creation
711 uint8 instance; // Instance number on each computer
712 uint64 timesync; // time sync
713 uint32 pagesSize; // total size of all pages in bytes {system, static, EOL}
714 uint32 dataSize[3]; // total size of all pages data spaces in bytes {system, static, EOL}
715 uint32 dataUsage[3]; // current usage of all pages in bytes {system, static, EOL}
716 uint32 count[3]; // current number of pages in use, for info only {system, static, EOL}
717 uint32 lastCreatedStaticPage; // id of last created static page
718 uint32 bitFieldSize; // number of bytes in the bitfield
719 uint32 pageTableSize; // maximum entries in page table and number of bits in bit field
720 // char* pageBitfield; // which pages are in use -> 111010001110101010....011010
721 // MemoryPageEntry* pageTable; // {ID24 offset -> address of MemoryPageEntry}
722};
723
724// SystemBlock for system data
725
726// structure for managing ttl pages
727
737public:
739
743 static char* GetAndLockSystemBlock(uint32 pageID, uint32& size);
745 static bool UnlockSystemBlock(uint32 pageID);
746 // Creates a new System Page with the next id
747 static char* CreateAndLockNewSystemPage(uint32 size, uint32& id);
748 // Resize an existing System Page
749 static char* ResizeSystemPage(uint32 pageID, uint32 newSize);
750 static bool GetMemoryUsage(uint32& total, uint32& usage, uint32& sysTotal, uint32& sysUsage, uint32& staticTotal, uint32& staticUsage, uint32& dynamicTotal, uint32& dynamicUsage);
751 // Destroys an exising System Page by id
752 static bool DestroySystemPage(uint32 pageID);
753
757 static bool InsertMemoryBlock(const char* data, uint32 size, uint64 eol, uint64& id);
759 static bool OverwriteMemoryBlock(uint64 id, const char* data, uint32 size, uint64 eol);
762 static char* GetAndLockMemoryBlock(uint64 id, uint32& size, uint64& eol);
764 static bool UnlockMemoryBlock(uint64 id);
766 static char* GetCopyMemoryBlock(uint64 id, uint32& size, uint64& eol);
767
769 static bool UnitTest();
770
772
775
776 // Connect to existing PageMaster in shared memory
777 bool connect(uint16 sysID);
778
779 // Create a new PageMaster in shared memory
780 bool create(uint16 sysID, uint32 staticPageTableSize = 100, uint32 slotCount = 360, uint32 slotDuration = 60000000, uint32 pagesPerSlot = 10, bool force = false);
781
782 // Either look up location of or create a new PageMaster in shared memory
783 // bool init(uint16 nodeID, uint32 pageTableSize, uint32 slotCount = 600, uint32 slotDuration = 1000000, uint32 bufferSlots = 10, uint32 pagesPerSlot = 1024);
784
785 // Insert new block of memory and return full id
786 bool insertMemoryBlock(const char* data, uint32 size, uint64 eol, uint64& id);
787
788 // Overwrite existing block of memory
789 bool overwriteMemoryBlock(uint64 id, const char* data, uint32 size, uint64 eol);
790
791 char* getAndLockMemoryBlock(uint64 id, uint32& size, uint64& eol);
792 char* getLockedMemoryBlock(MemoryPage* page, uint64 id, uint32& size, uint64& eol);
793 bool unlockMemoryBlock(uint64 id);
794 char* getCopyMemoryBlock(uint64 id, uint32& size, uint64& eol);
795
796 // Return a system memory block
797 char* getSystemBlock(uint32 pageID, uint32& size);
798
799 // Return a system memory block and lock it
800 char* getAndLockSystemBlock(uint32 pageID, uint32& size);
801 char* getLockedSystemBlock(uint32 pageID, uint32& size);
802 char* getLockedSystemBlock(MemoryPage* page, uint32& size);
803
804 // Unlock System Block
805 bool unlockSystemBlock(uint32 pageID);
806
807 // Creates a new System Page with the next id
808 char* createAndLockNewSystemPage(uint32 size, uint32& id);
809 // Resize an existing System Page
810 char* resizeSystemPage(uint32 pageID, uint32 size);
811
812private:
813 // Create new MemoryPage
814 MemoryPage* createPage(uint32 size, uint16 tableSize, uint64 eol, uint32& pageID); // if either parameter is 0, the default values will be used
815
816 // Insert new block of memory into a specific page and return full id
817 bool insertMemoryBlockIntoPage(uint32 pageID, const char* data, uint32 size, uint64 eol, uint64& id);
818
819 // Create a new Page Mutex
820 // Mutex createPageMutex(uint32 id);
821 // Get an existing Page Mutex
822 // bool getPageMutex(uint32 id, NMutex &mutex);
823 // Destroy a Page Mutex
824 // bool destroyPageMutex(uint32 id);
825
826// utils::Semaphore* getPageSemaphore(uint32 pageID);
827// utils::Mutex* getPageMutex(uint32 pageID);
828
829 bool lockPage(uint32 pageID);
830 bool unlockPage(uint32 pageID);
831// bool lockPage(MemoryPage* page);
832// bool unlockPage(MemoryPage* page);
833 bool lockPage(MemoryPageEntry* entry);
834 bool unlockPage(MemoryPageEntry* entry);
835
836 // Find an available page appropriate for the block size and ttl
837 MemoryPage* findPageForBlock(uint32 size, uint64 eol, uint32& id);
838
839 // Free up a page and put it into the pool
840 bool freePageIntoPool(uint32 pageID);
841
842 // Remove page from stats, but do not delete
843 bool removePageFromStats(uint32 pageID, uint32& dataSize);
844
845 // Insert a page into the idle pool
846 bool insertPageIntoPool(uint32 pageID, uint32 dataSize);
847
848 // Get page with required size from the idle pool
849 bool getPageFromPool(uint32 size, uint32& pageID);
850
851 // Destroy all Memory Pages
852 bool destroyAllPages();
853
854 // Destroy a Memory Page
855 bool destroyPage(uint32 pageID, bool updateStats = true);
856
857 // Continuous management of eol pages
858 uint32 runManager();
859
860 // Return string representing the bitfield
861 char* getBitFieldAsString(uint32& size);
862 // Print string representing the bitfield
863 bool printBitFieldAsString(char* title);
864
865 // Get the percentage in use of a page
866 bool getPageUsage(uint32 pageID, double& val);
867 // Get the percentage in use of a page
868 double getPageUsage(uint32 pageID);
869 // Get the number of bytes free of a page
870 bool getPageFree(uint32 pageID, uint32& bytes);
871 // Get the total size in bytes a page
872 bool getPageSize(uint32 pageID, uint32& bytes);
873
874 // Creates a System Page
875 char* createSystemPage(uint32 id, uint32 size, uint64& memID);
876
877 // Create the Manager System Pages
878 bool createSystemPages();
879
880 // Initialise the System Page
881 bool initSystemPage(char* data, uint32 size);
882
883 // Initialise the Page Pool
884 bool initPagePool(char* data, uint32 size);
885
886 // Resize the EOL Page
887 bool resizeEOLPage(uint32 slotCount, uint32 pagesPerSlot, uint32 slotDuration, uint32 bufferSlots);
888
889 // Insert page into EOL Structure
890 bool insertPageIntoEOL(uint32 pageID, uint64 eol, uint64& slotEOL);
891
892 // Initialise the Queue Page
893 bool initQueuePage(char* data, uint32 size);
894
895 // Calculate the new page size based on incoming block size
896 static uint16 CalcBlockTableSize(uint32 size);
897
898 MemoryPage* getCachedPage(uint32 pageID);
899 MemoryPage* getCachedPage(MemoryPageEntry *entry);
900 bool updateCachedPage(MemoryPageEntry *entry, MemoryPage *page);
901
902 MemoryPageMaster* pageMaster; // Shared memory location of PageMaster, looked up or created
903 utils::Mutex *pageMasterMutex; // Handle to global mutex for PageMaster access
904 MemoryPageCache* pageCache; // Non-shared memory location of cached page addresses
905 bool shouldContinue;
906 bool isRunning;
907 bool isMaster;
908 uint32 managementThreadID;
909 uint16 thisInstance;
910};
911
912} // namespace cmlabs
913 // end of defgroup Memory (file-level)
915
916#include "TemporalMemory.h"
917#include "ComponentMemory.h"
918#include "DataMapsMemory.h"
919#include "ProcessMemory.h"
920
921#endif //_MEMORYMANAGER_H_
922
Shared-memory component registry: identity, location, parameters, private data and statistics for eve...
Shared-memory name/id maps: message types, contexts, tags, cranks and cross-process requests.
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
Abstract interface that lets subsystem memories query/update their segment's id, size and resize seri...
Shared-memory process ("space") table plus per-process message queues.
Slot/bin shared-memory store for time-limited DataMessages (the node's "dynamic" memory).
Process-wide thread registry and lifecycle manager: the concurrency core of CMSDK.
Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory,...
#define THREAD_RET
Definition Utils.h:127
#define THREAD_FUNCTION_CALL
Definition Utils.h:129
#define THREAD_ARG
Definition Utils.h:130
Accessor for the shared component registry.
Accessor for the shared name/id maps and the request map.
The central Psyclone data container: a self-contained binary message with typed, named user entries.
Handle to the node's master shared-memory segment (MemoryMasterStruct).
uint32 incrementDynamicShmemSerial()
Bump the dynamic segment serial after resize.
bool create(uint16 port)
Create the master segment for the node instance listening on port.
uint32 incrementDataMapsShmemSerial()
Bump the data-maps segment serial after resize.
uint16 getID()
MemoryController interface:
bool setComponentShmemSize(uint64 size)
Record a new component segment size.
bool setID(uint16 id)
MemoryController interface: set the node id.
uint16 port
Node port this master segment belongs to (names all related segments).
bool setDataMapsShmemSize(uint64 size)
Record a new data-maps segment size.
uint32 incrementProcessShmemSerial()
Bump the process segment serial after resize.
friend class MemoryManager
uint32 incrementComponentShmemSerial()
Bump the component segment serial after resize.
bool setDynamicShmemSize(uint64 size)
Record a new dynamic segment size.
bool setNodeID(uint16 id)
Set the cluster-wide node id.
bool setProcessShmemSize(uint64 size)
Record a new process segment size.
bool open(uint16 port)
Attach to an existing master segment created by another process.
Top-level facade of the shared-memory subsystem for one process.
ProcessMemory * processMemory
Accessor for the process table and per-process queues.
DataMessage * getCopyOfMessage(uint64 id)
Fetch a private copy of a previously published message.
ComponentMemory * componentMemory
Accessor for the component registry.
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)
Create all shared segments for a new node instance (master process only).
static bool UnitTest()
Self-test of the shared-memory manager.
std::string subTypeToText(uint16 subtype)
Resolve a subtype id to its registered name.
DataMessage * retrieveAllSystemIDs()
Enumerate all live Psyclone system ids/ports on this machine (via the PsycloneIndex).
uint8 getNodeStatus(uint64 &lastseen, uint64 &createdTime)
Get the node status from the master segment.
bool setNodeID(uint16 id)
Set this node's cluster-wide id.
static MemoryManager * Singleton
Per-process singleton instance, set by the constructor.
static bool ShmUnitTest()
Self-test of the raw shared-memory primitives.
bool insertMessage(DataMessage *msg, uint64 &id)
Publish a DataMessage into shared (temporal) memory.
std::string getComponentName(uint32 compID)
Resolve a component id to its name.
std::string subContextToText(uint16 subcontext)
Resolve a subcontext id to its registered name.
std::string typeToText(PsyType type)
Resolve a type id to its registered name.
bool getTimeSyncData(uint64 &tmc, int64 &adjust)
Read the cluster time-sync values from the master segment.
bool getMemoryUsage(uint64 &sysAlloc, uint64 &sysUsage, uint64 &dataAlloc, uint64 &dataUsage)
Report allocation/usage figures for the system and data segments.
DataMapsMemory * dataMapsMemory
Accessor for the type/context/tag/crank/request maps.
bool connect(uint16 sysID, bool isMaster)
Attach this process to an existing node's shared segments.
TemporalMemory * temporalMemory
Accessor for time-limited message storage.
friend THREAD_RET THREAD_FUNCTION_CALL MemoryManagement(THREAD_ARG arg)
Background maintenance thread entry point for MemoryManager / MemoryManagerX.
std::string contextToText(PsyContext context)
Resolve a context id to its registered name.
bool setTimeSyncData(uint64 tmc, int64 adjust)
Write the cluster time-sync values into the master segment.
char * getLockedSystemBlock(MemoryPage *page, uint32 &size)
static bool UnitTest()
Self-test of the legacy page allocator.
static char * CreateAndLockNewSystemPage(uint32 size, uint32 &id)
bool unlockSystemBlock(uint32 pageID)
static MemoryManagerX * Singleton
Per-process singleton instance.
bool connect(uint16 sysID)
static char * GetAndLockMemoryBlock(uint64 id, uint32 &size, uint64 &eol)
Lock a block and return a pointer into shared memory; pair with UnlockMemoryBlock().
bool unlockMemoryBlock(uint64 id)
bool create(uint16 sysID, uint32 staticPageTableSize=100, uint32 slotCount=360, uint32 slotDuration=60000000, uint32 pagesPerSlot=10, bool force=false)
static char * GetCopyMemoryBlock(uint64 id, uint32 &size, uint64 &eol)
Return a heap copy of a block; caller owns and must free it.
char * getLockedMemoryBlock(MemoryPage *page, uint64 id, uint32 &size, uint64 &eol)
char * getAndLockMemoryBlock(uint64 id, uint32 &size, uint64 &eol)
static char * GetAndLockSystemBlock(uint32 pageID, uint32 &size)
Map and lock the system page pageID; pair with UnlockSystemBlock().
bool overwriteMemoryBlock(uint64 id, const char *data, uint32 size, uint64 eol)
char * getAndLockSystemBlock(uint32 pageID, uint32 &size)
static bool UnlockSystemBlock(uint32 pageID)
Release the lock taken by GetAndLockSystemBlock().
char * createAndLockNewSystemPage(uint32 size, uint32 &id)
static bool UnlockMemoryBlock(uint64 id)
Release the lock taken by GetAndLockMemoryBlock().
char * getSystemBlock(uint32 pageID, uint32 &size)
static bool OverwriteMemoryBlock(uint64 id, const char *data, uint32 size, uint64 eol)
Replace the contents of an existing block.
friend THREAD_RET THREAD_FUNCTION_CALL MemoryManagement(THREAD_ARG arg)
Background maintenance thread entry point for MemoryManager / MemoryManagerX.
static bool InsertMemoryBlock(const char *data, uint32 size, uint64 eol, uint64 &id)
Copy data into a new shared block.
static bool DestroySystemPage(uint32 pageID)
char * getLockedSystemBlock(uint32 pageID, uint32 &size)
bool insertMemoryBlock(const char *data, uint32 size, uint64 eol, uint64 &id)
char * resizeSystemPage(uint32 pageID, uint32 size)
char * getCopyMemoryBlock(uint64 id, uint32 &size, uint64 &eol)
static char * ResizeSystemPage(uint32 pageID, uint32 newSize)
static bool GetMemoryUsage(uint32 &total, uint32 &usage, uint32 &sysTotal, uint32 &sysUsage, uint32 &staticTotal, uint32 &staticUsage, uint32 &dynamicTotal, uint32 &dynamicUsage)
Accessor for the shared process table and per-process queues.
Accessor for the machine-global instance index segment.
bool setStatus(uint8 status)
Update this instance's status and heartbeat in the shared index.
bool init(uint16 port, uint64 instID)
Attach to (or create) the index segment and claim/refresh the slot for this instance.
static bool GetStatus(uint16 port, uint8 &status, uint64 &heartbeat)
Look up the status of the instance registered on port.
Accessor for the temporal (dynamic) message store in shared memory.
Recursive mutual-exclusion lock, optionally named for cross-process use.
Definition Utils.h:463
std::string StringFormat(const char *format,...)
printf into a std::string.
Definition Utils.cpp:7033
THREAD_RET THREAD_FUNCTION_CALL MemoryManagement(THREAD_ARG arg)
Background maintenance thread entry point for MemoryManager / MemoryManagerX.
Hierarchical execution-context identifier.
Definition Types.h:284
Hierarchical message type identifier — the key used for publish/subscribe matching in Psyclone.
Definition Types.h:123
Sliding-window averages derived from successive PerfStats snapshots.
double dataQueueBytesAverage[3]
Average queued bytes, per window.
double cycleCountPerSec[3]
Processing cycles per second, per window.
double dataInputCountPerSec[3]
Input message rate in msgs/s, per window.
uint64 maxMemoryBytes
Peak memory footprint observed.
double percentOfOSCPU[3]
Share of the hosting OS process's CPU use, per window.
uint64 time
Timestamp (µs) of the last update.
double localSystemCPUUsage[3]
CPU usage of the local Psyclone system, per window.
double memoryBytesAverage[3]
Average memory footprint, per window.
double dataOutputCountPerSec[3]
Output message rate in msgs/s, per window.
double computerMemoryUsage[3]
Whole-machine memory usage, per window.
double percentOfSystemCPU[3]
Share of the whole Psyclone system's CPU use, per window.
PerfStats lastStats
Most recent raw snapshot used for delta computation.
double localSystemMemoryUsage[3]
Memory usage of the local Psyclone system, per window.
double dataInputBytesPerSec[3]
Input throughput in bytes/s, per window.
uint32 periodsMS[3]
The three averaging window lengths in milliseconds.
double computerCPUUsage[3]
Whole-machine CPU usage, per window.
std::string toXML()
Render all averaged metrics as a single <performance/> XML element for monitoring.
uint64 dataQueueCountAverage[3]
Average queued message count, per window.
double dataOutputBytesPerSec[3]
Output throughput in bytes/s, per window.
Legacy registry block listing the Psyclone system ids present on this machine.
One page/expiry pair inside an EOL time-wheel slot (legacy allocator).
uint32 pageID
Page scheduled for expiry.
uint64 eol
Absolute end-of-life timestamp (µs).
Header of the end-of-life (EOL) time-wheel that schedules page expiry (legacy allocator).
uint32 pagesPerSlot
Capacity (page entries) of each slot.
uint32 startSlot
Index of the slot representing startTime.
uint32 slotCount
Number of time slots in the wheel.
uint64 startTime
Timestamp (µs) of the wheel's first slot.
uint32 slotDuration
Duration covered by one slot (µs).
Size prefix of a raw block inside a MemoryPage (legacy allocator).
Decomposed form of a 64-bit global memory-block id (legacy page allocator).
Root header of the node's master shared-memory segment.
uint64 memAlloc
Total bytes currently allocated across all segments.
uint16 nodeID
Cluster-wide id of this node.
uint64 processShmemSize
Current byte size of the process segment.
uint64 datamapsShmemSize
Current byte size of the data-maps segment.
uint64 currentTMC
Current time-master clock value (µs) for cluster time sync.
uint32 processShmemSerial
Serial of the process segment; bumped on every resize.
uint64 componentShmemSize
Current byte size of the component segment.
uint32 dynamicShmemLocks
Diagnostic lock counter for the dynamic segment.
uint32 dynamicShmemSerial
Serial of the dynamic (temporal) segment; bumped on every resize.
uint64 size
Total size of this segment in bytes.
uint64 memUsage
Total bytes currently in use across all segments.
int64 localSyncAdjustment
Signed offset applied to local clock to match the time master.
uint32 cid
Check/magic id used to validate the segment on attach.
uint64 dynamicShmemSize
Current byte size of the dynamic (temporal) segment.
uint32 componentShmemSerial
Serial of the component segment; bumped on every resize.
uint32 throughputCount
Total messages passed through the node.
uint64 createdTime
Creation timestamp of the segment (µs).
uint64 currentCPUTicks
Aggregate CPU ticks consumed by the node.
uint32 componentShmemLocks
Diagnostic lock counter for the component segment.
uint32 componentCount
Number of registered components.
uint64 throughputSize
Total message bytes passed through the node.
uint32 processShmemLocks
Diagnostic lock counter for the process segment.
uint32 datamapsShmemSerial
Serial of the data-maps segment; bumped on every resize.
uint16 status
Node readiness, 0-10; 10 means fully ready.
One process-local cached page mapping; stale when serials mismatch the page table (legacy allocator).
uint8 cacheSerial
uint8 pageSerial
MemoryPage * page
uint32 pageSize
uint32 pageID
Header of a process-local (non-shared) cache of mapped page addresses (legacy allocator).
Page-table slot describing one page's identity, size and lock state (legacy allocator).
uint32 pageSize
uint8 pageSerial
uint64 lockTime
uint16 lockCount
uint32 pageID
uint64 lockID
uint8 cacheSerial
In-segment header of one memory page holding packed data blocks (legacy allocator).
Root header of the legacy page-allocator segment ("PageMaster").
One recyclable page recorded in the page pool (legacy allocator).
uint32 pageID
uint64 time
uint32 dataSize
Header of the page-pool structure holding reusable, currently idle pages (legacy allocator).
Raw per-component performance counters sampled inside shared memory.
uint16 spaceID
Id of the space (process slot) hosting the component.
uint32 osID
OS process id of the hosting process.
uint64 totalCycleCount
Total processing cycles across all runs.
uint64 totalQueueBytes
Bytes currently waiting in the component's queues.
uint64 totalInputCount
Total number of input messages.
uint64 currentCPUTicks
Cumulative CPU ticks consumed so far.
uint64 runCount
Number of triggered runs executed.
uint64 totalOutputCount
Total number of output messages.
uint8 type
Component type (Whiteboard, Catalog, Module, ...).
uint64 totalRunCount
Total runs across the component's lifetime.
uint64 currentRunStartTime
Timestamp (µs) the current/last run started.
uint32 migrationCount
How many times the component migrated between spaces/nodes.
uint64 totalOutputBytes
Total bytes posted as output messages.
uint64 currentMemoryBytes
Current memory footprint in bytes.
uint64 totalInputBytes
Total bytes received as input messages.
uint16 nodeID
Id of the node the component runs on.
uint64 firstRunStartTime
Timestamp (µs) of the very first run.
uint32 compID
Component id these stats belong to.
uint32 totalQueueCount
Messages currently waiting in the component's queues.
One slot in the machine-global Psyclone instance index.
uint16 port
TCP port the instance listens on; doubles as the instance key.
uint64 heartbeat
Last heartbeat timestamp (µs since epoch); staleness implies a dead instance.
uint8 status
One of the PSYCLONE_STATUS_* values.
uint64 instanceID
Unique id of the owning instance, used to detect port reuse.
Header of the machine-global Psyclone instance index shared-memory segment.
uint32 count
Number of entry slots that have ever been used.
uint32 cid
Check/magic id used to validate the segment on attach.
uint32 size
Total size of the index segment in bytes (header + entries).