|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Accessor for the shared process table and per-process queues. More...
#include <ProcessMemory.h>
Public Member Functions | |
| ProcessMemory (MasterMemory *master) | |
| ~ProcessMemory () | |
| bool | getMemoryUsage (uint64 &alloc, uint64 &usage) |
| Report allocation/usage of the process segment. | |
| std::vector< ProcessInfoStruct > * | getAllProcesses () |
| Snapshot all process records. | |
| bool | checkProcessHeartbeats (uint32 timeoutMS, std::list< ProcessInfoStruct > &procIssues) |
| Find processes whose heartbeat is older than timeoutMS. | |
| bool | open () |
| Attach to the existing process segment. | |
| bool | create (uint32 initialProcCount) |
| Create the process segment (master only). | |
| bool | createNewProcess (const char *name, uint16 &id) |
| Register a new process (space) in the table. | |
| bool | deleteProcess (uint16 id) |
| Remove a process entry and free its queues. | |
| bool | getProcessName (uint16 id, char *name, uint32 maxSize) |
| Copy the process name into name (max maxSize bytes). | |
| bool | getProcessID (const char *name, uint16 &id) |
| Look up a process id by name. | |
| uint64 | getProcessCreateTime (uint16 id) |
| uint8 | getProcessStatus (uint16 id, uint64 &lastseen) |
| uint8 | getProcessStatus (uint16 id, uint64 &lastseen, uint64 &createTime) |
| Overload also returning creation time. | |
| bool | getProcessCommandLine (uint16 id, char *cmdline, uint32 maxSize) |
| Copy the launch command line. | |
| uint16 | getProcessIDFromOSID (uint32 osid) |
| Map an OS pid to a Psyclone process id. | |
| uint32 | getProcessOSID (uint16 id) |
| bool | setProcessStatus (uint16 id, uint8 status, uint64 currentCPUTicks=0) |
| Update status + heartbeat (and optionally CPU ticks) for process id. | |
| bool | setProcessCommandLine (uint16 id, const char *cmdline) |
| Record the launch command line. | |
| bool | setProcessOSID (uint16 id, uint32 osid) |
| Record the OS pid. | |
| bool | setProcessType (uint16 id, uint8 type) |
| Set type (0 = normal, 1 = inside node). | |
| AveragePerfStats | getProcessPerfStats (uint16 procID) |
| bool | setProcessPerfStats (uint16 procID, AveragePerfStats &perfStruct) |
| Store new performance averages. | |
| bool | addToProcessStats (uint16 id, DataMessage *inputMsg, DataMessage *outputMsg) |
| Add message traffic to the process's stats/rings. | |
| uint32 | getCmdQCount (uint16 procID) |
| uint32 | getMsgQCount (uint16 procID) |
| uint32 | getSigQCount (uint16 procID) |
| uint32 | getReqQCount (uint16 procID) |
| bool | getQueueSizes (uint16 procID, uint64 &bytes, uint32 &count) |
| Total queued bytes/messages across all four queues of procID. | |
| bool | addLocalPerformanceStats (std::list< PerfStats > &perfStats) |
| Append PerfStats snapshots for all local processes to perfStats. | |
Queue producers | |
Copy msg into the target process's queue and signal its semaphore; the caller keeps ownership of msg. Queues grow on demand.
| |
| bool | addToCmdQ (uint16 procID, DataMessage *msg) |
| Enqueue on the command queue. | |
| bool | addToMsgQ (uint16 procID, DataMessage *msg) |
| Enqueue on the data-message queue. | |
| bool | addToSigQ (uint16 procID, DataMessage *msg) |
| Enqueue on the signal queue. | |
| bool | addToReqQ (uint16 procID, DataMessage *msg) |
| Enqueue on the request queue. | |
| bool | addToAllSignalQs (DataMessage *msg) |
| Broadcast to every process's signal queue. | |
| bool | addToAllSignalQsExcept (DataMessage *msg, uint16 except) |
| Broadcast to all signal queues except process except. | |
Queue consumers (blocking) | |
Block up to timeout ms for the next message on this process's queue.
| |
| DataMessage * | waitForCmdQ (uint16 procID, uint32 timeout) |
| Wait on the command queue. | |
| DataMessage * | waitForMsgQ (uint16 procID, uint32 timeout) |
| Wait on the data-message queue. | |
| DataMessage * | waitForSigQ (uint16 procID, uint32 timeout) |
| Wait on the signal queue. | |
| DataMessage * | waitForReqQ (uint16 procID, uint32 timeout) |
| Wait on the request queue. | |
Static Public Member Functions | |
| static bool | UnitTest () |
| Self-test. | |
| static bool | PerfTest () |
| Queue throughput benchmark. | |
Accessor for the shared process table and per-process queues.
One instance per process (created by MemoryManager). create() is called by the node master; other processes open(). All calls lock the segment's named cross-process mutex and re-attach automatically if the segment was resized (serial check). Wait calls block on named semaphores up to the given timeout (ms) and return caller-owned message copies. The master pointer is borrowed; mapped memory is owned by the OS.
Definition at line 187 of file ProcessMemory.h.
| cmlabs::ProcessMemory::ProcessMemory | ( | MasterMemory * | master | ) |
| master | Segment bookkeeping interface (borrowed, not owned). |
Definition at line 26 of file ProcessMemory.cpp.
References MAXPROC4.
| cmlabs::ProcessMemory::~ProcessMemory | ( | ) |
Definition at line 36 of file ProcessMemory.cpp.
References cmlabs::utils::CloseSharedMemorySegment(), and MAXPROC4.
| bool cmlabs::ProcessMemory::addLocalPerformanceStats | ( | std::list< PerfStats > & | perfStats | ) |
Append PerfStats snapshots for all local processes to perfStats.
Definition at line 106 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, cmlabs::ProcessInfoStruct::createdTime, cmlabs::PerfStats::currentCPUTicks, cmlabs::ProcessStats::currentCPUTicks, cmlabs::PerfStats::currentMemoryBytes, cmlabs::PerfStats::firstRunStartTime, cmlabs::utils::GetProcessMemoryUsage(), getQueueSizes(), cmlabs::ProcessInfoStruct::id, MAXPROC, cmlabs::ProcessStats::msgInBytes, cmlabs::ProcessStats::msgInCount, cmlabs::ProcessStats::msgOutBytes, cmlabs::ProcessStats::msgOutCount, cmlabs::PerfStats::nodeID, cmlabs::ProcessInfoStruct::nodeID, cmlabs::PerfStats::osID, cmlabs::ProcessInfoStruct::osID, cmlabs::PerfStats::spaceID, cmlabs::ProcessInfoStruct::stats, cmlabs::PerfStats::totalInputBytes, cmlabs::PerfStats::totalInputCount, cmlabs::PerfStats::totalOutputBytes, cmlabs::PerfStats::totalOutputCount, cmlabs::PerfStats::totalQueueBytes, cmlabs::PerfStats::totalQueueCount, and cmlabs::ProcessInfoStruct::type.
| bool cmlabs::ProcessMemory::addToAllSignalQs | ( | DataMessage * | msg | ) |
Broadcast to every process's signal queue.
Definition at line 646 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, MAXPROC, and SIGQ_TYPE.
| bool cmlabs::ProcessMemory::addToAllSignalQsExcept | ( | DataMessage * | msg, |
| uint16 | except ) |
Broadcast to all signal queues except process except.
Definition at line 661 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, MAXPROC, and SIGQ_TYPE.
| bool cmlabs::ProcessMemory::addToCmdQ | ( | uint16 | procID, |
| DataMessage * | msg ) |
Enqueue on the command queue.
Definition at line 607 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and CMDQ_TYPE.
Referenced by PerfTest(), and UnitTest().
| bool cmlabs::ProcessMemory::addToMsgQ | ( | uint16 | procID, |
| DataMessage * | msg ) |
Enqueue on the data-message queue.
Definition at line 620 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and MSGQ_TYPE.
Referenced by cmlabs::ProcessMemoryPerfTest(), and UnitTest().
| bool cmlabs::ProcessMemory::addToProcessStats | ( | uint16 | id, |
| DataMessage * | inputMsg, | ||
| DataMessage * | outputMsg ) |
Add message traffic to the process's stats/rings.
Caller keeps ownership of both messages.
Definition at line 561 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, cmlabs::DataMessage::data, DRAFTMSGSIZE, cmlabs::DataMessage::getSize(), cmlabs::GetTimeNow(), cmlabs::DataMessageHeader::size, cmlabs::ProcessInfoStruct::stats, and cmlabs::ProcessStats::time.
| bool cmlabs::ProcessMemory::addToReqQ | ( | uint16 | procID, |
| DataMessage * | msg ) |
Enqueue on the request queue.
Definition at line 676 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and REQQ_TYPE.
| bool cmlabs::ProcessMemory::addToSigQ | ( | uint16 | procID, |
| DataMessage * | msg ) |
Enqueue on the signal queue.
Definition at line 633 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and SIGQ_TYPE.
Referenced by cmlabs::MessageQueue::QueueTest, and UnitTest().
| bool cmlabs::ProcessMemory::checkProcessHeartbeats | ( | uint32 | timeoutMS, |
| std::list< ProcessInfoStruct > & | procIssues ) |
Find processes whose heartbeat is older than timeoutMS.
| timeoutMS | Staleness threshold in ms. |
| procIssues | Receives copies of stale entries. |
Definition at line 63 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, cmlabs::ProcessInfoStruct::createdTime, cmlabs::GetTimeAgeMS(), cmlabs::ProcessInfoStruct::lastseen, MAXPROC, cmlabs::ProcessInfoStruct::nodeID, PSYPROC_ACTIVE, PSYPROC_IDLE, and cmlabs::ProcessInfoStruct::status.
| bool cmlabs::ProcessMemory::create | ( | uint32 | initialProcCount | ) |
Create the process segment (master only).
| initialProcCount | Initial table capacity. |
Definition at line 172 of file ProcessMemory.cpp.
References cmlabs::ProcessInfoStruct::cmdQID, cmlabs::ProcessInfoStruct::createdTime, cmlabs::utils::CreateSharedMemorySegment(), cmlabs::GetTimeNow(), INITIALQSIZE, cmlabs::ProcessInfoStruct::lastseen, LOG_MEMORY, LogPrint, MAXKEYNAMELEN, cmlabs::ProcessInfoStruct::msgQID, cmlabs::ProcessInfoStruct::name, cmlabs::ProcessInfoStruct::nodeID, PROCESSMEMORYID, PSYPROC_ACTIVE, cmlabs::ProcessInfoStruct::reqQID, cmlabs::ProcessInfoStruct::sigQID, cmlabs::ProcessInfoStruct::status, cmlabs::utils::strcpyavail(), and cmlabs::utils::StringFormat().
| bool cmlabs::ProcessMemory::createNewProcess | ( | const char * | name, |
| uint16 & | id ) |
Register a new process (space) in the table.
| name | Process name. |
| id | Receives the new process id. |
Definition at line 291 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, cmlabs::ProcessInfoStruct::cmdQID, cmlabs::ProcessInfoStruct::createdTime, cmlabs::GetTimeNow(), cmlabs::ProcessInfoStruct::id, cmlabs::ProcessInfoStruct::lastseen, MAXKEYNAMELEN, MAXPROC, cmlabs::ProcessInfoStruct::msgQID, cmlabs::ProcessInfoStruct::name, cmlabs::ProcessInfoStruct::nodeID, PSYPROC_CREATED, cmlabs::ProcessInfoStruct::reqQID, cmlabs::ProcessInfoStruct::sigQID, cmlabs::ProcessInfoStruct::status, and cmlabs::utils::strcpyavail().
| bool cmlabs::ProcessMemory::deleteProcess | ( | uint16 | id | ) |
Remove a process entry and free its queues.
Definition at line 346 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
| std::vector< ProcessInfoStruct > * cmlabs::ProcessMemory::getAllProcesses | ( | ) |
Snapshot all process records.
Definition at line 90 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, cmlabs::ProcessInfoStruct::createdTime, MAXPROC, and cmlabs::ProcessInfoStruct::nodeID.
| uint32 cmlabs::ProcessMemory::getCmdQCount | ( | uint16 | procID | ) |
Definition at line 726 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and CMDQ_TYPE.
| bool cmlabs::ProcessMemory::getMemoryUsage | ( | uint64 & | alloc, |
| uint64 & | usage ) |
Report allocation/usage of the process segment.
Definition at line 49 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
| uint32 cmlabs::ProcessMemory::getMsgQCount | ( | uint16 | procID | ) |
Definition at line 741 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and MSGQ_TYPE.
Referenced by UnitTest().
| bool cmlabs::ProcessMemory::getProcessCommandLine | ( | uint16 | id, |
| char * | cmdline, | ||
| uint32 | maxSize ) |
Copy the launch command line.
Definition at line 401 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and cmlabs::utils::strcpyavail().
| uint64 cmlabs::ProcessMemory::getProcessCreateTime | ( | uint16 | id | ) |
Definition at line 391 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
| bool cmlabs::ProcessMemory::getProcessID | ( | const char * | name, |
| uint16 & | id ) |
Look up a process id by name.
Definition at line 374 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, MAXPROC, and stricmp.
| uint16 cmlabs::ProcessMemory::getProcessIDFromOSID | ( | uint32 | osid | ) |
Map an OS pid to a Psyclone process id.
Definition at line 437 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and MAXPROC.
| bool cmlabs::ProcessMemory::getProcessName | ( | uint16 | id, |
| char * | name, | ||
| uint32 | maxSize ) |
Copy the process name into name (max maxSize bytes).
Definition at line 360 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and cmlabs::utils::strcpyavail().
| uint32 cmlabs::ProcessMemory::getProcessOSID | ( | uint16 | id | ) |
Definition at line 454 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
| AveragePerfStats cmlabs::ProcessMemory::getProcessPerfStats | ( | uint16 | procID | ) |
Definition at line 528 of file ProcessMemory.cpp.
References cmlabs::ProcessInfoStruct::createdTime, open(), and cmlabs::ProcessInfoStruct::perfStats.
| uint8 cmlabs::ProcessMemory::getProcessStatus | ( | uint16 | id, |
| uint64 & | lastseen ) |
Definition at line 415 of file ProcessMemory.cpp.
References getProcessStatus().
Referenced by getProcessStatus().
| uint8 cmlabs::ProcessMemory::getProcessStatus | ( | uint16 | id, |
| uint64 & | lastseen, | ||
| uint64 & | createTime ) |
Overload also returning creation time.
Definition at line 420 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
| bool cmlabs::ProcessMemory::getQueueSizes | ( | uint16 | procID, |
| uint64 & | bytes, | ||
| uint32 & | count ) |
Total queued bytes/messages across all four queues of procID.
Definition at line 147 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, cmlabs::MessageQueueHeader::count, cmlabs::MessageQueueHeader::endPos, and cmlabs::MessageQueueHeader::startPos.
Referenced by addLocalPerformanceStats().
| uint32 cmlabs::ProcessMemory::getReqQCount | ( | uint16 | procID | ) |
Definition at line 771 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and REQQ_TYPE.
| uint32 cmlabs::ProcessMemory::getSigQCount | ( | uint16 | procID | ) |
Definition at line 756 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and SIGQ_TYPE.
| bool cmlabs::ProcessMemory::open | ( | ) |
Attach to the existing process segment.
Definition at line 241 of file ProcessMemory.cpp.
References cmlabs::ProcessMemoryStruct::cid, cmlabs::utils::CloseSharedMemorySegment(), LOG_MEMORY, LogPrint, cmlabs::utils::OpenSharedMemorySegment(), PROCESSMEMORYID, and cmlabs::utils::StringFormat().
Referenced by getProcessPerfStats().
|
static |
Queue throughput benchmark.
Definition at line 1781 of file ProcessMemory.cpp.
References addToCmdQ(), cmlabs::MemoryManager::create(), cmlabs::ThreadManager::CreateThread(), cmlabs::CTRL_TEST, cmlabs::unittest::detail(), cmlabs::unittest::fail(), cmlabs::g_processTestStop, cmlabs::g_processTestThreadID, cmlabs::DataMessage::getCreatedTime(), cmlabs::GetTimeAge(), cmlabs::GetTimeNow(), cmlabs::unittest::metric(), cmlabs::MemoryManager::processMemory, cmlabs::ProcessMemoryPerfTest(), cmlabs::unittest::progress(), cmlabs::StopProcessTestThread(), and waitForMsgQ().
Referenced by cmlabs::PerfTest_CMSDK(), and cmlabs::Register_ProcessMemory_Tests().
| bool cmlabs::ProcessMemory::setProcessCommandLine | ( | uint16 | id, |
| const char * | cmdline ) |
Record the launch command line.
Definition at line 496 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, MAXCOMMANDLINELEN, and cmlabs::utils::strcpyavail().
| bool cmlabs::ProcessMemory::setProcessOSID | ( | uint16 | id, |
| uint32 | osid ) |
Record the OS pid.
Definition at line 468 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
| bool cmlabs::ProcessMemory::setProcessPerfStats | ( | uint16 | procID, |
| AveragePerfStats & | perfStruct ) |
Store new performance averages.
Definition at line 546 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
| bool cmlabs::ProcessMemory::setProcessStatus | ( | uint16 | id, |
| uint8 | status, | ||
| uint64 | currentCPUTicks = 0 ) |
Update status + heartbeat (and optionally CPU ticks) for process id.
Definition at line 510 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, cmlabs::utils::GetProcessMemoryUsage(), cmlabs::GetTimeNow(), and cmlabs::ProcessInfoStruct::status.
| bool cmlabs::ProcessMemory::setProcessType | ( | uint16 | id, |
| uint8 | type ) |
Set type (0 = normal, 1 = inside node).
Definition at line 482 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL.
|
static |
Self-test.
Definition at line 1235 of file ProcessMemory.cpp.
References addToCmdQ(), addToMsgQ(), addToSigQ(), cmlabs::MemoryManager::create(), cmlabs::ThreadManager::CreateThread(), cmlabs::CTRL_TEST, cmlabs::unittest::detail(), cmlabs::unittest::fail(), cmlabs::g_processTestStop, cmlabs::g_processTestThreadID, cmlabs::DataMessage::getCreatedTime(), getMsgQCount(), cmlabs::DataMessage::getString(), cmlabs::DataMessage::getTime(), cmlabs::GetTimeAge(), cmlabs::GetTimeNow(), cmlabs::unittest::metric(), cmlabs::MemoryManager::processMemory, cmlabs::unittest::progress(), cmlabs::QueueTest(), cmlabs::DataMessage::setString(), cmlabs::DataMessage::setTime(), cmlabs::utils::Sleep(), cmlabs::StopProcessTestThread(), waitForMsgQ(), and waitForSigQ().
Referenced by cmlabs::Register_ProcessMemory_Tests().
| DataMessage * cmlabs::ProcessMemory::waitForCmdQ | ( | uint16 | procID, |
| uint32 | timeout ) |
Wait on the command queue.
Definition at line 690 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and CMDQ_TYPE.
Referenced by cmlabs::ProcessMemoryPerfTest(), and cmlabs::MessageQueue::QueueTest.
| DataMessage * cmlabs::ProcessMemory::waitForMsgQ | ( | uint16 | procID, |
| uint32 | timeout ) |
Wait on the data-message queue.
Definition at line 699 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and MSGQ_TYPE.
Referenced by PerfTest(), and UnitTest().
| DataMessage * cmlabs::ProcessMemory::waitForReqQ | ( | uint16 | procID, |
| uint32 | timeout ) |
Wait on the request queue.
Definition at line 717 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and REQQ_TYPE.
| DataMessage * cmlabs::ProcessMemory::waitForSigQ | ( | uint16 | procID, |
| uint32 | timeout ) |
Wait on the signal queue.
Definition at line 708 of file ProcessMemory.cpp.
References CHECKPROCESSMEMORYSERIAL, and SIGQ_TYPE.
Referenced by UnitTest().