|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Top-level facade of the shared-memory subsystem for one process. More...
#include <MemoryManager.h>
Public Member Functions | |
| MemoryManager () | |
| ~MemoryManager () | |
| bool | getMemoryUsage (uint64 &sysAlloc, uint64 &sysUsage, uint64 &dataAlloc, uint64 &dataUsage) |
| Report allocation/usage figures for the system and data segments. | |
| uint8 | getNodeStatus (uint64 &lastseen, uint64 &createdTime) |
| Get the node status from the master segment. | |
| bool | connect (uint16 sysID, bool isMaster) |
| Attach this process to an existing node's shared segments. | |
| 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). | |
| bool | insertMessage (DataMessage *msg, uint64 &id) |
| Publish a DataMessage into shared (temporal) memory. | |
| DataMessage * | getCopyOfMessage (uint64 id) |
| Fetch a private copy of a previously published message. | |
| std::string | typeToText (PsyType type) |
| Resolve a type id to its registered name. | |
| std::string | subTypeToText (uint16 subtype) |
| Resolve a subtype id to its registered name. | |
| std::string | contextToText (PsyContext context) |
| Resolve a context id to its registered name. | |
| std::string | subContextToText (uint16 subcontext) |
| Resolve a subcontext id to its registered name. | |
| std::string | getComponentName (uint32 compID) |
| Resolve a component id to its name. | |
| uint16 | getNodeID () |
| bool | setNodeID (uint16 id) |
| Set this node's cluster-wide id. | |
| DataMessage * | retrieveAllSystemIDs () |
| Enumerate all live Psyclone system ids/ports on this machine (via the PsycloneIndex). | |
| bool | getTimeSyncData (uint64 &tmc, int64 &adjust) |
| Read the cluster time-sync values from the master segment. | |
| bool | setTimeSyncData (uint64 tmc, int64 adjust) |
| Write the cluster time-sync values into the master segment. | |
Static Public Member Functions | |
| static bool | UnitTest () |
| Self-test of the shared-memory manager. | |
| static bool | ShmUnitTest () |
| Self-test of the raw shared-memory primitives. | |
Public Attributes | |
| TemporalMemory * | temporalMemory |
| Accessor for time-limited message storage. | |
| ProcessMemory * | processMemory |
| Accessor for the process table and per-process queues. | |
| ComponentMemory * | componentMemory |
| Accessor for the component registry. | |
| DataMapsMemory * | dataMapsMemory |
| Accessor for the type/context/tag/crank/request maps. | |
Static Public Attributes | |
| static MemoryManager * | Singleton = NULL |
| Per-process singleton instance, set by the constructor. | |
Friends | |
| THREAD_RET THREAD_FUNCTION_CALL | MemoryManagement (THREAD_ARG arg) |
| Background maintenance thread entry point for MemoryManager / MemoryManagerX. | |
Top-level facade of the shared-memory subsystem for one process.
Every Psyclone process creates exactly one MemoryManager (exposed via ::Singleton). The node's master process calls create() to lay out all segments; every other space process calls connect() to attach to them. After that, the four public subsystem pointers (temporalMemory, processMemory, componentMemory, dataMapsMemory) give typed access to the shared state. A background management thread (MemoryManagement) runs in the master process to expire end-of-life data and perform maintenance.
Ownership: the MemoryManager owns the subsystem accessor objects (deleted in the destructor); the shared segments themselves outlive any single process and are owned by the OS. Thread-safety: all subsystem calls take their own cross-process mutexes; the facade itself is safe to use from multiple threads.
Definition at line 412 of file MemoryManager.h.
| cmlabs::MemoryManager::MemoryManager | ( | ) |
Definition at line 373 of file MemoryManager.cpp.
References componentMemory, dataMapsMemory, processMemory, and temporalMemory.
Referenced by MemoryManagement, and UnitTest().
| cmlabs::MemoryManager::~MemoryManager | ( | ) |
Definition at line 388 of file MemoryManager.cpp.
References componentMemory, dataMapsMemory, processMemory, PSYCLONE_STATUS_ENDED, cmlabs::ThreadManager::Shutdown(), cmlabs::utils::Sleep(), and temporalMemory.
| bool cmlabs::MemoryManager::connect | ( | uint16 | sysID, |
| bool | isMaster ) |
Attach this process to an existing node's shared segments.
| sysID | Node port/system id whose segments to open. |
| isMaster | true if this process should run the management thread. |
Definition at line 456 of file MemoryManager.cpp.
References componentMemory, cmlabs::ThreadManager::CreateThread(), dataMapsMemory, cmlabs::PsycloneIndex::GetStatus(), cmlabs::GetTimeAgeMS(), LOG_MEMORY, LogPrint, MemoryManagement, processMemory, PSYCLONE_STATUS_ENDED, PSYCLONE_STATUS_INIT, PSYCLONE_STATUS_NONE, and temporalMemory.
| std::string cmlabs::MemoryManager::contextToText | ( | PsyContext | context | ) |
Resolve a context id to its registered name.
| context | Context id. |
Definition at line 677 of file MemoryManager.cpp.
References subContextToText().
| bool cmlabs::MemoryManager::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).
| sysID | Node port/system id used to name the segments. |
| slotCount | Number of message slots in temporal memory. |
| binCount | Number of block-size bins in temporal memory. |
| minBlockSize | Smallest bin block size in bytes. |
| maxBlockSize | Largest bin block size in bytes. |
| initSize | Initial temporal segment size in bytes. |
| maxSize | Maximum temporal segment size in bytes. |
| force | If true, replace any stale existing segments. |
Definition at line 534 of file MemoryManager.cpp.
References componentMemory, cmlabs::ThreadManager::CreateThread(), dataMapsMemory, cmlabs::PsycloneIndex::GetStatus(), cmlabs::GetTimeAge(), cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), LOG_MEMORY, LogPrint, MemoryManagement, cmlabs::PrintTimeDifString(), processMemory, PSYCLONE_STATUS_INIT, PSYCLONE_STATUS_READY, and temporalMemory.
Referenced by cmlabs::ProcessMemory::PerfTest(), cmlabs::ComponentData::UnitTest(), cmlabs::ComponentMemory::UnitTest(), UnitTest(), and cmlabs::ProcessMemory::UnitTest().
| std::string cmlabs::MemoryManager::getComponentName | ( | uint32 | compID | ) |
Resolve a component id to its name.
| compID | Component id. |
Definition at line 700 of file MemoryManager.cpp.
References componentMemory, and MAXKEYNAMELEN.
| DataMessage * cmlabs::MemoryManager::getCopyOfMessage | ( | uint64 | id | ) |
Fetch a private copy of a previously published message.
| id | Message id returned by insertMessage() (possibly from another process). |
Definition at line 646 of file MemoryManager.cpp.
References temporalMemory.
Referenced by UnitTest().
| bool cmlabs::MemoryManager::getMemoryUsage | ( | uint64 & | sysAlloc, |
| uint64 & | sysUsage, | ||
| uint64 & | dataAlloc, | ||
| uint64 & | dataUsage ) |
Report allocation/usage figures for the system and data segments.
| sysAlloc | Receives bytes allocated for system segments. |
| sysUsage | Receives bytes in use in system segments. |
| dataAlloc | Receives bytes allocated for data (temporal) memory. |
| dataUsage | Receives bytes in use in data memory. |
Definition at line 417 of file MemoryManager.cpp.
References componentMemory, dataMapsMemory, processMemory, and temporalMemory.
| uint16 cmlabs::MemoryManager::getNodeID | ( | ) |
Definition at line 601 of file MemoryManager.cpp.
| uint8 cmlabs::MemoryManager::getNodeStatus | ( | uint64 & | lastseen, |
| uint64 & | createdTime ) |
Get the node status from the master segment.
| lastseen | Receives the last heartbeat timestamp (µs). |
| createdTime | Receives the segment creation time (µs). |
Definition at line 445 of file MemoryManager.cpp.
References cmlabs::PsycloneIndex::GetStatus(), and PSYCLONE_STATUS_NONE.
| bool cmlabs::MemoryManager::getTimeSyncData | ( | uint64 & | tmc, |
| int64 & | adjust ) |
Read the cluster time-sync values from the master segment.
| tmc | Receives the time-master clock (µs). |
| adjust | Receives the local offset. |
Definition at line 626 of file MemoryManager.cpp.
| bool cmlabs::MemoryManager::insertMessage | ( | DataMessage * | msg, |
| uint64 & | id ) |
Publish a DataMessage into shared (temporal) memory.
| msg | Message to copy into shared memory; caller retains ownership of msg. |
| id | Receives the cluster-unique message id (node|serial|slot encoded). |
Definition at line 639 of file MemoryManager.cpp.
References temporalMemory.
Referenced by UnitTest().
| DataMessage * cmlabs::MemoryManager::retrieveAllSystemIDs | ( | ) |
Enumerate all live Psyclone system ids/ports on this machine (via the PsycloneIndex).
Definition at line 611 of file MemoryManager.cpp.
References componentMemory, and dataMapsMemory.
| bool cmlabs::MemoryManager::setNodeID | ( | uint16 | id | ) |
Set this node's cluster-wide id.
| id | New id. |
Definition at line 605 of file MemoryManager.cpp.
References temporalMemory.
| bool cmlabs::MemoryManager::setTimeSyncData | ( | uint64 | tmc, |
| int64 | adjust ) |
Write the cluster time-sync values into the master segment.
| tmc | Time-master clock (µs). |
| adjust | Local clock offset. |
Definition at line 632 of file MemoryManager.cpp.
|
static |
Self-test of the raw shared-memory primitives.
Definition at line 3051 of file MemoryManager.cpp.
References cmlabs::unittest::progress().
Referenced by cmlabs::Register_MemoryManager_Tests().
| std::string cmlabs::MemoryManager::subContextToText | ( | uint16 | subcontext | ) |
Resolve a subcontext id to its registered name.
| subcontext | Subcontext id. |
Definition at line 687 of file MemoryManager.cpp.
References dataMapsMemory, and MAXKEYNAMELEN.
Referenced by contextToText().
| std::string cmlabs::MemoryManager::subTypeToText | ( | uint16 | subtype | ) |
Resolve a subtype id to its registered name.
| subtype | Subtype id. |
Definition at line 664 of file MemoryManager.cpp.
References dataMapsMemory, and MAXKEYNAMELEN.
Referenced by typeToText().
| std::string cmlabs::MemoryManager::typeToText | ( | PsyType | type | ) |
Resolve a type id to its registered name.
| type | Type id. |
Definition at line 652 of file MemoryManager.cpp.
References cmlabs::utils::StringFormat(), and subTypeToText().
|
static |
Self-test of the shared-memory manager.
Definition at line 778 of file MemoryManager.cpp.
References create(), cmlabs::unittest::detail(), cmlabs::unittest::fail(), getCopyOfMessage(), cmlabs::DataMessage::getInt(), cmlabs::DataMessage::getSize(), cmlabs::GetTimeNow(), insertMessage(), MemoryManager(), cmlabs::unittest::metric(), cmlabs::unittest::progress(), cmlabs::DataMessage::setData(), cmlabs::DataMessage::setEOL(), and cmlabs::DataMessage::setInt().
Referenced by cmlabs::Register_MemoryManager_Tests().
|
friend |
Background maintenance thread entry point for MemoryManager / MemoryManagerX.
| arg | The manager instance (cast internally). |
Definition at line 743 of file MemoryManager.cpp.
References MemoryManager(), THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
| ComponentMemory* cmlabs::MemoryManager::componentMemory |
Accessor for the component registry.
Owned; backed by shared memory.
Definition at line 506 of file MemoryManager.h.
Referenced by connect(), create(), getComponentName(), getMemoryUsage(), MemoryManager(), retrieveAllSystemIDs(), cmlabs::ComponentMemory::UnitTest(), and ~MemoryManager().
| DataMapsMemory* cmlabs::MemoryManager::dataMapsMemory |
Accessor for the type/context/tag/crank/request maps.
Owned; backed by shared memory.
Definition at line 507 of file MemoryManager.h.
Referenced by connect(), create(), getMemoryUsage(), MemoryManager(), retrieveAllSystemIDs(), subContextToText(), subTypeToText(), cmlabs::ComponentMemory::UnitTest(), and ~MemoryManager().
| ProcessMemory* cmlabs::MemoryManager::processMemory |
Accessor for the process table and per-process queues.
Owned; backed by shared memory.
Definition at line 505 of file MemoryManager.h.
Referenced by connect(), create(), getMemoryUsage(), MemoryManager(), cmlabs::ProcessMemory::PerfTest(), cmlabs::ProcessMemoryPerfTest(), cmlabs::MessageQueue::QueueTest, cmlabs::ProcessMemory::UnitTest(), and ~MemoryManager().
|
static |
Per-process singleton instance, set by the constructor.
Definition at line 414 of file MemoryManager.h.
| TemporalMemory* cmlabs::MemoryManager::temporalMemory |
Accessor for time-limited message storage.
Owned by this object; backing store is shared memory.
Definition at line 504 of file MemoryManager.h.
Referenced by connect(), create(), getCopyOfMessage(), getMemoryUsage(), insertMessage(), MemoryManager(), setNodeID(), and ~MemoryManager().