diff --git a/src/rm_allocator.c b/src/rm_allocator.c
index 241df5dce2d5d8f92fa366dc46e9b7b126e2918d..c18b64502b7888f432a9c2ebaba34bc7989ef140 100644 (file)
--- a/src/rm_allocator.c
+++ b/src/rm_allocator.c
* instance node is in the list of resource node owners. Otherwise,
* returns 0.
*/
-static int allocatorResNodeIsOwnedBy(Rm_Handle rmHandle, Rm_ResourceNode *node, void *serviceInstNode)
+static int allocatorResNodeIsOwnedBy(Rm_Handle rmHandle, Rm_ResourceNode *node, Rm_PolicyValidInstNode *serviceInstNode)
{
Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
Rm_Owner *owner = node->ownerList;
***********************************************************************
* DESCRIPTION: Increments a resource owner's reference count
*/
-static void allocatorResNodeOwnerRefCntInc(Rm_Handle rmHandle, Rm_ResourceNode *node, void *serviceInstNode)
+static void allocatorResNodeOwnerRefCntInc(Rm_Handle rmHandle, Rm_ResourceNode *node, Rm_PolicyValidInstNode *serviceInstNode)
{
Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
Rm_Owner *owner = node->ownerList;
@@ -148,7 +148,7 @@ static void allocatorResNodeOwnerRefCntInc(Rm_Handle rmHandle, Rm_ResourceNode *
***********************************************************************
* DESCRIPTION: Decrements a resource owner's reference count
*/
-static void allocatorResNodeOwnerRefCntDec(Rm_Handle rmHandle, Rm_ResourceNode *node, void *serviceInstNode)
+static void allocatorResNodeOwnerRefCntDec(Rm_Handle rmHandle, Rm_ResourceNode *node, Rm_PolicyValidInstNode *serviceInstNode)
{
Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
Rm_Owner *owner = node->ownerList;
@@ -164,13 +164,33 @@ static void allocatorResNodeOwnerRefCntDec(Rm_Handle rmHandle, Rm_ResourceNode *
}
}
+/* FUNCTION PURPOSE: Returns an owner's refCnt
+ ***********************************************************************
+ * DESCRIPTION: Returns a resource owner's reference count
+ */
+static uint16_t allocatorResNodeOwnerGetRefCnt(Rm_Handle rmHandle, Rm_ResourceNode *node, Rm_PolicyValidInstNode *serviceInstNode)
+{
+ Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
+ Rm_Owner *owner = node->ownerList;
+
+ while (owner) {
+ RM_SS_OBJ_INV(owner, Rm_Owner);
+ if (owner->instNameNode == serviceInstNode) {
+ return (owner->refCnt);
+ }
+ owner = owner->nextOwner;
+ }
+
+ return(0);
+}
+
/* FUNCTION PURPOSE: Adds an owner to an allocator resource
***********************************************************************
* DESCRIPTION: Adds a RM instance node to a resource node's
* list of owners. If the owner is already present that
* owner's reference count is incremented
*/
-static void allocatorResNodeOwnerAdd(Rm_Handle rmHandle, Rm_ResourceNode *node, void *serviceInstNode)
+static void allocatorResNodeOwnerAdd(Rm_Handle rmHandle, Rm_ResourceNode *node, Rm_PolicyValidInstNode *serviceInstNode)
{
Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
Rm_Owner *ownerList = node->ownerList;
@@ -397,7 +417,7 @@ static void allocatorResNodeOwnerClear(Rm_Handle rmHandle, Rm_ResourceNode *node
* resource's owner reference count is returned if the
* resource range is found.
*/
-static int32_t allocatorStatus(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
+static int32_t allocatorStatus(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_AllocatorOpInfo *opInfo)
{
Rm_ResourceNode findNode;
Rm_ResourceNode *matchingNode = NULL;
@@ -415,6 +435,8 @@ static int32_t allocatorStatus(Rm_Allocator *allocator, Rm_AllocatorOpInfo *opIn
findEnd = findNode.base + findNode.length - 1;
if ((findNode.base >= matchingNode->base) && (findEnd <= matchingEnd)) {
opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
+ opInfo->serviceSrcInstNode);
retVal = RM_SERVICE_APPROVED;
}
else {
@@ -503,11 +525,11 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
if (matchingNode) {
matchingEnd = matchingNode->base + matchingNode->length - 1;
findEnd = findNode.base + findNode.length - 1;
+ nodePassesPolicy = RM_BOOL_UNDEF;
if ((matchingNode->allocationCount == 0) &&
(findNode.base >= matchingNode->base) && (findEnd <= matchingEnd)) {
/* Attempt to preallocate from node only if not owned by anyone and sits
* within a matching node. */
- nodePassesPolicy = RM_FALSE;
policyCheckCfg.type = policyCheckType;
policyCheckCfg.validInstNode = opInfo->serviceSrcInstNode;
policyCheckCfg.resourceBase = findNode.base;
@@ -567,11 +589,17 @@ static int32_t allocatorPreAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator,
findNode.base = matchingNode->base;
}
else {
- if (nextNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode)) {
- findNode.base = nextNode->base;
+ if (!nodePassesPolicy) {
+ findNode.base += findNode.length;
}
else {
- retVal = RM_SERVICE_DENIED_RES_ALLOC_REQS_NOT_MET;
+ /* Matching node allocated, move to next node */
+ if (nextNode = RB_NEXT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode)) {
+ findNode.base = nextNode->base;
+ }
+ else {
+ retVal = RM_SERVICE_DENIED_RES_ALLOC_REQS_NOT_MET;
+ }
}
}
}
@@ -762,8 +790,11 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
/* Always reinsert matchingNode */
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
- /* Matching node contains new reference count after alloc. Return new owner count. */
+ /* Matching node contains new reference count after alloc. Return new owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
+ opInfo->serviceSrcInstNode);
}
else if ((findNode.base > matchingNode->base) && (findEnd < matchingEnd)) {
/* findNode range is subset of matchingNode range and neither boundary is
@@ -787,8 +818,11 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
- /* Matching node contains new reference count after alloc. Return new owner count. */
+ /* Matching node contains new reference count after alloc. Return new owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
+ opInfo->serviceSrcInstNode);
}
else {
if (findNode.base == matchingNode->base) {
@@ -819,8 +853,11 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
matchingNode->length = matchingEnd - findEnd;
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
- /* Left node contains new reference count after alloc. Return new owner count. */
+ /* Left node contains new reference count after alloc. Return new owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = leftNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, leftNode,
+ opInfo->serviceSrcInstNode);
}
else if (findEnd == matchingEnd) {
/* findNode end and matchingNode end are equivalent. May be combine
@@ -850,8 +887,11 @@ static int32_t allocatorAllocate(Rm_Handle rmHandle, Rm_Allocator *allocator, in
matchingNode->length -= findNode.length;
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
- /* Right node contains new reference count after alloc. Return new owner count. */
+ /* Right node contains new reference count after alloc. Return new owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = rightNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, rightNode,
+ opInfo->serviceSrcInstNode);
}
/* Remove allocating instance from leftover matchingNode */
allocatorResNodeOwnerDelete(rmHandle, matchingNode, opInfo->serviceSrcInstNode);
@@ -975,8 +1015,11 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
/* Always reinsert matchingNode */
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
- /* Matching node is what remains after free. Return remaining owner count. */
+ /* Matching node is what remains after free. Return remaining owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
+ opInfo->serviceSrcInstNode);
}
else if ((findNode.base > matchingNode->base) && (findEnd < matchingEnd)) {
/* Case 2: Free range is less than range in matched node. Split
@@ -1005,8 +1048,11 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
matchingNode->length = findNode.length;
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, matchingNode);
- /* Matching node is what remains after free. Return remaining owner count. */
+ /* Matching node is what remains after free. Return remaining owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
+ opInfo->serviceSrcInstNode);
}
else {
if (findNode.base == matchingNode->base) {
@@ -1038,8 +1084,11 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
matchingNode->length = matchingEnd - findEnd;
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, leftNode);
- /* Left node is what remains after free. Return remaining owner count. */
+ /* Left node is what remains after free. Return remaining owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = leftNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, leftNode,
+ opInfo->serviceSrcInstNode);
}
else if (findEnd == matchingEnd) {
/* Case 4: Free range is on right boundary of matched node. Try to
@@ -1070,8 +1119,11 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
matchingNode->length -= findNode.length;
RB_INSERT(_Rm_AllocatorResourceTree, allocator->allocatorRootEntry, rightNode);
- /* Right node is what remains after free. Return remaining owner count. */
+ /* Right node is what remains after free. Return remaining owner count
+ * and originating instance allocation reference count. */
opInfo->resourceInfo->ownerCount = rightNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, rightNode,
+ opInfo->serviceSrcInstNode);
}
/* Add freeing instance back into matchingNode allocations */
@@ -1081,14 +1133,20 @@ static int32_t allocatorFree(Rm_Handle rmHandle, Rm_Allocator *allocator, Rm_All
retVal = RM_SERVICE_APPROVED;
}
else {
- /* Return owner count. In case it's a reference count check in application */
+ /* Return owner count and instance alloc count. In case it's a reference count
+ * check in application */
opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
+ opInfo->serviceSrcInstNode);
retVal = RM_SERVICE_DENIED_RES_NOT_ALLOCD_TO_INST;
}
}
else {
- /* Return owner count. In case it's a reference count check in application */
+ /* Return owner count and instance alloc count. In case it's a reference count
+ * check in application */
opInfo->resourceInfo->ownerCount = matchingNode->allocationCount;
+ opInfo->resourceInfo->instAllocCount = allocatorResNodeOwnerGetRefCnt(rmHandle, matchingNode,
+ opInfo->serviceSrcInstNode);
retVal = RM_SERVICE_DENIED_RES_ALREADY_FREE;
}
}
}
if (opInfo->operation == Rm_allocatorOp_GET_STATUS) {
- retVal = allocatorStatus(allocator, opInfo);
+ retVal = allocatorStatus(rmHandle, allocator, opInfo);
}
else if ((opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE_INIT) ||
(opInfo->operation == Rm_allocatorOp_PRE_ALLOCATE_USE)) {