更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_queue_debug.c
浏览该文件的文档.
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_queue_debug_pri.h"
33#include "los_hw_pri.h"
34#include "los_ipcdebug_pri.h"
35#ifdef LOSCFG_SHELL
36#include "shcmd.h"
37#endif /* LOSCFG_SHELL */
38
39
40#ifdef LOSCFG_DEBUG_QUEUE
41
42typedef struct {
43 TSK_ENTRY_FUNC creater; /* The task entry who created this queue */
44 UINT64 lastAccessTime; /* The last access time */
47
48STATIC BOOL QueueCompareValue(const IpcSortParam *sortParam, UINT32 left, UINT32 right)
49{
50 return (*((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, left)) >
51 *((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, right)));
52}
53
55{
56 UINT32 size = LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(QueueDebugCB);
57 /* system resident memory, don't free */
59 if (g_queueDebugArray == NULL) {
60 PRINT_ERR("%s: malloc failed!\n", __FUNCTION__);
61 return LOS_NOK;
62 }
63 (VOID)memset_s(g_queueDebugArray, size, 0, size);
64 return LOS_OK;
65}
66
68{
69 QueueDebugCB *queueDebug = &g_queueDebugArray[GET_QUEUE_INDEX(queueID)];
70 queueDebug->lastAccessTime = LOS_TickCountGet();
71 return;
72}
73
75{
76 QueueDebugCB *queueDebug = &g_queueDebugArray[GET_QUEUE_INDEX(queueID)];
77 queueDebug->creater = entry;
78 queueDebug->lastAccessTime = LOS_TickCountGet();
79 return;
80}
81
82STATIC INLINE VOID OsQueueInfoOutPut(const LosQueueCB *node)
83{
84 PRINTK("Queue ID <0x%x> may leak, queue len is 0x%x, "
85 "readable cnt:0x%x, writable cnt:0x%x, ",
86 node->queueID,
87 node->queueLen,
90}
91
92STATIC INLINE VOID OsQueueOpsOutput(const QueueDebugCB *node)
93{
94 PRINTK("TaskEntry of creater:0x%p, Latest operation time: 0x%llx\n",
95 node->creater, node->lastAccessTime);
96}
97
98STATIC VOID SortQueueIndexArray(UINT32 *indexArray, UINT32 count)
99{
100 LosQueueCB queueNode = {0};
101 QueueDebugCB queueDebugNode = {0};
102 UINT32 index, intSave;
103 IpcSortParam queueSortParam;
104 queueSortParam.buf = (CHAR *)g_queueDebugArray;
105 queueSortParam.ipcDebugCBSize = sizeof(QueueDebugCB);
106 queueSortParam.ipcDebugCBCnt = LOSCFG_BASE_IPC_SEM_LIMIT;
107 queueSortParam.sortElemOff = LOS_OFF_SET_OF(QueueDebugCB, lastAccessTime);
108
109 if (count > 0) {
110 SCHEDULER_LOCK(intSave);
111 OsArraySortByTime(indexArray, 0, count - 1, &queueSortParam, QueueCompareValue);
112 SCHEDULER_UNLOCK(intSave);
113 for (index = 0; index < count; index++) {
114 SCHEDULER_LOCK(intSave);
115 (VOID)memcpy_s(&queueNode, sizeof(LosQueueCB),
116 GET_QUEUE_HANDLE(indexArray[index]), sizeof(LosQueueCB));
117 (VOID)memcpy_s(&queueDebugNode, sizeof(QueueDebugCB),
118 &g_queueDebugArray[indexArray[index]], sizeof(QueueDebugCB));
119 SCHEDULER_UNLOCK(intSave);
120 if (queueNode.queueState == OS_QUEUE_UNUSED) {
121 continue;
122 }
123 OsQueueInfoOutPut(&queueNode);
124 OsQueueOpsOutput(&queueDebugNode);
125 }
126 }
127 (VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, indexArray);
128}
129
130VOID OsQueueCheck(VOID)
131{
132 LosQueueCB queueNode = {0};
133 QueueDebugCB queueDebugNode = {0};
134 UINT32 index, intSave;
135 UINT32 count = 0;
136
137 /*
138 * This return value does not need to be judged immediately,
139 * and the following code logic has already distinguished the return value from null and non-empty,
140 * and there is no case of accessing the null pointer.
141 */
142 UINT32 *indexArray = (UINT32 *)LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(UINT32));
143
144 for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) {
145 SCHEDULER_LOCK(intSave);
146 (VOID)memcpy_s(&queueNode, sizeof(LosQueueCB),
147 GET_QUEUE_HANDLE(index), sizeof(LosQueueCB));
148 (VOID)memcpy_s(&queueDebugNode, sizeof(QueueDebugCB),
149 &g_queueDebugArray[index], sizeof(QueueDebugCB));
150 SCHEDULER_UNLOCK(intSave);
151 if ((queueNode.queueState == OS_QUEUE_UNUSED) ||
152 ((queueNode.queueState == OS_QUEUE_INUSED) && (queueDebugNode.creater == NULL))) {
153 continue;
154 }
155 if ((queueNode.queueState == OS_QUEUE_INUSED) &&
156 (queueNode.queueLen == queueNode.readWriteableCnt[OS_QUEUE_WRITE]) &&
159 LOS_ListEmpty(&queueNode.memList)) {
160 PRINTK("Queue ID <0x%x> may leak, No task uses it, "
161 "QueueLen is 0x%x, ",
162 queueNode.queueID,
163 queueNode.queueLen);
164 OsQueueOpsOutput(&queueDebugNode);
165 } else {
166 if (indexArray != NULL) {
167 *(indexArray + count) = index;
168 count++;
169 } else {
170 OsQueueInfoOutPut(&queueNode);
171 OsQueueOpsOutput(&queueDebugNode);
172 }
173 }
174 }
175
176 if (indexArray != NULL) {
177 SortQueueIndexArray(indexArray, count);
178 }
179
180 return;
181}
182
183#ifdef LOSCFG_SHELL_CMD_DEBUG
184LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdQueueInfoGet(UINT32 argc, const CHAR **argv)
185{
186 if (argc > 0) {
187 PRINTK("\nUsage: queue\n");
188 return OS_ERROR;
189 }
190 PRINTK("used queues information: \n");
191 OsQueueCheck();
192 return LOS_OK;
193}
194
196#endif /* LOSCFG_SHELL */
197#endif /* LOSCFG_DEBUG_QUEUE */
198
@ CMD_TYPE_EX
不支持标准命令参数输入,会把用户填写的命令关键字屏蔽掉,例如:输入ls /ramfs,传入给注册函数的参数只有/ramfs,而ls命令关键字并不会被传入。
Definition: shell.h:91
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
Definition: los_list.h:321
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
Definition: los_memory.c:108
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
获取自系统启动以来的Tick数
Definition: los_sys.c:82
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
Definition: los_task.h:480
VOID OsArraySortByTime(UINT32 *sortArray, UINT32 start, UINT32 end, const IpcSortParam *sortParam, OsCompareFunc compareFunc)
Definition: los_ipcdebug.c:37
STATIC BOOL QueueCompareValue(const IpcSortParam *sortParam, UINT32 left, UINT32 right)
VOID OsQueueDbgTimeUpdate(UINT32 queueID)
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdQueueInfoGet(UINT32 argc, const CHAR **argv)
STATIC QueueDebugCB * g_queueDebugArray
STATIC VOID SortQueueIndexArray(UINT32 *indexArray, UINT32 count)
SHELLCMD_ENTRY(queue_shellcmd, CMD_TYPE_EX, "queue", 0,(CmdCallBackFunc) OsShellCmdQueueInfoGet)
STATIC INLINE VOID OsQueueInfoOutPut(const LosQueueCB *node)
STATIC INLINE VOID OsQueueOpsOutput(const QueueDebugCB *node)
UINT32 OsQueueDbgInit(VOID)
VOID OsQueueCheck(VOID)
VOID OsQueueDbgUpdate(UINT32 queueID, TSK_ENTRY_FUNC entry)
@ OS_QUEUE_WRITE
写队列
Definition: los_queue_pri.h:64
@ OS_QUEUE_READ
读队列
Definition: los_queue_pri.h:63
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
size_t BOOL
Definition: los_typedef.h:88
size_t ipcDebugCBCnt
size_t ipcDebugCBSize
UINT16 readWriteableCnt[OS_QUEUE_N_RW]
Definition: los_queue_pri.h:96
UINT16 queueLen
Definition: los_queue_pri.h:91
LOS_DL_LIST memList
UINT16 queueState
Definition: los_queue_pri.h:90
UINT32 queueID
Definition: los_queue_pri.h:93
LOS_DL_LIST readWriteList[OS_QUEUE_N_RW]
Definition: los_queue_pri.h:98
UINT64 lastAccessTime
TSK_ENTRY_FUNC creater
u32_t(* CmdCallBackFunc)(u32_t argc, const char **argv)
Definition: types_adapt.h:86