!286 按任务统计已经alloc的内存大小

Merge pull request !286 from lnlan/taskinfo
This commit is contained in:
openharmony_ci 2021-09-01 01:48:21 +00:00 committed by Gitee
commit 459cabf7de
4 changed files with 193 additions and 148 deletions

View File

@ -65,11 +65,17 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID)
PRINTK("Name TaskEntryAddr TID ");
PRINTK("Priority Status "
#if (LOSCFG_TASK_MEM_USED == 1)
"AllocSize "
#endif
"StackSize StackPoint TopOfStack");
PRINTK("\n");
PRINTK("---- ------------- --- ");
PRINTK("-------- -------- "
#if (LOSCFG_TASK_MEM_USED == 1)
"--------- "
#endif
"--------- ---------- ----------");
PRINTK("\n");
}
@ -91,6 +97,17 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas
UINT32 loop;
UINT32 semId;
#if (LOSCFG_TASK_MEM_USED == 1)
UINT32 arraySize = sizeof(UINT32) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1);
UINT32 *getUsedSizeArray = (UINT32 *)LOS_MemAlloc(m_aucSysMem0, arraySize);
if (getUsedSizeArray == NULL) {
PRINTK("Memory is not enough to save task info!\n");
return;
}
(VOID)memset_s(getUsedSizeArray, arraySize, 0, arraySize);
OsTaskMemUsed(m_aucSysMem0, getUsedSizeArray, arraySize);
#endif
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
@ -100,11 +117,20 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas
semId = OsGetSemID(taskCB);
PRINTK("%-23s%-20p0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskID);
#if (LOSCFG_TASK_MEM_USED == 1)
PRINTK("%-11u%-13s0x%-11x 0x%-11x 0x%-8x 0x%-10x ", taskCB->priority,
OsShellCmdConvertTskStatus(taskCB->taskStatus), getUsedSizeArray[loop], taskCB->stackSize,
taskCB->stackPointer, taskCB->topOfStack, semId);
#else
PRINTK("%-11u%-13s0x%-11x 0x%-8x 0x%-10x ", taskCB->priority,
OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize,
taskCB->stackPointer, taskCB->topOfStack, semId);
#endif
PRINTK("\n");
}
#if (LOSCFG_TASK_MEM_USED == 1)
(VOID)LOS_MemFree(m_aucSysMem0, getUsedSizeArray);
#endif
}
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)

View File

@ -800,6 +800,14 @@ extern UINT8 *m_aucSysMem0;
#define LOSCFG_SHELL_PRIO 3
#endif
/**
* @ingroup los_config
* Configuration item to get task used memory.
*/
#ifndef LOSCFG_TASK_MEM_USED
#define LOSCFG_TASK_MEM_USED 0
#endif
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -469,6 +469,7 @@ extern UINT32 LOS_MemIntegrityCheck(const VOID *pool);
extern VOID LOS_MemUnlockEnable(VOID *pool);
extern UINT32 OsMemSystemInit(VOID);
extern VOID OsTaskMemUsed(VOID *pool, UINT32 *outArray, UINT32 arraySize);
#ifdef __cplusplus
#if __cplusplus

View File

