CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::ProcessMemory Class Reference

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.

Returns
true on success.
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.

Returns
Caller-owned DataMessage copy (delete after use), or NULL on timeout.
DataMessagewaitForCmdQ (uint16 procID, uint32 timeout)
 Wait on the command queue.
DataMessagewaitForMsgQ (uint16 procID, uint32 timeout)
 Wait on the data-message queue.
DataMessagewaitForSigQ (uint16 procID, uint32 timeout)
 Wait on the signal queue.
DataMessagewaitForReqQ (uint16 procID, uint32 timeout)
 Wait on the request queue.

Static Public Member Functions

static bool UnitTest ()
 Self-test.
static bool PerfTest ()
 Queue throughput benchmark.

Detailed Description

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.

uint16 pid;
processMemory->createNewProcess("VisionSpace", pid);
processMemory->addToCmdQ(pid, cmdMsg); // any process
DataMessage* m = processMemory->waitForCmdQ(pid, 100); // inside that process
if (m) { ...; delete m; }
The central Psyclone data container: a self-contained binary message with typed, named user entries.

Definition at line 187 of file ProcessMemory.h.

Constructor & Destructor Documentation

◆ ProcessMemory()

cmlabs::ProcessMemory::ProcessMemory ( MasterMemory * master)
Parameters
masterSegment bookkeeping interface (borrowed, not owned).

Definition at line 26 of file ProcessMemory.cpp.

References MAXPROC4.

◆ ~ProcessMemory()

cmlabs::ProcessMemory::~ProcessMemory ( )

Definition at line 36 of file ProcessMemory.cpp.

References cmlabs::utils::CloseSharedMemorySegment(), and MAXPROC4.

Member Function Documentation

◆ addLocalPerformanceStats()

◆ addToAllSignalQs()

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.

◆ addToAllSignalQsExcept()

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.

◆ addToCmdQ()

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().

◆ addToMsgQ()

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().

◆ addToProcessStats()

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.

Returns
true on success.

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.

◆ addToReqQ()

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.

◆ addToSigQ()

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().

◆ checkProcessHeartbeats()

bool cmlabs::ProcessMemory::checkProcessHeartbeats ( uint32 timeoutMS,
std::list< ProcessInfoStruct > & procIssues )

Find processes whose heartbeat is older than timeoutMS.

Parameters
timeoutMSStaleness threshold in ms.
procIssuesReceives copies of stale entries.
Returns
true if the check ran.

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.

◆ create()

◆ createNewProcess()

◆ deleteProcess()

bool cmlabs::ProcessMemory::deleteProcess ( uint16 id)

Remove a process entry and free its queues.

Returns
true on success.

Definition at line 346 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ getAllProcesses()

std::vector< ProcessInfoStruct > * cmlabs::ProcessMemory::getAllProcesses ( )

Snapshot all process records.

Returns
New vector owned by the caller (delete it).

Definition at line 90 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, cmlabs::ProcessInfoStruct::createdTime, MAXPROC, and cmlabs::ProcessInfoStruct::nodeID.

◆ getCmdQCount()

uint32 cmlabs::ProcessMemory::getCmdQCount ( uint16 procID)
Returns
Messages waiting in the command queue.

Definition at line 726 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, and CMDQ_TYPE.

◆ getMemoryUsage()

bool cmlabs::ProcessMemory::getMemoryUsage ( uint64 & alloc,
uint64 & usage )

Report allocation/usage of the process segment.

Returns
true on success.

Definition at line 49 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ getMsgQCount()

uint32 cmlabs::ProcessMemory::getMsgQCount ( uint16 procID)
Returns
Messages waiting in the data-message queue.

Definition at line 741 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, and MSGQ_TYPE.

Referenced by UnitTest().

◆ getProcessCommandLine()

bool cmlabs::ProcessMemory::getProcessCommandLine ( uint16 id,
char * cmdline,
uint32 maxSize )

Copy the launch command line.

Returns
true if found.

Definition at line 401 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, and cmlabs::utils::strcpyavail().

◆ getProcessCreateTime()

uint64 cmlabs::ProcessMemory::getProcessCreateTime ( uint16 id)
Returns
Creation timestamp (µs), 0 if unknown.

Definition at line 391 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ getProcessID()

bool cmlabs::ProcessMemory::getProcessID ( const char * name,
uint16 & id )

Look up a process id by name.

Returns
true if found.

