19#if !defined(_COMPONENTMEMORY_H_)
20#define _COMPONENTMEMORY_H_
31#define COMPSTATUS_IDLE 1
32#define COMPSTATUS_STARTING 2
33#define COMPSTATUS_RUNNING 3
34#define COMPSTATUS_FINISHED 4
44#define GETCOMPOFFSETP(header,id) (uint64*)(((char*)header) + sizeof(ComponentMemoryStruct) + (id*sizeof(uint64)))
45#define GETCOMPOFFSET(header,id) *GETCOMPOFFSETP(header,id)
46#define GETCOMPDATA(header,id) (ComponentInfoStruct*)(GETCOMPOFFSET(header,id) ? ((char*)header) + (header->indexSize * sizeof(uint64)) + GETCOMPOFFSET(header,id) : NULL)
66#define PARAM_INTEGER 2
68#define PARAM_STRING_COLL 4
69#define PARAM_INTEGER_COLL 5
70#define PARAM_FLOAT_COLL 6
71#define PARAM_TYPE_COLL 7
75#define COMPONENT_CAN_MIGRATE 1
81struct ComponentStats {
99 std::string xmlIn, xmlOut;
101 const char* oldData = NULL;
104 for (n = 0; n < 10; n++) {
108 xmlIn += msg->
toXML();
113 for (n = 0; n < 10; n++) {
117 xmlOut += msg->
toXML();
124 return utils::StringFormat(
"<componentstats runcount=\"%llu\" msgincount=\"%llu\" msginbytes=\"%llu\" msgoutcount=\"%llu\" msgoutbytes=\"%llu\" time=\"%llu\">\n<inmsg>\n%s</inmsg>\n<outmsg>\n%s</outmsg>\n</componentstats>\n",
131#define SELFTRIGGER_NONE 0
132#define SELFTRIGGER_WARN 1
133#define SELFTRIGGER_ALLOW 2
166 std::string
toXML(
bool printStats =
true) {
168 return utils::StringFormat(
"<component id=\"%u\" status=\"%u\" name=\"%s\" node=\"%u\" proc=\"%u\" type=\"%u\" policy=\"%u\" paramcount=\"%u\" paramsize=\"%u\" datacount=\"%u\" datasize=\"%llu\" createdtime=\"%llu\" migratedtime=\"%llu\" lastupdatetime=\"%llu\" selftrigger=\"%u\">\n%s%s</component>\n",
169 id,
syncStatus,
name,
nodeID,
procID,
type,
policy,
paramCount,
paramSize,
dataCount,
dataSize,
createdTime,
migratedTime,
lastUpdateTime,
selfTrigger,
stats.toXML().c_str(),
perfStats.toXML().c_str());
171 return utils::StringFormat(
"<component id=\"%u\" status=\"%u\" name=\"%s\" node=\"%u\" proc=\"%u\" type=\"%u\" policy=\"%u\" paramcount=\"%u\" paramsize=\"%u\" datacount=\"%u\" datasize=\"%llu\" createdtime=\"%llu\" migratedtime=\"%llu\" lastupdatetime=\"%llu\" selftrigger=\"%u\" />\n",
172 id,
syncStatus,
name,
nodeID,
procID,
type,
policy,
paramCount,
paramSize,
dataCount,
dataSize,
createdTime,
migratedTime,
lastUpdateTime,
selfTrigger);
175 if (!msg)
return false;
176 msg->
setInt((int64)n,
"ID",
id);
191#define COMPINFOUSAGE(info) (sizeof(ComponentInfoStruct) + info->paramSize + info->dataSize)
244#define CHECKCOMPONENTMEMORYSERIAL if (serial != master->getComponentShmemSerial()) {if (!open()) {mutex->leave();return 0;}}
245#define CHECKCOMPONENTMEMORYSERIALRETURN(a) if (serial != master->getComponentShmemSerial()) {if (!open()) {mutex->leave();return a;}}
275 bool create(uint32 indexSize);
300 bool createComponent(uint32
id, uint8 type, uint8 policy, uint8 selfTrigger,
const char* name, uint64 size, uint16 nodeID, uint16 procID, uint64 time, uint32& existingID);
340 bool setComponentData(uint32 cid,
const char* data, uint64 size,
bool wasMigrated);
346 bool setPrivateData(uint32 cid,
const char* name,
const char* data, uint64 size,
const char* mimetype = NULL);
349 bool getPrivateData(uint32 cid,
const char* name,
char* data, uint64 maxSize);
362 bool createParameter(uint32 cid,
const char* name,
const char* val,
const char* defaultValue = NULL);
363 bool createParameter(uint32 cid,
const char* name,
const char* val, uint32 count, uint32 defaultIndex);
364 bool createParameter(uint32 cid,
const char* name, std::vector<std::string> values,
const char* defaultValue = NULL);
365 bool createParameter(uint32 cid,
const char* name, int64* val, uint32 count, uint32 defaultIndex);
366 bool createParameter(uint32 cid,
const char* name, std::vector<std::string> values, int64 defaultValue);
367 bool createParameter(uint32 cid,
const char* name, std::vector<int64> values, int64 defaultValue = 0);
368 bool createParameter(uint32 cid,
const char* name, float64* val, uint32 count, uint32 defaultIndex);
369 bool createParameter(uint32 cid,
const char* name, std::vector<std::string> values, float64 defaultValue);
370 bool createParameter(uint32 cid,
const char* name, std::vector<float64> values, float64 defaultValue = 0);
371 bool createParameter(uint32 cid,
const char* name, int64 val, int64 min = 0, int64 max = 0, int64 interval = 0);
372 bool createParameter(uint32 cid,
const char* name, float64 val, float64 min = 0, float64 max = 0, float64 interval = 0);
384 bool getParameter(uint32 cid,
const char* name,
char* val, uint32 maxSize);
385 bool getParameter(uint32 cid,
const char* name, int64& val);
386 bool getParameter(uint32 cid,
const char* name, float64& val);
393 bool setParameter(uint32 cid,
const char* name,
const char* val);
394 bool setParameter(uint32 cid,
const char* name, int64 val);
395 bool setParameter(uint32 cid,
const char* name, float64 val);
403 std::string
toXML(
bool stats =
true);
406 bool resize(uint64 newMemorySize);
407 bool resizeIndex(uint32 newIndexSize);
408 bool resizeComponent(uint32
id, uint64 newSize);
409 bool growComponent(uint32
id, uint64 addSize);
410 bool getSurroundingComponents(uint32 cid, uint32& prevID, uint32& nextID);
412 char* makeRoomForPrivateData(uint32 cid, uint64 newSize);
413 char* makeRoomForParameter(uint32 cid, uint64 newSize);
Central shared-memory manager for a Psyclone node: master segment, per-subsystem shared maps and the ...
#define DRAFTMSGSIZE
Fixed byte size of the per-message draft slots used in the recent-message rings of ComponentStats / P...
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
Subscription, trigger, retrieval, query, post and signal specifications — the declarative wiring of a...
bool setParameter(uint32 cid, const char *name, const char *val)
bool writeComponentsToMsg(DataMessage *msg)
Serialize all component records into msg.
bool create(uint32 indexSize)
Create the component segment (master only).
uint16 getComponentNodeID(uint32 cid)
bool getComponentName(uint32 cid, char *name, uint32 maxNameLen)
Copy the component name into name.
bool open()
Attach to the existing component segment.
bool getParameterAsBool(uint32 cid, const char *name)
bool syncComponents(DataMessage *msg)
Merge component records received from a remote node.
std::string getComponentNameString(uint32 cid)
bool updateComponentInformation(uint32 cid, uint8 type, uint8 policy, uint8 selfTrigger, uint16 nodeID, uint16 procID)
Update type/policy/self-trigger/location in one call.
std::string printFriendly()
bool deletePrivateData(uint32 cid, const char *name)
Delete blob name.
bool updateComponentLocation(uint32 cid, uint16 nodeID, uint16 procID)
Record a new location (after migration).
std::vector< ComponentInfoStruct > * getAllModules()
Snapshot all module components.
uint8 getParameterDataType(uint32 cid, const char *name)
bool deleteParameter(uint32 cid, const char *name)
Remove the parameter.
bool setComponentStats(uint32 cid, ComponentStats &stats)
Overwrite the component's stats.
bool cancelComponentID(uint32 id)
Release a provisionally reserved component id.
bool getComponentID(const char *name, uint32 &cid)
Look up a component id by name.
AveragePerfStats getComponentPerfStats(uint32 cid)
uint16 getComponentProcessID(uint32 cid)
bool setComponentData(uint32 cid, const char *data, uint64 size, bool wasMigrated)
Replace a component's data area (after migration).
bool addLocalPerformanceStats(std::list< PerfStats > &perfStats)
Append PerfStats for all local components.
bool tweakParameter(uint32 cid, const char *name, int32 tweak)
Step the value by tweak * interval (or collection index).
char * getPrivateDataCopy(uint32 cid, const char *name, uint64 &size)
ComponentMemory(MasterMemory *master)
std::list< std::string > getPrivateDataKeys(uint32 cid)
uint8 lookupComponentID(const char *name, uint32 &id)
Look up a component by name without filtering on readiness.
bool destroyComponent(uint32 cid)
Remove a component record and free its space.
float64 getParameterFloat(uint32 cid, const char *name)
uint32 getParameterValueSize(uint32 cid, const char *name)
uint8 getComponentPolicy(uint32 cid)
bool confirmComponentID(uint32 id)
Mark a provisionally reserved component id as ready (syncStatus 2).
bool getPrivateData(uint32 cid, const char *name, char *data, uint64 maxSize)
Copy blob into caller buffer data (max maxSize).
bool canComponentMigrate(uint32 cid)
std::string getPrivateDataMimetype(uint32 cid, const char *name)
bool getComponentLocation(uint32 cid, uint16 &nodeID, uint16 &procID)
Get the node/process the component runs in.
std::list< uint16 > * findProcessComponents(uint16 procID)
List ids of components in process procID.
std::vector< ComponentInfoStruct > * getAllComponents()
Snapshot all components.
uint64 getPrivateDataSize(uint32 cid, const char *name)
std::vector< ComponentInfoStruct > * getAllCatalogs()
Snapshot all catalog components.
bool setComponentPerfStats(uint32 cid, AveragePerfStats &perfStruct)
Store new performance averages.
char * getComponentData(uint32 cid, uint64 &size)
Copy a component's whole data area (for migration).
static bool UnitTest()
Self-test.
bool hasParameter(uint32 cid, const char *name)
std::map< std::string, std::string > getPrivateDataKeysAndTypes(uint32 cid)
uint8 getComponentSelfTrigger(uint32 cid)
bool createComponent(uint32 id, uint8 type, uint8 policy, uint8 selfTrigger, const char *name, uint64 size, uint16 nodeID, uint16 procID, uint64 time, uint32 &existingID)
Register a component record.
bool isComponentLocal(uint32 cid)
bool addComponentStats(uint32 cid, uint8 status, uint64 usageCPUTicks, DataMessage *inputMsg, DataMessage *outputMsg, uint32 runCount, uint32 cycleCount)
Fold a run's activity into the component's stats (counters, rings, CPU ticks).
bool setComponentPolicy(uint32 cid, uint8 policy)
Set the migration policy.
bool getParameter(uint32 cid, const char *name, char *val, uint32 maxSize)
bool resetParameter(uint32 cid, const char *name)
Restore the parameter's default value/index.
std::vector< ComponentInfoStruct > * getAllLocalComponents()
Snapshot components on this node.
uint8 getComponentType(uint32 cid)
ComponentStats getComponentStats(uint32 cid)
bool setPrivateData(uint32 cid, const char *name, const char *data, uint64 size, const char *mimetype=NULL)
Create/replace blob name.
std::string toXML(bool stats=true)
int64 getParameterInt(uint32 cid, const char *name)
std::string getParameterString(uint32 cid, const char *name, uint32 maxSize)
bool createParameter(uint32 cid, const char *name, const char *val, const char *defaultValue=NULL)
bool writeComponentNamesToMsg(DataMessage *msg)
Write just the component names into msg.
bool setComponentSelfTrigger(uint32 cid, uint8 selfTrigger)
Set the self-trigger policy.
bool getMemoryUsage(uint64 &alloc, uint64 &usage)
Report allocation/usage of the component segment.
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool setTime(const char *key, uint64 value)
setTime(const char* key, uint64 value)
std::string toXML(std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toXML()
bool setString(const char *key, const char *value)
setString(const char* key, const char* value)
bool setInt(const char *key, int64 value)
setInt(const char* key, int64 value)
const char * swapMessageData(const char *data)
swapMessageData(const char* data)
Handle to the node's master shared-memory segment (MemoryMasterStruct).
Recursive mutual-exclusion lock, optionally named for cross-process use.
std::string StringFormat(const char *format,...)
printf into a std::string.
Sliding-window averages derived from successive PerfStats snapshots.
One component's registry record in shared memory.
uint16 nodeID
Node the component currently runs on.
uint8 policy
Migration policy (COMPONENT_CAN_MIGRATE flag).
uint64 size
Total record size in bytes including parameter and data areas.
uint8 type
Component type (Whiteboard, Catalog, Module, ...).
uint8 selfTrigger
SELFTRIGGER_* policy.
std::string toXML(bool printStats=true)
char name[MAXKEYNAMELEN]
Component name (unique per system).
uint64 createdTime
Creation timestamp (µs).
uint16 procID
Process (space) the component currently runs in.
bool writeToMsg(uint32 n, DataMessage *msg)
uint64 migratedTime
Timestamp of the last migration (µs), 0 if never migrated.
uint64 lastUpdateTime
Timestamp of the last record update (µs).
uint32 id
Component id (index into the segment's offset table).
AveragePerfStats perfStats
uint8 status
COMPSTATUS_* run status.
uint8 syncStatus
Cluster sync status (0: not there, 1: in-sync, 2: ready).
Root header of the component-memory segment.
uint64 size
Total segment size in bytes.
uint32 count
Number of registered components.
uint32 maxID
Highest component id assigned so far.
uint64 usage
Bytes currently in use in the segment.
uint32 cid
Check/magic id validated on attach.
uint32 indexSize
Number of offset slots in the index.
Legacy per-component throughput counters (DataMessageHeader-based rings).
uint64 usageCPUTicks
Cumulative CPU ticks consumed.
uint32 migrationCount
Times this component has migrated.
uint64 msgInBytes
Total bytes received.
uint64 msgInCount
Total messages received.
uint64 cycleCount
Total processing cycles.
uint64 time
Timestamp of the last update (µs).
uint64 currentRunStartTime
Timestamp the current/last run started (µs).
uint64 runCount
Total runs.
uint64 msgOutBytes
Total bytes posted.
DataMessageHeader recentInMsg[10]
uint64 firstRunStartTime
Timestamp of the first run (µs).
std::string toXML()
Serialize counters and recent messages as a <componentstats> XML element.
DataMessageHeader recentOutMsg[10]
uint64 msgOutCount
Total messages posted.