@ -111,6 +111,9 @@ STATIC INLINE UINT32 OsMemSlGet(UINT32 size, UINT32 fl)
}
/* The following is the memory algorithm related macro definition and interface implementation. */
#if (LOSCFG_TASK_MEM_USED != 1 && LOSCFG_MEM_FREE_BY_TASKID == 1 && (LOSCFG_BASE_CORE_TSK_LIMIT + 1) > 64)
#error "When enter here, LOSCFG_BASE_CORE_TSK_LIMIT larger than 63 is not support"
#endif
struct OsMemNodeHead {
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1)
@ -123,7 +126,10 @@ struct OsMemNodeHead {
struct OsMemNodeHead *prev; /* The prev is used for current node points to the previous node */
struct OsMemNodeHead *next; /* The next is used for sentinel node points to the expand node */
} ptr;
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
#if (LOSCFG_TASK_MEM_USED == 1)
UINT32 taskID;
UINT32 sizeAndFlag;
#elif (LOSCFG_MEM_FREE_BY_TASKID == 1)
UINT32 taskID : 6;
UINT32 sizeAndFlag : 26;
#else
@ -180,7 +186,7 @@ struct OsMemPoolHead {
} while (0);
#define OS_MEM_NODE_MAGIC 0xABCDDCBA
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
#if (LOSCFG_TASK_MEM_USED != 1 && LOSCFG_MEM_FREE_BY_TASKID == 1)
#define OS_MEM_NODE_USED_FLAG (1U << 25)
#define OS_MEM_NODE_ALIGNED_FLAG (1U << 24)
#if (LOSCFG_MEM_LEAKCHECK == 1)
@ -274,13 +280,16 @@ STATIC INLINE UINT32 OsMemAllocCheck(struct OsMemPoolHead *pool, UINT32 intSave)
#if (LOSCFG_MEM_MUL_REGIONS == 1)
/**
* When LOSCFG_MEM_MUL_REGIONS is enabled to support multiple non-continuous memory regions, the gap between two memory regions
* is marked as a used OsMemNodeHead node. The gap node couldn't be freed, and would also be skipped in some DFX functions. The
* 'ptr.prev' pointer of this node is set to OS_MEM_GAP_NODE_MAGIC to identify that this is a gap node.
* When LOSCFG_MEM_MUL_REGIONS is enabled to support multiple non-continuous memory regions,
* the gap between two memory regions is marked as a used OsMemNodeHead node. The gap node
* couldn't be freed, and would also be skipped in some DFX functions. The 'ptr.prev' pointer
* of this node is set to OS_MEM_GAP_NODE_MAGIC to identify that this is a gap node.
*/
#define OS_MEM_GAP_NODE_MAGIC 0xDCBAABCD
#define OS_MEM_MARK_GAP_NODE(node) (((struct OsMemNodeHead *)(node))->ptr.prev = (struct OsMemNodeHead *)OS_MEM_GAP_NODE_MAGIC)
#define OS_MEM_IS_GAP_NODE(node) (((struct OsMemNodeHead *)(node))->ptr.prev == (struct OsMemNodeHead *)OS_MEM_GAP_NODE_MAGIC)
#define OS_MEM_MARK_GAP_NODE(node) \
(((struct OsMemNodeHead *)(node))->ptr.prev = (struct OsMemNodeHead *)OS_MEM_GAP_NODE_MAGIC)
#define OS_MEM_IS_GAP_NODE(node) \
(((struct OsMemNodeHead *)(node))->ptr.prev == (struct OsMemNodeHead *)OS_MEM_GAP_NODE_MAGIC)
#else
#define OS_MEM_MARK_GAP_NODE(node)
#define OS_MEM_IS_GAP_NODE(node) FALSE
@ -290,12 +299,73 @@ STATIC INLINE VOID OsMemFreeNodeAdd(VOID *pool, struct OsMemFreeNodeHead *node);
STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead *node);
STATIC VOID OsMemInfoPrint(VOID *pool);
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
#if (LOSCFG_MEM_FREE_BY_TASKID == 1 || LOSCFG_TASK_MEM_USED == 1)
STATIC INLINE VOID OsMemNodeSetTaskID(struct OsMemUsedNodeHead *node)
{
node->header.taskID = LOS_CurTaskIDGet();
}
#endif
STATIC VOID OsAllMemNodeDoHandle(VOID *pool, VOID (*handle)(struct OsMemNodeHead *curNode, VOID *arg), VOID *arg)
{
struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
struct OsMemNodeHead *tmpNode = NULL;
struct OsMemNodeHead *endNode = NULL;
UINT32 intSave;
if (pool == NULL) {
PRINTK("input param is NULL\n");
return;
}
if (LOS_MemIntegrityCheck(pool)) {
PRINTK("LOS_MemIntegrityCheck error\n");
return;
}
MEM_LOCK(poolInfo, intSave);
endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode; tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
if (tmpNode == endNode) {
#if OS_MEM_EXPAND_ENABLE
UINT32 size;
if (OsMemIsLastSentinelNode(endNode) == FALSE) {
size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
tmpNode = OsMemSentinelNodeGet(endNode);
endNode = OS_MEM_END_NODE(tmpNode, size);
continue;
}
#endif
break;
}
handle(tmpNode, arg);
}
MEM_UNLOCK(poolInfo, intSave);
}
#if (LOSCFG_TASK_MEM_USED == 1)
STATIC VOID GetTaskMemUsedHandle(struct OsMemNodeHead *curNode, VOID *arg)
{
UINT32 *args = (UINT32 *)arg;
UINT32 *outArray = (UINT32 *)(UINTPTR)*args;
UINT32 arraySize = *(args + 1);
#ifndef LOSCFG_MEM_MUL_REGIONS
if (OS_MEM_NODE_GET_USED_FLAG(curNode->sizeAndFlag)) {
#else
if (OS_MEM_NODE_GET_USED_FLAG(curNode->sizeAndFlag) && !OS_MEM_IS_GAP_NODE(curNode)) {
#endif
if (curNode->taskID < arraySize) {
outArray[curNode->taskID] += OS_MEM_NODE_GET_SIZE(curNode->sizeAndFlag);
}
}
return;
}
VOID OsTaskMemUsed(VOID *pool, UINT32 *outArray, UINT32 arraySize)
{
UINT32 args[2] = {(UINT32)(UINTPTR)outArray, arraySize};
OsAllMemNodeDoHandle(pool, GetTaskMemUsedHandle, (VOID *)args);
return;
}
#endif
#if (LOSCFG_MEM_WATERLINE == 1)
STATIC INLINE VOID OsMemWaterUsedRecord(struct OsMemPoolHead *pool, UINT32 size)
@ -535,20 +605,15 @@ STATIC INLINE VOID OsMemUsedNodePrint(struct OsMemNodeHead *node)
}
}
STATIC VOID OsMemUsedNodePrintHandle(struct OsMemNodeHead *node, VOID *arg)
{
UNUSED(arg);
OsMemUsedNodePrint(node);
return;
}
VOID LOS_MemUsedNodeShow(VOID *pool)
{
if (pool == NULL) {
PRINTK("input param is NULL\n");
return;
}
if (LOS_MemIntegrityCheck(pool)) {
PRINTK("LOS_MemIntegrityCheck error\n");
return;
}
struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
struct OsMemNodeHead *tmpNode = NULL;
struct OsMemNodeHead *endNode = NULL;
UINT32 intSave;
UINT32 count;
PRINTK("\n\rnode size ");
@ -557,33 +622,9 @@ VOID LOS_MemUsedNodeShow(VOID *pool)
}
PRINTK("\n");
MEM_LOCK(poolInfo, intSave);
OsMemLeakCheckInit();
endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
#if OS_MEM_EXPAND_ENABLE
UINT32 size;
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode;
tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
if (tmpNode == endNode) {
if (OsMemIsLastSentinelNode(endNode) == FALSE) {
size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
tmpNode = OsMemSentinelNodeGet(endNode);
endNode = OS_MEM_END_NODE(tmpNode, size);
continue;
} else {
break;
}
} else {
OsMemUsedNodePrint(tmpNode);
}
}
#else
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < endNode;
tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
OsMemUsedNodePrint(tmpNode);
}
#endif
MEM_UNLOCK(poolInfo, intSave);
OsAllMemNodeDoHandle(pool, OsMemUsedNodePrintHandle, NULL);
return;
}
#if (LOSCFG_KERNEL_PRINTF != 0)
@ -631,7 +672,8 @@ STATIC INLINE struct OsMemFreeNodeHead *OsMemFindCurSuitableBlock(struct OsMemPo
STATIC INLINE UINT32 OsMemNotEmptyIndexGet(struct OsMemPoolHead *poolHead, UINT32 index)
{
UINT32 mask = poolHead->freeListBitmap[index >> 5]; /* 5: Divide by 32 to calculate the index of the bitmap array. */
/* 5: Divide by 32 to calculate the index of the bitmap array. */
UINT32 mask = poolHead->freeListBitmap[index >> 5];
mask &= ~((1 << (index & OS_MEM_BITMAP_MASK)) - 1);
if (mask != 0) {
index = OsMemFFS(mask) + (index & ~OS_MEM_BITMAP_MASK);
@ -666,7 +708,8 @@ STATIC INLINE struct OsMemFreeNodeHead *OsMemFindNextSuitableBlock(VOID *pool, U
}
for (index = LOS_Align(index + 1, 32); index < OS_MEM_FREE_LIST_COUNT; index += 32) {
mask = poolHead->freeListBitmap[index >> 5]; /* 5: Divide by 32 to calculate the index of the bitmap array. */
/* 5: Divide by 32 to calculate the index of the bitmap array. */
mask = poolHead->freeListBitmap[index >> 5];
if (mask != 0) {
index = OsMemFFS(mask) + index;
goto DONE;
@ -687,12 +730,14 @@ DONE:
STATIC INLINE VOID OsMemSetFreeListBit(struct OsMemPoolHead *head, UINT32 index)
{
head->freeListBitmap[index >> 5] |= 1U << (index & 0x1f); /* 5: Divide by 32 to calculate the index of the bitmap array. */
/* 5: Divide by 32 to calculate the index of the bitmap array. */
head->freeListBitmap[index >> 5] |= 1U << (index & 0x1f);
}
STATIC INLINE VOID OsMemClearFreeListBit(struct OsMemPoolHead *head, UINT32 index)
{
head->freeListBitmap[index >> 5] &= ~(1U << (index & 0x1f)); /* 5: Divide by 32 to calculate the index of the bitmap array. */
/* 5: Divide by 32 to calculate the index of the bitmap array. */
head->freeListBitmap[index >> 5] &= ~(1U << (index & 0x1f));
}
STATIC INLINE VOID OsMemListAdd(struct OsMemPoolHead *pool, UINT32 listIndex, struct OsMemFreeNodeHead *node)
@ -791,7 +836,7 @@ STATIC INLINE VOID *OsMemCreateUsedNode(VOID *addr)
{
struct OsMemUsedNodeHead *node = (struct OsMemUsedNodeHead *)addr;
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
#if (LOSCFG_MEM_FREE_BY_TASKID == 1 || LOSCFG_TASK_MEM_USED == 1)
OsMemNodeSetTaskID(node);
#endif
@ -808,7 +853,8 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
poolHead->info.pool = pool;
poolHead->info.totalSize = size;
poolHead->info.attr &= ~(OS_MEM_POOL_UNLOCK_ENABLE | OS_MEM_POOL_EXPAND_ENABLE); /* default attr: lock, not expand. */
/* default attr: lock, not expand. */
poolHead->info.attr &= ~(OS_MEM_POOL_UNLOCK_ENABLE | OS_MEM_POOL_EXPAND_ENABLE);
newNode = OS_MEM_FIRST_NODE(pool);
newNode->sizeAndFlag = (size - sizeof(struct OsMemPoolHead) - OS_MEM_NODE_HEAD_SIZE);
@ -1399,8 +1445,26 @@ VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size)
}
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
STATIC VOID MemNodeFreeByTaskIDHandle(struct OsMemNodeHead *curNode, VOID *arg)
{
UINT32 *args = (UINT32 *)arg;
UINT32 taskID = *args;
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)(UINTPTR)(*(args + 1));
struct OsMemUsedNodeHead *node = NULL;
if (!OS_MEM_NODE_GET_USED_FLAG(curNode->sizeAndFlag)) {
return;
}
node = (struct OsMemUsedNodeHead *)curNode;
if (node->header.taskID == taskID) {
OsMemFree(poolHead, &node->header);
}
return;
}
UINT32 LOS_MemFreeByTaskID(VOID *pool, UINT32 taskID)
{
UINT32 args[2] = {taskID, (UINT32)(UINTPTR)pool};
if (pool == NULL) {
return OS_ERROR;
}
@ -1409,26 +1473,7 @@ UINT32 LOS_MemFreeByTaskID(VOID *pool, UINT32 taskID)
return OS_ERROR;
}
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
struct OsMemNodeHead *tmpNode = NULL;
struct OsMemUsedNodeHead *node = NULL;
struct OsMemNodeHead *endNode = NULL;
UINT32 intSave;
MEM_LOCK(poolHead, intSave);
endNode = OS_MEM_END_NODE(pool, poolHead->info.totalSize);
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < endNode;
tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
if (!OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
continue;
}
node = (struct OsMemUsedNodeHead *)tmpNode;
if (node->header.taskID == taskID) {
OsMemFree(poolHead, &node->header);
}
}
MEM_UNLOCK(poolHead, intSave);
OsAllMemNodeDoHandle(pool, MemNodeFreeByTaskIDHandle, (VOID *)args);
return LOS_OK;
}
@ -1462,11 +1507,19 @@ UINT32 LOS_MemPoolSizeGet(const VOID *pool)
return count;
}
STATIC VOID MemUsedGetHandle(struct OsMemNodeHead *curNode, VOID *arg)
{
UINT32 *memUsed = (UINT32 *)arg;
if (OS_MEM_IS_GAP_NODE(curNode)) {
*memUsed += OS_MEM_NODE_HEAD_SIZE;
} else if (OS_MEM_NODE_GET_USED_FLAG(curNode->sizeAndFlag)) {
*memUsed += OS_MEM_NODE_GET_SIZE(curNode->sizeAndFlag);
}
return;
}
UINT32 LOS_MemTotalUsedGet(VOID *pool)
{
struct OsMemNodeHead *tmpNode = NULL;
struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
struct OsMemNodeHead *endNode = NULL;
UINT32 memUsed = 0;
UINT32 intSave;
@ -1474,39 +1527,7 @@ UINT32 LOS_MemTotalUsedGet(VOID *pool)
return LOS_NOK;
}
MEM_LOCK(poolInfo, intSave);
endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
#if OS_MEM_EXPAND_ENABLE
UINT32 size;
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode;) {
if (tmpNode == endNode) {
memUsed += OS_MEM_NODE_HEAD_SIZE;
if (OsMemIsLastSentinelNode(endNode) == FALSE) {
size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
tmpNode = OsMemSentinelNodeGet(endNode);
endNode = OS_MEM_END_NODE(tmpNode, size);
continue;
} else {
break;
}
} else {
if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
memUsed += OS_MEM_NODE_GET_SIZE(tmpNode->sizeAndFlag);
}
tmpNode = OS_MEM_NEXT_NODE(tmpNode);
}
}
#else
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < endNode;) {
if (OS_MEM_IS_GAP_NODE(tmpNode)) {
memUsed += OS_MEM_NODE_HEAD_SIZE;
} else if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
memUsed += OS_MEM_NODE_GET_SIZE(tmpNode->sizeAndFlag);
}
tmpNode = OS_MEM_NEXT_NODE(tmpNode);
}
#endif
MEM_UNLOCK(poolInfo, intSave);
OsAllMemNodeDoHandle(pool, MemUsedGetHandle, (VOID *)&memUsed);
return memUsed;
}
@ -1747,7 +1768,7 @@ STATIC VOID OsMemIntegrityCheckError(struct OsMemPoolHead *pool,
OsMemNodeInfo(tmpNode, preNode);
#endif
OsMemCheckInfoRecord(tmpNode, preNode);
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
#if (LOSCFG_MEM_FREE_BY_TASKID == 1 || LOSCFG_TASK_MEM_USED == 1)
LosTaskCB *taskCB = NULL;
if (OS_MEM_NODE_GET_USED_FLAG(preNode->sizeAndFlag)) {
struct OsMemUsedNodeHead *usedNode = (struct OsMemUsedNodeHead *)preNode;
@ -1814,7 +1835,7 @@ ERROR_OUT:
return LOS_NOK;
}
STATIC INLINE VOID OsMemInfoGet(struct OsMemPoolHead *poolInfo, struct OsMemNodeHead *node,
STATIC INLINE VOID OsMemInfoGet(struct OsMemNodeHead *node,
LOS_MEM_POOL_STATUS *poolStatus)
{
UINT32 totalUsedSize = 0;
@ -1849,9 +1870,17 @@ STATIC INLINE VOID OsMemInfoGet(struct OsMemPoolHead *poolInfo, struct OsMemNode
poolStatus->freeNodeNum += freeNodeNum;
}
STATIC VOID OsMemNodeInfoGetHandle(struct OsMemNodeHead *curNode, VOID *arg)
{
LOS_MEM_POOL_STATUS *poolStatus = (LOS_MEM_POOL_STATUS *)arg;
OsMemInfoGet(curNode, poolStatus);
return;
}
UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
{
struct OsMemPoolHead *poolInfo = pool;
UINT32 intSave;
if (poolStatus == NULL) {
PRINT_ERR("can't use NULL addr to save info\n");
@ -1865,35 +1894,9 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
(VOID)memset_s(poolStatus, sizeof(LOS_MEM_POOL_STATUS), 0, sizeof(LOS_MEM_POOL_STATUS));
struct OsMemNodeHead *tmpNode = NULL;
struct OsMemNodeHead *endNode = NULL;
UINT32 intSave;
OsAllMemNodeDoHandle(pool, OsMemNodeInfoGetHandle, (VOID *)poolStatus);
MEM_LOCK(poolInfo, intSave);
endNode = OS_MEM_END_NODE(pool, poolInfo->info.totalSize);
#if OS_MEM_EXPAND_ENABLE
UINT32 size;
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode <= endNode; tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
if (tmpNode == endNode) {
poolStatus->totalUsedSize += OS_MEM_NODE_HEAD_SIZE;
poolStatus->usedNodeNum++;
if (OsMemIsLastSentinelNode(endNode) == FALSE) {
size = OS_MEM_NODE_GET_SIZE(endNode->sizeAndFlag);
tmpNode = OsMemSentinelNodeGet(endNode);
endNode = OS_MEM_END_NODE(tmpNode, size);
continue;
} else {
break;
}
} else {
OsMemInfoGet(poolInfo, tmpNode, poolStatus);
}
}
#else
for (tmpNode = OS_MEM_FIRST_NODE(pool); tmpNode < endNode; tmpNode = OS_MEM_NEXT_NODE(tmpNode)) {
OsMemInfoGet(poolInfo, tmpNode, poolStatus);
}
#endif
#if (LOSCFG_MEM_WATERLINE == 1)
poolStatus->usageWaterLine = poolInfo->info.waterLine;
#endif
@ -1971,8 +1974,10 @@ UINT32 LOS_MemFreeNodeShow(VOID *pool)
} else {
UINT32 val = 1 << (((index - OS_MEM_SMALL_BUCKET_COUNT) >> OS_MEM_SLI) + OS_MEM_LARGE_START_BUCKET);
UINT32 offset = val >> OS_MEM_SLI;
PRINTK("size: [0x%x, 0x%x], num: %u\n", (offset * ((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI))) + val,
((offset * (((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI)) + 1)) + val - 1), countNum[index]);
PRINTK("size: [0x%x, 0x%x], num: %u\n",
(offset * ((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI))) + val,
((offset * (((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI)) + 1)) + val - 1),
countNum[index]);
}
}
PRINTK("\n ********************************************************************\n\n");
@ -1990,7 +1995,8 @@ VOID LOS_MemUnlockEnable(VOID *pool)
}
#if (LOSCFG_MEM_MUL_REGIONS == 1)
STATIC INLINE UINT32 OsMemMulRegionsParamCheck(VOID *pool, const LosMemRegion * const memRegions, UINT32 memRegionCount)
STATIC INLINE UINT32 OsMemMulRegionsParamCheck(VOID *pool, const LosMemRegion * const memRegions,
UINT32 memRegionCount)
{
const LosMemRegion *memRegion = NULL;
VOID *lastStartAddress = NULL;
@ -2015,16 +2021,18 @@ STATIC INLINE UINT32 OsMemMulRegionsParamCheck(VOID *pool, const LosMemRegion *
curStartAddress = memRegion->startAddress;
curLength = memRegion->length;
if ((curStartAddress == NULL) || (curLength == 0)) {
PRINT_ERR("Memory address or length configured wrongly:address:0x%x, the length:0x%x\n", (UINTPTR)curStartAddress, curLength);
PRINT_ERR("Memory address or length configured wrongly:address:0x%x, the length:0x%x\n",
(UINTPTR)curStartAddress, curLength);
return LOS_NOK;
}
if (((UINTPTR)curStartAddress & (OS_MEM_ALIGN_SIZE - 1)) || (curLength & (OS_MEM_ALIGN_SIZE - 1))) {
PRINT_ERR("Memory address or length configured not aligned:address:0x%x, the length:0x%x, alignsize:%d\n", \
PRINT_ERR("Memory address or length configured not aligned:address:0x%x, the length:0x%x, alignsize:%d\n",
(UINTPTR)curStartAddress, curLength, OS_MEM_ALIGN_SIZE);
return LOS_NOK;
}
if ((lastStartAddress != NULL) && (((UINT8 *)lastStartAddress + lastLength) >= (UINT8 *)curStartAddress)) {
PRINT_ERR("Memory regions overlapped, the last start address:0x%x, the length:0x%x, the current start address:0x%x\n", \
PRINT_ERR("Memory regions overlapped, the last start address:0x%x, "
"the length:0x%x, the current start address:0x%x\n",
(UINTPTR)lastStartAddress, lastLength, (UINTPTR)curStartAddress);
return LOS_NOK;
}
@ -2036,7 +2044,8 @@ STATIC INLINE UINT32 OsMemMulRegionsParamCheck(VOID *pool, const LosMemRegion *
return LOS_OK;
}
STATIC INLINE VOID OsMemMulRegionsLink(struct OsMemPoolHead *poolHead, VOID *lastStartAddress, UINT32 lastLength, struct OsMemNodeHead *lastEndNode, const LosMemRegion *memRegion)
STATIC INLINE VOID OsMemMulRegionsLink(struct OsMemPoolHead *poolHead, VOID *lastStartAddress, UINT32 lastLength,
struct OsMemNodeHead *lastEndNode, const LosMemRegion *memRegion)
{
UINT32 curLength;
UINT32 gapSize;
@ -2115,7 +2124,8 @@ UINT32 LOS_MemRegionsAdd(VOID *pool, const LosMemRegion *const memRegions, UINT3
firstFreeNode = OS_MEM_FIRST_NODE(lastStartAddress);
lastEndNode = OS_MEM_END_NODE(lastStartAddress, lastLength);
while (regionCount < memRegionCount) { // traverse the rest memory regions, and initialize them as free nodes and link together
/* traverse the rest memory regions, and initialize them as free nodes and link together */
while (regionCount < memRegionCount) {
curStartAddress = memRegion->startAddress;
curLength = memRegion->length;
@ -2170,7 +2180,7 @@ STATIC VOID OsMemExcInfoGetSub(struct OsMemPoolHead *pool, MemInfoCB *memExcInfo
if (OS_MEM_NODE_GET_USED_FLAG(tmpNode->sizeAndFlag)) {
if (!OS_MEM_MAGIC_VALID(tmpNode) ||
!OsMemAddrValidCheck(pool, tmpNode->ptr.prev)) {
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
#if (LOSCFG_MEM_FREE_BY_TASKID == 1 || LOSCFG_TASK_MEM_USED == 1)
taskID = ((struct OsMemUsedNodeHead *)tmpNode)->header.taskID;
#endif
goto ERROUT;