From be6cfc821c4afe4a26b3f045f4f60fa247d5d862 Mon Sep 17 00:00:00 2001 From: Justin Sobota Date: Tue, 9 Apr 2013 16:19:51 -0400 Subject: [PATCH] Create shared copy of policy for Shared Server/Client so application doesn't have to manage the policy in shared memory via linker. Some Coverity bug fixes --- include/rm_internal.h | 3 ++ include/rm_loc.h | 2 ++ src/rm.c | 45 +++++++++++++++++++++------- src/rm_allocator.c | 9 ++++-- test/k2h/c66/bios/rm_mem_test.cfg | 2 +- test/k2h/c66/bios/rm_shared_test.cfg | 2 +- test/k2k/c66/bios/rm_mem_test.cfg | 2 +- test/k2k/c66/bios/rm_shared_test.cfg | 2 +- 8 files changed, 51 insertions(+), 16 deletions(-) diff --git a/include/rm_internal.h b/include/rm_internal.h index 73adccc..44ec8c4 100644 --- a/include/rm_internal.h +++ b/include/rm_internal.h @@ -54,6 +54,9 @@ extern "C" { #define RM_FALSE 0 #define RM_TRUE 1 +/* RM cache alignment */ +#define RM_MAX_CACHE_ALIGN 128 + /* Shared server enter critical section macro */ #define RM_SS_INST_INV_ENTER_CS(csKey) \ if (rmInst->instType == Rm_instType_SHARED_SERVER) { \ diff --git a/include/rm_loc.h b/include/rm_loc.h index 06c2241..daef888 100644 --- a/include/rm_loc.h +++ b/include/rm_loc.h @@ -90,6 +90,8 @@ typedef struct Rm_Transaction_s { typedef struct { /* Pointer to the global policy */ void *globalPolicy; + /* Policy size in bytes */ + uint32_t policySize; /* Pointer to root entry of the global policy valid instance tree */ Rm_PolicyValidInstTree *globalValidInstTree; /* Pointer to the linked list of allocators */ diff --git a/src/rm.c b/src/rm.c index d19ca1c..1cfd0a4 100644 --- a/src/rm.c +++ b/src/rm.c @@ -1061,12 +1061,13 @@ void Rm_instanceStatus(Rm_Handle rmHandle) */ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result) { - Rm_Inst *rmInst = NULL; - Rm_Inst *sharedServerInst = NULL; - void *globalResourceDtb = NULL; - void *linuxResourceDtb = NULL; - int addLinux = RM_FALSE; - void *key; + Rm_Inst *rmInst = NULL; + Rm_Inst *sharedServerInst = NULL; + uint32_t policySize; + void *globalResourceDtb = NULL; + void *linuxResourceDtb = NULL; + int addLinux = RM_FALSE; + void *key; *result = RM_OK; @@ -1082,8 +1083,8 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result) } /* Create and initialize instance */ - rmInst = Rm_osalMalloc (sizeof(Rm_Inst)); - memset ((void *) rmInst, 0, sizeof(Rm_Inst)); + rmInst = Rm_osalMalloc(sizeof(*rmInst)); + memset ((void *)rmInst, 0, sizeof(*rmInst)); rmInst->isLocked = RM_FALSE; rmInst->registeredWithDelegateOrServer = RM_FALSE; rmInst->transactionSeqNum = transactionInitSequenceNum(); @@ -1099,7 +1100,21 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result) goto errorExit; } - rmInst->u.server.globalPolicy = initCfg->instCfg.serverCfg.globalPolicy; + if (rmInst->instType == Rm_instType_SHARED_SERVER) { + /* Shared Server makes copy of policy in shared memory for Shared Clients + * on other cores */ + policySize = fdt_totalsize(initCfg->instCfg.serverCfg.globalPolicy); + /* Align policy size to cache boundary */ + if (policySize % RM_MAX_CACHE_ALIGN) { + policySize += (RM_MAX_CACHE_ALIGN - (policySize % RM_MAX_CACHE_ALIGN)); + } + rmInst->u.server.policySize = policySize; + rmInst->u.server.globalPolicy = Rm_osalMalloc(rmInst->u.server.policySize); + memcpy(rmInst->u.server.globalPolicy, initCfg->instCfg.serverCfg.globalPolicy, rmInst->u.server.policySize); + } + else { + rmInst->u.server.globalPolicy = initCfg->instCfg.serverCfg.globalPolicy; + } if (initCfg->instCfg.serverCfg.linuxDtb) { linuxResourceDtb = initCfg->instCfg.serverCfg.linuxDtb; @@ -1182,6 +1197,11 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result) Rm_osalCsExit(key); goto errorExit; } + else { + /* Invalidate the policy */ + Rm_osalBeginMemAccess((void *)sharedServerInst->u.server.globalPolicy, + sharedServerInst->u.server.policySize); + } Rm_osalCsExit(key); } else { @@ -1191,8 +1211,9 @@ Rm_Handle Rm_init(const Rm_InitCfg *initCfg, int32_t *result) } if (initCfg->instType == Rm_instType_SHARED_SERVER) { - /* Writeback the instance for other cores */ + /* Writeback the instance and policy for other cores */ Rm_osalEndMemAccess ((void *)rmInst, sizeof(Rm_Inst)); + Rm_osalEndMemAccess ((void *)rmInst->u.server.globalPolicy, rmInst->u.server.policySize); } else if (rmInst->instType != Rm_instType_SHARED_CLIENT) { /* Create the instance's task blocking mechanism */ @@ -1238,6 +1259,10 @@ int32_t Rm_delete(Rm_Handle rmHandle, int ignorePendingServices) rmAllocatorDeleteResources(rmHandle); rmNameServerDelete(rmHandle); rmInst->u.server.allocators = NULL; + + if (rmInst->instType == Rm_instType_SHARED_SERVER) { + Rm_osalFree((void *)rmInst->u.server.globalPolicy, rmInst->u.server.policySize); + } } else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) { rmAllocatorDeleteResources(rmHandle); diff --git a/src/rm_allocator.c b/src/rm_allocator.c index 8e2d72c..59d44c9 100644 --- a/src/rm_allocator.c +++ b/src/rm_allocator.c @@ -320,8 +320,10 @@ static void allocatorResNodeOwnerDelete(Rm_Handle rmHandle, Rm_ResourceNode *nod /* FUNCTION PURPOSE: Copies the owners of a resource node *********************************************************************** * DESCRIPTION: Creates a list of resource owners for the destination - * resource node that is equivalent to the the - * source resource node's owners + * resource node that is equivalent to the source resource + * node's owners + * + * dstNode must be a newly created node without any owners. */ static void allocatorResNodeOwnerCopy(Rm_Handle rmHandle, Rm_ResourceNode *dstNode, Rm_ResourceNode *srcNode) { @@ -330,6 +332,9 @@ static void allocatorResNodeOwnerCopy(Rm_Handle rmHandle, Rm_ResourceNode *dstNo Rm_Owner *dstNewOwner; Rm_Owner *dstPrevOwner; + if (dstNode->ownerList != NULL) { + return; + } dstNode->allocationCount = srcNode->allocationCount; while (srcOwnerList) { diff --git a/test/k2h/c66/bios/rm_mem_test.cfg b/test/k2h/c66/bios/rm_mem_test.cfg index c50ed1a..518d134 100644 --- a/test/k2h/c66/bios/rm_mem_test.cfg +++ b/test/k2h/c66/bios/rm_mem_test.cfg @@ -72,7 +72,7 @@ Program.sectMap[".sharedGlobalPolicy"] = new Program.SectionSpec(); Program.sectMap[".sharedGlobalPolicy"] = "L2SRAM"; Program.sectMap[".sharedPolicy"] = new Program.SectionSpec(); -Program.sectMap[".sharedPolicy"] = "MSMCSRAM"; +Program.sectMap[".sharedPolicy"] = "L2SRAM"; Program.sectMap[".rm"] = new Program.SectionSpec(); Program.sectMap[".rm"] = "MSMCSRAM"; diff --git a/test/k2h/c66/bios/rm_shared_test.cfg b/test/k2h/c66/bios/rm_shared_test.cfg index 85a826f..67df97a 100644 --- a/test/k2h/c66/bios/rm_shared_test.cfg +++ b/test/k2h/c66/bios/rm_shared_test.cfg @@ -73,7 +73,7 @@ Program.sectMap[".sharedGRL"] = new Program.SectionSpec(); Program.sectMap[".sharedGRL"] = "L2SRAM"; Program.sectMap[".sharedGlobalPolicy"] = new Program.SectionSpec(); -Program.sectMap[".sharedGlobalPolicy"] = "MSMCSRAM"; +Program.sectMap[".sharedGlobalPolicy"] = "L2SRAM"; /* Synchronize all processors (this will be done in Ipc_start) */ Ipc.procSync = Ipc.ProcSync_ALL; diff --git a/test/k2k/c66/bios/rm_mem_test.cfg b/test/k2k/c66/bios/rm_mem_test.cfg index ae8c491..b6466fe 100644 --- a/test/k2k/c66/bios/rm_mem_test.cfg +++ b/test/k2k/c66/bios/rm_mem_test.cfg @@ -72,7 +72,7 @@ Program.sectMap[".sharedGlobalPolicy"] = new Program.SectionSpec(); Program.sectMap[".sharedGlobalPolicy"] = "L2SRAM"; Program.sectMap[".sharedPolicy"] = new Program.SectionSpec(); -Program.sectMap[".sharedPolicy"] = "MSMCSRAM"; +Program.sectMap[".sharedPolicy"] = "L2SRAM"; Program.sectMap[".rm"] = new Program.SectionSpec(); Program.sectMap[".rm"] = "MSMCSRAM"; diff --git a/test/k2k/c66/bios/rm_shared_test.cfg b/test/k2k/c66/bios/rm_shared_test.cfg index bb11d72..9f06b27 100644 --- a/test/k2k/c66/bios/rm_shared_test.cfg +++ b/test/k2k/c66/bios/rm_shared_test.cfg @@ -73,7 +73,7 @@ Program.sectMap[".sharedGRL"] = new Program.SectionSpec(); Program.sectMap[".sharedGRL"] = "L2SRAM"; Program.sectMap[".sharedGlobalPolicy"] = new Program.SectionSpec(); -Program.sectMap[".sharedGlobalPolicy"] = "MSMCSRAM"; +Program.sectMap[".sharedGlobalPolicy"] = "L2SRAM"; /* Synchronize all processors (this will be done in Ipc_start) */ Ipc.procSync = Ipc.ProcSync_ALL; -- 2.39.2