1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "los_memstat_pri.h"
33 #include "los_task_pri.h"
34
35
36 LITE_OS_SEC_BSS_MINOR STATIC TskMemUsedInfo g_tskMemUsedInfo[LOSCFG_BASE_CORE_TSK_LIMIT];
37
OsTaskMemUsedInc(UINT32 usedSize,UINT32 taskID)38 LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemUsedInc(UINT32 usedSize, UINT32 taskID)
39 {
40 if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
41 return;
42 }
43 if (OS_INT_ACTIVE) {
44 return;
45 }
46 g_tskMemUsedInfo[taskID].memUsed += usedSize;
47 }
48
OsTaskMemUsedDec(UINT32 usedSize,UINT32 taskID)49 LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemUsedDec(UINT32 usedSize, UINT32 taskID)
50 {
51 if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
52 return;
53 }
54 if (OS_INT_ACTIVE) {
55 return;
56 }
57 if (g_tskMemUsedInfo[taskID].memUsed < usedSize) {
58 PRINT_WARN("mem used of current task '%s':0x%x, decrease size:0x%x\n",
59 OsCurrTaskGet()->taskName, g_tskMemUsedInfo[taskID].memUsed, usedSize);
60 return;
61 }
62 g_tskMemUsedInfo[taskID].memUsed -= usedSize;
63 }
64
OsTaskMemUsage(UINT32 taskID)65 LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskMemUsage(UINT32 taskID)
66 {
67 if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
68 return LOS_NOK;
69 }
70
71 return g_tskMemUsedInfo[taskID].memUsed;
72 }
73
OsTaskMemClear(UINT32 taskID)74 LITE_OS_SEC_TEXT_MINOR VOID OsTaskMemClear(UINT32 taskID)
75 {
76 if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
77 return;
78 }
79 if (g_tskMemUsedInfo[taskID].memUsed != 0) {
80 PRINT_WARN("mem used of task '%s' is:0x%x, not zero when task being deleted\n",
81 OS_TCB_FROM_TID(taskID)->taskName, g_tskMemUsedInfo[taskID].memUsed);
82 }
83 g_tskMemUsedInfo[taskID].memUsed = 0;
84 }
85
86 #ifdef LOS_MEM_SLAB
87
88 LITE_OS_SEC_BSS_MINOR STATIC TskSlabUsedInfo g_tskSlabUsedInfo[LOSCFG_BASE_CORE_TSK_LIMIT];
OsTaskSlabUsedInc(UINT32 usedSize,UINT32 taskID)89 LITE_OS_SEC_TEXT_MINOR VOID OsTaskSlabUsedInc(UINT32 usedSize, UINT32 taskID)
90 {
91 if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
92 return;
93 }
94
95 g_tskSlabUsedInfo[taskID].slabUsed += usedSize;
96 }
97
OsTaskSlabUsedDec(UINT32 usedSize,UINT32 taskID)98 LITE_OS_SEC_TEXT_MINOR VOID OsTaskSlabUsedDec(UINT32 usedSize, UINT32 taskID)
99 {
100 if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
101 return;
102 }
103
104 g_tskSlabUsedInfo[taskID].slabUsed -= usedSize;
105 }
106
OsTaskSlabUsage(UINT32 taskID)107 LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskSlabUsage(UINT32 taskID)
108 {
109 if (taskID >= LOSCFG_BASE_CORE_TSK_LIMIT) {
110 return LOS_NOK;
111 }
112
113 return g_tskSlabUsedInfo[taskID].slabUsed;
114 }
115 #endif
116
117