Definition at line 374 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, MAXPROC, and stricmp.

◆ getProcessIDFromOSID()

uint16 cmlabs::ProcessMemory::getProcessIDFromOSID ( uint32 osid)

Map an OS pid to a Psyclone process id.

Returns
Id or 0.

Definition at line 437 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, and MAXPROC.

◆ getProcessName()

bool cmlabs::ProcessMemory::getProcessName ( uint16 id,
char * name,
uint32 maxSize )

Copy the process name into name (max maxSize bytes).

Returns
true if found.

Definition at line 360 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, and cmlabs::utils::strcpyavail().

◆ getProcessOSID()

uint32 cmlabs::ProcessMemory::getProcessOSID ( uint16 id)
Returns
OS pid of process id, 0 if unknown.

Definition at line 454 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ getProcessPerfStats()

AveragePerfStats cmlabs::ProcessMemory::getProcessPerfStats ( uint16 procID)
Returns
Copy of the process's windowed performance averages.

Definition at line 528 of file ProcessMemory.cpp.

References cmlabs::ProcessInfoStruct::createdTime, open(), and cmlabs::ProcessInfoStruct::perfStats.

◆ getProcessStatus() [1/2]

uint8 cmlabs::ProcessMemory::getProcessStatus ( uint16 id,
uint64 & lastseen )
Returns
PSYPROC_* status; lastseen gets the last heartbeat.

Definition at line 415 of file ProcessMemory.cpp.

References getProcessStatus().

Referenced by getProcessStatus().

◆ getProcessStatus() [2/2]

uint8 cmlabs::ProcessMemory::getProcessStatus ( uint16 id,
uint64 & lastseen,
uint64 & createTime )

Overload also returning creation time.

Returns
PSYPROC_* status.

Definition at line 420 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ getQueueSizes()

bool cmlabs::ProcessMemory::getQueueSizes ( uint16 procID,
uint64 & bytes,
uint32 & count )

Total queued bytes/messages across all four queues of procID.

Returns
true on success.

Definition at line 147 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, cmlabs::MessageQueueHeader::count, cmlabs::MessageQueueHeader::endPos, and cmlabs::MessageQueueHeader::startPos.

Referenced by addLocalPerformanceStats().

◆ getReqQCount()

uint32 cmlabs::ProcessMemory::getReqQCount ( uint16 procID)
Returns
Messages waiting in the request queue.

Definition at line 771 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, and REQQ_TYPE.

◆ getSigQCount()

uint32 cmlabs::ProcessMemory::getSigQCount ( uint16 procID)
Returns
Messages waiting in the signal queue.

Definition at line 756 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, and SIGQ_TYPE.

◆ open()

bool cmlabs::ProcessMemory::open ( )

◆ PerfTest()

◆ setProcessCommandLine()

bool cmlabs::ProcessMemory::setProcessCommandLine ( uint16 id,
const char * cmdline )

Record the launch command line.

Returns
true on success.

Definition at line 496 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, MAXCOMMANDLINELEN, and cmlabs::utils::strcpyavail().

◆ setProcessOSID()

bool cmlabs::ProcessMemory::setProcessOSID ( uint16 id,
uint32 osid )

Record the OS pid.

Returns
true on success.

Definition at line 468 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ setProcessPerfStats()

bool cmlabs::ProcessMemory::setProcessPerfStats ( uint16 procID,
AveragePerfStats & perfStruct )

Store new performance averages.

Returns
true on success.

Definition at line 546 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ setProcessStatus()

bool cmlabs::ProcessMemory::setProcessStatus ( uint16 id,
uint8 status,
uint64 currentCPUTicks = 0 )

Update status + heartbeat (and optionally CPU ticks) for process id.

Returns
true on success.

Definition at line 510 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL, cmlabs::utils::GetProcessMemoryUsage(), cmlabs::GetTimeNow(), and cmlabs::ProcessInfoStruct::status.

◆ setProcessType()

bool cmlabs::ProcessMemory::setProcessType ( uint16 id,
uint8 type )

Set type (0 = normal, 1 = inside node).

Returns
true on success.

Definition at line 482 of file ProcessMemory.cpp.

References CHECKPROCESSMEMORYSERIAL.

◆ UnitTest()

◆ waitForCmdQ()

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.

◆ waitForMsgQ()

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().

◆ waitForReqQ()

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.

◆ waitForSigQ()

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().


The documentation for this class was generated from the following files: