diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..de2a377 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "files.associations": { + "los_queue_pri.h": "c", + "los_trace.h": "c", + "los_task_pri.h": "c", + "los_mux_debug_pri.h": "c" + } +} \ No newline at end of file diff --git a/debug/los_mux_deadlock.c b/debug/los_mux_deadlock.c new file mode 100644 index 0000000..6862541 --- /dev/null +++ b/debug/los_mux_deadlock.c @@ -0,0 +1,257 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. + * Description: Mutex Deadlock Check + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_mux_debug_pri.h" +#include "los_typedef.h" +#include "los_task.h" +#include "arch/exception.h" +#ifdef LOSCFG_SHELL +#include "shcmd.h" +#endif /* LOSCFG_SHELL */ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */nbb + +typedef struct { + LOS_DL_LIST muxListHead; /* Task-held mutexs list */ //用于管理任务持有的互斥锁列表// + UINT64 lastAccessTime; /* The last operation time */ //记录最后一次操作的时间// +} MuxDLinkCB; + +/*管理任务持有的互斥锁列表和跟踪死锁情况*/ +typedef struct { + LOS_DL_LIST muxList; /* Insert mutex into the owner task CB */ //用于将互斥锁插入到所属任务的控制块中// + VOID *muxCB; /* The Mutex CB pointer */ //指向互斥锁控制块的指针// +} MuxDLinkNode; + +STATIC MuxDLinkCB *g_muxDeadlockCBArray = NULL; + +/* + * Mutex deadlock detection time threshold, will print out task information + * that has not been scheduled within this time. + * The unit is tick. + */ +#define OS_MUX_DEADLOCK_CHECK_THRESHOLD 60000 //定义两次检查互斥锁死锁之间的最小时间间隔,单位为毫秒// + +UINT32 OsMuxDlockCheckInit(VOID) //用于分配内存并初始化互斥锁控制块列表// +{ + UINT32 index; + UINT32 size = (LOSCFG_BASE_CORE_TSK_LIMIT + 1) * sizeof(MuxDLinkCB); + + /* system resident memory, don't free */ + g_muxDeadlockCBArray = (MuxDLinkCB *)LOS_MemAlloc(m_aucSysMem1, size); + if (g_muxDeadlockCBArray == NULL) { + PRINT_ERR("%s: malloc failed!\n", __FUNCTION__); + return LOS_NOK; + } + + for (index = 0; index < LOSCFG_BASE_CORE_TSK_LIMIT + 1; index++) { + g_muxDeadlockCBArray[index].lastAccessTime = 0; + LOS_ListInit(&g_muxDeadlockCBArray[index].muxListHead); + } + return LOS_OK; +} + +VOID OsMuxDlockNodeInsert(UINT32 taskId, VOID *muxCB) //用于向指定任务的互斥锁链表中插入一个互斥锁节点// +{ + MuxDLinkNode *muxDLNode = NULL; + + if ((taskId > LOSCFG_BASE_CORE_TSK_LIMIT) || (muxCB == NULL)) { + return; + } + + muxDLNode = (MuxDLinkNode *)LOS_MemAlloc(m_aucSysMem1, sizeof(MuxDLinkNode)); + if (muxDLNode == NULL) { + return; + } + (VOID)memset_s(muxDLNode, sizeof(MuxDLinkNode), 0, sizeof(MuxDLinkNode)); + muxDLNode->muxCB = muxCB; + + LOS_ListTailInsert(&g_muxDeadlockCBArray[taskId].muxListHead, &muxDLNode->muxList); +} + +VOID OsMuxDlockNodeDelete(UINT32 taskId, const VOID *muxCB) //用于从指定任务的互斥锁链表中删除指定的互斥锁节点// +{ + MuxDLinkCB *muxDLCB = NULL; + LOS_DL_LIST *list = NULL; + MuxDLinkNode *muxDLNode = NULL; + + if ((taskId > LOSCFG_BASE_CORE_TSK_LIMIT) || (muxCB == NULL)) { + return; + } + + muxDLCB = &g_muxDeadlockCBArray[taskId]; + LOS_DL_LIST_FOR_EACH(list, &muxDLCB->muxListHead) { + muxDLNode = LOS_DL_LIST_ENTRY(list, MuxDLinkNode, muxList); + if (muxDLNode->muxCB == muxCB) { + LOS_ListDelete(&muxDLNode->muxList); + (VOID)LOS_MemFree(m_aucSysMem1, muxDLNode); + return; + } + } +} + +VOID OsTaskTimeUpdate(UINT32 taskId, UINT64 tickCount) //用于更新任务的最后访问时间// +{ + if (taskId > LOSCFG_BASE_CORE_TSK_LIMIT) { + return; + } + + g_muxDeadlockCBArray[taskId].lastAccessTime = tickCount; +} + +STATIC VOID OsDeadlockBackTrace(const LosTaskCB *taskCB) //用于打印任务的函数调用栈信息// +{ + TaskContext *context = NULL; + + PRINTK("*******backtrace begin*******\n"); + context = (TaskContext *)taskCB->stackPointer; + ArchBackTraceWithSp(context); + PRINTK("********backtrace end********\n"); + return; +} + +STATIC VOID OsMutexPendTaskList(LOS_DL_LIST *list) //用于打印互斥锁等待任务的列表信息// +{ + LOS_DL_LIST *listTmp = NULL; + LosTaskCB *pendedTask = NULL; + CHAR *name = NULL; + UINT32 index = 0; + UINT32 id, intSave; + + SCHEDULER_LOCK(intSave); + if (LOS_ListEmpty(list) == TRUE) { + SCHEDULER_UNLOCK(intSave); + PRINTK("Pended Task: null\n"); + return; + } + + LOS_DL_LIST_FOR_EACH(listTmp, list) { + pendedTask = OS_TCB_FROM_PENDLIST(listTmp); + name = pendedTask->taskName; + id = pendedTask->taskId; + SCHEDULER_UNLOCK(intSave); + if (index == 0) { + PRINTK("Pended task: %u. name:%-15s, id:0x%-5x\n", index, name, id); + } else { + PRINTK(" %u. name:%-15s, id:0x%-5x\n", index, name, id); + } + index++; + SCHEDULER_LOCK(intSave); + } + SCHEDULER_UNLOCK(intSave); +} + +STATIC VOID OsTaskHoldMutexList(MuxDLinkCB *muxDLCB) //用于打印任务持有的互斥锁的信息// +{ + UINT32 index = 0; + MuxDLinkNode *muxDLNode = NULL; + CHAR *ownerName = NULL; + LosMuxCB *muxCB = NULL; + LOS_DL_LIST *list = NULL; + LOS_DL_LIST *listTmp = NULL; + UINT32 count, intSave; + + SCHEDULER_LOCK(intSave); + if (LOS_ListEmpty(&muxDLCB->muxListHead) == TRUE) { + SCHEDULER_UNLOCK(intSave); + PRINTK("null\n"); + } else { + LOS_DL_LIST_FOR_EACH(list, &muxDLCB->muxListHead) { + muxDLNode = LOS_DL_LIST_ENTRY(list, MuxDLinkNode, muxList); + muxCB = (LosMuxCB *)muxDLNode->muxCB; + count = muxCB->muxCount; + ownerName = muxCB->owner->taskName; + SCHEDULER_UNLOCK(intSave); + PRINTK("\n", index); + PRINTK("Ptr handle:%p\n", muxCB); + PRINTK("Owner:%s\n", ownerName); + PRINTK("Count:%u\n", count); + + listTmp = &muxCB->muxList; + OsMutexPendTaskList(listTmp); + + index++; + SCHEDULER_LOCK(intSave); + } + SCHEDULER_UNLOCK(intSave); + } +} + +VOID OsMutexDlockCheck(VOID) //用于检测互斥锁死锁情况并输出相关信息// +{ + UINT32 loop, intSave; + UINT32 taskId; + CHAR *name = NULL; + LosTaskCB *taskCB = NULL; + MuxDLinkCB *muxDLCB = NULL; + + SCHEDULER_LOCK(intSave); + for (loop = 0; loop < g_taskMaxNum; loop++) { + taskCB = (LosTaskCB *)g_taskCBArray + loop; + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + continue; + } + + muxDLCB = &g_muxDeadlockCBArray[taskCB->taskId]; + if ((LOS_TickCountGet() - muxDLCB->lastAccessTime) > OS_MUX_DEADLOCK_CHECK_THRESHOLD) { + name = taskCB->taskName; + taskId = taskCB->taskId; + SCHEDULER_UNLOCK(intSave); + PRINTK("Task_name:%s, ID:0x%x, holds the Mutexs below:\n", name, taskId); + OsTaskHoldMutexList(muxDLCB); + OsDeadlockBackTrace(taskCB); + PRINTK("\n"); + SCHEDULER_LOCK(intSave); + } + } + SCHEDULER_UNLOCK(intSave); +} + +#ifdef LOSCFG_SHELL //用于在命令行中执行互斥锁死锁检查并输出相关信息// +UINT32 OsShellCmdMuxDeadlockCheck(UINT32 argc, const CHAR **argv) +{ + if (argc > 0) { + PRINTK("\nUsage: dlock\n"); + return OS_ERROR; + } + PRINTK("Start mutexs deadlock check: \n"); + OsMutexDlockCheck(); + PRINTK("-----------End-----------\n"); + return LOS_OK; +} +SHELLCMD_ENTRY(deadlock_shellcmd, CMD_TYPE_EX, "dlock", 0, (CmdCallBackFunc)OsShellCmdMuxDeadlockCheck); +#endif /* LOSCFG_SHELL */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ diff --git a/debug/los_mux_debug.c b/debug/los_mux_debug.c new file mode 100644 index 0000000..5008bc5 --- /dev/null +++ b/debug/los_mux_debug.c @@ -0,0 +1,189 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. + * Description: Mutex Debug + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_mux_debug_pri.h" +#include "los_typedef.h" +#include "los_task.h" +#include "los_misc_pri.h" +#include "arch/exception.h" +#ifdef LOSCFG_SHELL +#include "shcmd.h" +#endif /* LOSCFG_SHELL */ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#ifdef LOSCFG_DEBUG_MUTEX //用于表示互斥锁的调试信息// +typedef struct { + TSK_ENTRY_FUNC creator; /* The task entry who created this mutex */ + UINT64 lastAccessTime; /* The last access time */ +} MuxDebugCB; +STATIC MuxDebugCB *g_muxDebugArray = NULL; + +//用于比较两个互斥锁调试信息的最后访问时间// +STATIC BOOL MuxCompareValue(const SortParam *sortParam, UINT32 left, UINT32 right) +{ + return (*((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, left)) > + *((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, right))); +} + +UINT32 OsMuxDbgInit(VOID) //用于初始化互斥锁调试信息数组// +{ + UINT32 size = LOSCFG_BASE_IPC_MUX_LIMIT * sizeof(MuxDebugCB); + /* system resident memory, don't free */ + g_muxDebugArray = (MuxDebugCB *)LOS_MemAlloc(m_aucSysMem1, size); + if (g_muxDebugArray == NULL) { + PRINT_ERR("%s: malloc failed!\n", __FUNCTION__); + return LOS_NOK; + } + (VOID)memset_s(g_muxDebugArray, size, 0, size); + return LOS_OK; +} + +VOID OsMuxDbgTimeUpdate(UINT32 muxId) //用于更新指定互斥锁的最后访问时间// +{ + MuxDebugCB *muxDebug = &g_muxDebugArray[GET_MUX_INDEX(muxId)]; + muxDebug->lastAccessTime = LOS_TickCountGet(); +} + +VOID OsMuxDbgUpdate(UINT32 muxId, TSK_ENTRY_FUNC creator) //用于更新指定互斥锁的创建者和最后访问时间// +{ + MuxDebugCB *muxDebug = &g_muxDebugArray[GET_MUX_INDEX(muxId)]; + muxDebug->creator = creator; + muxDebug->lastAccessTime = LOS_TickCountGet(); +} + +//用于对互斥锁索引数组进行排序,并检查可能存在的互斥锁泄漏// +STATIC VOID SortMuxIndexArray(UINT32 *indexArray, UINT32 count) +{ + LosMuxCB muxNode = {{0, 0}, 0, 0, 0, 0}; + MuxDebugCB muxDebugNode = {0}; + UINT32 index, intSave; + SortParam muxSortParam; + muxSortParam.buf = (CHAR *)g_muxDebugArray; + muxSortParam.ctrlBlockSize = sizeof(MuxDebugCB); + muxSortParam.ctrlBlockCnt = LOSCFG_BASE_IPC_MUX_LIMIT; + muxSortParam.sortElemOff = LOS_OFF_SET_OF(MuxDebugCB, lastAccessTime); + + if (count > 0) { + SCHEDULER_LOCK(intSave); + OsArraySort(indexArray, 0, count - 1, &muxSortParam, MuxCompareValue); + SCHEDULER_UNLOCK(intSave); + for (index = 0; index < count; index++) { + SCHEDULER_LOCK(intSave); + (VOID)memcpy_s(&muxNode, sizeof(LosMuxCB), + GET_MUX(indexArray[index]), sizeof(LosMuxCB)); + (VOID)memcpy_s(&muxDebugNode, sizeof(MuxDebugCB), + &g_muxDebugArray[indexArray[index]], sizeof(MuxDebugCB)); + SCHEDULER_UNLOCK(intSave); + /* + * muxStat may be altered after the g_taskSpin is unlocked in OsMutexCheck. + * We should recheck the muxStat before the print. + */ + if ((muxNode.muxStat != LOS_USED) || + ((muxNode.muxStat == LOS_USED) && ((muxDebugNode.creator == NULL) || (muxNode.owner == NULL)))) { + continue; + } + PRINTK("Mutex ID <0x%x> may leak, TaskID of owner:0x%x, TaskEntry of owner: %p," + "TaskEntry of creator: %p,Latest operation time: 0x%llx\n", + muxNode.muxId, muxNode.owner->taskId, muxNode.owner->taskEntry, muxDebugNode.creator, + muxDebugNode.lastAccessTime); + } + } + (VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, indexArray); +} + +VOID OsMutexCheck(VOID) //用于检查互斥锁的状态并对可能存在的互斥锁泄漏进行处理// +{ + LosMuxCB muxNode = {{0, 0}, 0, 0, 0, 0}; + MuxDebugCB muxDebugNode = {0}; + UINT32 index, intSave; + UINT32 count = 0; + + /* + * This return value does not need to be judged immediately, + * and the following code logic has already distinguished the return value from null and non-empty, + * and there is no case of accessing the null pointer. + */ + UINT32 *indexArray = (UINT32 *)LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, LOSCFG_BASE_IPC_MUX_LIMIT * sizeof(UINT32)); + + for (index = 0; index < LOSCFG_BASE_IPC_MUX_LIMIT; index++) { + SCHEDULER_LOCK(intSave); + (VOID)memcpy_s(&muxNode, sizeof(LosMuxCB), GET_MUX(index), sizeof(LosMuxCB)); + (VOID)memcpy_s(&muxDebugNode, sizeof(MuxDebugCB), &g_muxDebugArray[index], sizeof(MuxDebugCB)); + SCHEDULER_UNLOCK(intSave); + + if ((muxNode.muxStat != LOS_USED) || + ((muxNode.muxStat == LOS_USED) && (muxDebugNode.creator == NULL))) { + continue; + } else if ((muxNode.muxStat == LOS_USED) && (muxNode.owner == NULL)) { + PRINTK("Mutex ID <0x%x> may leak, Owner is null, TaskEntry of creator: %p," + "Latest operation time: 0x%llx\n", + muxNode.muxId, muxDebugNode.creator, muxDebugNode.lastAccessTime); + } else { + if (indexArray != NULL) { + *(indexArray + count) = index; + count++; + } else { + PRINTK("Mutex ID <0x%x> may leak, TaskID of owner:0x%x, TaskEntry of owner: %p," + "TaskEntry of creator: %p,Latest operation time: 0x%llx\n", + muxNode.muxId, muxNode.owner->taskId, muxNode.owner->taskEntry, muxDebugNode.creator, + muxDebugNode.lastAccessTime); + } + } + } + + if (indexArray != NULL) { + SortMuxIndexArray(indexArray, count); + } +} + +#ifdef LOSCFG_SHELL +//用于获取互斥锁信息// +LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMuxInfoGet(UINT32 argc, const CHAR **argv) +{ + if (argc > 0) { + PRINTK("\nUsage: mutex\n"); + return OS_ERROR; + } + PRINTK("used mutexs information: \n"); + OsMutexCheck(); + return LOS_OK; +} +SHELLCMD_ENTRY(mutex_shellcmd, CMD_TYPE_EX, "mutex", 0, (CmdCallBackFunc)OsShellCmdMuxInfoGet); +#endif /* LOSCFG_SHELL */ +#endif /* LOSCFG_DEBUG_MUTEX */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ diff --git a/debug/los_queue_debug.c b/debug/los_queue_debug.c new file mode 100644 index 0000000..43ba6ad --- /dev/null +++ b/debug/los_queue_debug.c @@ -0,0 +1,206 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. + * Description: Queue Debug + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_queue_debug_pri.h" +#include "los_misc_pri.h" +#ifdef LOSCFG_SHELL +#include "shcmd.h" +#endif /* LOSCFG_SHELL */ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#ifdef LOSCFG_DEBUG_QUEUE //用于保存队列的调试信息// +typedef struct { + TSK_ENTRY_FUNC creator; /* The task entry who created this queue */ + UINT64 lastAccessTime; /* The last access time */ +} QueueDebugCB; +STATIC QueueDebugCB *g_queueDebugArray = NULL; + +//用于比较队列中的元素值// +STATIC BOOL QueueCompareValue(const SortParam *sortParam, UINT32 left, UINT32 right) +{ + return (*((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, left)) > + *((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, right))); +} + +UINT32 OsQueueDbgInit(VOID) //用于初始化队列的调试信息// +{ + UINT32 size = LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(QueueDebugCB); + + /* system resident memory, don't free */ + g_queueDebugArray = (QueueDebugCB *)LOS_MemAlloc(m_aucSysMem1, size); + if (g_queueDebugArray == NULL) { + PRINT_ERR("%s: malloc failed!\n", __FUNCTION__); + return LOS_NOK; + } + (VOID)memset_s(g_queueDebugArray, size, 0, size); + return LOS_OK; +} + +VOID OsQueueDbgTimeUpdate(UINT32 queueId) //用于更新队列的最后访问时间// +{ + QueueDebugCB *queueDebug = &g_queueDebugArray[GET_QUEUE_INDEX(queueId)]; + queueDebug->lastAccessTime = LOS_TickCountGet(); + return; +} + +VOID OsQueueDbgUpdate(UINT32 queueId, TSK_ENTRY_FUNC entry) //用于更新队列的调试信息// +{ + QueueDebugCB *queueDebug = &g_queueDebugArray[GET_QUEUE_INDEX(queueId)]; + queueDebug->creator = entry; + queueDebug->lastAccessTime = LOS_TickCountGet(); + return; +} + +STATIC INLINE VOID OsQueueInfoOutPut(const LosQueueCB *node) //用于输出队列的信息// +{ + PRINTK("Queue ID <0x%x> may leak, queue len is 0x%x, " + "readable cnt:0x%x, writeable cnt:0x%x, ", + node->queueId, + node->queueLen, + node->readWriteableCnt[OS_QUEUE_READ], + node->readWriteableCnt[OS_QUEUE_WRITE]); +} + +STATIC INLINE VOID OsQueueOpsOutput(const QueueDebugCB *node) //用于输出队列操作的信息// +{ + PRINTK("TaskEntry of creator:0x%p, Latest operation time: 0x%llx\n", + node->creator, node->lastAccessTime); +} + +STATIC VOID SortQueueIndexArray(UINT32 *indexArray, UINT32 count) //用于对队列索引数组进行排序并输出相应的队列信息// +{ + LosQueueCB queueNode = {0}; + QueueDebugCB queueDebugNode = {0}; + UINT32 index, intSave; + SortParam queueSortParam; + queueSortParam.buf = (CHAR *)g_queueDebugArray; + queueSortParam.ctrlBlockSize = sizeof(QueueDebugCB); + queueSortParam.ctrlBlockCnt = LOSCFG_BASE_IPC_QUEUE_LIMIT; + queueSortParam.sortElemOff = LOS_OFF_SET_OF(QueueDebugCB, lastAccessTime); + + if (count > 0) { + SCHEDULER_LOCK(intSave); + OsArraySort(indexArray, 0, count - 1, &queueSortParam, QueueCompareValue); + SCHEDULER_UNLOCK(intSave); + for (index = 0; index < count; index++) { + SCHEDULER_LOCK(intSave); + (VOID)memcpy_s(&queueNode, sizeof(LosQueueCB), + GET_QUEUE_HANDLE(indexArray[index]), sizeof(LosQueueCB)); + (VOID)memcpy_s(&queueDebugNode, sizeof(QueueDebugCB), + &g_queueDebugArray[indexArray[index]], sizeof(QueueDebugCB)); + SCHEDULER_UNLOCK(intSave); + if (queueNode.queueState == LOS_UNUSED) { + continue; + } + OsQueueInfoOutPut(&queueNode); + OsQueueOpsOutput(&queueDebugNode); + } + } + (VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, indexArray); +} + +VOID OsQueueCheck(VOID) //用于检查队列的状态并输出相应信息// +{ + LosQueueCB queueNode = {0}; + QueueDebugCB queueDebugNode = {0}; + UINT32 index, intSave; + UINT32 count = 0; + + /* + * This return value does not need to be judged immediately, + * and the following code logic has already distinguished the return value from null and non-empty, + * and there is no case of accessing the null pointer. + */ + UINT32 *indexArray = (UINT32 *)LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, LOSCFG_BASE_IPC_QUEUE_LIMIT * sizeof(UINT32)); + + for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) { + SCHEDULER_LOCK(intSave); + (VOID)memcpy_s(&queueNode, sizeof(LosQueueCB), + GET_QUEUE_HANDLE(index), sizeof(LosQueueCB)); + (VOID)memcpy_s(&queueDebugNode, sizeof(QueueDebugCB), + &g_queueDebugArray[index], sizeof(QueueDebugCB)); + SCHEDULER_UNLOCK(intSave); + if ((queueNode.queueState == LOS_UNUSED) || + ((queueNode.queueState == LOS_USED) && (queueDebugNode.creator == NULL))) { + continue; + } + if ((queueNode.queueState == LOS_USED) && + (queueNode.queueLen == queueNode.readWriteableCnt[OS_QUEUE_WRITE]) && + LOS_ListEmpty(&queueNode.readWriteList[OS_QUEUE_READ]) && + LOS_ListEmpty(&queueNode.readWriteList[OS_QUEUE_WRITE]) && + LOS_ListEmpty(&queueNode.memList)) { + PRINTK("Queue ID <0x%x> may leak, No task uses it, " + "QueueLen is 0x%x, ", + queueNode.queueId, + queueNode.queueLen); + OsQueueOpsOutput(&queueDebugNode); + } else { + if (indexArray != NULL) { + *(indexArray + count) = index; + count++; + } else { + OsQueueInfoOutPut(&queueNode); + OsQueueOpsOutput(&queueDebugNode); + } + } + } + + if (indexArray != NULL) { + SortQueueIndexArray(indexArray, count); + } + + return; +} + +#ifdef LOSCFG_SHELL +//当用户输入 "queue" 命令时,会输出已使用队列的信息// +LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdQueueInfoGet(UINT32 argc, const CHAR **argv) +{ + if (argc > 0) { + PRINTK("\nUsage: queue\n"); + return OS_ERROR; + } + PRINTK("used queues information: \n"); + OsQueueCheck(); + return LOS_OK; +} + +SHELLCMD_ENTRY(queue_shellcmd, CMD_TYPE_EX, "queue", 0, (CmdCallBackFunc)OsShellCmdQueueInfoGet); +#endif /* LOSCFG_SHELL */ +#endif /* LOSCFG_DEBUG_QUEUE */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ diff --git a/debug/los_sched_debug.c b/debug/los_sched_debug.c new file mode 100644 index 0000000..ec4a78b --- /dev/null +++ b/debug/los_sched_debug.c @@ -0,0 +1,347 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved. + * Description: Schedule Statistics + * Author: Huawei LiteOS Team + * Create: 2018-11-16 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_task_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_DEBUG_SCHED_STATISTICS +#define HIGHTASKPRI 16 +#define NS_PER_MS 1000000 +#define DECIMAL_TO_PERCENTAGE 100 + +typedef struct { + UINT64 idleRuntime; //空闲任务的运行时间// + UINT64 idleStarttime; //空闲任务的启动时间// + UINT64 highTaskRuntime; //高优先级任务的运行时间// + UINT64 highTaskStarttime; //高优先级任务的启动时间// + UINT64 sumPriority; //任务优先级之和// + UINT32 prioritySwitch; //任务切换次数// + UINT32 highTaskSwitch; //高优先级任务切换次数// + UINT32 contexSwitch; //上下文切换次数// + UINT32 hwiNum; //硬件中断次数// +#ifdef LOSCFG_KERNEL_SMP + UINT32 ipiIrqNum; //中断次数(仅在多核配置下定义)// +#endif +} StatPercpu; + +STATIC BOOL g_statisticsStartFlag = FALSE; +STATIC UINT64 g_statisticsStartTime; +STATIC StatPercpu g_statPercpu[LOSCFG_KERNEL_CORE_NUM]; + +//用于在每个 CPU 核心上进行调度统计// +STATIC VOID OsSchedStatisticsPerCpu(const LosTaskCB *runTask, const LosTaskCB *newTask) +{ + UINT32 cpuId; + UINT32 idleTaskId; + UINT64 now, runtime; + + if (g_statisticsStartFlag != TRUE) { + return; + } + + cpuId = ArchCurrCpuid(); + idleTaskId = OsGetIdleTaskId(); + now = LOS_CurrNanosec(); + + g_statPercpu[cpuId].contexSwitch++; + + if ((runTask->taskId != idleTaskId) && (newTask->taskId == idleTaskId)) { + g_statPercpu[cpuId].idleStarttime = now; + } + + if ((runTask->taskId == idleTaskId) && (newTask->taskId != idleTaskId)) { + runtime = now - g_statPercpu[cpuId].idleStarttime; + g_statPercpu[cpuId].idleRuntime += runtime; + g_statPercpu[cpuId].idleStarttime = 0; + } + + if ((runTask->priority >= HIGHTASKPRI) && (newTask->priority < HIGHTASKPRI)) { + g_statPercpu[cpuId].highTaskStarttime = now; + } + + if ((runTask->priority < HIGHTASKPRI) && (newTask->priority >= HIGHTASKPRI)) { + runtime = now - g_statPercpu[cpuId].highTaskStarttime; + g_statPercpu[cpuId].highTaskRuntime += runtime; + g_statPercpu[cpuId].highTaskStarttime = 0; + } + + if (newTask->priority < HIGHTASKPRI) { + g_statPercpu[cpuId].highTaskSwitch++; + } + + if (newTask->taskId != idleTaskId) { + g_statPercpu[cpuId].sumPriority += newTask->priority; + g_statPercpu[cpuId].prioritySwitch++; + } + + return; +} + +//用于更新调度统计信息// +LITE_OS_SEC_TEXT_MINOR VOID OsSchedStatistics(LosTaskCB *runTask, LosTaskCB *newTask) +{ + UINT64 runtime; + UINT32 cpuId = ArchCurrCpuid(); + UINT64 now = LOS_CurrNanosec(); + + SchedStat *schedRun = &runTask->schedStat; + SchedStat *schedNew = &newTask->schedStat; + SchedPercpu *cpuRun = &schedRun->schedPercpu[cpuId]; + SchedPercpu *cpuNew = &schedNew->schedPercpu[cpuId]; + + /* calculate one chance of running time */ + runtime = now - schedRun->startRuntime; + + /* add running timer to running task statistics */ + cpuRun->runtime += runtime; + schedRun->allRuntime += runtime; + + /* add context switch counters and schedule start time */ + cpuNew->contexSwitch++; + schedNew->allContextSwitch++; + schedNew->startRuntime = now; + OsSchedStatisticsPerCpu(runTask, newTask); +} + +LITE_OS_SEC_TEXT_MINOR VOID OsHwiStatistics(size_t intNum) //用于更新硬中断的统计信息// +{ + UINT32 cpuId = ArchCurrCpuid(); + + if ((g_statisticsStartFlag != TRUE) || (intNum == OS_TICK_INT_NUM)) { + return; + } + + g_statPercpu[cpuId].hwiNum++; +#ifdef LOSCFG_KERNEL_SMP + /* 16: 0~15 is ipi interrupts */ + if (intNum < 16) { + g_statPercpu[cpuId].ipiIrqNum++; + } +#endif + return; +} + +LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdDumpSched(VOID) //用于打印任务的调度统计信息// +{ + LosTaskCB *taskCB = NULL; + UINT32 loop; + UINT32 cpuId; +#ifdef LOSCFG_KERNEL_SMP + UINT32 affinity; +#endif + + PRINTK("\n"); + PRINTK("Task TID Total Time Total CST " + "CPU Time CST\n"); + PRINTK("---- --- ------------------ ---------- -" + "--- ------------------ ----------\n"); + + for (loop = 0; loop < g_taskMaxNum; loop++) { + taskCB = (((LosTaskCB *)g_taskCBArray) + loop); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + continue; + } +#ifdef LOSCFG_KERNEL_SMP + affinity = (UINT32)taskCB->cpuAffiMask; +#endif + PRINTK("%-30s0x%-6x%+16lf ms %10u\n", taskCB->taskName, taskCB->taskId, + (DOUBLE)(taskCB->schedStat.allRuntime) / NS_PER_MS, + taskCB->schedStat.allContextSwitch); + + for (cpuId = 0; cpuId < LOSCFG_KERNEL_CORE_NUM; cpuId++) { +#ifdef LOSCFG_KERNEL_SMP + if (!((1U << cpuId) & affinity)) { + continue; + } +#endif + PRINTK(" " + "CPU%u %+16lf ms %12u\n", cpuId, + (DOUBLE)(taskCB->schedStat.schedPercpu[cpuId].runtime) / NS_PER_MS, + taskCB->schedStat.schedPercpu[cpuId].contexSwitch); + } + } + + PRINTK("\n"); +} + +LITE_OS_SEC_TEXT_MINOR VOID OsStatisticsShow(UINT64 statisticsPastTime) //用于显示系统的统计信息// +{ + UINT32 cpuId; + PRINTK("\n"); + PRINTK("Passed Time: %+16lf ms\n", ((DOUBLE)statisticsPastTime / NS_PER_MS)); + PRINTK("--------------------------------\n"); + PRINTK("CPU Idle(%%) ContexSwitch HwiNum " + "Avg Pri HiTask(%%) HiTask SwiNum HiTask P(ms)" +#ifdef LOSCFG_KERNEL_SMP + " MP Hwi\n"); +#else + "\n"); +#endif + PRINTK("---- --------- ----------- -------- --------- " + "---------- ------------ ----------" +#ifdef LOSCFG_KERNEL_SMP + " ------\n"); +#else + "\n"); +#endif + + for (cpuId = 0; cpuId < LOSCFG_KERNEL_CORE_NUM; cpuId++) { +#ifdef LOSCFG_KERNEL_SMP + PRINTK("CPU%u %+10lf%14u%14u %+11lf %+11lf%14u %+11lf %11u\n", cpuId, +#else + PRINTK("CPU%u %+10lf%14u%14u %+11lf %+11lf%14u %+11lf\n", cpuId, +#endif + ((DOUBLE)(g_statPercpu[cpuId].idleRuntime) / statisticsPastTime) * DECIMAL_TO_PERCENTAGE, + g_statPercpu[cpuId].contexSwitch, + g_statPercpu[cpuId].hwiNum, + (g_statPercpu[cpuId].prioritySwitch == 0) ? OS_TASK_PRIORITY_LOWEST : + ((DOUBLE)(g_statPercpu[cpuId].sumPriority) / (g_statPercpu[cpuId].prioritySwitch)), + ((DOUBLE)(g_statPercpu[cpuId].highTaskRuntime) / statisticsPastTime) * DECIMAL_TO_PERCENTAGE, + g_statPercpu[cpuId].highTaskSwitch, + (g_statPercpu[cpuId].highTaskSwitch == 0) ? 0 : + ((DOUBLE)(g_statPercpu[cpuId].highTaskRuntime) / (g_statPercpu[cpuId].highTaskSwitch)) / NS_PER_MS +#ifdef LOSCFG_KERNEL_SMP + , g_statPercpu[cpuId].ipiIrqNum); +#else + ); +#endif + } + + PRINTK("\n"); +} + +LITE_OS_SEC_TEXT_MINOR VOID OsShellStatisticsStart(VOID) //用于在多核系统中启动统计功能// +{ + LosTaskCB *taskCB = NULL; + UINT32 loop; + UINT32 cpuId = 0; + UINT32 intSave; + + SCHEDULER_LOCK(intSave); + + if (g_statisticsStartFlag) { + SCHEDULER_UNLOCK(intSave); + PRINT_WARN("mp static has started\n"); + return; + } + + g_statisticsStartTime = LOS_CurrNanosec(); + + for (loop = 0; loop < g_taskMaxNum; loop++) { + taskCB = (((LosTaskCB *)g_taskCBArray) + loop); + if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) { +#ifdef LOSCFG_KERNEL_SMP + cpuId = taskCB->currCpu; +#endif + if ((UINT32)(OS_TASK_INVALID_CPUID) == cpuId) { + continue; + } + if (!strcmp(taskCB->taskName, "IdleCore000")) { + g_statPercpu[cpuId].idleStarttime = g_statisticsStartTime; + } + if (taskCB->priority < HIGHTASKPRI) { + g_statPercpu[cpuId].highTaskStarttime = g_statisticsStartTime; + g_statPercpu[cpuId].highTaskSwitch++; + } + if (strcmp(taskCB->taskName, "IdleCore000")) { + g_statPercpu[cpuId].sumPriority += taskCB->priority; + g_statPercpu[cpuId].prioritySwitch++; + } + } + } + g_statisticsStartFlag = TRUE; + SCHEDULER_UNLOCK(intSave); + + PRINTK("mp static start\n"); + + return; +} + +//用于在多核系统中停止统计功能,并进行统计数据的处理和展示// +LITE_OS_SEC_TEXT_MINOR VOID OsShellStatisticsStop(VOID) +{ + LosTaskCB *taskCB = NULL; + UINT32 loop; + UINT32 cpuId = 0; + UINT64 statisticsStopTime; + UINT64 statisticsPastTime; + UINT64 runtime; + UINT32 intSave; + + SCHEDULER_LOCK(intSave); + + if (g_statisticsStartFlag != TRUE) { + SCHEDULER_UNLOCK(intSave); + PRINT_WARN("Please set mp static start\n"); + return; + } + + g_statisticsStartFlag = FALSE; + statisticsStopTime = LOS_CurrNanosec(); + statisticsPastTime = statisticsStopTime - g_statisticsStartTime; + + for (loop = 0; loop < g_taskMaxNum; loop++) { + taskCB = (((LosTaskCB *)g_taskCBArray) + loop); + if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) { +#ifdef LOSCFG_KERNEL_SMP + cpuId = taskCB->currCpu; +#endif + if (cpuId == (UINT32)(OS_TASK_INVALID_CPUID)) { + continue; + } + if (!strcmp(taskCB->taskName, "IdleCore000")) { + runtime = statisticsStopTime - g_statPercpu[cpuId].idleStarttime; + g_statPercpu[cpuId].idleRuntime += runtime; + g_statPercpu[cpuId].idleStarttime = 0; + } + if (taskCB->priority < HIGHTASKPRI) { + runtime = statisticsStopTime - g_statPercpu[cpuId].highTaskStarttime; + g_statPercpu[cpuId].highTaskRuntime += runtime; + g_statPercpu[cpuId].highTaskStarttime = 0; + } + } + } + SCHEDULER_UNLOCK(intSave); + OsStatisticsShow(statisticsPastTime); + + (VOID)memset_s(g_statPercpu, sizeof(g_statPercpu), 0, sizeof(g_statPercpu)); + g_statisticsStartTime = 0; + return; +} +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/debug/los_sem_debug.c b/debug/los_sem_debug.c new file mode 100644 index 0000000..8f1774b --- /dev/null +++ b/debug/los_sem_debug.c @@ -0,0 +1,299 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. + * Description: Sem Debug + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_sem_debug_pri.h" +#include "stdlib.h" +#include "los_typedef.h" +#include "los_task_pri.h" +#include "los_misc_pri.h" +#ifdef LOSCFG_SHELL +#include "shcmd.h" +#endif /* LOSCFG_SHELL */ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#ifdef LOSCFG_DEBUG_SEMAPHORE +#define OS_ALL_SEM_MASK 0xffffffff + +STATIC VOID OsSemPendedTaskNamePrint(LosSemCB *semNode) //用于打印等待某个信号量的任务列表// +{ + LosTaskCB *tskCB = NULL; + CHAR *nameArr[LOSCFG_BASE_CORE_TSK_LIMIT] = {0}; + UINT32 i, intSave; + UINT32 num = 0; + + SCHEDULER_LOCK(intSave); + if ((semNode->semStat == LOS_UNUSED) || (LOS_ListEmpty(&semNode->semList))) { + SCHEDULER_UNLOCK(intSave); + return; + } + + LOS_DL_LIST_FOR_EACH_ENTRY(tskCB, &semNode->semList, LosTaskCB, pendList) { + nameArr[num++] = tskCB->taskName; + if (num == LOSCFG_BASE_CORE_TSK_LIMIT) { + break; + } + } + SCHEDULER_UNLOCK(intSave); + + PRINTK("Pended task list : "); + for (i = 0; i < num; i++) { + if (i == 0) { + PRINTK("%s\n", nameArr[i]); + } else { + PRINTK(", %s", nameArr[i]); + } + } + PRINTK("\n"); +} + +typedef struct { //用于记录信号量的调试信息// + UINT16 origSemCount; /* Number of original available semaphores */ + UINT64 lastAccessTime; /* The last operation time */ + TSK_ENTRY_FUNC creator; /* The task entry who created this sem */ +} SemDebugCB; +STATIC SemDebugCB *g_semDebugArray = NULL; //用于存储所有信号量的调试信息// + +//用于比较两个排序元素的值// +STATIC BOOL SemCompareValue(const SortParam *sortParam, UINT32 left, UINT32 right) +{ + return (*((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, left)) > + *((UINT64 *)(VOID *)SORT_ELEM_ADDR(sortParam, right))); +} + +UINT32 OsSemDbgInit(VOID) //用于初始化信号量的调试信息数组// +{ + UINT32 size = LOSCFG_BASE_IPC_SEM_LIMIT * sizeof(SemDebugCB); + /* system resident memory, don't free */ + g_semDebugArray = (SemDebugCB *)LOS_MemAlloc(m_aucSysMem1, size); + if (g_semDebugArray == NULL) { + PRINT_ERR("%s: malloc failed!\n", __FUNCTION__); + return LOS_NOK; + } + (VOID)memset_s(g_semDebugArray, size, 0, size); + return LOS_OK; +} + +VOID OsSemDbgTimeUpdate(UINT32 semId) //用于更新指定信号量的最后一次访问时间// +{ + SemDebugCB *semDebug = &g_semDebugArray[GET_SEM_INDEX(semId)]; + semDebug->lastAccessTime = LOS_TickCountGet(); + return; +} + +VOID OsSemDbgUpdate(UINT32 semId, TSK_ENTRY_FUNC creator, UINT16 count) //用于更新指定信号量的调试信息// +{ + SemDebugCB *semDebug = &g_semDebugArray[GET_SEM_INDEX(semId)]; + semDebug->creator = creator; + semDebug->lastAccessTime = LOS_TickCountGet(); + semDebug->origSemCount = count; + return; +} + +/*用于按照信号量的最后访问时间对当前正在使用的信号量进行排序,*/ +/*并打印每个信号量的调试信息和等待该信号量的任务名*/ +STATIC VOID OsSemSort(UINT32 *semIndexArray, UINT32 usedCount) +{ + UINT32 i, intSave; + LosSemCB *semCB = NULL; + LosSemCB semNode = {0}; + SemDebugCB semDebug = {0}; + SortParam semSortParam; + semSortParam.buf = (CHAR *)g_semDebugArray; + semSortParam.ctrlBlockSize = sizeof(SemDebugCB); + semSortParam.ctrlBlockCnt = LOSCFG_BASE_IPC_SEM_LIMIT; + semSortParam.sortElemOff = LOS_OFF_SET_OF(SemDebugCB, lastAccessTime); + + /* It will Print out ALL the Used Semaphore List. */ + PRINTK("Used Semaphore List: \n"); + PRINTK("\r\n SemID Count OriginalCount Creater(TaskEntry) LastAccessTime\n"); + PRINTK(" ------ ------ ------------- ------------------ -------------- \n"); + + SCHEDULER_LOCK(intSave); + OsArraySort(semIndexArray, 0, usedCount - 1, &semSortParam, SemCompareValue); + SCHEDULER_UNLOCK(intSave); + for (i = 0; i < usedCount; i++) { + semCB = GET_SEM(semIndexArray[i]); + SCHEDULER_LOCK(intSave); + (VOID)memcpy_s(&semNode, sizeof(LosSemCB), semCB, sizeof(LosSemCB)); + (VOID)memcpy_s(&semDebug, sizeof(SemDebugCB), &g_semDebugArray[semIndexArray[i]], sizeof(SemDebugCB)); + SCHEDULER_UNLOCK(intSave); + if ((semNode.semStat != LOS_USED) || (semDebug.creator == NULL)) { + continue; + } + PRINTK(" 0x%-07x0x%-07u0x%-14u%-22p0x%llx\n", semNode.semId, semDebug.origSemCount, + semNode.semCount, semDebug.creator, semDebug.lastAccessTime); + if (!LOS_ListEmpty(&semNode.semList)) { + OsSemPendedTaskNamePrint(semCB); + } + } +} +/*用于获取当前正在使用的信号量信息,并按照信号量的最后访问时间对信号量进行排序*/ +UINT32 OsSemInfoGetFullData(VOID) +{ + UINT32 usedSemCnt = 0; + LosSemCB *semNode = NULL; + SemDebugCB *semDebug = NULL; + UINT32 i; + UINT32 *semIndexArray = NULL; + UINT32 count, intSave; + + SCHEDULER_LOCK(intSave); + /* Get the used semaphore count. */ + for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) { + semNode = GET_SEM(i); + semDebug = &g_semDebugArray[i]; + if ((semNode->semStat == LOS_USED) && (semDebug->creator != NULL)) { + usedSemCnt++; + } + } + SCHEDULER_UNLOCK(intSave); + + if (usedSemCnt > 0) { + semIndexArray = (UINT32 *)LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, usedSemCnt * sizeof(UINT32)); + if (semIndexArray == NULL) { + PRINTK("LOS_MemAlloc failed in %s \n", __func__); + return LOS_NOK; + } + + /* Fill the semIndexArray with the real index. */ + count = 0; + + SCHEDULER_LOCK(intSave); + for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) { + semNode = GET_SEM(i); + semDebug = &g_semDebugArray[i]; + if ((semNode->semStat != LOS_USED) || (semDebug->creator == NULL)) { + continue; + } + *(semIndexArray + count) = i; + count++; + /* if the count is touched usedSemCnt break. */ + if (count >= usedSemCnt) { + break; + } + } + SCHEDULER_UNLOCK(intSave); + OsSemSort(semIndexArray, count); + + /* free the index array. */ + (VOID)LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, semIndexArray); + } + return LOS_OK; +} + +#ifdef LOSCFG_SHELL +STATIC UINT32 OsSemInfoOutput(size_t semId) //用于输出信号量信息// +{ + UINT32 loop, semCnt, intSave; + LosSemCB *semCB = NULL; + LosSemCB semNode = {0}; + + if (semId == OS_ALL_SEM_MASK) { + for (loop = 0, semCnt = 0; loop < LOSCFG_BASE_IPC_SEM_LIMIT; loop++) { + semCB = GET_SEM(loop); + SCHEDULER_LOCK(intSave); + if (semCB->semStat == LOS_USED) { + (VOID)memcpy_s(&semNode, sizeof(LosSemCB), semCB, sizeof(LosSemCB)); + SCHEDULER_UNLOCK(intSave); + semCnt++; + PRINTK("\r\n SemID Count\n ---------- -----\n"); + PRINTK(" 0x%08x %u\n", semNode.semId, semNode.semCount); + continue; + } + SCHEDULER_UNLOCK(intSave); + } + PRINTK(" SemUsingNum : %u\n\n", semCnt); + return LOS_OK; + } else { + semCB = GET_SEM(semId); + SCHEDULER_LOCK(intSave); + (VOID)memcpy_s(&semNode, sizeof(LosSemCB), semCB, sizeof(LosSemCB)); + SCHEDULER_UNLOCK(intSave); + if ((semNode.semId != semId) || (semNode.semStat != LOS_USED)) { + PRINTK("\nThe semaphore is not in use!\n"); + return LOS_OK; + } + + PRINTK("\r\n SemID Count\n ---------- -----\n"); + PRINTK(" 0x%08x 0x%u\n", semNode.semId, semNode.semCount); + + if (LOS_ListEmpty(&semNode.semList)) { + PRINTK("No task is pended on this semaphore!\n"); + return LOS_OK; + } else { + OsSemPendedTaskNamePrint(semCB); + } + } + return LOS_OK; +} + +//用于获取信号量信息// +LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSemInfoGet(UINT32 argc, const CHAR **argv) +{ + size_t semId; + CHAR *endPtr = NULL; + UINT32 ret; + + if (argc > 1) { + PRINTK("\nUsage: sem [fulldata|ID]\n"); + return OS_ERROR; + } + + if (argc == 0) { + semId = OS_ALL_SEM_MASK; + } else { + if (strcmp(argv[0], "fulldata") == 0) { + ret = OsSemInfoGetFullData(); + return ret; + } + + semId = strtoul(argv[0], &endPtr, 0); + if ((*endPtr != 0) || (GET_SEM_INDEX(semId) >= LOSCFG_BASE_IPC_SEM_LIMIT)) { + PRINTK("\nsem ID can't access %s.\n", argv[0]); + return OS_ERROR; + } + } + + ret = OsSemInfoOutput(semId); + return ret; +} + +SHELLCMD_ENTRY(sem_shellcmd, CMD_TYPE_EX, "sem", 1, (CmdCallBackFunc)OsShellCmdSemInfoGet); +#endif /* LOSCFG_SHELL */ +#endif /* LOSCFG_DEBUG_SEMAPHORE */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ diff --git a/doc/寮婧愪唬鐮佺殑娉涜鎶ュ憡-LiteOS.docx b/doc/寮婧愪唬鐮佺殑娉涜鎶ュ憡-LiteOS.docx new file mode 100644 index 0000000..5a3b73c Binary files /dev/null and b/doc/寮婧愪唬鐮佺殑娉涜鎶ュ憡-LiteOS.docx differ diff --git a/doc/鐢ㄤ緥鍥.pdf b/doc/鐢ㄤ緥鍥.pdf new file mode 100644 index 0000000..3030218 Binary files /dev/null and b/doc/鐢ㄤ緥鍥.pdf differ diff --git a/doc/鐢ㄤ緥鎻忚堪_oujiashu.docx b/doc/鐢ㄤ緥鎻忚堪_oujiashu.docx new file mode 100644 index 0000000..367e6a9 Binary files /dev/null and b/doc/鐢ㄤ緥鎻忚堪_oujiashu.docx differ diff --git a/doc/鐢ㄤ緥鎻忚堪_钄′鸡.docx b/doc/鐢ㄤ緥鎻忚堪_钄′鸡.docx new file mode 100644 index 0000000..7c2941e Binary files /dev/null and b/doc/鐢ㄤ緥鎻忚堪_钄′鸡.docx differ diff --git a/doc/钄′鸡_LiteOS闃呰娉涜鎶ュ憡.docx b/doc/钄′鸡_LiteOS闃呰娉涜鎶ュ憡.docx new file mode 100644 index 0000000..6bfadf4 Binary files /dev/null and b/doc/钄′鸡_LiteOS闃呰娉涜鎶ュ憡.docx differ diff --git a/doc/钄′鸡_LiteOS闃呰鎶ュ憡.docx b/fuaojia_branch.txt similarity index 100% rename from doc/钄′鸡_LiteOS闃呰鎶ュ憡.docx rename to fuaojia_branch.txt diff --git a/hjc/hjc.txt b/hjc/hjc.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/kernel/base/include/los_binarytree_pri.h b/src/kernel/base/include/los_binarytree_pri.h index 2de75ae..7c10fdc 100644 --- a/src/kernel/base/include/los_binarytree_pri.h +++ b/src/kernel/base/include/los_binarytree_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟浜嗕笌浜屽弶鏍戠浉鍏崇殑缁撴瀯浣撳拰鍑芥暟锛岀敤浜庡疄鐜板鏁版嵁鐨勫揩閫熸煡鎵惧拰鎻掑叆銆 #ifndef _LOS_BINARYTREE_PRI_H #define _LOS_BINARYTREE_PRI_H @@ -35,67 +35,76 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//瀹氫箟浜屽弶鏍戣妭鐐圭殑妯″瀷 typedef struct tagBinNode { - struct tagBinNode *left; - struct tagBinNode *right; - UINT32 nodeId; - CHAR keyValue[0]; + struct tagBinNode *left;//宸﹀瓙鏍戣妭鐐 + struct tagBinNode *right;//鍙冲瓙鏍戣妭鐐 + UINT32 nodeId;//鑺傜偣鐨勭紪鍙 + CHAR keyValue[0];//鑺傜偣璁板綍鐨勫硷紙鏌旀ф暟缁勶紝鍔ㄦ佸垎閰嶅唴瀛橈級 } BinNode; +//閾炬帴浜屽弶鏍戣妭鐐 typedef struct { - BinNode leaf; - UINTPTR linkReg1; + BinNode leaf;//涓涓簩鍙夋爲 + UINTPTR linkReg1;//鏃犵鍙锋暟鐨勬寚閽堬紝鍙繛鎺ヤ笁涓妭鐐 UINTPTR linkReg2; UINTPTR linkReg3; } LinkRegNode; #define LR_COUNT 4096 -extern LinkRegNode g_linkRegNode[LR_COUNT]; -extern UINT32 g_linkRegNodeIndex; -extern LinkRegNode *g_linkRegRoot; +extern LinkRegNode g_linkRegNode[LR_COUNT];//4096涓摼鎺ヤ簩鍙夋爲鑺傜偣 +extern UINT32 g_linkRegNodeIndex;//閾炬帴浜屽弶鏍戣妭鐐圭殑绱㈠紩 +extern LinkRegNode *g_linkRegRoot;//閾炬帴浜屽弶鏍戣妭鐐圭殑鎸囬拡 +//鍦板潃浜屽弶鏍戣妭鐐 typedef struct { - BinNode leaf; - UINTPTR addr; + BinNode leaf;//涓涓簩鍙夋爲鑺傜偣 + UINTPTR addr;//浜屽弶鏍戣妭鐐硅褰曠殑鍦板潃 } AddrNode; #define ADDR_COUNT 40960 -extern AddrNode g_addrNode[ADDR_COUNT]; -extern UINT32 g_addrNodeIndex; -extern AddrNode *g_addrRoot; +extern AddrNode g_addrNode[ADDR_COUNT];//40960涓湴鍧浜屽弶鏍戣妭鐐 +extern UINT32 g_addrNodeIndex;//鍦板潃浜屽弶鏍戣妭鐐圭殑绱㈠紩 +extern AddrNode *g_addrRoot;//鍦板潃浜屽弶鏍戣妭鐐圭殑鎸囬拡 +//璇锋眰澶у皬浜屽弶鏍戣妭鐐 typedef struct { - BinNode leaf; - UINT32 reqSize; + BinNode leaf;//涓涓簩鍙夋爲 + UINT32 reqSize;//璇锋眰鏁版嵁澶у皬 } ReqSizeNode; #define REQ_SIZE_COUNT 4096 -extern ReqSizeNode g_reqSizeNode[REQ_SIZE_COUNT]; -extern UINT32 g_reqSizeNodeIndex; -extern ReqSizeNode *g_reqSizeRoot; +extern ReqSizeNode g_reqSizeNode[REQ_SIZE_COUNT];//4096涓姹傚ぇ灏忎簩鍙夋爲鑺傜偣 +extern UINT32 g_reqSizeNodeIndex;//璇锋眰澶у皬浜屽弶鏍戣妭鐐圭殑绱㈠紩 +extern ReqSizeNode *g_reqSizeRoot;//璇锋眰澶у皬浜屽弶鏍戣妭鐐圭殑鎸囬拡 +//浠诲姟缂栧彿浜屽弶鏍戣妭鐐 typedef struct { BinNode leaf; UINT32 taskId; } TaskIDNode; -#define TASK_ID_COUNT 1024 +#define TASK_ID_COUNT 1024//1024涓换鍔$紪鍙 +//灏嗚妭鐐规彃鍏ヤ簩鍙夋爲鐨勫嚱鏁 extern UINT32 OsBinTreeInsert(const VOID *node, UINT32 nodeLen, BinNode **leaf, BinNode *(*GetMyBinNode)(UINT32 *nodeId), INT32 (*CompareNode)(const VOID *node1, const VOID *node2)); - +//姣旇緝涓や釜浜屽弶鏍戣妭鐐 extern INT32 OsCompareLRNode(const VOID *node1, const VOID *node2); +//閫氳繃浜屽弶鏍戣妭鐐圭殑缂栧彿寰楀埌浜屽弶鏍 extern BinNode *OsGetLRBinNode(UINT32 *nodeId); - +//姣旇緝涓や釜鍦板潃浜屽弶鏍戣妭鐐 extern INT32 OsCompareAddrNode(const VOID *node1, const VOID *node2); +//閫氳繃鍦板潃浜屽弶鏍戣妭鐐圭殑缂栧彿寰楀埌鍦板潃浜屽弶鏍 extern BinNode *OsGetAddrBinNode(UINT32 *nodeId); - +//姣旇緝涓や釜璇锋眰澶у皬浜屽弶鏍戣妭鐐 extern INT32 OsCompareReqSizeNode(const VOID *node1, const VOID *node2); +//閫氳繃璇锋眰澶у皬浜屽弶鏍戣妭鐐圭殑缂栧彿寰楀埌璇锋眰澶у皬浜屽弶鏍 extern BinNode *OsGetReqSizeBinNode(UINT32 *nodeId); - +//姣旇緝涓や釜浠诲姟缂栧彿浜屽弶鏍戣妭鐐 extern INT32 OsCompareTaskIDNode(const VOID *node1, const VOID *node2); +//閫氳繃浠诲姟缂栧彿浜屽弶鏍戣妭鐐圭殑缂栧彿寰楀埌浠诲姟缂栧彿浜屽弶鏍 extern BinNode *OsGetTaskIDBinNode(UINT32 *nodeId); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_err_pri.h b/src/kernel/base/include/los_err_pri.h index 9b44583..0755153 100644 --- a/src/kernel/base/include/los_err_pri.h +++ b/src/kernel/base/include/los_err_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//鐢ㄤ簬瀹氫箟涓浜涢敊璇鐞嗙浉鍏崇殑瀹忓拰鍑芥暟銆 #ifndef _LOS_ERR_PRI_H #define _LOS_ERR_PRI_H @@ -40,6 +40,7 @@ extern "C" { #define OS_ERR_MAGIC_WORD 0xa1b2c3f8 /* used to call the error handling function by using an error code and return the same error code. */ +//閫氳繃璋冪敤澶勭悊寮傚父鐨勯敊璇爜杩斿洖閿欒鐮 #define OS_RETURN_ERROR(errNo) do { \ (VOID)LOS_ErrHandle("os_unspecific_file", OS_ERR_MAGIC_WORD, errNo, 0, NULL); \ return errNo; \ @@ -49,12 +50,14 @@ extern "C" { * Call the error handling function by using an error code and the line number of * the erroneous line, and return the same error code. */ +//閫氳繃璋冪敤寮傚父鍙戠敓琛岀殑浣嶇疆杩斿洖閿欒鐮 #define OS_RETURN_ERROR_P2(errLine, errNo) do { \ (VOID)LOS_ErrHandle("os_unspecific_file", errLine, errNo, 0, NULL); \ return errNo; \ } while (0) /* Used to call the error handling function by using an error code. */ +//閫氳繃閿欒鐮佽繘琛岃皟鐢ㄥ鐞嗗紓甯哥殑鍑芥暟 #define OS_GOTO_ERR_HANDLER(errorNo) do { \ errNo = errorNo; \ errLine = OS_ERR_MAGIC_WORD; \ diff --git a/src/kernel/base/include/los_event_pri.h b/src/kernel/base/include/los_event_pri.h index 45c9beb..3ed390d 100644 --- a/src/kernel/base/include/los_event_pri.h +++ b/src/kernel/base/include/los_event_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟浜嗕竴浜涗笌浜嬩欢鎿嶄綔鐩稿叧鐨勭鏈夊嚱鏁板拰缁撴瀯浣撱 #ifndef _LOS_EVENT_PRI_H #define _LOS_EVENT_PRI_H @@ -38,10 +38,11 @@ extern "C" { #endif /* __cplusplus */ #ifdef LOSCFG_COMPAT_POSIX +//瀹氫箟鏃堕棿鐘舵佺殑缁撴瀯浣 typedef struct { - volatile INT32 *realValue; - INT32 value; - UINT32 clearEvent; + volatile INT32 *realValue;//鎸囧悜鐨勬槸涓涓叡浜祫婧愮殑璁℃暟鍣 + INT32 value;//鏉′欢鍙橀噺鐨勫 + UINT32 clearEvent;//闇瑕佹竻闄ょ殑浜嬩欢鏍囧織 } EventCond; extern UINT32 OsEventReadWithCond(const EventCond *cond, PEVENT_CB_S eventCB, diff --git a/src/kernel/base/include/los_exc_pri.h b/src/kernel/base/include/los_exc_pri.h index 43d5a26..93d154f 100644 --- a/src/kernel/base/include/los_exc_pri.h +++ b/src/kernel/base/include/los_exc_pri.h @@ -25,12 +25,14 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟浜嗕竴浜涗笌寮傚父澶勭悊鐩稿叧鐨勭鏈夊嚱鏁板拰瀹 +//闃叉鍚屼竴涓ご鏂囦欢琚娆″寘鍚 #ifndef _LOS_EXC_PRI_H #define _LOS_EXC_PRI_H #include "los_exc.h" + #ifdef __cplusplus #if __cplusplus extern "C" { @@ -38,17 +40,28 @@ extern "C" { #endif /* __cplusplus */ #ifdef LOSCFG_SHELL_EXCINFO_DUMP +//鐢ㄤ簬璁剧疆寮傚父淇℃伅璇诲啓鍑芥暟鐨勬寚閽堛 extern VOID OsSetExcInfoRW(LogReadWriteFunc func); extern LogReadWriteFunc OsGetExcInfoRW(VOID); +//鐢ㄤ簬璁剧疆寮傚父淇℃伅缂撳啿鍖虹殑鎸囬拡銆 extern VOID OsSetExcInfoBuf(CHAR *buf); +//鐢ㄤ簬鑾峰彇寮傚父淇℃伅缂撳啿鍖虹殑鎸囬拡銆 extern CHAR *OsGetExcInfoBuf(VOID); +//鐢ㄤ簬璁剧疆寮傚父淇℃伅鍦ㄧ紦鍐插尯涓殑鍋忕Щ閲忋 extern VOID OsSetExcInfoOffset(UINT32 offset); +//鐢ㄤ簬鑾峰彇寮傚父淇℃伅鍦ㄧ紦鍐插尯涓殑鍋忕Щ閲忋 extern UINT32 OsGetExcInfoOffset(VOID); +//鐢ㄤ簬璁剧疆寮傚父淇℃伅杞偍鍦板潃銆 extern VOID OsSetExcInfoDumpAddr(UINTPTR addr); +//鐢ㄤ簬鑾峰彇寮傚父淇℃伅杞偍鍦板潃銆 extern UINTPTR OsGetExcInfoDumpAddr(VOID); +//鐢ㄤ簬璁剧疆寮傚父淇℃伅鐨勯暱搴︺ extern VOID OsSetExcInfoLen(UINT32 len); +//鐢ㄤ簬鑾峰彇寮傚父淇℃伅鐨勯暱搴︺ extern UINT32 OsGetExcInfoLen(VOID); +//鐢ㄤ簬璁板綍寮傚父淇℃伅鐨勬椂闂存埑銆 extern VOID OsRecordExcInfoTime(VOID); +//鐢ㄤ簬灏嗘牸寮忓寲鐨勫瓧绗︿覆鍐欏叆寮傚父淇℃伅缂撳啿鍖恒 extern VOID WriteExcBufVa(const CHAR *format, va_list arg); extern VOID WriteExcInfoToBuf(const CHAR *format, ...); #endif diff --git a/src/kernel/base/include/los_hwi_pri.h b/src/kernel/base/include/los_hwi_pri.h index 257a07b..4b0ed7a 100644 --- a/src/kernel/base/include/los_hwi_pri.h +++ b/src/kernel/base/include/los_hwi_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟浜嗕竴浜涗笌纭欢涓柇澶勭悊鐩稿叧鐨勬暟鎹粨鏋勫拰鍑芥暟鎺ュ彛锛岀敤浜庢搷浣滃拰绠$悊绯荤粺涓殑纭欢涓柇銆 #ifndef _LOS_HWI_PRI_H #define _LOS_HWI_PRI_H @@ -67,9 +67,11 @@ typedef struct { } HwiControllerOps; extern const HwiControllerOps *g_hwiOps; - +//鐢ㄤ簬鍒濆鍖栫‖浠朵腑鏂 extern VOID OsHwiInit(VOID); +//鐢ㄤ簬鑾峰彇褰撳墠涓柇宓屽鐨勮鏁板硷紝鍙互鐢ㄤ簬妫鏌ュ綋鍓嶆槸鍚﹀浜庝腑鏂祵濂楃姸鎬併 extern size_t OsIrqNestingCntGet(VOID); +//鐢ㄤ簬璁剧疆涓柇宓屽鐨勮鏁板笺 extern VOID OsIrqNestingCntSet(size_t val); /** @@ -77,8 +79,9 @@ extern VOID OsIrqNestingCntSet(size_t val); * by the kernel. The handleIrq hook function MUST be registered in the interrupt controller driver layer, otherwise it * will not respond. eg: Used for arm(cortex-a/r)/arm64. */ +//涓涓眹缂栧叆鍙e嚱鏁帮紝鐢辨眹缂栦唬鐮佸湪dispatch.S涓皟鐢紝鐢ㄤ簬缁熶竴澶勭悊澶栭儴涓柇鐨勫叆鍙o紝鐢卞唴鏍告帴绠′腑鏂鐞嗘祦绋嬨 extern VOID OsIntEntry(VOID); - +//鏍规嵁涓柇鍙疯幏鍙栦腑鏂鐞嗕俊鎭殑鎸囬拡 STATIC INLINE HwiHandleInfo *OsGetHwiForm(UINT32 hwiNum) { if ((g_hwiOps == NULL) || (g_hwiOps->getHandleForm == NULL)) { @@ -86,7 +89,7 @@ STATIC INLINE HwiHandleInfo *OsGetHwiForm(UINT32 hwiNum) } return g_hwiOps->getHandleForm(hwiNum); } - +//鐢ㄤ簬鑾峰彇鎸囧畾涓柇鐨勫搷搴旇鏁板 STATIC INLINE UINT32 OsGetHwiFormCnt(UINT32 hwiNum) { HwiHandleInfo *hwiForm = OsGetHwiForm(hwiNum); @@ -96,7 +99,7 @@ STATIC INLINE UINT32 OsGetHwiFormCnt(UINT32 hwiNum) } return hwiForm->respCount; } - +//鐢ㄤ簬鑾峰彇褰撳墠姝e湪澶勭悊鐨勪腑鏂彿銆 STATIC INLINE UINT32 OsIntNumGet(VOID) { if ((g_hwiOps == NULL) || (g_hwiOps->getCurIrqNum == NULL)) { @@ -104,7 +107,7 @@ STATIC INLINE UINT32 OsIntNumGet(VOID) } return g_hwiOps->getCurIrqNum(); } - +//鐢ㄤ簬鍒ゆ柇鎸囧畾鐨勪腑鏂彿鏄惁宸茬粡娉ㄥ唽浜嗙浉搴旂殑澶勭悊鍑芥暟銆 STATIC INLINE BOOL OsIntIsRegisted(UINT32 num) { HwiHandleInfo *hwiForm = OsGetHwiForm(num); @@ -118,7 +121,7 @@ STATIC INLINE BOOL OsIntIsRegisted(UINT32 num) return (hwiForm->hook != NULL); #endif } - +//鐢ㄤ簬鑾峰彇鎸囧畾涓柇鐨勬敞鍐屽弬鏁颁俊鎭 STATIC INLINE HWI_ARG_T OsIntGetPara(UINT32 num) { HwiHandleInfo *hwiForm = OsGetHwiForm(num); @@ -128,7 +131,7 @@ STATIC INLINE HWI_ARG_T OsIntGetPara(UINT32 num) } return hwiForm->registerInfo; } - +//鐢ㄤ簬鑾峰彇涓柇鐗堟湰淇℃伅銆 STATIC INLINE CHAR *OsIntVersionGet(VOID) { if ((g_hwiOps == NULL) || (g_hwiOps->getIrqVersion == NULL)) { @@ -143,6 +146,7 @@ STATIC INLINE CHAR *OsIntVersionGet(VOID) * handleForm to this interface. * eg: Used for arm(cortex-m),xtensa,riscv. */ +//鍦ㄤ腑鏂帶鍒跺櫒椹卞姩灞傚疄鐜伴氱敤鐨勪腑鏂鐞嗗叆鍙o紝鐢ㄤ簬浼犻掍腑鏂彿鍜屽鐞嗕俊鎭粰鐩稿簲鐨勫鐞嗗嚱鏁般 extern VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *handleForm); /** @@ -151,6 +155,7 @@ extern VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *handleForm); * HwiControllerOps need to be registered. If this function is not supported, you can call the LOS_Panic interface in * the implementation of the stub function to report an error in time. */ +//鐢ㄤ簬娉ㄥ唽涓柇鎺у埗鍣ㄧ浉鍏崇殑鎿嶄綔鍑芥暟锛岄渶瑕佸湪涓柇鎺у埗鍣ㄥ垵濮嬪寲鏃惰璋冪敤銆 STATIC INLINE VOID OsHwiControllerReg(const HwiControllerOps *ops) { g_hwiOps = ops; diff --git a/src/kernel/base/include/los_membox_pri.h b/src/kernel/base/include/los_membox_pri.h index 6b64895..c7def84 100644 --- a/src/kernel/base/include/los_membox_pri.h +++ b/src/kernel/base/include/los_membox_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠剁殑浣滅敤鏄畾涔変簡涓庡唴瀛樻睜鐩稿叧鐨勭鏈夊嚱鏁板拰鏁版嵁缁撴瀯銆 #ifndef _LOS_MEMBOX_PRI_H #define _LOS_MEMBOX_PRI_H diff --git a/src/kernel/base/include/los_memory_pri.h b/src/kernel/base/include/los_memory_pri.h index fe56414..642d88e 100644 --- a/src/kernel/base/include/los_memory_pri.h +++ b/src/kernel/base/include/los_memory_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟鍐呭瓨绠$悊鐨勭鏈夋帴鍙e拰鏁版嵁缁撴瀯銆 #ifndef _LOS_MEMORY_PRI_H #define _LOS_MEMORY_PRI_H @@ -35,6 +35,8 @@ #include "los_spinlock.h" #include "los_misc_pri.h" +//鍏充簬鍐呭瓨绠$悊鐨勭鏈夋帴鍙e0鏄 + #ifdef __cplusplus #if __cplusplus extern "C" { @@ -60,6 +62,7 @@ typedef struct { struct LosSlabControlHeader slabCtrlHdr; #endif } LosMemPoolInfo; +//鐢ㄤ簬鎻忚堪鍐呭瓨姹犵殑淇℃伅锛屽寘鎷唴瀛樻睜鐨勮捣濮嬪湴鍧銆佸ぇ灏忕瓑淇℃伅銆 #elif defined(LOSCFG_KERNEL_MEM_BESTFIT_LITTLE) @@ -90,6 +93,7 @@ extern SPIN_LOCK_S g_memSpin; #define MEM_LOCK(state) LOS_SpinLockSave(&g_memSpin, &(state)) #define MEM_UNLOCK(state) LOS_SpinUnlockRestore(&g_memSpin, (state)) +//鐢ㄤ簬绯荤粺鍐呭瓨鐨勫垵濮嬪寲銆 extern UINTPTR g_sys_mem_addr_end; extern UINT32 OsMemSystemInit(UINTPTR memStart); @@ -104,11 +108,12 @@ extern UINT32 OsMemMulPoolInit(VOID *pool, UINT32 size); extern UINT32 OsMemMulPoolDeinit(const VOID *pool); extern VOID *OsMemMulPoolHeadGet(VOID); #else /* LOSCFG_MEM_MUL_POOL */ +//鐢ㄤ簬鍒濆鍖栧鍐呭瓨姹狅紝鎺ュ彈鍐呭瓨姹犵殑璧峰鍦板潃鍜屽ぇ灏忎綔涓哄弬鏁般 STATIC INLINE UINT32 OsMemMulPoolInit(VOID *pool, UINT32 size) { return LOS_OK; } - +//鐢ㄤ簬鍙嶅垵濮嬪寲澶氬唴瀛樻睜锛屾帴鍙楀唴瀛樻睜鐨勬寚閽堜綔涓哄弬鏁般 STATIC INLINE UINT32 OsMemMulPoolDeinit(const VOID *pool) { return LOS_OK; @@ -116,16 +121,21 @@ STATIC INLINE UINT32 OsMemMulPoolDeinit(const VOID *pool) #endif /* LOSCFG_MEM_MUL_POOL */ #ifdef LOSCFG_EXC_INTERACTION +//浜庡垵濮嬪寲鍐呭瓨寮傚父浜や簰锛屾帴鍙楀唴瀛樿捣濮嬪湴鍧浣滀负鍙傛暟銆 extern UINT32 OsMemExcInteractionInit(UINTPTR memStart); #endif #ifdef LOSCFG_MEM_LEAKCHECK +//鐢ㄤ簬灞曠ず宸蹭娇鐢ㄧ殑鍐呭瓨鑺傜偣淇℃伅锛屾帴鍙楀唴瀛樻睜鎸囬拡浣滀负鍙傛暟銆 extern VOID OsMemUsedNodeShow(VOID *pool); #endif - +//鐢ㄤ簬閲嶇疆鍐呭瓨姹犵殑缁撴潫鑺傜偣锛屾帴鍙楀唴瀛樻睜鎸囬拡鍜屽墠涓涓湴鍧浣滀负鍙傛暟銆 extern VOID OsMemResetEndNode(VOID *pool, UINTPTR preAddr); +//鐢ㄤ簬鎵撳嵃鍐呭瓨淇℃伅锛屾帴鍙楀唴瀛樻睜鎸囬拡浣滀负鍙傛暟銆 extern VOID OsMemInfoPrint(const VOID *pool); +//鐢ㄤ簬鎵ц鍐呭瓨妫鏌ョ殑 shell 鍛戒护锛屾帴鍙楀懡浠ゅ弬鏁颁綔涓鸿緭鍏ャ extern UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[]); +//鐢ㄤ簬鎵ц澶氶噸鍐呭瓨瀹屾暣鎬ф鏌ャ extern VOID OsMemIntegrityMultiCheck(VOID); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_memstat_pri.h b/src/kernel/base/include/los_memstat_pri.h index 2b43079..40d8131 100644 --- a/src/kernel/base/include/los_memstat_pri.h +++ b/src/kernel/base/include/los_memstat_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟浜嗕竴浜涚敤浜庡唴瀛樼粺璁$殑鏁版嵁缁撴瀯鍜屽嚱鏁版帴鍙o紝鐢ㄤ簬璺熻釜鍜岀鐞嗕换鍔′娇鐢ㄧ殑鍐呭瓨鎯呭喌銆 #ifndef _LOS_MEMSTAT_PRI_H #define _LOS_MEMSTAT_PRI_H @@ -43,19 +43,22 @@ extern "C" { #ifdef LOSCFG_MEM_TASK_STAT typedef struct { - UINT32 memUsed; - UINT32 memPeak; + UINT32 memUsed;//鍐呭瓨浣跨敤 + UINT32 memPeak;//鍐呭瓨宄板 } TaskMemUsedInfo; typedef struct { - UINT32 memTotalUsed; - UINT32 memTotalPeak; - TaskMemUsedInfo taskMemstats[TASK_NUM]; + UINT32 memTotalUsed;//鍐呭瓨浣跨敤閲 + UINT32 memTotalPeak;//鍐呭瓨浣跨敤宄板 + TaskMemUsedInfo taskMemstats[TASK_NUM];//浣跨敤鍐呭瓨鐨勪换鍔″垪琛 } Memstat; - +//鐢ㄤ簬澧炲姞浠诲姟鐨勫唴瀛樹娇鐢ㄩ噺鍜屽嘲鍊笺 extern VOID OsMemstatTaskUsedInc(Memstat *stat, UINT32 usedSize, UINT32 taskId); +//鐢ㄤ簬鍑忓皯浠诲姟鐨勫唴瀛樹娇鐢ㄩ噺鍜屽嘲鍊笺 extern VOID OsMemstatTaskUsedDec(Memstat *stat, UINT32 usedSize, UINT32 taskId); +//鐢ㄤ簬娓呴櫎浠诲姟鐨勫唴瀛樼粺璁′俊鎭 extern VOID OsMemstatTaskClear(Memstat *stat, UINT32 taskId); +//鐢ㄤ簬鑾峰彇浠诲姟鐨勫唴瀛樹娇鐢ㄧ巼銆 extern UINT32 OsMemstatTaskUsage(const Memstat *stat, UINT32 taskId); #endif @@ -63,9 +66,13 @@ extern VOID OsMemTaskClear(UINT32 taskId); extern UINT32 OsMemTaskUsage(UINT32 taskId); #ifdef LOSCFG_MEM_TASK_STAT +//澧炲姞浠诲姟鐨勫唴瀛樹娇鐢ㄩ噺鍜屽嘲鍊笺 #define OS_MEM_ADD_USED(stat, usedSize, taskId) OsMemstatTaskUsedInc(stat, usedSize, taskId) +//鍑忓皯浠诲姟鐨勫唴瀛樹娇鐢ㄩ噺鍜屽嘲鍊笺 #define OS_MEM_REDUCE_USED(stat, usedSize, taskId) OsMemstatTaskUsedDec(stat, usedSize, taskId) +//娓呴櫎浠诲姟鐨勫唴瀛樼粺璁′俊鎭 #define OS_MEM_CLEAR(taskId) OsMemTaskClear(taskId) +//鑾峰彇浠诲姟鐨勫唴瀛樹娇鐢ㄧ巼銆 #define OS_MEM_USAGE(taskId) OsMemTaskUsage(taskId) #else #define OS_MEM_ADD_USED(stat, usedSize, taskId) diff --git a/src/kernel/base/include/los_misc_pri.h b/src/kernel/base/include/los_misc_pri.h index b0a3403..041d8bd 100644 --- a/src/kernel/base/include/los_misc_pri.h +++ b/src/kernel/base/include/los_misc_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟浜嗕竴浜涚鏈夋帴鍙e拰鏁版嵁缁撴瀯锛屼富瑕佹秹鍙婁笌鍐呭瓨鐩稿叧鐨勫姛鑳藉拰璋冭瘯鍔熻兘銆 #ifndef _LOS_MISC_PRI_H #define _LOS_MISC_PRI_H @@ -36,7 +36,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//瀹氫箟浜嗕竴涓敤浜庡皢鎸囧畾鍦板潃寮濮嬬殑杩炵画鍐呭瓨瀛楄妭杩涜杞偍鐨勫嚱鏁般傚彲浠ョ敤浜庤皟璇曞拰瑙傚療鍐呭瓨涓殑鏁版嵁銆 VOID OsDumpMemByte(size_t length, UINTPTR addr); #if defined(LOSCFG_DEBUG_SEMAPHORE) || defined(LOSCFG_DEBUG_MUTEX) || defined(LOSCFG_DEBUG_QUEUE) @@ -48,13 +48,16 @@ typedef struct { } SortParam; /* Compare the size of the last access time */ +//鐢ㄤ簬鎺掑簭鏃舵瘮杈冩帶鍒跺潡鎴愬憳鐨勫ぇ灏忋 typedef BOOL (*OsCompareFunc)(const SortParam *sortParam, UINT32 left, UINT32 right); /* Get the address of the comparison member variable */ +//鐢ㄤ簬鑾峰彇鎺у埗鍧楁垚鍛樺彉閲忕殑鍦板潃銆 #define SORT_ELEM_ADDR(sortParam, index) \ ((sortParam)->buf + ((index) * (sortParam)->ctrlBlockSize) + (sortParam)->sortElemOff) /* Sort this index array. */ +//鐢ㄤ簬瀵圭储寮曟暟缁勮繘琛屾帓搴忋 extern VOID OsArraySort(UINT32 *sortArray, UINT32 start, UINT32 end, const SortParam *sortParam, OsCompareFunc compareFunc); #endif diff --git a/src/kernel/base/include/los_mp_pri.h b/src/kernel/base/include/los_mp_pri.h index ad2d5de..0359e40 100644 --- a/src/kernel/base/include/los_mp_pri.h +++ b/src/kernel/base/include/los_mp_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹氫箟浜嗕竴浜涚鏈夋帴鍙c佹暟鎹粨鏋勫拰瀹忥紝涓昏娑夊強澶氬鐞嗗櫒锛圡P锛夌浉鍏崇殑鍔熻兘銆 #ifndef _LOS_MP_PRI_H #define _LOS_MP_PRI_H @@ -56,10 +56,15 @@ typedef enum { typedef VOID (*SMP_FUNC_CALL)(VOID *args); #ifdef LOSCFG_KERNEL_SMP +//瀹氫箟浜嗕竴涓敤浜庡湪澶氬鐞嗗櫒绯荤粺涓垏鎹㈣皟搴︾洰鏍囩殑鍑芥暟銆 extern VOID LOS_MpSchedule(UINT32 target); +//瀹氫箟浜嗕竴涓敤浜庡鐞嗗澶勭悊鍣ㄥ敜閱掍簨浠剁殑鍑芥暟銆 extern VOID OsMpWakeHandler(VOID); +//瀹氫箟浜嗕竴涓敤浜庡鐞嗗澶勭悊鍣ㄨ皟搴︿簨浠剁殑鍑芥暟銆 extern VOID OsMpScheduleHandler(VOID); +//瀹氫箟浜嗕竴涓敤浜庡鐞嗗澶勭悊鍣ㄥ仠鏈轰簨浠剁殑鍑芥暟銆 extern VOID OsMpHaltHandler(VOID); +//瀹氫箟浜嗕竴涓敤浜庡垵濮嬪寲澶氬鐞嗗櫒鐩稿叧鍔熻兘鐨勫嚱鏁般 extern UINT32 OsMpInit(VOID); #else STATIC INLINE VOID LOS_MpSchedule(UINT32 target) @@ -69,7 +74,7 @@ STATIC INLINE VOID LOS_MpSchedule(UINT32 target) #endif #ifdef LOSCFG_KERNEL_SMP_CALL - +//鐢ㄤ簬鍦ㄧ洰鏍 CPU 涓婅皟鐢ㄥ嚱鏁 typedef struct { LOS_DL_LIST node; SMP_FUNC_CALL func; @@ -82,6 +87,7 @@ typedef struct { extern VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args); extern VOID OsMpFuncCallHandler(VOID); #else +//鐢ㄤ簬澶勭悊澶氬鐞嗗櫒鍑芥暟璋冪敤浜嬩欢銆 STATIC INLINE VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args) { (VOID)target; diff --git a/src/kernel/base/include/los_multipledlinkhead_pri.h b/src/kernel/base/include/los_multipledlinkhead_pri.h index 7befa0e..f8c3880 100644 --- a/src/kernel/base/include/los_multipledlinkhead_pri.h +++ b/src/kernel/base/include/los_multipledlinkhead_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠跺畾涔変簡涓涓閲嶅弻鍚戦摼琛ㄥご鐨勭鏈夋帴鍙e拰鏁版嵁缁撴瀯銆 #ifndef _LOS_MULTIPLE_DLINK_HEAD_PRI_H #define _LOS_MULTIPLE_DLINK_HEAD_PRI_H @@ -37,25 +37,30 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//琛ㄧず鏈澶х殑澶氶噸鍙屽悜閾捐〃鐨勫ぇ灏忕殑瀵规暟鍊笺 #define OS_MAX_MULTI_DLNK_LOG2 29 +//琛ㄧず鏈灏忕殑澶氶噸鍙屽悜閾捐〃鐨勫ぇ灏忕殑瀵规暟鍊笺 #define OS_MIN_MULTI_DLNK_LOG2 4 +//琛ㄧず澶氶噸鍙屽悜閾捐〃鐨勬暟閲忥紝閫氳繃鏈澶у拰鏈灏忕殑瀵规暟鍊艰绠楀緱鍒般 #define OS_MULTI_DLNK_NUM ((OS_MAX_MULTI_DLNK_LOG2 - OS_MIN_MULTI_DLNK_LOG2) + 1) +//琛ㄧず澶氶噸鍙屽悜閾捐〃澶寸殑澶у皬銆 #define OS_DLNK_HEAD_SIZE OS_MULTI_DLNK_HEAD_SIZE +//琛ㄧず澶氶噸鍙屽悜閾捐〃澶寸粨鏋勪綋鐨勫ぇ灏忋 #define OS_MULTI_DLNK_HEAD_SIZE sizeof(LosMultipleDlinkHead) - +//鐢ㄤ簬瀛樺偍澶氶噸鍙屽悜閾捐〃鐨勫ご鎸囬拡鏁扮粍銆 typedef struct { LOS_DL_LIST listHead[OS_MULTI_DLNK_NUM]; } LosMultipleDlinkHead; - +//鏍规嵁缁欏畾鐨勫ご鍦板潃鍜岄摼琛ㄨ妭鐐瑰ご鎸囬拡锛岃繑鍥炰笅涓涓閲嶉摼琛ㄧ殑澶存寚閽堛 STATIC INLINE LOS_DL_LIST *OsDLnkNextMultiHead(VOID *headAddr, LOS_DL_LIST *listNodeHead) { LosMultipleDlinkHead *head = (LosMultipleDlinkHead *)headAddr; return (&head->listHead[OS_MULTI_DLNK_NUM - 1] == listNodeHead) ? NULL : (listNodeHead + 1); } - +//瀵圭粰瀹氱殑澶村湴鍧杩涜鍒濆鍖栵紝灏嗗閲嶅弻鍚戦摼琛ㄧ殑澶存寚閽堟暟缁勪腑鐨勬墍鏈夋寚閽堢疆涓 NULL銆 extern VOID OsDLnkInitMultiHead(VOID *headAddr); +//鏍规嵁缁欏畾鐨勫ご鍦板潃鍜屽ぇ灏忥紝杩斿洖瀵瑰簲鐨勫閲嶅弻鍚戦摼琛ㄧ殑澶存寚閽堛 extern LOS_DL_LIST *OsDLnkMultiHead(VOID *headAddr, UINT32 size); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_mux_debug_pri.h b/src/kernel/base/include/los_mux_debug_pri.h index 30e49dd..6aabee6 100644 --- a/src/kernel/base/include/los_mux_debug_pri.h +++ b/src/kernel/base/include/los_mux_debug_pri.h @@ -26,6 +26,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ +/*杩欎釜澶存枃浠跺畾涔変簡涓浜涚敤浜庝簰鏂ラ攣锛坢utex锛夎皟璇曠殑鎺ュ彛鍜屽嚱鏁帮紝鍖呮嫭姝婚攣妫娴嬨佷簰鏂ラ攣鐘舵佽窡韪佷簰鏂ラ攣娉勬紡妫鏌ョ瓑銆 + 杩欎簺鎺ュ彛鍜屽嚱鏁颁富瑕佺敤浜庡紑鍙戜汉鍛樺湪璋冭瘯杩囩▼涓垎鏋愪簰鏂ラ攣鐨勪娇鐢ㄦ儏鍐碉紝甯姪鎵惧嚭娼滃湪鐨勯棶棰樺苟瑙e喅瀹冧滑銆*/ + #ifndef _LOS_MUX_DEBUG_PRI_H #define _LOS_MUX_DEBUG_PRI_H @@ -35,7 +38,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//鍒濆鍖栨閿佹娴嬫満鍒 /* Deadlock detection initialization interface */ extern UINT32 OsMuxDlockCheckInit(VOID); STATIC INLINE UINT32 OsMuxDlockCheckInitHook(VOID) @@ -46,7 +49,7 @@ STATIC INLINE UINT32 OsMuxDlockCheckInitHook(VOID) return LOS_OK; #endif } - +//鍚戞閿佹娴嬫満鍒朵腑娣诲姞浠诲姟鎸佹湁鐨勪簰鏂ラ攣淇℃伅 /* Add holding mutex lock node information */ extern VOID OsMuxDlockNodeInsert(UINT32 taskId, VOID *muxCB); STATIC INLINE VOID OsMuxDlockNodeInsertHook(UINT32 taskId, VOID *muxCB) @@ -55,6 +58,7 @@ STATIC INLINE VOID OsMuxDlockNodeInsertHook(UINT32 taskId, VOID *muxCB) OsMuxDlockNodeInsert(taskId, muxCB); #endif } +//浠庢閿佹娴嬫満鍒朵腑鍒犻櫎浠诲姟鎸佹湁鐨勪簰鏂ラ攣淇℃伅 /* Delete holding mutex lock node information */ extern VOID OsMuxDlockNodeDelete(UINT32 taskId, const VOID *muxCB); STATIC INLINE VOID OsMuxDlockNodeDeleteHook(UINT32 taskId, const VOID *muxCB) @@ -63,6 +67,7 @@ STATIC INLINE VOID OsMuxDlockNodeDeleteHook(UINT32 taskId, const VOID *muxCB) OsMuxDlockNodeDelete(taskId, muxCB); #endif } +//鏇存柊浠诲姟鏈鍚庢墽琛岀殑鏃堕棿 /* Update the last time the task was executed */ extern VOID OsTaskTimeUpdate(UINT32 taskId, UINT64 tickCount); STATIC INLINE VOID OsTaskTimeUpdateHook(UINT32 taskId, UINT64 tickCount) @@ -71,7 +76,7 @@ STATIC INLINE VOID OsTaskTimeUpdateHook(UINT32 taskId, UINT64 tickCount) OsTaskTimeUpdate(taskId, tickCount); #endif } - +//鍒濆鍖栦簰鏂ラ攣鐘舵佽窡韪満鍒 /* mutex debug initialization interface */ extern UINT32 OsMuxDbgInit(VOID); STATIC INLINE UINT32 OsMuxDbgInitHook(VOID) @@ -82,6 +87,7 @@ STATIC INLINE UINT32 OsMuxDbgInitHook(VOID) return LOS_OK; #endif } +//鏇存柊浜掓枼閿佹渶鍚庢墽琛岀殑鏃堕棿 /* Update the last time the mutex was executed */ extern VOID OsMuxDbgTimeUpdate(UINT32 muxId); STATIC INLINE VOID OsMuxDbgTimeUpdateHook(UINT32 muxId) @@ -90,6 +96,7 @@ STATIC INLINE VOID OsMuxDbgTimeUpdateHook(UINT32 muxId) OsMuxDbgTimeUpdate(muxId); #endif } +//鍦ㄥ垱寤烘垨鍒犻櫎浜掓枼閿佹椂鏇存柊浜掓枼閿佺殑鐘舵佽窡韪俊鎭 /* Update the MUX_DEBUG_CB of the mutex when created or deleted */ extern VOID OsMuxDbgUpdate(UINT32 muxID, TSK_ENTRY_FUNC creator); STATIC INLINE VOID OsMuxDbgUpdateHook(UINT32 muxId, TSK_ENTRY_FUNC creator) @@ -98,6 +105,7 @@ STATIC INLINE VOID OsMuxDbgUpdateHook(UINT32 muxId, TSK_ENTRY_FUNC creator) OsMuxDbgUpdate(muxId, creator); #endif } +//妫鏌ヤ簰鏂ラ攣鏄惁娉勬紡 /* check the leak of mutex */ extern VOID OsMutexCheck(VOID); STATIC INLINE VOID OsMutexCheckHook(VOID) diff --git a/src/kernel/base/include/los_mux_pri.h b/src/kernel/base/include/los_mux_pri.h index c2ffb83..0361b35 100644 --- a/src/kernel/base/include/los_mux_pri.h +++ b/src/kernel/base/include/los_mux_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//涓涓叧浜庝簰鏂ラ攣鐨勫唴閮ㄥ疄鐜扮殑澶存枃浠 #ifndef _LOS_MUX_PRI_H #define _LOS_MUX_PRI_H @@ -45,12 +45,13 @@ extern "C" { * Mutex base object must be the same as the first three member names of LosMuxCB, * so that pthread_mutex_t can share the kernel mutex mechanism. */ +//杩欐槸浜掓枼閿佺殑鍩烘湰鎺у埗鍧楋紝鍖呭惈浜嗕簰鏂ラ攣鐨勪竴浜涘熀鏈俊鎭 typedef struct { - LOS_DL_LIST muxList; /* Mutex linked list */ - LosTaskCB *owner; /* The current thread that is locking a mutex */ - UINT16 muxCount; /* Times of locking a mutex */ + LOS_DL_LIST muxList;//杩炴帴鍒楄〃 /* Mutex linked list */ + LosTaskCB *owner; //浜掓枼閿佺殑鎷ユ湁鑰 /* The current thread that is locking a mutex */ + UINT16 muxCount; //琚攣瀹氱殑娆℃暟 /* Times of locking a mutex */ } MuxBaseCB; - +//杩欐槸浜掓枼閿佺殑鎺у埗鍧楋紝鍖呭惈浜嗘洿澶氱殑浜掓枼閿佷俊鎭 typedef struct { LOS_DL_LIST muxList; /* Mutex linked list */ LosTaskCB *owner; /* The current thread that is locking a mutex */ @@ -60,21 +61,29 @@ typedef struct { } LosMuxCB; /* Mutex global array address, which can be obtained by using a handle ID. */ +//鍏ㄥ眬鍙橀噺锛氳繖鏄竴涓簰鏂ラ攣鐨勫叏灞鏁扮粍鍦板潃锛屽彲浠ラ氳繃浜掓枼閿佺殑 ID 鏉ヨ幏鍙栧搴旂殑浜掓枼閿佸璞° extern LosMuxCB *g_allMux; /* COUNT | INDEX split bit */ #define MUX_SPLIT_BIT 16 /* Set the mutex id */ +//璁剧疆浜掓枼閿佺殑 ID #define SET_MUX_ID(count, muxId) (((count) << MUX_SPLIT_BIT) | (muxId)) +//鏍规嵁浜掓枼閿佺殑 ID 鑾峰彇绱㈠紩 #define GET_MUX_INDEX(muxId) ((muxId) & ((1U << MUX_SPLIT_BIT) - 1)) +//鏍规嵁浜掓枼閿佺殑 ID 鑾峰彇璁℃暟鍊 #define GET_MUX_COUNT(muxId) ((muxId) >> MUX_SPLIT_BIT) /* Obtain the pointer to a mutex object of the mutex that has a specified handle. */ +//鏍规嵁浜掓枼閿佺殑 ID 鑾峰彇瀵瑰簲鐨勪簰鏂ラ攣瀵硅薄鎸囬拡 #define GET_MUX(muxId) (((LosMuxCB *)g_allMux) + GET_MUX_INDEX(muxId)) +//鍒濆鍖栦簰鏂ラ攣 extern UINT32 OsMuxInit(VOID); +//鎵ц浜掓枼閿佺殑绛夊緟鎿嶄綔 extern UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UINT32 timeout, UINT32 *intSave); +//鎵ц浜掓枼閿佺殑閲婃斁鎿嶄綔 extern UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted); #ifdef __cplusplus #if __cplusplus diff --git a/src/kernel/base/include/los_percpu_pri.h b/src/kernel/base/include/los_percpu_pri.h index bc8f0fa..340ed0f 100644 --- a/src/kernel/base/include/los_percpu_pri.h +++ b/src/kernel/base/include/los_percpu_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠跺畾涔変簡鍏充簬姣忎釜CPU鐨勭鏈夋暟鎹粨鏋勶紝杩欎釜缁撴瀯浣撳瓨鍌ㄤ簡涓庢瘡涓 CPU 鐩稿叧鐨勪竴浜涗俊鎭 #ifndef _LOS_PERCPU_PRI_H #define _LOS_PERCPU_PRI_H @@ -47,35 +47,34 @@ typedef enum { CPU_EXC /* cpu in the exc */ } ExcFlag; #endif - +//鎺掑簭閾捐〃鐨勫睘鎬х粨鏋勪綋锛岀敤浜庤〃绀轰换鍔¢摼琛ㄥ拰杞欢瀹氭椂鍣ㄩ摼琛 typedef struct { SortLinkAttribute taskSortLink; /* task sort link */ #ifdef LOSCFG_BASE_CORE_SWTMR SortLinkAttribute swtmrSortLink; /* swtmr sort link */ #endif - UINT32 idleTaskId; /* idle task id */ - UINT32 taskLockCnt; /* task lock flag */ - UINT32 swtmrHandlerQueue; /* software timer timeout queue id */ - UINT32 swtmrTaskId; /* software timer task id */ - - UINT32 schedFlag; /* pending scheduler flag */ + UINT32 idleTaskId;//绌洪棽浠诲姟鐨勪换鍔 ID /* idle task id */ + UINT32 taskLockCnt;//浠诲姟閿佽鏁帮紝鐢ㄤ簬鏍囪浠诲姟鏄惁琚攣瀹 /* task lock flag */ + UINT32 swtmrHandlerQueue;//杞欢瀹氭椂鍣ㄧ殑瓒呮椂闃熷垪 ID /* software timer timeout queue id */ + UINT32 swtmrTaskId;//杞欢瀹氭椂鍣ㄤ换鍔$殑 ID /* software timer task id */ + UINT32 schedFlag;//璋冨害鏍囧織锛岀敤浜庤〃绀烘槸鍚﹂渶瑕佽繘琛岃皟搴 /* pending scheduler flag */ #ifdef LOSCFG_KERNEL_SMP - UINT32 excFlag; /* cpu halt or exc flag */ + UINT32 excFlag;//CPU 寮傚父鏍囧織锛岀敤浜庤〃绀 CPU 鐨勮繍琛岀姸鎬侊紝鍖呮嫭杩愯銆佷紤鐪犲拰寮傚父鐘舵 /* cpu halt or exc flag */ #ifdef LOSCFG_KERNEL_SMP_CALL - LOS_DL_LIST funcLink; /* mp function call link */ + LOS_DL_LIST funcLink;//澶氬鐞嗗櫒鍑芥暟璋冪敤閾捐〃锛岀敤浜庡澶勭悊鍣ㄩ棿鐨勫嚱鏁拌皟鐢 /* mp function call link */ #endif #endif } Percpu; /* the kernel per-cpu structure */ extern Percpu g_percpu[LOSCFG_KERNEL_CORE_NUM]; - +//鐢ㄤ簬鑾峰彇褰撳墠CPU STATIC INLINE Percpu *OsPercpuGet(VOID) { return &g_percpu[ArchCurrCpuid()]; } - +//鐢ㄤ簬鑾峰彇鎸囧畾CPU鐨凱ercpu缁撴瀯浣撴寚閽 STATIC INLINE Percpu *OsPercpuGetByID(UINT32 cpuid) { return &g_percpu[cpuid]; diff --git a/src/kernel/base/include/los_printf_pri.h b/src/kernel/base/include/los_printf_pri.h index b150765..0dd3b03 100644 --- a/src/kernel/base/include/los_printf_pri.h +++ b/src/kernel/base/include/los_printf_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//鍏充簬鎵撳嵃鍑芥暟鐨勭鏈夊ご鏂囦欢 #ifndef _LOS_PRINTF_PRI_H #define _LOS_PRINTF_PRI_H @@ -36,13 +36,16 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//鍦ㄦ帶鍒跺彴涓婃墦鍗版牸寮忓寲瀛楃涓 extern VOID ConsoleVprintf(const CHAR *fmt, va_list ap); +//鍦ㄤ覆鍙d笂鎵撳嵃鏍煎紡鍖栧瓧绗︿覆 extern VOID UartVprintf(const CHAR *fmt, va_list ap); +//鎵撳嵃寮傚父淇℃伅 extern VOID PrintExcInfo(const CHAR *fmt, ...); - +//鎵撳嵃鍐呮牳璋冭瘯淇℃伅 extern VOID LkDprintf(const CHAR *fmt, va_list ap); #ifdef LOSCFG_SHELL_DMESG +//鎵撳嵃绯荤粺鏃ュ織淇℃伅 extern VOID DmesgPrintf(const CHAR *fmt, va_list ap); #endif diff --git a/src/kernel/base/include/los_priqueue_pri.h b/src/kernel/base/include/los_priqueue_pri.h index 79cd22d..eecc647 100644 --- a/src/kernel/base/include/los_priqueue_pri.h +++ b/src/kernel/base/include/los_priqueue_pri.h @@ -25,7 +25,8 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*杩欎釜澶存枃浠跺畾涔変簡浼樺厛绾ч槦鍒楃殑鐩稿叧鎿嶄綔鍑芥暟锛 +鍖呮嫭鍒濆鍖栦紭鍏堢骇闃熷垪銆佹彃鍏ラ」鐩埌浼樺厛绾ч槦鍒椼佷粠浼樺厛绾ч槦鍒椾腑鍒犻櫎椤圭洰銆佽幏鍙栧叿鏈夋渶楂樹紭鍏堢骇鐨勯」鐩瓑*/ #ifndef _LOS_PRIQUEUE_PRI_H #define _LOS_PRIQUEUE_PRI_H @@ -57,6 +58,7 @@ extern "C" { * @see none. * @since Huawei LiteOS V100R001C00 */ +//鍒濆鍖栦紭鍏堢骇闃熷垪 extern UINT32 OsPriQueueInit(VOID); /** @@ -79,6 +81,7 @@ extern UINT32 OsPriQueueInit(VOID); * @see OsPriQueueDequeue. * @since Huawei LiteOS V100R001C00 */ +//鏍规嵁椤圭洰鐨勪紭鍏堢骇灏嗛」鐩彃鍏ュ埌浼樺厛绾ч槦鍒椾腑 extern VOID OsPriQueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority); /** @@ -99,6 +102,7 @@ extern VOID OsPriQueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority); * @see OsPriQueueEnqueue. * @since Huawei LiteOS V100R001C00 */ +//浠庝紭鍏堢骇闃熷垪涓垹闄や竴涓」鐩 extern VOID OsPriQueueDequeue(LOS_DL_LIST *priqueueItem); /** @@ -120,6 +124,7 @@ extern VOID OsPriQueueDequeue(LOS_DL_LIST *priqueueItem); * @see none. * @since Huawei LiteOS V100R001C00 */ +//鑾峰彇浼樺厛绾ч槦鍒椾腑鍏锋湁鏈楂樹紭鍏堢骇鐨勯」鐩 extern LOS_DL_LIST *OsPriQueueTop(VOID); /** @@ -140,6 +145,7 @@ extern LOS_DL_LIST *OsPriQueueTop(VOID); * @see none. * @since Huawei LiteOS V100R001C00 */ +//鑾峰彇鍏锋湁鎸囧畾浼樺厛绾х殑椤圭洰鏁伴噺 extern UINT32 OsPriQueueSize(UINT32 priority); /** @@ -159,6 +165,7 @@ extern UINT32 OsPriQueueSize(UINT32 priority); * @see none. * @since Huawei LiteOS V100R001C00 */ +//鑾峰彇浼樺厛绾ч槦鍒椾腑椤圭洰鐨勬绘暟 extern UINT32 OsPriQueueTotalSize(VOID); /** @@ -181,6 +188,7 @@ extern UINT32 OsPriQueueTotalSize(VOID); * @see OsPriQueueDequeue. * @since Huawei LiteOS V100R001C00 */ +//鏍规嵁椤圭洰鐨勪紭鍏堢骇灏嗛」鐩彃鍏ュ埌浼樺厛绾ч槦鍒楃殑澶撮儴 extern VOID OsPriQueueEnqueueHead(LOS_DL_LIST *priqueueItem, UINT32 priority); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_queue_debug_pri.h b/src/kernel/base/include/los_queue_debug_pri.h index 4186e09..806239a 100644 --- a/src/kernel/base/include/los_queue_debug_pri.h +++ b/src/kernel/base/include/los_queue_debug_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠舵彁渚涗簡閽堝闃熷垪璋冭瘯鐨勭浉鍏冲嚱鏁板0鏄 #ifndef _LOS_QUEUE_DEBUG_PRI_H #define _LOS_QUEUE_DEBUG_PRI_H @@ -40,7 +40,9 @@ extern "C" { #endif /* __cplusplus */ /* queue debug initialization interface */ +//闃熷垪璋冭瘯鍒濆鍖栨帴鍙 extern UINT32 OsQueueDbgInit(VOID); +//闃熷垪璋冭瘯鍒濆鍖栫殑閽╁瓙鍑芥暟锛屾牴鎹厤缃槸鍚﹀紑鍚槦鍒楄皟璇曞姛鑳芥潵璋冪敤OsQueueDbgInit STATIC INLINE UINT32 OsQueueDbgInitHook(VOID) { #ifdef LOSCFG_DEBUG_QUEUE @@ -50,7 +52,9 @@ STATIC INLINE UINT32 OsQueueDbgInitHook(VOID) #endif } /* Update the last time the queue was executed */ +//鏇存柊闃熷垪涓婃鎵ц鐨勬椂闂 extern VOID OsQueueDbgTimeUpdate(UINT32 queueId); +//鏇存柊闃熷垪鎵ц鏃堕棿鐨勯挬瀛愬嚱鏁 STATIC INLINE VOID OsQueueDbgTimeUpdateHook(UINT32 queueId) { #ifdef LOSCFG_DEBUG_QUEUE @@ -58,7 +62,9 @@ STATIC INLINE VOID OsQueueDbgTimeUpdateHook(UINT32 queueId) #endif } /* Update the task entry of the queue debug info when created or deleted */ +//褰撻槦鍒楄鍒涘缓鎴栧垹闄ゆ椂锛屾洿鏂伴槦鍒楄皟璇曚俊鎭腑鐨勪换鍔″叆鍙d俊鎭 extern VOID OsQueueDbgUpdate(UINT32 queueId, TSK_ENTRY_FUNC entry); +//鏂伴槦鍒楄皟璇曚俊鎭殑閽╁瓙鍑芥暟 STATIC INLINE VOID OsQueueDbgUpdateHook(UINT32 queueId, TSK_ENTRY_FUNC entry) { #ifdef LOSCFG_DEBUG_QUEUE @@ -66,7 +72,9 @@ STATIC INLINE VOID OsQueueDbgUpdateHook(UINT32 queueId, TSK_ENTRY_FUNC entry) #endif } /* check the leak of queue */ +//妫鏌ラ槦鍒楀唴瀛樻硠婕 extern VOID OsQueueCheck(VOID); +//妫鏌ラ槦鍒楀唴瀛樻硠婕忕殑閽╁瓙鍑芥暟 STATIC INLINE VOID OsQueueCheckHook(VOID) { #ifdef LOSCFG_DEBUG_QUEUE diff --git a/src/kernel/base/include/los_queue_pri.h b/src/kernel/base/include/los_queue_pri.h index 8f1674a..5a5b13a 100644 --- a/src/kernel/base/include/los_queue_pri.h +++ b/src/kernel/base/include/los_queue_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠跺畾涔変簡绉佹湁闃熷垪鐩稿叧鐨勪竴浜涚粨鏋勪綋銆佸畯鍜屽嚱鏁板0鏄 #ifndef _LOS_QUEUE_PRI_H #define _LOS_QUEUE_PRI_H @@ -42,12 +42,12 @@ typedef enum { OS_QUEUE_WRITE = 1, OS_QUEUE_N_RW = 2 } QueueReadWrite; - +//鏋氫妇绫诲瀷锛屽垎鍒〃绀洪槦鍒楃殑璇诲啓鎿嶄綔鍜岄槦鍒楀ご灏炬搷浣 typedef enum { OS_QUEUE_HEAD = 0, OS_QUEUE_TAIL = 1 } QueueHeadTail; - +//鐢ㄤ簬鐢熸垚鎴栬幏鍙栭槦鍒楁搷浣滅被鍨嬪拰璇诲啓绫诲瀷 #define OS_QUEUE_OPERATE_TYPE(ReadOrWrite, HeadOrTail) (((UINT32)(HeadOrTail) << 1) | (ReadOrWrite)) #define OS_QUEUE_READ_WRITE_GET(type) ((type) & 0x01U) #define OS_QUEUE_READ_HEAD (OS_QUEUE_READ | (OS_QUEUE_HEAD << 1)) @@ -73,6 +73,7 @@ typedef enum { #define GET_QUEUE_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosQueueCB, readWriteList[OS_QUEUE_WRITE]) /* Queue information block structure */ +//闃熷垪淇℃伅鍧楃粨鏋勪綋锛屽寘鍚簡闃熷垪鐨勫悇绉嶅睘鎬у拰鐘舵佷俊鎭 typedef struct { UINT8 *queueHandle; /* Pointer to a queue handle */ UINT8 queueState; /* state */ @@ -88,12 +89,16 @@ typedef struct { } LosQueueCB; /* Queue information control block */ +//鍏ㄥ眬鍙橀噺锛屾寚鍚戞墍鏈夐槦鍒椾俊鎭潡鐨勮捣濮嬪湴鍧 extern LosQueueCB *g_allQueue; /* alloc a stationary memory for a mail according to queueId */ +//鐢ㄤ簬鍦ㄦ寚瀹氱殑鍐呭瓨姹犱腑涓洪偖浠跺垎閰嶅唴瀛 extern VOID *OsQueueMailAlloc(UINT32 queueId, VOID *mailPool, UINT32 timeout); /* free a stationary memory for a mail according to queueId. */ +//閲婃斁閭欢鍗犵敤鐨勫唴瀛 extern UINT32 OsQueueMailFree(UINT32 queueId, VOID *mailPool, VOID *mailMem); +//鍒楀垵濮嬪寲鍑芥暟锛岀敤浜庡垵濮嬪寲闃熷垪姹 extern UINT32 OsQueueInit(VOID); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_sched_debug_pri.h b/src/kernel/base/include/los_sched_debug_pri.h index 7e28ae5..2188c24 100644 --- a/src/kernel/base/include/los_sched_debug_pri.h +++ b/src/kernel/base/include/los_sched_debug_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠跺畾涔変簡璋冨害鍣ㄧ浉鍏崇殑涓浜涚粨鏋勪綋鍜屽嚱鏁板0鏄 #ifndef __LOS_SCHED_DEBUG_PRI_H #define __LOS_SCHED_DEBUG_PRI_H @@ -34,19 +34,19 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//琛ㄧず鍗曚釜CPU鐨勮繍琛屾椂闂村拰涓婁笅鏂囧垏鎹㈡鏁 typedef struct { UINT64 runtime; UINT32 contexSwitch; } SchedPercpu; - +//琛ㄧず鏁翠釜绯荤粺鐨勮皟搴︾粺璁′俊鎭 typedef struct { - UINT64 startRuntime; - UINT64 allRuntime; - UINT32 allContextSwitch; - SchedPercpu schedPercpu[LOSCFG_KERNEL_CORE_NUM]; + UINT64 startRuntime;//寮濮嬭繍琛岀殑鏃堕棿 + UINT64 allRuntime;//鎵鏈塁PU鐨勬诲叡杩愯鏃堕棿 + UINT32 allContextSwitch;//涓婁笅鏂囧垏鎹㈡鏁 + SchedPercpu schedPercpu[LOSCFG_KERNEL_CORE_NUM];//姣忎釜CPU鐨勫叿浣撴儏鍐 } SchedStat; - +//鐢ㄤ簬缁熻涓柇澶勭悊鐨勬椂闂村拰娆℃暟 extern VOID OsHwiStatistics(size_t intNum); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_sched_pri.h b/src/kernel/base/include/los_sched_pri.h index e5ae61d..5ea0138 100644 --- a/src/kernel/base/include/los_sched_pri.h +++ b/src/kernel/base/include/los_sched_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠跺畾涔変簡璋冨害鍣ㄧ浉鍏崇殑涓浜涚粨鏋勪綋鍜屽嚱鏁板0鏄 #ifndef _LOS_SCHED_PRI_H #define _LOS_SCHED_PRI_H @@ -37,21 +37,22 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//琛ㄧず浠诲姟璋冨害鏍囧織浣嶏紝姣忎釜浣嶄唬琛ㄤ竴涓牳蹇冿紝鐢ㄤ簬闃叉鍦∣SStartToRun涔嬪墠杩涜鍐呮牳璋冨害 extern UINT32 g_taskScheduled; /* * Schedule flag, one bit represents one core. * This flag is used to prevent kernel scheduling before OSStartToRun. */ +//璁剧疆瀵瑰簲鏍稿績鐨勮皟搴︽爣蹇椾綅 #define OS_SCHEDULER_SET(cpuid) do { \ g_taskScheduled |= (1U << (cpuid)); \ } while (0); - +//娓呴櫎瀵瑰簲鏍稿績鐨勮皟搴︽爣蹇椾綅 #define OS_SCHEDULER_CLR(cpuid) do { \ g_taskScheduled &= ~(1U << (cpuid)); \ } while (0); - +//鍒ゆ柇褰撳墠鏍稿績鐨勮皟搴︽爣蹇椾綅鏄惁婵娲 #define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid())) typedef enum { @@ -60,6 +61,7 @@ typedef enum { } SchedFlag; /* Check if preemptable with counter flag */ +//鐢ㄤ簬鍒ゆ柇褰撳墠浠诲姟鏄惁鍙互琚姠鍗 STATIC INLINE BOOL OsPreemptable(VOID) { /* @@ -76,7 +78,7 @@ STATIC INLINE BOOL OsPreemptable(VOID) LOS_IntRestore(intSave); return preemptable; } - +//鐢ㄤ簬鍒ゆ柇褰撳墠浠诲姟鏄惁鍙互鍦ㄨ皟搴﹁繃绋嬩腑琚姠鍗 STATIC INLINE BOOL OsPreemptableInSched(VOID) { BOOL preemptable = FALSE; @@ -104,6 +106,7 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID) * Current task needs to already be in the right state or the right * queues it needs to be in. */ +//閫夋嫨涓嬩竴涓换鍔″苟鍒囨崲鍒板畠 extern VOID OsSchedResched(VOID); /* @@ -111,12 +114,14 @@ extern VOID OsSchedResched(VOID); * try to do the schedule. However, the schedule won't be definitely * taken place while there're no other higher priority tasks or locked. */ +//灏嗗綋鍓嶄换鍔℃斁鍥炲氨缁槦鍒楋紝骞跺皾璇曡繘琛岃皟搴 extern VOID OsSchedPreempt(VOID); /* * Just like OsSchedPreempt, except this function will do the OS_INT_ACTIVE * check, in case the schedule taken place in the middle of an interrupt. */ +//瑙﹀彂璋冨害锛屽鏋滃湪涓柇涓垯璁剧疆璋冨害鏍囧織浣 STATIC INLINE VOID LOS_Schedule(VOID) { if (OS_INT_ACTIVE) { @@ -138,6 +143,7 @@ STATIC INLINE VOID LOS_Schedule(VOID) * This API is used to check time slices. If the number of Ticks equals to the time for task switch, * tasks are switched. Otherwise, the Tick counting continues. */ +//妫鏌ユ椂闂寸墖锛屽鏋滄弧瓒充换鍔″垏鎹㈢殑鏉′欢鍒欒繘琛屽垏鎹 extern VOID OsTimesliceCheck(VOID); #endif diff --git a/src/kernel/base/include/los_sem_debug_pri.h b/src/kernel/base/include/los_sem_debug_pri.h index 2b43684..8b8a7e1 100644 --- a/src/kernel/base/include/los_sem_debug_pri.h +++ b/src/kernel/base/include/los_sem_debug_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠跺畾涔変簡涓浜涚敤浜庤皟璇曚俊鍙烽噺鐨勬帴鍙e拰鍑芥暟澹版槑 #ifndef _LOS_SEM_DEBUG_PRI_H #define _LOS_SEM_DEBUG_PRI_H @@ -39,7 +39,9 @@ extern "C" { #endif /* __cplusplus */ /* semaphore debug initialization interface */ +//淇″彿閲忚皟璇曞垵濮嬪寲鎺ュ彛 extern UINT32 OsSemDbgInit(VOID); +//鏇存柊淇″彿閲忔渶鍚庝竴娆℃墽琛岀殑鏃堕棿 STATIC INLINE UINT32 OsSemDbgInitHook(VOID) { #ifdef LOSCFG_DEBUG_SEMAPHORE @@ -49,6 +51,7 @@ STATIC INLINE UINT32 OsSemDbgInitHook(VOID) #endif } /* Update the last time the semaphore was executed */ +//鏇存柊淇″彿閲忔渶鍚庝竴娆℃墽琛岀殑鏃堕棿 extern VOID OsSemDbgTimeUpdate(UINT32 semId); STATIC INLINE VOID OsSemDbgTimeUpdateHook(UINT32 semId) { @@ -58,6 +61,7 @@ STATIC INLINE VOID OsSemDbgTimeUpdateHook(UINT32 semId) return; } /* Update the SEM_DEBUG_CB of the semaphore when created or deleted */ +//鍦ㄥ垱寤烘垨鍒犻櫎淇″彿閲忔椂鏇存柊SEM_DEBUG_CB鐨勪俊鎭 extern VOID OsSemDbgUpdate(UINT32 semID, TSK_ENTRY_FUNC creator, UINT16 count); STATIC INLINE VOID OsSemDbgUpdateHook(UINT32 semId, TSK_ENTRY_FUNC creator, UINT16 count) { @@ -67,6 +71,7 @@ STATIC INLINE VOID OsSemDbgUpdateHook(UINT32 semId, TSK_ENTRY_FUNC creator, UINT return; } /* get the full data of SEM_DFX_CB */ +//鍙朣EM_DFX_CB鐨勫畬鏁存暟鎹 extern UINT32 OsSemInfoGetFullData(VOID); STATIC INLINE VOID OsSemInfoGetFullDataHook(VOID) { diff --git a/src/kernel/base/include/los_sem_pri.h b/src/kernel/base/include/los_sem_pri.h index de3a5bb..ba40aec 100644 --- a/src/kernel/base/include/los_sem_pri.h +++ b/src/kernel/base/include/los_sem_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠跺畾涔変簡涓浜涘叧浜庝俊鍙烽噺鐨勬暟鎹粨鏋勫拰鍑芥暟澹版槑锛岀敤浜庝俊鍙烽噺鐨勬帶鍒跺拰绠$悊銆 #ifndef _LOS_SEM_PRI_H #define _LOS_SEM_PRI_H @@ -38,24 +38,28 @@ extern "C" { #endif /* __cplusplus */ /* Semaphore control structure. */ +//淇″彿閲忔帶鍒跺潡鐨勬暟鎹粨鏋 typedef struct { - UINT8 semStat; /* Semaphore state, enum LosSemState */ - UINT8 semType; /* Semaphore Type, enum LosSemType */ - UINT16 semCount; /* number of available semaphores */ - UINT32 semId; /* Semaphore control structure ID, COUNT(UINT16)|INDEX(UINT16) */ + UINT8 semStat;//淇″彿閲忕殑鐘舵 /* Semaphore state, enum LosSemState */ + UINT8 semType;//淇″彿閲忕殑绫诲瀷 /* Semaphore Type, enum LosSemType */ + UINT16 semCount;//淇″彿閲忓彲鐢ㄦ暟閲 /* number of available semaphores */ + UINT32 semId;//淇″彿閲廔D /* Semaphore control structure ID, COUNT(UINT16)|INDEX(UINT16) */ LOS_DL_LIST semList; /* List of tasks that are waiting on a semaphore */ } LosSemCB; /* Semaphore type */ +//淇″彿閲忕被鍨嬬殑鏋氫妇鍊硷細鍖呮嫭璁℃暟淇″彿閲忓拰浜岃繘鍒朵俊鍙烽噺 enum { OS_SEM_COUNTING, /* The semaphore is a counting semaphore which max count is LOS_SEM_COUNT_MAX */ OS_SEM_BINARY, /* The semaphore is a binary semaphore which max count is OS_SEM_BINARY_COUNT_MAX */ }; /* Max count of binary semaphores */ +//浜岃繘鍒朵俊鍙烽噺鐨勬渶澶ц鏁板 #define OS_SEM_BINARY_COUNT_MAX 1 /* Semaphore information control block */ +//淇″彿閲忎俊鎭帶鍒跺潡鐨勫叏灞鎸囬拡 extern LosSemCB *g_allSem; #define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList) @@ -75,6 +79,7 @@ extern LosSemCB *g_allSem; /* This API is used to create a semaphore control structure according to the initial number of available semaphores * specified by count and return the ID of this semaphore control structure. */ +鐢ㄤ簬鏍规嵁鍒濆鍙敤淇″彿閲忕殑鏁伴噺鍒涘缓淇″彿閲忔帶鍒剁粨鏋勭殑鍑芥暟 extern UINT32 OsSemInit(VOID); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_slab_pri.h b/src/kernel/base/include/los_slab_pri.h index 24c8b94..e7c37e7 100644 --- a/src/kernel/base/include/los_slab_pri.h +++ b/src/kernel/base/include/los_slab_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠舵槸鎿嶄綔绯荤粺涓叧浜 Slab 鍐呭瓨鍒嗛厤鐨勫簳灞傚疄鐜板拰鎺ュ彛澹版槑 /** * @defgroup los_slab Slab * @ingroup kernel @@ -53,7 +53,7 @@ extern "C" { /* max slab block size */ #define SLAB_MEM_MAX_SIZE (SLAB_MEM_CALSS_STEP_SIZE << (SLAB_MEM_COUNT - 1)) - +//鎻忚堪 Slab 鍐呭瓨鍒嗛厤鍣ㄧ姸鎬佺殑缁撴瀯浣 typedef struct tagLosSlabStatus { UINT32 totalSize; UINT32 usedSize; @@ -61,13 +61,13 @@ typedef struct tagLosSlabStatus { UINT32 allocCount; UINT32 freeCount; } LosSlabStatus; - +//Slab 鍧楃殑鑺傜偣缁撴瀯浣 typedef struct tagOsSlabBlockNode { UINT16 magic; UINT8 blkSz; UINT8 recordId; } OsSlabBlockNode; - +//鍘熷瓙浣嶅浘缁撴瀯浣擄紝鐢ㄤ簬琛ㄧず Slab 鍐呭瓨鍒嗛厤鍣ㄤ腑鐨勪綅鍥 struct AtomicBitset { UINT32 numBits; UINT32 words[0]; @@ -144,25 +144,25 @@ extern UINT32 OsSlabGetMaxFreeBlkSize(const VOID *pool); extern VOID *OsSlabCtrlHdrGet(const VOID *pool); #else /* !LOSCFG_KERNEL_MEM_SLAB_EXTENTION */ - +//鍒濆鍖 Slab 鍐呭瓨姹 STATIC INLINE VOID OsSlabMemInit(VOID *pool, UINT32 size) { } - +//閿姣 Slab 鍐呭瓨姹 STATIC INLINE VOID OsSlabMemDeinit(VOID *pool) { } - +//浠 Slab 鍐呭瓨姹犱腑鍒嗛厤鍐呭瓨 STATIC INLINE VOID *OsSlabMemAlloc(VOID *pool, UINT32 size) { return NULL; } - +//閲婃斁 Slab 鍐呭瓨姹犱腑鐨勫唴瀛 STATIC INLINE BOOL OsSlabMemFree(VOID *pool, VOID *ptr) { return FALSE; } - +//妫鏌ユ寚閽堟槸鍚﹀睘浜 Slab 鍐呭瓨姹 STATIC INLINE UINT32 OsSlabMemCheck(const VOID *pool, const VOID *ptr) { return (UINT32)-1; diff --git a/src/kernel/base/include/los_sortlink_pri.h b/src/kernel/base/include/los_sortlink_pri.h index 6faeaeb..1f2b66a 100644 --- a/src/kernel/base/include/los_sortlink_pri.h +++ b/src/kernel/base/include/los_sortlink_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//涓涓敤浜庢搷浣滄帓搴忛摼琛紙SortLink锛夌殑绉佹湁澶存枃浠躲 #ifndef _LOS_SORTLINK_PRI_H #define _LOS_SORTLINK_PRI_H @@ -118,13 +118,17 @@ typedef struct { UINT16 cursor; UINT16 reserved; } SortLinkAttribute; - +//鍒濆鍖栨帓搴忛摼琛 extern UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader); +//涓涓妭鐐规坊鍔犲埌鎺掑簭閾捐〃涓 extern VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList); +//浠庢帓搴忛摼琛ㄤ腑鍒犻櫎涓涓妭鐐 extern VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList); +//鑾峰彇涓嬩竴涓埌鏈熸椂闂 extern UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader); +//鑾峰彇鐩爣鑺傜偣鐨勫埌鏈熸椂闂 extern UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader, - const SortLinkList *targetSortList); +//鏇存柊鍒版湡鏃堕棿 const SortLinkList *targetSortList); extern VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_stackinfo_pri.h b/src/kernel/base/include/los_stackinfo_pri.h index 4d9c9ae..0642106 100644 --- a/src/kernel/base/include/los_stackinfo_pri.h +++ b/src/kernel/base/include/los_stackinfo_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//涓涓敤浜庡鐞嗗爢鏍堜俊鎭殑绉佹湁澶存枃浠 #ifndef _LOS_STACK_INFO_PRI_H #define _LOS_STACK_INFO_PRI_H @@ -37,20 +37,25 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//鍫嗘爤淇℃伅缁撴瀯浣 typedef struct { - VOID *stackTop; - UINT32 stackSize; - CHAR *stackName; + VOID *stackTop;//鍫嗘爤鐨勯《閮 + UINT32 stackSize;//鍫嗘爤鐨勫ぇ灏 + CHAR *stackName;//鍫嗘爤鐨勫悕绉 } StackInfo; - +//琛ㄧず鏃犳晥鐨勬按浣嶇嚎鍊 #define OS_INVALID_WATERLINE 0xFFFFFFFF +//浜庢鏌ュ爢鏍堥《閮ㄧ殑榄旀湳瀛楁槸鍚︽湁鏁堢殑瀹忓畾涔 #define OS_STACK_MAGIC_CHECK(topstack) (*(UINTPTR *)(topstack) == OS_STACK_MAGIC_WORD) /* 1:magic valid 0:unvalid */ - +//鐢ㄤ簬寮傚父鏃惰幏鍙栧爢鏍堜俊鎭殑鍑芥暟 extern VOID OsExcStackInfo(VOID); +//鐢ㄤ簬娉ㄥ唽寮傚父鏃惰幏鍙栫殑鍫嗘爤淇℃伅鐨勫嚱鏁 extern VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum); +//鐢ㄤ簬鍒濆鍖栧爢鏍堢殑鍑芥暟 extern VOID OsStackInit(VOID *stacktop, UINT32 stacksize); +//鐢ㄤ簬鑾峰彇鍫嗘爤鐨勬按浣嶇嚎鍜屼娇鐢ㄥ嘲鍊肩殑鍑芥暟 extern UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed); +//鐢ㄤ簬鑾峰彇鍫嗘爤淇℃伅鐨勫嚱鏁 extern VOID OsGetStackInfo(const StackInfo **stackInfo, UINT32 *stackNum); #ifdef __cplusplus diff --git a/src/kernel/base/include/los_swtmr_pri.h b/src/kernel/base/include/los_swtmr_pri.h index 39f64a3..791e096 100644 --- a/src/kernel/base/include/los_swtmr_pri.h +++ b/src/kernel/base/include/los_swtmr_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//涓涓敤浜庡疄鐜拌蒋浠跺畾鏃跺櫒鐨勭鏈夊ご鏂囦欢銆 #ifndef _LOS_SWTMR_PRI_H #define _LOS_SWTMR_PRI_H @@ -40,7 +40,7 @@ extern "C" { #endif /* __cplusplus */ #ifdef LOSCFG_BASE_CORE_SWTMR - +//杞欢瀹氭椂鍣ㄧ殑鐘舵佹灇涓撅紝鍖呮嫭鏈娇鐢ㄣ佸凡鍒涘缓鍜岃鏃朵腑 enum SwtmrState { OS_SWTMR_STATUS_UNUSED, /* The software timer is not used. */ OS_SWTMR_STATUS_CREATED, /* The software timer is created. */ @@ -48,12 +48,13 @@ enum SwtmrState { }; /* Structure of the callback function that handles software timer timeout */ +//澶勭悊杞欢瀹氭椂鍣ㄨ秴鏃跺洖璋冪殑鍥炶皟鍑芥暟缁撴瀯浣 typedef struct { SWTMR_PROC_FUNC handler; /* Callback function that handles software timer timeout */ UINTPTR arg; /* Parameter passed in when the callback function that handles software timer timeout is called */ } SwtmrHandlerItem; - +//杞欢瀹氭椂鍣ㄦ帶鍒跺潡缁撴瀯浣 typedef struct { SortLinkList sortList; UINT8 state; /* Software timer state */ @@ -71,22 +72,28 @@ typedef struct { } LosSwtmrCB; /* Type of the pointer to the structure of the callback function that handles software timer timeout */ +//鎸囧悜澶勭悊杞欢瀹氭椂鍣ㄨ秴鏃跺洖璋冪殑鍥炶皟鍑芥暟缁撴瀯浣撶殑鎸囬拡绫诲瀷 typedef SwtmrHandlerItem *SwtmrHandlerItemPtr; - +//杞欢瀹氭椂鍣ㄦ帶鍒跺潡鏁扮粍 extern LosSwtmrCB *g_swtmrCBArray; /* The software timer count list */ +//杞欢瀹氭椂鍣ㄦ帓搴忛摼琛 extern SortLinkAttribute g_swtmrSortLink; - #define OS_SWT_FROM_SWTID(swtmrId) ((LosSwtmrCB *)g_swtmrCBArray + ((swtmrId) % KERNEL_SWTMR_LIMIT)) /* This API is used to scan a software timer when a Tick interrupt occurs and determine whether * the software timer expires. */ +//鍦═ick涓柇鍙戠敓鏃舵壂鎻忚蒋浠跺畾鏃跺櫒锛屽垽鏂槸鍚﹀埌杈捐秴鏃舵椂闂 extern VOID OsSwtmrScan(VOID); +//鍒濆鍖栬蒋浠跺畾鏃跺櫒 extern UINT32 OsSwtmrInit(VOID); +//杞欢瀹氭椂鍣ㄤ换鍔★紝鐢ㄤ簬澶勭悊杞欢瀹氭椂鍣ㄧ殑瓒呮椂浜嬩欢 extern VOID OsSwtmrTask(VOID); +//杞欢瀹氭椂鍣ㄨ嚜鏃嬮攣 extern SPIN_LOCK_S g_swtmrSpin; #ifdef LOSCFG_EXC_INTERACTION +//鍒ゆ柇褰撳墠浠诲姟鏄惁涓鸿蒋浠跺畾鏃跺櫒浠诲姟 extern BOOL IsSwtmrTask(UINT32 taskId); #endif #endif /* LOSCFG_BASE_CORE_SWTMR */ diff --git a/src/kernel/base/include/los_task_pri.h b/src/kernel/base/include/los_task_pri.h index 4dab9bb..e755763 100644 --- a/src/kernel/base/include/los_task_pri.h +++ b/src/kernel/base/include/los_task_pri.h @@ -25,7 +25,8 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*杩欐槸鍏充簬LiteOS涓换鍔¤皟搴︾浉鍏崇殑澶存枃浠讹紝鍏朵腑瀹氫箟浜嗕换鍔℃帶鍒跺潡鐨勬暟鎹粨鏋勫拰涓浜涗换鍔$鐞嗙殑鎺ュ彛鍑芥暟銆 +鍦ㄨ繖涓ご鏂囦欢涓紝瀹氫箟浜嗕换鍔$殑鐘舵併佷紭鍏堢骇銆佹爣蹇椾綅绛変俊鎭紝骞舵彁渚涗簡涓浜涙搷浣滆繖浜涗俊鎭殑瀹忓拰鍑芥暟銆*/ #ifndef _LOS_TASK_PRI_H #define _LOS_TASK_PRI_H diff --git a/src/kernel/base/include/los_tick_pri.h b/src/kernel/base/include/los_tick_pri.h index 5e67cef..5019d05 100644 --- a/src/kernel/base/include/los_tick_pri.h +++ b/src/kernel/base/include/los_tick_pri.h @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//杩欎釜澶存枃浠舵槸鍏充簬绯荤粺鏃堕挓涓柇tick鐨勫畾涔夊拰鎿嶄綔銆 #ifndef _LOS_TICK_PRI_H #define _LOS_TICK_PRI_H @@ -40,30 +40,41 @@ extern "C" { #endif /* __cplusplus */ /* spinlock for tick */ +//鐢ㄤ簬淇濇姢tick鐩稿叧鎿嶄綔鐨勮嚜鏃嬮攣 extern SPIN_LOCK_S g_tickSpin; +//鑾峰彇tick鑷棆閿佸苟淇濆瓨鐘舵 #define TICK_LOCK(state) LOS_SpinLockSave(&g_tickSpin, &(state)) +//閲婃斁tick鑷棆閿佸苟鎭㈠鐘舵 #define TICK_UNLOCK(state) LOS_SpinUnlockRestore(&g_tickSpin, (state)) /* Count of Ticks */ +//鍏ㄥ眬鍙橀噺锛屼繚瀛樼郴缁焧ick鐨勮鏁板 extern volatile UINT64 g_tickCount[]; /* Cycle to nanosecond scale */ +//寰幆鍛ㄦ湡鍒扮撼绉掔殑杞崲姣斾緥 extern DOUBLE g_cycle2NsScale; /* This API is called when the system tick timeout and triggers the interrupt. */ +//绯荤粺tick涓柇澶勭悊鍑芥暟锛屽綋绯荤粺tick瓒呮椂瑙﹀彂涓柇鏃惰皟鐢 extern VOID OsTickHandler(VOID); +//鍒濆鍖栫郴缁焧ick鐩稿叧閰嶇疆 extern UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond); +//鍚姩绯荤粺tick涓柇 extern VOID OsTickStart(VOID); /* Convert from the cycle count to nanosecond. */ +//灏嗗惊鐜懆鏈熻浆鎹负绾崇 #define CYCLE_TO_NS(cycles) ((cycles) * g_cycle2NsScale) /** * Current system timer register is 32 bit, therefore TIMER_MAXLOAD define just in order to avoid ambiguity. */ +//瀹氭椂鍣ㄦ渶澶у姞杞藉硷紝鐢ㄤ簬閬垮厤姝т箟 #define TIMER_MAXLOAD 0xffffffff #ifdef LOSCFG_KERNEL_TICKLESS +//tick涓柇鏍囧織锛屽湪LOSCFG_KERNEL_TICKLESS閫夐」寮鍚椂浣跨敤 #define LOS_TICK_INT_FLAG 0x80000000 #endif diff --git a/src/kernel/base/los_bitmap.c b/src/kernel/base/los_bitmap.c index 84a056a..8ac0390 100644 --- a/src/kernel/base/los_bitmap.c +++ b/src/kernel/base/los_bitmap.c @@ -26,6 +26,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ +/*杩欐槸涓涓綅鍥撅紙bitmap锛夌殑瀹炵幇锛岀敤浜庡浣嶅浘杩涜璁剧疆銆佹竻闄ゅ拰鑾峰彇鏈楂/鏈浣庝綅鐨勬搷浣溿 +璇ヤ綅鍥句娇鐢ㄤ竴涓32浣嶆棤绗﹀彿鏁存暟锛圲INT32锛夋潵琛ㄧず锛屾瘡涓浣嶉兘浠h〃涓涓爣璁 +鍑芥暟閫氳繃浣嶈繍绠楁潵瀹炵幇瀵逛綅鍥剧殑鎿嶄綔锛屽叾涓寘鎷乏绉汇佹寜浣嶄笌銆佹寜浣嶆垨銆佹寜浣嶅彇鍙嶇瓑鎿嶄綔銆*/ + #include "los_bitmap.h" #include "los_toolchain.h" @@ -36,7 +40,7 @@ extern "C" { #endif /* __cplusplus */ #define OS_BITMAP_MASK 0x1FU - +//LOS_BitmapSet锛氬皢鎸囧畾浣嶇疆鐨勪綅璁剧疆涓1 VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos) { if (bitmap == NULL) { @@ -45,7 +49,7 @@ VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos) *bitmap |= 1U << (pos & OS_BITMAP_MASK); } - +//LOS_BitmapClr锛氬皢鎸囧畾浣嶇疆鐨勪綅娓呴櫎涓0 VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos) { if (bitmap == NULL) { @@ -54,7 +58,7 @@ VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos) *bitmap &= ~(1U << (pos & OS_BITMAP_MASK)); } - +//LOS_HighBitGet锛氳幏鍙栦綅鍥句腑鏈楂樹綅锛堝间负1鐨勪綅缃級鐨勭储寮 UINT16 LOS_HighBitGet(UINT32 bitmap) { if (bitmap == 0) { @@ -63,7 +67,7 @@ UINT16 LOS_HighBitGet(UINT32 bitmap) return (OS_BITMAP_MASK - CLZ(bitmap)); } - +//LOS_LowBitGet锛氳幏鍙栦綅鍥句腑鏈浣庝綅锛堝间负1鐨勪綅缃級鐨勭储寮 UINT16 LOS_LowBitGet(UINT32 bitmap) { if (bitmap == 0) { diff --git a/src/kernel/base/los_err.c b/src/kernel/base/los_err.c index 970015d..abcc40a 100644 --- a/src/kernel/base/los_err.c +++ b/src/kernel/base/los_err.c @@ -25,7 +25,8 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*杩欐浠g爜鏄叧浜庨敊璇鐞嗙殑鐩稿叧鍔熻兘锛屽寘鎷敞鍐岄敊璇鐞嗗嚱鏁板拰鎵ц閿欒澶勭悊鐨勫嚱鏁般 +閫氳繃浠ヤ笅鎺ュ彛锛岀敤鎴峰彲浠ヨ嚜瀹氫箟閿欒澶勭悊鍑芥暟锛屽苟鍦ㄥ彂鐢熼敊璇椂杩涜鐩稿簲鐨勫鐞嗘搷浣溿傝繖鏍峰彲浠ュ寮虹郴缁熺殑鍋ュ.鎬у拰瀹归敊鎬э紝鏇村ソ鍦板簲瀵瑰悇绉嶉敊璇儏鍐点*/ #include "los_err.h" #ifdef __cplusplus @@ -35,8 +36,9 @@ extern "C" { #endif /* __cplusplus */ /* Hook function for error handling. */ +//g_usrErrFunc锛氬叏灞鍙橀噺锛岀敤浜庝繚瀛樼敤鎴锋敞鍐岀殑閿欒澶勭悊鍑芥暟 LITE_OS_SEC_BSS LOS_ERRORHANDLE_FUNC g_usrErrFunc; - +//LOS_ErrHandle锛氱敤浜庢墽琛岄敊璇鐞嗙殑鍑芥暟锛屽綋绯荤粺鍑虹幇閿欒鏃朵細璋冪敤璇ュ嚱鏁版潵澶勭悊閿欒淇℃伅 LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, UINT32 errorNo, UINT32 paraLen, VOID *para) { @@ -46,7 +48,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, UINT32 return LOS_OK; } - +//LOS_RegErrHandle锛氱敤浜庢敞鍐岄敊璇鐞嗗嚱鏁扮殑鎺ュ彛锛岀敤鎴峰彲浠ラ氳繃璇ュ嚱鏁版敞鍐岃嚜瀹氫箟鐨勯敊璇鐞嗗嚱鏁 LITE_OS_SEC_TEXT_INIT VOID LOS_RegErrHandle(LOS_ERRORHANDLE_FUNC func) { g_usrErrFunc = func; diff --git a/src/kernel/base/los_event.c b/src/kernel/base/los_event.c index b2fe8cb..3caadc8 100644 --- a/src/kernel/base/los_event.c +++ b/src/kernel/base/los_event.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*杩欐浠g爜鏄叧浜庝簨浠剁鐞嗙殑瀹炵幇锛屽寘鎷簨浠剁殑鍒濆鍖栥佽鍙栥佸啓鍏ャ佹竻闄ょ瓑鎿嶄綔銆*/ #include "los_event_pri.h" #include "los_task_pri.h" #include "los_spinlock.h" @@ -38,7 +38,7 @@ extern "C" { #endif #endif /* __cplusplus */ - +//LOS_EventInit()鍑芥暟鐢ㄤ簬鍒濆鍖栦簨浠舵帶鍒跺潡锛坋ventCB锛夛紝骞跺皢浜嬩欢ID銆佷簨浠跺垪琛ㄧ瓑灞炴ц缃负鍒濆鍊 LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB) { UINT32 intSave; @@ -55,7 +55,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB) LOS_IntRestore(intSave); return LOS_OK; } - +//OsEventParamCheck()鍑芥暟鐢ㄤ簬妫鏌ュ弬鏁扮殑鏈夋晥鎬э紝鍖呮嫭浜嬩欢鎺╃爜锛坋ventMask锛夈佹ā寮忥紙mode锛夌瓑 LITE_OS_SEC_TEXT STATIC UINT32 OsEventParamCheck(const VOID *ptr, UINT32 eventMask, UINT32 mode) { if (ptr == NULL) { @@ -75,16 +75,17 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventParamCheck(const VOID *ptr, UINT32 eventMa !(mode & (LOS_WAITMODE_OR | LOS_WAITMODE_AND))) { return LOS_ERRNO_EVENT_FLAGS_INVALID; } + //鎸囬拡闈炵┖锛屼簨浠舵帺鐮侀潪0锛屼簨浠舵帺鐮佷笉鍖呭惈LOS_ERRTYPE_ERROR鏍囧織浣嶏紝妯″紡鍚堟硶 return LOS_OK; } - +//OsEventPoll()鍑芥暟鐢ㄤ簬杞浜嬩欢锛屾牴鎹寚瀹氱殑浜嬩欢鎺╃爜鍜屾ā寮忓垽鏂槸鍚︽弧瓒虫潯浠 LITE_OS_SEC_TEXT STATIC UINT32 OsEventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode) { UINT32 ret = 0; LOS_ASSERT(ArchIntLocked()); LOS_ASSERT(LOS_SpinHeld(&g_taskSpin)); - + if (mode & LOS_WAITMODE_OR) { if ((*eventId & eventMask) != 0) { ret = *eventId & eventMask; @@ -101,7 +102,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventPoll(UINT32 *eventId, UINT32 eventMask, UI return ret; } - +//OsEventReadCheck()鍑芥暟鐢ㄤ簬妫鏌ヤ簨浠惰鍙栨搷浣滅殑鍙傛暟鏈夋晥鎬э紝鍖呮嫭浜嬩欢鎺у埗鍧楋紙eventCB锛夈佷簨浠舵帺鐮侊紙eventMask锛夈佹ā寮忥紙mode锛夌瓑 LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadCheck(const PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode) { UINT32 ret; @@ -122,7 +123,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadCheck(const PEVENT_CB_S eventCB, UINT3 } return LOS_OK; } - +//OsEventReadImp()鍑芥暟鏄簨浠惰鍙栫殑瀹炵幇锛屾牴鎹寚瀹氱殑浜嬩欢鎺╃爜鍜屾ā寮忚繘琛岃疆璇紝骞舵牴鎹秴鏃舵椂闂村拰鏄惁鍙鍙栦竴娆¤繘琛岀浉搴旂殑鎿嶄綔 LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout, BOOL once, UINT32 *intSave) { @@ -165,7 +166,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventM } return ret; } - +//OsEventRead()鍑芥暟鏄澶栨彁渚涚殑浜嬩欢璇诲彇鎺ュ彛锛岃皟鐢∣sEventReadCheck()鍜孫sEventReadImp()瀹炵幇浜嬩欢鐨勮鍙栨搷浣 LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout, BOOL once) { @@ -184,7 +185,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventRead(PEVENT_CB_S eventCB, UINT32 eventMask SCHEDULER_UNLOCK(intSave); return ret; } - +//OsEventWrite()鍑芥暟鐢ㄤ簬鍚戜簨浠舵帶鍒跺潡涓啓鍏ユ寚瀹氱殑浜嬩欢 LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events, BOOL once) { LosTaskCB *resumedTask = NULL; @@ -230,7 +231,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventWrite(PEVENT_CB_S eventCB, UINT32 events, } return LOS_OK; } - +//LOS_EventPoll()鍑芥暟鏄澶栨彁渚涚殑浜嬩欢杞鎺ュ彛锛岃皟鐢∣sEventParamCheck()鍜孫sEventPoll()瀹炵幇浜嬩欢鐨勮疆璇㈡搷浣 LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode) { UINT32 ret; @@ -246,17 +247,17 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 SCHEDULER_UNLOCK(intSave); return ret; } - +//LOS_EventRead()鍑芥暟鏄澶栨彁渚涚殑浜嬩欢璇诲彇鎺ュ彛锛岃皟鐢∣sEventRead()瀹炵幇浜嬩欢鐨勮鍙栨搷浣 LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout) { return OsEventRead(eventCB, eventMask, mode, timeout, FALSE); } - +//LOS_EventWrite()鍑芥暟鏄澶栨彁渚涚殑浜嬩欢鍐欏叆鎺ュ彛锛岃皟鐢∣sEventWrite()瀹炵幇浜嬩欢鐨勫啓鍏ユ搷浣 LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events) { return OsEventWrite(eventCB, events, FALSE); } - +//LOS_EventDestroy()鍑芥暟鐢ㄤ簬閿姣佷簨浠舵帶鍒跺潡锛屽皢浜嬩欢ID璁剧疆涓0 LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB) { UINT32 intSave; @@ -279,7 +280,7 @@ OUT: LOS_TRACE(EVENT_DELETE, (UINTPTR)eventCB, ret); return ret; } - +//LOS_EventClear()鍑芥暟鐢ㄤ簬娓呴櫎鎸囧畾鐨勪簨浠 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events) { UINT32 intSave; @@ -296,18 +297,19 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events) return LOS_OK; } - +//OsEventWriteOnce()鍑芥暟鏄簨浠跺啓鍏ョ殑瀹炵幇锛屼笌OsEventWrite()绫讳技锛屼絾鍙啓鍏ヤ竴娆 LITE_OS_SEC_TEXT_MINOR UINT32 OsEventWriteOnce(PEVENT_CB_S eventCB, UINT32 events) { return OsEventWrite(eventCB, events, TRUE); } #ifdef LOSCFG_COMPAT_POSIX +//OsEventReadOnce()鍑芥暟鏄簨浠惰鍙栫殑瀹炵幇锛屼笌OsEventRead()绫讳技锛屼絾鍙鍙栦竴娆 LITE_OS_SEC_TEXT_MINOR UINT32 OsEventReadOnce(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout) { return OsEventRead(eventCB, eventMask, mode, timeout, TRUE); } - +// /OsEventReadWithCond()鍑芥暟鐢ㄤ簬鏍规嵁鏉′欢璇诲彇浜嬩欢锛屽彧鏈夊綋鏉′欢婊¤冻鏃舵墠杩涜浜嬩欢璇诲彇鎿嶄綔 LITE_OS_SEC_TEXT UINT32 OsEventReadWithCond(const EventCond *cond, PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout) { diff --git a/src/kernel/base/los_exc.c b/src/kernel/base/los_exc.c index 71970f0..3ea59a0 100644 --- a/src/kernel/base/los_exc.c +++ b/src/kernel/base/los_exc.c @@ -25,7 +25,8 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*杩欐槸鍏充簬LiteOS涓紓甯稿鐞嗙殑浠g爜锛屽叾涓寘鎷褰曞紓甯镐俊鎭佸紓甯镐俊鎭繚瀛樺拰璇诲彇绛夊姛鑳姐 +鍚屾椂杩樺寘鎷簡涓浜涗笌寮傚父鐩稿叧鐨勫嚱鏁帮紝濡傛墦鍗板紓甯镐俊鎭佷换鍔″洖婧瓑*/ #include "los_exc.h" #include "los_printf_pri.h" #include "los_task_pri.h" @@ -48,7 +49,7 @@ extern "C" { #endif #endif /* __cplusplus */ - +//ExcInfoDumpFormat鐨勭粨鏋勪綋绫诲瀷锛屽寘鍚簡鐢ㄤ簬瀛樺偍寮傚父淇℃伅鐨勭紦鍐插尯鎸囬拡銆佸亸绉婚噺銆侀暱搴﹀拰瀛樺偍鍦板潃绛変俊鎭 #ifdef LOSCFG_SHELL_EXCINFO_DUMP typedef struct { CHAR *buf; /* pointer to the buffer for storing the exception information */ @@ -56,11 +57,13 @@ typedef struct { UINT32 len; /* the size of storing the exception information */ UINTPTR dumpAddr; /* the address of storing the exception information */ } ExcInfoDumpFormat; - +//鍏ㄥ眬鍙橀噺g_excInfoPool锛岀敤浜庡瓨鍌ㄥ紓甯镐俊鎭殑缂撳啿鍖哄拰鐩稿叧鐨勪俊鎭 STATIC ExcInfoDumpFormat g_excInfoPool = {0}; /* the hook of read-writing exception information */ STATIC __attribute__((section(".data"))) LogReadWriteFunc g_dumpHook = NULL; - +//LOS_ExcInfoRegHook锛氭敞鍐屽紓甯镐俊鎭鍐欓挬瀛愬嚱鏁帮紝鐢ㄤ簬璁剧疆寮傚父淇℃伅鐨勫瓨鍌ㄥ湴鍧銆侀暱搴︿互鍙婄紦鍐插尯绛変俊鎭 +//"閽╁瓙鍑芥暟"鏄寚鍦ㄧ壒瀹氫簨浠跺彂鐢熸椂浼氳璋冪敤鐨勫嚱鏁 +//閫氳繃浣跨敤閽╁瓙鍑芥暟锛屽彲浠ュ湪寮傚父鍙戠敓鏃剁伒娲诲湴鎵ц鐗瑰畾鐨勬搷浣滐紝渚嬪璁板綍寮傚父淇℃伅銆佽繘琛岀壒瀹氱殑澶勭悊鎴栭氱煡鍏朵粬妯″潡杩涜鐩稿簲鐨勬搷浣 VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 len, CHAR *buf, LogReadWriteFunc hook) { if ((hook == NULL) || (buf == NULL)) { @@ -78,57 +81,57 @@ VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 len, CHAR *buf, LogReadWriteFu g_excInfoPool.buf = buf; g_dumpHook = hook; } - +//OsSetExcInfoRW锛氳缃紓甯镐俊鎭鍐欓挬瀛愬嚱鏁 VOID OsSetExcInfoRW(LogReadWriteFunc func) { g_dumpHook = func; } - +//OsGetExcInfoRW锛氳幏鍙栧紓甯镐俊鎭鍐欓挬瀛愬嚱鏁 LogReadWriteFunc OsGetExcInfoRW(VOID) { return g_dumpHook; } - +//OsSetExcInfoBuf锛氳缃紓甯镐俊鎭殑缂撳啿鍖 VOID OsSetExcInfoBuf(CHAR *buf) { g_excInfoPool.buf = buf; } - +//OsGetExcInfoBuf锛氳幏鍙栧紓甯镐俊鎭殑缂撳啿鍖 CHAR *OsGetExcInfoBuf(VOID) { return g_excInfoPool.buf; } - +//OsSetExcInfoOffset锛氳缃紓甯镐俊鎭殑鍋忕Щ閲 VOID OsSetExcInfoOffset(UINT32 Offset) { g_excInfoPool.offset = Offset; } - +//OsGetExcInfoOffset锛氳幏鍙栧紓甯镐俊鎭殑鍋忕Щ閲 UINT32 OsGetExcInfoOffset(VOID) { return g_excInfoPool.offset; } - +//OsSetExcInfoDumpAddr锛氳缃紓甯镐俊鎭殑瀛樺偍鍦板潃 VOID OsSetExcInfoDumpAddr(UINTPTR addr) { g_excInfoPool.dumpAddr = addr; } - +//OsGetExcInfoDumpAddr锛氳幏鍙栧紓甯镐俊鎭殑瀛樺偍鍦板潃 UINTPTR OsGetExcInfoDumpAddr(VOID) { return g_excInfoPool.dumpAddr; } - +//OsSetExcInfoLen锛氳缃紓甯镐俊鎭殑闀垮害 VOID OsSetExcInfoLen(UINT32 len) { g_excInfoPool.len = len; } - +//OsGetExcInfoLen锛氳幏鍙栧紓甯镐俊鎭殑闀垮害 UINT32 OsGetExcInfoLen(VOID) { return g_excInfoPool.len; } - +//WriteExcBufVa锛氬皢鏍煎紡鍖栫殑瀛楃涓插啓鍏ュ紓甯镐俊鎭紦鍐插尯 VOID WriteExcBufVa(const CHAR *format, va_list arglist) { errno_t ret; @@ -143,7 +146,7 @@ VOID WriteExcBufVa(const CHAR *format, va_list arglist) g_excInfoPool.offset += ret; } } - +//WriteExcInfoToBuf锛氬皢鏍煎紡鍖栫殑瀛楃涓插啓鍏ュ紓甯镐俊鎭紦鍐插尯 VOID WriteExcInfoToBuf(const CHAR *format, ...) { va_list arglist; @@ -152,7 +155,7 @@ VOID WriteExcInfoToBuf(const CHAR *format, ...) WriteExcBufVa(format, arglist); va_end(arglist); } - +//OsRecordExcInfoTime锛氳褰曞紓甯镐俊鎭殑鏃堕棿 VOID OsRecordExcInfoTime(VOID) { #define NOW_TIME_LENGTH 24 @@ -169,7 +172,7 @@ VOID OsRecordExcInfoTime(VOID) #undef NOW_TIME_LENGTH PrintExcInfo("%s \n", nowTime); } - +//OsShellCmdReadExcInfo锛氳鍙栧苟鎵撳嵃寮傚父淇℃伅鐨凷hell鍛戒护 #ifdef LOSCFG_SHELL INT32 OsShellCmdReadExcInfo(INT32 argc, const CHAR **argv) { @@ -200,6 +203,9 @@ SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc #endif #ifdef LOSCFG_EXC_INTERACTION +//OsCheckExcInteractionTask锛氭鏌ヤ换鍔℃槸鍚︿负寮傚父浜や簰浠诲姟 +//寮傚父浜や簰浠诲姟閫氬父鎸囩殑鏄敤浜庡鐞嗗紓甯告儏鍐电殑鐗规畩浠诲姟鎴栫嚎绋 +//褰撶郴缁熷彂鐢熶弗閲嶇殑閿欒鎴栧紓甯告椂锛岄渶瑕佺珛鍗抽噰鍙栫浉搴旂殑鎺柦鏉ュ鐞嗗紓甯告儏鍐碉紝杩欏氨闇瑕佷娇鐢ㄥ紓甯镐氦浜掍换鍔℃潵澶勭悊 UINT32 OsCheckExcInteractionTask(const TSK_INIT_PARAM_S *initParam) { if ((initParam->pfnTaskEntry == (TSK_ENTRY_FUNC)ShellTask) || @@ -209,7 +215,7 @@ UINT32 OsCheckExcInteractionTask(const TSK_INIT_PARAM_S *initParam) } return LOS_NOK; } - +//OsKeepExcInteractionTask锛氫繚鐣欏紓甯镐氦浜掍换鍔★紝鍒犻櫎鍏朵粬浠诲姟 VOID OsKeepExcInteractionTask(VOID) { LosTaskCB *taskCB = NULL; @@ -243,7 +249,7 @@ VOID OsKeepExcInteractionTask(VOID) } #endif - +//LOS_Panic锛氭墦鍗板紓甯镐俊鎭苟鍋滄CPU鎵ц VOID LOS_Panic(const CHAR *fmt, ...) { va_list ap; @@ -252,7 +258,7 @@ VOID LOS_Panic(const CHAR *fmt, ...) va_end(ap); ArchHaltCpu(); } - +//LOS_BackTrace锛氭墦鍗板綋鍓嶄换鍔$殑杩愯淇℃伅鍜屽洖婧爢鏍 VOID LOS_BackTrace(VOID) { #ifdef LOSCFG_BACKTRACE @@ -262,7 +268,7 @@ VOID LOS_BackTrace(VOID) ArchBackTrace(); #endif } - +//LOS_TaskBackTrace锛氭墦鍗版寚瀹氫换鍔$殑杩愯淇℃伅鍜屽洖婧爢鏍 VOID LOS_TaskBackTrace(UINT32 taskID) { #ifdef LOSCFG_BACKTRACE @@ -289,6 +295,7 @@ VOID LOS_TaskBackTrace(UINT32 taskID) #ifdef __GNUC__ /* stack protector */ +//__stack_chk_fail锛氱敤浜庢爤淇濇姢鏈哄埗锛屽綋鍙戠幇鏍堣鐮村潖鏃惰Е鍙戝紓甯稿鐞 VOID __stack_chk_fail(VOID) { /* __builtin_return_address is a builtin function, building in gcc */ diff --git a/src/kernel/base/los_hwi.c b/src/kernel/base/los_hwi.c index 0adc4f4..c620a44 100644 --- a/src/kernel/base/los_hwi.c +++ b/src/kernel/base/los_hwi.c @@ -25,7 +25,9 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/* +鍏充簬LiteOS涓‖浠朵腑鏂鐞嗙殑閮ㄥ垎锛屾秹鍙婁簡涓柇鐨勬敞鍐屻佸垹闄ゃ佽Е鍙戙佷娇鑳姐佺姝㈢瓑鎿嶄綔 +*/ #include "los_hwi_pri.h" #include "los_hwi.h" #include "los_memory.h" @@ -61,7 +63,7 @@ const HwiControllerOps *g_hwiOps = NULL; typedef VOID (*HWI_PROC_FUNC0)(VOID); typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *); - +//OsIrqNestingActive锛氱敤浜庡湪澶勭悊涓柇鏈熼棿婵娲讳腑鏂祵濂楄鏁板櫒锛岄伩鍏嶅湪澶勭悊鏃堕挓涓柇鏃惰繘琛屾姠鍗 STATIC INLINE VOID OsIrqNestingActive(UINT32 hwiNum) { #ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION @@ -71,7 +73,7 @@ STATIC INLINE VOID OsIrqNestingActive(UINT32 hwiNum) } #endif } - +//OsIrqNestingInactive锛氱敤浜庡湪澶勭悊涓柇缁撴潫鍚庣鐢ㄤ腑鏂祵濂楄鏁板櫒 STATIC INLINE VOID OsIrqNestingInactive(UINT32 hwiNum) { #ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION @@ -80,17 +82,17 @@ STATIC INLINE VOID OsIrqNestingInactive(UINT32 hwiNum) } #endif } - +//OsIrqNestingCntGet锛氳幏鍙栧綋鍓岰PU鐨勪腑鏂祵濂楄鏁板 size_t OsIrqNestingCntGet(VOID) { return g_intCount[ArchCurrCpuid()]; } - +//OsIrqNestingCntSet锛氳缃綋鍓岰PU鐨勪腑鏂祵濂楄鏁板 VOID OsIrqNestingCntSet(size_t val) { g_intCount[ArchCurrCpuid()] = val; } - +//InterruptHandle锛氬鐞嗕腑鏂殑瀹為檯鍑芥暟锛屾牴鎹腑鏂彿璋冪敤瀵瑰簲鐨勪腑鏂鐞嗗嚱鏁 STATIC INLINE VOID InterruptHandle(HwiHandleInfo *hwiForm) { hwiForm->respCount++; @@ -114,7 +116,7 @@ STATIC INLINE VOID InterruptHandle(HwiHandleInfo *hwiForm) } #endif } - +//OsIntHandle锛氫腑鏂鐞嗗叆鍙e嚱鏁帮紝璐熻矗澶勭悊涓柇鍓嶇殑涓浜涘噯澶囧伐浣滐紝濡傝皟鐢ㄤ腑鏂鐞嗗墠鐨勯挬瀛愬嚱鏁扮瓑 VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *hwiForm) { size_t *intCnt = NULL; @@ -148,7 +150,7 @@ VOID OsIntHandle(UINT32 hwiNum, HwiHandleInfo *hwiForm) OsCpupIrqEnd(hwiNum); #endif } - +//OsIntEntry锛氫腑鏂悜閲忓叆鍙e嚱鏁帮紝鏍规嵁涓柇鍙疯皟鐢ㄥ搴旂殑涓柇澶勭悊鍑芥暟 VOID OsIntEntry(VOID) { if ((g_hwiOps != NULL) && (g_hwiOps->handleIrq != NULL)) { @@ -156,7 +158,7 @@ VOID OsIntEntry(VOID) } return; } - +//OsHwiCpIrqParam锛氭牴鎹紶鍏ョ殑涓柇鍙傛暟缁撴瀯浣撳垎閰嶅唴瀛橈紝骞跺皢鍙傛暟淇℃伅鎷疯礉鍒版柊鍒嗛厤鐨勫唴瀛樹腑 STATIC HWI_ARG_T OsHwiCpIrqParam(const HWI_IRQ_PARAM_S *irqParam) { HWI_IRQ_PARAM_S *paramByAlloc = NULL; @@ -169,6 +171,7 @@ STATIC HWI_ARG_T OsHwiCpIrqParam(const HWI_IRQ_PARAM_S *irqParam) return (HWI_ARG_T)paramByAlloc; } #ifndef LOSCFG_SHARED_IRQ +//OsHwiDel锛氬垹闄ゆ寚瀹氱殑涓柇澶勭悊鍑芥暟 STATIC UINT32 OsHwiDel(HwiHandleInfo *hwiForm, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId) { UINT32 intSave; @@ -190,7 +193,7 @@ STATIC UINT32 OsHwiDel(HwiHandleInfo *hwiForm, const HWI_IRQ_PARAM_S *irqParam, HWI_UNLOCK(intSave); return LOS_OK; } - +//OsHwiCreate锛氬垱寤轰腑鏂鐞嗗嚱鏁帮紝骞跺皢鍏舵坊鍔犲埌涓柇澶勭悊閾捐〃涓 STATIC UINT32 OsHwiCreate(HwiHandleInfo *hwiForm, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler, const HWI_IRQ_PARAM_S *irqParam) { @@ -218,6 +221,7 @@ STATIC UINT32 OsHwiCreate(HwiHandleInfo *hwiForm, HWI_MODE_T hwiMode, HWI_PROC_F return LOS_OK; } #else /* LOSCFG_SHARED_IRQ */ +//鍑芥暟OsFreeHwiNode:鐢ㄤ簬閲婃斁涓柇澶勭悊鍑芥暟鑺傜偣锛屽苟鍦ㄩ渶瑕佹椂绂佹璇ヤ腑鏂 STATIC INLINE UINT32 OsFreeHwiNode(HwiHandleInfo *head, HwiHandleInfo *hwiForm, UINT32 irqId) { UINT32 ret = LOS_OK; @@ -240,7 +244,8 @@ STATIC INLINE UINT32 OsFreeHwiNode(HwiHandleInfo *head, HwiHandleInfo *hwiForm, return ret; } - +//OsHwiDel:鐢ㄤ簬鍒犻櫎纭欢涓柇澶勭悊鍑芥暟锛屽畠棣栧厛鍒ゆ柇涓柇鏄惁鏄叡浜腑鏂 +//濡傛灉涓嶆槸锛屽垯鐩存帴閲婃斁璇ヤ腑鏂殑澶勭悊鍑芥暟鑺傜偣;濡傛灉鏄叡浜腑鏂紝鍒欓亶鍘嗛摼琛ㄦ壘鍒板搴旂殑璁惧ID锛岀劧鍚庨噴鏀捐涓柇鐨勫鐞嗗嚱鏁拌妭鐐 STATIC UINT32 OsHwiDel(HwiHandleInfo *head, const HWI_IRQ_PARAM_S *irqParam, UINT32 irqId) { HwiHandleInfo *hwiFormPrev = NULL; @@ -290,7 +295,8 @@ STATIC UINT32 OsHwiDel(HwiHandleInfo *head, const HWI_IRQ_PARAM_S *irqParam, UIN HWI_UNLOCK(intSave); return ret; } - +//OsHwiCreate:鐢ㄤ簬鍒涘缓纭欢涓柇澶勭悊鍑芥暟锛屽畠棣栧厛鍒ゆ柇涓柇鏄惁鏄叡浜腑鏂紝骞舵鏌ユ槸鍚﹀凡缁忓瓨鍦ㄥ叿鏈夌浉鍚岃澶嘔D鐨勪腑鏂鐞嗗嚱鏁拌妭鐐癸紝濡傛灉瀛樺湪鍒欒繑鍥為敊璇 +//鐒跺悗鐢宠鍐呭瓨骞跺垵濮嬪寲鏂扮殑涓柇澶勭悊鍑芥暟鑺傜偣锛屽皢鍏舵坊鍔犲埌閾捐〃涓 STATIC UINT32 OsHwiCreate(HwiHandleInfo *head, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler, const HWI_IRQ_PARAM_S *irqParam) { @@ -359,7 +365,9 @@ size_t IntActive() LOS_IntRestore(intSave); return intCount; } - +//LOS_HwiCreate 鍑芥暟锛氱敤浜庡垱寤虹‖浠朵腑鏂鐞嗗嚱鏁 +//瀹冧細娉ㄥ唽涓涓腑鏂鐞嗗嚱鏁帮紝骞跺皢鍏朵笌鎸囧畾鐨勭‖浠朵腑鏂彿鐩稿叧鑱 +//鍙互璁剧疆涓柇鐨勪紭鍏堢骇銆佺‖浠朵腑鏂ā寮忓拰澶勭悊鍑芥暟 LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio, HWI_MODE_T hwiMode, @@ -396,7 +404,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, } return ret; } - +//LOS_HwiDelete 鍑芥暟锛氱敤浜庡垹闄ゅ凡缁忓垱寤虹殑纭欢涓柇澶勭悊鍑芥暟 +//閫氳繃鎸囧畾纭欢涓柇鍙凤紝鍙互灏嗕箣鍓嶆敞鍐岀殑涓柇澶勭悊鍑芥暟浠庣郴缁熶腑鍒犻櫎 LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam) { UINT32 ret; @@ -417,7 +426,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqP return ret; } - +//LOS_HwiTrigger 鍑芥暟锛氱敤浜庢墜鍔ㄨЕ鍙戞寚瀹氱殑纭欢涓柇 +//璋冪敤璇ュ嚱鏁板悗锛屼細绔嬪嵆瑙﹀彂瀵瑰簲鐨勭‖浠朵腑鏂紝浣垮緱绯荤粺鎵ц鐩稿簲鐨勪腑鏂鐞嗗嚱鏁 LITE_OS_SEC_TEXT UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum) { if ((g_hwiOps == NULL) || (g_hwiOps->triggerIrq == NULL)) { @@ -427,7 +437,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum) return g_hwiOps->triggerIrq(hwiNum); } - +//LOS_HwiEnable 鍑芥暟锛氱敤浜庝娇鑳芥寚瀹氱殑纭欢涓柇 +//璋冪敤璇ュ嚱鏁板悗锛岀郴缁熷皢鍏佽瀵瑰簲鐨勭‖浠朵腑鏂骇鐢燂紝骞舵墽琛岀浉搴旂殑涓柇澶勭悊鍑芥暟 LITE_OS_SEC_TEXT UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum) { if ((g_hwiOps == NULL) || (g_hwiOps->enableIrq == NULL)) { @@ -437,7 +448,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum) return g_hwiOps->enableIrq(hwiNum); } - +//LOS_HwiDisable 鍑芥暟锛氱敤浜庣姝㈡寚瀹氱殑纭欢涓柇 +//璋冪敤璇ュ嚱鏁板悗锛岀郴缁熷皢闃绘瀵瑰簲鐨勭‖浠朵腑鏂骇鐢燂紝灞忚斀鍏跺奖鍝 LITE_OS_SEC_TEXT UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum) { if ((g_hwiOps == NULL) || (g_hwiOps->disableIrq == NULL)) { @@ -447,7 +459,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum) return g_hwiOps->disableIrq(hwiNum); } - +//LOS_HwiClear 鍑芥暟锛氱敤浜庢竻闄ゆ寚瀹氱殑纭欢涓柇 +//鍦ㄦ煇浜涘钩鍙颁笂锛岀‖浠朵腑鏂彂鐢熷悗鍙兘闇瑕佹墜鍔ㄦ竻闄や腑鏂爣蹇椾綅锛屼互渚挎纭鐞嗗悗缁殑涓柇 LITE_OS_SEC_TEXT UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum) { if ((g_hwiOps == NULL) || (g_hwiOps->clearIrq == NULL)) { @@ -457,7 +470,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum) return g_hwiOps->clearIrq(hwiNum); } - +//LOS_HwiSetPriority 鍑芥暟锛氱敤浜庤缃‖浠朵腑鏂殑浼樺厛绾 +//閫氳繃鎸囧畾纭欢涓柇鍙峰拰浼樺厛绾э紝鍙互璋冩暣纭欢涓柇鐨勮Е鍙戦『搴 LITE_OS_SEC_TEXT UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority) { if ((g_hwiOps == NULL) || (g_hwiOps->setIrqPriority == NULL)) { @@ -468,6 +482,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T prio return g_hwiOps->setIrqPriority(hwiNum, priority); } #ifdef LOSCFG_KERNEL_SMP +//LOS_HwiSetAffinity鍑芥暟锛氱敤浜庤缃‖浠朵腑鏂殑澶勭悊CPU浜插拰鎬 +//瀹冮鍏堟鏌ョ‖浠朵腑鏂搷浣滃嚱鏁版寚閽堟槸鍚︿负绌猴紝鐒跺悗璋冪敤鍏蜂綋鐨勬搷浣滃嚱鏁版潵璁剧疆涓柇鐨勫鐞咰PU浜插拰鎬 LITE_OS_SEC_TEXT UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask) { if ((g_hwiOps == NULL) || (g_hwiOps->setIrqCpuAffinity == NULL)) { @@ -477,7 +493,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask) return g_hwiOps->setIrqCpuAffinity(hwiNum, cpuMask); } - +//LOS_HwiSendIpi鍑芥暟锛氱敤浜庡彂閫佺‖浠朵腑鏂鐞嗚姹傜粰鎸囧畾鐨凜PU +//瀹冮鍏堟鏌ョ‖浠朵腑鏂搷浣滃嚱鏁版寚閽堟槸鍚︿负绌猴紝鐒跺悗璋冪敤鍏蜂綋鐨勬搷浣滃嚱鏁版潵鍙戦佷腑鏂鐞嗚姹 LITE_OS_SEC_TEXT UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask) { if ((g_hwiOps == NULL) || (g_hwiOps->sendIpi == NULL)) { @@ -490,6 +507,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask) #endif #ifdef LOSCFG_KERNEL_LOWPOWER +//LOS_IntWakeupHookReg鍑芥暟锛氱敤浜庢敞鍐屼腑鏂敜閱掑洖璋冨嚱鏁 +//瀹冨皢浼犲叆鐨勫洖璋冨嚱鏁拌祴鍊肩粰鍏ㄥ眬鍙橀噺g_intWakeupHook锛屼互渚垮湪涓柇鍞ら啋鏃惰皟鐢ㄨ鍥炶皟鍑芥暟 LITE_OS_SEC_TEXT_MINOR VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook) { g_intWakeupHook = hook; @@ -497,6 +516,8 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook) #endif /* Initialization of the hardware interrupt */ +//OsHwiInit鍑芥暟锛氱敤浜庡垵濮嬪寲纭欢涓柇 +//瀹冧細璋冪敤鍏蜂綋鐨勫钩鍙扮浉鍏冲嚱鏁版潵杩涜纭欢涓柇鐨勫垵濮嬪寲鎿嶄綔 LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID) { ArchIrqInit(); diff --git a/src/kernel/base/los_lockdep.c b/src/kernel/base/los_lockdep.c index 7c65cf1..b4826f0 100644 --- a/src/kernel/base/los_lockdep.c +++ b/src/kernel/base/los_lockdep.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*杩欐浠g爜鏄叧浜庨攣渚濊禆妫鏌ョ殑瀹炵幇銆傚寘鍚簡涓浜涘ご鏂囦欢鍜屽嚱鏁扮殑瀹氫箟锛岀敤浜庡湪澶氭牳绯荤粺涓娴嬮攣鐨勪娇鐢ㄦ儏鍐*/ #include "los_base.h" #include "los_spinlock.h" #include "los_task_pri.h" @@ -47,6 +47,8 @@ extern "C" { STATIC Atomic g_lockdepAvailable = 1; /* atomic insurance for lockdep check */ +//OsLockDepRequire锛氳鍑芥暟鐢ㄤ簬鑾峰彇閿佷緷璧栨鏌ョ殑鍘熷瓙鎿嶄綔锛岀‘淇濆湪杩涜閿佷緷璧栨鏌ユ椂涓嶄細琚腑鏂 +//鍘熷瓙鎿嶄綔鏄寚鍦ㄨ绠楁満绉戝涓紝涓嶄細琚腑鏂殑鎿嶄綔 STATIC INLINE VOID OsLockDepRequire(UINT32 *intSave) { *intSave = LOS_IntLock(); @@ -54,13 +56,13 @@ STATIC INLINE VOID OsLockDepRequire(UINT32 *intSave) /* busy waiting */ } } - +//OsLockDepRelease锛氶噴鏀鹃攣渚濊禆妫鏌ョ殑鍘熷瓙鎿嶄綔锛岀敤浜庡湪瀹屾垚閿佷緷璧栨鏌ュ悗鎭㈠姝e父鐨勪腑鏂姸鎬 STATIC INLINE VOID OsLockDepRelease(UINT32 intSave) { LOS_AtomicSet(&g_lockdepAvailable, 1); LOS_IntRestore(intSave); } - +//OsLockDepGetCycles锛氳幏鍙栧綋鍓 CPU 鐨勫懆鏈熻鏁板櫒鐨勫硷紝鐢ㄤ簬璁板綍閿佽姹傚拰閲婃斁鏃剁殑鏃堕棿鎴 STATIC INLINE UINT64 OsLockDepGetCycles(VOID) { UINT32 high, low; @@ -69,7 +71,7 @@ STATIC INLINE UINT64 OsLockDepGetCycles(VOID) /* combine cycleHi and cycleLo into 8 bytes cycles */ return (((UINT64)high << 32) + low); } - +//OsLockDepErrorStringGet锛氭牴鎹敊璇被鍨嬭繑鍥炲搴旂殑閿欒瀛楃涓诧紝鐢ㄤ簬鎵撳嵃閿欒淇℃伅 STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type) { CHAR *errorString = NULL; @@ -94,7 +96,7 @@ STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type) return errorString; } - +//OsLockDepPanic锛氬綋鍙戠敓涓ラ噸閿欒鏃惰Е鍙戠郴缁熺殑宕╂簝锛岄氬父鍦ㄦ娴嬪埌姝婚攣绛夋棤娉曚慨澶嶇殑鎯呭喌涓嬭皟鐢 WEAK VOID OsLockDepPanic(enum LockDepErrType errType) { /* halt here */ @@ -103,7 +105,7 @@ WEAK VOID OsLockDepPanic(enum LockDepErrType errType) OsBackTrace(); while (1) {} } - +//OsLockDepDumpLock锛氳緭鍑洪攣渚濊禆妫鏌ュけ璐ユ椂鐨勮皟璇曚俊鎭紝鍖呮嫭浠诲姟鍚嶃佷换鍔 ID銆丆PU 鍙风瓑锛屽苟鏈缁堣Е鍙戝穿婧 STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock, const VOID *requestAddr, enum LockDepErrType errType) { @@ -143,7 +145,7 @@ STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock, OsLockDepPanic(errType); } - +//OsLockDepCheckDependancy锛氭鏌ュ綋鍓嶄换鍔′笌閿佺殑鎵鏈夎呬箣闂存槸鍚﹀瓨鍦ㄤ緷璧栧叧绯伙紝浠ラ伩鍏嶆閿 STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, const LosTaskCB *lockOwner) { BOOL checkResult = TRUE; @@ -164,7 +166,7 @@ STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, const LosTaskCB * return checkResult; } - +//OsLockDepCheckIn锛氬湪璇锋眰閿佹椂杩涜渚濊禆妫鏌ワ紝璁板綍閿佺殑璇锋眰鍦板潃鍜岀瓑寰呮椂闂达紝濡傛鏌ュけ璐ュ垯瑙﹀彂宕╂簝 VOID OsLockDepCheckIn(const SPIN_LOCK_S *lock) { UINT32 intSave; @@ -217,7 +219,7 @@ OUT: OsLockDepRelease(intSave); } - +//OsLockDepRecord锛氳褰曟垚鍔熻幏鍙栭攣鐨勬椂闂存埑鍜屾寔鏈夎呬俊鎭紝骞舵洿鏂伴攣鐨勬墍鏈夎呭拰 CPU 鍙风瓑淇℃伅 VOID OsLockDepRecord(SPIN_LOCK_S *lock) { UINT32 intSave; @@ -250,7 +252,7 @@ VOID OsLockDepRecord(SPIN_LOCK_S *lock) OsLockDepRelease(intSave); } - +//OsLockDepCheckOut锛氬湪閲婃斁閿佹椂杩涜渚濊禆妫鏌ワ紝璁板綍鎸佹湁鏃堕棿骞舵竻闄ょ浉鍏充俊鎭紝濡傛鏌ュけ璐ュ垯瑙﹀彂宕╂簝 VOID OsLockDepCheckOut(SPIN_LOCK_S *lock) { UINT32 intSave; @@ -302,7 +304,8 @@ VOID OsLockDepCheckOut(SPIN_LOCK_S *lock) OUT: OsLockDepRelease(intSave); } - +//OsLockdepClearSpinlocks锛氭竻闄ゅ綋鍓嶄换鍔℃寔鏈夌殑鎵鏈夎嚜鏃嬮攣锛岄氬父鍦ㄧ郴缁熷浜庡紓甯哥姸鎬佷笅璋冪敤浠ョ‘淇濊В閿 +//鑷棆閿佹槸涓绉嶇敤浜庡绾跨▼鍚屾鐨勬満鍒躲傚湪浣跨敤鑷棆閿佹椂锛岀嚎绋嬩細鍙嶅妫鏌ラ攣鏄惁琚噴鏀撅紝濡傛灉閿佸凡缁忚鍗犵敤锛岀嚎绋嬪氨浼氫竴鐩村惊鐜瓑寰咃紝鐩村埌閿佽閲婃斁涓烘 VOID OsLockdepClearSpinlocks(VOID) { LosTaskCB *task = OsCurrTaskGet(); diff --git a/src/kernel/base/los_misc.c b/src/kernel/base/los_misc.c index 3cbe7fc..6e495c5 100644 --- a/src/kernel/base/los_misc.c +++ b/src/kernel/base/los_misc.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//鎿嶄綔绯荤粺鐨勫熀纭鍑芥暟 #include "los_task_pri.h" #include "los_misc_pri.h" #include "los_memory_pri.h" @@ -48,23 +48,23 @@ extern "C" { #endif /* __cplusplus */ #ifdef LOSCFG_LIB_CONFIGURABLE -LITE_OS_SEC_BSS UINT32 g_osSysClock; -LITE_OS_SEC_BSS UINT32 g_semLimit; -LITE_OS_SEC_BSS UINT32 g_muxLimit; -LITE_OS_SEC_BSS UINT32 g_queueLimit; - -LITE_OS_SEC_BSS UINT32 g_swtmrLimit; -LITE_OS_SEC_BSS UINT32 g_taskLimit; -LITE_OS_SEC_BSS UINT32 g_minusOneTickPerSecond; -LITE_OS_SEC_BSS UINT32 g_taskMinStkSize; -LITE_OS_SEC_BSS UINT32 g_taskIdleStkSize; -LITE_OS_SEC_BSS UINT32 g_taskSwtmrStkSize; -LITE_OS_SEC_BSS UINT32 g_taskDfltStkSize; -LITE_OS_SEC_BSS UINT32 g_timeSliceTimeOut; - -LITE_OS_SEC_DATA BOOL g_nxEnabled = FALSE; -LITE_OS_SEC_BSS UINTPTR g_dlNxHeapBase; -LITE_OS_SEC_BSS UINT32 g_dlNxHeapSize; +LITE_OS_SEC_BSS UINT32 g_osSysClock; //鎿嶄綔绯荤粺鐨勭郴缁熸椂閽熼鐜 +LITE_OS_SEC_BSS UINT32 g_semLimit; //淇″彿閲忕殑鏈澶ф暟閲忛檺鍒 +LITE_OS_SEC_BSS UINT32 g_muxLimit; //浜掓枼閿佺殑鏈澶ф暟閲忛檺鍒 +LITE_OS_SEC_BSS UINT32 g_queueLimit; //闃熷垪鏈澶ф暟閲忛檺鍒 + +LITE_OS_SEC_BSS UINT32 g_swtmrLimit; //杞欢瀹氭椂鍣ㄧ殑鏈澶ф暟閲忛檺鍒 +LITE_OS_SEC_BSS UINT32 g_taskLimit; //浠诲姟鐨勬渶澶ф暟閲忛檺鍒 +LITE_OS_SEC_BSS UINT32 g_minusOneTickPerSecond; //姣忕鍑忓幓鐨勬淮绛旀暟锛岀敤浜庢椂闂存埑璁$畻 +LITE_OS_SEC_BSS UINT32 g_taskMinStkSize;//浠诲姟鐨勬渶灏忓爢鏍堝ぇ灏 +LITE_OS_SEC_BSS UINT32 g_taskIdleStkSize; //绌洪棽浠诲姟鐨勫爢鏍堝ぇ灏 +LITE_OS_SEC_BSS UINT32 g_taskSwtmrStkSize; //杞欢瀹氭椂鍣ㄤ换鍔$殑鍫嗘爤澶у皬 +LITE_OS_SEC_BSS UINT32 g_taskDfltStkSize; //榛樿浠诲姟鐨勫爢鏍堝ぇ灏 +LITE_OS_SEC_BSS UINT32 g_timeSliceTimeOut; //鏃堕棿鐗囩殑瓒呮椂鏃堕棿 + +LITE_OS_SEC_DATA BOOL g_nxEnabled = FALSE; //鏄惁鍚敤浜嗗唴瀛樹繚鎶ゆ満鍒 +LITE_OS_SEC_BSS UINTPTR g_dlNxHeapBase; //鍔ㄦ佸姞杞藉簱鐨勫唴瀛樺爢璧峰鍦板潃 +LITE_OS_SEC_BSS UINT32 g_dlNxHeapSize; //鍔ㄦ佸姞杞藉簱鐨勫唴瀛樺爢澶у皬 #endif #ifdef LOSCFG_KERNEL_TRACE @@ -77,11 +77,12 @@ LMS_INIT_HOOK g_lmsMemInitHook = NULL; LMS_FUNC_HOOK g_lmsMallocHook = NULL; LMS_FUNC_HOOK g_lmsFreeHook = NULL; #endif +//LOS_Align锛氱敤浜庡皢缁欏畾鐨勫湴鍧鎸夋寚瀹氱殑杈圭晫瀵归綈锛岃繑鍥炲榻愬悗鐨勫湴鍧 LITE_OS_SEC_TEXT UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary) { return (addr + boundary - 1) & ~((UINTPTR)(boundary - 1)); } - +//OsDumpMemByte锛氱敤浜庝互瀛楄妭涓哄崟浣嶆墦鍗板唴瀛樹腑鐨勬暟鎹 LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs) { UINT32 interval; @@ -97,7 +98,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_Msleep(UINT32 msecs) (VOID)LOS_TaskDelay(interval); } - +//OsDumpMemByte锛氱敤浜庝互瀛楄妭涓哄崟浣嶆墦鍗板唴瀛樹腑鐨勬暟鎹 VOID OsDumpMemByte(size_t length, UINTPTR addr) { size_t dataLen; @@ -141,6 +142,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr) } #if defined(LOSCFG_DEBUG_SEMAPHORE) || defined(LOSCFG_DEBUG_MUTEX) || defined(LOSCFG_DEBUG_QUEUE) +//OsArraySort锛氬揩閫熸帓搴 VOID OsArraySort(UINT32 *sortArray, UINT32 start, UINT32 end, const SortParam *sortParam, OsCompareFunc compareFunc) { diff --git a/src/kernel/base/los_mp.c b/src/kernel/base/los_mp.c index d176a17..ba29cd8 100644 --- a/src/kernel/base/los_mp.c +++ b/src/kernel/base/los_mp.c @@ -25,7 +25,8 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*閽堝澶氬鐞嗗櫒锛圫MP锛夌郴缁熺殑鎿嶄綔绯荤粺鍐呮牳閮ㄥ垎鐨勫疄鐜 +涓昏鍖呮嫭浜嗗澶勭悊鍣ㄨ皟搴︺佷换鍔$鐞嗗拰涓柇澶勭悊绛夊姛鑳*/ #include "los_mp_pri.h" #include "los_task_pri.h" #include "los_percpu_pri.h" @@ -45,7 +46,7 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_mpCallSpin); #define MP_CALL_LOCK(state) LOS_SpinLockSave(&g_mpCallSpin, &(state)) #define MP_CALL_UNLOCK(state) LOS_SpinUnlockRestore(&g_mpCallSpin, (state)) #endif - +//LOS_MpSchedule锛氬澶勭悊鍣ㄨ皟搴﹀嚱鏁帮紝鐢ㄤ簬鍚戞寚瀹氱殑澶勭悊鍣ㄥ彂閫佽皟搴︿腑鏂 VOID LOS_MpSchedule(UINT32 target) { UINT32 ret; @@ -57,12 +58,12 @@ VOID LOS_MpSchedule(UINT32 target) } return; } - +//OsMpWakeHandler锛氬澶勭悊鍣ㄥ敜閱掑鐞嗗嚱鏁帮紝鐩墠涓虹┖瀹炵幇锛屾棤鐗瑰畾鎿嶄綔 VOID OsMpWakeHandler(VOID) { /* generic wakeup ipi, do nothing */ } - +//OsMpScheduleHandler锛氬澶勭悊鍣ㄨ皟搴﹀鐞嗗嚱鏁帮紝璁剧疆璋冨害鏍囧織浠ヨЕ鍙戣皟搴﹀櫒鍦ㄤ腑鏂粨鏉熸椂鎵ц璋冨害 VOID OsMpScheduleHandler(VOID) { /* @@ -71,7 +72,7 @@ VOID OsMpScheduleHandler(VOID) */ OsPercpuGet()->schedFlag = INT_PEND_RESCH; } - +//OsMpHaltHandler锛氬澶勭悊鍣ㄥ仠鏈哄鐞嗗嚱鏁帮紝灏嗗綋鍓嶅鐞嗗櫒鏍囪涓哄凡鍋滄満鐘舵侊紝骞惰繘鍏ユ寰幆 VOID OsMpHaltHandler(VOID) { (VOID)LOS_IntLock(); @@ -79,7 +80,7 @@ VOID OsMpHaltHandler(VOID) while (1) {} } - +//OsMpCollectTasks锛氬澶勭悊鍣ㄤ换鍔″洖鏀跺嚱鏁帮紝鐢ㄤ簬閫掑綊妫鏌ユ墍鏈夊彲鐢ㄤ换鍔★紝骞跺垹闄ゆ爣璁颁负闇瑕侀攢姣佺殑浠诲姟 VOID OsMpCollectTasks(VOID) { LosTaskCB *taskCB = NULL; @@ -109,6 +110,7 @@ VOID OsMpCollectTasks(VOID) } #ifdef LOSCFG_KERNEL_SMP_CALL +//OsMpFuncCall锛氬澶勭悊鍣ㄥ嚱鏁拌皟鐢ㄥ嚱鏁帮紝鐢ㄤ簬鍚戞寚瀹氱殑澶勭悊鍣ㄥ彂閫佸嚱鏁拌皟鐢ㄨ姹 VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args) { UINT32 index; @@ -144,7 +146,7 @@ VOID OsMpFuncCall(UINT32 target, SMP_FUNC_CALL func, VOID *args) } return; } - +//OsMpFuncCallHandler锛氬澶勭悊鍣ㄥ嚱鏁拌皟鐢ㄥ鐞嗗嚱鏁帮紝浠庢湰澶勭悊鍣ㄧ殑鍑芥暟璋冪敤闃熷垪涓彇鍑哄苟鎵ц鍑芥暟璋冪敤璇锋眰 VOID OsMpFuncCallHandler(VOID) { UINT32 intSave; @@ -166,7 +168,7 @@ VOID OsMpFuncCallHandler(VOID) } MP_CALL_UNLOCK(intSave); } - +//OsMpFuncCallInit锛氬澶勭悊鍣ㄥ嚱鏁拌皟鐢ㄥ垵濮嬪寲鍑芥暟锛岀敤浜庡垵濮嬪寲姣忎釜鏍稿績鐨勫嚱鏁拌皟鐢ㄩ槦鍒 VOID OsMpFuncCallInit(VOID) { UINT32 index; @@ -176,7 +178,7 @@ VOID OsMpFuncCallInit(VOID) } } #endif /* LOSCFG_KERNEL_SMP_CALL */ - +//OsMpInit锛氬澶勭悊鍣ㄥ垵濮嬪寲鍑芥暟锛屽寘鎷垱寤哄懆鏈熸ц蒋浠跺畾鏃跺櫒鍜屽垵濮嬪寲鍑芥暟璋冪敤闃熷垪绛 UINT32 OsMpInit(VOID) { UINT16 swtmrId; diff --git a/src/kernel/base/los_mux.c b/src/kernel/base/los_mux.c index 25dbacc..31bb6df 100644 --- a/src/kernel/base/los_mux.c +++ b/src/kernel/base/los_mux.c @@ -25,7 +25,8 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*浠g爜瀹炵幇浜嗕竴涓畝鍗曠殑浜掓枼閿侊紙Mutex锛夛紝鐢ㄤ簬淇濇姢鍏变韩璧勬簮鐨勮闂 +浜掓枼閿佺殑涓昏鍔熻兘鏄‘淇濆湪鍚屼竴鏃堕棿鍙湁涓涓嚎绋嬪彲浠ヨ闂淇濇姢鐨勪唬鐮佸潡鎴栧叡浜祫婧愶紝浠庤岄伩鍏嶅苟鍙戣闂紩鍙戠殑鏁版嵁绔炰簤鍜屼笉涓鑷存*/ #include "los_mux_pri.h" #include "los_mux_debug_pri.h" #include "los_bitmap.h" @@ -49,6 +50,7 @@ LITE_OS_SEC_DATA_INIT STATIC LOS_DL_LIST g_unusedMuxList; * Description : Initializes the mutex * Return : LOS_OK on success, or error code on failure */ +//OsMuxInit锛歁utex鍒濆鍖栧嚱鏁帮紝鐢ㄤ簬鍒濆鍖朚utex鏁版嵁缁撴瀯骞惰缃垵濮嬬姸鎬 LITE_OS_SEC_TEXT UINT32 OsMuxInit(VOID) { LosMuxCB *muxNode = NULL; @@ -74,7 +76,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxInit(VOID) } return LOS_OK; } - +//LOS_MuxCreate锛氬垱寤篗utex鍑芥暟锛岀敤浜庡垱寤轰竴涓柊鐨凪utex瀵硅薄锛屽苟杩斿洖鍏跺彞鏌 LITE_OS_SEC_TEXT UINT32 LOS_MuxCreate(UINT32 *muxHandle) { UINT32 intSave; @@ -113,7 +115,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxCreate(UINT32 *muxHandle) ERR_HANDLER: OS_RETURN_ERROR_P2(errLine, errNo); } - +//LOS_MuxDelete锛氬垹闄utex鍑芥暟锛岀敤浜庡垹闄ゆ寚瀹氱殑Mutex瀵硅薄鍙婂叾鐩稿叧璧勬簮 LITE_OS_SEC_TEXT UINT32 LOS_MuxDelete(UINT32 muxHandle) { UINT32 intSave; @@ -154,7 +156,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxDelete(UINT32 muxHandle) ERR_HANDLER: OS_RETURN_ERROR_P2(errLine, errNo); } - +//OsMuxParaCheck 鍑芥暟涓昏鐢ㄤ簬楠岃瘉浜掓枼閲忔搷浣滅殑鍙傛暟鏄惁鏈夋晥锛屽寘鎷簰鏂ラ噺鏄惁琚纭垱寤哄拰浼犲叆鐨勫彞鏌勬槸鍚︽湁鏁堬紝浠ュ強褰撳墠鏄惁澶勪簬涓柇涓婁笅鏂 LITE_OS_SEC_TEXT STATIC UINT32 OsMuxParaCheck(const LosMuxCB *muxCB, UINT32 muxHandle) { if ((muxCB->muxStat == LOS_UNUSED) || (muxCB->muxId != muxHandle)) { @@ -168,7 +170,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsMuxParaCheck(const LosMuxCB *muxCB, UINT32 muxH } return LOS_OK; } - +//OsMuxBitmapSet 鍑芥暟鐢ㄤ簬鍦ㄤ簰鏂ラ噺绛夊緟闃熷垪涓缃换鍔$殑浼樺厛绾т綅鍥撅紝骞舵牴鎹渶瑕佽皟鏁翠换鍔$殑浼樺厛绾э紝浠ョ‘淇濅换鍔″湪绛夊緟浜掓枼閲忔椂鑳藉姝g‘鍙嶆槧鍏朵紭鍏堢骇鍏崇郴 LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapSet(const LosTaskCB *runTask, const MuxBaseCB *muxPended) { if (muxPended->owner->priority > runTask->priority) { @@ -176,7 +178,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapSet(const LosTaskCB *runTask, const MuxB OsTaskPriModify(muxPended->owner, runTask->priority); } } - +//OsMuxBitmapRestore 鍑芥暟鐢ㄤ簬鎭㈠浠诲姟鐨勪紭鍏堢骇浣嶅浘锛屽苟鏍规嵁闇瑕佹洿鏂版嫢鏈夎呬换鍔$殑浼樺厛绾 LITE_OS_SEC_TEXT STATIC VOID OsMuxBitmapRestore(const LosTaskCB *runTask, LosTaskCB *owner) { UINT16 bitMapPri; @@ -244,7 +246,8 @@ LITE_OS_SEC_TEXT STATIC LOS_DL_LIST *OsMuxPendFindPos(const LosTaskCB *runTask, return node; } #endif - +//鎬讳綋鏉ヨ锛孫sMuxPostOp 鍑芥暟鐢ㄤ簬澶勭悊 Mutex 鐨勯噴鏀炬搷浣滐紝鍖呮嫭鍞ら啋绛夊緟浠诲姟銆佹洿鏂 Mutex 鐘舵佸拰鎸佹湁鑰呯瓑 +//纭繚 Mutex 鑳藉鎸夌収棰勬湡鐨勬柟寮忚姝g‘閲婃斁鍜屼紶閫掔粰涓嬩竴涓换鍔 LITE_OS_SEC_TEXT UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UINT32 timeout, UINT32 *intSave) { @@ -270,7 +273,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UI return ret; } - +//LOS_MuxPend锛氱瓑寰匨utex鍑芥暟锛岀敤浜庡皾璇曡幏鍙栨寚瀹歁utex鐨勮闂潈闄愩傚鏋淢utex宸茶鍏朵粬浠诲姟鎸佹湁锛屽垯褰撳墠浠诲姟浼氳鎸傝捣锛岀洿鍒癕utex鍙敤 LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout) { UINT32 ret; @@ -332,7 +335,7 @@ OUT_UNLOCK: } return ret; } - +//OsMuxPostOpSub:閫氳繃姣旇緝褰撳墠浠诲姟鍜 Mutex 绛夊緟闃熷垪涓殑浠诲姟鐨勪紭鍏堢骇锛屾潵璋冩暣褰撳墠浠诲姟鐨勪紭鍏堢骇浣嶅浘锛屽苟灏 Mutex 鎸佹湁鑰呯殑浼樺厛绾ф彁鍗 LITE_OS_SEC_TEXT STATIC VOID OsMuxPostOpSub(LosTaskCB *runTask, MuxBaseCB *muxPosted) { LosTaskCB *pendedTask = NULL; @@ -350,7 +353,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsMuxPostOpSub(LosTaskCB *runTask, MuxBaseCB *muxPo LOS_BitmapClr(&runTask->priBitMap, bitMapPri); OsTaskPriModify(muxPosted->owner, bitMapPri); } - +// LITE_OS_SEC_TEXT UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted) { LosTaskCB *resumedTask = NULL; @@ -386,7 +389,7 @@ LITE_OS_SEC_TEXT UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted) return MUX_SCHEDULE; } - +//LOS_MuxPost锛氶噴鏀綧utex鍑芥暟锛岀敤浜庨噴鏀惧綋鍓嶄换鍔″鎸囧畾Mutex鐨勮闂潈闄愶紝浠ヤ究鍏朵粬浠诲姟鍙互鑾峰彇璇utex LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle) { UINT32 ret; diff --git a/src/kernel/base/los_percpu.c b/src/kernel/base/los_percpu.c index 7110c08..c7e0782 100644 --- a/src/kernel/base/los_percpu.c +++ b/src/kernel/base/los_percpu.c @@ -33,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//瀹氫箟鍏ㄥ眬鍙橀噺鏁扮粍锛岀敤浜庡瓨鍌ㄦ瘡涓狢PU鏍稿績鐨勭鏈夋暟鎹 Percpu g_percpu[LOSCFG_KERNEL_CORE_NUM]; #ifdef __cplusplus diff --git a/src/kernel/base/los_printf.c b/src/kernel/base/los_printf.c index 6457a4d..7974cb3 100644 --- a/src/kernel/base/los_printf.c +++ b/src/kernel/base/los_printf.c @@ -32,7 +32,7 @@ * It should not add OS inner invocation, which is not allowed to be accessed in user space. * But it's allowed to invoke syscall interface. *---------------------------------------------------------------------------- */ - +/*杩欐浠g爜鏄竴涓緭鍑烘帶鍒舵ā鍧楋紝鏍规嵁涓嶅悓鐨勮緭鍑虹被鍨嬪皢瀛楃涓茶緭鍑哄埌涓嶅悓鐨勮澶囦笂*/ #ifdef LOSCFG_LIB_LIBC #include "unistd.h" #endif @@ -62,13 +62,13 @@ typedef enum { CONSOLE_OUTPUT = 2, EXC_OUTPUT = 3 } OutputType; - +//ErrorMsg锛氱敤浜庤緭鍑洪敊璇俊鎭紝褰撳瓧绗︿覆杈撳嚭闈炴硶鎴栬卾snprintf_s鍑芥暟澶辫触鏃惰皟鐢 STATIC VOID ErrorMsg(VOID) { const CHAR *p = "Output illegal string! vsnprintf_s failed!\n"; UartPuts(p, (UINT32)strlen(p), UART_WITH_LOCK); } - +//UartOutput锛氬疄闄呭皢瀛楃涓茶緭鍑哄埌涓插彛鐨勫嚱鏁帮紝鏍规嵁閰嶇疆鍙兘浼氳繘琛屼竴浜涢澶栫殑澶勭悊 STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock) { #ifdef LOSCFG_SHELL_DMESG @@ -82,7 +82,7 @@ STATIC VOID UartOutput(const CHAR *str, UINT32 len, BOOL isLock) UartPuts(str, len, isLock); #endif } - +//OutputControl锛氭牴鎹緭鍑虹被鍨嬮夋嫨鐩稿簲鐨勮緭鍑鸿澶囷紝骞惰皟鐢ㄥ搴旂殑杈撳嚭鍑芥暟 STATIC VOID OutputControl(const CHAR *str, UINT32 len, OutputType type) { switch (type) { @@ -105,14 +105,14 @@ STATIC VOID OutputControl(const CHAR *str, UINT32 len, OutputType type) } return; } - +//OsVprintfFree锛氶噴鏀惧姩鎬佸垎閰嶇殑缂撳啿鍖哄唴瀛 STATIC VOID OsVprintfFree(CHAR *buf, UINT32 bufLen) { if (bufLen != SIZEBUF) { (VOID)LOS_MemFree(m_aucSysMem0, buf); } } - +//OsVprintf锛氭牳蹇冨嚱鏁帮紝鏍规嵁缁欏畾鐨勬牸寮忓寲瀛楃涓插拰鍙彉鍙傛暟锛岃繘琛屽瓧绗︿覆鏍煎紡鍖栧苟杈撳嚭鍒扮浉搴旂殑璁惧 STATIC VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type) { INT32 len; @@ -156,7 +156,7 @@ STATIC VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type) OutputControl(bBuf, len, type); OsVprintfFree(bBuf, bufLen); } - +//UartVprintf銆丆onsoleVprintf銆乁artPrintf銆乨printf銆丩kDprintf銆丏mesgPrintf銆丒xcPrintf銆丳rintExcInfo锛氳繖浜涘嚱鏁伴兘鏄OsVprintf鐨勫皝瑁咃紝鎻愪緵浜嗕笉鍚岀殑杈撳嚭鎺ュ彛锛屽湪涓嶅悓鐨勫満鏅笅璋冪敤OsVprintf鏉ュ畬鎴愬瓧绗︿覆鐨勬牸寮忓寲鍜岃緭鍑 VOID UartVprintf(const CHAR *fmt, va_list ap) { OsVprintf(fmt, ap, UART_OUTPUT); diff --git a/src/kernel/base/los_queue.c b/src/kernel/base/los_queue.c index f6804c0..3a7e9a6 100644 --- a/src/kernel/base/los_queue.c +++ b/src/kernel/base/los_queue.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//瀹炵幇浜嗕竴涓熀浜庤交閲忕骇鎿嶄綔绯荤粺鐨勯槦鍒楃鐞嗘ā鍧楋紝鎻愪緵浜嗛槦鍒楃殑鍒涘缓銆佽鍐欍佸垹闄や互鍙婁俊鎭幏鍙栫瓑鍔熻兘 #include "los_queue_pri.h" #include "los_queue_debug_pri.h" #include "los_task_pri.h" @@ -53,6 +53,7 @@ LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList; * Description : queue initial * Return : LOS_OK on success or error code on failure */ +//鍒濆鍖栭槦鍒楋紝杩斿洖鎴愬姛鎴栧け璐ラ敊璇爜 LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID) { LosQueueCB *queueNode = NULL; @@ -78,7 +79,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID) } return LOS_OK; } - +//OsQueueCreateParameterCheck鍑芥暟鐢ㄤ簬妫鏌ュ垱寤洪槦鍒楁椂浼犲叆鐨勫弬鏁版槸鍚﹀悎娉 STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queueId, UINT16 maxMsgSize) { if (queueId == NULL) { @@ -94,7 +95,7 @@ STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queue } return LOS_OK; } - +//OsQueueCreateInternal鍑芥暟鐢ㄤ簬鍒涘缓闃熷垪锛屽寘鎷湪闃熷垪鎺у埗鍧椾腑璁板綍闃熷垪闀垮害銆佹秷鎭ぇ灏忕瓑淇℃伅 LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsQueueCreateInternal(UINT16 len, UINT32 *queueId, UINT16 msgSize, UINT8 *queue, UINT8 queueMemType) { @@ -165,7 +166,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreateStatic(const CHAR *queueName, return OsQueueCreateInternal(len, queueId, msgSize, queueMem, OS_QUEUE_ALLOC_STATIC); } #endif - +//鍒涘缓闃熷垪 LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len, UINT32 *queueId, UINT32 flags, UINT16 maxMsgSize) { @@ -198,7 +199,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len, return LOS_OK; } - +//OsQueueReadParameterCheck鍜孫sQueueWriteParameterCheck鍒嗗埆鐢ㄤ簬妫鏌ヨ鍜屽啓鎿嶄綔鐨勫弬鏁板悎娉曟 LITE_OS_SEC_TEXT STATIC UINT32 OsQueueReadParameterCheck(UINT32 queueId, const VOID *bufferAddr, const UINT32 *bufferSize, UINT32 timeout) { @@ -248,7 +249,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsQueueWriteParameterCheck(UINT32 queueId, const } return LOS_OK; } - +//瀹炵幇浜嗛槦鍒楃殑璇诲彇鍜屽啓鍏ユ搷浣滐紝骞跺鍙兘鍑虹幇鐨勯敊璇繘琛屼簡澶勭悊 STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize) { UINT8 *queueNode = NULL; @@ -296,7 +297,7 @@ STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID } return LOS_OK; } - +//鐢ㄤ簬澶勭悊闃熷垪鎿嶄綔鍑芥暟 OsQueueBufferOperate 杩斿洖鐨勯敊璇爜,浣垮緱鍦ㄥ彂鐢熼敊璇椂鑳藉鎵撳嵃鐩稿簲鐨勯敊璇俊鎭 STATIC VOID OsQueueBufferOperateErrProcess(UINT32 errorCode) { switch (errorCode) { @@ -336,7 +337,7 @@ STATIC UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 queueId } return LOS_OK; } - +//OsQueueOperate:瀹炵幇浜嗗闃熷垪鐨勬搷浣滐紝鍖呮嫭鍙傛暟妫鏌ャ佷换鍔℃寕璧蜂笌鍞ら啋浠ュ強閿欒澶勭悊绛夊姛鑳 STATIC UINT32 OsQueueOperate(UINT32 queueId, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout) { LosQueueCB *queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueId); @@ -400,7 +401,7 @@ QUEUE_END: OsQueueBufferOperateErrProcess(errorCode); return ret; } - +//LOS_QueueReadCopy锛氫粠闃熷垪涓鍙栨暟鎹紝閫氳繃鍙傛暟妫鏌ュ悗璋冪敤OsQueueOperate鍑芥暟杩涜瀹為檯鐨勮鍙栨搷浣 LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId, VOID *bufferAddr, UINT32 *bufferSize, @@ -417,7 +418,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId, operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD); return OsQueueOperate(queueId, operateType, bufferAddr, bufferSize, timeout); } - +//LOS_QueueWriteHeadCopy锛氬悜闃熷垪鐨勫ご閮ㄥ啓鍏ユ暟鎹紝閫氳繃鍙傛暟妫鏌ュ悗璋冪敤OsQueueOperate鍑芥暟杩涜瀹為檯鐨勫啓鍏ユ搷浣 LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, @@ -434,7 +435,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId, operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD); return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout); } - +//LOS_QueueWriteCopy锛氬悜闃熷垪鐨勫熬閮ㄥ啓鍏ユ暟鎹紝閫氳繃鍙傛暟妫鏌ュ悗璋冪敤OsQueueOperate鍑芥暟杩涜瀹為檯鐨勫啓鍏ユ搷浣 LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, @@ -451,12 +452,12 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId, operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL); return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout); } - +//LOS_QueueRead锛氫粠闃熷垪涓鍙栨暟鎹殑绠鍖栨帴鍙o紝鐩存帴璋冪敤LOS_QueueReadCopy鍑芥暟 LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout) { return LOS_QueueReadCopy(queueId, bufferAddr, &bufferSize, timeout); } - +//LOS_QueueWrite锛氬悜闃熷垪涓啓鍏ユ暟鎹殑绠鍖栨帴鍙o紝鍏堣繘琛屽弬鏁版鏌ワ紝鐒跺悗璋冪敤LOS_QueueWriteCopy鍑芥暟 LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout) { if (bufferAddr == NULL) { @@ -465,7 +466,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize = sizeof(CHAR *); return LOS_QueueWriteCopy(queueId, &bufferAddr, bufferSize, timeout); } - +//LOS_QueueWriteHead锛氬悜闃熷垪澶撮儴鍐欏叆鏁版嵁鐨勭畝鍖栨帴鍙o紝鍏堣繘琛屽弬鏁版鏌ワ紝鐒跺悗璋冪敤LOS_QueueWriteHeadCopy鍑芥暟 LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, @@ -477,7 +478,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId, bufferSize = sizeof(CHAR *); return LOS_QueueWriteHeadCopy(queueId, &bufferAddr, bufferSize, timeout); } - +//LOS_QueueDelete锛氬垹闄ら槦鍒楃殑鍑芥暟 +//棣栧厛妫鏌ラ槦鍒楁槸鍚﹀瓨鍦紝濡傛灉瀛樺湪鍒欐鏌ユ槸鍚︽湁浠诲姟姝e湪浣跨敤闃熷垪鎴栬呴槦鍒椾腑杩樻湁鏈噴鏀剧殑鍐呭瓨鍧楋紝濡傛灉婊¤冻鏉′欢鍒欓噴鏀鹃槦鍒楁墍鍗犵敤鐨勮祫婧 LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueId) { LosQueueCB *queueCB = NULL; @@ -537,7 +539,7 @@ QUEUE_END: SCHEDULER_UNLOCK(intSave); return ret; } - +//LOS_QueueInfoGet:鑾峰彇鎸囧畾闃熷垪鐨勭浉鍏充俊鎭紝鍖呮嫭闃熷垪ID銆侀槦鍒楅暱搴︺侀槦鍒楀ぇ灏忋侀槦鍒楀ご灏炬寚閽堛佺瓑寰呰鍙栧拰鍐欏叆鐨勪换鍔℃暟绛 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueId, QUEUE_INFO_S *queueInfo) { UINT32 intSave; @@ -595,6 +597,9 @@ QUEUE_END: * : timeout --- Expiry time. The value range is [0,LOS_WAIT_FOREVER] * Return : pointer if success otherwise NULL */ +//OsQueueMailAlloc鍑芥暟鐢ㄦ潵浠庨偖浠舵睜涓垎閰嶄竴涓偖浠跺唴瀛樺潡 +//濡傛灉娌℃湁鍙敤鐨勫唴瀛樺潡锛屽垯鏍规嵁瓒呮椂鏃堕棿鎸傝捣褰撳墠浠诲姟锛屽苟灏嗗叾鍔犲叆鍒扮瓑寰呭唴瀛樺潡鐨勪换鍔¢摼琛ㄤ腑 +//褰撴湁鍐呭瓨鍧楀彲鐢ㄦ椂锛屼細灏嗕换鍔′粠浠诲姟閾捐〃涓Щ闄わ紝骞惰繑鍥炲垎閰嶇殑鍐呭瓨鍧楁寚閽 LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueId, VOID *mailPool, UINT32 timeout) { VOID *mem = NULL; @@ -663,6 +668,8 @@ END: * : mailMem --- The mail memory block address * Return : LOS_OK on success or error code on failure */ +//OsQueueMailFree鍑芥暟鐢ㄦ潵閲婃斁鎸囧畾鐨勯偖浠跺唴瀛樺潡锛屽苟灏嗗叾鍔犲叆鍒伴偖浠舵睜鐨勭┖闂查摼琛ㄤ腑 +//濡傛灉鏈変换鍔″湪绛夊緟鍐呭瓨鍧楋紝鍒欎細浠庝换鍔¢摼琛ㄤ腑鍞ら啋涓涓换鍔★紝骞跺皢鍏朵粠浠诲姟閾捐〃涓Щ闄 LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueId, VOID *mailPool, VOID *mailMem) { VOID *mem = NULL; diff --git a/src/kernel/base/los_ringbuf.c b/src/kernel/base/los_ringbuf.c index c33ea3f..524cea8 100644 --- a/src/kernel/base/los_ringbuf.c +++ b/src/kernel/base/los_ringbuf.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*瀹炵幇鐜舰缂撳啿鍖恒傜幆褰㈢紦鍐插尯鏄竴绉嶅惊鐜娇鐢ㄥ浐瀹氬ぇ灏忓瓨鍌ㄧ┖闂寸殑鏁版嵁缁撴瀯锛屽父鐢ㄤ簬瑙e喅鐢熶骇鑰-娑堣垂鑰呴棶棰*/ #include "los_ringbuf.h" #ifdef __cplusplus @@ -33,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//LOS_RingbufUsedSize锛氳幏鍙栫幆褰㈢紦鍐插尯宸蹭娇鐢ㄧ殑澶у皬 UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf) { UINT32 size; @@ -56,6 +56,7 @@ UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf) * | * endIdx */ +//OsRingbufWriteLinear锛氱嚎鎬у啓鍏ユ暟鎹埌鐜舰缂撳啿鍖 STATIC UINT32 OsRingbufWriteLinear(Ringbuf *ringbuf, const CHAR *buf, UINT32 size) { UINT32 cpSize; @@ -77,7 +78,7 @@ STATIC UINT32 OsRingbufWriteLinear(Ringbuf *ringbuf, const CHAR *buf, UINT32 siz return cpSize; } - +//OsRingbufWriteLoop锛氬惊鐜啓鍏ユ暟鎹埌鐜舰缂撳啿鍖 STATIC UINT32 OsRingbufWriteLoop(Ringbuf *ringbuf, const CHAR *buf, UINT32 size) { UINT32 right, cpSize; @@ -105,7 +106,7 @@ STATIC UINT32 OsRingbufWriteLoop(Ringbuf *ringbuf, const CHAR *buf, UINT32 size) return cpSize; } - +//LOS_RingbufWrite锛氬悜鐜舰缂撳啿鍖哄啓鍏ユ暟鎹 UINT32 LOS_RingbufWrite(Ringbuf *ringbuf, const CHAR *buf, UINT32 size) { UINT32 cpSize = 0; @@ -130,7 +131,7 @@ EXIT: LOS_SpinUnlockRestore(&ringbuf->lock, intSave); return cpSize; } - +//OsRingbufReadLinear锛氱嚎鎬ц鍙栫幆褰㈢紦鍐插尯涓殑鏁版嵁 STATIC UINT32 OsRingbufReadLinear(Ringbuf *ringbuf, CHAR *buf, UINT32 size) { UINT32 cpSize, remain; @@ -153,7 +154,7 @@ STATIC UINT32 OsRingbufReadLinear(Ringbuf *ringbuf, CHAR *buf, UINT32 size) return cpSize; } - +//OsRingbufReadLoop锛氬惊鐜鍙栫幆褰㈢紦鍐插尯涓殑鏁版嵁 STATIC UINT32 OsRingbufReadLoop(Ringbuf *ringbuf, CHAR *buf, UINT32 size) { UINT32 right, cpSize; @@ -179,7 +180,7 @@ STATIC UINT32 OsRingbufReadLoop(Ringbuf *ringbuf, CHAR *buf, UINT32 size) return cpSize; } - +//LOS_RingbufRead锛氫粠鐜舰缂撳啿鍖鸿鍙栨暟鎹 UINT32 LOS_RingbufRead(Ringbuf *ringbuf, CHAR *buf, UINT32 size) { UINT32 cpSize; @@ -205,7 +206,7 @@ EXIT: LOS_SpinUnlockRestore(&ringbuf->lock, intSave); return cpSize; } - +//LOS_RingbufInit锛氬垵濮嬪寲鐜舰缂撳啿鍖 UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size) { if ((ringbuf == NULL) || (fifo == NULL) || @@ -221,7 +222,7 @@ UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size) ringbuf->status = RBUF_INITED; return LOS_OK; } - +//LOS_RingbufReset锛氶噸缃幆褰㈢紦鍐插尯 VOID LOS_RingbufReset(Ringbuf *ringbuf) { UINT32 intSave; diff --git a/src/kernel/base/los_sem.c b/src/kernel/base/los_sem.c index 8703827..867babf 100644 --- a/src/kernel/base/los_sem.c +++ b/src/kernel/base/los_sem.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*瀹炵幇淇″彿閲忕殑鎿嶄綔绯荤粺鍐呮牳浠g爜锛屼富瑕佸寘鎷俊鍙烽噺鐨勫垱寤恒佸垹闄ゃ佺瓑寰咃紙Pend锛夊拰閲婃斁锛圥ost锛夌瓑鎿嶄綔*/ #include "los_sem_pri.h" #include "los_sem_debug_pri.h" #include "los_err_pri.h" @@ -49,7 +49,7 @@ STATIC_INLINE VOID OsSemNodeRecycle(LosSemCB *semNode) semNode->semStat = LOS_UNUSED; LOS_ListTailInsert(&g_unusedSemList, &semNode->semList); } - +//OsSemInit()鍑芥暟:鐢ㄤ簬鍒濆鍖栦俊鍙烽噺绠$悊妯″潡锛屽寘鎷敵璇峰垱寤轰俊鍙烽噺鎵闇瑕佺殑鍐呭瓨绌洪棿銆佸皢淇″彿閲忕粨鏋勪綋鍔犲叆鍒版湭浣跨敤閾捐〃涓瓑 LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID) { LosSemCB *semNode = NULL; @@ -74,7 +74,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID) } return LOS_OK; } - +//OsSemCreate鍑芥暟:鐢ㄤ簬鍒涘缓涓涓俊鍙烽噺锛屽苟灏嗗叾鍔犲叆鍒板凡浣跨敤淇″彿閲忓垪琛ㄤ腑 +//鍙傛暟count琛ㄧず淇″彿閲忕殑鍒濆鍊硷紝type琛ㄧず淇″彿閲忕殑绫诲瀷锛堣鏁颁俊鍙烽噺鎴栦簩杩涘埗淇″彿閲忥級锛宻emHandle鐢ㄤ簬杩斿洖鍒涘缓鐨勪俊鍙烽噺鐨勫彞鏌 LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsSemCreate(UINT16 count, UINT8 type, UINT32 *semHandle) { UINT32 intSave; @@ -109,7 +110,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsSemCreate(UINT16 count, UINT8 type, UINT32 LOS_TRACE(SEM_CREATE, semCreated->semId, type, count); return LOS_OK; } - +//LOS_SemCreate:瀵瑰閮ㄦ彁渚涚殑鎺ュ彛鍑芥暟锛岀敤浜庡垱寤轰竴涓鏁颁俊鍙烽噺 LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle) { if (count > LOS_SEM_COUNT_MAX) { @@ -117,7 +118,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle) } return OsSemCreate(count, OS_SEM_COUNTING, semHandle); } - +//LOS_BinarySemCreate:瀵瑰閮ㄦ彁渚涚殑鎺ュ彛鍑芥暟锛岀敤浜庡垱寤轰竴涓簩杩涘埗淇″彿閲 LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle) { if (count > OS_SEM_BINARY_COUNT_MAX) { @@ -125,7 +126,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle } return OsSemCreate(count, OS_SEM_BINARY, semHandle); } - +//OsSemStateVerify:鐢ㄤ簬楠岃瘉淇″彿閲忕殑鐘舵佹槸鍚︽湁鏁 +//鍙傛暟semId琛ㄧず瑕侀獙璇佺殑淇″彿閲忕殑ID锛宻emNode鏄寚鍚戜俊鍙烽噺鎺у埗鍧楃殑鎸囬拡 STATIC_INLINE UINT32 OsSemStateVerify(UINT32 semId, const LosSemCB *semNode) { #ifndef LOSCFG_RESOURCE_ID_NOT_USE_HIGH_BITS @@ -137,7 +139,8 @@ STATIC_INLINE UINT32 OsSemStateVerify(UINT32 semId, const LosSemCB *semNode) } return LOS_OK; } - +//OsSemGetCBWithCheck:鐢ㄤ簬鏍规嵁淇″彿閲忓彞鏌勮幏鍙栦俊鍙烽噺鐨勬帶鍒跺潡 +//鍙傛暟semHandle琛ㄧず淇″彿閲忕殑鍙ユ焺锛宻emCB鏄竴涓寚鍚戞寚閽堢殑鎸囬拡锛岀敤浜庤繑鍥炶幏鍙栧埌鐨勪俊鍙烽噺鎺у埗鍧 STATIC UINT32 OsSemGetCBWithCheck(UINT32 semHandle, LosSemCB **semCB) { if (GET_SEM_INDEX(semHandle) >= (UINT32)KERNEL_SEM_LIMIT) { @@ -147,7 +150,7 @@ STATIC UINT32 OsSemGetCBWithCheck(UINT32 semHandle, LosSemCB **semCB) *semCB = GET_SEM(semHandle); return LOS_OK; } - +//LOS_SemDelete:鐢ㄤ簬鍒犻櫎鎸囧畾鍙ユ焺鐨勪俊鍙烽噺锛屽鏋滄湁浠诲姟姝e湪绛夊緟璇ヤ俊鍙烽噺锛屽垯鍒犻櫎澶辫触 LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle) { UINT32 intSave; @@ -184,7 +187,7 @@ OUT: LOS_TRACE(SEM_DELETE, semHandle, ret); return ret; } - +//LOS_SemPend:鐢ㄤ簬绛夊緟锛圥end锛変竴涓俊鍙烽噺锛屽鏋滀俊鍙烽噺涓嶅彲鐢紝鍒欓樆濉炲綋鍓嶄换鍔$洿鍒颁俊鍙烽噺鍙敤鎴栬秴鏃躲倀imeout琛ㄧず瓒呮椂鏃堕棿 LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout) { UINT32 intSave; @@ -252,7 +255,7 @@ OUT: SCHEDULER_UNLOCK(intSave); return ret; } - +//LOS_SemPost:鐢ㄤ簬閲婃斁锛圥ost锛変竴涓俊鍙烽噺锛屼娇鍏跺彉涓哄彲鐢ㄧ姸鎬侊紝骞跺敜閱掔瓑寰呰淇″彿閲忕殑浠诲姟涓殑绗竴涓换鍔 LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle) { UINT32 intSave; diff --git a/src/kernel/base/los_sortlink.c b/src/kernel/base/los_sortlink.c index e39fdbc..e934398 100644 --- a/src/kernel/base/los_sortlink.c +++ b/src/kernel/base/los_sortlink.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*宓屽叆寮忔搷浣滅郴缁熶腑涓庝换鍔¤皟搴︾浉鍏崇殑鎺掑簭閾捐〃绠$悊浠g爜銆傚寘鎷簡瀵规帓搴忛摼琛ㄧ殑鍒濆鍖栥佸悜鎺掑簭閾捐〃涓坊鍔犺妭鐐广佷粠鎺掑簭閾捐〃涓垹闄よ妭鐐广佽幏鍙栦笅涓涓秴鏃舵椂闂寸瓑鎿嶄綔*/ #include "los_sortlink_pri.h" #include "los_memory.h" #include "los_exc.h" @@ -39,7 +39,7 @@ extern "C" { #define OS_INVALID_VALUE 0xFFFFFFFF #ifdef LOSCFG_BASE_CORE_USE_MULTI_LIST - +//OsSortLinkInit锛氬垵濮嬪寲鎺掑簭閾捐〃锛屼负鎺掑簭閾捐〃鐨勫ご鑺傜偣鍒嗛厤鍐呭瓨锛屽苟杩涜鍒濆鍖 LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader) { UINT32 size; @@ -60,7 +60,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader) } return LOS_OK; } - +//OsAdd2SortLink锛氬皢涓涓妭鐐规坊鍔犲埌鎺掑簭閾捐〃涓紝鏍规嵁鑺傜偣鐨勮秴鏃舵椂闂磋绠楄妭鐐瑰湪鎺掑簭閾捐〃涓殑浣嶇疆锛岀劧鍚庢彃鍏ュ埌鐩稿簲浣嶇疆 LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) { SortLinkList *listSorted = NULL; @@ -106,7 +106,7 @@ LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, So LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode); } } - +//OsCheckSortLink锛氭鏌ユ帓搴忛摼琛ㄦ槸鍚﹀悎娉曪紝鎺掗櫎寰幆寮曠敤鍜屾棤鏁堣妭鐐 LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode) { LOS_DL_LIST *tmp = listNode->pstPrev; @@ -122,7 +122,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const /* delete invalid sortlink node */ OsBackTrace(); } - +//OsDeleteSortLink锛氫粠鎺掑簭閾捐〃涓垹闄や竴涓妭鐐癸紝鐒跺悗鏇存柊鐩搁偦鑺傜偣鐨勮秴鏃舵椂闂 LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) { LOS_DL_LIST *listObject = NULL; @@ -141,7 +141,7 @@ LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, } LOS_ListDelete(&sortList->sortLinkNode); } - +//OsCalcExpierTime锛氭牴鎹綋鍓嶇殑鎺掑簭閾捐〃娓告爣鍜岃妭鐐圭殑浣嶇疆璁$畻瓒呮椂鏃堕棿 LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 sortIndex, UINT16 curSortIndex) { UINT32 expireTime; @@ -154,7 +154,7 @@ LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 so expireTime = ((rollNum - 1) << OS_TSK_SORTLINK_LOGLEN) + sortIndex; return expireTime; } - +//OsSortLinkGetNextExpireTime锛氳幏鍙栨帓搴忛摼琛ㄤ腑涓嬩竴涓秴鏃舵椂闂存渶灏忕殑鑺傜偣鐨勮秴鏃舵椂闂 LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader) { UINT16 cursor; @@ -184,7 +184,7 @@ LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sor return expireTime; } - +//OsSortLinkUpdateExpireTime锛氭洿鏂版帓搴忛摼琛ㄤ腑鎵鏈夎妭鐐圭殑瓒呮椂鏃堕棿锛屽苟鏇存柊娓告爣 LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader) { SortLinkList *sortList = NULL; @@ -215,7 +215,7 @@ LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttr } sortLinkHeader->cursor = (sortLinkHeader->cursor + sleepTicks - 1) % OS_TSK_SORTLINK_LEN; } - +//OsSortLinkGetTargetExpireTime锛氳幏鍙栫洰鏍囪妭鐐圭殑瓒呮椂鏃堕棿 LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader, const SortLinkList *targetSortList) { @@ -235,7 +235,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttrib } #else /* LOSCFG_BASE_CORE_USE_SINGLE_LIST */ - +//OsSortLinkInit:鍒濆鍖栨帓搴忛摼琛ㄥご閮 LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader) { UINT32 size; @@ -252,7 +252,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader) LOS_ListInit(listObject); return LOS_OK; } - +//OsAdd2SortLink:鍚戞帓搴忛摼琛ㄤ腑娣诲姞鍏冪礌 LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) { SortLinkList *listSorted = NULL; @@ -286,7 +286,7 @@ LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, So LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode); } } - +//OsCheckSortLink:妫鏌ユ帓搴忛摼琛ㄧ殑鏈夋晥鎬э紝鐢ㄤ簬鍐呴儴璋冪敤 LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode) { LOS_DL_LIST *tmp = listNode->pstPrev; @@ -302,7 +302,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const /* delete invalid sortlink node */ OsBackTrace(); } - +//OsDeleteSortLink:浠庢帓搴忛摼琛ㄤ腑鍒犻櫎鎸囧畾鍏冪礌 LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList) { LOS_DL_LIST *listObject = NULL; @@ -319,7 +319,7 @@ LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, } LOS_ListDelete(&sortList->sortLinkNode); } - +//OsSortLinkGetNextExpireTime:鑾峰彇鎺掑簭閾捐〃涓笅涓涓埌鏈熺殑鏃堕棿 LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader) { UINT32 expireTime = OS_INVALID_VALUE; @@ -333,7 +333,7 @@ LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sor } return expireTime; } - +//OsSortLinkUpdateExpireTime:鏇存柊鎺掑簭閾捐〃涓埌鏈熸椂闂 LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader) { SortLinkList *sortList = NULL; @@ -349,7 +349,7 @@ LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttr ROLLNUM_SUB(sortList->idxRollNum, sleepTicks - 1); } } - +//OsSortLinkGetTargetExpireTime:鑾峰彇鎸囧畾鎺掑簭閾捐〃鍏冪礌鐨勫埌鏈熸椂闂 LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader, const SortLinkList *targetSortList) { diff --git a/src/kernel/base/los_stackinfo.c b/src/kernel/base/los_stackinfo.c index 9f90a6c..feb3da6 100644 --- a/src/kernel/base/los_stackinfo.c +++ b/src/kernel/base/los_stackinfo.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//鏍 #include "securec.h" #include "los_stackinfo_pri.h" #ifdef LOSCFG_SHELL @@ -35,7 +35,7 @@ const StackInfo *g_stackInfo = NULL; UINT32 g_stackNum; - +//OsStackWaterLineGet:鑾峰彇鏍堢殑浣跨敤鎯呭喌 UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed) { UINT32 size; @@ -53,20 +53,20 @@ UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, return LOS_NOK; } } - +//OsExcStackInfoReg:娉ㄥ唽寮傚父鏍堜俊鎭 VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum) { g_stackInfo = stackInfo; g_stackNum = stackNum; } - +//OsStackInit:鍒濆鍖栦换鍔℃爤 VOID OsStackInit(VOID *stacktop, UINT32 stacksize) { /* initialize the task stack, write magic num to stack top */ (VOID)memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize); *((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD; } - +//OsGetStackInfo:鑾峰彇鏍堜俊鎭 VOID OsGetStackInfo(const StackInfo **stackInfo, UINT32 *stackNum) { *stackInfo = g_stackInfo; diff --git a/src/kernel/base/los_swtmr.c b/src/kernel/base/los_swtmr.c index 052e6ff..393f3d7 100644 --- a/src/kernel/base/los_swtmr.c +++ b/src/kernel/base/los_swtmr.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*杞欢瀹氭椂鍣ㄧ殑瀹炵幇锛屾秹鍙婅蒋浠跺畾鏃跺櫒鐨勫垱寤恒佸惎鍔ㄣ佸仠姝€佸垹闄ょ瓑鎿嶄綔*/ #include "los_swtmr_pri.h" #include "los_sortlink_pri.h" #include "los_queue_pri.h" @@ -52,6 +52,7 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_swtmrSpin); * Description: Start Software Timer * Input : swtmr --- Need to start software timer */ +//OsSwtmrStart锛氬惎鍔ㄨ蒋浠跺畾鏃跺櫒 LITE_OS_SEC_TEXT VOID OsSwtmrStart(LosSwtmrCB *swtmr) { if ((swtmr->overrun == 0) && ((swtmr->mode == LOS_SWTMR_MODE_ONCE) || @@ -75,13 +76,14 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(LosSwtmrCB *swtmr) * Description: Delete Software Timer * Input : swtmr --- Need to delete software timer, When using, Ensure that it can't be NULL. */ +//OsSwtmrDelete锛氬垹闄よ蒋浠跺畾鏃跺櫒 STATIC INLINE VOID OsSwtmrDelete(LosSwtmrCB *swtmr) { /* insert to free list */ LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->sortList.sortLinkNode); swtmr->state = OS_SWTMR_STATUS_UNUSED; } - +//OsSwtmrUpdate锛氭洿鏂拌蒋浠跺畾鏃跺櫒 STATIC INLINE VOID OsSwtmrUpdate(LosSwtmrCB *swtmr) { if (swtmr->mode == LOS_SWTMR_MODE_ONCE) { @@ -101,6 +103,7 @@ STATIC INLINE VOID OsSwtmrUpdate(LosSwtmrCB *swtmr) } #ifndef LOSCFG_BASE_CORE_SWTMR_IN_ISR +//OsSwtmrTask锛氳蒋浠跺畾鏃跺櫒浠诲姟澶勭悊鍑芥暟锛岀敤浜庡鐞嗗畾鏃跺櫒瓒呮椂浜嬩欢 LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID) { UINT32 ret, swtmrHandlerQueue; @@ -136,7 +139,7 @@ BOOL IsSwtmrTask(UINT32 taskId) return FALSE; } #endif - +//OsSwtmrTaskCreate锛氬垱寤鸿蒋浠跺畾鏃跺櫒浠诲姟 LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID) { UINT32 ret, swtmrTaskId; @@ -161,7 +164,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID) return ret; } #endif - +//OsSwtmrInit锛氳蒋浠跺畾鏃跺櫒鍒濆鍖 LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID) { UINT32 size; @@ -209,6 +212,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID) * Description: Tick interrupt interface module of software timer * Return : LOS_OK on success or error code on failure */ +//OsSwtmrScan锛氭壂鎻忚蒋浠跺畾鏃跺櫒 LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID) { SortLinkList *sortList = NULL; @@ -277,6 +281,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID) * Description: Get next timeout * Return : Count of the Timer list */ +//OsSwtmrGetNextTimeout锛氳幏鍙栦笅涓涓秴鏃舵椂闂 LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID) { return OsSortLinkGetNextExpireTime(&OsPercpuGet()->swtmrSortLink); @@ -286,6 +291,7 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID) * Description: Stop of Software Timer interface * Input : swtmr --- the software timer control handler */ +//OsSwtmrStop锛氬仠姝㈣蒋浠跺畾鏃跺櫒 LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(LosSwtmrCB *swtmr) { SortLinkAttribute *sortLinkHeader = NULL; @@ -309,6 +315,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(LosSwtmrCB *swtmr) * Description: Get next software timer expiretime * Input : swtmr --- the software timer control handler */ +//鑾峰彇鎸囧畾杞欢瀹氭椂鍣ㄧ殑鍓╀綑鏃堕棿 LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const LosSwtmrCB *swtmr) { SortLinkAttribute *sortLinkHeader = NULL; @@ -325,7 +332,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const LosSwtmrCB *swtmr) return OsSortLinkGetTargetExpireTime(sortLinkHeader, &swtmr->sortList); } - +//鍒涘缓涓涓蒋浠跺畾鏃跺櫒 LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval, UINT8 mode, SWTMR_PROC_FUNC handler, @@ -377,7 +384,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval, return LOS_OK; } - +//鍚姩涓涓蒋浠跺畾鏃跺櫒 LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId) { LosSwtmrCB *swtmr = NULL; @@ -421,7 +428,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId) LOS_TRACE(SWTMR_START, swtmr->timerId, swtmr->mode, swtmr->overrun, swtmr->interval, swtmr->expiry); return ret; } - +//鍋滄涓涓蒋浠跺畾鏃跺櫒 LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId) { LosSwtmrCB *swtmr = NULL; @@ -461,7 +468,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId) LOS_TRACE(SWTMR_STOP, swtmr->timerId); return ret; } - +//鑾峰彇涓涓蒋浠跺畾鏃跺櫒鐨勫墿浣欐椂闂 LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick) { LosSwtmrCB *swtmr = NULL; @@ -502,7 +509,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick) SWTMR_UNLOCK(intSave); return ret; } - +//鍒犻櫎涓涓蒋浠跺畾鏃跺櫒 LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrId) { LosSwtmrCB *swtmr = NULL; diff --git a/src/kernel/base/los_task.c b/src/kernel/base/los_task.c index c771be6..31de5b0 100644 --- a/src/kernel/base/los_task.c +++ b/src/kernel/base/los_task.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*鍏充簬LiteOS涓换鍔$鐞嗘ā鍧楃殑閮ㄥ垎瀹炵幇锛屽寘鎷换鍔℃帶鍒跺潡鐨勫垵濮嬪寲銆佷换鍔″垱寤恒佷换鍔″垹闄ょ瓑鍔熻兘*/ #include "los_task_pri.h" #include "los_priqueue_pri.h" #include "los_sem_pri.h" @@ -282,7 +282,7 @@ LITE_OS_SEC_TEXT VOID OsTaskScan(VOID) LOS_Schedule(); } } - +//OsTaskInit鐢ㄤ簬鍒濆鍖栦换鍔$鐞嗘ā鍧楋紝鍖呮嫭浠诲姟鎺у埗鍧楁暟缁勩佺┖闂蹭换鍔″垪琛ㄣ佷换鍔″洖鏀跺垪琛ㄧ瓑鏁版嵁缁撴瀯鐨勫垵濮嬪寲 LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID) { UINT32 index; @@ -335,7 +335,7 @@ UINT32 OsGetIdleTaskId(VOID) Percpu *perCpu = OsPercpuGet(); return perCpu->idleTaskId; } - +//鍒涘缓绌洪棽浠诲姟锛圛dle Task锛 LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID) { UINT32 ret; @@ -363,6 +363,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID) * Description : get id of current running task. * Return : task id */ +//璇诲彇浠诲姟ID LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID) { LosTaskCB *runTask = OsCurrTaskGet(); @@ -372,7 +373,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID) } return runTask->taskId; } - +//鑾峰彇褰撳墠姝e湪杩愯鐨勪换鍔$殑浠诲姟鍚嶇О LITE_OS_SEC_TEXT CHAR *OsCurTaskNameGet(VOID) { LosTaskCB *runTask = OsCurrTaskGet(); @@ -428,12 +429,12 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_LowpowerHookReg(LOWPOWERIDLEHOOK hook) g_lowPowerHook = hook; } #endif - +//娉ㄥ唽绌洪棽浠诲姟閽╁瓙鍑芥暟锛屽嵆鍦ㄧ郴缁熺┖闂叉椂鎵ц鐨勫嚱鏁 LITE_OS_SEC_TEXT_MINOR VOID LOS_IdleHandlerHookReg(IDLEHANDLERHOOK hook) { g_idleHandlerHook = hook; } - +//妫鏌ヤ换鍔℃槸鍚﹀垎绂伙紙detached锛 STATIC BOOL OsTaskDeleteCheckDetached(const LosTaskCB *taskCB) { #if LOSCFG_COMPAT_POSIX @@ -442,7 +443,7 @@ STATIC BOOL OsTaskDeleteCheckDetached(const LosTaskCB *taskCB) return TRUE; #endif } - +//鍒犻櫎宸插垎绂荤殑浠诲姟 STATIC VOID OsTaskDeleteDetached(const LosTaskCB *taskCB) { UINT32 intSave; @@ -451,7 +452,7 @@ STATIC VOID OsTaskDeleteDetached(const LosTaskCB *taskCB) LOS_IntRestore(intSave); (VOID)LOS_TaskDelete(taskCB->taskId); } - +//鍒犻櫎宸插姞鍏ョ殑浠诲姟 STATIC VOID OsTaskDeleteJoined(LosTaskCB *taskCB, VOID *ret) { #ifdef LOSCFG_COMPAT_POSIX @@ -481,6 +482,8 @@ STATIC VOID OsTaskDeleteJoined(LosTaskCB *taskCB, VOID *ret) * Description : All task entry * Input : taskId --- The ID of the task to be run */ +//鎵ц浠诲姟鐨勫疄闄呬唬鐮侊紝骞舵牴鎹换鍔$殑灞炴у垽鏂槸鍚﹂渶瑕佸垹闄や换鍔 +//濡傛灉浠诲姟鏄垎绂荤殑锛屽垯鐩存帴鍒犻櫎浠诲姟锛涘鏋滀换鍔℃槸鍔犲叆鐨勶紝鍒欏皢浠诲姟鍔犲叆鐨勫叾浠栦换鍔″敜閱掞紝骞堕噸鏂拌皟搴︿换鍔 LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskId) { LosTaskCB *taskCB = NULL; @@ -511,7 +514,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskId) OsTaskDeleteJoined(taskCB, ret); } } - +//瀵逛换鍔″垵濮嬪寲鍙傛暟杩涜妫鏌ワ紝纭繚浠诲姟鍙傛暟鐨勫悎娉曟 STATIC UINT32 OsTaskInitParamCheck(const TSK_INIT_PARAM_S *initParam) { if (initParam == NULL) { @@ -566,7 +569,7 @@ STATIC UINT32 OsTaskCreateParamCheckStatic(const UINT32 *taskId, return LOS_OK; } #endif - +//瀵逛换鍔″垱寤哄弬鏁拌繘琛屾鏌ワ紝纭繚鍙傛暟鐨勫悎娉曟с傚鏋滃弬鏁颁笉鍚堟硶锛屽垯杩斿洖鐩稿簲鐨勯敊璇爜锛涘惁鍒欒繑鍥炴垚鍔 LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCreateParamCheck(const UINT32 *taskId, TSK_INIT_PARAM_S *initParam, VOID **pool) { @@ -776,6 +779,7 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskDelAction(LosTaskCB *taskCB, BOOL useUsr * 3. Do the deletion in hard-irq * then LOS_TaskDelete will directly return with 'ret' value. */ +//OsTaskDeleteCheckOnRun鍑芥暟鐢ㄦ潵妫鏌ユ槸鍚﹂渶瑕佸湪浠诲姟杩愯鏃惰繘琛屽垹闄ゆ搷浣 LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskDeleteCheckOnRun(LosTaskCB *taskCB, UINT32 *ret) { /* init default out return value */ @@ -813,7 +817,7 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskDeleteCheckOnRun(LosTaskCB *taskCB, UINT return TRUE; } - +//OsTaskCBInit鍑芥暟鐢ㄤ簬鍒濆鍖栦换鍔℃帶鍒跺潡锛岃缃换鍔$殑鍚勭灞炴у拰鐘舵 LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam, VOID *stackPtr, const VOID *topStack, BOOL useUsrStack) { @@ -869,7 +873,7 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT (VOID)memset_s(&taskCB->schedStat, sizeof(SchedStat), 0, sizeof(SchedStat)); #endif } - +//OsTaskGetFreeTaskCB鍑芥暟鐢ㄤ簬鑾峰彇涓涓┖闂茬殑浠诲姟鎺у埗鍧 STATIC UINT32 OsTaskGetFreeTaskCB(LosTaskCB **taskCB) { if (LOS_ListEmpty(&g_losFreeTask)) { @@ -883,7 +887,7 @@ STATIC UINT32 OsTaskGetFreeTaskCB(LosTaskCB **taskCB) LOS_ListDelete(LOS_DL_LIST_FIRST(&g_losFreeTask)); return LOS_OK; } - +//OsTaskCreateOnly鍑芥暟鐢ㄤ簬鍒涘缓涓涓柊鐨勪换鍔★紝鍏朵腑浼氬鍙傛暟杩涜鍚堟硶鎬ф鏌 STATIC UINT32 OsTaskCreateOnly(UINT32 *taskId, TSK_INIT_PARAM_S *initParam, VOID *topStack, BOOL useUsrStack) { UINT32 intSave, errRet; @@ -947,7 +951,7 @@ LOS_ERREND: SCHEDULER_UNLOCK(intSave); return errRet; } - +//OsTaskResume鍑芥暟鐢ㄤ簬鎭㈠涓涓鎸傝捣鐨勪换鍔 STATIC VOID OsTaskResume(const UINT32 *taskId) { UINT32 intSave; @@ -998,7 +1002,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskId, TSK_INIT_PARAM_S { return OsTaskCreateOnly(taskId, initParam, NULL, FALSE); } - +//LOS_TaskCreate璇ュ嚱鏁扮敤浜庡垱寤轰竴涓柊鐨勪换鍔★紝鍖呮嫭浠诲姟鐨勫悕绉般佷紭鍏堢骇銆佹爤澶у皬绛夊弬鏁扮殑璁剧疆 +//鍦ㄥ垱寤轰换鍔℃椂锛岄渶瑕佽繘琛屼竴浜涘弬鏁扮殑鍚堟硶鎬ф鏌ワ紝渚嬪鏄惁瓒呭嚭鏈澶т换鍔℃暟閲忋佹槸鍚︽湁瓒冲鐨勫爢鏍堢┖闂寸瓑 LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskId, TSK_INIT_PARAM_S *initParam) { UINT32 ret; @@ -1012,7 +1017,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskId, TSK_INIT_PARAM_S *in return LOS_OK; } - +//LOS_TaskDelete鐢ㄤ簬鍒犻櫎涓涓凡缁忓瓨鍦ㄧ殑浠诲姟 +//鍦ㄥ垹闄や换鍔℃椂锛岄渶瑕佸浠诲姟鐨勭姸鎬佽繘琛屽垽鏂傚鏋滀换鍔℃鍦ㄨ繍琛岋紝鍒欏皢鍏舵爣璁颁负鍒犻櫎鐘舵佸苟鏀惧叆鍥炴敹鍒楄〃锛涘惁鍒欑洿鎺ラ噴鏀句换鍔″崰鐢ㄧ殑璧勬簮 LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskId) { LosTaskCB *taskCB = NULL; @@ -1072,7 +1078,7 @@ LOS_RETURN: SCHEDULER_UNLOCK(intSave); return errRet; } - +//LOS_TaskResume鍑芥暟鐢ㄤ簬鎭㈠涓涓寕璧风殑浠诲姟 LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskId) { UINT32 intSave; @@ -1136,6 +1142,7 @@ LOS_ERREND: * 3. Do the suspension in hard-irq * then LOS_TaskSuspend will directly return with 'ret' value. */ +//OsTaskSuspendCheckOnRun锛氭鏌ュ綋鍓嶄换鍔℃槸鍚﹂渶瑕佹寕璧风殑鍑芥暟锛屾牴鎹潯浠跺垽鏂槸鍚﹂渶瑕佽繘琛屼换鍔℃寕璧锋搷浣 LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UINT32 *ret) { /* init default out return value */ @@ -1164,7 +1171,8 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UIN return TRUE; } - +//LOS_TaskSuspend锛氭寕璧锋寚瀹氫换鍔$殑鍑芥暟 +//濡傛灉浠诲姟宸茬粡澶勪簬鎸傝捣鐘舵佹垨鑰呮鍦ㄨ繍琛岋紝骞朵笖涓嶆弧瓒虫寕璧锋潯浠讹紝鍒欑洿鎺ヨ繑鍥為敊璇爜锛涘惁鍒欐墽琛屾寕璧锋搷浣 LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskSuspend(UINT32 taskId) { UINT32 intSave; @@ -1218,7 +1226,7 @@ LOS_RETURN: SCHEDULER_UNLOCK(intSave); return errRet; } - +//LOS_TaskDelay璇ュ嚱鏁扮敤浜庤浠诲姟杩涘叆寤舵椂鐘舵侊紝鍦ㄦ寚瀹氱殑鏃堕棿鍚庨噸鏂拌璋冨害鎵ц LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick) { UINT32 intSave; @@ -1250,7 +1258,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick) return LOS_OK; } - +//LOS_TaskDelay锛氬皢浠诲姟杩涘叆寤舵椂鐘舵侊紝鍦ㄦ寚瀹氱殑鏃堕棿鍚庨噸鏂拌璋冨害鎵ц锛屽鏋滃綋鍓嶅湪涓柇涓垨鑰呬笉鍙姠鍗狅紝鍒欒繑鍥炵浉搴旂殑閿欒鐮 LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskId) { UINT32 intSave; @@ -1273,7 +1281,7 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskId) SCHEDULER_UNLOCK(intSave); return priority; } - +//LOS_TaskPriGet锛氳幏鍙栨寚瀹氫换鍔$殑浼樺厛绾 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskId, UINT16 taskPrio) { BOOL isReady = FALSE; @@ -1325,7 +1333,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskId, UINT16 taskPrio) } return LOS_OK; } - +//LOS_TaskPriSet锛氳缃寚瀹氫换鍔$殑浼樺厛绾э紝鏍规嵁浠诲姟褰撳墠鐘舵侀夋嫨涓嶅悓鐨勫鐞嗘柟寮 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CurTaskPriSet(UINT16 taskPrio) { return LOS_TaskPriSet(OsCurrTaskGet()->taskId, taskPrio); @@ -1337,6 +1345,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CurTaskPriSet(UINT16 taskPrio) * taskStatus --- task status * timeOut --- Expiry time * Return : LOS_OK on success or LOS_NOK on failure + * OsTaskWait鍜孫sTaskWake锛氫换鍔$瓑寰呭拰鍞ら啋鐨勮緟鍔╁嚱鏁 */ VOID OsTaskWait(LOS_DL_LIST *list, UINT16 taskStatus, UINT32 timeout) { @@ -1373,7 +1382,7 @@ VOID OsTaskWake(LosTaskCB *resumedTask, UINT16 taskStatus) OsPriQueueEnqueue(&resumedTask->pendList, resumedTask->priority); } } - +//LOS_TaskYield鐢ㄤ簬浣垮綋鍓嶄换鍔′富鍔ㄦ斁寮 CPU 鎺у埗鏉冿紝璁╁嚭 CPU 缁欏叾浠栭珮浼樺厛绾т换鍔℃墽琛 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID) { UINT32 tskCount; @@ -1412,6 +1421,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID) return LOS_OK; } +//LOS_TaskLock鍜孡OS_TaskUnlock锛氫换鍔¢攣瀹氬拰瑙i攣鍑芥暟锛岀敤浜庝繚鎶や复鐣屽尯 + LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskLock(VOID) { UINT32 intSave; @@ -1446,7 +1457,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskUnlock(VOID) LOS_IntRestore(intSave); } - +//LOS_TaskInfoGet锛氳幏鍙栨寚瀹氫换鍔$殑淇℃伅锛屽寘鎷换鍔″悕銆佹爤澶у皬銆佸爢鏍堜娇鐢ㄦ儏鍐电瓑 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskId, TSK_INFO_S *taskInfo) { UINT32 intSave; @@ -1503,7 +1514,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskId, TSK_INFO_S *taskInf return LOS_OK; } - +//LOS_TaskCpuAffiSet鍜孡OS_TaskCpuAffiGet锛氳缃拰鑾峰彇浠诲姟鐨 CPU 浜插拰鎬э紝浠呭湪鏀寔澶氭牳鐨勬儏鍐典笅鏈夋晥 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskId, UINT16 cpuAffiMask) { #ifdef LOSCFG_KERNEL_SMP @@ -1580,6 +1591,7 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskId) /* * Description : Process pending signals tagged by others cores + *OsTaskProcSignal锛氬鐞嗘寕璧枫佸垹闄や换鍔$瓑淇″彿 */ LITE_OS_SEC_TEXT_MINOR UINT32 OsTaskProcSignal(VOID) { diff --git a/src/kernel/base/los_tick.c b/src/kernel/base/los_tick.c index c1d2db8..09c598b 100644 --- a/src/kernel/base/los_tick.c +++ b/src/kernel/base/los_tick.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/*鏃堕挓妯″潡:涓昏鍖呮嫭绯荤粺鏃堕挓鐨勫垵濮嬪寲銆佹椂閽熶腑鏂鐞嗗嚱鏁般佽幏鍙栫郴缁焧ick鏁扮瓑鍔熻兘*/ #include "los_tick_pri.h" #include "los_swtmr_pri.h" #include "los_task_pri.h" @@ -52,6 +52,7 @@ STATIC WAKEUPFROMINTHOOK g_tickWakeupHook = NULL; /* * Description : Tick interruption handler */ +//OsTickHandler鍑芥暟锛氭椂閽熶腑鏂鐞嗗嚱鏁帮紝鐢ㄤ簬澶勭悊鏃堕挓涓柇浜嬩欢銆 LITE_OS_SEC_TEXT VOID OsTickHandler(VOID) { UINT32 intSave; @@ -76,7 +77,7 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID) OsSwtmrScan(); #endif } - +//OsTickInit锛氬垵濮嬪寲绯荤粺鏃堕挓 LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond) { if ((systemClock == 0) || @@ -88,12 +89,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond return LOS_OK; } - +//鍚姩绯荤粺鏃堕挓 LITE_OS_SEC_TEXT_INIT VOID OsTickStart(VOID) { HalClockStart(); } - +//LOS_TickCountGet鍑芥暟锛氳幏鍙栫郴缁焧ick鏁 LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID) { UINT32 intSave; @@ -109,12 +110,12 @@ LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID) return tick; } - +//LOS_CyclePerTickGet鍑芥暟锛氳幏鍙栨瘡涓猼ick鎵瀵瑰簲鐨凜PU鍛ㄦ湡鏁 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CyclePerTickGet(VOID) { return g_sysClock / KERNEL_TICK_PER_SECOND; } - +//LOS_GetCpuCycle鍑芥暟锛氳幏鍙朇PU鍛ㄦ湡鏁 LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt) { UINT64 cycle; @@ -129,7 +130,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt) /* get the low 32 bits */ *lowCnt = (UINT32)(cycle & 0xFFFFFFFFULL); } - +//LOS_CurrNanosec鍑芥暟锛氳幏鍙栧綋鍓嶇殑绾崇鏁 LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID) { UINT64 nanos; @@ -137,7 +138,7 @@ LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID) nanos = HalClockGetCycles() * (OS_SYS_NS_PER_SECOND / OS_SYS_NS_PER_MS) / (g_sysClock / OS_SYS_NS_PER_MS); return nanos; } - +//LOS_MS2Tick鍑芥暟锛氬皢姣杞崲涓簍ick鏁 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec) { UINT64 delaySec; @@ -149,17 +150,17 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec) delaySec = (UINT64)millisec * KERNEL_TICK_PER_SECOND; return (UINT32)((delaySec + OS_SYS_MS_PER_SECOND - 1) / OS_SYS_MS_PER_SECOND); } - +//LOS_Tick2MS鍑芥暟锛氬皢tick鏁拌浆鎹负姣鏁 LITE_OS_SEC_TEXT_MINOR UINT32 LOS_Tick2MS(UINT32 tick) { return (UINT32)(((UINT64)tick * OS_SYS_MS_PER_SECOND) / KERNEL_TICK_PER_SECOND); } - +//LOS_Udelay鍑芥暟锛氬井绉掔骇寤惰繜鍑芥暟 LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs) { HalDelayUs(usecs); } - +//LOS_Mdelay鍑芥暟锛氭绉掔骇寤惰繜鍑芥暟 LITE_OS_SEC_TEXT_MINOR VOID LOS_Mdelay(UINT32 msecs) { UINT32 delayUs = (UINT32_MAX / OS_SYS_US_PER_MS) * OS_SYS_US_PER_MS; diff --git a/src/kernel/base/mem/bestfit_little/los_heap.c b/src/kernel/base/mem/bestfit_little/los_heap.c index 8bfa91c..3313db0 100644 --- a/src/kernel/base/mem/bestfit_little/los_heap.c +++ b/src/kernel/base/mem/bestfit_little/los_heap.c @@ -43,9 +43,9 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#define HEAP_CAST(t, exp) ((t)(exp)) -#define HEAP_ALIGN sizeof(UINTPTR) -#define MALLOC_MAXSIZE (0xFFFFFFFF - HEAP_ALIGN + 1) +#define HEAP_CAST(t, exp) ((t)(exp))//这个宏定义是一个类型转换的快捷方式。它接受两个参数,t 表示目标类型,exp 是需要进行类型转换的表达式。这个宏最终会将 exp 转换为类型 t。 +#define HEAP_ALIGN sizeof(UINTPTR)//这个宏定义定义了 HEAP_ALIGN,它的值是 sizeof(UINTPTR)。sizeof 操作符用于返回其操作数的大小(以字节为单位),所以 HEAP_ALIGN 的值将取决于 UINTPTR 类型的大小。 +#define MALLOC_MAXSIZE (0xFFFFFFFF - HEAP_ALIGN + 1)//这个宏定义了 MALLOC_MAXSIZE,它的值是 0xFFFFFFFF - HEAP_ALIGN + 1。在这里,0xFFFFFFFF 表示一个32位无符号整数的最大值,HEAP_ALIGN 已经在上面定义过了。这个宏定义似乎是用来表示在分配内存时可能的最大尺寸。 /* * Description : look up the next memory node according to one memory node in the memory block list. @@ -53,13 +53,25 @@ extern "C" { * struct LosHeapNode *node --- Size of memory in bytes to allocate * Return : Pointer to next memory node */ + /*这个函数的作用是获取下一个堆节点的指针。具体实现过程如下: +如果当前节点已经是最后一个节点(即 node 等于堆管理器的尾节点),则返回 NULL。 +否则,计算出下一个节点的指针。根据结构体 LosHeapNode 的定义可知,每个节点都有一个 data 指针和一个 size 字段。为了得到下一个节点的指针,需要将当前节点的 data 指针加上当前节点的 size 字段。 +这个结果是一个地址,需要将其转换成 struct LosHeapNode* 类型的指针。可以通过先将地址转换为 UINTPTR 类型,再强制转换为 struct LosHeapNode* 来实现这一点。 +返回下一个节点的指针。*/ struct LosHeapNode* OsHeapPrvGetNext(struct LosHeapManager *heapMan, struct LosHeapNode *node) { return (heapMan->tail == node) ? NULL : (struct LosHeapNode *)(UINTPTR)(node->data + node->size); } #ifdef LOSCFG_MEM_TASK_STAT - +/*该函数接受两个参数:heapMan 表示堆管理器的指针,size 表示堆的初始大小。该函数的作用是初始化堆的统计信息, +即将 heapMan->stat 结构体清零, +并设置 heapMan->stat.memTotalUsed 和 heapMan->stat.memTotalPeak,表示内存使用情况的总量和峰值。 +具体实现过程如下: +首先调用 memset_s 函数将 heapMan->stat 清零,确保所有字段的值都为 0。 +接着,设置 heapMan->stat.memTotalUsed 的值为 sizeof(struct LosHeapNode) + sizeof(struct LosHeapManager),即堆管理器结构体和堆节点结构体的大小之和,这是堆使用的总 +将 heapMan->stat.memTotalPeak 的初始值也设为 heapMan->stat.memTotalUsed,表示在堆使用过程中的最高峰值。 +这段代码的前提条件是 LOSCFG_MEM_TASK_STAT 宏定义已经被定义,否则该函数不会被编译。*/ VOID OsHeapStatInit(struct LosHeapManager *heapMan, UINT32 size) { (VOID)memset_s(&heapMan->stat, sizeof(Memstat), 0, sizeof(Memstat)); @@ -67,7 +79,16 @@ VOID OsHeapStatInit(struct LosHeapManager *heapMan, UINT32 size) heapMan->stat.memTotalUsed = sizeof(struct LosHeapNode) + sizeof(struct LosHeapManager); heapMan->stat.memTotalPeak = heapMan->stat.memTotalUsed; } - +/*该函数的作用是向堆的统计信息中添加被使用的内存块。具体实现过程如下: +首先定义了两个变量 taskId 和 blockSize。taskId 用于记录当前任务的 ID,blockSize 表示要添加的内存块的大小, +包括堆节点结构体和节点存储的数据大小。 +然后,通过条件判断来确定 taskId 的值。如果当前任务不为空且处于非中断状态(OS_INT_INACTIVE), +则将 taskId 设置为当前任务的 ID(通过 LOS_CurTaskIDGet 函数获取)。否则,将 taskId 设置为 TASK_NUM - 1, +表示该内存块属于最后一个任务。 +将节点的 taskId 字段设置为 taskId,以便记录该内存块所属的任务。 +最后,调用 OS_MEM_ADD_USED 宏来更新堆的统计信息。该宏会将 blockSize 和 taskId 传递给堆管理器的 stat 结构体, +以便记录已使用内存的总量和各任务的内存使用情况。 +该函数的目的是在堆的统计信息中记录每个内存块的使用情况,以便进行内存管理和监控。*/ VOID OsHeapStatAddUsed(struct LosHeapManager *heapMan, struct LosHeapNode *node) { UINT32 taskId; @@ -87,7 +108,13 @@ VOID OsHeapStatAddUsed(struct LosHeapManager *heapMan, struct LosHeapNode *node) node->taskId = taskId; OS_MEM_ADD_USED(&heapMan->stat, blockSize, taskId); } - +/*该函数的作用是从堆的统计信息中减少被使用的内存块。具体实现过程如下: +首先定义了两个变量 taskId 和 blockSize。taskId 用于记录当前节点所属的任务 ID,该值在添加内存块时被设置; +blockSize 表示要减少的内存块的大小,包括堆节点结构体和节点存储的数据大小。 +调用 OS_MEM_REDUCE_USED 宏来更新堆的统计信息。该宏会将 blockSize 和 taskId 传递给堆管理器的 stat 结构体, +以便记录已使用内存的总量和各任务的内存使用情况。 +该函数的目的是在堆的统计信息中记录每个内存块的使用情况,以便进行内存管理和监控。和 OsHeapStatAddUsed 函数相反, +该函数的作用是将内存块从使用中状态转变为未使用状态。*/ VOID OsHeapStatDecUsed(struct LosHeapManager *heapMan, struct LosHeapNode *node) { UINT32 taskId = node->taskId; @@ -97,17 +124,25 @@ VOID OsHeapStatDecUsed(struct LosHeapManager *heapMan, struct LosHeapNode *node) } #else /* LOSCFG_MEM_TASK_STAT */ - +//函数用于初始化堆管理器的内存统计信息。它接受两个参数:heapMan 表示堆管理器的指针,size 表示堆的总大小。在这个备选实现中,该函数没有任何具体的实现操作,直接返回。 VOID OsHeapStatInit(struct LosHeapManager *heapMan, UINT32 size) { } - +//函数用于向堆的统计信息中添加被使用的内存块。它接受两个参数:heapMan 表示堆管理器的指针,node 表示要添加到统计信息中的堆节点指针。在这个备选实现中,该函数没有任何具体的实现操作,什么也不做。 VOID OsHeapStatAddUsed(struct LosHeapManager *heapMan, struct LosHeapNode *node) { } - +//函数用于从堆的统计信息中减少被使用的内存块。它接受两个参数:heapMan 表示堆管理器的指针,node 表示要从统计信息中减少使用的堆节点指针。在这个备选实现中,该函数没有任何具体的实现操作,什么也不做。 VOID OsHeapStatDecUsed(struct LosHeapManager *heapMan, struct LosHeapNode *node) { } #endif /* LOSCFG_MEM_TASK_STAT */ #ifdef LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK - +/*这段代码实现了一个堆完整性检查的函数 OsHeapIntegrityCheck,用于检查堆内存的完整性, +以确保堆管理器中的内存块没有被破坏或越界。让我逐步解释这段代码的功能: +首先,通过 (struct LosHeapNode *)(heap + 1) 的方式来获取第一个堆节点的地址,其中 heap 是指向堆管理器结构体的指针。 +然后,计算出堆的起始地址和结束地址,其中 heapStart 表示堆的起始地址,heapEnd 表示堆的结束地址。 +接下来进入循环,遍历堆中的每个节点。在循环内部,首先检查当前节点的地址是否位于堆的范围内,如果节点地址小于堆的起始地址或大于堆的结束地址, +则说明堆节点已经被破坏或越界,此时触发错误处理并返回 LOS_NOK 表示检查失败。 +如果当前节点的地址在合法范围内,则通过 OsHeapPrvGetNext 函数获取下一个节点的地址,继续进行下一轮的检查。 +当所有节点都通过合法性检查后,函数返回 LOS_OK 表示堆的完整性检查通过。 +总之,这段代码实现了对堆内存完整性的检查,避免了堆内存被破坏或越界,确保了堆管理器中的内存块的正确性。*/ UINT32 OsHeapIntegrityCheck(struct LosHeapManager *heap) { struct LosHeapNode *node = (struct LosHeapNode *)(heap + 1); @@ -127,7 +162,7 @@ UINT32 OsHeapIntegrityCheck(struct LosHeapManager *heap) } #else /* LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK */ - +//这段代码实现了一个名为 OsHeapIntegrityCheck 的函数,它接受一个指向 LosHeapManager 结构体的指针作为参数,并直接返回 LOS_OK。 UINT32 OsHeapIntegrityCheck(struct LosHeapManager *heap) { return LOS_OK; @@ -136,12 +171,16 @@ UINT32 OsHeapIntegrityCheck(struct LosHeapManager *heap) #endif /* LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK */ #ifdef LOSCFG_KERNEL_MEM_SLAB_EXTENTION - +/*接受一个指向内存池的指针 pool 和一个表示需要分配内存大小的参数 size。 +在函数内部,调用 OsHeapAlloc 函数将内存分配操作委托给堆内存管理器进行处理。 +最终将堆内存管理器返回的内存分配结果直接返回给调用者。*/ VOID *OsMemAlloc(VOID *pool, UINT32 size) { return OsHeapAlloc(pool, size); } - +/*接受一个指向内存池的指针 pool 和一个指向待释放内存块的指针 ptr。 +在函数内部,调用 OsHeapFree 函数将内存释放操作委托给堆内存管理器进行处理。 +检查堆内存管理器的释放操作是否成功,如果成功则返回 LOS_OK 表示释放成功,否则返回 LOS_NOK 表示释放失败。*/ UINT32 OsMemFree(VOID *pool, const VOID *ptr) { if (OsHeapFree(pool, ptr) == TRUE) { @@ -160,6 +199,19 @@ UINT32 OsMemFree(VOID *pool, const VOID *ptr) * UITN32 size --- size of the heap memory pool * Return : 1:success 0:error */ +/*这段代码实现了一个名为 OsHeapInit 的函数,用于初始化堆内存管理器。让我逐步解释这段代码的功能: +首先,函数接受一个指向内存池的指针 pool 和表示内存池大小的参数 size。 +接着,代码将 pool 指针强制类型转换为 struct LosHeapManager 类型的指针 heapMan,以便后续对堆管理器结构体成员的操作。 +然后,代码执行了一系列的条件检查: +检查 heapMan 是否为 NULL,或者内存池的大小是否小于等于堆管理器结构体和堆节点结构体所需的空间大小之和。 +如果满足其中任何一个条件,函数将返回 FALSE。 +如果条件检查通过,接下来的操作包括: +使用 memset_s 函数将整个内存池的内容初始化为 0。 +设置堆管理器结构体中的 size 成员为 size - sizeof(struct LosHeapManager)。 +将 head 和 tail 指针指向内存池中的起始位置,并初始化堆节点的相关属性,如 used、prev 和 size。 +调用 OsHeapStatInit 函数对堆内存管理器进行统计信息的初始化。 +最后,函数返回 TRUE 表示堆内存管理器初始化成功。 +总之,这段代码实现了对堆内存管理器的初始化操作,包括内存池的清零、设置管理器结构体的各个成员值,以及进行统计信息的初始化。这是堆内存分配器在启动阶段需要执行的关键操作,以确保后续的内存分配和释放能够正常进行。*/ BOOL OsHeapInit(VOID *pool, UINT32 size) { struct LosHeapNode *node = NULL; @@ -192,6 +244,33 @@ BOOL OsHeapInit(VOID *pool, UINT32 size) * UINT32 size --- size of the heap memory pool * Return : NULL:error, other value:the address of the memory we alloced */ +/*这段代码实现了一个名为 OsHeapAlloc 的函数,用于在堆内存管理器中分配指定大小的内存块。让我逐步解释这段代码的功能: + +首先,函数接受一个指向内存池的指针 pool 和表示要分配的内存块大小的参数 size。 + +接着,代码定义了一些局部变量,包括 node、next、best、ptr 和 alignSize,用于记录堆节点和其他临时数据。 + +heapMan 是将 pool 指针强制类型转换为 struct LosHeapManager 类型的指针,以便后续对堆管理器结构体成员的操作。 + +然后,代码执行了一系列的条件检查: + +检查 heapMan 是否为 NULL,或者要分配的内存块大小是否超过了最大允许的大小 MALLOC_MAXSIZE。如果满足其中任何一个条件,函数将返回 NULL。 +如果条件检查通过,接下来的操作包括: + +调用 OsHeapIntegrityCheck 函数对堆内存管理器进行完整性检查。如果检查失败(返回值不等于 LOS_OK),函数将返回 NULL。 +然后,代码从堆内存管理器的尾部开始遍历堆节点,寻找合适的空闲节点来分配内存块。具体过程如下: + +判断当前节点是否未被使用(node->used == 0)且大小足够容纳请求的对齐后的大小(node->size >= alignSize)。 +如果是,则更新 best 指针,选择找到的第一个合适的节点。 +如果找到的节点大小正好与请求的对齐后的大小相等(best->size == alignSize),跳转到 SIZE_MATCH 标签处。 +循环遍历完所有节点后,函数将根据找到的最佳节点进行不同的处理: + +如果找到了合适的节点(best != NULL),则继续下面的操作。 +如果找到的节点大小与对齐后的大小完全匹配(即跳转到 SIZE_MATCH 标签处),直接执行后续处理操作。 +否则,函数将在找到的节点上分割出一个大小为 alignSize 的内存块,并更新相关节点和管理器的属性值。 +最后,函数返回分配的内存块的起始地址 ptr。 + +总之,这段代码实现了在堆内存管理器中分配指定大小的内存块的功能。它会遍历堆节点,寻找满足条件的空闲节点,并根据需要进行内存分割,以满足对齐要求。如果分配失败或出现错误,函数将返回 NULL。*/ VOID *OsHeapAlloc(VOID *pool, UINT32 size) { struct LosHeapNode *node = NULL; @@ -222,11 +301,18 @@ VOID *OsHeapAlloc(VOID *pool, UINT32 size) } /* alloc failed */ + /*这是一个条件判断语句,如果找到的最佳节点为空(即没有足够大小的空闲节点),则执行花括号中的代码块。*/ if (best == NULL) { - PRINT_ERR("there's not enough mem to alloc 0x%x Bytes!\n", alignSize); - goto OUT; + PRINT_ERR("there's not enough mem to alloc 0x%x Bytes!\n", alignSize);//在没有足够空闲内存来分配请求大小的内存块时,打印错误信息,提示用户无法分配指定大小的内存。 + goto OUT;//跳转到标签 OUT 处,这通常是用于执行清理和释放资源的操作。 } - + /*这是另一个条件判断语句,用于判断是否有足够的空间将找到的节点分割为两部分,以满足请求的大小,并且保留一个足够大的空洞来放置下一个节点的元数据。*/ + /*node = (struct LosHeapNode*)(UINTPTR)(best->data + alignSize);:计算出新的节点的地址,该节点位于原节点的空闲空间之后,用于存放剩余的内存块。 +node->used = 0;:将新节点标记为未使用。 +node->size = best->size - alignSize - sizeof(struct LosHeapNode);:设置新节点的大小为原节点大小减去已分配内存大小和节点元数据大小的剩余空间。 +node->prev = best;:设置新节点的前驱节点为原节点。 +接下来的条件判断和操作用于更新堆管理器中的节点关系,确保堆的连续性。 +最后,best->size = alignSize;:更新原节点的大小为已分配大小,表示原节点存放了分配的内存块。*/ if ((best->size - alignSize) > sizeof(struct LosHeapNode)) { /* hole divide into 2 */ node = (struct LosHeapNode*)(UINTPTR)(best->data + alignSize); @@ -246,7 +332,11 @@ VOID *OsHeapAlloc(VOID *pool, UINT32 size) best->size = alignSize; } +/*这段代码可能是用于实现动态内存分配器的代码。具体来说,函数名称 SIZE_MATCH 可能代表了一种内存分配策略,即在进行内存分配时,选择最能够匹配请求大小的空闲内存块进行分配。 + +其中,代码中的 best 变量可能表示了符合请求大小的、最佳匹配的空闲内存块。代码将 best 的 align 属性设为 0,used 属性设为 1,表示该内存块已被使用。然后,代码通过指针 ptr 返回了该内存块的起始地址。最后,代码调用了 OsHeapStatAddUsed 函数,可能是用于统计内存分配情况的函数,将该内存块的使用信息记录到内存分配器的统计数据中。 +值得注意的是,代码中可能存在一些未给出的上下文信息,因此具体含义可能需要根据上下文和相关代码进行推断和理解。*/ SIZE_MATCH: best->align = 0; best->used = 1; @@ -264,6 +354,15 @@ OUT: * UINT32 boundary --- boundary the heap needs align * Return : NULL:error, other value:the address of the memory we alloced */ +/*这段代码是一个用于分配指定大小、指定对齐边界(alignment boundary)的内存块的函数。该函数的名称为 OsHeapAllocAlign。 + +代码首先进行了一些错误检查,确保传入的参数 pool 不为空、size 大于 0、boundary 大于等于 sizeof(VOID*)(VOID* 的大小,即指针大小),且 boundary 是对齐的。如果有任何一个条件不满足,则返回 NULL,表示内存分配失败。 + +接着,代码计算了需要分配的内存块的大小 useSize,并使用 OsHeapAlloc 函数在内存池 pool 中分配了 useSize 大小的内存块,并将其赋值给指针变量 ptr。 + +如果内存分配成功,则代码通过 OS_MEM_ALIGN 宏将 ptr 指针对齐到指定的边界 boundary。如果对齐后的指针地址与原始指针地址相同,则说明原始指针已经对齐,直接跳转到 OUT 标签处并返回 ptr 指针即可。否则,说明原始指针未对齐,需要在原始指针和对齐后的指针间填补一定的空隙(gap),并将 gap 的大小信息存储在对齐后的指针前 sizeof(UINTPTR) 个字节的位置。最后,代码返回对齐后的指针 alignedPtr。 + +需要注意的是,代码中可能存在一些未给出的宏定义和类型定义,具体含义可能需要根据上下文和相关代码进行推断和理解。*/ VOID* OsHeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary) { UINT32 useSize; @@ -297,7 +396,15 @@ VOID* OsHeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary) OUT: return ptr; } +/*这段代码是一个用于释放内存的函数,名称为 OsHeapDoFree。该函数接收两个参数:一个是 LosHeapManager 结构体指针 heapMan,代表内存池管理器;另一个是 LosHeapNode 结构体指针 curNode,代表需要释放的内存块对应的内存池节点。 + +代码首先将 curNode 赋值给 node 变量,并将其 used 属性设为 0,表示该节点为未使用状态。 + +接着,代码使用 while 循环向前遍历链表,查找前面的空闲节点。具体来说,如果当前节点 node 的前一个节点存在且未被使用,则将 node 更新为前一个节点。这一步的目的是将 node 扩展到尽可能大的空闲区域。 +然后,代码使用 while 循环向后遍历链表,查找后面的空闲节点。具体来说,代码使用 OsHeapPrvGetNext 函数获取 node 的下一个节点 next,如果 next 存在且未被使用,则将 node 和 next 合并为一个新的节点,并更新 node 的 size 属性。如果合并后的节点是链表中的最后一个节点(也就是 heapMan->tail 指向该节点),则更新 heapMan->tail 为合并后的新节点。如果 next 不存在或已经被使用,则结束循环。 + +需要注意的是,代码中使用了 LosHeapManager 和 LosHeapNode 两个结构体,具体属性和方法的含义可能需要根据上下文和相关代码进行推断和理解。*/ STATIC VOID OsHeapDoFree(struct LosHeapManager *heapMan, struct LosHeapNode *curNode) { struct LosHeapNode *node = curNode; @@ -330,6 +437,15 @@ STATIC VOID OsHeapDoFree(struct LosHeapManager *heapMan, struct LosHeapNode *cur * VOID* ptr --- the pointer of heap memory we want to free * Return : 1:success 0:error */ +/*这段代码是用于释放指定内存块的函数 OsHeapFree。该函数接收两个参数:一个是 VOID 类型指针 pool,代表内存池;另一个是 const VOID 类型指针 ptr,代表需要释放的内存块的起始地址。 + +代码首先声明了一些变量和结构体指针,其中 node 是一个 LosHeapNode 结构体指针,用于表示需要释放的内存块对应的内存池节点。gapSize 是一个 UINT32 类型变量,用于记录内存块前面的空隙大小,ret 是一个 BOOL 类型变量,用于表示内存是否成功释放。 + +接着,代码通过将传入的 ptr 指针往前移动 sizeof(UINTPTR) 个字节,找到真正的内存块地址,并将其赋值给 ptr 变量。然后,代码判断 ptr 所指向的内存块地址是否在内存池的范围内,如果不在范围内,则返回 FALSE。 + +接下来,代码使用 ((struct LosHeapNode *)ptr) - 1 计算出内存块对应的内存池节点的地址,并将其赋值给 node 变量。然后,代码检查该节点是否已经被使用,以及它是否是链表中的一个节点。如果检查不通过,则将 ret 设置为 FALSE,并跳转到 OUT 标签处。 + +最后,代码调用 OsHeapStatDecUsed 函数将内存池管理器中 used 字段减一,然后调用 OsHeapDoFree 函数将 node 对应的内存块释放,并更新内存池管理器中的相关参数。最终返回 ret 表示操作是否成功。*/ BOOL OsHeapFree(VOID *pool, const VOID *ptr) { struct LosHeapNode *node = NULL; @@ -378,6 +494,19 @@ OUT: * Output : status --- heap statistics * Return : LOS_OK on success or error code on failure */ +/*这段代码是用于获取指定内存池的统计信息的函数 OsHeapStatisticsGet。该函数接收两个参数:一个是 VOID 类型指针 pool,代表内存池;另一个是 LosHeapStatus 结构体指针 status,用于保存内存池的统计信息。 + +函数中首先声明了一些变量,包括 heapUsed、maxFreeNodeSize、freeNodeNum、usedNodeNum 以及结构体指针 node 和 ramHeap。其中 heapUsed 表示已用内存大小,maxFreeNodeSize 表示最大可用内存块大小,freeNodeNum 表示空闲节点数量,usedNodeNum 表示已用节点数量。 + +然后,代码检查传入的内存池指针是否为空,如果为空,则返回 LOS_NOK。接着,代码检查传入的结构体指针 status 是否为空,如果为空,则返回 LOS_NOK。 + +之后,代码使用 sizeof(struct LosHeapManager) 计算出内存池管理器头部占用的空间大小,并将其加到 heapUsed 变量中。 + +接下来,代码使用指针 node 遍历整个内存池的节点链表,对每个节点进行处理。如果该节点已被使用,则将其大小和节点头部大小相加,并将结果累加到 heapUsed 中,并将 usedNodeNum 加一。否则,如果该节点未被使用,则更新 maxFreeNodeSize 和 freeNodeNum 的值。 + +最后,代码检查 heapUsed 是否超过了内存池总大小,如果超过,则返回 LOS_NOK。否则,将统计信息保存到结构体指针 status 中,并返回 LOS_OK。 + +需要注意的是,如果系统开启了 LOSCFG_MEM_TASK_STAT 宏定义,则代码还会更新 usageWaterLine 字段的值。*/ UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status) { UINT32 heapUsed = 0; @@ -435,6 +564,15 @@ UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status) * Input : pool --- Pointer to the manager, to distinguish heap * Return : max free block size */ +/*这段代码是用于获取指定内存池中最大可用块大小的函数 OsHeapGetMaxFreeBlkSize。该函数接收一个参数:一个 VOID 类型指针 pool,代表内存池。 + +函数中首先声明了一些变量,包括 size、temp、结构体指针 node 和 ramHeap。其中 size 表示最大可用块大小,temp 是一个临时变量,用于保存当前节点的大小。 + +然后,代码检查传入的内存池指针是否为空,如果为空,则返回 LOS_NOK。 + +之后,代码使用指针 node 遍历整个内存池的节点链表,对每个节点进行处理。如果该节点未被使用,则将其大小保存到 temp 变量中。如果 temp 的值比 size 大,则更新 size 的值为 temp。 + +最后,函数返回 size 变量的值,即内存池中最大可用块的大小。*/ UINT32 OsHeapGetMaxFreeBlkSize(VOID *pool) { UINT32 size = 0; diff --git a/src/kernel/base/mem/bestfit_little/los_memory.c b/src/kernel/base/mem/bestfit_little/los_memory.c index cf9269d..53d9bd0 100644 --- a/src/kernel/base/mem/bestfit_little/los_memory.c +++ b/src/kernel/base/mem/bestfit_little/los_memory.c @@ -41,18 +41,40 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#define POOL_ADDR_ALIGNSIZE 64 +#define POOL_ADDR_ALIGNSIZE 64//是一个宏,表示内存池地址对齐的大小,值为64。 -LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_memSpin); +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_memSpin);//是一个修饰符,用于指定变量所属的段(section)为.bss.init,该变量在程序运行前会被初始化为0。 +//是一个宏,用于初始化自旋锁变量g_memSpin。 -UINT8 *m_aucSysMem0 = (UINT8 *)NULL; -UINT8 *m_aucSysMem1 = (UINT8 *)NULL; -__attribute__((section(".data.init"))) UINTPTR g_sys_mem_addr_end; +UINT8 *m_aucSysMem0 = (UINT8 *)NULL;//是一个指向UINT8类型的指针变量,初始值为NULL。 +UINT8 *m_aucSysMem1 = (UINT8 *)NULL;//是一个指向UINT8类型的指针变量,初始值为NULL。 +__attribute__((section(".data.init"))) UINTPTR g_sys_mem_addr_end;//是一个UINTPTR类型的变量,位于.data.init段,用于记录系统内存地址的末尾位置。 -#ifdef LOSCFG_EXC_INTERACTION -__attribute__((section(".data.init"))) UINTPTR g_excInteractMemSize = 0; + +#ifdef LOSCFG_EXC_INTERACTION//表示如果定义了宏LOSCFG_EXC_INTERACTION,则编译以下代码块。 +__attribute__((section(".data.init"))) UINTPTR g_excInteractMemSize = 0;//是一个UINTPTR类型的变量,位于.data.init段,用于记录异常交互内存的大小,初始值为0。 #endif + +/*这段代码是一个函数LOS_MemInit()的实现,用于初始化内存池。 + +LITE_OS_SEC_TEXT_INIT 是一个修饰符,用于指定函数所属的段(section)为.text.init,表示该函数在程序运行前会被初始化。 + +函数参数: + +pool 是一个指向内存池的指针,用于存储分配的内存块。 +size 是内存池的大小。 +函数内部逻辑: + +首先,函数会对传入的参数进行检查。如果pool为空指针或size小于等于sizeof(struct LosHeapManager)(一种内部结构的大小),则函数直接返回错误码LOS_NOK。 +接下来,函数会检查pool和size是否按照OS_MEM_ALIGN_SIZE(内存对齐大小)进行对齐。如果没有对齐,则打印警告信息,并将size调整为对齐后的大小。 +然后,函数会获取并保存当前的中断状态,以防止在初始化过程中发生中断。 +接着,函数调用OsMemMulPoolInit()初始化多内存池管理器,如果初始化失败,则跳转到OUT标签处。 +如果多内存池管理器初始化成功,函数继续调用OsHeapInit()初始化堆管理器。如果堆管理器初始化失败,则先释放多内存池,然后跳转到OUT标签处。 +最后,函数调用OsSlabMemInit()初始化 Slab 内存管理器,并将返回值设置为成功的状态码LOS_OK。 +在OUT标签处,函数会解锁之前保存的中断状态,并打印内存信息请求的跟踪日志。 +最终,函数返回初始化结果,可能是LOS_NOK表示失败,或者LOS_OK表示成功。 +这段代码主要实现了内存池的初始化逻辑,包括多内存池管理器、堆管理器和 Slab 内存管理器的初始化。*/ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemInit(VOID *pool, UINT32 size) { UINT32 ret = LOS_NOK; @@ -103,6 +125,21 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsMemExcInteractionInit(UINTPTR memStart) * Description : Initialize Dynamic Memory pool * Return : LOS_OK on success or error code on failure */ + +/*这段代码是一个条件编译块,当定义了宏LOSCFG_EXC_INTERACTION时才会被编译。 + +LITE_OS_SEC_TEXT_INIT 是一个修饰符,用于指定函数所属的段(section)为.text.init,表示该函数在程序运行前会被初始化。 + +函数参数: + +memStart 是一个无符号整数指针,表示内存起始地址。 +函数内部逻辑: + +首先,函数将全局变量m_aucSysMem0指向memStart,即将系统内存的起始地址设为memStart。 +然后,函数将全局变量g_excInteractMemSize设置为宏定义EXC_INTERACT_MEM_SIZE的值,表示异常交互内存区域的大小。 +接下来,函数调用LOS_MemInit()函数,将m_aucSysMem0和g_excInteractMemSize作为参数进行内存初始化操作,并将返回结果保存在变量ret中。 +最后,函数打印一条信息,包含异常交互内存的地址和大小,并将初始化结果ret作为返回值返回。 +这段代码主要是用于初始化异常交互内存,通过调用LOS_MemInit()函数来初始化系统内存,并打印初始化信息。条件编译的目的是根据是否定义了LOSCFG_EXC_INTERACTION宏来控制代码的编译和执行。*/ LITE_OS_SEC_TEXT_INIT UINT32 OsMemSystemInit(UINTPTR memStart) { UINT32 ret; @@ -121,6 +158,18 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsMemSystemInit(UINTPTR memStart) * Description : print heap information * Input : pool --- Pointer to the manager, to distinguish heap */ +/*这段代码是用于打印内存池(pool)信息的函数,接收一个pool指针作为参数。 + +函数参数: + +pool 是一个指向内存池的指针,用于获取内存池的信息。 +函数内部逻辑: + +首先,函数将传入的pool指针转换为LosHeapManager结构体类型的指针,并赋值给变量heapMan。 +然后,函数定义了一个LosHeapStatus类型的变量status,用于保存堆管理器的状态信息。 +接着,函数调用OsHeapStatisticsGet()函数获取堆管理器的状态信息,并将其保存在status变量中。如果函数返回错误码LOS_NOK,则函数直接返回。 +最后,函数打印一条包含内存池信息的日志信息,包括内存池地址、内存池大小、已使用内存大小、空闲内存大小、最大空闲节点大小、已分配节点数量和空闲节点数量。 +这段代码主要是用于获取内存池的状态信息,并打印到控制台或日志文件中,方便调试和排查内存泄漏等问题。*/ VOID OsMemInfoPrint(const VOID *pool) { struct LosHeapManager *heapMan = (struct LosHeapManager *)pool; @@ -136,6 +185,20 @@ VOID OsMemInfoPrint(const VOID *pool) status.usedNodeNum, status.freeNodeNum); } +/*这段代码是用于内存分配的函数,可以从指定的内存池中分配一块指定大小的内存。 + +函数参数: + +pool 是一个指向内存池的指针,用于从该内存池中分配内存。 +size 是需要分配的内存大小。 +函数内部逻辑: + +首先,函数定义了一个空指针ptr,用于保存分配到的内存块地址。 +然后,函数检查传入的参数,如果pool为空或者size为0,则直接返回空指针。 +接着,函数锁住中断,调用OsSlabMemAlloc()函数尝试从内存池的SLAB分配器中获取一块指定大小的内存。如果分配成功,则将返回的内存地址保存在ptr中。 +如果从SLAB分配器中分配内存失败,则调用OsHeapAlloc()函数从堆内存中分配一块指定大小的内存,并将返回的内存地址保存在ptr中。 +最后,函数解锁中断,记录内存分配操作的追踪日志,并返回分配到的内存地址。 +这段代码主要是用于从内存池中分配内存,首先尝试从SLAB分配器中获取内存,如果失败则从堆内存中获取。在获取内存时还记录了内存分配操作的追踪日志,方便调试和内存优化。*/ LITE_OS_SEC_TEXT VOID *LOS_MemAlloc(VOID *pool, UINT32 size) { VOID *ptr = NULL; @@ -158,6 +221,19 @@ LITE_OS_SEC_TEXT VOID *LOS_MemAlloc(VOID *pool, UINT32 size) return ptr; } +/*这段代码是用于按指定对齐边界分配内存的函数,可以从指定的内存池中分配一块指定大小、按指定对齐边界对齐的内存。 + +函数参数: + +pool 是一个指向内存池的指针,用于从该内存池中分配内存。 +size 是需要分配的内存大小。 +boundary 是需要对齐的边界大小。返回的内存地址将会是该边界的整数倍。 +函数内部逻辑: + +首先,函数定义了一个空指针ptr,用于保存分配到的内存块地址。 +然后,函数锁住中断,调用OsHeapAllocAlign()函数从堆内存中按指定对齐边界分配一块指定大小的内存。如果分配成功,则将返回的内存地址保存在ptr中。 +最后,函数解锁中断,记录内存分配操作的追踪日志,并返回分配到的内存地址。 +这段代码主要是用于从内存池中按指定对齐边界分配内存,只能在堆内存上操作。在分配内存时还记录了内存分配操作的追踪日志,方便调试和内存优化。*/ LITE_OS_SEC_TEXT VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary) { VOID *ptr = NULL; @@ -171,6 +247,14 @@ LITE_OS_SEC_TEXT VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundar return ptr; } + +/*这段代码是用于重新分配内存大小的函数,主要有以下几个步骤: + +首先判断需要重新分配大小的指针ptr是否为空,如果为空,说明需要分配一块新的内存,直接调用LOS_MemAlloc()函数从内存池中分配一块指定大小的内存并返回。 +如果需要重新分配大小的指针ptr不为空且所需大小为0,则将该指针对应的内存块释放掉。 +如果需要重新分配大小的指针ptr不为空且所需大小非0,则需要从堆内存中分配一块新的内存,并将原内存中的数据拷贝到新内存中。这里在拷贝数据之前,需要先判断原内存地址是否合法。具体方法是通过OsSlabMemCheck()函数检查该指针是否属于内存池中的某个内存块,若是,则复制原内存中的数据;否则,根据原内存指针前面存储的一个整数值(表示实际内存块的大小和对齐状态)找到真正的内存块,再进行内存拷贝。 +将原内存块释放掉,返回分配到的新内存地址。 +这段代码的作用是实现重新分配内存大小的功能,可以对已经分配的内存进行扩展或缩小。在实现过程中,需要考虑到原内存块中已经存储的数据,避免无意义的内存拷贝操作。*/ VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size) { VOID *retPtr = NULL; @@ -228,6 +312,15 @@ VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size) return retPtr; } +/*这段代码是用于释放内存的函数,主要有以下几个步骤: + +首先判断内存池指针pool和需要释放的内存指针mem是否为空,如果其中任意一个为空,则返回错误码LOS_NOK表示释放失败。 +获取并保存当前的中断状态,以便后续恢复。 +调用OsSlabMemFree()函数尝试从内存池中释放指定的内存块。若成功释放,则将返回值设置为TRUE,否则继续执行下一步。 +如果调用OsSlabMemFree()函数失败,说明该内存块不是由内存池分配的,需要调用OsHeapFree()函数尝试从堆内存中释放指定的内存块。同样,若成功释放,则将返回值设置为TRUE,否则返回值保持为FALSE。 +恢复之前保存的中断状态。 +根据最终的返回值,如果为TRUE,则返回成功码LOS_OK,否则返回失败码LOS_NOK。 +这段代码的作用是实现内存的释放功能。首先尝试从内存池中释放内存,如果失败,则再尝试从堆内存中释放内存。通过这两种方式,可以确保能够释放从内存池或堆中分配的内存块。*/ LITE_OS_SEC_TEXT UINT32 LOS_MemFree(VOID *pool, VOID *mem) { BOOL ret = FALSE; @@ -250,6 +343,17 @@ LITE_OS_SEC_TEXT UINT32 LOS_MemFree(VOID *pool, VOID *mem) return (ret == TRUE ? LOS_OK : LOS_NOK); } +/*这段代码是用于获取内存池状态信息的函数,主要有以下几个步骤: + +首先判断内存池指针pool和状态信息指针status是否为空,如果其中任意一个为空,则返回错误码LOS_NOK表示获取失败。 +声明一个LosHeapStatus结构体类型的变量heapStatus,用于保存堆内存的状态信息。 +声明一个错误码变量err和一个中断状态变量intSave。 +获取并保存当前的中断状态,以便后续恢复。 +调用OsHeapStatisticsGet()函数获取指定内存池的堆内存状态信息,将结果保存在heapStatus中。如果返回错误码不等于LOS_OK,则表示获取失败,释放锁并返回错误码LOS_NOK。 +将获取到的堆内存状态信息赋值给传入的status参数,包括总使用大小、总空闲大小、最大空闲节点大小、已使用节点数量和空闲节点数量。 +如果配置了任务内存统计,则还会将使用的峰值赋值给status的uwUsageWaterLine字段。 +释放锁并返回成功码LOS_OK。 +这段代码的作用是获取指定内存池的状态信息,包括已使用的内存大小、空闲的内存大小、最大空闲节点的大小等。通过这些状态信息,可以了解内存池的使用情况,并进行相应的优化和管理。*/ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *status) { LosHeapStatus heapStatus; @@ -282,6 +386,15 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *st return LOS_OK; } +/*这段代码是用于获取指定内存池已使用内存大小的函数,主要有以下几个步骤: + +首先判断内存池指针pool是否为空,如果为空,则返回错误码OS_NULL_INT表示获取失败。 +声明一个LosHeapStatus结构体类型的变量heapStatus,用于保存堆内存的状态信息。 +声明一个错误码变量err和一个中断状态变量intSave。 +获取并保存当前的中断状态,以便后续恢复。 +调用OsHeapStatisticsGet()函数获取指定内存池的堆内存状态信息,将结果保存在heapStatus中。如果返回错误码不等于LOS_OK,则表示获取失败,释放锁并返回错误码OS_NULL_INT。 +释放锁并返回堆内存的总使用大小。 +这段代码的作用是获取指定内存池已使用的内存大小。通过该函数可以了解内存池的已使用情况,以便进行相应的管理和优化。*/ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemTotalUsedGet(VOID *pool) { LosHeapStatus heapStatus; @@ -303,6 +416,13 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemTotalUsedGet(VOID *pool) return heapStatus.totalUsedSize; } +/*这段代码是用于获取指定内存池的大小的函数,主要有以下几个步骤: + +首先判断内存池指针pool是否为空,如果为空,则返回错误码OS_NULL_INT表示获取失败。 +声明一个LosHeapManager结构体类型的指针变量heapManager,用于保存内存池的管理信息。 +将传入的内存池指针转换为LosHeapManager类型的指针,并将结果保存在heapManager中。 +返回内存池的大小,即heapManager->size。 +这段代码的作用是获取指定内存池的大小。通过该函数可以了解内存池的大小,以便进行相应的管理和优化。*/ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemPoolSizeGet(const VOID *pool) { struct LosHeapManager *heapManager = NULL; @@ -315,6 +435,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemPoolSizeGet(const VOID *pool) return heapManager->size; } +/*这段代码是用于对指定内存池进行完整性检查的函数,主要有以下几个步骤: + +首先判断内存池指针pool是否为空,如果为空,则返回错误码OS_NULL_INT表示检查失败。 +声明一个中断状态变量intSave和一个无符号整型变量ret用于保存检查结果。 +获取并保存当前的中断状态,以便后续恢复。 +调用OsHeapIntegrityCheck()函数对指定的内存池进行完整性检查,并将检查结果保存在ret中。如果返回的结果不为0,则表示检查失败。 +释放锁并返回检查结果。 +这段代码的作用是对指定的内存池进行完整性检查,以确保内存池中的数据没有被破坏或溢出。通过该函数可以及时发现内存池中的问题,并采取相应的措施进行修复或处理。*/ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemIntegrityCheck(VOID *pool) { UINT32 intSave; @@ -331,6 +459,16 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MemIntegrityCheck(VOID *pool) return ret; } +/*这段代码是用于对多个内存池进行完整性检查的函数,主要有以下几个步骤: + +首先调用LOS_MemIntegrityCheck()函数对系统内存池m_aucSysMem1进行完整性检查,并判断返回值是否为LOS_OK。 +如果检查通过,则在控制台输出一条信息表示检查成功,并在需要时将该信息写入异常信息缓冲区。 +如果系统内存池检查未通过,则不进行任何处理。 +如果宏定义LOSCFG_EXC_INTERACTION被定义,则继续执行下面的代码,否则直接结束函数。 +调用LOS_MemIntegrityCheck()函数对异常交互内存池m_aucSysMem0进行完整性检查,并判断返回值是否为LOS_OK。 +如果检查通过,则在控制台输出一条信息表示检查成功,并在需要时将该信息写入异常信息缓冲区。 +如果异常交互内存池检查未通过,则不进行任何处理。 +这段代码的作用是对多个内存池进行完整性检查,以确保内存池中的数据没有被破坏或溢出。通过该函数可以及时发现内存池中的问题,并采取相应的措施进行修复或处理。*/ VOID OsMemIntegrityMultiCheck(VOID) { if (LOS_MemIntegrityCheck(m_aucSysMem1) == LOS_OK) { diff --git a/src/kernel/base/mem/bestfit_little/los_memory_internal.h b/src/kernel/base/mem/bestfit_little/los_memory_internal.h index 2aeb022..52e29ff 100644 --- a/src/kernel/base/mem/bestfit_little/los_memory_internal.h +++ b/src/kernel/base/mem/bestfit_little/los_memory_internal.h @@ -42,13 +42,18 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//用于将指定的大小 sz 进行对齐,返回对齐后的大小。它使用 HEAP_ALIGN 宏定义来指定对齐的字节数,通过将 sz 加上 HEAP_ALIGN - 1,然后按位取反与运算(&)来实现向上对齐。 #define ALIGNE(sz) (((sz) + HEAP_ALIGN - 1) & (~(HEAP_ALIGN - 1))) +//用于将指定的 value 进行 align 字节对齐,返回对齐后的值。它将 value 转换为 UINT32 类型,并将其与 align - 1 按位取反与运算,即将 value 向上舍入到最近的 align 的倍数。 #define OS_MEM_ALIGN(value, align) (((UINT32)(UINTPTR)(value) + (UINT32)((align) - 1)) & \ (~(UINT32)((align) - 1))) +//用于表示对齐标志的宏定义,其值为 0x80000000。 #define OS_MEM_ALIGN_FLAG 0x80000000 +//用于设置对齐标志的宏定义,将传入的 align 参数按位或运算与 OS_MEM_ALIGN_FLAG 进行组合。 #define OS_MEM_SET_ALIGN_FLAG(align) ((align) = ((align) | OS_MEM_ALIGN_FLAG)) +//用于获取对齐标志的宏定义,将传入的 align 参数与 OS_MEM_ALIGN_FLAG 进行按位与运算,得到对齐标志。 #define OS_MEM_GET_ALIGN_FLAG(align) ((align) & OS_MEM_ALIGN_FLAG) +//用于获取对齐间隙大小的宏定义,将传入的 align 参数与 ~OS_MEM_ALIGN_FLAG 进行按位与运算,得到去除对齐标志后的值。 #define OS_MEM_GET_ALIGN_GAPSIZE(align) ((align) & (~OS_MEM_ALIGN_FLAG)) typedef struct tagLosHeapStatus { @@ -60,8 +65,12 @@ typedef struct tagLosHeapStatus { #ifdef LOSCFG_MEM_TASK_STAT UINT32 usageWaterLine; #endif -} LosHeapStatus; +} LosHeapStatus;//结构体:描述了内存堆的状态信息,包括总共使用的大小、总共空闲的大小、最大空闲节点的大小、已用节点数和空闲节点数等字段。 +/*结构体:描述了内存堆中的每个节点,包括前一个节点指针、任务 ID、节点大小、 +是否已经被使用、是否需要对齐等字段。这里使用了位域来节省空间, +并且使用了一个长度为 0 的数组 data[0] 来占位, +方便动态分配内存。*/ struct LosHeapNode { struct LosHeapNode *prev; #ifdef LOSCFG_MEM_TASK_STAT @@ -73,12 +82,12 @@ struct LosHeapNode { UINT8 data[0]; }; -extern BOOL OsHeapInit(VOID *pool, UINT32 size); -extern VOID* OsHeapAlloc(VOID *pool, UINT32 size); -extern VOID* OsHeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary); -extern BOOL OsHeapFree(VOID *pool, const VOID* ptr); -extern UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status); -extern UINT32 OsHeapIntegrityCheck(struct LosHeapManager *heap); +extern BOOL OsHeapInit(VOID *pool, UINT32 size);//函数声明:用于初始化内存池,即将一块内存空间转化为一个内存堆,并返回是否初始化成功。 +extern VOID* OsHeapAlloc(VOID *pool, UINT32 size);//函数声明:用于在内存堆上分配一块指定大小的内存,并返回分配到的内存地址。 +extern VOID* OsHeapAllocAlign(VOID *pool, UINT32 size, UINT32 boundary);//函数声明:用于在内存堆上分配一块指定大小并且按照给定对齐边界对齐的内存,并返回分配到的内存地址。 +extern BOOL OsHeapFree(VOID *pool, const VOID* ptr);//函数声明:用于释放内存堆中的指定内存地址所对应的节点,返回是否释放成功。 +extern UINT32 OsHeapStatisticsGet(VOID *pool, LosHeapStatus *status);//函数声明:用于获取内存堆的状态信息,并将其保存在传入的 LosHeapStatus 结构体中,返回获取到的信息字节数。 +extern UINT32 OsHeapIntegrityCheck(struct LosHeapManager *heap);//函数声明:用于检查整个内存堆的完整性,即检查是否存在内存泄漏或内存重叠等问题。 #ifdef __cplusplus #if __cplusplus diff --git a/src/kernel/base/mem/common/memstat/los_memstat.c b/src/kernel/base/mem/common/memstat/los_memstat.c index 7517b88..b0dc92c 100644 --- a/src/kernel/base/mem/common/memstat/los_memstat.c +++ b/src/kernel/base/mem/common/memstat/los_memstat.c @@ -39,6 +39,15 @@ extern "C" { #define MIN_TASK_ID(x, y) ((x) > (y) ? (y) : (x)) #define MAX_MEM_USE(x, y) ((x) > (y) ? (x) : (y)) +/*这段代码是一个函数OsMemstatTaskUsedInc的实现,用于更新内存统计信息。 + +代码首先获取任务ID的最小值,确保不越界。然后通过stat参数获取到任务内存统计数组taskMemstats。 + +接下来,代码将usedSize参数累加到对应任务的memUsed字段上,表示该任务使用的内存增加了usedSize字节。然后使用MAX_MEM_USE宏更新该任务的内存峰值,即将当前的memUsed值与memPeak进行比较,取较大值作为新的memPeak值。 + +最后,代码将usedSize参数累加到整体内存统计信息stat的memTotalUsed字段上,表示系统整体使用的内存增加了usedSize字节。同样地,使用MAX_MEM_USE宏更新整体内存的峰值。 + +这段代码的作用是在任务执行过程中,根据实际使用的内存大小更新任务和整体的内存统计信息。*/ LITE_OS_SEC_TEXT_MINOR VOID OsMemstatTaskUsedInc(Memstat *stat, UINT32 usedSize, UINT32 taskId) { UINT32 record = MIN_TASK_ID(taskId, TASK_NUM - 1); @@ -51,6 +60,13 @@ LITE_OS_SEC_TEXT_MINOR VOID OsMemstatTaskUsedInc(Memstat *stat, UINT32 usedSize, stat->memTotalPeak = MAX_MEM_USE(stat->memTotalPeak, stat->memTotalUsed); } +/*这段代码是一个函数OsMemstatTaskUsedDec的实现,用于更新内存统计信息。 + +代码首先获取任务ID的最小值,确保不越界。然后通过stat参数获取到任务内存统计数组taskMemstats。 + +接下来,代码判断当前任务使用的内存是否小于要释放的内存usedSize,如果是,则打印一条信息并直接返回。否则,将usedSize从对应任务的memUsed字段上减去,表示该任务使用的内存减少了usedSize字节。然后将usedSize从整体内存统计信息stat的memTotalUsed字段上减去,表示系统整体使用的内存减少了usedSize字节。 + +这段代码的作用是在任务执行过程中,根据实际释放的内存大小更新任务和整体的内存统计信息。如果当前任务使用的内存小于要释放的内存大小,则说明存在内存释放错误,打印一条信息以便调试。*/ LITE_OS_SEC_TEXT_MINOR VOID OsMemstatTaskUsedDec(Memstat *stat, UINT32 usedSize, UINT32 taskId) { UINT32 record = MIN_TASK_ID(taskId, TASK_NUM - 1); @@ -66,6 +82,15 @@ LITE_OS_SEC_TEXT_MINOR VOID OsMemstatTaskUsedDec(Memstat *stat, UINT32 usedSize, stat->memTotalUsed -= usedSize; } +/*这段代码是一个函数OsMemstatTaskClear的实现,用于清除任务的内存统计信息。 + +代码首先获取任务ID的最小值,确保不越界。然后通过stat参数获取到任务内存统计数组taskMemstats。 + +接下来,代码判断当前任务使用的内存是否为0,如果不为0,则打印一条信息,说明在删除任务时该任务仍有未释放的内存。 + +然后,将对应任务的memUsed字段和memPeak字段都设置为0,表示清除该任务的内存使用和内存峰值记录。 + +这段代码的作用是在删除任务时,清除该任务的内存统计信息,并在必要时打印警告信息以提醒开发者注意内存释放的完整性。*/ LITE_OS_SEC_TEXT_MINOR VOID OsMemstatTaskClear(Memstat *stat, UINT32 taskId) { UINT32 record = MIN_TASK_ID(taskId, TASK_NUM - 1); @@ -80,6 +105,13 @@ LITE_OS_SEC_TEXT_MINOR VOID OsMemstatTaskClear(Memstat *stat, UINT32 taskId) taskMemstats[record].memPeak = 0; } +/*这段代码是一个函数OsMemstatTaskUsage的实现,用于获取指定任务的内存使用量。 + +代码首先获取任务ID的最小值,确保不越界。然后通过stat参数获取到任务内存统计数组taskMemstats。 + +接下来,代码返回指定任务的memUsed字段,即该任务当前使用的内存量。 + +这段代码的作用是获取指定任务的内存使用量,可以用于监控和调试任务的内存消耗情况。*/ LITE_OS_SEC_TEXT_MINOR UINT32 OsMemstatTaskUsage(const Memstat *stat, UINT32 taskId) { UINT32 record = MIN_TASK_ID(taskId, TASK_NUM - 1); @@ -88,6 +120,17 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsMemstatTaskUsage(const Memstat *stat, UINT32 tas return taskMemstats[record].memUsed; } +/*这段代码是一个函数OsMemTaskUsage的实现,用于获取指定任务在系统内所有内存池中的内存使用量之和。 + +首先,代码定义了两个指针变量pool和stat,用于存储内存池信息和内存统计信息。 + +然后,通过判断是否开启了多内存池支持,分别处理单内存池和多内存池的情况。 + +如果未开启多内存池支持,则直接获取系统内存池的内存统计信息stat。最后,调用OsMemstatTaskUsage函数获取指定任务在该内存池中的内存使用量,并返回结果。 + +如果开启了多内存池支持,则需要遍历所有内存池,将每个内存池中指定任务的内存使用量累加起来,最终返回总和。 + +这段代码的作用是获取指定任务在系统内所有内存池中的内存使用量之和,可以用于监控和调试系统内存的消耗情况。*/ UINT32 OsMemTaskUsage(UINT32 taskId) { LosMemPoolInfo *pool = NULL; @@ -110,6 +153,17 @@ UINT32 OsMemTaskUsage(UINT32 taskId) #endif } +/*这段代码是一个函数OsMemTaskClear的实现,用于清除指定任务在系统内所有内存池中的内存统计信息。 + +首先,代码定义了两个指针变量pool和stat,用于存储内存池信息和内存统计信息。 + +然后,通过判断是否开启了多内存池支持,分别处理单内存池和多内存池的情况。 + +如果未开启多内存池支持,则直接获取系统内存池的内存统计信息stat。最后,调用OsMemstatTaskClear函数清除指定任务在该内存池中的内存统计信息。 + +如果开启了多内存池支持,则需要遍历所有内存池,依次获取每个内存池的内存统计信息,并调用OsMemstatTaskClear函数清除指定任务在每个内存池中的内存统计信息。 + +这段代码的作用是清除指定任务在系统内所有内存池中的内存统计信息,可以用于在删除任务时释放相关的内存统计记录,以确保内存统计信息的准确性。*/ VOID OsMemTaskClear(UINT32 taskId) { LosMemPoolInfo *pool = NULL; diff --git a/src/kernel/base/mem/common/multipool/los_multipool.c b/src/kernel/base/mem/common/multipool/los_multipool.c index c4c8e33..d50caa8 100644 --- a/src/kernel/base/mem/common/multipool/los_multipool.c +++ b/src/kernel/base/mem/common/multipool/los_multipool.c @@ -30,6 +30,17 @@ STATIC VOID *g_poolHead = NULL; +/*这段代码是一个函数OsMemMulPoolInit的实现,用于初始化多内存池。 + +首先,代码定义了几个变量,包括nextPool、curPool和poolEnd。其中,nextPool和curPool用于遍历内存池链表,poolEnd用于计算内存池的结束地址。 + +然后,通过循环遍历内存池链表,检查新的内存池是否与已有的内存池冲突。如果发现冲突,则输出错误信息并返回错误码。 + +接着,根据内存池链表的状态,将新的内存池插入到链表的末尾或者作为链表的头节点。 + +最后,设置新的内存池的下一个内存池指针为NULL,并返回成功的状态码。 + +这段代码的作用是初始化多内存池,将新的内存池插入到内存池链表中,并确保各个内存池之间没有冲突。多内存池的使用可以提供更灵活的内存管理能力,方便系统对不同类型的内存进行分配和释放。*/ UINT32 OsMemMulPoolInit(VOID *pool, UINT32 size) { VOID *nextPool = g_poolHead; @@ -58,6 +69,21 @@ UINT32 OsMemMulPoolInit(VOID *pool, UINT32 size) return LOS_OK; } +/*这段代码是一个函数OsMemMulPoolDeinit的实现,用于反初始化多内存池。 + +首先,代码定义了几个变量,包括ret、nextPool和curPool。其中,ret用于保存函数执行结果,nextPool和curPool用于遍历内存池链表。 + +然后,通过一个do-while循环的结构来执行具体的反初始化操作。 + +在循环中,首先检查传入的内存池指针是否为空,如果为空则直接退出循环。 + +接着,判断传入的内存池是否为链表的头节点。如果是头节点,则将链表的头指针指向下一个内存池,并返回成功的状态码。 + +如果不是头节点,则遍历内存池链表,寻找与传入的内存池指针相等的节点。一旦找到对应的节点,将前一个节点的next指针指向下一个节点,并返回成功的状态码。 + +最后,循环结束后,返回执行结果。 + +这段代码的作用是反初始化多内存池,从内存池链表中移除指定的内存池,并释放相关的资源。反初始化操作可以根据需要动态地增加或删除内存池,以适应系统的内存管理需求的变化。*/ UINT32 OsMemMulPoolDeinit(const VOID *pool) { UINT32 ret = LOS_NOK; @@ -90,12 +116,29 @@ UINT32 OsMemMulPoolDeinit(const VOID *pool) return ret; } +/*这段代码是函数OsMemMulPoolHeadGet的实现,用于获取多内存池链表的头节点指针。 +代码很简单,直接返回全局变量g_poolHead,该变量保存了多内存池链表的头节点指针。 + +调用这个函数可以方便地获取多内存池链表的头节点地址,以便后续进行其他操作,比如对内存池进行遍历、查询或者修改等。*/ VOID *OsMemMulPoolHeadGet(VOID) { return g_poolHead; } +/*这段代码是函数LOS_MemDeInit的实现,用于释放指定内存池的资源并进行反初始化操作。 + +首先,代码定义了几个变量,包括ret和intSave。其中,ret用于保存函数执行结果,intSave用于保存中断状态。 + +接下来,通过调用MEM_LOCK函数保存中断状态,以确保在执行反初始化操作期间不会被中断打断。 + +然后,调用OsMemMulPoolDeinit函数对指定的内存池进行反初始化操作,将返回结果保存到ret中。 + +最后,通过调用MEM_UNLOCK函数恢复之前保存的中断状态。 + +最终,返回执行结果。 + +这段代码的作用是释放指定内存池的资源,并执行反初始化操作。在释放内存池之前,使用MEM_LOCK函数保存中断状态,避免在释放内存池期间被中断打断,然后通过调用OsMemMulPoolDeinit函数执行反初始化操作。最后,使用MEM_UNLOCK函数恢复之前保存的中断状态。这样可以确保在释放内存池的过程中,不会发生竞态条件或者资源冲突的问题。*/ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemDeInit(VOID *pool) { UINT32 ret; @@ -108,6 +151,17 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemDeInit(VOID *pool) return ret; } +/*这段代码是函数LOS_MemPoolList的实现,用于打印多内存池链表中每个内存池的信息。 + +首先,代码定义了两个变量,包括nextPool和index。其中,nextPool用于保存下一个内存池的指针,index用于记录内存池的数量。 + +然后,通过一个while循环遍历多内存池链表,对每个内存池调用OsMemInfoPrint函数进行信息输出,并更新nextPool和index。 + +在循环中,先输出当前内存池的编号,然后调用OsMemInfoPrint函数输出该内存池的相关信息。 + +最后,返回内存池的数量。 + +这段代码的作用是打印多内存池链表中每个内存池的信息,便于开发人员进行调试和管理。通过遍历内存池链表,可以获取每个内存池的地址,并使用OsMemInfoPrint函数将内存池的相关信息输出到控制台上。同时,还可以统计内存池的数量,以便对内存池进行更精细的管理。*/ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemPoolList(VOID) { VOID *nextPool = g_poolHead; diff --git a/src/kernel/base/shellcmd/hwi_shellcmd.c b/src/kernel/base/shellcmd/hwi_shellcmd.c index 5ea7227..30a7e5f 100644 --- a/src/kernel/base/shellcmd/hwi_shellcmd.c +++ b/src/kernel/base/shellcmd/hwi_shellcmd.c @@ -25,7 +25,11 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/* +杩欎釜鏂囦欢鏄拡瀵筁iteOS鎿嶄綔绯荤粺涓殑Shell鍛戒护缂栧啓鐨勶紝涓昏瀹炵幇浜嗗纭欢涓柇淇℃伅鐨勮幏鍙栧拰鏄剧ず鍔熻兘锛 +鍖呮嫭浜嗗纭欢涓柇鐨勫叡浜ā寮忋佸搷搴旀鏁般丆PU鍒╃敤鐜囩瓑淇℃伅鐨勮幏鍙栧拰鏄剧ず銆傛牴鎹搷浣滅郴缁熼厤缃笉鍚岋紝 +杩樺寘鎷簡瀵笴PU鍒╃敤鐜囩殑涓嶅悓鏃堕棿娈碉紙鎵鏈夋椂闂淬佹渶杩10绉掋佹渶杩1绉掞級鐨勭粺璁″拰鏄剧ず銆 +*/ #include "los_config.h" #ifdef LOSCFG_SHELL #ifdef LOSCFG_CPUP_INCLUDE_IRQ @@ -39,7 +43,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ - +//杩欎釜鍑芥暟瀹炵幇浜嗘墦鍗扮‖浠朵腑鏂俊鎭殑琛ㄥご LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdHwiInfoTitle(VOID) { #ifdef LOSCFG_CPUP_INCLUDE_IRQ @@ -53,7 +57,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdHwiInfoTitle(VOID) PRINTK("----------- ----- ------------- --------- --------\n"); #endif } - +//杩欎釜鍑芥暟浼氭牴鎹紶鍏ョ殑纭欢涓柇鍙ユ焺淇℃伅锛岃幏鍙栬涓柇鏄惁涓哄叡浜ā寮 STATIC BOOL GetHwiShare(const HwiHandleInfo *hwiForm) { #ifndef LOSCFG_SHARED_IRQ @@ -64,9 +68,10 @@ STATIC BOOL GetHwiShare(const HwiHandleInfo *hwiForm) } #ifdef LOSCFG_CPUP_INCLUDE_IRQ -STATIC CPUP_INFO_S g_hwiCpupAll[LOSCFG_PLATFORM_HWI_LIMIT]; -STATIC CPUP_INFO_S g_hwiCpup10s[LOSCFG_PLATFORM_HWI_LIMIT]; -STATIC CPUP_INFO_S g_hwiCpup1s[LOSCFG_PLATFORM_HWI_LIMIT]; +STATIC CPUP_INFO_S g_hwiCpupAll[LOSCFG_PLATFORM_HWI_LIMIT];//鎵鏈夋椂闂存CPU鍒╃敤鐜囩殑缁熻淇℃伅 +STATIC CPUP_INFO_S g_hwiCpup10s[LOSCFG_PLATFORM_HWI_LIMIT];//鏈杩10sCPU鍒╃敤鐜囩殑缁熻淇℃伅 +STATIC CPUP_INFO_S g_hwiCpup1s[LOSCFG_PLATFORM_HWI_LIMIT];//鏈杩1sCPU鍒╃敤鐜囩殑缁熻淇℃伅 +//杩欎釜鍑芥暟瀹炵幇浜嗙‖浠朵腑鏂俊鎭殑鏌ヨ锛屾牴鎹弬鏁癮rgc鍜宎rgv鍒ゆ柇鏄惁鏈夎锛屽苟璋冪敤鍏朵粬鍑芥暟鑾峰彇纭欢涓柇鐨勫悇椤逛俊鎭紝鏈缁堟墦鍗拌緭鍑虹‖浠朵腑鏂殑璇︾粏淇℃伅銆 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv) { UINT32 i, intSave; @@ -75,22 +80,24 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv) HwiHandleInfo *hwiForm = NULL; (VOID)argv; + //鎵撳嵃閿欒淇℃伅 if (argc > 0) { PRINTK("\nUsage: hwi\n"); return OS_ERROR; } - (VOID)memset_s(g_hwiCpupAll, size, 0, size); - (VOID)memset_s(g_hwiCpup10s, size, 0, size); - (VOID)memset_s(g_hwiCpup1s, size, 0, size); + (VOID)memset_s(g_hwiCpupAll, size, 0, size);//缃浂 + (VOID)memset_s(g_hwiCpup10s, size, 0, size);//缃浂 + (VOID)memset_s(g_hwiCpup1s, size, 0, size);//缃浂 intSave = LOS_IntLock(); (VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpupAll, CPUP_ALL_TIME, 0); (VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpup10s, CPUP_LAST_TEN_SECONDS, 0); (VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpup1s, CPUP_LAST_ONE_SECONDS, 0); LOS_IntRestore(intSave); - + //鎵撳嵃纭欢涓柇淇℃伅鐨勮〃澶 OsShellCmdHwiInfoTitle(); + //鎵撳嵃CPU纭欢涓柇鐨勫埄鐢ㄧ巼 for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) { if (!HWI_IS_REGISTED(i)) { continue; @@ -101,6 +108,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv) } /* Different cores has different hwi form implementation */ + //鎵撳嵃鍚勪釜鏃堕棿鍐呯殑纭欢涓柇鍒╃敤鐜 hwiForm = OsGetHwiForm(i); PRINTK("%-8u\t %-s\t %-10u\t %-10llu %2u.%-7u %2u.%-7u %2u.%-6u", i, GetHwiShare(hwiForm) ? "Y" : "N", OsGetHwiFormCnt(i), cycles, @@ -110,6 +118,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv) #ifdef LOSCFG_SHARED_IRQ hwiForm = hwiForm->next; #endif + //鎵撳嵃涓柇璁惧ID鍜屼俊鎭 if ((hwiForm->registerInfo != 0) && ((HWI_IRQ_PARAM_S *)hwiForm->registerInfo)->pName != NULL) { PRINTK("\t %-16s 0x%-.8x\n", ((HWI_IRQ_PARAM_S *)hwiForm->registerInfo)->pName, @@ -128,24 +137,28 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv) return 0; } #else +//杩欎釜鍑芥暟涓昏瀹炵幇瀵筯wi鍛戒护鐨勮В閲婂姛鑳斤紝杈撳嚭纭欢涓柇淇℃伅 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv) { UINT32 i; HwiHandleInfo *hwiForm = NULL; + //鍙傛暟閿欒锛屾墦鍗伴敊璇俊鎭 (VOID)argv; if (argc > 0) { PRINTK("\nUsage: hwi\n"); return OS_ERROR; } - + //鎵撳嵃纭欢涓柇淇℃伅鐨勮〃澶 OsShellCmdHwiInfoTitle(); + //閬嶅巻鎵鏈夌‖浠朵腑鏂瘎瀛樺櫒 for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) { if (!HWI_IS_REGISTED(i)) { continue; } /* Different cores has different hwi form implementation */ + //杈撳嚭淇℃伅 hwiForm = OsGetHwiForm(i); PRINTK("%-8u\t %-s\t %-10u", i, GetHwiShare(hwiForm) ? "Y" : "N", OsGetHwiFormCnt(i)); #ifdef LOSCFG_SHARED_IRQ @@ -170,7 +183,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv) return 0; } #endif - +//璇ュ嚱鏁板疄鐜颁簡OsShellCmdHwi鐨勫嚱鏁拌皟鐢紝鐢ㄦ埛鍙互杈撳叆hwi鍛戒护鏉ヨ皟鐢ㄨ鍑芥暟锛屼粠鑰屾煡璇㈠拰灞曠ず纭欢涓柇淇℃伅 SHELLCMD_ENTRY(hwi_shellcmd, CMD_TYPE_EX, "hwi", 0, (CmdCallBackFunc)OsShellCmdHwi); #ifdef __cplusplus diff --git a/src/kernel/base/shellcmd/mempt_shellcmd.c b/src/kernel/base/shellcmd/mempt_shellcmd.c index 9c4be25..b67641e 100644 --- a/src/kernel/base/shellcmd/mempt_shellcmd.c +++ b/src/kernel/base/shellcmd/mempt_shellcmd.c @@ -25,7 +25,10 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/* +杩欎釜鏂囦欢鏄拡瀵筁iteOS鎿嶄綔绯荤粺涓殑Shell鍛戒护缂栧啓鐨勶紝 +涓昏瀹炵幇浜嗙郴缁熷唴瀛樼殑瀹夊叏妫鏌ャ佺郴缁熷唴瀛樹娇鐢ㄦ儏鍐电殑鏄剧ず銆佽鍙栨寚瀹氬唴瀛樹腑鎸囧畾浣嶇疆鎸囧畾闀垮害鐨勪俊鎭拰閲婃斁鍐呭瓨绌洪棿銆 +*/ #include "stdlib.h" #include "stdio.h" #include "los_memory_pri.h" @@ -45,54 +48,60 @@ extern "C" { #define MEM_SIZE_1K 0x400 #define MEM_SIZE_1M 0x100000 - +//杩欎釜鍑芥暟鐢ㄤ簬妫鏌ュ唴瀛樺畬鏁存 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[]) { + //鎵撳嵃閿欒淇℃伅 if (argc > 0) { PRINTK("\nUsage: memcheck\n"); return OS_ERROR; } - + //璋冪敤OsMemIntegrityMultiCheck鍑芥暟瀹屾垚鍐呭瓨瀹屾暣鎬ф鏌 OsMemIntegrityMultiCheck(); return 0; } #ifdef LOSCFG_SHELL +//杩欎釜鍑芥暟鍙互璇诲彇鍐呭瓨涓寚瀹氫綅缃寚瀹氶暱搴︾殑鏁版嵁锛岃皟鐢∣sDumpMemByte鍑芥暟瀹屾垚鍐呭瓨璇诲彇骞舵墦鍗版暟鎹 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemRead(INT32 argc, const CHAR *argv[]) { size_t tempAddr; size_t length; CHAR *ptrlen = NULL; CHAR *ptrAddr = NULL; - + //璇诲彇閿欒锛屾墦鍗伴敊璇俊鎭 if ((argc == 0) || (argc > 2)) { /* argc is num of parameters */ PRINTK("\nUsage: readreg [ADDRESS] [LENGTH]\n"); return OS_ERROR; } - + //璇诲彇姝g‘ if (argc == 1) { length = 0; } else { + //璇诲彇闀垮害涓鸿礋鏁帮紝鎵撳嵃閿欒淇℃伅 length = strtoul(argv[1], &ptrlen, 0); if ((ptrlen == NULL) || (*ptrlen != 0)) { PRINTK("readreg invalid length %s\n", argv[1]); return OS_ERROR; } } + //淇濆瓨ptrAddr鐨勫湴鍧 tempAddr = strtoul(argv[0], &ptrAddr, 0); + //鍦板潃閿欒锛屾墦鍗伴敊璇俊鎭 if ((ptrAddr == NULL) || (*ptrAddr != 0) || (tempAddr > g_sys_mem_addr_end) || ((tempAddr + length) > g_sys_mem_addr_end) || (tempAddr > (OS_NULL_INT - length))) { PRINTK("readreg invalid address %s\n", argv[0]); return OS_ERROR; } - + //璋冪敤OsDumpMemByte鍑芥暟锛屾墦鍗版寚瀹氬唴瀛樹綅缃鍙栫殑淇℃伅銆 OsDumpMemByte(length, tempAddr); return 0; } - +//杩欎釜鍑芥暟鐢ㄤ簬杈撳嚭浠g爜娈点佹暟鎹銆佸彧璇绘暟鎹鍜孊SS娈电殑澶у皬淇℃伅銆 LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR *argv[]) { + //璁$畻鍚勯儴鍒嗛暱搴 size_t textLen = &__text_end - &__text_start; size_t dataLen = &__ram_data_end - &__ram_data_start; size_t rodataLen = &__rodata_end - &__rodata_start; @@ -103,7 +112,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR dataLen += &__fast_data_end - &__fast_data_start; rodataLen += &__fast_rodata_end - &__fast_rodata_start; #endif - + //鎵撳嵃浠g爜娈点佹暟鎹銆佸彧璇绘暟鎹銆丅SS娈电殑澶у皬淇℃伅 PRINTK("\r\n text data rodata bss\n"); if ((argc == 1) && (strcmp(argv[0], "-k") == 0)) { PRINTK("Mem: %-9lu %-10lu %-10lu %-10lu\n", textLen / MEM_SIZE_1K, dataLen / MEM_SIZE_1K, @@ -115,19 +124,24 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR PRINTK("Mem: %-9lu %-10lu %-10lu %-10lu\n", textLen, dataLen, rodataLen, bssLen); } } - +//杩欎釜鍑芥暟鐢ㄤ簬杈撳嚭绯荤粺鍙敤鐨勫唴瀛樻婚噺銆佸凡缁忎娇鐢ㄧ殑鍐呭瓨閲忓拰鍓╀綑鍐呭瓨閲忕殑澶у皬 LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OsShellCmdFreeInfo(INT32 argc, const CHAR *argv[]) { #ifdef LOSCFG_EXC_INTERACTION + //璋冪敤LOS_MemTotaUsedGet鍑芥暟寰楀埌宸茬粡浣跨敤鐨勫唴瀛橀噺 UINT32 memUsed0 = LOS_MemTotalUsedGet(m_aucSysMem0); + //璋冪敤LOS_MemPoolSizeGet鍑芥暟寰楀埌绯荤粺鍙敤鐨勫唴瀛樻婚噺 UINT32 totalMem0 = LOS_MemPoolSizeGet(m_aucSysMem0); + //璁$畻寰楀埌绯荤粺鍓╀綑鐨勫唴瀛橀噺 UINT32 freeMem0 = totalMem0 - memUsed0; #endif - + //璋冪敤LOS_MemTotaUsedGet鍑芥暟寰楀埌宸茬粡浣跨敤鐨勫唴瀛橀噺 UINT32 memUsed = LOS_MemTotalUsedGet(m_aucSysMem1); + //璋冪敤LOS_MemPoolSizeGet鍑芥暟寰楀埌绯荤粺鍙敤鐨勫唴瀛樻婚噺 UINT32 totalMem = LOS_MemPoolSizeGet(m_aucSysMem1); + /璁$畻寰楀埌绯荤粺鍓╀綑鐨勫唴瀛橀噺 UINT32 freeMem = totalMem - memUsed; - + //鎵撳嵃缁熷彲鐢ㄧ殑鍐呭瓨鎬婚噺銆佸凡缁忎娇鐢ㄧ殑鍐呭瓨閲忓拰鍓╀綑鍐呭瓨閲忕殑澶у皬 if ((argc == 0) || ((argc == 1) && (strcmp(argv[0], "-k") == 0)) || ((argc == 1) && (strcmp(argv[0], "-m") == 0))) { @@ -157,47 +171,57 @@ LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OsShellCmdFreeInfo(INT32 argc, const CHAR * PRINTK("Mem1: %-9u %-10u %-10u\n", totalMem0, memUsed0, freeMem0); #endif } else { + //鎵撳嵃閿欒淇℃伅 PRINTK("\nUsage: free or free [-k/-m]\n"); return OS_ERROR; } return 0; } - +//杩欎釜鍑芥暟鐢ㄤ簬鏄剧ず绯荤粺鍐呭瓨鐨勪娇鐢ㄦ儏鍐碉紝璋冪敤浜哋sShellCmdFreeInfo鍜孫sShellCmdSectionInfo鍑芥暟瀹屾垚鍐呭瓨浣跨敤鎯呭喌鍜屽唴瀛樺垎閰嶆儏鍐电殑鎵撳嵃杈撳嚭銆 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdFree(INT32 argc, const CHAR *argv[]) { + //鎵撳嵃閿欒淇℃伅 if (argc > 1) { PRINTK("\nUsage: free or free [-k/-m]\n"); return OS_ERROR; } + //鎵撳嵃閿欒淇℃伅 if (OsShellCmdFreeInfo(argc, argv) != 0) { return OS_ERROR; } + //璋冪敤OsShellCmdSectionInfo鍑芥暟杈撳嚭瀛樹娇鐢ㄦ儏鍐靛拰鍐呭瓨鍒嗛厤鎯呭喌 OsShellCmdSectionInfo(argc, argv); return 0; } - +//杩欎釜鍑芥暟鏍规嵁鍙傛暟閫夋嫨杈撳嚭涓嶅悓鐨勭郴缁熶俊鎭紝鍦ㄦ帶鍒跺彴涓婅緭鍑虹浉搴旂殑淇℃伅銆 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[]) { + //濡傛灉鍙傛暟涓0锛屽湪鎺у埗鍙颁笂鎵撳嵃Huawei LiteOS if (argc == 0) { PRINTK("Huawei LiteOS\n"); return 0; } if (argc == 1) { + //绯荤粺鍙傛暟涓-a鏃讹紝鎵撳嵃LiteOS鎵鏈夌殑淇℃伅 if (strcmp(argv[0], "-a") == 0) { PRINTK("%s %s %s %s %s\n", HW_LITEOS_VER, HW_LITEOS_SYSNAME, HW_LITEOS_KERNEL_VERSION_STRING, __DATE__, __TIME__); return 0; + //绯荤粺鍙傛暟涓-s鏃讹紝鎵撳嵃Huawei LiteOS } else if (strcmp(argv[0], "-s") == 0) { PRINTK("Huawei LiteOS\n"); return 0; + //绯荤粺鍙傛暟涓-t鏃讹紝鎵撳嵃绯荤粺鍒涘缓鐨勬椂闂翠俊鎭 } else if (strcmp(argv[0], "-t") == 0) { PRINTK("build date : %s %s", __DATE__, __TIME__); return 0; + //绯荤粺鍙傛暟涓-v鏃讹紝鎵撳嵃LiteOS鐨勭増鏈俊鎭拰鏃堕棿淇℃伅 } else if (strcmp(argv[0], "-v") == 0) { PRINTK("%s %s %s %s\n", HW_LITEOS_SYSNAME, HW_LITEOS_KERNEL_VERSION_STRING, __DATE__, __TIME__); return 0; + //绯荤粺鍙傛暟涓--help鏃讹紝鎵撳嵃鍚勫弬鏁扮殑鍚箟 } else if (strcmp(argv[0], "--help") == 0) { PRINTK("-a, print all information\n" "-s, print the kernel name\n" @@ -206,20 +230,22 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[]) return 0; } } - + //濡傛灉閮戒笉鏄紝鎵撳嵃閿欒淇℃伅锛屾彁绀虹敤鎴疯緭鍏--help鏉ユ煡鐪嬩俊鎭 PRINTK("uname: invalid option %s\n" "Try 'uname --help' for more information.\n", argv[0]); return OS_ERROR; } #ifdef LOSCFG_MEM_LEAKCHECK +//杩欎釜鍑芥暟鎵撳嵃浜嗙郴缁熷凡浣跨敤鐨勫唴瀛樹俊鎭 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemUsed(INT32 argc, const CHAR *argv[]) { + //鎵撳嵃閿欒淇℃伅 if (argc > 0) { PRINTK("\nUsage: memused\n"); return OS_ERROR; } - + //璋冪敤OsMemUsedNodeShow鍑芥暟锛岃緭鍑哄凡浣跨敤鐨勮妭鐐逛俊鎭 OsMemUsedNodeShow(m_aucSysMem1); #ifdef LOSCFG_EXC_INTERACTION @@ -230,6 +256,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemUsed(INT32 argc, const CHAR *argv[]) } #endif +/* +鍛戒护瑙i噴鍣ㄤ釜鍚勪釜鍛戒护璋冪敤鐨勫嚱鏁颁互鍙婁綔鐢 +memcheck鍛戒护锛氭鏌ュ唴瀛樺畬鏁存с傝皟鐢ㄤ簡OsMemIntegrityMultiCheck鍑芥暟瀹屾垚鍐呭瓨瀹屾暣鎬ф鏌ャ +memread [ADDRESS] [LENGTH]鍛戒护锛氳鍙栨寚瀹氬湴鍧鍜岄暱搴︾殑鍐呭瓨鏁版嵁銆傝皟鐢ㄤ簡OsDumpMemByte鍑芥暟瀹屾垚鍐呭瓨鏁版嵁璇诲彇骞舵墦鍗拌緭鍑恒 +free鍛戒护锛氭樉绀虹郴缁熷唴瀛樼殑浣跨敤鎯呭喌銆傝皟鐢ㄤ簡OsShellCmdFreeInfo鍜孫sShellCmdSectionInfo鍑芥暟瀹屾垚鍐呭瓨浣跨敤鎯呭喌鍜屽唴瀛樺垎閰嶆儏鍐电殑鎵撳嵃杈撳嚭銆 +uname [-a/-s/-t/-v]鍛戒护锛氭樉绀虹郴缁熶俊鎭傛牴鎹弬鏁伴夋嫨杈撳嚭涓嶅悓鐨勭郴缁熶俊鎭傝皟鐢ㄤ簡PRINTK瀹忓湪鎺у埗鍙颁笂杈撳嚭鐩稿簲鐨勪俊鎭 +*/ + #ifdef LOSCFG_MEM_LEAKCHECK SHELLCMD_ENTRY(memused_shellcmd, CMD_TYPE_EX, "memused", 0, (CmdCallBackFunc)OsShellCmdMemUsed); #endif diff --git a/src/kernel/base/shellcmd/stack_shellcmd.c b/src/kernel/base/shellcmd/stack_shellcmd.c index 1ac2386..607fac0 100644 --- a/src/kernel/base/shellcmd/stack_shellcmd.c +++ b/src/kernel/base/shellcmd/stack_shellcmd.c @@ -25,7 +25,10 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/* +杩欐鏂囦欢鏄拡瀵筁iteOS鎿嶄綔绯荤粺涓殑Shell鍛戒护缂栧啓鐨勶紝 +涓昏瀹炵幇浜嗗唴鏍稿紓甯稿鐞嗘満鍒朵腑涓庡爢鏍堢浉鍏崇殑鍔熻兘锛屽寘鎷爢鏍堜俊鎭殑鑾峰彇鍜屾鏌ャ +*/ #include "securec.h" #include "los_config.h" #include "los_stackinfo_pri.h" @@ -34,7 +37,7 @@ #include "shcmd.h" #include "shell.h" #endif - +//杩欎釜鍑芥暟鐢ㄤ簬妫鏌ュ爢鏍堟槸鍚︽孩鍑 VOID OsExcStackCheck(VOID) { UINT32 index; @@ -42,15 +45,17 @@ VOID OsExcStackCheck(VOID) UINTPTR *stackTop = NULL; const StackInfo *stackInfo = NULL; UINT32 stackNum; - + //鑾峰彇鍫嗘爤淇℃伅锛屽鏋滃爢鏍堜俊鎭敊璇紝鐩存帴杩斿洖 OsGetStackInfo(&stackInfo, &stackNum); if ((stackInfo == NULL) || (stackNum == 0)) { return; } - + //浠庡ご寮濮嬶紝閬嶅巻鎵鏈夌殑鍫嗘爤 for (index = 0; index < stackNum; index++) { for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) { + //鍫嗘爤鐨勬爤椤 stackTop = (UINTPTR *)((UINTPTR)stackInfo[index].stackTop + cpuid * stackInfo[index].stackSize); + //妫鏌ユ爤椤朵俊鎭槸鍚﹁绡℃敼锛屽鏋滆绡℃敼杈撳嚭璇ュ爢鏍堟孩鍑虹殑淇℃伅 if (*stackTop != OS_STACK_MAGIC_WORD) { PRINT_ERR("cpu:%u %s overflow , magic word changed to 0x%x\n", LOSCFG_KERNEL_CORE_NUM - 1 - cpuid, stackInfo[index].stackName, *stackTop); @@ -58,7 +63,7 @@ VOID OsExcStackCheck(VOID) } } } - +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇骞舵墦鍗版墍鏈夌殑鍫嗘爤淇℃伅 VOID OsExcStackInfo(VOID) { UINT32 index; @@ -68,29 +73,31 @@ VOID OsExcStackInfo(VOID) UINTPTR *stack = NULL; const StackInfo *stackInfo = NULL; UINT32 stackNum; - + //鑾峰彇鍫嗘爤淇℃伅锛屽鏋滃爢鏍堜俊鎭敊璇紝鐩存帴杩斿洖 OsGetStackInfo(&stackInfo, &stackNum); if ((stackInfo == NULL) || (stackNum == 0)) { return; } - + //杈撳嚭鍫嗘爤鍚嶃丆PU ID銆佸爢鏍堢殑鍦板潃銆佸爢鏍堢殑鎬诲ぇ灏忥紝鍫嗘爤宸蹭娇鐢ㄧ殑澶у皬 PrintExcInfo("\n stack name cpu id stack addr total size used size\n" " ---------- ------ --------- -------- --------\n"); - + //浠庡ご寮濮嬶紝閬嶅巻鎵鏈夌殑鍫嗘爤 for (index = 0; index < stackNum; index++) { for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) { + //鑾峰彇鍫嗘爤鐨勬爤椤 stackTop = (UINTPTR *)((UINTPTR)stackInfo[index].stackTop + cpuid * stackInfo[index].stackSize); stack = (UINTPTR *)((UINTPTR)stackTop + stackInfo[index].stackSize); + //璋冪敤OsStackWaterLineGet鍑芥暟璁$畻鍫嗘爤宸蹭娇鐢ㄧ殑澶у皬 (VOID)OsStackWaterLineGet(stack, stackTop, &size); - + //杈撳嚭鍚勭被淇℃伅 PrintExcInfo("%11s %-5d %-10p 0x%-8x 0x%-4x\n", stackInfo[index].stackName, LOSCFG_KERNEL_CORE_NUM - 1 - cpuid, stackTop, stackInfo[index].stackSize, size); } } - + //杩涜鍫嗘爤婧㈠嚭妫鏌 OsExcStackCheck(); } - +//娉ㄥ唽Shell鍛戒护stack锛岃皟鐢∣sExcStackInfo鍑芥暟鑾峰彇骞舵墦鍗版墍鏈夊爢鏍堜俊鎭嚦鎺у埗鍙般 #ifdef LOSCFG_SHELL SHELLCMD_ENTRY(stack_shellcmd, CMD_TYPE_EX, "stack", 1, (CmdCallBackFunc)OsExcStackInfo); #endif diff --git a/src/kernel/base/shellcmd/swtmr_shellcmd.c b/src/kernel/base/shellcmd/swtmr_shellcmd.c index 476c660..95039e2 100644 --- a/src/kernel/base/shellcmd/swtmr_shellcmd.c +++ b/src/kernel/base/shellcmd/swtmr_shellcmd.c @@ -25,7 +25,10 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/* +杩欎釜鏂囦欢涓昏鏄拡瀵筁iteOS绯荤粺涓蒋浠跺畾鏃跺櫒鐨勫懡浠よ鎿嶄綔杩涜瀹氫箟鍜屽疄鐜扮殑锛 +涓昏瀹炵幇浜嗘牴鎹蒋浠跺畾鏃跺櫒鐨処D杈撳嚭杞欢瀹氭椂鍣ㄧ殑鍚勭淇℃伅銆 +*/ #include "los_config.h" #ifdef LOSCFG_SHELL #include "stdlib.h" @@ -42,20 +45,20 @@ extern "C" { #define SWTMR_STRLEN 12 #ifdef LOSCFG_BASE_CORE_SWTMR - +//灞曠ずg_shellSwtmrMode鐨勬暟鎹 LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrMode[][SWTMR_STRLEN] = { "Once", "Period", "NSD", "OPP", }; - +//灞曠ずg_shellSwtmrStatus鐨勬暟鎹 LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrStatus[][SWTMR_STRLEN] = { "UnUsed", "Created", "Ticking", }; - +//杩欎釜鍑芥暟鐢ㄤ簬鎵撳嵃杞欢瀹氭椂鍣ㄧ殑淇℃伅锛屽寘鎷畾鏃跺櫒ID銆佺姸鎬併佹ā寮忋侀棿闅斻佸弬鏁板拰澶勭悊鍑芥暟鍦板潃绛夈 STATIC VOID OsPrintSwtmrMsg(const LosSwtmrCB *swtmr) { PRINTK("0x%08x " @@ -64,20 +67,20 @@ STATIC VOID OsPrintSwtmrMsg(const LosSwtmrCB *swtmr) "%-6u " "0x%08x " "%p\n", - swtmr->timerId % LOSCFG_BASE_CORE_SWTMR_LIMIT, - g_shellSwtmrStatus[swtmr->state], - g_shellSwtmrMode[swtmr->mode], - swtmr->interval, - swtmr->arg, - swtmr->handler); + swtmr->timerId % LOSCFG_BASE_CORE_SWTMR_LIMIT,//鎵撳嵃瀹氭椂鍣↖D + g_shellSwtmrStatus[swtmr->state],//鎵撳嵃瀹氭椂鍣ㄧ殑鐘舵 + g_shellSwtmrMode[swtmr->mode],//鎵撳嵃瀹氭椂鍣ㄧ殑妯″紡 + swtmr->interval,//鎵撳嵃瀹氭椂鍣ㄧ殑闂撮殧 + swtmr->arg,//鎵撳嵃瀹氭椂鍣ㄧ殑鍙傛暟 + swtmr->handler);//鎵撳嵃瀹氭椂鍣ㄧ殑澶勭悊鍑芥暟鍦板潃 } - +//杩欎釜鍑芥暟鐢ㄤ簬鎵撳嵃杞欢瀹氭椂鍣ㄤ俊鎭殑琛ㄥご STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID) { PRINTK("\r\nSwTmrID State Mode Interval Arg handlerAddr\n"); PRINTK("---------- ------- ------- --------- ---------- --------\n"); } - +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇杞欢瀹氭椂鍣ㄧ殑淇℃伅銆 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **argv) { #define OS_ALL_SWTMR_MASK 0xffffffff @@ -87,34 +90,36 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a size_t timerId; UINT16 num = 0; CHAR *endPtr = NULL; - + //鎵撳嵃閿欒淇℃伅 if (argc > 1) { PRINTK("\nUsage: swtmr [ID]\n"); return OS_ERROR; } - + //鑾峰彇璁℃椂鍣↖D if (argc == 0) { timerId = OS_ALL_SWTMR_MASK; } else { + //娌℃湁杩欎釜ID锛屾墦鍗伴敊璇俊鎭 timerId = strtoul((CHAR *)argv[0], &endPtr, 0); if ((endPtr == NULL) || (*endPtr != 0) || (timerId > LOSCFG_BASE_CORE_SWTMR_LIMIT)) { PRINTK("\nswtmr ID can't access %s.\n", argv[0]); return OS_ERROR; } } - + //閬嶅巻鎵鏈夎鏃跺櫒锛岃璁℃椂鍣ㄧ殑鐘舵佸姞1 for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr1++) { if (swtmr1->state == 0) { num = num + 1; } } - + //杈惧埌鏃堕棿闄愬埗锛岃緭鍑洪敊璇俊鎭 if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) { PRINTK("\r\nThere is no swtmr was created!\n"); return OS_ERROR; } - + //鎵撳嵃杞欢瀹氭椂鍣ㄤ俊鎭殑琛ㄥご OsPrintSwtmrMsgHead(); + //鎵撳嵃杞欢瀹氭椂鍣ㄧ殑鍚勭被淇℃伅 if (timerId == OS_ALL_SWTMR_MASK) { for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) { if (swtmr->state != 0) { @@ -132,7 +137,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a } return LOS_OK; } - +//娉ㄥ唽Shell鍛戒护swtmr锛岃皟鐢∣sShellCmdSwtmrInfoGet鍑芥暟鑾峰彇杞欢瀹氭椂鍣ㄧ殑淇℃伅銆傛牴鎹緭鍏ョ殑鍙傛暟鑾峰彇鐗瑰畾鎴栬呮墍鏈夎蒋浠跺畾鏃跺櫒鐨勭姸鎬佷俊鎭苟鎵撳嵃鍑烘潵銆 SHELLCMD_ENTRY(swtmr_shellcmd, CMD_TYPE_EX, "swtmr", 1, (CmdCallBackFunc)OsShellCmdSwtmrInfoGet); #endif diff --git a/src/kernel/base/shellcmd/sysinfo_shellcmd.c b/src/kernel/base/shellcmd/sysinfo_shellcmd.c index 69f73a5..813a2ea 100644 --- a/src/kernel/base/shellcmd/sysinfo_shellcmd.c +++ b/src/kernel/base/shellcmd/sysinfo_shellcmd.c @@ -25,7 +25,10 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/* +杩欐鏂囦欢鏄拡瀵筁iteOS鎿嶄綔绯荤粺涓殑Shell鍛戒护缂栧啓鐨勶紝 +涓昏瀹炵幇浜嗚幏鍙栫郴缁熶俊鎭殑鍔熻兘锛岃幏鍙栫殑淇℃伅鍖呮嫭杩涚▼鏁伴噺銆佷俊鍙烽噺鏁伴噺銆佷簰鏂ラ攣鏁伴噺銆佹秷鎭槦鍒楁暟閲忓拰杞欢瀹氭椂鍣ㄦ暟閲忋 +*/ #include "los_config.h" #include "los_swtmr.h" #include "los_sem_pri.h" @@ -43,141 +46,173 @@ extern "C" { #endif #endif /* __cplusplus */ - +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇褰撶郴缁熺殑杩涚▼鏁伴噺 UINT32 OsShellCmdTaskCntGet(VOID) { UINT32 loop; UINT32 taskCnt = 0; UINT32 intSave; LosTaskCB *taskCB = NULL; - + //鍔犱笂閿侊紝鐢ㄤ簬闃叉涓柇 intSave = LOS_IntLock(); + //閬嶅巻鎵鏈夎繘绋嬶紝骞剁粺璁¤繘绋嬫暟閲 for (loop = 0; loop < g_taskMaxNum; loop++) { taskCB = (LosTaskCB *)g_taskCBArray + loop; + //鑻ヨ杩涚▼鏈娇鐢紝鍒欑洿鎺ヨ烦杩 if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { continue; } taskCnt++; } + //涓鸿繘绋嬭В閿 LOS_IntRestore(intSave); + //杩斿洖绯荤粺鐨勮繘绋嬫暟閲 return taskCnt; } #ifdef LOSCFG_BASE_IPC_SEM +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇褰撳墠绯荤粺淇″彿閲忕殑鏁伴噺 UINT32 OsShellCmdSemCntGet(VOID) { UINT32 loop; UINT32 semCnt = 0; UINT32 intSave; LosSemCB *semNode = NULL; - + //鍔犱笂閿侊紝鐢ㄤ簬闃叉涓柇 intSave = LOS_IntLock(); + //閬嶅巻鎵鏈変俊鍙烽噺 for (loop = 0; loop < LOSCFG_BASE_IPC_SEM_LIMIT; loop++) { semNode = GET_SEM(loop); + //濡傛灉璇ヤ俊鍙烽噺琚娇鐢ㄤ簡锛屾暟閲忓姞1 if (semNode->semStat == LOS_USED) { semCnt++; } } + //涓鸿繘绋嬭В閿 LOS_IntRestore(intSave); + //杩斿洖绯荤粺淇″彿閲忕殑鏁伴噺 return semCnt; } #endif #ifdef LOSCFG_BASE_IPC_MUX +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇褰撳墠绯荤粺浜掓枼閿佺殑鏁伴噺 UINT32 OsShellCmdMuxCntGet(VOID) { UINT32 loop; UINT32 muxCnt = 0; UINT32 intSave; LosMuxCB *muxNode = NULL; - + //鍔犱笂閿侊紝鐢ㄤ簬闃叉涓柇 intSave = LOS_IntLock(); + //閬嶅巻鎵鏈変簰鏂ラ攣 for (loop = 0; loop < LOSCFG_BASE_IPC_MUX_LIMIT; loop++) { muxNode = GET_MUX(loop); + //濡傛灉浜掓枼閿佺殑鐘舵佽浣跨敤浜嗭紝鏁伴噺鍔1 if (muxNode->muxStat == LOS_USED) { muxCnt++; } } + //涓鸿繘绋嬭В閿 LOS_IntRestore(intSave); + //杩斿洖绯荤粺浜掓枼閿佺殑鏁伴噺 return muxCnt; } #endif #ifdef LOSCFG_BASE_IPC_QUEUE +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇绯荤粺娑堟伅闃熷垪鐨勬暟閲 UINT32 OsShellCmdQueueCntGet(VOID) { UINT32 loop; UINT32 queueCnt = 0; UINT32 intSave; LosQueueCB *queueCB = NULL; - + //鍔犱笂閿侊紝鐢ㄤ簬闃叉涓柇 intSave = LOS_IntLock(); queueCB = g_allQueue; + //閬嶅巻鎵鏈夋秷鎭槦鍒 for (loop = 0; loop < LOSCFG_BASE_IPC_QUEUE_LIMIT; loop++, queueCB++) { + //濡傛灉娑堟伅闃熷垪鐨勭姸鎬佷负浣跨敤锛屾暟閲忓姞1 if (queueCB->queueState == LOS_USED) { queueCnt++; } } + //涓鸿繘绋嬭В閿 LOS_IntRestore(intSave); + //杩斿洖绯荤粺鑾峰彇娑堟伅闃熷垪鐨勬暟閲 return queueCnt; } #endif #ifdef LOSCFG_BASE_CORE_SWTMR +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇绯荤粺杞欢瀹氭椂鍣ㄧ殑鏁伴噺 UINT32 OsShellCmdSwtmrCntGet(VOID) { UINT32 loop; UINT32 swtmrCnt = 0; UINT32 intSave; LosSwtmrCB *swtmrCB = NULL; - + //鍔犱笂閿侊紝鐢ㄤ簬闃叉涓柇 intSave = LOS_IntLock(); swtmrCB = g_swtmrCBArray; + //閬嶅巻鎵鏈夎蒋浠跺畾鏃跺櫒 for (loop = 0; loop < LOSCFG_BASE_CORE_SWTMR_LIMIT; loop++, swtmrCB++) { + //濡傛灉杞欢瀹氭椂鍣ㄧ殑鐘舵佷笉鏄病鏈変娇鐢紝鏁伴噺鍔1 if (swtmrCB->state != OS_SWTMR_STATUS_UNUSED) { swtmrCnt++; } } + //涓鸿繘绋嬭В閿 LOS_IntRestore(intSave); + //杩斿洖绯荤粺杞欢瀹氭椂鍣ㄧ殑鏁伴噺 return swtmrCnt; } #endif - +//杩欎釜鍑芥暟鐢ㄤ簬鎵撳嵃绯荤粺淇℃伅锛屽寘鎷繘绋嬫暟閲忋佷俊鍙烽噺鏁伴噺銆佷簰鏂ラ攣鏁伴噺銆佹秷鎭槦鍒楁暟閲忓拰杞欢瀹氭椂鍣ㄦ暟閲忋 LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdSystemInfoGet(VOID) { + //鎵撳嵃琛ㄥご PRINTK("\n Module Used Total\n"); PRINTK("--------------------------------\n"); + //鎵撳嵃杩涚▼鏁伴噺 PRINTK(" Task %-10u%-10d\n", OsShellCmdTaskCntGet(), LOSCFG_BASE_CORE_TSK_LIMIT); #ifdef LOSCFG_BASE_IPC_SEM + //鎵撳嵃淇″彿閲忔暟閲 PRINTK(" Sem %-10u%-10d\n", OsShellCmdSemCntGet(), LOSCFG_BASE_IPC_SEM_LIMIT); #endif #ifdef LOSCFG_BASE_IPC_MUX + //鎵撳嵃浜掓枼閿佹暟閲 PRINTK(" Mutex %-10u%-10d\n", OsShellCmdMuxCntGet(), LOSCFG_BASE_IPC_MUX_LIMIT); #endif #ifdef LOSCFG_BASE_IPC_QUEUE + //鎵撳嵃娑堟伅闃熷垪鏁伴噺 PRINTK(" Queue %-10u%-10d\n", OsShellCmdQueueCntGet(), LOSCFG_BASE_IPC_QUEUE_LIMIT); #endif #ifdef LOSCFG_BASE_CORE_SWTMR + //鎵撳嵃杞欢瀹氭椂鍣ㄦ暟閲 PRINTK(" SwTmr %-10u%-10d\n", OsShellCmdSwtmrCntGet(), LOSCFG_BASE_CORE_SWTMR_LIMIT); #endif } - +//杩欎釜鍑芥暟鐢ㄤ簬澶勭悊shell鐨剆ysteminfo鍛戒护锛屾牴鎹浉搴旂殑鍙傛暟锛屽仛鍑虹浉搴旂殑澶勭悊 INT32 OsShellCmdSystemInfo(INT32 argc, const CHAR **argv) { + //濡傛灉鍙傛暟鏁伴噺涓0锛岃皟鐢∣sShellCmdSystemInfoGet鍑芥暟锛屾墦鍗版墍鏈夌殑绯荤粺淇℃伅銆 if (argc == 0) { OsShellCmdSystemInfoGet(); return 0; } + //鍙傛暟鏁伴噺涓嶆纭紝鎵撳嵃閿欒淇℃伅 PRINTK("systeminfo: invalid option %s\n" "Systeminfo has NO ARGS.\n", argv[0]); @@ -185,6 +220,7 @@ INT32 OsShellCmdSystemInfo(INT32 argc, const CHAR **argv) } #ifdef LOSCFG_SHELL +//娉ㄥ唽Shell鍛戒护systeminfo锛岃皟鐢∣sShellCmdSystemInfo锛屾牴鎹弬鏁拌緭鍑哄綋鍓嶇郴缁熺殑绋嬫暟閲忋佷俊鍙烽噺鏁伴噺銆佷簰鏂ラ攣鏁伴噺銆佹秷鎭槦鍒楁暟閲忓拰杞欢瀹氭椂鍣ㄦ暟閲忋傘 SHELLCMD_ENTRY(systeminfo_shellcmd, CMD_TYPE_EX, "systeminfo", 1, (CmdCallBackFunc)OsShellCmdSystemInfo); #endif /* LOSCFG_SHELL */ diff --git a/src/kernel/base/shellcmd/task_shellcmd.c b/src/kernel/base/shellcmd/task_shellcmd.c index 43dbde6..35ed967 100644 --- a/src/kernel/base/shellcmd/task_shellcmd.c +++ b/src/kernel/base/shellcmd/task_shellcmd.c @@ -25,7 +25,10 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +/* +杩欐鏂囦欢鏄拡瀵筁iteOS鎿嶄綔绯荤粺涓殑Shell鍛戒护缂栧啓鐨勶紝 +涓昏瀹炵幇浜嗘搷浣滅郴缁熺殑浠诲姟绠$悊妯″潡锛岄氳繃杩涚▼鍙疯幏鍙栬杩涚▼鐨勬墍鏈変俊鎭紝鎴栬呯洿鎺ヨ幏鍙栨墍鏈夎繘绋嬬殑淇℃伅銆 +*/ #include "stdio.h" #include "stdlib.h" #include "los_config.h" @@ -53,55 +56,65 @@ extern "C" { #define OS_INVALID_SEM_ID 0xFFFFFFFF #ifdef LOSCFG_KERNEL_CPUP -LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpupAll[LOSCFG_BASE_CORE_TSK_LIMIT]; -LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup10s[LOSCFG_BASE_CORE_TSK_LIMIT]; -LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup1s[LOSCFG_BASE_CORE_TSK_LIMIT]; +LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpupAll[LOSCFG_BASE_CORE_TSK_LIMIT];//鎵鏈夋椂闂存CPU鍒╃敤鐜囩殑缁熻淇℃伅 +LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup10s[LOSCFG_BASE_CORE_TSK_LIMIT];//鏈杩10sCPU鍒╃敤鐜囩殑缁熻淇℃伅 +LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup1s[LOSCFG_BASE_CORE_TSK_LIMIT];//鏈杩1sCPU鍒╃敤鐜囩殑缁熻淇℃伅 #endif -LITE_OS_SEC_BSS STATIC UINT32 g_taskWaterLine[LOSCFG_BASE_CORE_TSK_LIMIT]; - +LITE_OS_SEC_BSS STATIC UINT32 g_taskWaterLine[LOSCFG_BASE_CORE_TSK_LIMIT];//璁板綍鍚勪釜鍫嗘爤鏈浣庣殑姘翠綅 +//杩欎釜鍑芥暟閫氳繃杩涚▼鐘舵佷綅鏉ュ垽鏂繘绋嬬殑鐘舵侊紝骞惰繑鍥炵浉搴旂殑瀛楃涓茶〃绀鸿繘绋嬬姸鎬併 LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus) { + //杩涚▼澶勪簬杩愯鐘舵侊紝杩斿洖Running if (taskStatus & OS_TASK_STATUS_RUNNING) { - return (UINT8 *)"Running"; + return (UINT8 *)"Running"; + //杩涚▼澶勪簬灏辩华鐘舵侊紝杩斿洖Ready } else if (taskStatus & OS_TASK_STATUS_READY) { return (UINT8 *)"Ready"; + //鍏朵粬鐨勮繘绋嬬姸鎬 } else { + //杩涚▼澶勪簬寤惰繜鐘舵侊紝杩斿洖Delay if (taskStatus & OS_TASK_STATUS_DELAY) { return (UINT8 *)"Delay"; } else if (taskStatus & OS_TASK_STATUS_PEND_TIME) { + //杩涚▼澶勪簬瀹氭椂鎸傝捣鐘舵侊紝杩斿洖SuspendTime if (taskStatus & OS_TASK_STATUS_SUSPEND) { return (UINT8 *)"SuspendTime"; + //杩涚▼澶勪簬瀹氭椂绛夊緟鐘舵侊紝杩斿洖PendTime } else if (taskStatus & OS_TASK_STATUS_PEND) { return (UINT8 *)"PendTime"; } + //杩涚▼澶勪簬绛夊緟鐘舵侊紝杩斿洖Pend } else if (taskStatus & OS_TASK_STATUS_PEND) { return (UINT8 *)"Pend"; + //杩涚▼澶勪簬鎸傝捣鐘舵侊紝杩斿洖SusPend } else if (taskStatus & OS_TASK_STATUS_SUSPEND) { return (UINT8 *)"Suspend"; } } - + //杩涚▼鐘舵佷笉鍚堟硶锛岃繑鍥濱nvalid return (UINT8 *)"Invalid"; } - +//杩欎釜鍑芥暟鐢ㄤ簬鑾峰彇鎵鏈夊爢鏍堢殑鏍堟按浣嶏紙鍫嗘爤鐨勪娇鐢ㄦ儏鍐碉級 STATIC VOID OsShellCmdTaskWaterLineGet(const LosTaskCB *allTaskArray) { const LosTaskCB *taskCB = NULL; UINT32 loop; - + //閬嶅巻鎵鏈夊爢鏍 for (loop = 0; loop < g_taskMaxNum; ++loop) { taskCB = allTaskArray + loop; + //濡傛灉璇ュ爢鏍堟湭浣跨敤锛岀洿鎺ヨ烦杩 if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { continue; } - + //璋冪敤OsStackWaterLineGet锛岃緭鍑哄爢鏍堢殑鏍堟按浣嶄俊鎭 (VOID)OsStackWaterLineGet((const UINTPTR *)((UINTPTR)taskCB->topOfStack + taskCB->stackSize), (const UINTPTR *)taskCB->topOfStack, &g_taskWaterLine[taskCB->taskId]); } } #ifdef LOSCFG_SHELL_EXCINFO_DUMP +//杩欎釜鍑芥暟鐢ㄤ簬鍦ㄥ紓甯镐俊鎭緭鍑虹紦鍐插尯涓墦鍗颁换鍔′俊鎭殑鏍囬銆 LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitleExc(VOID) { WriteExcInfoToBuf("\r\nName TaskEntryAddr TID "); @@ -133,7 +146,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitleExc(VOID) WriteExcInfoToBuf("\n"); } #endif - +//杩欎釜鍑芥暟鐢ㄤ簬鍦ㄦ帶鍒跺彴鎵撳嵃浠诲姟淇℃伅鐨勬爣棰樸 LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID) { PRINTK("\r\nName TaskEntryAddr TID "); @@ -165,14 +178,15 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID) PRINTK("\n"); #ifdef LOSCFG_SHELL_EXCINFO_DUMP + //鍦ㄥ紓甯镐俊鎭緭鍑虹紦鍐插尯涓墦鍗颁换鍔′俊鎭殑鏍囬銆 OsShellCmdTskInfoTitleExc(); #endif } - +//杩欎釜鍑芥暟閫氳繃TCB锛堣繘绋嬫帶鍒跺潡锛夎幏鍙栬繘绋嬫墍鎸佹湁鐨勪俊鍙烽噺鐨処D銆 LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsGetSemID(const LosTaskCB *taskCB) { UINT32 semId = OS_INVALID_SEM_ID; - + //杩斿洖璇ヨ繘绋嬬殑淇″彿閲廔D if (taskCB->taskSem != NULL) { semId = ((LosSemCB *)taskCB->taskSem)->semId; } @@ -181,12 +195,13 @@ LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsGetSemID(const LosTaskCB *taskCB) } #ifdef LOSCFG_SHELL_EXCINFO_DUMP +//杩欎釜鍑芥暟鐢ㄤ簬灏員CB锛堣繘绋嬫帶鍒跺潡锛変腑鐨勮繘绋嬩俊鎭緭鍑哄埌寮傚父淇℃伅杈撳嚭缂撳啿鍖恒 LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *allTaskArray) { const LosTaskCB *taskCB = NULL; UINT32 loop; UINT32 semId; - + //閬嶅巻鎵鏈夌殑鍫嗘爤 for (loop = 0; loop < g_taskMaxNum; ++loop) { taskCB = allTaskArray + loop; if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { @@ -194,21 +209,25 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *all } semId = OsGetSemID(taskCB); - + //璋冪敤WriteExcInfoToBuf鍑芥暟锛屽皢TCB锛堣繘绋嬫帶鍒跺潡锛夌殑淇℃伅鍐欏叆缂撳啿鍖 WriteExcInfoToBuf("%-23s0x%-18.8x0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskId); #ifdef LOSCFG_KERNEL_SMP + //璋冪敤WriteExcInfoToBuf鍑芥暟锛屽皢TCB锛堣繘绋嬫帶鍒跺潡锛夌殑淇℃伅鍐欏叆缂撳啿鍖 WriteExcInfoToBuf("0x%04x %4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu)); #endif + //璋冪敤WriteExcInfoToBuf鍑芥暟锛屽皢TCB锛堣繘绋嬫帶鍒跺潡锛夌殑淇℃伅鍐欏叆缂撳啿鍖 WriteExcInfoToBuf("%-11u%-13s0x%-11x0x%-11x 0x%-.8x 0x%-.8x 0x%-11x", taskCB->priority, OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize, g_taskWaterLine[taskCB->taskId], taskCB->stackPointer, taskCB->topOfStack, semId); #ifdef LOSCFG_BASE_IPC_EVENT + //璋冪敤WriteExcInfoToBuf鍑芥暟锛屽皢TCB锛堣繘绋嬫帶鍒跺潡锛夌殑淇℃伅鍐欏叆缂撳啿鍖 WriteExcInfoToBuf("0x%-6x", taskCB->eventMask); #endif #ifdef LOSCFG_KERNEL_CPUP + //璋冪敤WriteExcInfoToBuf鍑芥暟锛屽皢TCB锛堣繘绋嬫帶鍒跺潡锛夌殑淇℃伅鍐欏叆缂撳啿鍖 WriteExcInfoToBuf(" %4u.%1u%9u.%1u%8u.%1u ", g_taskCpupAll[taskCB->taskId].uwUsage / LOS_CPUP_PRECISION_MULT, g_taskCpupAll[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT, @@ -218,41 +237,47 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *all g_taskCpup1s[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT); #endif /* LOSCFG_KERNEL_CPUP */ #ifdef LOSCFG_MEM_TASK_STAT + //璋冪敤WriteExcInfoToBuf鍑芥暟锛屽皢TCB锛堣繘绋嬫帶鍒跺潡锛夌殑淇℃伅鍐欏叆缂撳啿鍖 WriteExcInfoToBuf(" %-11u", OsMemTaskUsage(taskCB->taskId)); #endif + //璋冪敤WriteExcInfoToBuf鍑芥暟锛屽皢TCB锛堣繘绋嬫帶鍒跺潡锛夌殑淇℃伅鍐欏叆缂撳啿鍖 WriteExcInfoToBuf("\n"); } } #endif - +//杩欎釜鍑芥暟鍙互灏員CB(杩涚▼鎺у埗鍧)涓殑淇℃伅杈撳嚭鍒版帶鍒跺彴銆 LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTaskArray) { const LosTaskCB *taskCB = NULL; UINT32 loop; UINT32 semId; - + //閬嶅巻鎵鏈夌殑鍫嗘爤 for (loop = 0; loop < g_taskMaxNum; ++loop) { taskCB = allTaskArray + loop; if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { continue; } - + //璋冪敤OsGetSemID鑾峰彇璇ヨ繘绋嬬殑淇″彿閲廔D semId = OsGetSemID(taskCB); - + //杈撳嚭杩涚▼淇℃伅鍒版帶鍒跺彴 PRINTK("%-23s0x%-18.8x0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskId); #ifdef LOSCFG_KERNEL_SMP + //杈撳嚭杩涚▼淇℃伅鍒版帶鍒跺彴 PRINTK("0x%04x %4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu)); #endif + //杈撳嚭杩涚▼淇℃伅鍒版帶鍒跺彴 PRINTK("%-11u%-13s0x%-11x0x%-11x 0x%-.8x 0x%-.8x 0x%-11x", taskCB->priority, OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize, g_taskWaterLine[taskCB->taskId], taskCB->stackPointer, taskCB->topOfStack, semId); #ifdef LOSCFG_BASE_IPC_EVENT + //杈撳嚭杩涚▼淇℃伅鍒版帶鍒跺彴 PRINTK("0x%-6x", taskCB->eventMask); #endif #ifdef LOSCFG_KERNEL_CPUP + //杈撳嚭杩涚▼淇℃伅鍒版帶鍒跺彴 PRINTK(" %4u.%1u%9u.%1u%8u.%1u ", g_taskCpupAll[taskCB->taskId].uwUsage / LOS_CPUP_PRECISION_MULT, g_taskCpupAll[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT, @@ -262,16 +287,19 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas g_taskCpup1s[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT); #endif /* LOSCFG_KERNEL_CPUP */ #ifdef LOSCFG_MEM_TASK_STAT + //杈撳嚭杩涚▼淇℃伅鍒版帶鍒跺彴 PRINTK(" %-11u", OsMemTaskUsage(taskCB->taskId)); #endif + //杈撳嚭杩涚▼淇℃伅鍒版帶鍒跺彴 PRINTK("\n"); } #ifdef LOSCFG_SHELL_EXCINFO_DUMP + //灏嗚繘绋嬩俊鎭緭鍑哄埌寮傚父淇℃伅杈撳嚭缂撳啿鍖恒 OsShellCmdTskInfoDataExc(allTaskArray); #endif } - +//杩欎釜鍑芥暟鍙互閫氳繃杩涚▼鍙疯幏鍙栬繘绋嬬殑淇℃伅 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId) { BOOL backupFlag = TRUE; @@ -279,50 +307,57 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId) UINT32 size, intSave; LosTaskCB *tcbArray = NULL; INT32 ret; - + //濡傛灉鏄洰鏍囪繘绋 if (taskId == OS_ALL_TASK_MASK) { size = g_taskMaxNum * sizeof(LosTaskCB); tcbArray = (LosTaskCB *)LOS_MemAlloc(m_aucSysMem1, size); + //濡傛灉鐩爣杩涚▼淇℃伅涓虹┖锛岃緭鍑洪敊璇俊鎭紝灏哹ackup璁剧疆涓篎asle锛屼笉澶囦唤璇ヨ繘绋嬩俊鎭 if (tcbArray == NULL) { PRINTK("Memory is not enough to save task info!\n"); tcbArray = g_taskCBArray; backupFlag = FALSE; } #ifdef LOSCFG_KERNEL_CPUP - (VOID)memset_s((VOID *)g_taskCpupAll, sizeof(g_taskCpupAll), 0, sizeof(g_taskCpupAll)); - (VOID)memset_s((VOID *)g_taskCpup10s, sizeof(g_taskCpup10s), 0, sizeof(g_taskCpup10s)); - (VOID)memset_s((VOID *)g_taskCpup1s, sizeof(g_taskCpup1s), 0, sizeof(g_taskCpup1s)); + (VOID)memset_s((VOID *)g_taskCpupAll, sizeof(g_taskCpupAll), 0, sizeof(g_taskCpupAll));//缃浂 + (VOID)memset_s((VOID *)g_taskCpup10s, sizeof(g_taskCpup10s), 0, sizeof(g_taskCpup10s));//缃浂 + (VOID)memset_s((VOID *)g_taskCpup1s, sizeof(g_taskCpup1s), 0, sizeof(g_taskCpup1s));//缃浂 #endif - (VOID)memset_s((VOID *)g_taskWaterLine, sizeof(g_taskWaterLine), 0, sizeof(g_taskWaterLine)); - + (VOID)memset_s((VOID *)g_taskWaterLine, sizeof(g_taskWaterLine), 0, sizeof(g_taskWaterLine));//缃浂 + //濡傛灉娌℃湁璋冨害鍣ㄨ嚜鏃嬮攣锛屼负璇ヨ繘绋嬫坊鍔犺皟搴﹀櫒鑷棆閿 if (LOS_SpinHeld(&g_taskSpin) == FALSE) { SCHEDULER_LOCK(intSave); lockFlag = TRUE; } + //濡傛灉闇瑕佸皢杩涚▼淇℃伅澶囦唤 if (backupFlag == TRUE) { + //灏嗚繘绋嬩俊鎭浠藉埌tcbArray ret = memcpy_s(tcbArray, size, g_taskCBArray, size); + //濡傛灉娌℃湁澶囦唤鎴愭灉杩斿洖閿欒 if (ret != EOK) { return LOS_NOK; } } #ifdef LOSCFG_KERNEL_CPUP - (VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpupAll, CPUP_ALL_TIME, 1); - (VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup10s, CPUP_LAST_TEN_SECONDS, 1); - (VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup1s, CPUP_LAST_ONE_SECONDS, 1); + (VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpupAll, CPUP_ALL_TIME, 1);//鏄剧ずCPU鎵鏈夋椂娈电殑浣跨敤鐜囦俊鎭 + (VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup10s, CPUP_LAST_TEN_SECONDS, 1);//鏄剧ずCPU鏈杩10s鐨勪娇鐢ㄧ巼淇℃伅 + (VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup1s, CPUP_LAST_ONE_SECONDS, 1);//鏄剧ずCPU鏈杩1s鐨勪娇鐢ㄧ巼淇℃伅 #endif + //鑾峰彇杩涚▼鐨勬爤姘翠綅淇℃伅 OsShellCmdTaskWaterLineGet(tcbArray); - + //濡傛灉杩涚▼鏈夎皟搴﹀櫒鑷棆閿侊紝灏嗚杩涚▼瑙i攣 if (lockFlag == TRUE) { SCHEDULER_UNLOCK(intSave); } - + //鎵撳嵃杩涚▼淇℃伅鏍囬 OsShellCmdTskInfoTitle(); + //鎵撳嵃杩涚▼淇℃伅鐨勬暟鎹 OsShellCmdTskInfoData(tcbArray); - + //濡傛灉杩涚▼淇℃伅鏁版嵁澶囦唤鎴愭灉锛岄噴鏀総cbArrayd鐨勫唴瀛樼┖闂 if (backupFlag == TRUE) { (VOID)LOS_MemFree(m_aucSysMem1, tcbArray); } } else { + //璋冪敤 OsTaskBackTrace鍑芥暟鏉ヨ幏鍙栬浠诲姟鐨勫洖婧俊鎭 OsTaskBackTrace(taskId); } @@ -330,29 +365,34 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId) } #ifdef LOSCFG_SHELL +//杩欎釜鍑芥暟鐢ㄤ簬澶勭悊task鍛戒护锛岄氳繃鍚勭鍙傛暟杈撳嚭缁撴灉 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv) { size_t taskId; CHAR *endPtr = NULL; - + //褰撳弬鏁版暟閲忓悎娉曟椂 if (argc < 2) { /* 2:Just as number of parameters */ + //濡傛灉娌℃湁鍙傛暟锛岃繘绋嬪彿鏄墍鏈夎繘绋 if (argc == 0) { taskId = OS_ALL_TASK_MASK; + //瀛樺湪涓涓弬鏁颁负杩涚▼鍙 } else { taskId = strtoul(argv[0], &endPtr, 0); + //濡傛灉杩涚▼鍙蜂笉鍚堟硶锛屾墦鍗伴敊璇俊鎭 if ((*endPtr != 0) || (taskId >= g_taskMaxNum)) { PRINTK("\ntask ID can't access %s.\n", argv[0]); return OS_ERROR; } } - + //璋冪敤OsShellCmdTskInfoGet鍑芥暟锛岃緭鍑鸿杩涚▼鐨勮繘绋嬩俊鎭 return OsShellCmdTskInfoGet((UINT32)taskId); } else { + //鍙傛暟涓嶅悎娉曪紝鎵撳嵃閿欒淇℃伅 PRINTK("\nUsage: task or task ID\n"); return OS_ERROR; } } - +//娉ㄥ唽Shell鍛戒护task锛岃皟鐢∣sShellCmdDumpTask锛屾牴鎹弬鏁帮紙杩涚▼鍙锋垨鑰呮病鏈夊弬鏁帮級鑾峰彇杩涚▼淇℃伅骞惰緭鍑恒 SHELLCMD_ENTRY(task_shellcmd, CMD_TYPE_EX, "task", 1, (CmdCallBackFunc)OsShellCmdDumpTask); #endif diff --git a/src/kernel/extended/.vscode/c_cpp_properties.json b/src/kernel/extended/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b1880ec --- /dev/null +++ b/src/kernel/extended/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "D:/mingw64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/src/kernel/extended/.vscode/launch.json b/src/kernel/extended/.vscode/launch.json new file mode 100644 index 0000000..f78275c --- /dev/null +++ b/src/kernel/extended/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "h:/ruanjian/LiteOS-Reading/src/kernel/extended/perf/pmu", + "program": "h:/ruanjian/LiteOS-Reading/src/kernel/extended/perf/pmu/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/src/kernel/extended/.vscode/settings.json b/src/kernel/extended/.vscode/settings.json new file mode 100644 index 0000000..3e5eb95 --- /dev/null +++ b/src/kernel/extended/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/src/kernel/extended/lowpower/los_lowpower.c b/src/kernel/extended/lowpower/los_lowpower.c index bd9dde0..2a19c3e 100644 --- a/src/kernel/extended/lowpower/los_lowpower.c +++ b/src/kernel/extended/lowpower/los_lowpower.c @@ -25,7 +25,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - + /*浣庡姛鑰楃鐞*/ #include "los_lowpower_pri.h" #ifdef LOSCFG_KERNEL_TICKLESS #include "los_tickless_pri.h" @@ -36,10 +36,10 @@ __attribute__((section(".data"))) STATIC const PowerMgrOps *g_pmOps = NULL; -VOID OsLowpowerInit(const PowerMgrOps *pmOps) +VOID OsLowpowerInit(const PowerMgrOps *pmOps) /*鍒濆鍖栦綆鍔熻楃鐞*/ { if (pmOps == NULL) { -#ifdef LOSCFG_KERNEL_POWER_MGR +#ifdef LOSCFG_KERNEL_POWER_MGR/*鏄惁閰嶇疆浜嗕綆鍔熻楀唴鏍哥鐞*/ PRINT_ERR("\r\n [PM] PowerMgrOps must be non-null.\n"); return; #endif @@ -48,34 +48,34 @@ VOID OsLowpowerInit(const PowerMgrOps *pmOps) return; } - if (g_pmOps != NULL) { + if (g_pmOps != NULL) { PRINT_ERR("\r\n [PM] Reassignment of PowerMgrOps is forbidden.\n"); return; } g_pmOps = pmOps; LOS_LowpowerHookReg(OsPowerMgrProcess); - + /*娉ㄥ唽浣庡姛鑰楀鐞嗗嚱鏁板拰缁堢鍞ら啋澶勭悊鍑芥暟*/ LOS_IntWakeupHookReg(OsPowerMgrWakeUpFromInterrupt); } -VOID OsPowerMgrProcess(VOID) +VOID OsPowerMgrProcess(VOID) /*鎵ц浣庡姛鑰楃鐞嗙殑澶勭悊杩囩▼*/ { -#ifdef LOSCFG_KERNEL_POWER_MGR +#ifdef LOSCFG_KERNEL_POWER_MGR/*鍒ゆ柇鏄惁閰嶇疆浜嗗唴鏍镐綆鍔熻楃鐞*/ CALL_PMOPS_FUNC_VOID(process); #else - if (g_pmOps == NULL) { + if (g_pmOps == NULL) { #ifdef LOSCFG_KERNEL_TICKLESS OsTicklessOpen(); - wfi(); + wfi(); /*绠$悊杩涚▼杩涘叆鐫$湢鐘舵*/ #endif } else { - CALL_PMOPS_FUNC_VOID(process); + CALL_PMOPS_FUNC_VOID(process);/*鎵ц浣庡姛鑰楃鐞*/ } #endif } -VOID OsPowerMgrWakeUpFromInterrupt(UINT32 intNum) +VOID OsPowerMgrWakeUpFromInterrupt(UINT32 intNum) /*浠庝腑鏂敜閱掑鐞*/ { #ifdef LOSCFG_KERNEL_POWER_MGR CALL_PMOPS_FUNC_VOID(resumeFromInterrupt, intNum); @@ -90,44 +90,44 @@ VOID OsPowerMgrWakeUpFromInterrupt(UINT32 intNum) #endif } -VOID OsPowerMgrWakeupFromReset(VOID) +VOID OsPowerMgrWakeupFromReset(VOID) /*浠庡浣嶅敜閱掑鐞*/ { CALL_PMOPS_FUNC_VOID(wakeupFromReset); } -VOID LOS_PowerMgrChangeFreq(LosFreqMode freq) +VOID LOS_PowerMgrChangeFreq(LosFreqMode freq)/*鏀瑰彉绯荤粺棰戠巼*/ { CALL_PMOPS_FUNC_VOID(changeFreq, freq); } -VOID LOS_PowerMgrDeepSleepVoteBegin(VOID) +VOID LOS_PowerMgrDeepSleepVoteBegin(VOID)/*寮濮嬫繁搴︾潯鐪犺缃*/ { CALL_PMOPS_FUNC_VOID(deepSleepVoteBegin); } -VOID LOS_PowerMgrDeepSleepVoteEnd(VOID) +VOID LOS_PowerMgrDeepSleepVoteEnd(VOID)/*缁撴潫娣卞害鐫$湢鐘舵*/ { CALL_PMOPS_FUNC_VOID(deepSleepVoteEnd); } -VOID LOS_PowerMgrSleepDelay(UINT32 tick) +VOID LOS_PowerMgrSleepDelay(UINT32 tick)/*寤惰繜杩涘叆鐫$湢鐘舵*/ { CALL_PMOPS_FUNC_VOID(deepSleepVoteDelay, tick); } -VOID LOS_PowerMgrRegisterExtVoter(UINT32 (*callback)(VOID)) +VOID LOS_PowerMgrRegisterExtVoter(UINT32 (*callback)(VOID))/*娉ㄥ唽澶栭儴鎶曠エ鑰*/ { CALL_PMOPS_FUNC_VOID(registerExternalVoter, callback); } -UINT32 LOS_PowerMgrGetSleepMode(VOID) +UINT32 LOS_PowerMgrGetSleepMode(VOID)/*鑾峰彇鐫$湢妯″紡*/ { UINT32 ret = 0; CALL_PMOPS_FUNC_RET(getSleepMode, ret); return ret; } -UINT32 LOS_PowerMgrGetDeepSleepVoteCount(VOID) +UINT32 LOS_PowerMgrGetDeepSleepVoteCount(VOID)/*鑾峰彇娣卞害鐫$湢鐨勬姇绁ㄨ鏁*/ { UINT32 ret = 0; CALL_PMOPS_FUNC_RET(getDeepSleepVoteCount, ret); diff --git a/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c b/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c index 0f8cc28..78f5f94 100644 --- a/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c +++ b/src/kernel/extended/lowpower/powermgr/los_lowpower_impl.c @@ -44,7 +44,7 @@ #endif #if defined(LOSCFG_KERNEL_RUNSTOP) || defined(LOSCFG_KERNEL_DEEPSLEEP) -/* Is system is up from the memory image, then this flag should be 1; else 0 */ +/* 濡傛灉绯荤粺鏄粠鍐呭瓨鏄犲儚涓惎鍔ㄧ殑锛屽垯璇ユ爣蹇楀簲涓1锛涘惁鍒欎负0銆*/ #ifdef LOSCFG_AARCH64 __attribute__((section(".data"))) INT64 g_resumeFromImg = LOS_COLD_RESET; __attribute__((section(".data"))) STATIC INT64 g_otherCoreResume = 0; @@ -55,8 +55,8 @@ __attribute__((section(".data"))) INT32 g_otherCoreResume = 0; #ifdef LOSCFG_AARCH64 /* - * 16: The number of aligned memory, - * 34: The number of task context registers(X0~X30, SP, DAIF, NZCV) + * 16: 瀵归綈鍐呭瓨鐨勬暟閲, + * 34: 浠诲姟涓婁笅鏂囧瘎瀛樺櫒鐨勬暟閲忥紝鎸囧瘎瀛樺櫒鐨勯泦鍚(X0~X30, SP, DAIF, NZCV) */ LITE_OS_SEC_DATA_MINOR __attribute__((aligned(16))) UINT64 g_saveSRContext[34]; /* 3: The number of available universal registers(X0, X1, X2) temporarily saved */ @@ -161,24 +161,24 @@ STATIC PowerMgrRunOps g_pmRunOps = { .postConfig = OsPostConfigDefault, }; -STATIC VOID OsLightSleepDefault(VOID) +STATIC VOID OsLightSleepDefault(VOID)/*杞婚噺绾х潯鐪犲嚱鏁帮紝鎵цwfi鎸囦护锛岃澶勭悊鍣ㄨ繘鍏ョ潯鐪犵姸鎬*/ { TRACE_FUNC_CALL(); wfi(); } -STATIC VOID OsSetWakeUpTimerDefault(UINT32 sleepTick) +STATIC VOID OsSetWakeUpTimerDefault(UINT32 sleepTick)/*璁剧疆鍞ら啋瀹氭椂鍣紝榛樿瀹炵幇涓虹┖鍑芥暟*/ { TRACE_FUNC_CALL(); } -STATIC UINT32 OsWithrawWakeUpTimerDefault(VOID) +STATIC UINT32 OsWithrawWakeUpTimerDefault(VOID)/*鎾ら攢鍞ら啋瀹氭椂鍣紝榛樿瀹炵幇杩斿洖0*/ { TRACE_FUNC_CALL(); return 0; } -STATIC UINT32 OsGetSleepTimeDefault(VOID) +STATIC UINT32 OsGetSleepTimeDefault(VOID)/*鑾峰彇褰撳墠浠诲姟浼戠湢鏃堕棿*/ { #ifdef LOSCFG_KERNEL_TICKLESS return OsSleepTicksGet(); @@ -187,12 +187,12 @@ STATIC UINT32 OsGetSleepTimeDefault(VOID) #endif } -STATIC UINT32 OsSelectSleepModeDefault(UINT32 sleepTicks) +STATIC UINT32 OsSelectSleepModeDefault(UINT32 sleepTicks)/*閫夋嫨鍚堥傜殑浼戠湢妯″紡*/ { if (sleepTicks < g_pmMgr.minSleepTicks) { return LOS_INTERMIT_NONE; } - + /*榛樿瀹炵幇鏍规嵁浼戠湢鏃堕棿鍜屽綋鍓嶇郴缁熺姸鎬侀夋嫨杞婚噺绾х潯鐪犳垨鑰呮繁搴︾潯鐪犳ā寮*/ if (g_pmMgr.deepSleepOps != NULL && sleepTicks >= g_pmMgr.minDeepSleepTicks && g_pmRunOps.getDeepSleepVoteCount() == 0) { return LOS_INTERMIT_DEEP_SLEEP; @@ -201,73 +201,73 @@ STATIC UINT32 OsSelectSleepModeDefault(UINT32 sleepTicks) return LOS_INTERMIT_LIGHT_SLEEP; } -STATIC VOID OsChangeFreqDefault(UINT8 freq) +STATIC VOID OsChangeFreqDefault(UINT8 freq)/*鏀瑰彉澶勭悊鍣ㄩ鐜*/ { (VOID)freq; TRACE_FUNC_CALL(); } -STATIC VOID OsEnterDeepSleepDefault(VOID) +STATIC VOID OsEnterDeepSleepDefault(VOID)// 杩涘叆娣卞害鐫$湢妯″紡鍑芥暟 { TRACE_FUNC_CALL(); wfi(); } -STATIC UINT32 OsPreConfigDefault(VOID) +STATIC UINT32 OsPreConfigDefault(VOID)//鐢垫簮绠$悊妯″潡棰勯厤缃嚱鏁 { TRACE_FUNC_CALL(); return 1; } -STATIC VOID OsPostConfigDefault(VOID) +STATIC VOID OsPostConfigDefault(VOID)//鐢垫簮绠$悊妯″潡鍚庨厤缃嚱鏁 { } #ifdef LOSCFG_KERNEL_DEEPSLEEP -STATIC BOOL OsCouldDeepSleepDefault(VOID) +STATIC BOOL OsCouldDeepSleepDefault(VOID)// 鍒ゆ柇鏄惁鍙互杩涘叆娣卞害鐫$湢妯″紡 { TRACE_FUNC_CALL(); return true; } -STATIC BOOL OsSuspendPreConfigDefault(VOID) +STATIC BOOL OsSuspendPreConfigDefault(VOID)// 浼戠湢鍓嶇殑棰勯厤缃嚱鏁 { TRACE_FUNC_CALL(); return true; } -STATIC VOID OsSuspendDeviceDefault(VOID) +STATIC VOID OsSuspendDeviceDefault(VOID)//浼戠湢鏃惰澶囨寕璧峰嚱鏁 { TRACE_FUNC_CALL(); } -STATIC VOID OsRollBackDefault(VOID) +STATIC VOID OsRollBackDefault(VOID)//鍞ら啋鍚庣殑鍥炴粴鍑芥暟 { TRACE_FUNC_CALL(); } -STATIC VOID OsResumeDeviceDefault(VOID) +STATIC VOID OsResumeDeviceDefault(VOID)//鍞ら啋鍚庣殑璁惧鎭㈠鍑芥暟 { TRACE_FUNC_CALL(); } -STATIC VOID OsResumePostConfigDefault(VOID) +STATIC VOID OsResumePostConfigDefault(VOID)//鍞ら啋鍚庣數婧愮鐞嗘ā鍧楀悗閰嶇疆鍑芥暟 { TRACE_FUNC_CALL(); } -STATIC VOID OsSystemWakeupDefault(VOID) +STATIC VOID OsSystemWakeupDefault(VOID)//绯荤粺鍞ら啋鍑芥暟 { TRACE_FUNC_CALL(); } -STATIC VOID OsResumeCallBackDefault(VOID) +STATIC VOID OsResumeCallBackDefault(VOID)//鍞ら啋鍚庡洖璋冨嚱鏁 { TRACE_FUNC_CALL(); } -STATIC VOID OsOtherCoreResumeDefault(VOID) +STATIC VOID OsOtherCoreResumeDefault(VOID)//鍏朵粬鏍稿績鍞ら啋鍑芥暟 { TRACE_FUNC_CALL(); } @@ -275,18 +275,18 @@ STATIC VOID OsOtherCoreResumeDefault(VOID) STATIC VOID OsDeepSleepResume(VOID); STATIC PowerMgrDeepSleepOps g_deepSleepOps = { - .couldDeepSleep = OsCouldDeepSleepDefault, - .systemWakeup = OsSystemWakeupDefault, - .suspendPreConfig = OsSuspendPreConfigDefault, - .suspendDevice = OsSuspendDeviceDefault, - .rollback = OsRollBackDefault, - .resumeDevice = OsResumeDeviceDefault, - .resumePostConfig = OsResumePostConfigDefault, - .resumeCallBack = OsResumeCallBackDefault, - .otherCoreResume = OsOtherCoreResumeDefault + .couldDeepSleep = OsCouldDeepSleepDefault, //鍒ゆ柇鏄惁鍙互杩涘叆娣卞害鐫$湢妯″紡鐨勫嚱鏁版寚閽 + .systemWakeup = OsSystemWakeupDefault,//鍞ら啋鍑芥暟鐨勫嚱鏁版寚閽 + .suspendPreConfig = OsSuspendPreConfigDefault,//淇潰鍓嶇殑棰勯厤缃嚱鏁扮殑鍑芥暟鎸囬拡 + .suspendDevice = OsSuspendDeviceDefault,//璁惧鎸傝捣鍑芥暟鐨勫嚱鏁版寚閽 + .rollback = OsRollBackDefault,//鍞ら啋鍚庣殑鍥炴粴鍑芥暟鐨勫嚱鏁版寚閽 + .resumeDevice = OsResumeDeviceDefault,//璁惧鍥炲鍑芥暟鐨勫嚱鏁版寚閽 + .resumePostConfig = OsResumePostConfigDefault,//鍞ら啋鍚庣數婧愮鐞嗘ā鍧楀悗閰嶇疆鍑芥暟鐨勫嚱鏁版寚閽 + .resumeCallBack = OsResumeCallBackDefault,//鍞ら啋鍚庡洖璋冨嚱鏁扮殑鍑芥暟鎸囬拡 + .otherCoreResume = OsOtherCoreResumeDefault//鍏朵粬鏍稿績鍞ら啋鍑芥暟鐨勫嚱鏁版寚閽 }; -STATIC INLINE VOID OsTickResume(UINT32 sleepTicks) +STATIC INLINE VOID OsTickResume(UINT32 sleepTicks)//鐢ㄤ簬鏇存柊绯荤粺濮嬬粓锛屾牴鎹紤鐪犳椂闂磋皟鏁寸郴缁熸椂閽 { UINT32 cpuid = ArchCurrCpuid(); if (sleepTicks > g_pmMgr.sleepTime[cpuid]) { @@ -297,7 +297,7 @@ STATIC INLINE VOID OsTickResume(UINT32 sleepTicks) OsSysTimeUpdate(sleepTicks); } -STATIC VOID OsDeepSleepResume(VOID) +STATIC VOID OsDeepSleepResume(VOID)//娣卞害鐫$湢鍞ら啋鍚庣殑澶勭悊鍑芥暟 { DEEPOPS_CALL_FUNC_VOID(resumeFromReset); LOS_AtomicSet(&g_pmMgr.resumeSleepCores, OS_MP_CPU_ALL); @@ -305,30 +305,32 @@ STATIC VOID OsDeepSleepResume(VOID) #ifdef LOSCFG_KERNEL_CPUP OsSetCpuCycle(0); #endif - +//鎭㈠璁剧疆锛屾仮澶嶅叾浠栨牳蹇冭繘绋 #if (LOSCFG_KERNEL_SMP == YES) release_secondary_cores(); #endif OsSRRestoreRegister(); } -STATIC INLINE VOID OsEnterDeepSleepMainCore(VOID) +STATIC INLINE VOID OsEnterDeepSleepMainCore(VOID)//鐢ㄤ簬涓绘牳蹇冭繘鍏ユ繁搴︾潯鐪 { + //鎸傝捣棰勯厤缃 LOS_AtomicAdd(&g_pmMgr.deepSleepCores, 1); g_deepSleepOps.suspendPreConfig(); - + //鏄惁鍙互杩涘叆绁炲鐫$湢鍒ゆ柇 if (g_pmMgr.deepSleepCores == LOSCFG_KERNEL_CORE_NUM && g_deepSleepOps.couldDeepSleep()) { g_deepSleepOps.suspendDevice(); g_pmRunOps.setWakeUpTimer(g_pmMgr.sleepTime[0]); g_resumeFromImg = LOS_COLD_RESET; OsSRSaveRegister(); - + //杩涘叆娣卞害鐫$湢锛岃繘琛屽洖婊氭搷浣滐紝淇濆瓨涓婁笅鏂 if (g_resumeFromImg == LOS_COLD_RESET) { g_resumeFromImg = LOS_DEEP_SLEEP_RESET; CALL_RUN_OPS_FUNC_NO_RETURN(contextSave); g_pmRunOps.enterDeepSleep(); g_deepSleepOps.rollback(); } + //璁剧疆鍞ら啋瀹氭椂鍣 g_deepSleepOps.resumeDevice(); UINT32 sleepTicks = g_pmRunOps.withdrawWakeUpTimer(); OsSysTimeUpdate(sleepTicks); @@ -342,42 +344,43 @@ STATIC INLINE VOID OsEnterDeepSleepMainCore(VOID) LOS_AtomicSub(&g_pmMgr.deepSleepCores, 1); } -STATIC INLINE VOID OsEnterSleepMode(VOID) +STATIC INLINE VOID OsEnterSleepMode(VOID)//杩涘叆鐫$湢妯″紡锛屽寘鎷富鏍稿績鍜屽叾浠栨牳蹇冪殑涓嶅悓澶勭悊 { #ifdef LOSCFG_KERNEL_SMP UINT32 currCpuid = ArchCurrCpuid(); - if (currCpuid == 0) { + if (currCpuid == 0) { //濡傛灉鏄0鍒欒繘鍏ヤ富鏍稿績娣卞害鐫$湢 #endif OsEnterDeepSleepMainCore(); -#ifdef LOSCFG_KERNEL_SMP +#ifdef LOSCFG_KERNEL_SMP //濡傛灉褰撳墠鏍稿績涓嶆槸涓绘牳蹇冿紝鍒欑洿鎺ヨ繑鍥烇紝鍥犱负鍏朵粬鏍稿績鐨勭潯鐪犲鐞嗛昏緫涓嶅湪姝ゅ嚱鏁颁腑澶勭悊 return; } UINT32 cpuMask = 1 << currCpuid; LOS_AtomicAdd(&g_pmMgr.deepSleepCores, 1); - OsSRSaveRegister(); + OsSRSaveRegister();//淇濆瓨鐩稿叧瀵勫瓨鍣ㄧ姸鎬佸苟鍒ゆ柇鏄惁闇瑕佸敜閱掑綋鍓嶆牳蹇冦 if (g_pmMgr.resumeSleepCores & cpuMask) { INT32 val; - do { + do { //锛屽皢 g_pmMgr.resumeSleepCores 鐨勫间腑褰撳墠鏍稿績鐨勪綅娓呴浂锛岃〃绀鸿鏍稿績宸茶鍞ら啋銆 val = LOS_AtomicRead(&g_pmMgr.resumeSleepCores); } while (LOS_AtomicCmpXchg32bits(&g_pmMgr.resumeSleepCores, val & (~cpuMask), val)); g_deepSleepOps.otherCoreResume(); UINT32 sleepTicks = g_pmRunOps.withdrawWakeUpTimer(); OsTickResume(sleepTicks); + //鎵ц鍏朵粬鏍稿績鐨勬仮澶嶆搷浣滐紝骞朵粠鍞ら啋瀹氭椂鍣ㄤ腑鑾峰彇浼戠湢鏃堕棿锛岀劧鍚庤皟鐢 OsTickResume 鍑芥暟鏇存柊绯荤粺鏃堕挓銆 } else { - if (g_pmMgr.deepSleepCores == LOSCFG_KERNEL_CORE_NUM) { - LOS_MpSchedule(1 << 0); + if (g_pmMgr.deepSleepCores == LOSCFG_KERNEL_CORE_NUM) {//濡傛灉涓嶉渶瑕佸敜閱掞紝鍒欏垽鏂槸鍚︽墍鏈夋牳蹇冮兘杩涘叆浜嗘繁搴︾潯鐪 + LOS_MpSchedule(1 << 0);//璋冪敤鍑芥暟閫夋嫨涓涓牳蹇冨敜閱掔郴缁 } #ifdef LOSCFG_KERNEL_TICKLESS - OsTicklessOpen(); + OsTicklessOpen();//寮鍚妭鑳芥ā寮 #endif g_pmRunOps.enterLightSleep(); } - LOS_AtomicSub(&g_pmMgr.deepSleepCores, 1); + LOS_AtomicSub(&g_pmMgr.deepSleepCores, 1);//灏 g_pmMgr.deepSleepCores 鐨勫煎噺1锛岃〃绀哄綋鍓嶆牳蹇冨凡缁忓鐞嗗畬鐫$湢鐘舵 #endif // LOSCFG_KERNEL_SMP } -STATIC INLINE VOID OsSystemSuspend(LosIntermitMode *mode) +STATIC INLINE VOID OsSystemSuspend(LosIntermitMode *mode)//閫夋嫨鍚堥傜殑浣庡姛鑰楁ā寮忥紙娣卞害锛岃交搴 { // If enterShutdownMode is not defined, will fall through to standby mode // If enterStandbyMode is not defined, will fall through to stop mode @@ -402,10 +405,10 @@ STATIC INLINE VOID OsSystemSuspend(LosIntermitMode *mode) } #endif -STATIC VOID OsLowpowerLightSleep(UINT32 mode, UINT32 cpuid, UINT32 sleepTicks) +STATIC VOID OsLowpowerLightSleep(UINT32 mode, UINT32 cpuid, UINT32 sleepTicks)//杞诲害鐫$湢涓殑妯″紡璋冩暣 { if (g_pmRunOps.preConfig != NULL) { - sleepTicks = g_pmRunOps.getSleepTime(); + sleepTicks = g_pmRunOps.getSleepTime();//鑾峰彇浼戠湢鏃堕棿 } if (sleepTicks > 1) { g_pmMgr.sleepMode[cpuid] = (mode & 0x0FF); @@ -414,18 +417,19 @@ STATIC VOID OsLowpowerLightSleep(UINT32 mode, UINT32 cpuid, UINT32 sleepTicks) OsTicklessOpen(); #endif if (mode == LOS_INTERMIT_LIGHT_SLEEP && g_pmRunOps.enterLightSleep != NULL) { - g_pmRunOps.enterLightSleep(); + g_pmRunOps.enterLightSleep();//杩涘叆杞诲害鐫$湢 } else { wfi(); } } else { - g_pmMgr.sleepMode[cpuid] = LOS_INTERMIT_NONE; + g_pmMgr.sleepMode[cpuid] = LOS_INTERMIT_NONE;//绛夊緟涓柇浜嬩欢 g_pmMgr.sleepTime[cpuid] = 0; wfi(); } } STATIC VOID OsLowpowerDeepSleep(LosIntermitMode *mode, UINT32 cpuid, UINT32 sleepTicks) +//娣卞害鐫$湢璁剧疆 { #ifdef LOSCFG_KERNEL_DEEPSLEEP if (g_pmRunOps.enterDeepSleep == NULL) { @@ -438,27 +442,31 @@ STATIC VOID OsLowpowerDeepSleep(LosIntermitMode *mode, UINT32 cpuid, UINT32 slee OsSystemSuspend(mode); } #else - *mode = LOS_INTERMIT_LIGHT_SLEEP; + *mode = LOS_INTERMIT_LIGHT_SLEEP;//鑻ヤ笉鏀寔娣卞害鐫$湢鍒欏己鍒惰繘鍏ヨ交搴︾潯鐪 #endif } -STATIC VOID OsLowpowerProcess(VOID) +STATIC VOID OsLowpowerProcess(VOID)//澶勭悊绯荤粺杩涘叆浣庡姛鑰楁ā寮忕殑杩囩▼ { -#ifdef LOSCFG_KERNEL_RUNSTOP +#ifdef LOSCFG_KERNEL_RUNSTOP//妫鏌ョ郴缁熸槸鍚﹂渶瑕佸湪杩涘叆浣庡姛鑰楁ā寮忓墠淇濆瓨绯荤粺娑堟伅 if (OsWowSysDoneFlagGet() == OS_STORE_SYSTEM) { OsStoreSystemInfoBeforeSuspend(); } #endif /* Change frequency is pended, need to change the freq here. */ - if ((g_pmRunOps.changeFreq != NULL)) { + if ((g_pmRunOps.changeFreq != NULL)) {//濡傛灉闇瑕佹敼鍙橀鐜囧垯璋冩暣鍒囨崲 OsChangeFreq(); } - + //绂佹涓柇锛岄攣浣忎换鍔¤皟搴︼紝骞惰幏鍙栧綋鍓岰PUID鍜屼紤鐪犳椂闂 UINT32 intSave = LOS_IntLock(); LOS_TaskLock(); RUNOPS_CALL_FUNC_VOID(preConfig); UINT32 cpuid = ArchCurrCpuid(); UINT32 sleepTicks = g_pmRunOps.getSleepTime(); + /*濡傛灉浼戠湢鏃堕棿灏忎簬绛変簬鏈灏忎紤鐪犳椂闂达紙g_pmMgr.minSleepTicks锛 + 鎴栬呮湁浠诲姟璇锋眰涓嶈繘鍏ユ繁搴︾潯鐪狅紙LOS_PowerMgrGetDeepSleepVoteCount 杩斿洖鍊间笉涓0锛夛紝 + 鍒欏皢褰撳墠 CPU 璁剧疆涓轰笉杩涘叆浠讳綍涓柇妯″紡锛屾竻闆朵紤鐪犳椂闂达紝 + 骞惰皟鐢 postConfig 鍑芥暟銆*/ if (sleepTicks <= g_pmMgr.minSleepTicks || LOS_PowerMgrGetDeepSleepVoteCount() != 0) { g_pmMgr.sleepMode[cpuid] = LOS_INTERMIT_NONE; g_pmMgr.sleepTime[cpuid] = 0; @@ -477,23 +485,23 @@ STATIC VOID OsLowpowerProcess(VOID) sleepTicks = g_pmMgr.maxSleepCount; } UINT32 mode = g_pmRunOps.selectSleepMode(sleepTicks); - if (mode >= LOS_INTERMIT_DEEP_SLEEP) { + if (mode >= LOS_INTERMIT_DEEP_SLEEP) {//濡傛灉鏀寔娣卞害鐫$湢 g_pmMgr.sleepTime[cpuid] = g_pmRunOps.withdrawWakeUpTimer(); OsLowpowerDeepSleep(&mode, cpuid, sleepTicks); } RUNOPS_CALL_FUNC_VOID(postConfig); - if (mode < LOS_INTERMIT_DEEP_SLEEP) { + if (mode < LOS_INTERMIT_DEEP_SLEEP) {//杩涘叆杞诲害鐫$湢 OsLowpowerLightSleep(mode, cpuid, sleepTicks); } } LOS_TaskUnlock(); - LOS_IntRestore(intSave); + LOS_IntRestore(intSave);//瑙i攣浠诲姟璋冨害骞舵仮澶嶄腑鏂 } -STATIC VOID OsLowpowerWakeupFromReset(VOID) +STATIC VOID OsLowpowerWakeupFromReset(VOID)//澶勭悊绯荤粺浠庨噸缃姸鎬佸敜閱掔殑鎯呭喌 { #ifdef LOSCFG_KERNEL_RUNSTOP if (g_resumeFromImg == LOS_RUN_STOP_RESET) { @@ -508,7 +516,7 @@ STATIC VOID OsLowpowerWakeupFromReset(VOID) #endif } -STATIC VOID OsLowpowerWakeupFromInterrupt(UINT32 intNum) +STATIC VOID OsLowpowerWakeupFromInterrupt(UINT32 intNum)//鐢ㄤ簬澶勭悊绯荤粺浠庨噸缃姸鎬佸敜閱掔殑鎯呭喌 { #ifdef LOSCFG_KERNEL_TICKLESS OsTicklessUpdate(intNum); @@ -517,26 +525,27 @@ STATIC VOID OsLowpowerWakeupFromInterrupt(UINT32 intNum) #endif } -STATIC VOID OsChangeFreq(VOID) +STATIC VOID OsChangeFreq(VOID)//澶勭悊鏀瑰彉绯荤粺棰戠巼鐨勬搷浣 { UINT32 freq; BOOL ret; - do { + do {//灏濊瘯鑾峰彇棰戠巼鍒囨崲鐨勮嚜鏃嬮攣锛堥氳繃鍘熷瓙鎿嶄綔瀹炵幇锛 + //濡傛灉鎴愬姛鑾峰彇閿侊紝鍒欒鏄庢病鏈夊叾浠栫嚎绋嬫鍦ㄩ鐜囧垏鎹㈣繃绋嬩腑锛屽彲浠ョ户缁墽琛 ret = LOS_AtomicCmpXchg32bits(&g_pmMgr.freeLock, LOCK_ON, LOCK_OFF); if (ret) { return; } - freq = (UINT32)g_pmMgr.freqPending; + freq = (UINT32)g_pmMgr.freqPending;//鑾峰彇棰戠巼鍒囨崲鐨勭洰鏍囬鐜囷紝骞惰繘琛岄鐜囧垏鎹 if (freq != (UINT32)g_pmMgr.freq) { - g_pmRunOps.changeFreq(freq); + g_pmRunOps.changeFreq(freq);//鏇存柊棰戠巼 LOS_AtomicSet(&g_pmMgr.freq, (INT32)freq); } - LOS_AtomicSet(&g_pmMgr.freeLock, LOCK_OFF); + LOS_AtomicSet(&g_pmMgr.freeLock, LOCK_OFF);//閲婃斁鑷棆閿 } while (FreqHigher(g_pmMgr.freqPending, freq)); } -STATIC VOID OsLowpowerChangeFreq(LosFreqMode freq) +STATIC VOID OsLowpowerChangeFreq(LosFreqMode freq)//鏀瑰彉绯荤粺棰戠巼 { TRACE_FUNC_CALL(); if (g_pmRunOps.changeFreq == NULL) { @@ -554,36 +563,36 @@ STATIC VOID OsLowpowerChangeFreq(LosFreqMode freq) // We get a high frequency request, then change it if (FreqHigher(g_pmMgr.freqPending, g_pmMgr.freq) && g_pmRunOps.changeFreq != NULL) { - OsChangeFreq(); + OsChangeFreq();//濡傛灉鐩爣棰戠巼楂樹簬褰撳墠棰戠巼锛屽苟涓 g_pmRunOps.changeFreq 涓嶄负绌猴紝鍒欒皟鐢 OsChangeFreq 鍑芥暟杩涜棰戠巼鍒囨崲銆 } } -STATIC VOID OsLowpowerDeepSleepVoteBegin(VOID) +STATIC VOID OsLowpowerDeepSleepVoteBegin(VOID)//寮濮嬫繁搴︾潯鐪犳姇绁 { TRACE_FUNC_CALL(); - LOS_AtomicInc(&g_pmMgr.sleepVoteCount); + LOS_AtomicInc(&g_pmMgr.sleepVoteCount);//鐢ㄥ師瀛愭搷浣滃皢 g_pmMgr.sleepVoteCount 鍔犱竴锛屽苟鏂█ g_pmMgr.sleepVoteCount 澶т簬闆躲 LOS_ASSERT(g_pmMgr.sleepVoteCount > 0); } -STATIC VOID OsLowpowerDeepSleepVoteEnd(VOID) +STATIC VOID OsLowpowerDeepSleepVoteEnd(VOID)//缁撴潫娣卞害鐫$湢鎶曠エ { TRACE_FUNC_CALL(); - LOS_AtomicDec(&g_pmMgr.sleepVoteCount); + LOS_AtomicDec(&g_pmMgr.sleepVoteCount);//鍘熷瓙鎿嶄綔灏 g_pmMgr.sleepVoteCount 鍑忎竴锛屽苟鏂█ g_pmMgr.sleepVoteCount 澶т簬绛変簬闆躲 LOS_ASSERT(g_pmMgr.sleepVoteCount >= 0); } -STATIC VOID OsLowpowerDeepSleepVoteDelay(UINT32 delayTicks) +STATIC VOID OsLowpowerDeepSleepVoteDelay(UINT32 delayTicks)//寤惰繜娣卞害鐫$湢鎶曠エ { TRACE_FUNC_CALL(); } -STATIC VOID OsLowpowerRegisterExternalVoter(LowpowerExternalVoterHandle callback) +STATIC VOID OsLowpowerRegisterExternalVoter(LowpowerExternalVoterHandle callback)//娉ㄥ唽澶栭儴鎶曠エ鑰 { TRACE_FUNC_CALL(); g_pmMgr.exVoterHandle = callback; } -STATIC UINT32 OsLowpowerGetDeepSleepVoteCount(VOID) +STATIC UINT32 OsLowpowerGetDeepSleepVoteCount(VOID)//鑾峰彇娣卞害鐫$湢鎶曠エ鏁 { if (g_pmMgr.exVoterHandle == NULL) { return (UINT32)g_pmMgr.sleepVoteCount; @@ -593,22 +602,26 @@ STATIC UINT32 OsLowpowerGetDeepSleepVoteCount(VOID) } STATIC PowerMgrOps g_pmOps = { - .process = OsLowpowerProcess, - .wakeupFromReset = OsLowpowerWakeupFromReset, - .resumeFromInterrupt = OsLowpowerWakeupFromInterrupt, - .changeFreq = OsLowpowerChangeFreq, - .deepSleepVoteBegin = OsLowpowerDeepSleepVoteBegin, - .deepSleepVoteEnd = OsLowpowerDeepSleepVoteEnd, - .deepSleepVoteDelay = OsLowpowerDeepSleepVoteDelay, - .registerExternalVoter = OsLowpowerRegisterExternalVoter, - .getDeepSleepVoteCount = OsLowpowerGetDeepSleepVoteCount, - .getSleepMode = NULL, - .setSleepMode = NULL, + .process = OsLowpowerProcess, //璇ュ嚱鏁版寚閽堢敤浜庡鐞嗕綆鍔熻楄繃绋嬶紝鍗冲湪杩涘叆浣庡姛鑰楁ā寮忓墠闇瑕佹墽琛岀殑鎿嶄綔 + .wakeupFromReset = OsLowpowerWakeupFromReset,//璇ュ嚱鏁版寚閽堢敤浜庡鐞嗕粠澶嶄綅鐘舵佸敜閱掓椂鐨勬搷浣 + .resumeFromInterrupt = OsLowpowerWakeupFromInterrupt,//璇ュ嚱鏁版寚閽堢敤浜庡鐞嗕粠涓柇鐘舵佹仮澶嶆椂鐨勬搷浣溿 + .changeFreq = OsLowpowerChangeFreq,//璇ュ嚱鏁版寚閽堢敤浜庢敼鍙樼郴缁熼鐜囩殑鎿嶄綔锛屽彲浠ユ牴鎹渶瑕佽皟鏁寸郴缁熺殑宸ヤ綔棰戠巼 + .deepSleepVoteBegin = OsLowpowerDeepSleepVoteBegin,//璇ュ嚱鏁版寚閽堢敤浜庡紑濮嬫繁搴︿紤鐪犳姇绁紝鍗冲湪杩涘叆娣卞害浼戠湢妯″紡鍓嶉渶瑕佹墽琛岀殑鎿嶄綔 + .deepSleepVoteEnd = OsLowpowerDeepSleepVoteEnd,//璇ュ嚱鏁版寚閽堢敤浜庣粨鏉熸繁搴︿紤鐪犳姇绁紝鍗冲湪閫鍑烘繁搴︿紤鐪犳ā寮忓悗闇瑕佹墽琛岀殑鎿嶄綔 + .deepSleepVoteDelay = OsLowpowerDeepSleepVoteDelay,//璇ュ嚱鏁版寚閽堢敤浜庡鐞嗘繁搴︿紤鐪犳姇绁ㄥ欢杩熺殑鎿嶄綔锛屽彲浠ユ牴鎹渶瑕佸欢杩熸繁搴︿紤鐪犵殑鎶曠エ + .registerExternalVoter = OsLowpowerRegisterExternalVoter,//璇ュ嚱鏁版寚閽堢敤浜庢敞鍐屽閮ㄦ姇绁ㄨ咃紝鍗冲湪绯荤粺涓瓨鍦ㄥ叾浠栨ā鍧椾篃闇瑕佸弬涓庝綆鍔熻楁姇绁ㄦ椂鐨勬搷浣 + .getDeepSleepVoteCount = OsLowpowerGetDeepSleepVoteCount,//璇ュ嚱鏁版寚閽堢敤浜庤幏鍙栧綋鍓嶆繁搴︿紤鐪犳姇绁ㄧ殑鏁伴噺锛屽彲浠ョ敤鏉ョ洃鎺х郴缁熶腑鍙備笌浼戠湢鎶曠エ鐨勬ā鍧楁暟閲 + .getSleepMode = NULL,//璇ュ嚱鏁版寚閽堢敤浜庤幏鍙栧綋鍓嶇殑鐫$湢妯″紡锛屽嵆鑾峰彇绯荤粺褰撳墠鏄惁澶勪簬鐫$湢鐘舵 + .setSleepMode = NULL,//璇ュ嚱鏁版寚閽堢敤浜庤缃潯鐪犳ā寮忥紝鍗冲皢绯荤粺璁剧疆涓烘寚瀹氱殑鐫$湢妯″紡 + //浠ヤ笂鎻愬強鐨勫嚱鏁板潎涓哄嚱鏁版寚閽 }; #define FORCE_NULL_CALLBACK (void *)0x3f3f3f3f - -#define ASSIGN_MEMBER(lhs, rhs, member) \ +//浠ヤ笅瀹氫箟鏄敤浜庣粰缁撴瀯浣撴垚鍛樿祴鍊硷紝濡傛灉鏌愪釜鍥炶皟鍑芥暟鎸囬拡涓虹壒娈婄┖鍊硷紝鍒欏皢鐩稿簲鐨勬垚鍛樼疆涓虹┖锛屽惁鍒欒繘琛岃祴鍊 +#define ASSIGN_MEMBER(lhs, rhs, member) +//lhs 鏄乏鎿嶄綔鏁帮紝琛ㄧず瑕佽祴鍊肩殑缁撴瀯浣撴寚閽堬紱 +//rhs 鏄彸鎿嶄綔鏁帮紝琛ㄧず瑕佽祴缁欐垚鍛樼殑鍊硷紱 +//member 鏄璧嬪肩殑缁撴瀯浣撴垚鍛 do { \ if ((rhs)->member == FORCE_NULL_CALLBACK) { \ (lhs)->member = NULL; \ @@ -631,16 +644,16 @@ VOID LOS_PowerMgrInit(const PowerMgrParameter *para) const PowerMgrRunOps *runOps = NULL; const PowerMgrDeepSleepOps *deepSleepOps = NULL; (void)deepSleepOps; - if (para != NULL) { + if (para != NULL) { //濡傛灉para涓虹┖锛屽垯杩愯鎿嶄綔鍜屾繁搴︾潯鐪犳搷浣滈兘涓虹┖鎸囬拡 runOps = ¶->runOps; #ifdef LOSCFG_KERNEL_DEEPSLEEP deepSleepOps = ¶->deepSleepOps; #endif - g_pmMgr.minSleepTicks = para->config.minLightSleepTicks; - g_pmMgr.maxSleepCount = para->config.maxDeepSleepTicks; - g_pmMgr.minDeepSleepTicks = para->config.minDeepSleepTicks; + g_pmMgr.minSleepTicks = para->config.minLightSleepTicks;//璁板綍浜嗙郴缁熶腑闇瑕佷粠鐫$湢鐘舵佸敜閱掔殑 CPU 鏍稿績鏁 + g_pmMgr.maxSleepCount = para->config.maxDeepSleepTicks;//鐢ㄤ簬淇濇姢鐢垫簮绠$悊妯″潡鍦ㄥ绾跨▼鐜涓嬬殑骞跺彂璁块棶 + g_pmMgr.minDeepSleepTicks = para->config.minDeepSleepTicks;//璁板綍鑷棆閿佹槸鍚﹁閲婃斁 } - + //灏嗕紶鍏ョ殑杩愯鎿嶄綔鍜屾繁搴︾潯鐪犳搷浣滃垎鍒祴鍊肩粰鍏ㄥ眬鍙橀噺 g_pmRunOps 鍜 g_deepSleepOps LOS_AtomicSet(&g_pmMgr.resumeSleepCores, 0); LOS_SpinInit(&g_pmMgr.lock); @@ -648,25 +661,25 @@ VOID LOS_PowerMgrInit(const PowerMgrParameter *para) // verify and assign input operators. if (runOps != NULL) { - ASSIGN_MEMBER(&g_pmRunOps, runOps, changeFreq); - ASSIGN_MEMBER(&g_pmRunOps, runOps, enterLightSleep); + ASSIGN_MEMBER(&g_pmRunOps, runOps, changeFreq);//鏀瑰彉CPU棰戠巼 + ASSIGN_MEMBER(&g_pmRunOps, runOps, enterLightSleep);//杩涘叆娴呭害鐫$湢 #ifdef LOSCFG_KERNEL_DEEPSLEEP - ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, enterDeepSleep); - ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, setWakeUpTimer); - ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, withdrawWakeUpTimer); + ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, enterDeepSleep);//杩涘叆娣卞害鐫$湢 + ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, setWakeUpTimer);//璁剧疆鍞ら啋瀹氭椂鍣 + ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, withdrawWakeUpTimer);//鎾ら攢瀹氭椂鍣 #else ASSIGN_MEMBER(&g_pmRunOps, runOps, enterDeepSleep); ASSIGN_MEMBER(&g_pmRunOps, runOps, setWakeUpTimer); ASSIGN_MEMBER(&g_pmRunOps, runOps, withdrawWakeUpTimer); #endif - ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, getSleepTime); - ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, selectSleepMode); - ASSIGN_MEMBER(&g_pmRunOps, runOps, preConfig); - ASSIGN_MEMBER(&g_pmRunOps, runOps, postConfig); + ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, getSleepTime);//璐х殑鐫$湢鏃堕棿 + ASSIGN_MEMBER_NOT_NULL(&g_pmRunOps, runOps, selectSleepMode);//閫夋嫨涓嶅悓鐨勭潯鐪犳ā寮 + ASSIGN_MEMBER(&g_pmRunOps, runOps, preConfig);//棰勯厤缃 + ASSIGN_MEMBER(&g_pmRunOps, runOps, postConfig);//鍚庨厤缃 } #ifdef LOSCFG_KERNEL_DEEPSLEEP - if (deepSleepOps != NULL) { + if (deepSleepOps != NULL) {//杩涘叆娣卞害鐫$湢 ASSIGN_MEMBER(&g_deepSleepOps, deepSleepOps, couldDeepSleep); ASSIGN_MEMBER(&g_deepSleepOps, deepSleepOps, systemWakeup); ASSIGN_MEMBER(&g_deepSleepOps, deepSleepOps, suspendPreConfig); @@ -680,4 +693,7 @@ VOID LOS_PowerMgrInit(const PowerMgrParameter *para) #endif // Register PowerMgr to Low-Power Framework. LOS_LowpowerInit(&g_pmOps); + //灏嗙數婧愮鐞嗘ā鍧楁敞鍐屽埌浣庡姛鑰楁鏋朵腑銆 + //浣庡姛鑰楁鏋舵槸涓涓敤浜庣鐞嗗鐞嗗櫒鍜岃澶囪繘鍏ヤ綆鍔熻楁ā寮忕殑杞欢妗嗘灦锛 + //瀹冭兘澶熸渶澶ч檺搴﹀湴闄嶄綆绯荤粺鑳借楋紝鎻愰珮绯荤粺鐨勭數姹犲鍛 } diff --git a/src/kernel/extended/lowpower/runstop/src/los_runstop.c b/src/kernel/extended/lowpower/runstop/src/los_runstop.c index 0da74e3..f529d6a 100644 --- a/src/kernel/extended/lowpower/runstop/src/los_runstop.c +++ b/src/kernel/extended/lowpower/runstop/src/los_runstop.c @@ -51,22 +51,28 @@ extern "C" { /* If core is ready for imaging */ LITE_OS_SEC_DATA_MINOR STATIC UINT32 g_sysDoneFlag[LOSCFG_KERNEL_CORE_NUM] = { [0 ... (LOSCFG_KERNEL_CORE_NUM - 1)] = OS_NO_STORE_SYSTEM -}; +}; /*鏍囪鏁扮粍鐘舵侊紝鐢ㄦ潵琛ㄧず绯荤粺鏄惁鍔犺浇瀹屾垚*/ /* Start position of flash to write image */ LITE_OS_SEC_DATA_MINOR STATIC UINTPTR g_flashImgAddr; +/*flash鍥惧儚鍦板潃鍜屽ぇ灏忥紝鐢ㄤ簬瀛樺偍flash鐩稿叧淇℃伅銆*/ /* Start position of heap memory after carry the image from flash to memory */ LITE_OS_SEC_DATA_MINOR STATIC const VOID *g_heapMemStart = NULL; +/*鍒濆鍖栧浘鍍忓湴鍧*/ /* Size of heap memory in image */ LITE_OS_SEC_DATA_MINOR STATIC size_t g_heapMemSize = 0; +/*鍒濆鍖栧畾涔夊浘鍍忓ぇ灏*/ + #ifdef LOSCFG_EXC_INTERACTION /* Start position of exc interaction heap memory after carry the image from flash to memory */ LITE_OS_SEC_DATA_MINOR STATIC const VOID *g_excInteractionMemStart = NULL; +/*鍦ㄥ瓨鍌ㄥ櫒鏄犲儚浠庨棯瀛樺鍒跺埌鍐呭瓨涔嬪悗寮傚父浜や簰鍫嗙殑璧峰浣嶇疆鍙橀噺*/ /* Size of exc interaction heap memory in image */ LITE_OS_SEC_DATA_MINOR STATIC size_t g_excInteractionMemSize = 0; +/*寮傚父浜や簰鍫嗗唴瀛樺湪鍌ㄥ瓨鍣ㄦ槧鍍忎腑鐨勫ぇ灏*/ #endif /* Size of wow image */ LITE_OS_SEC_DATA_MINOR STATIC size_t g_wowImgSize = 0; @@ -76,15 +82,17 @@ LITE_OS_SEC_DATA_MINOR STATIC EVENT_CB_S g_suspendResumeEvent; LITE_OS_SEC_DATA_MINOR STATIC EVENT_CB_S g_writeFlashEvent; typedef struct { - UINTPTR memStart; - UINTPTR flashStart; - size_t memSize; + UINTPTR memStart; /*鍐呭瓨璧峰鍦板潃*/ + UINTPTR flashStart; /*闂瓨璧峰鍦板潃*/ + size_t memSize; /*瀛樺偍绌洪棿澶у皬*/ } FlashWriteParam; BOOL IsImageResume(VOID) { return (g_resumeFromImg != LOS_COLD_RESET); } +/*鍒ゆ柇绯荤粺鏄惁浠庡瓨鍌ㄥ櫒鏄犲儚涓仮澶嶇殑锛屽姛鑳芥槸褰撶郴缁熷紓甯稿惎鍔ㄦ垨鑰呴渶瑕侀噸鍚殑鏃跺欏氨浼氫粠鍐呭瓨灏嗗叾鏁版嵁淇濆瓨鍒伴棯瀛樹腑 +姝ゅ嚱鏁板氨鏄垽鏂郴缁熸槸鍚︽槸浠庡瓨鍌ㄥ櫒鏄犲儚鍥炲鐨勶紝浠庤岀‘瀹氭槸鍚﹂渶瑕佸绯荤粺鐘舵佽繘琛屾仮澶*/ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsDoWriteWow2Flash(FLASH_WRITE_FUNC flashWriteFunc, const FlashWriteParam *wowSection, @@ -109,29 +117,32 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsDoWriteWow2Flash(FLASH_WRITE_FUNC flashWrit return; } } - -LITE_OS_SEC_TEXT_MINOR VOID OsWriteWow2Flash(VOID) +/*棣栧厛妫鏌ュ唴瀛樹腑鐨勫ぇ灏忔槸鍚︿负0 +鑻ヤ笉涓0鍒欏皢wowsection銆乪xcheapsection銆乭eapmemsection涓殑闈欐佹暟鎹拰浠g爜瀛樺偍鍦ㄧ郴缁熷惎鍔ㄧ殑鏃跺欏皢鍏朵粠闂瓨鍔犲叆鍒板唴瀛樹腑*/ +LITE_OS_SEC_TEXT_MINOR VOID OsWriteWow2Flash(VOID) /*鏍规嵁鎸囧畾鐨勫唴瀛樺尯鍩燂紝鍦ㄩ棯瀛樹腑鍐欏叆鐩稿簲鐨勬暟鎹紝瀹屾垚鍐欏叆鎿嶄綔*/ { FlashWriteParam wowSection; FlashWriteParam excHeapSection = {0}; - FlashWriteParam heapMemSection; - size_t eraseAlignSize; - size_t writeAlignSize; + FlashWriteParam heapMemSection; /*杩欐槸涓夌闂瓨鍐呴儴鐙珛鐨勫爢涓撶敤鐨勫唴瀛樺尯鍩熷搴旂殑闂瓨鍐欏叆鍙傛暟*/ + size_t eraseAlignSize; /*琛ㄧず闂瓨鎿﹂櫎鏃剁殑瀵归綈澶у皬*/ + size_t writeAlignSize; /*闂瓨鍐欏叆鏃剁殑瀵归綈澶у皬*/ FLASH_WRITE_FUNC flashWriteFunc = g_runstopParam.pfFlashWriteFunc; - eraseAlignSize = g_runstopParam.uwFlashEraseAlignSize; - writeAlignSize = g_runstopParam.uwFlashWriteAlignSize; + eraseAlignSize = g_runstopParam.uwFlashEraseAlignSize; /*鐢ㄦ潵鎸囧畾鎿﹂櫎鍜屽啓鍏ユ椂鐨勫榻愬ぇ灏忥紝閫氬父璁剧疆涓烘墖鍖哄ぇ灏忕殑鏁存暟鍊*/ + writeAlignSize = g_runstopParam.uwFlashWriteAlignSize; /*涓轰簡閬垮厤鍑虹幇鎿﹂櫎鎴栧啓鍏ヤ笉瑙勫垯鏁版嵁鐨勬儏鍐碉紝 + 闇瑕佸皢鎿嶄綔鐨勫湴鍧鍚戜笅鎴栧悜涓婅垗鍏ュ埌鎵囧尯澶у皬鐨勬暣鏁板 + 浠庤岄伩鍏嶅洜涓轰笉瑙勫垯鐨勬搷浣滆屽鑷存暟鎹殑閿欒鎴栨崯鍧忋*/ writeAlignSize = (writeAlignSize >= eraseAlignSize) ? writeAlignSize : eraseAlignSize; if (flashWriteFunc == NULL) { PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__); return; } - wowSection.memStart = (UINTPTR)&__ram_vectors_vma; - wowSection.flashStart = g_flashImgAddr; + wowSection.memStart = (UINTPTR)&__ram_vectors_vma;/*鍒濆鍖杦owSection锛屼负鍐呭瓨涓捣濮嬪湴鍧*/ + wowSection.flashStart = g_flashImgAddr; /*涓洪棯瀛樹腑璧峰鍦板潃*/ wowSection.memSize = ((UINTPTR)&__wow_end) - ((UINTPTR)&__ram_vectors_vma); wowSection.memSize = (wowSection.memSize + writeAlignSize - 1) & ~(writeAlignSize - 1); - + /*璁$畻浜唚owSection澶у皬锛岄氳繃涓庤繍绠椾繚璇佹瘡娆″啓鍏ョ殑鏁版嵁閮芥槸鏁翠釜鎵囧尯鐨勫嶆暟*/ #ifdef LOSCFG_EXC_INTERACTION excHeapSection.memStart = (UINTPTR)m_aucSysMem0; excHeapSection.flashStart = g_flashImgAddr + wowSection.memSize; @@ -152,39 +163,41 @@ LITE_OS_SEC_TEXT_MINOR VOID OsWriteWow2Flash(VOID) g_wowImgSize = wowSection.memSize + heapMemSection.memSize + excHeapSection.memSize; OsDoWriteWow2Flash(flashWriteFunc, &wowSection, &excHeapSection, &heapMemSection); + /*灏嗗彉閲忎紶杈撶粰鍑芥暟锛岀敱鍏跺疄鐜扮浉搴旂殑鍐欏叆鎿嶄綔*/ } -LITE_OS_SEC_TEXT_MINOR VOID OsSystemSuspend(VOID) +LITE_OS_SEC_TEXT_MINOR VOID OsSystemSuspend(VOID) /*瀹炵幇绯荤粺鐨勬寕璧锋搷浣*/ { - UINT32 cpuid; + UINT32 cpuid; /*鑾峰彇褰撳墠CPU鐨処D*/ - (VOID)LOS_IntLock(); + (VOID)LOS_IntLock(); LOS_TaskLock(); cpuid = ArchCurrCpuid(); + /*绂佹涓柇骞堕攣瀹氫换鍔¤皟搴﹀櫒锛岀‘淇濆湪鎵ц鎸傝捣鎿嶄綔鏈熼棿涓嶄細琚墦鏂*/ + g_sysDoneFlag[cpuid] = OS_NO_STORE_SYSTEM; /*灏嗗綋鍓岰PU鐨勭郴缁熸寕璧锋爣蹇楄缃负涓嶉渶瑕佷繚瀛樼郴缁熺姸鎬*/ + g_saveTsk[cpuid] = OsCurrTaskGet(); /*淇濆瓨褰撳墠浠诲姟鎸囬拡鍒皊avetask鍙橀噺涓*/ - g_sysDoneFlag[cpuid] = OS_NO_STORE_SYSTEM; - g_saveTsk[cpuid] = OsCurrTaskGet(); - - OsSRSaveRegister(); + OsSRSaveRegister(); /*淇濆瓨褰撳墠CPU鐨勫瘎瀛樺櫒鐘舵侊紝浠ヤ究鍦ㄦ仮澶嶇郴缁熸椂鑳藉姝g‘鎭㈠鍒版寕璧峰墠鐨勭姸鎬*/ /* If 1 core, only to save registers */ - if (cpuid != 0) { - if (g_otherCoreResume != 0) { + if (cpuid != 0) { /*鑻ユCPU閮ㄤ綅0鍙峰唴鏍*/ + if (g_otherCoreResume != 0) { /*璇存槑鍏朵粬澶氭牳鏍稿績闇瑕佹仮澶嶈繍琛*/ HalIrqInitPercpu(); OsTickStart(); LOS_TaskUnlock(); (VOID)LOS_IntUnLock(); - return; + return; } - g_sysDoneFlag[cpuid - 1] = OS_STORE_SYSTEM; + g_sysDoneFlag[cpuid - 1] = OS_STORE_SYSTEM; /*闇瑕佸垵濮嬪寲涓柇骞跺惎鍔ㄧ郴缁熸椂閽燂紝骞舵渶缁堣В閿佷换鍔¤皟搴﹀櫒骞舵仮澶嶄腑鏂*/ while (1) {} } - if (g_resumeFromImg) { + if (g_resumeFromImg) { /*濡傛灉鏄 0 鍙 CPU锛屼笖绯荤粺闇瑕佷粠闀滃儚涓仮澶嶏紙g_resumeFromImg 涓虹湡锛*/ OsWriteWow2Flash(); LOS_TaskUnlock(); (VOID)LOS_IntUnLock(); (VOID)LOS_EventWrite(&g_suspendResumeEvent, FLASH_IMG_SUCCESS); - } else { + /*璋冪敤 OsWriteWow2Flash 鍑芥暟灏嗘暟鎹啓鍏ラ棯瀛橈紝骞跺彂閫 FLASH_IMG_SUCCESS 浜嬩欢淇″彿锛岃〃绀烘垚鍔熶粠闀滃儚涓仮澶*/ + } else { /*涓嶉渶瑕佷粠闀滃儚涓仮澶*/ OsTickStart(); LOS_TaskUnlock(); (VOID)LOS_IntUnLock(); @@ -194,9 +207,15 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemSuspend(VOID) } (VOID)LOS_EventWrite(&g_suspendResumeEvent, WAKEUP_FROM_SUSPEND); } + /*鍚姩绯荤粺鏃堕挓锛岃В閿佷换鍔¤皟搴﹀櫒鍜屼腑鏂紝骞舵牴鎹槸鍚﹁缃簡绌洪棽鍞ら啋鍥炶皟鍑芥暟鏉ユ墽琛岀浉搴旂殑鎿嶄綔锛 + 鏈鍚庡彂閫 WAKEUP_FROM_SUSPEND 浜嬩欢淇″彿锛岃〃绀轰粠鎸傝捣鐘舵佸敜閱*/ } LITE_OS_SEC_TEXT VOID OsWriteToFlashTask(VOID) +/*鍒濆鍖栦簡涓涓簨浠跺璞 g_writeFlashEvent +骞朵笖鍦ㄥ惊鐜腑璋冪敤 LOS_EventRead 鍑芥暟绛夊緟浜嬩欢鐨勫彂鐢燂紝 +骞朵互 OR 妯″紡鍜屾竻闄ゆā寮忕瓑寰呬簨浠剁殑鏍囧織浣嶄负 0x01銆 +涓鏃︿簨浠跺彂鐢燂紝瀹冭皟鐢 OsSystemSuspend 鍑芥暟灏嗙郴缁熸寕璧枫*/ { (VOID)LOS_EventInit(&g_writeFlashEvent); @@ -207,6 +226,10 @@ LITE_OS_SEC_TEXT VOID OsWriteToFlashTask(VOID) } LITE_OS_SEC_TEXT VOID OsStoreSystemInfoBeforeSuspend(VOID) +/*鏍规嵁褰撳墠 CPU 鐨 ID 鍒ゆ柇鏄惁闇瑕佹寕璧风郴缁熴 +濡傛灉褰撳墠 CPU 涓嶆槸 0 鍙 CPU锛岀洿鎺ヨ皟鐢 OsSystemSuspend 鍑芥暟鎸傝捣绯荤粺銆 +濡傛灉鏄 0 鍙 CPU锛屽垯璋冪敤 LOS_EventWrite 鍑芥暟鍚戜簨浠跺璞 g_writeFlashEvent 鍙戦佷竴涓簨浠讹紝 +鍞ら啋 OsWriteToFlashTask 浠诲姟鏉ユ墽琛屾寕璧锋搷浣溿*/ { UINT32 cpuid = ArchCurrCpuid(); if (cpuid != 0) { @@ -218,6 +241,9 @@ LITE_OS_SEC_TEXT VOID OsStoreSystemInfoBeforeSuspend(VOID) } LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID) +/*鏄郴缁熶粠鎸傝捣鐘舵佸敜閱掑悗鐨勫鐞嗗嚱鏁般*/ + + { UINT32 cpuid; errno_t err; @@ -225,7 +251,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID) if (!g_resumeFromImg) { return; } - +/*杩涜涓浜涘唴瀛樻暟鎹殑澶嶅埗鎿嶄綔锛岀劧鍚庤缃綋鍓 CPU 鐨勪换鍔℃寚閽堬紝*/ #ifdef LOSCFG_EXC_INTERACTION err = memmove_s(m_aucSysMem0, g_excInteractMemSize, g_excInteractionMemStart, g_excInteractionMemSize); if (err != EOK) { @@ -243,6 +269,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID) cpuid = ArchCurrCpuid(); OsCurrTaskSet(g_saveTsk[cpuid]); +/*璁剧疆绯荤粺璁℃暟鍣ㄩ鐜囥傛帴鐫锛屽畠閲嶇疆鍐呭瓨姹犵殑鏈熬鑺傜偣锛屾竻闆 BSS 鍖哄煙鐨勬暟鎹紝閲嶆柊鍒濆鍖栦腑鏂*/ /* Set system counter freq */ HalClockFreqWrite(OS_SYS_CLOCK); dsb(); @@ -270,7 +297,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsSystemWakeup(VOID) #ifdef LOSCFG_KERNEL_CPUP OsSetCpuCycle(0); #endif - +/*骞惰皟鐢 OsSRRestoreRegister 鍑芥暟鎭㈠瀵勫瓨鍣ㄧ姸鎬*/ #if (LOSCFG_KERNEL_SMP == YES) release_secondary_cores(); #endif @@ -281,32 +308,33 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsWaitImagingDone(UINTPTR wowFlashAddr, size_t *wo { UINT32 ret; - g_flashImgAddr = wowFlashAddr; - (VOID)LOS_EventInit(&g_suspendResumeEvent); + g_flashImgAddr = wowFlashAddr; /*鐑у綍鐨刦lash鍦板潃*/ + (VOID)LOS_EventInit(&g_suspendResumeEvent); /*鎸囧悜鐢ㄤ簬瀛樺偍鐑у綍闀滃儚澶у皬鐨勫彉閲忕殑鎸囬拡*/ - // This flag will be stored into flash, and will affect the wakeup procedure when cpu is rebooting. + // 杩欎釜鏍囧織灏嗚瀛樺偍鍒伴棯瀛樹腑锛屽綋 CPU 閲嶆柊鍚姩鏃讹紝瀹冨皢褰卞搷鍞ら啋娴佺▼銆 g_resumeFromImg = LOS_RUN_STOP_RESET; - // This flag affects the suspending procedure later, - // and will be reset depending on 'g_resumeFromImg' when cpu is rebooting. + // 杩欎釜鏍囧織浼氬奖鍝嶄箣鍚庣殑鎸傝捣杩囩▼锛屽苟涓斿湪 CPU 閲嶆柊鍚姩鏃舵牴鎹 'g_resumeFromImg' 鐨勫艰繘琛岄噸缃 g_otherCoreResume = 0; - g_sysDoneFlag[LOSCFG_KERNEL_CORE_NUM - 1] = OS_STORE_SYSTEM; + g_sysDoneFlag[LOSCFG_KERNEL_CORE_NUM - 1] = OS_STORE_SYSTEM; /*琛ㄧず绯荤粺鐘舵侀渶瑕佽淇濆瓨*/ ret = LOS_EventRead(&g_suspendResumeEvent, 0xFF, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER); + /*绛夊緟浜嬩欢鍙戠敓*/ if (wowImgSize != NULL) { *wowImgSize = g_wowImgSize; - } + }/*淇濊瘉鑳藉鍦ㄧ儳褰曞畬鎴愪箣鍚庢纭殑淇濆瓨鍜屾仮澶嶇姸鎬*/ return ret; } -LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID) +LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID) /*灏嗕綅浜嶳AM鐨勬暟鎹粠鎸囧畾浣嶇疆澶嶅埗鍒癋lash瀛樺偍鍣ㄤ腑*/ { size_t size; UINTPTR memAddr; - size_t wowSize; - size_t readAlignSize; - size_t eraseAlignSize; - size_t writeAlignSize; + size_t wowSize;/*绛夊緟澶嶅埗鏁版嵁鐨勫ぇ灏*/ + size_t readAlignSize;/*璇诲彇瀵归綈澶у皬*/ + size_t eraseAlignSize;/*鎿﹂櫎瀵归綈澶у皬*/ + size_t writeAlignSize;/*鍐欏叆瀵归綈澶у皬*/ + /*璇诲彇鎵鏈夊弬鏁扮殑鍒濆鐘舵*/ UINTPTR imageFlashAddr; FLASH_READ_FUNC flashReadFunc = g_runstopParam.pfFlashReadFunc; @@ -315,18 +343,19 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID) eraseAlignSize = g_runstopParam.uwFlashEraseAlignSize; writeAlignSize = g_runstopParam.uwFlashWriteAlignSize; writeAlignSize = (writeAlignSize >= eraseAlignSize) ? writeAlignSize : eraseAlignSize; - + /*璁$畻wowsize鐨勫ぇ灏忥紝鏍规嵁瀵归綈澶у皬璋冩暣鍊*/ wowSize = ((UINTPTR)&__wow_end) - ((UINTPTR)&__ram_vectors_vma); wowSize = (wowSize + writeAlignSize - 1) & ~(writeAlignSize - 1); imageFlashAddr += wowSize; - + /*妫鏌emaddr鏄惁瓒呭嚭浜咮SS娈电殑璧峰鍦板潃*/ memAddr = ((UINTPTR)&__ram_vectors_vma) + wowSize; if (memAddr >= ((UINTPTR)&__bss_start)) { return; } + /*璁$畻浜嗚澶嶅埗鐨勬暟鎹ぇ灏忥紝鍦ㄧ鐩樹腑鏍规嵁瀵归綈澶у皬璋冩暣size*/ size = ((UINTPTR)&__int_stack_start) - memAddr; size = (size + readAlignSize - 1) & ~(readAlignSize - 1); - + /*灏哛AM涓殑鏁版嵁浠巑emaddr澶嶅埗鍒癴lash瀛樺偍鍣ㄧ殑imageflashaddr锛岃繘琛岀紦瀛樺拰鍚屾鎿嶄綔*/ if ((flashReadFunc != NULL) && (flashReadFunc((VOID *)memAddr, imageFlashAddr, size) != 0)) { PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__); } @@ -336,6 +365,8 @@ LITE_OS_SEC_TEXT_MINOR VOID OsCarryLeftScatter(VOID) } LITE_OS_SEC_TEXT_MINOR VOID OsRunstopParamInit(const RUNSTOP_PARAM_S *runstopParam) +/*鍒濆鍖栬繍琛屾殏鍋滃姛鑳芥墍闇鐨勫弬鏁帮紝淇濆瓨鍦ㄥ叏灞鍙橀噺g_涓紝浠ヤ究鍛婅瘔璁$畻鏈虹洰鍓嶇殑绯荤粺杞彴 +鍖呭惈浜嗚繍琛屾殏鍋滃姛鑳芥墍闇鐨勫悇涓洖璋冨嚱鏁板拰瀵归綈澶у皬绛夊弬鏁*/ { g_runstopParam.pfIdleWakeupCallback = runstopParam->pfIdleWakeupCallback; g_runstopParam.pfWakeupCallback = runstopParam->pfWakeupCallback; @@ -350,28 +381,31 @@ LITE_OS_SEC_TEXT_MINOR VOID OsRunstopParamInit(const RUNSTOP_PARAM_S *runstopPar } LITE_OS_SEC_TEXT_MINOR VOID LOS_MakeImage(RUNSTOP_PARAM_S *runstopParam) +/*鐢ㄤ簬闄ゆ硶杩愯鏆傚仠鍔熻兘鐨勬搷浣滐紝骞舵牴鎹繑鍥炲艰繘琛岀浉搴斿鐞*/ { UINT32 ret; size_t imgSize; - + /*妫鏌ユ槸鍚﹂渶瑕佹殏鍋*/ if (runstopParam == NULL) { return; } + /*璋冪敤鍑芥暟锛屽皢浼犲叆鐨剅unstopparam杞崲涓哄叏灞鍙橀噺*/ OsRunstopParamInit(runstopParam); ret = OsWaitImagingDone(g_runstopParam.uwWowFlashAddr, &imgSize); - if (ret == WAKEUP_FROM_SUSPEND) { + /*鐢ㄤ簬绛夊緟鍥惧儚杞Щ瀹屾垚锛岃寖鍥寸浉搴旂殑鐘舵佺爜ret鍜屽浘鍍忓ぇ灏廼mgsize*/ + if (ret == WAKEUP_FROM_SUSPEND) { /*浠庢殏鍋滅姸鎬佸敜閱掞紝骞舵煡鐪嬬郴缁熸槸鍚﹂渶瑕佺┖闂插敜閱掑洖璋*/ if (g_runstopParam.pfWakeupCallback != NULL) { g_runstopParam.pfWakeupCallback(); } - OsCarryLeftScatter(); + OsCarryLeftScatter(); /*灏哛AM涓殑鏁版嵁澶嶅埗鍒癋lash瀛樺偍鍣*/ PRINT_INFO("Resume ok!\n"); - } else if (ret == FLASH_IMG_SUCCESS) { + } else if (ret == FLASH_IMG_SUCCESS) { /*闂瓨鍥惧儚鎴愬姛*/ if (g_runstopParam.pfImageDoneCallback != NULL) { g_runstopParam.pfImageDoneCallback(); } - PRINT_INFO("Flash ok! Image length 0x%x\n", imgSize); + PRINT_INFO("Flash ok! Image length 0x%x\n", imgSize);/*鍥惧儚杞Щ鎴愬姛锛屽苟鎵撳嵃鍥惧儚澶у皬*/ } } @@ -380,8 +414,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsWowWriteFlashTaskCreate(VOID) UINT32 ret; UINT32 writeFlashTaskId; TSK_INIT_PARAM_S taskInitParam; - + /*棣栧厛瀵逛换鍔″垵濮嬪寲鍙傛暟杩涜浜嗘竻闆舵搷浣*/ (VOID)memset_s((VOID *)(&taskInitParam), sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); + /*璁剧疆浜嗕换鍔″叆鍙e嚱鏁帮紝骞朵笖鍒跺畾浜嗕换鍔$殑鍫嗘爤澶у皬锛屼换鍔″悕鍜屼紭鍏堢骇*/ taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsWriteToFlashTask; taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; taskInitParam.pcName = "WowWriteFlashTask"; @@ -389,24 +424,28 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsWowWriteFlashTaskCreate(VOID) #ifdef LOSCFG_KERNEL_SMP taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(0); #endif + /*鍒涘缓浠诲姟锛岃繑鍥炵粨鏋*/ ret = LOS_TaskCreate(&writeFlashTaskId, &taskInitParam); return ret; } LITE_OS_SEC_TEXT_MINOR size_t OsWowImageSizeGet(VOID) +/*鑾峰彇wow鍥惧儚鐨勫ぇ灏忥紝杩斿洖鍏ㄥ眬鍙橀噺*/ { return g_wowImgSize; } LITE_OS_SEC_TEXT_MINOR UINT32 OsWowSysDoneFlagGet(VOID) +/*鑾峰彇wow绯荤粺瀹屾垚鐨勬爣蹇*/ { UINT32 cpuid = ArchCurrCpuid(); return g_sysDoneFlag[cpuid]; } LITE_OS_SEC_TEXT_MINOR VOID OsWowOtherCoreResume(UINT32 cpuid) +/*鍞ら啋鍏朵粬鐨勬牳蹇*/ { - if (g_otherCoreResume == 1) { + if (g_otherCoreResume == 1) { /*鍏ㄥ眬鍙橀噺鐨勫间负1鍒欒〃绀洪渶瑕佸敜閱掑叾浠栨牳蹇*/ OsCurrTaskSet(g_saveTsk[cpuid]); OsSRRestoreRegister(); } diff --git a/src/kernel/extended/lowpower/tickless/los_tickless.c b/src/kernel/extended/lowpower/tickless/los_tickless.c index fdeb5b8..d609b1e 100644 --- a/src/kernel/extended/lowpower/tickless/los_tickless.c +++ b/src/kernel/extended/lowpower/tickless/los_tickless.c @@ -46,42 +46,46 @@ STATIC volatile UINT32 g_sleepTicks[LOSCFG_KERNEL_CORE_NUM] = {0}; (((GET_SYS_CLOCK()) / (g_tickPerSecond)) - (cyclesCur)) : \ ((((GET_SYS_CLOCK()) / (g_tickPerSecond)) << 1) - (cyclesCur))) -LITE_OS_SEC_TEXT VOID LOS_TicklessEnable(VOID) +LITE_OS_SEC_TEXT VOID LOS_TicklessEnable(VOID) /*寮鍚疶ickless鍔熻兘*/ { g_ticklessFlag = TRUE; + /*鍙橀噺琛ㄧずTickless鍔熻兘鐨勫紑鍚姸鎬侊紝涓篢RUE琛ㄧず宸插紑鍚紝涓篎ALSE琛ㄧず宸插叧闂*/ } -LITE_OS_SEC_TEXT VOID LOS_TicklessDisable(VOID) +LITE_OS_SEC_TEXT VOID LOS_TicklessDisable(VOID) /*寮鍚疶ickless鍔熻兘*/ { g_ticklessFlag = FALSE; } -LITE_OS_SEC_TEXT BOOL OsTicklessFlagGet(VOID) +LITE_OS_SEC_TEXT BOOL OsTicklessFlagGet(VOID) /*鐢ㄤ簬鑾峰彇Tickless鏍囧織鐨勭姸鎬*/ { return g_ticklessFlag; } -LITE_OS_SEC_TEXT BOOL OsTickIrqFlagGet(VOID) +LITE_OS_SEC_TEXT BOOL OsTickIrqFlagGet(VOID) { return g_tickIrqFlag[ArchCurrCpuid()]; + /*鏁扮粍琛ㄧず姣忎釜鏍稿績鐨凾ick涓柇鏍囧織鐨勭姸鎬侊紝 + 涓篢RUE琛ㄧず涓柇姝e湪澶勭悊涓紝涓篎ALSE琛ㄧず涓柇鏈鐞嗐*/ } -LITE_OS_SEC_TEXT VOID OsTickIrqFlagSet(BOOL tickIrqFlag) +LITE_OS_SEC_TEXT VOID OsTickIrqFlagSet(BOOL tickIrqFlag) /*鐢ㄤ簬璁剧疆褰撳墠鏍稿績鐨勬椂閽熶腑鏂爣蹇*/ { g_tickIrqFlag[ArchCurrCpuid()] = tickIrqFlag; } -LITE_OS_SEC_TEXT UINT32 OsTicklessSleepTickGet(VOID) +LITE_OS_SEC_TEXT UINT32 OsTicklessSleepTickGet(VOID) /*鐢ㄤ簬鑾峰彇褰撳墠绯荤粺鐨勭潯鐪犺鏃跺櫒鐨勬暟鍊*/ { return g_sleepTicks[ArchCurrCpuid()]; } -LITE_OS_SEC_TEXT VOID OsTicklessSleepTickSet(UINT32 sleeptick) +LITE_OS_SEC_TEXT VOID OsTicklessSleepTickSet(UINT32 sleeptick) /*璁剧疆褰撳墠鏍稿績寰楀埌鐫$湢璁℃椂鍣ㄧ殑鏁板*/ { g_sleepTicks[ArchCurrCpuid()] = sleeptick; } -LITE_OS_SEC_TEXT UINT32 OsSleepTicksGet(VOID) +LITE_OS_SEC_TEXT UINT32 OsSleepTicksGet(VOID) /*鍑芥暟鐢ㄤ簬鑾峰彇褰撳墠闇瑕佷紤鐪犵殑ticks鏁帮紝閫氳繃鏌ヨ浠诲姟閾捐〃鍜岃蒋浠跺畾鏃跺櫒閾捐〃锛 + 鎵惧埌鏈灏忕殑瀹氭椂鍣ㄥ埌鏈熸椂闂达紝浣滀负浼戠湢鏃堕暱銆*/ { UINT32 tskSortLinkTicks, sleepTicks; @@ -104,7 +108,8 @@ LITE_OS_SEC_TEXT UINT32 OsSleepTicksGet(VOID) return sleepTicks; } -LITE_OS_SEC_TEXT VOID OsSysTimeUpdate(UINT32 sleepTicks) +LITE_OS_SEC_TEXT VOID OsSysTimeUpdate(UINT32 sleepTicks) /*鐢ㄤ簬鏇存柊绯荤粺鏃堕棿锛 + 鏍规嵁浼戠湢鏃堕暱鏇存柊鍏ㄥ眬璁℃暟鍣ㄥ拰浠诲姟閾捐〃銆佽蒋浠跺畾鏃跺櫒閾捐〃鐨勫埌鏈熸椂闂*/ { UINT32 intSave; @@ -127,7 +132,7 @@ LITE_OS_SEC_TEXT VOID OsSysTimeUpdate(UINT32 sleepTicks) LOS_IntRestore(intSave); } -VOID OsTicklessUpdate(UINT32 irqnum) +VOID OsTicklessUpdate(UINT32 irqnum) /*OsTicklessUpdate鍑芥暟鐢ㄤ簬鍦ㄥ彂鐢熶腑鏂椂鏇存柊绯荤粺鏃堕棿*/ { UINT32 cycles, ticks; UINT32 cyclesPertick; @@ -165,7 +170,8 @@ VOID OsTicklessUpdate(UINT32 irqnum) LOS_IntRestore(intSave); } -VOID OsTicklessStart(VOID) +VOID OsTicklessStart(VOID) /*Tickless妯″紡鐨勫叆鍙e嚱鏁帮紝鏍规嵁浼戠湢鏃堕暱璁$畻闇瑕佸欢杩熺殑鍛ㄦ湡鏁帮紝 + 骞惰缃畾鏃跺櫒鐨勯噸杞藉硷紝鍚姩Tickless妯″紡銆*/ { UINT32 intSave; /* @@ -202,7 +208,8 @@ VOID OsTicklessStart(VOID) return; } -VOID OsTicklessOpen(VOID) +VOID OsTicklessOpen(VOID) /*鍦═ick涓柇澶勭悊鍑芥暟涓紑鍚疶ickless妯″紡銆 + 褰揟ick涓柇澶勭悊鍑芥暟妫娴嬪埌Tickless鏍囧織涓1鏃讹紝璋冪敤璇ュ嚱鏁板惎鍔═ickless妯″紡銆*/ { if (OsTickIrqFlagGet()) { OsTickIrqFlagSet(0); diff --git a/src/kernel/extended/perf/los_perf.c b/src/kernel/extended/perf/los_perf.c index ecb0c2e..e8b84f6 100644 --- a/src/kernel/extended/perf/los_perf.c +++ b/src/kernel/extended/perf/los_perf.c @@ -37,10 +37,11 @@ extern "C" { #endif /* __cplusplus */ #ifdef LOSCFG_KERNEL_PERF -STATIC Pmu *g_pmu = NULL; -STATIC PerfCB g_perfCb = {0}; +STATIC Pmu *g_pmu = NULL;//鐢ㄤ簬淇濆瓨褰撳墠绯荤粺涓墍浣跨敤鐨勭‖浠舵ц兘璁℃暟鍣 +STATIC PerfCB g_perfCb = {0};//淇濆瓨浜嗘ц兘娴嬮噺鍥炶皟鍑芥暟鍜屼竴浜涙祴閲忕粨鏋滄暟鎹 LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_perfSpin); +//瀹氫箟浜嗕竴涓嚜鏃嬮攣 g_perfSpin锛岀敤浜庝繚鎶ゆц兘娴嬮噺妯″潡鍦ㄥ绾跨▼鐜涓嬬殑骞跺彂璁块棶 #define PERF_LOCK(state) LOS_SpinLockSave(&g_perfSpin, &(state)) #define PERF_UNLOCK(state) LOS_SpinUnlockRestore(&g_perfSpin, (state)) @@ -55,8 +56,9 @@ STATIC INLINE UINT64 OsPerfGetCurrTime(VOID) #endif } -STATIC UINT32 OsPmuInit(VOID) +STATIC UINT32 OsPmuInit(VOID)//鍒濆鍖栨ц兘璁℃暟鍣 { + //鍒ゆ柇鏄惁寮鍚簡璁℃暟鍣 #ifdef LOSCFG_PERF_HW_PMU if (OsHwPmuInit() != LOS_OK) { return LOS_ERRNO_PERF_HW_INIT_ERROR; @@ -77,13 +79,13 @@ STATIC UINT32 OsPmuInit(VOID) return LOS_OK; } -STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg) +STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg)//閰嶇疆鎬ц兘璁℃暟鍣 { UINT32 i; UINT32 ret; g_pmu = OsPerfPmuGet(eventsCfg->type); - if (g_pmu == NULL) { + if (g_pmu == NULL) {//鏍规嵁閰嶇疆鐨勭被鍨嬭幏鍙栧搴旂殑鎬ц兘璁℃暟鍣ㄥ璞 PRINT_ERR("perf config type error %u!\n", eventsCfg->type); return LOS_ERRNO_PERF_INVALID_PMU; } @@ -92,6 +94,7 @@ STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg) (VOID)memset_s(&g_pmu->events, sizeof(PerfEvent), 0, sizeof(PerfEvent)); +//鏍规嵁閰嶇疆淇℃伅璁剧疆鍚勬ц兘浜嬩欢鐨勫弬鏁帮紝璋冪敤鎬ц兘璁℃暟鍣ㄥ璞$殑閰嶇疆鍑芥暟杩涜閰嶇疆 for (i = 0; i < eventNum; i++) { g_pmu->events.per[i].eventId = eventsCfg->events[i].eventId; g_pmu->events.per[i].period = eventsCfg->events[i].period; @@ -109,13 +112,13 @@ STATIC UINT32 OsPerfConfig(PerfEventConfig *eventsCfg) return LOS_OK; } -STATIC VOID OsPerfPrintCount(VOID) +STATIC VOID OsPerfPrintCount(VOID)//鐢ㄤ簬鎵撳嵃鎬ц兘璁℃暟鍣ㄧ殑缁熻淇℃伅 { UINT32 index; UINT32 intSave; UINT32 cpuid = ArchCurrCpuid(); - PerfEvent *events = &g_pmu->events; + PerfEvent *events = &g_pmu->events;//鑾峰彇鎬ц兘璁℃暟鍣ㄥ璞$殑鎬ц兘鏃堕棿鏁扮粍鍜屼簨浠舵暟閲 UINT32 eventNum = events->nr; PERF_LOCK(intSave); @@ -123,7 +126,7 @@ STATIC VOID OsPerfPrintCount(VOID) Event *event = &(events->per[index]); /* filter out event counter with no event binded. */ - if (event->period == 0) { + if (event->period == 0) { //浜嬩欢鍛ㄦ湡 continue; } PRINT_EMG("[%s] eventType: 0x%x [core %u]: %llu\n", g_pmu->getName(event), event->eventId, cpuid, @@ -132,7 +135,7 @@ STATIC VOID OsPerfPrintCount(VOID) PERF_UNLOCK(intSave); } -STATIC INLINE VOID OsPerfPrintTs(VOID) +STATIC INLINE VOID OsPerfPrintTs(VOID)//鎵撳嵃鏃堕棿淇℃伅 { #ifdef LOSCFG_PERF_CALC_TIME_BY_TICK DOUBLE time = (g_perfCb.endTime - g_perfCb.startTime) * 1.0 / LOSCFG_BASE_CORE_TICK_PER_SECOND; @@ -142,7 +145,7 @@ STATIC INLINE VOID OsPerfPrintTs(VOID) PRINT_EMG("time used: %.6f(s)\r\n", time); } -STATIC VOID OsPerfStart(VOID) +STATIC VOID OsPerfStart(VOID)//鍚姩鍙婃洿鏂癈PU鍜岃鏁板櫒鐘舵 { UINT32 cpuid = ArchCurrCpuid(); @@ -152,7 +155,7 @@ STATIC VOID OsPerfStart(VOID) } if (g_perfCb.pmuStatusPerCpu[cpuid] != PERF_PMU_STARTED) { - UINT32 ret = g_pmu->start(); + UINT32 ret = g_pmu->start();//鑻ヨ鏁板櫒鏈惎鍔ㄥ垯鍚姩 if (ret != LOS_OK) { PRINT_ERR("perf start on core:%u failed, ret = 0x%x\n", cpuid, ret); return; @@ -164,7 +167,7 @@ STATIC VOID OsPerfStart(VOID) } } -STATIC VOID OsPerfStop(VOID) +STATIC VOID OsPerfStop(VOID)//鍋滄鎬ц兘璁℃暟鍣 { UINT32 cpuid = ArchCurrCpuid(); @@ -191,19 +194,21 @@ STATIC VOID OsPerfStop(VOID) } STATIC UINT32 OsPerfBackTrace(UINTPTR *callChain, UINT32 maxDepth, PerfRegs *regs) +//鑾峰彇褰撳墠鍑芥暟璋冪敤閾剧殑淇℃伅锛屽苟灏嗙粨鏋滃瓨鍌ㄥ湪 callChain 鏁扮粍涓 { UINT32 i; - UINT32 count = ArchBackTraceGet(regs->fp, callChain, maxDepth); + UINT32 count = ArchBackTraceGet(regs->fp, callChain, maxDepth);//鑾峰彇褰撳墠鐘舵佺殑甯ф寚閽堝 PRINT_DEBUG("backtrace depth = %u, fp = 0x%x\n", count, regs->fp); for (i = 0; i < count; i++) { - PRINT_DEBUG("ip[%u]: 0x%x\n", i, callChain[i]); + PRINT_DEBUG("ip[%u]: 0x%x\n", i, callChain[i]);//鎵撳嵃璋冪敤閾句腑姣忎釜鍑芥暟鐨勬寚浠ゅ湴鍧 } - return count; + return count;//杩斿洖鐢ㄩ摼鐨勬繁搴 } STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *regs) +//鏀堕泦鎬ц兘璁℃暟鍣ㄧ殑鏁版嵁锛屽苟灏嗗叾瀛樺偍鍦 data 缁撴瀯浣撲腑 { UINT32 size = 0; UINT32 depth; @@ -211,12 +216,12 @@ STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *re CHAR *p = (CHAR *)data; if (sampleType & PERF_RECORD_CPU) { - *(UINT32 *)(p + size) = ArchCurrCpuid(); + *(UINT32 *)(p + size) = ArchCurrCpuid();//鍑芥暟鑾峰彇褰撳墠CPU鐨処D锛屽苟瀛樺偍鍦 data->cpuid 瀛楁涓 size += sizeof(data->cpuid); } if (sampleType & PERF_RECORD_TID) { - *(UINT32 *)(p + size) = LOS_CurTaskIDGet(); + *(UINT32 *)(p + size) = LOS_CurTaskIDGet();// 鍑芥暟鑾峰彇褰撳墠浠诲姟鐨処D锛屽苟瀛樺偍鍦 data->taskId 瀛楁涓 size += sizeof(data->taskId); } @@ -231,7 +236,7 @@ STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *re } if (sampleType & PERF_RECORD_TIMESTAMP) { - *(UINT64 *)(p + size) = OsPerfGetCurrTime(); + *(UINT64 *)(p + size) = OsPerfGetCurrTime();//鑾峰彇褰撳墠鏃堕棿鎴筹紝骞跺瓨鍌ㄥ湪 data->time 瀛楁涓 size += sizeof(data->time); } @@ -254,7 +259,7 @@ STATIC UINT32 OsPerfCollectData(Event *event, PerfSampleData *data, PerfRegs *re * return TRUE if user haven't specified any taskId(which is supposed * to instrument the whole system) */ -STATIC BOOL OsPerfTaskFilter(UINT32 taskId) +STATIC BOOL OsPerfTaskFilter(UINT32 taskId)//杩囨护浠诲姟ID锛屽垽鏂竴涓粰瀹氱殑浠诲姟ID鏄惁闇瑕佽繘琛屾ц兘浼樺寲 { UINT32 i; @@ -262,7 +267,7 @@ STATIC BOOL OsPerfTaskFilter(UINT32 taskId) return TRUE; } - for (i = 0; i < g_perfCb.taskIdsNr; i++) { + for (i = 0; i < g_perfCb.taskIdsNr; i++) { //鍌ㄥ瓨鍏佽杩囨护浠诲姟ID鐨勫垪琛 if (g_perfCb.taskIds[i] == taskId) { return TRUE; } @@ -270,7 +275,7 @@ STATIC BOOL OsPerfTaskFilter(UINT32 taskId) return FALSE; } -STATIC INLINE UINT32 OsPerfParamValid(VOID) +STATIC INLINE UINT32 OsPerfParamValid(VOID)//妫鏌ユц兘鍑芥暟鐨勬湁鏁堟 { UINT32 index; UINT32 res = 0; @@ -287,7 +292,7 @@ STATIC INLINE UINT32 OsPerfParamValid(VOID) return res; } -STATIC UINT32 OsPerfHdrInit(UINT32 id) +STATIC UINT32 OsPerfHdrInit(UINT32 id)//鍒濆鍖栨ц兘鏁版嵁鐨勫ご閮ㄤ俊鎭 { PerfDataHdr head = { .magic = PERF_DATA_MAGIC_WORD, @@ -299,7 +304,7 @@ STATIC UINT32 OsPerfHdrInit(UINT32 id) return OsPerfOutPutWrite((CHAR *)&head, head.len); } -VOID OsPerfUpdateEventCount(Event *event, UINT32 value) +VOID OsPerfUpdateEventCount(Event *event, UINT32 value)//鏇存柊涓婁紶浜嬩欢鐨勬妧鏈 { if (event == NULL) { return; @@ -307,46 +312,46 @@ VOID OsPerfUpdateEventCount(Event *event, UINT32 value) event->count[ArchCurrCpuid()] += (value & 0xFFFFFFFF); /* event->count is UINT64 */ } -VOID OsPerfHandleOverFlow(Event *event, PerfRegs *regs) +VOID OsPerfHandleOverFlow(Event *event, PerfRegs *regs)//澶勭悊鎬ц兘璁℃暟鍣ㄦ孩鍑虹殑鎯呭喌 { PerfSampleData data; UINT32 len; (VOID)memset_s(&data, sizeof(PerfSampleData), 0, sizeof(PerfSampleData)); - if ((g_perfCb.needSample) && OsPerfTaskFilter(LOS_CurTaskIDGet())) { + if ((g_perfCb.needSample) && OsPerfTaskFilter(LOS_CurTaskIDGet())) {//鍒ゆ柇鏄惁浼樺寲 len = OsPerfCollectData(event, &data, regs); OsPerfOutPutWrite((CHAR *)&data, len); } } -UINT32 LOS_PerfInit(VOID *buf, UINT32 size) +UINT32 LOS_PerfInit(VOID *buf, UINT32 size)//鍒濆鍖栨ц兘缁熻妯″潡 { UINT32 ret; UINT32 intSave; - PERF_LOCK(intSave); + PERF_LOCK(intSave);//淇濆瓨涓柇鐘舵 if (g_perfCb.status != PERF_UNINIT) { ret = LOS_ERRNO_PERF_STATUS_INVALID; goto PERF_INIT_ERROR; } - ret = OsPmuInit(); + ret = OsPmuInit();//鍑芥暟鎬ц兘璁℃暟鍣ㄥ垵濮嬪寲 if (ret != LOS_OK) { goto PERF_INIT_ERROR; } - ret = OsPerfOutPutInit(buf, size); + ret = OsPerfOutPutInit(buf, size);//鎬ц兘杈撳嚭缂撳啿鍖鸿繘琛屽垵濮嬪寲 if (ret != LOS_OK) { ret = LOS_ERRNO_PERF_BUF_ERROR; goto PERF_INIT_ERROR; } g_perfCb.status = PERF_STOPED; PERF_INIT_ERROR: - PERF_UNLOCK(intSave); + PERF_UNLOCK(intSave);//瑙i攣涓柇澶勭悊 return ret; } -UINT32 LOS_PerfConfig(PerfConfigAttr *attr) +UINT32 LOS_PerfConfig(PerfConfigAttr *attr)//閰嶇疆鎬ц兘缁熻妯″潡鐨勫睘鎬 { UINT32 ret; UINT32 intSave; @@ -355,20 +360,20 @@ UINT32 LOS_PerfConfig(PerfConfigAttr *attr) return LOS_ERRNO_PERF_CONFIG_NULL; } - PERF_LOCK(intSave); + PERF_LOCK(intSave);//淇濆瓨涓柇鐘舵 if (g_perfCb.status != PERF_STOPED) { ret = LOS_ERRNO_PERF_STATUS_INVALID; PRINT_ERR("perf config status error : 0x%x\n", g_perfCb.status); goto PERF_CONFIG_ERROR; } - g_pmu = NULL; + g_pmu = NULL;//灏嗗叏灞鏍囬噺PMU璁℃暟鍣ㄧ疆闆 g_perfCb.needSample = attr->needSample; g_perfCb.taskFilterEnable = attr->taskFilterEnable; g_perfCb.sampleType = attr->sampleType; - if (attr->taskFilterEnable) { + if (attr->taskFilterEnable) {//寮鍚换鍔¤繃婊ゅ姛鑳 ret = memcpy_s(g_perfCb.taskIds, PERF_MAX_FILTER_TSKS * sizeof(UINT32), attr->taskIds, g_perfCb.taskIdsNr * sizeof(UINT32)); if (ret != EOK) { @@ -377,29 +382,29 @@ UINT32 LOS_PerfConfig(PerfConfigAttr *attr) } g_perfCb.taskIdsNr = MIN(attr->taskIdsNr, PERF_MAX_FILTER_TSKS); } - ret = OsPerfConfig(&attr->eventsCfg); + ret = OsPerfConfig(&attr->eventsCfg);//瀵逛簨浠堕厤缃繘琛屽鐞 PERF_CONFIG_ERROR: PERF_UNLOCK(intSave); return ret; } -VOID LOS_PerfStart(UINT32 sectionId) +VOID LOS_PerfStart(UINT32 sectionId)//鍚姩鎬ц兘缁熻妯″潡 { UINT32 intSave; UINT32 ret; PERF_LOCK(intSave); - if (g_perfCb.status != PERF_STOPED) { + if (g_perfCb.status != PERF_STOPED) {//鍒ゆ柇缁熻妯″潡鏄惁鎵撳紑 PRINT_ERR("perf start status error : 0x%x\n", g_perfCb.status); goto PERF_START_ERROR; } - if (!OsPerfParamValid()) { + if (!OsPerfParamValid()) {//妫杞﹁鍛釜缁熻妯″潡鐨勫弬鏁版槸鍚︽湁鏁 PRINT_ERR("forgot call `LOS_Config(...)` before instrumenting?\n"); goto PERF_START_ERROR; } - if (g_perfCb.needSample) { + if (g_perfCb.needSample) {//鍒ゆ柇鏄惁闇瑕佹娊鏍 ret = OsPerfHdrInit(sectionId); /* section header init */ if (ret != LOS_OK) { PRINT_ERR("perf hdr init error 0x%x\n", ret); @@ -407,7 +412,7 @@ VOID LOS_PerfStart(UINT32 sectionId) } } - SMP_CALL_PERF_FUNC(OsPerfStart); /* send to all cpu to start pmu */ + SMP_CALL_PERF_FUNC(OsPerfStart); /* 鎵鏈塁PU寮濮婸MU璁℃暟鍣紝鍚姩鎬ц兘缁熻妯″潡i濂 */ g_perfCb.status = PERF_STARTED; g_perfCb.startTime = OsPerfGetCurrTime(); PERF_START_ERROR: @@ -415,7 +420,7 @@ PERF_START_ERROR: return; } -VOID LOS_PerfStop(VOID) +VOID LOS_PerfStop(VOID)//鍋滄鎬ц兘缁熻妯″潡鐨勮繍琛岋紝杩涜涓浜涙竻鐞嗘搷浣 { UINT32 intSave; @@ -427,12 +432,12 @@ VOID LOS_PerfStop(VOID) SMP_CALL_PERF_FUNC(OsPerfStop); /* send to all cpu to stop pmu */ - OsPerfOutPutFlush(); + OsPerfOutPutFlush();//鍒锋柊杈撳嚭鎿嶄綔 if (g_perfCb.needSample) { OsPerfOutPutInfo(); } - + //鏇存柊浜嗕袱涓叏灞鍙橀噺鐨勫硷紝琛ㄧず鎬ц兘缁熻妯″潡宸茬粡鍦ㄧ姸鎬佷笂鍜屾椂闂翠笂鍋滄浜 g_perfCb.status = PERF_STOPED; g_perfCb.endTime = OsPerfGetCurrTime(); @@ -442,21 +447,21 @@ PERF_STOP_ERROR: return; } -UINT32 LOS_PerfDataRead(CHAR *dest, UINT32 size) +UINT32 LOS_PerfDataRead(CHAR *dest, UINT32 size)//浠庢ц兘缁熻闂ㄧエ蹇殑杈撳嚭缂撳啿鍖轰腑璇诲彇鏁版嵁鍒版寚瀹氱殑鍐呭瓨 { return OsPerfOutPutRead(dest, size); } -VOID LOS_PerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func) +VOID LOS_PerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func)//娉ㄥ唽鍨嬮偅涓粺璁℃ā鍧楃殑閫氱煡hook鍑芥暟 { UINT32 intSave; - + //淇濆瓨涓柇鐘舵侊紝鎭㈠涓柇鐘舵 PERF_LOCK(intSave); OsPerfNotifyHookReg(func); PERF_UNLOCK(intSave); } -VOID LOS_PerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func) +VOID LOS_PerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)//鍒锋柊hook { UINT32 intSave; @@ -465,7 +470,7 @@ VOID LOS_PerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func) PERF_UNLOCK(intSave); } -VOID OsPerfSetIrqRegs(UINTPTR pc, UINTPTR fp) +VOID OsPerfSetIrqRegs(UINTPTR pc, UINTPTR fp)//璁剧疆涓柇鐩稿叧鐨勫瘎瀛樺櫒锛岀敤浜庝腑鏂椂鐨勬ц兘缁熻 { LosTaskCB *runTask = (LosTaskCB *)ArchCurrTaskGet(); runTask->pc = pc; diff --git a/src/kernel/extended/perf/perf_output.c b/src/kernel/extended/perf/perf_output.c index 20bea3a..a83d806 100644 --- a/src/kernel/extended/perf/perf_output.c +++ b/src/kernel/extended/perf/perf_output.c @@ -39,11 +39,14 @@ STATIC PERF_BUF_FLUSH_HOOK g_perfBufFlushHook = NULL; STATIC PerfOutputCB g_perfOutputCb; STATIC VOID OsPerfDefaultNotify(VOID) +//榛樿鐨勬ц兘缂撳啿鍖洪氱煡鍥炶皟鍑芥暟锛屽湪鎬ц兘缂撳啿鍖虹殑姘翠綅绾胯揪鍒颁竴瀹氬兼椂鎵撳嵃涓鏉′俊鎭 { PRINT_INFO("perf buf waterline notify!\n"); } UINT32 OsPerfOutPutInit(VOID *buf, UINT32 size) +//鍒濆鍖栨ц兘杈撳嚭妯″潡銆傚鏋滀紶鍏ョ殑缂撳啿鍖烘寚閽堜负绌猴紝鍒欎娇鐢↙OS_MemAlloc鍑芥暟鍔ㄦ佸垎閰嶅唴瀛樸 +//鐒跺悗鍒濆鍖栫幆褰㈢紦鍐插尯锛岃缃按浣嶇嚎锛屽苟娉ㄥ唽榛樿鐨勬ц兘缂撳啿鍖洪氱煡鍥炶皟鍑芥暟 { UINT32 ret; BOOL releaseFlag = FALSE; @@ -69,21 +72,22 @@ RELEASE: return ret; } -VOID OsPerfOutPutFlush(VOID) +VOID OsPerfOutPutFlush(VOID)//鍒锋柊鎬ц兘杈撳嚭缂撳啿鍖 { if (g_perfBufFlushHook != NULL) { g_perfBufFlushHook(g_perfOutputCb.ringbuf.fifo, g_perfOutputCb.ringbuf.size); } } -UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size) +UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size)//浠庢ц兘杈撳嚭缂撳啿鍖轰腑璇诲彇鏁版嵁 { OsPerfOutPutFlush(); return LOS_RingbufRead(&g_perfOutputCb.ringbuf, dest, size); } -STATIC BOOL OsPerfOutPutBegin(UINT32 size) +STATIC BOOL OsPerfOutPutBegin(UINT32 size)//寮濮嬪啓鍏ユц兘杈撳嚭缂撳啿鍖 { + //妫鏌ユ槸鍚︽湁瓒冲绌洪棿 if (g_perfOutputCb.ringbuf.remain < size) { PRINT_INFO("perf buf has no enough space for 0x%x\n", size); return FALSE; @@ -91,9 +95,9 @@ STATIC BOOL OsPerfOutPutBegin(UINT32 size) return TRUE; } -STATIC VOID OsPerfOutPutEnd(VOID) +STATIC VOID OsPerfOutPutEnd(VOID)//缁撴潫鎬ц兘杈撳嚭 { - OsPerfOutPutFlush(); + OsPerfOutPutFlush();//鍒锋柊缂撳啿鍖 if (LOS_RingbufUsedSize(&g_perfOutputCb.ringbuf) >= g_perfOutputCb.waterMark) { if (g_perfBufNotifyHook != NULL) { g_perfBufNotifyHook(); @@ -101,7 +105,7 @@ STATIC VOID OsPerfOutPutEnd(VOID) } } -UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size) +UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size)//灏嗘暟鎹啓鍏ユц兘杈撳叆缂撳啿鍖 { if (!OsPerfOutPutBegin(size)) { return LOS_NOK; @@ -113,17 +117,17 @@ UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size) return LOS_OK; } -VOID OsPerfOutPutInfo(VOID) +VOID OsPerfOutPutInfo(VOID)//鎵撳嵃鎬ц兘杈撳嚭缂撳啿鍖虹殑淇℃伅锛屽寘鎷湴鍧鍜岄暱搴 { PRINT_EMG("dump section data, addr: %p length: %#x \r\n", g_perfOutputCb.ringbuf.fifo, g_perfOutputCb.ringbuf.size); } -VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func) +VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func)//娉ㄥ唽鎬ц兘缂撳啿鍖洪氱煡 { g_perfBufNotifyHook = func; } -VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func) +VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)//娉ㄥ唽鎬ц兘缂撳啿鍖哄埛鏂扮殑鍑芥暟 { g_perfBufFlushHook = func; } diff --git a/src/kernel/extended/perf/perf_output_pri.h b/src/kernel/extended/perf/perf_output_pri.h index 382f2a9..603e64d 100644 --- a/src/kernel/extended/perf/perf_output_pri.h +++ b/src/kernel/extended/perf/perf_output_pri.h @@ -43,13 +43,13 @@ typedef struct { UINT32 waterMark; /* notify water mark */ } PerfOutputCB; -extern UINT32 OsPerfOutPutInit(VOID *buf, UINT32 size); -extern UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size); -extern UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size); -extern VOID OsPerfOutPutInfo(VOID); -extern VOID OsPerfOutPutFlush(VOID); -extern VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func); -extern VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func); +extern UINT32 OsPerfOutPutInit(VOID *buf, UINT32 size);//鍒濆鍖栨ц兘杈撳嚭妯″潡 +extern UINT32 OsPerfOutPutRead(CHAR *dest, UINT32 size);//浠庢ц兘杈撳嚭缂撳啿鍖轰腑璇诲彇鏁版嵁锛屽皢鏁版嵁鎷疯礉鍒版寚瀹氱殑鐩爣缂撳啿鍖轰腑 +extern UINT32 OsPerfOutPutWrite(CHAR *data, UINT32 size);//灏嗘暟鎹啓鍏ユц兘杈撳嚭缂撳啿鍖 +extern VOID OsPerfOutPutInfo(VOID);//杈撳嚭鎬ц兘缁熻淇℃伅 +extern VOID OsPerfOutPutFlush(VOID);//鍒锋柊鎬ц兘杈撳嚭缂撳啿鍖 +extern VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func);//娉ㄥ唽鎬ц兘杈撳嚭缂撳啿鍖洪氱煡 +extern VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func);//娉ㄥ唽鎬ц兘杈撳嚭缂撳啿鍖哄埛鏂 #ifdef __cplusplus #if __cplusplus diff --git a/src/kernel/extended/perf/perf_pmu.c b/src/kernel/extended/perf/perf_pmu.c index a2771ba..ff5cca6 100644 --- a/src/kernel/extended/perf/perf_pmu.c +++ b/src/kernel/extended/perf/perf_pmu.c @@ -36,11 +36,11 @@ extern "C" { STATIC Pmu *g_pmuMgr[PERF_EVENT_TYPE_MAX] = {NULL}; -UINT32 OsPerfPmuRegister(Pmu *pmu) +UINT32 OsPerfPmuRegister(Pmu *pmu)//娉ㄥ唽鎬ц兘璁℃暟鍣 { UINT32 type; - if ((pmu == NULL) || (pmu->type >= PERF_EVENT_TYPE_MAX)) { + if ((pmu == NULL) || (pmu->type >= PERF_EVENT_TYPE_MAX)) {//濡傛灉浼犲叆PMU涓虹┖鎸囬拡鎴栬卼ype瓒呭嚭浜嗘湁鏁堣寖鍥 return LOS_NOK; } @@ -52,19 +52,20 @@ UINT32 OsPerfPmuRegister(Pmu *pmu) return LOS_NOK; } -Pmu *OsPerfPmuGet(UINT32 type) +Pmu *OsPerfPmuGet(UINT32 type)//鑾峰彇鎸囧畾绫诲瀷鐨勬ц兘璁℃暟鍣 { if (type >= PERF_EVENT_TYPE_MAX) { return NULL; } - if (type == PERF_EVENT_TYPE_RAW) { /* process hardware raw events with hard pmu */ - type = PERF_EVENT_TYPE_HW; + if (type == PERF_EVENT_TYPE_RAW) { //濡傛灉鏄師濮嬩簨浠剁被鍨 + /* process hardware raw events with hard pmu */ + type = PERF_EVENT_TYPE_HW;//鍒欏皢鍏惰浆鍖栦负纭欢浜嬩欢绫诲瀷 } return g_pmuMgr[type]; } -VOID OsPerfPmuRm(UINT32 type) +VOID OsPerfPmuRm(UINT32 type)//鍒犻櫎鎸囧畾绫诲瀷鐨勬ц兘璁℃暟鍣 { if (type >= PERF_EVENT_TYPE_MAX) { return; diff --git a/src/kernel/extended/perf/perf_pmu_pri.h b/src/kernel/extended/perf/perf_pmu_pri.h index 2507d34..4cbb5bd 100644 --- a/src/kernel/extended/perf/perf_pmu_pri.h +++ b/src/kernel/extended/perf/perf_pmu_pri.h @@ -53,7 +53,7 @@ typedef struct { VOID (*setPeriod)(Event *event); UINTPTR (*readCnt)(Event *event); UINT32 (*mapEvent)(UINT32 eventType, BOOL reverse); -} HwPmu; +} HwPmu;//纭欢鎬ц兘璁℃暟鍣ㄧ粨鏋勪綋锛屽寘鎷‖浠惰鏁板櫒銆佽鏁板櫒鏄惁鑳借鍒嗛銆佸垎棰戠郴鏁般佸惎鐢ㄣ佺鐢ㄣ佸紑濮嬨佸仠姝€佹竻闄ゃ佽缃懆鏈熴佽鍙栬鏁板櫒鍊煎拰浜嬩欢鏄犲皠绛夊嚱鏁版寚閽 typedef struct { Pmu pmu; @@ -69,35 +69,35 @@ typedef struct { }; #endif }; -} SwPmu; +} SwPmu;//杞欢鎬ц兘璁℃暟鍣ㄧ粨鏋勪綋锛屽寘鎷蒋浠惰鏁板櫒銆佹槸鍚﹀惎鐢ㄦ爣蹇椾綅銆佸畾鏃跺櫒閰嶇疆鏃堕棿 #define GET_HW_PMU(item) LOS_DL_LIST_ENTRY(item, HwPmu, pmu) -#define TIMER_PERIOD_LOWER_BOUND_US 100 +#define TIMER_PERIOD_LOWER_BOUND_US 100//瀹氭椂鍣ㄦ渶灏忓懆鏈 -#define CCNT_FULL 0xFFFFFFFF -#define CCNT_PERIOD_LOWER_BOUND 0x00000000 -#define CCNT_PERIOD_UPPER_BOUND 0xFFFFFF00 -#define PERIOD_CALC(p) (CCNT_FULL - (p)) +#define CCNT_FULL 0xFFFFFFFF//璁℃暟鍣ㄦ渶澶у +#define CCNT_PERIOD_LOWER_BOUND 0x00000000//鏈灏忓懆鏈 +#define CCNT_PERIOD_UPPER_BOUND 0xFFFFFF00//鏈澶у懆鏈 +#define PERIOD_CALC(p) (CCNT_FULL - (p))//璁$畻缁欏畾鍛ㄦ湡瀵瑰簲鐨勮鏁板櫒鍊 #define VALID_PERIOD(p) ((PERIOD_CALC(p) > CCNT_PERIOD_LOWER_BOUND) \ - && (PERIOD_CALC(p) < CCNT_PERIOD_UPPER_BOUND)) + && (PERIOD_CALC(p) < CCNT_PERIOD_UPPER_BOUND))//鍒ゆ柇缁欏畾鍛ㄦ湡鏄惁鍚堟硶 -#define PERF_HW_INVAILD_EVENT_TYPE 0xFFFFFFFF +#define PERF_HW_INVAILD_EVENT_TYPE 0xFFFFFFFF//鏃犳晥鐨勪簨浠剁被鍨 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) -extern UINT32 OsPerfPmuRegister(Pmu *pmu); -extern VOID OsPerfPmuRm(UINT32 type); -extern Pmu *OsPerfPmuGet(UINT32 type); +extern UINT32 OsPerfPmuRegister(Pmu *pmu);//娉ㄥ唽纭欢鎬ц兘璁℃暟鍣 +extern VOID OsPerfPmuRm(UINT32 type);//鍒犻櫎纭欢鎬ц兘璁℃暟鍣 +extern Pmu *OsPerfPmuGet(UINT32 type);//鑾峰彇鎸囧畾绫诲瀷鐨勭‖浠舵ц兘璁℃暟鍣 -extern UINT32 OsHwPmuInit(VOID); -extern UINT32 OsSwPmuInit(VOID); -extern UINT32 OsTimedPmuInit(VOID); +extern UINT32 OsHwPmuInit(VOID);//鍒濆鍖栫‖浠舵ц兘璁℃暟鍣 +extern UINT32 OsSwPmuInit(VOID);//鍒濆鍖栬蒋浠舵ц兘璁℃暟鍣 +extern UINT32 OsTimedPmuInit(VOID);//鍒濆鍖栧畾鏃跺櫒鎬ц兘璁℃暟鍣 -extern UINT32 OsGetPmuCounter0(VOID); -extern UINT32 OsGetPmuMaxCounter(VOID); -extern UINT32 OsGetPmuCycleCounter(VOID); -extern UINT32 OsPerfHwInit(HwPmu *hwPmu); +extern UINT32 OsGetPmuCounter0(VOID);//鑾峰彇0鏍歌鏁板櫒鍊 +extern UINT32 OsGetPmuMaxCounter(VOID);//鑾峰彇鏈澶ц鏁板櫒鏁 +extern UINT32 OsGetPmuCycleCounter(VOID);//鑾峰彇鍛ㄦ湡鎬ц鏁板櫒鍊 +extern UINT32 OsPerfHwInit(HwPmu *hwPmu);//鍒濆鍖栫‖浠舵ц兘璁℃暟鍣 #ifdef __cplusplus #if __cplusplus diff --git a/src/kernel/extended/perf/pmu/perf_hw_pmu.c b/src/kernel/extended/perf/pmu/perf_hw_pmu.c index ca0b797..f76869d 100644 --- a/src/kernel/extended/perf/pmu/perf_hw_pmu.c +++ b/src/kernel/extended/perf/pmu/perf_hw_pmu.c @@ -34,7 +34,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -STATIC Pmu *g_perfHw = NULL; +STATIC Pmu *g_perfHw = NULL;//鎸囧悜鎬ц兘璁℃暟鍣ㄧ浉鍏崇殑鏁版嵁缁撴瀯鎴栧璞 STATIC CHAR *g_eventName[PERF_COUNT_HW_MAX] = { [PERF_COUNT_HW_CPU_CYCLES] = "cycles", @@ -53,39 +53,41 @@ STATIC CHAR *g_eventName[PERF_COUNT_HW_MAX] = { * 2.Find available counter for each event. * 3.Decide whether this hardware pmu need prescaler (once every 64 cycle counts). */ -STATIC UINT32 OsPerfHwConfig(VOID) +STATIC UINT32 OsPerfHwConfig(VOID)//鎬ц兘璁℃暟鍣ㄧ殑閰嶇疆鍑芥暟锛岀敤浜庡垵濮嬪寲鍜岄厤缃‖浠舵ц兘璁℃暟鍣 { UINT32 i; HwPmu *armPmu = GET_HW_PMU(g_perfHw); - UINT32 maxCounter = OsGetPmuMaxCounter(); - UINT32 counter = OsGetPmuCounter0(); - UINT32 cycleCounter = OsGetPmuCycleCounter(); + UINT32 maxCounter = OsGetPmuMaxCounter();//鑾峰緱鏈澶ц鏁板櫒鏁伴噺 + UINT32 counter = OsGetPmuCounter0();//鑾峰彇0鏍歌鏁板櫒鐨勫 + UINT32 cycleCounter = OsGetPmuCycleCounter();//鍛ㄦ湡璁℃暟鍣ㄧ殑鍊 UINT32 cycleCode = armPmu->mapEvent(PERF_COUNT_HW_CPU_CYCLES, PERF_EVENT_TO_CODE); if (cycleCode == PERF_HW_INVAILD_EVENT_TYPE) { return LOS_NOK; } - + //鑾峰彇鎬ц兘浜嬩欢鐨勫垪琛ㄧ殑鍜屾暟閲忓苟杩涜閬嶅巻 PerfEvent *events = &g_perfHw->events; UINT32 eventNum = events->nr; for (i = 0; i < eventNum; i++) { Event *event = &(events->per[i]); - if (!VALID_PERIOD(event->period)) { + if (!VALID_PERIOD(event->period)) {//妫鏌ヤ簨浠跺懆鏈熸槸鍚﹀悎娉 PRINT_ERR("Config period: 0x%x invalid, should be in (%#x, %#x)\n", event->period, PERIOD_CALC(CCNT_PERIOD_UPPER_BOUND), PERIOD_CALC(CCNT_PERIOD_LOWER_BOUND)); return LOS_NOK; } if (g_perfHw->type == PERF_EVENT_TYPE_HW) { /* do map */ + //鏄犲皠缂栫爜 UINT32 eventId = armPmu->mapEvent(event->eventId, PERF_EVENT_TO_CODE); if (eventId == PERF_HW_INVAILD_EVENT_TYPE) { return LOS_NOK; } event->eventId = eventId; } - + //鍑芥暟鏍规嵁浜嬩欢缂栫爜鏄惁涓庡懆鏈熻鏁板櫒鐨勪簨浠剁紪鐮佺浉鍚岋紝鏉ョ‘瀹氳浜嬩欢浣跨敤鐨勮鏁板櫒銆 + //濡傛灉鐩稿悓锛屽垯浣跨敤鍛ㄦ湡璁℃暟鍣紱鍚﹀垯锛屼娇鐢ㄦ櫘閫氳鏁板櫒锛屽苟閫掑璁℃暟鍣ㄧ殑鍊笺 if (event->eventId == cycleCode) { event->counter = cycleCounter; } else { @@ -93,11 +95,11 @@ STATIC UINT32 OsPerfHwConfig(VOID) counter++; } - if (counter >= maxCounter) { + if (counter >= maxCounter) {//妫鏌ヨ鏁板櫒鏄惁瓒呰繃浜嗘渶澶ц鏁板櫒鏁伴噺 PRINT_ERR("max events: %u excluding cycle event\n", maxCounter - 1); return LOS_NOK; } - + //鎵撳嵃缁撴灉锛岃缃牴鎹钩鍙版敮鎸佺殑鍒嗛 PRINT_DEBUG("Perf Config %u eventId = 0x%x, counter = 0x%x, period = 0x%x\n", i, event->eventId, event->counter, event->period); } @@ -106,21 +108,21 @@ STATIC UINT32 OsPerfHwConfig(VOID) return LOS_OK; } -STATIC UINT32 OsPerfHwStart(VOID) +STATIC UINT32 OsPerfHwStart(VOID)//鐢ㄤ簬鍚姩纭欢鎬ц兘璁℃暟鍣 { UINT32 i; UINT32 cpuid = ArchCurrCpuid(); - HwPmu *armPmu = GET_HW_PMU(g_perfHw); + HwPmu *armPmu = GET_HW_PMU(g_perfHw);//鑾峰彇纭欢鎬ц兘璁℃暟鍣ㄧ殑鎸囬拡 PerfEvent *events = &g_perfHw->events; UINT32 eventNum = events->nr; - armPmu->clear(); + armPmu->clear();//娓呴浂璁℃暟鍣 for (i = 0; i < eventNum; i++) { Event *event = &(events->per[i]); - armPmu->setPeriod(event); - armPmu->enable(event); + armPmu->setPeriod(event);//璁剧疆浜嬩欢鐨勮鏁板懆鏈 + armPmu->enable(event);//鍚敤浜嬩欢鐨勮鏁板櫒 event->count[cpuid] = 0; } @@ -128,7 +130,7 @@ STATIC UINT32 OsPerfHwStart(VOID) return LOS_OK; } -STATIC UINT32 OsPerfHwStop(VOID) +STATIC UINT32 OsPerfHwStop(VOID)//鍋滄纭欢鎬ц兘璁℃暟鍣 { UINT32 i; UINT32 cpuid = ArchCurrCpuid(); @@ -148,7 +150,9 @@ STATIC UINT32 OsPerfHwStop(VOID) /* multiplier of cycle counter */ UINT32 eventId = armPmu->mapEvent(event->eventId, PERF_CODE_TO_EVENT); if ((eventId == PERF_COUNT_HW_CPU_CYCLES) && (armPmu->cntDivided != 0)) { + //濡傛灉璇ヤ簨浠剁殑浜嬩欢ID涓庡懆鏈熻鏁板櫒浜嬩欢ID鐩稿悓锛屽苟涓旂‖浠舵ц兘璁℃暟鍣ㄧ殑鍒嗛璁剧疆armPmu->cntDivided涓嶄负0 PRINT_DEBUG("perf stop is cycle\n"); + //姝ゅ灏嗚浜嬩欢鐨勮鏁板煎乏绉6浣嶏紝鐩稿綋浜庝箻浠64 event->count[cpuid] = event->count[cpuid] << 6; /* CCNT counts every 64th cpu cycle */ } PRINT_DEBUG("perf stop eventCount[0x%x] : [%s] = %llu\n", event->eventId, g_eventName[eventId], @@ -157,11 +161,11 @@ STATIC UINT32 OsPerfHwStop(VOID) return LOS_OK; } -STATIC CHAR *OsPerfGetEventName(Event *event) +STATIC CHAR *OsPerfGetEventName(Event *event)//鑾峰彇浜嬩欢鍚嶇О { UINT32 eventId; - HwPmu *armPmu = GET_HW_PMU(g_perfHw); - eventId = armPmu->mapEvent(event->eventId, PERF_CODE_TO_EVENT); + HwPmu *armPmu = GET_HW_PMU(g_perfHw);//鑾峰彇PMU涓婄殑浜嬩欢淇℃伅 + eventId = armPmu->mapEvent(event->eventId, PERF_CODE_TO_EVENT);//灏嗕簨浠禝D鏄犲皠浣嶅搴旇鏁板櫒浜嬩欢ID if (eventId < PERF_COUNT_HW_MAX) { return g_eventName[eventId]; } else { @@ -169,21 +173,21 @@ STATIC CHAR *OsPerfGetEventName(Event *event) } } -UINT32 OsPerfHwInit(HwPmu *hwPmu) +UINT32 OsPerfHwInit(HwPmu *hwPmu)//鍒濆鍖栨ц兘璁℃暟鍣 { UINT32 ret; if (hwPmu == NULL) { return LOS_NOK; } - + //璁剧疆鎬ц兘璁℃暟鍣ㄧ殑绫诲瀷锛岄厤缃嚱鏁帮紝鍚姩鍑芥暟锛屽仠姝㈠嚱鏁帮紝鑾峰彇浜嬩欢鍚嶇О鍑芥暟 hwPmu->pmu.type = PERF_EVENT_TYPE_HW; hwPmu->pmu.config = OsPerfHwConfig; hwPmu->pmu.start = OsPerfHwStart; hwPmu->pmu.stop = OsPerfHwStop; hwPmu->pmu.getName = OsPerfGetEventName; - + //灏嗙‖浠舵ц兘璁℃暟鍣ㄧ殑浜嬩欢鏁版嵁缁撴瀯娓呴浂 (VOID)memset_s(&hwPmu->pmu.events, sizeof(PerfEvent), 0, sizeof(PerfEvent)); - ret = OsPerfPmuRegister(&hwPmu->pmu); + ret = OsPerfPmuRegister(&hwPmu->pmu);//娉ㄥ唽纭欢鎬ц兘璁℃暟鍣紝灏嗗叾瀛樺偍鍦ㄥ叏灞鍙橀噺涓 g_perfHw = OsPerfPmuGet(PERF_EVENT_TYPE_HW); return ret; diff --git a/src/kernel/extended/perf/pmu/perf_sw_pmu.c b/src/kernel/extended/perf/pmu/perf_sw_pmu.c index 5ea7e52..fe6f251 100644 --- a/src/kernel/extended/perf/pmu/perf_sw_pmu.c +++ b/src/kernel/extended/perf/pmu/perf_sw_pmu.c @@ -51,7 +51,7 @@ STATIC CHAR* g_eventName[PERF_COUNT_SW_MAX] = { [PERF_COUNT_SW_MUX_PEND] = "mux pend", }; -VOID OsPerfHook(UINT32 eventType) +VOID OsPerfHook(UINT32 eventType)//杞欢鎬ц兘璁℃暟鍣ㄧ殑浜嬩欢澶勭悊鍑芥暟 { if (!g_perfSw.enable) { return; @@ -69,7 +69,7 @@ VOID OsPerfHook(UINT32 eventType) if (event->counter == eventType) { OsPerfUpdateEventCount(event, 1); if (event->count[ArchCurrCpuid()] % event->period == 0) { - OsPerfFetchCallerRegs(®s); + OsPerfFetchCallerRegs(®s);//鑾峰彇瀵勫瓨鍣ㄤ俊鎭 OsPerfHandleOverFlow(event, ®s); } return; @@ -77,7 +77,7 @@ VOID OsPerfHook(UINT32 eventType) } } -STATIC UINT32 OsPerfSwConfig(VOID) +STATIC UINT32 OsPerfSwConfig(VOID)//瀵硅蒋浠舵ц兘璁℃暟鍣ㄨ繘琛岄厤缃 { UINT32 i; PerfEvent *events = &g_perfSw.pmu.events; @@ -94,29 +94,29 @@ STATIC UINT32 OsPerfSwConfig(VOID) return LOS_OK; } -STATIC UINT32 OsPerfSwStart(VOID) +STATIC UINT32 OsPerfSwStart(VOID)//鍚姩杞欢鎬ц兘璁℃暟鍣 { UINT32 i; UINT32 cpuid = ArchCurrCpuid(); PerfEvent *events = &g_perfSw.pmu.events; UINT32 eventNum = events->nr; - for (i = 0; i < eventNum; i++) { + for (i = 0; i < eventNum; i++) {//閬嶅巻鎵鏈変簨浠 Event *event = &(events->per[i]); - event->count[cpuid] = 0; + event->count[cpuid] = 0;//娓呴浂褰撳墠浜嬩欢鍦–PU涓殑璁℃暟鍣 } - g_perfSw.enable = TRUE; + g_perfSw.enable = TRUE;//鍚姩璁℃暟鍣 return LOS_OK; } -STATIC UINT32 OsPerfSwStop(VOID) +STATIC UINT32 OsPerfSwStop(VOID)//鍏抽棴杞欢鎬ц兘璁℃暟鍣 { g_perfSw.enable = FALSE; return LOS_OK; } -STATIC CHAR *OsPerfGetEventName(Event *event) +STATIC CHAR *OsPerfGetEventName(Event *event)//鑾峰彇浜嬩欢鐨勫悕绉 { UINT32 eventId = event->eventId; if (eventId < PERF_COUNT_SW_MAX) { @@ -125,7 +125,7 @@ STATIC CHAR *OsPerfGetEventName(Event *event) return "unknown"; } -UINT32 OsSwPmuInit(VOID) +UINT32 OsSwPmuInit(VOID)//瀵筆MU璁℃暟鍣ㄨ繘琛屽垵濮嬪寲 { g_perfSw.pmu = (Pmu) { .type = PERF_EVENT_TYPE_SW, diff --git a/src/kernel/extended/perf/pmu/perf_timed_pmu.c b/src/kernel/extended/perf/pmu/perf_timed_pmu.c index 4659c08..6080f90 100644 --- a/src/kernel/extended/perf/pmu/perf_timed_pmu.c +++ b/src/kernel/extended/perf/pmu/perf_timed_pmu.c @@ -39,12 +39,12 @@ extern "C" { STATIC SwPmu g_perfTimed; -STATIC BOOL OsPerfTimedPeriodValid(UINT32 period) +STATIC BOOL OsPerfTimedPeriodValid(UINT32 period)//楠岃瘉瀹氭椂鍣ㄤ腑鐨勬椂闂村懆鏈熸槸鍚﹀悎娉 { return period >= TIMER_PERIOD_LOWER_BOUND_US; } -STATIC UINT32 OsPerfTimedStart(VOID) +STATIC UINT32 OsPerfTimedStart(VOID)//鍚姩瀹氭椂鍣ㄤ簨浠 { UINT32 i; UINT32 cpuid = ArchCurrCpuid(); @@ -74,7 +74,7 @@ STATIC UINT32 OsPerfTimedStart(VOID) return LOS_OK; } -STATIC UINT32 OsPerfTimedConfig(VOID) +STATIC UINT32 OsPerfTimedConfig(VOID)//閰嶇疆瀹氭椂鍣紝妫楠屾槸鍚﹀悎娉 { UINT32 i; PerfEvent *events = &g_perfTimed.pmu.events; @@ -101,7 +101,7 @@ STATIC UINT32 OsPerfTimedConfig(VOID) return LOS_NOK; } -STATIC UINT32 OsPerfTimedStop(VOID) +STATIC UINT32 OsPerfTimedStop(VOID)//鍏抽棴瀹氭椂鍣ㄨ缃 { UINT32 ret; if (ArchCurrCpuid() != 0) { /* only need stop on one core */ @@ -116,7 +116,7 @@ STATIC UINT32 OsPerfTimedStop(VOID) return LOS_OK; } -STATIC VOID OsPerfTimedHandle(VOID) +STATIC VOID OsPerfTimedHandle(VOID)//澶勭悊瀹氭椂鍣ㄤ簨浠 { UINT32 index; PerfRegs regs; @@ -125,7 +125,7 @@ STATIC VOID OsPerfTimedHandle(VOID) UINT32 eventNum = events->nr; (VOID)memset_s(®s, sizeof(PerfRegs), 0, sizeof(PerfRegs)); - OsPerfFetchIrqRegs(®s); + OsPerfFetchIrqRegs(®s);//鑾峰彇褰撳墠瀵勫瓨鍣ㄧ姸鎬 for (index = 0; index < eventNum; index++) { Event *event = &(events->per[index]); @@ -134,48 +134,50 @@ STATIC VOID OsPerfTimedHandle(VOID) } } -STATIC enum hrtimer_restart OsPerfHrtimer(struct hrtimer *hrtimer) +STATIC enum hrtimer_restart OsPerfHrtimer(struct hrtimer *hrtimer)//楂樼簿搴﹀畾鏃跺櫒(hrtimer)鐨勫洖璋冨嚱鏁 { SMP_CALL_PERF_FUNC(OsPerfTimedHandle); /* send to all cpu to collect data */ + //灏嗗畾鏃跺櫒浜嬩欢鐨勫鐞嗗彂閫佺粰鎵鏈塁PU杩涜鏁版嵁鏀堕泦 return HRTIMER_RESTART; } -STATIC CHAR *OsPerfGetEventName(Event *event) +STATIC CHAR *OsPerfGetEventName(Event *event)//鑾峰彇浜嬩欢鍚嶇О { - if (event->eventId == PERF_COUNT_CPU_CLOCK) { + if (event->eventId == PERF_COUNT_CPU_CLOCK) {//璇诲彇浜嬩欢ID鏄惁涓庤鏁板櫒涓殑浜嬩欢璁板綍鐩稿悓 return "timed"; } else { return "unknown"; } } -UINT32 OsTimedPmuInit(VOID) +UINT32 OsTimedPmuInit(VOID)//鍒濆鍖栧畾鏃跺櫒 { UINT32 ret; - g_perfTimed.time = (union ktime) { + g_perfTimed.time = (union ktime) {//淇濆瓨瀹氭椂鍣ㄤ俊鎭 .tv.sec = 0, .tv.usec = HRTIMER_DEFAULT_PERIOD_US, }; - hrtimer_init(&g_perfTimed.hrtimer, 1, HRTIMER_MODE_REL); + hrtimer_init(&g_perfTimed.hrtimer, 1, HRTIMER_MODE_REL);//绗竴涓弬鏁颁唬琛ㄥ畾鏃跺櫒瀵硅薄锛岀浜屼釜鍙傛暟涓烘椂闂存簮绫诲瀷锛屼唬琛ㄧ殑鏄浉瀵规椂闂达紝鏈鍚庝竴涓弬鏁颁唬琛ㄥ畾鏃跺櫒妯″紡锛岃繖閲屼娇鐢ㄧ殑鏄浉瀵规椂闂存ā寮 - ret = hrtimer_create(&g_perfTimed.hrtimer, g_perfTimed.time, OsPerfHrtimer); + ret = hrtimer_create(&g_perfTimed.hrtimer, g_perfTimed.time, OsPerfHrtimer);//鍒涘缓瀹氭椂鍣 if (ret != LOS_OK) { return ret; } g_perfTimed.pmu = (Pmu) { - .type = PERF_EVENT_TYPE_TIMED, - .config = OsPerfTimedConfig, - .start = OsPerfTimedStart, - .stop = OsPerfTimedStop, - .getName = OsPerfGetEventName, + .type = PERF_EVENT_TYPE_TIMED,//姝ゆц兘璁℃暟鍣ㄦ槸瀹氭椂鍣ㄧ被鍨 + .config = OsPerfTimedConfig,//鎬ц兘璁℃暟鍣ㄧ殑浜嬩欢閰嶇疆 + .start = OsPerfTimedStart,//鍚姩 + .stop = OsPerfTimedStop,//鍋滄 + .getName = OsPerfGetEventName,//鑾峰彇浜嬩欢鍚嶇О }; (VOID)memset_s(&g_perfTimed.pmu.events, sizeof(PerfEvent), 0, sizeof(PerfEvent)); + //鎵ц瀹屼箣鍚庢竻闆朵簨浠剁粨鏋勪綋锛屽苟鍦ㄤ笅闈㈣繘琛岀姸鎬佺爜鐨勬敞鍐岃鍙 ret = OsPerfPmuRegister(&g_perfTimed.pmu); - return ret; + return ret;//杩斿洖鍊间负鍒濆鍖栫姸鎬佺爜 } #ifdef __cplusplus diff --git a/src/kernel/extended/杞欢宸ョ▼浠g爜闃呰锛堝垵绋匡級-浣曚匠鑱-.docx b/src/kernel/extended/杞欢宸ョ▼浠g爜闃呰锛堝垵绋匡級-浣曚匠鑱-.docx new file mode 100644 index 0000000..4d112b6 Binary files /dev/null and b/src/kernel/extended/杞欢宸ョ▼浠g爜闃呰锛堝垵绋匡級-浣曚匠鑱-.docx differ diff --git a/src/kernel/include/arch_generic/atomic.h b/src/kernel/include/arch_generic/atomic.h index 2b68336..81dc858 100644 --- a/src/kernel/include/arch_generic/atomic.h +++ b/src/kernel/include/arch_generic/atomic.h @@ -31,6 +31,7 @@ * @ingroup kernel */ +//在LiteOS操作系统中,atomic.h头文件通常用于提供原子操作的支持。原子操作是不可中断的操作,它可以确保在多线程环境中对共享资源进行安全的访问和修改。 #ifndef _ARCH_GENERIC_ATOMIC_H #define _ARCH_GENERIC_ATOMIC_H @@ -44,17 +45,26 @@ extern "C" { #endif /* __cplusplus */ #ifndef LOSCFG_KERNEL_SMP - +/*ArchAtomicRead 函数用于原子读取一个整数变量的值。 +它将一个指向原子变量的指针 v 强制转换为 volatile INT32 类型的指针, +并返回该指针所指向的值。*/ STATIC INLINE INT32 ArchAtomicRead(const Atomic *v) { return *(volatile INT32 *)v; } +/*ArchAtomicSet 函数用于原子设置一个整数变量的值。 +它将一个指向原子变量的指针 v 强制转换为 volatile INT32 类型的指针, +并将 setVal 的值赋给该指针所指向的变量。*/ STATIC INLINE VOID ArchAtomicSet(Atomic *v, INT32 setVal) { *(volatile INT32 *)v = setVal; } +/*ArchAtomicAdd 函数用于原子增加一个整数变量的值。 +它先保存当前中断状态,然后在关闭中断的情况下,将 addVal 加到指针 v 所指向的变量上, +并返回增加后的值。 +最后,恢复之前保存的中断状态。*/ STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal) { UINT32 intSave; @@ -66,6 +76,9 @@ STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal) return *v; } +/*ArchAtomicSub 函数用于原子减少一个整数变量的值。 +它的实现与 ArchAtomicAdd 类似, +只是将 subVal 减去指针 v 所指向的变量。*/ STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal) { UINT32 intSave; @@ -77,6 +90,10 @@ STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal) return *v; } +/*ArchAtomicInc 函数用于原子增加一个整数变量的值。 +它首先保存当前中断状态 intSave,然后在关闭中断的情况下, +将指针 addr 指向的变量加 1, +最后恢复之前保存的中断状态。*/ STATIC INLINE VOID ArchAtomicInc(Atomic *addr) { UINT32 intSave; @@ -86,6 +103,7 @@ STATIC INLINE VOID ArchAtomicInc(Atomic *addr) LOS_IntRestore(intSave); } +//ArchAtomicIncRet 函数与 ArchAtomicInc 类似,但它还返回增加后的变量值。 STATIC INLINE INT32 ArchAtomicIncRet(Atomic *addr) { UINT32 intSave; @@ -96,6 +114,7 @@ STATIC INLINE INT32 ArchAtomicIncRet(Atomic *addr) return *addr; } +//ArchAtomicDec 函数用于原子减少一个整数变量的值。它的实现类似于 ArchAtomicInc,只是将指针 addr 指向的变量减 1。 STATIC INLINE VOID ArchAtomicDec(Atomic *addr) { UINT32 intSave; @@ -105,6 +124,7 @@ STATIC INLINE VOID ArchAtomicDec(Atomic *addr) LOS_IntRestore(intSave); } +//ArchAtomicDecRet 函数与 ArchAtomicDec 类似,但它还返回减少后的变量值。 STATIC INLINE INT32 ArchAtomicDecRet(Atomic *addr) { UINT32 intSave; @@ -115,6 +135,10 @@ STATIC INLINE INT32 ArchAtomicDecRet(Atomic *addr) return *addr; } +/*ArchAtomic64Read 函数用于原子读取一个 64 位整数变量的值。 +它首先保存当前中断状态 intSave,然后在关闭中断的情况下, +读取指针 v 指向的 64 位整数变量的值, +最后恢复之前保存的中断状态,并返回读取的值。*/ STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v) { UINT32 intSave; @@ -127,6 +151,10 @@ STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v) return val; } +/*ArchAtomic64Set 函数用于原子设置一个 64 位整数变量的值为 setVal。 +它首先保存当前中断状态 intSave,然后在关闭中断的情况下, +将指针 v 指向的变量设置为 setVal, +最后恢复之前保存的中断状态。*/ STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal) { UINT32 intSave; @@ -136,6 +164,10 @@ STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal) LOS_IntRestore(intSave); } +/*ArchAtomic64Add 函数用于原子增加一个 64 位整数变量的值。 +它首先保存当前中断状态 intSave,然后在关闭中断的情况下, +将指针 v 指向的变量增加 addVal,然后将增加后的值赋给变量 val, +最后恢复之前保存的中断状态,并返回 val。*/ STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal) { UINT32 intSave; @@ -149,6 +181,9 @@ STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal) return val; } +/*ArchAtomic64Sub 函数用于原子减少一个 64 位整数变量的值。 +它的实现类似于 ArchAtomic64Add, +只是将指针 v 指向的变量减去 subVal。*/ STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal) { UINT32 intSave; @@ -162,6 +197,8 @@ STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal) return val; } +/*ArchAtomic64Inc 函数用于原子增加一个 64 位整数变量的值。 +它的实现类似于 ArchAtomic64Add,只是将增加的值固定为 1。*/ STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v) { UINT32 intSave; @@ -171,6 +208,7 @@ STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v) LOS_IntRestore(intSave); } +//ArchAtomic64IncRet 函数与 ArchAtomic64Inc 类似,但它还返回增加后的变量值。 STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v) { UINT32 intSave; @@ -184,6 +222,9 @@ STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v) return val; } +/*ArchAtomic64Dec 函数用于原子减少一个 64 位整数变量的值。 +它首先保存当前中断状态 intSave,然后在关闭中断的情况下,将指针 v 指向的变量减去 1, +最后恢复之前保存的中断状态。*/ STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v) { UINT32 intSave; @@ -193,6 +234,7 @@ STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v) LOS_IntRestore(intSave); } +//ArchAtomic64DecRet 函数与 ArchAtomic64Dec 类似,但它还返回减少后的变量值。 STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v) { UINT32 intSave; @@ -206,6 +248,10 @@ STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v) return val; } +/*ArchAtomicXchg32bits 函数用于原子交换一个 32 位整数变量的值。 +它首先保存当前中断状态 intSave,然后在关闭中断的情况下, +将指针 v 指向的变量的值赋给 prevVal,再将变量 v 的值设置为 val, +最后恢复之前保存的中断状态,并返回原先的值 prevVal。*/ STATIC INLINE INT32 ArchAtomicXchg32bits(Atomic *v, INT32 val) { UINT32 intSave; @@ -219,6 +265,7 @@ STATIC INLINE INT32 ArchAtomicXchg32bits(Atomic *v, INT32 val) return prevVal; } +//ArchAtomicXchg64bits 函数类似于 ArchAtomicXchg32bits,但它用于原子交换一个 64 位整数变量的值。 STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val) { UINT32 intSave; @@ -232,6 +279,11 @@ STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val) return prevVal; } +/*ArchAtomicCmpXchg32bits 函数用于原子比较和交换一个 32 位整数变量的值。 +它首先保存当前中断状态 intSave,然后在关闭中断的情况下, +将指针 v 指向的变量的值赋给 prevVal,接着判断 prevVal 是否等于 oldVal, +如果相等,则将变量 v 的值设置为 val,最后恢复之前保存的中断状态, +并返回是否执行了交换操作的布尔值。*/ STATIC INLINE BOOL ArchAtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal) { UINT32 intSave; @@ -247,6 +299,7 @@ STATIC INLINE BOOL ArchAtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal) return (prevVal != oldVal); } +//ArchAtomicCmpXchg64bits 函数类似于 ArchAtomicCmpXchg32bits,但它用于原子比较和交换一个 64 位整数变量的值。 STATIC INLINE BOOL ArchAtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal) { UINT32 intSave; diff --git a/src/kernel/include/console.h b/src/kernel/include/console.h index a0f102a..e57aba9 100644 --- a/src/kernel/include/console.h +++ b/src/kernel/include/console.h @@ -25,18 +25,18 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ - +//在LiteOS操作系统中,console头文件通常用于定义与控制台交互相关的函数和数据结构。 #ifndef _CONSOLE_H #define _CONSOLE_H - -#include "los_config.h" -#ifdef LOSCFG_FS_VFS -#include "termios.h" -#ifdef LOSCFG_NET_TELNET -#include "telnet_dev.h" -#endif -#include "virtual_serial.h" -#include "los_ringbuf.h" +//代码中,首先使用了条件编译防护,以确保头文件内容只被包含一次。接着定义了控制台输入输出缓冲区的大小,并声明了控制台初始化、打印和读取等函数。 +#include "los_config.h"//引用了系统配置文件,用于获取操作系统的一些设置和属性。 +#ifdef LOSCFG_FS_VFS//使用条件编译指令判断是否定义了宏LOSCFG_FS_VFS,如果已经定义,则编译下面的代码块,否则跳过。 +#include "termios.h"//包含了 POSIX 终端控制定义的头文件,用于对终端进行控制。 +#ifdef LOSCFG_NET_TELNET//使用条件编译指令判断是否定义了宏,如果已经定义,则编译下面的代码块,否则跳过。 +#include "telnet_dev.h"//包含了 Telnet 设备驱动的头文件,用于实现 Telnet 连接。 +#endif//结束条件编译指令。 +#include "virtual_serial.h"//包含了虚拟串口的头文件,用于实现虚拟串口的功能。 +#include "los_ringbuf.h"//包含了环形缓冲区的头文件,用于实现缓冲区的读写操作。 #endif #ifdef __cplusplus @@ -57,76 +57,76 @@ extern "C" { #define CONSOLE "/dev/console" #define CONSOLE_NAMELEN 16 - -#define CONSOLE_CMD_RD_BLOCK_SERIAL 0x104 -#define CONSOLE_CMD_RD_BLOCK_TELNET 101 -#define CONSOLE_RD_BLOCK 1 -#define CONSOLE_RD_NONBLOCK 0 -#define CONSOLE_SHELL_KEY_EVENT 0x112 -#define CONSOLE_SHELL_EXITED 0x400 -#define CONSOLE_CONTROL_RIGHTS_CAPTURE 201 -#define CONSOLE_CONTROL_RIGHTS_RELEASE 202 -#define CONSOLE_CONTROL_CAPTURE_LINE 203 -#define CONSOLE_CONTROL_CAPTURE_CHAR 204 -#define CONSOLE_FIFO_SIZE 1024 -#define CONSOLE_NUM 2 +//这段代码定义了一些宏和常量,它们的含义如下: +#define CONSOLE_CMD_RD_BLOCK_SERIAL 0x104//表示从串口读取数据的阻塞命令,其值为0x104。 +#define CONSOLE_CMD_RD_BLOCK_TELNET 101//表示从Telnet连接读取数据的阻塞命令,其值为101。 +#define CONSOLE_RD_BLOCK 1//表示阻塞模式,其值为1。 +#define CONSOLE_RD_NONBLOCK 0//表示非阻塞模式,其值为0。 +#define CONSOLE_SHELL_KEY_EVENT 0x112//表示shell键盘事件,其值为0x112。 +#define CONSOLE_SHELL_EXITED 0x400//表示shell已退出,其值为0x400。 +#define CONSOLE_CONTROL_RIGHTS_CAPTURE 201//表示控制权被捕获,其值为201。 +#define CONSOLE_CONTROL_RIGHTS_RELEASE 202//表示控制权被释放,其值为202。 +#define CONSOLE_CONTROL_CAPTURE_LINE 203//表示捕获行命令,其值为203。 +#define CONSOLE_CONTROL_CAPTURE_CHAR 204//表示捕获字符命令,其值为204。 +#define CONSOLE_FIFO_SIZE 1024//表示控制台FIFO(First In First Out)缓冲区大小,其值为1024。 +#define CONSOLE_NUM 2//表示控制台数量,其值为2。 typedef struct { - Ringbuf ringbuf; /* Ring buffer */ - EVENT_CB_S sendEvent; /* Inform telnet send task */ + Ringbuf ringbuf; /* Ring buffer *///表示环形缓冲区,它可能是一个用于缓存数据的循环队列或者环形链表。 + EVENT_CB_S sendEvent; /* Inform telnet send task *///表示向telnet发送任务发送事件的回调函数。 } RingbufSendCB; typedef struct { - UINT32 consoleID; - UINT32 consoleType; - UINT32 consoleSem; - UINT32 shellEntryId; - UINT32 consoleMask; - struct inode *devInode; - CHAR *name; - INT32 fd; - UINT32 refCount; - BOOL isNonBlock; + UINT32 consoleID;//表示控制台的ID。 + UINT32 consoleType;//表示控制台的类型。 + UINT32 consoleSem;//表示用于同步的控制台信号量。 + UINT32 shellEntryId;//表示shell的入口ID。 + UINT32 consoleMask;//表示控制台的掩码。 + struct inode *devInode;//表示设备节点。 + CHAR *name;//表示控制台的名称。 + INT32 fd;//表示文件描述符。 + UINT32 refCount;//表示引用计数。 + BOOL isNonBlock;//表示是否为非阻塞模式。 #ifdef LOSCFG_SHELL - VOID *shellHandle; + VOID *shellHandle;//表示shell的句柄。 #endif - UINT32 sendTaskID; - RingbufSendCB *ringbufSendCB; - UINT8 fifo[CONSOLE_FIFO_SIZE]; - UINT32 fifoOut; - UINT32 fifoIn; - UINT32 currentLen; - struct termios consoleTermios; + UINT32 sendTaskID;//表示发送任务的ID。 + RingbufSendCB *ringbufSendCB;//表示环形缓冲区发送回调。 + UINT8 fifo[CONSOLE_FIFO_SIZE];//表示控制台的FIFO缓冲区。 + UINT32 fifoOut;//表示FIFO缓冲区的输出位置。 + UINT32 fifoIn;//表示FIFO缓冲区的输入位置。 + UINT32 currentLen;//表示当前长度。 + struct termios consoleTermios;//表示控制台的终端属性。 } CONSOLE_CB; -extern INT32 system_console_init(const CHAR *deviceName); -extern INT32 system_console_deinit(const CHAR *deviceName); -extern BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB); -extern BOOL SetSerialBlock(const CONSOLE_CB *consoleCB); -extern BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB); -extern BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB); -extern CONSOLE_CB *OsGetConsoleByID(INT32 consoleId); -extern CONSOLE_CB *OsGetConsoleByTaskID(UINT32 taskId); -extern UINT32 ConsoleTaskReg(INT32 consoleId, UINT32 taskId); -extern INT32 ConsoleUpdateFd(VOID); -extern BOOL ConsoleEnable(VOID); -extern BOOL is_nonblock(const CONSOLE_CB *consoleCB); -extern BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB); -extern INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops); -extern INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops); -extern INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR *buffer, size_t bufLen); -extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen); -extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds); -extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg); -extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops); +extern INT32 system_console_init(const CHAR *deviceName);//控制台初始化函数用于初始化控制台相关的资源和状态 +extern INT32 system_console_deinit(const CHAR *deviceName);//控制台反初始化函数,用于释放控制台相关的资源和状态。 +extern BOOL SetSerialNonBlock(const CONSOLE_CB *consoleCB);//设置串口为非阻塞模式。 +extern BOOL SetSerialBlock(const CONSOLE_CB *consoleCB);//设置串口为阻塞模式。 +extern BOOL SetTelnetNonBlock(const CONSOLE_CB *consoleCB);//设置Telnet连接为非阻塞模式。 +extern BOOL SetTelnetBlock(const CONSOLE_CB *consoleCB);//设置Telnet连接为阻塞模式。 +extern CONSOLE_CB *OsGetConsoleByID(INT32 consoleId);//根据控制台ID获取控制台的控制块(Control Block)。 +extern CONSOLE_CB *OsGetConsoleByTaskID(UINT32 taskId);//根据任务ID获取关联的控制台的控制块。 +extern UINT32 ConsoleTaskReg(INT32 consoleId, UINT32 taskId);//将任务与指定的控制台进行关联。 +extern INT32 ConsoleUpdateFd(VOID);//更新控制台的文件描述符(File Descriptor)。 +extern BOOL ConsoleEnable(VOID);//使能控制台功能。 +extern BOOL is_nonblock(const CONSOLE_CB *consoleCB);//判断控制台是否为非阻塞模式。 +extern BOOL IsConsoleOccupied(const CONSOLE_CB *consoleCB);//判断控制台是否已经被占用。 +extern INT32 FilepOpen(struct file *filep, const struct file_operations_vfs *fops);//打开文件。 +extern INT32 FilepClose(struct file *filep, const struct file_operations_vfs *fops);//关闭文件。 +extern INT32 FilepRead(struct file *filep, const struct file_operations_vfs *fops, CHAR *buffer, size_t bufLen);//从文件中读取数据。 +extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fops, const CHAR *buffer, size_t bufLen);//向文件中写入数据。 +extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds);//对文件进行轮询操作。 +extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg);//对文件进行IO控制操作。 +extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops);//获取文件的操作函数。 #else -STATIC INLINE INT32 ConsoleUpdateFd(VOID) +STATIC INLINE INT32 ConsoleUpdateFd(VOID)//这是一个函数声明,声明了一个名为ConsoleUpdateFd的静态内联函数,返回类型为INT32(32位整数),参数为空。根据函数体的实现为return -1;,该函数的作用是更新控制台的文件描述符(File Descriptor),并返回-1。 { return -1; } -#endif +#endif//这个宏表示结束了之前的条件编译指令#if。 -#ifdef __cplusplus +#ifdef __cplusplus//这一组条件编译指令用于判断是否为C++编译环境。如果是C++编译环境,则将后面的代码块用extern "C"包裹起来,以保证C和C++之间的函数调用规则一致。 #if __cplusplus } #endif /* __cplusplus */ diff --git a/src/kernel/include/los_atomic.h b/src/kernel/include/los_atomic.h index 05fff5f..eaf9204 100644 --- a/src/kernel/include/los_atomic.h +++ b/src/kernel/include/los_atomic.h @@ -30,12 +30,12 @@ * @defgroup los_atomic Atomic * @ingroup kernel */ - -#ifndef _LOS_ATOMIC_H -#define _LOS_ATOMIC_H +//los_atomic.h是用于支持原子操作的头文件。 +#ifndef _LOS_ATOMIC_H//表示如果宏变量 _LOS_ATOMIC_H 没有被定义过,则执行以下代码,否则忽略这段代码。 +#define _LOS_ATOMIC_H//是定义一个宏变量,可以用来判断这个头文件是否已经被包含过。 #include "los_typedef.h" -#include "arch/atomic.h" +#include "arch/atomic.h"//是平台相关的原子操作头文件,具体实现依赖于不同的硬件平台。 #ifdef __cplusplus #if __cplusplus @@ -60,7 +60,7 @@ extern "C" { * @see LOS_Atomic64Read * @since Huawei LiteOS V200R003C00 */ -STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v) +STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v)//函数接受一个Atomic类型的指针参数v,并返回一个32位整数。用于读取指定内存位置的原子变量的值。 { return ArchAtomicRead(v); } @@ -84,7 +84,7 @@ STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v) * @see LOS_Atomic64Set * @since Huawei LiteOS V200R003C00 */ -STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal) +STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal)//函数接受一个Atomic类型的指针参数v和一个32位整数setVal,没有返回值(返回类型为VOID)。 { ArchAtomicSet(v, setVal); } @@ -114,7 +114,7 @@ STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal) */ STATIC INLINE INT32 LOS_AtomicAdd(Atomic *v, INT32 addVal) { - return ArchAtomicAdd(v, addVal); + return ArchAtomicAdd(v, addVal);//用于将指定内存位置的原子变量增加指定的值。 } /** @@ -142,7 +142,7 @@ STATIC INLINE INT32 LOS_AtomicAdd(Atomic *v, INT32 addVal) */ STATIC INLINE INT32 LOS_AtomicSub(Atomic *v, INT32 subVal) { - return ArchAtomicSub(v, subVal); + return ArchAtomicSub(v, subVal);//用于将指定内存位置的原子变量减少指定的值。 } /** @@ -168,7 +168,7 @@ STATIC INLINE INT32 LOS_AtomicSub(Atomic *v, INT32 subVal) */ STATIC INLINE VOID LOS_AtomicInc(Atomic *v) { - ArchAtomicInc(v); + ArchAtomicInc(v);//用于将指定内存位置的原子变量增加1。 } /** @@ -222,7 +222,7 @@ STATIC INLINE INT32 LOS_AtomicIncRet(Atomic *v) */ STATIC INLINE VOID LOS_AtomicDec(Atomic *v) { - ArchAtomicDec(v); + ArchAtomicDec(v);//该函数通常是由特定的体系结构提供的原子递减函数的实现。通过使用内联函数和宏定义,可以在编译时将这段代码直接嵌入到调用处,从而提高执行效率和节省函数调用的开销。 } /** @@ -248,7 +248,7 @@ STATIC INLINE VOID LOS_AtomicDec(Atomic *v) */ STATIC INLINE INT32 LOS_AtomicDecRet(Atomic *v) { - return ArchAtomicDecRet(v); + return ArchAtomicDecRet(v);//该函数通常是由特定的体系结构提供的原子递减操作并返回递减后的值的函数。 } /** @@ -270,7 +270,7 @@ STATIC INLINE INT32 LOS_AtomicDecRet(Atomic *v) */ STATIC INLINE INT64 LOS_Atomic64Read(const Atomic64 *v) { - return ArchAtomic64Read(v); + return ArchAtomic64Read(v);//该函数通常是由特定的体系结构提供的原子读取操作的函数。 } /** @@ -294,7 +294,7 @@ STATIC INLINE INT64 LOS_Atomic64Read(const Atomic64 *v) */ STATIC INLINE VOID LOS_Atomic64Set(Atomic64 *v, INT64 setVal) { - ArchAtomic64Set(v, setVal); + ArchAtomic64Set(v, setVal);//该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -322,7 +322,7 @@ STATIC INLINE VOID LOS_Atomic64Set(Atomic64 *v, INT64 setVal) */ STATIC INLINE INT64 LOS_Atomic64Add(Atomic64 *v, INT64 addVal) { - return ArchAtomic64Add(v, addVal); + return ArchAtomic64Add(v, addVal);//函数来完成原子加操作,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -350,7 +350,7 @@ STATIC INLINE INT64 LOS_Atomic64Add(Atomic64 *v, INT64 addVal) */ STATIC INLINE INT64 LOS_Atomic64Sub(Atomic64 *v, INT64 subVal) { - return ArchAtomic64Sub(v, subVal); + return ArchAtomic64Sub(v, subVal);//函数来完成原子减操作,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -376,7 +376,7 @@ STATIC INLINE INT64 LOS_Atomic64Sub(Atomic64 *v, INT64 subVal) */ STATIC INLINE VOID LOS_Atomic64Inc(Atomic64 *v) { - ArchAtomic64Inc(v); + ArchAtomic64Inc(v);//函数来完成原子增加操作,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -403,7 +403,7 @@ STATIC INLINE VOID LOS_Atomic64Inc(Atomic64 *v) */ STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v) { - return ArchAtomic64IncRet(v); + return ArchAtomic64IncRet(v);//函数来完成原子增加操作并返回增加后的值,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -430,7 +430,7 @@ STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v) */ STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v) { - ArchAtomic64Dec(v); + ArchAtomic64Dec(v);//函数来完成原子减少操作,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -456,7 +456,7 @@ STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v) */ STATIC INLINE INT64 LOS_Atomic64DecRet(Atomic64 *v) { - return ArchAtomic64DecRet(v); + return ArchAtomic64DecRet(v);//函数来完成原子减少操作并返回减少后的值,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -480,7 +480,7 @@ STATIC INLINE INT64 LOS_Atomic64DecRet(Atomic64 *v) */ STATIC INLINE INT32 LOS_AtomicXchg32bits(Atomic *v, INT32 val) { - return ArchAtomicXchg32bits(v, val); + return ArchAtomicXchg32bits(v, val);//函数来完成原子交换操作并返回交换前的值,该函数应该是由底层的架构代码提供的,用于实现 32 位整数的原子操作。 } /** @@ -504,7 +504,7 @@ STATIC INLINE INT32 LOS_AtomicXchg32bits(Atomic *v, INT32 val) */ STATIC INLINE INT64 LOS_AtomicXchg64bits(Atomic64 *v, INT64 val) { - return ArchAtomicXchg64bits(v, val); + return ArchAtomicXchg64bits(v, val);//函数来完成原子交换操作并返回交换前的值,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } /** @@ -531,7 +531,7 @@ STATIC INLINE INT64 LOS_AtomicXchg64bits(Atomic64 *v, INT64 val) */ STATIC INLINE BOOL LOS_AtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal) { - return ArchAtomicCmpXchg32bits(v, val, oldVal); + return ArchAtomicCmpXchg32bits(v, val, oldVal);//函数来完成原子比较和交换操作,并返回比较结果,该函数应该是由底层的架构代码提供的,用于实现 32 位整数的原子操作。 } /** @@ -558,7 +558,7 @@ STATIC INLINE BOOL LOS_AtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal) */ STATIC INLINE BOOL LOS_AtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal) { - return ArchAtomicCmpXchg64bits(v, val, oldVal); + return ArchAtomicCmpXchg64bits(v, val, oldVal);//函数来完成原子比较和交换操作,并返回比较结果,该函数应该是由底层的架构代码提供的,用于实现 64 位整数的原子操作。 } #ifdef __cplusplus diff --git a/src/kernel/include/los_base.h b/src/kernel/include/los_base.h index a4544a5..bf1e570 100644 --- a/src/kernel/include/los_base.h +++ b/src/kernel/include/los_base.h @@ -75,19 +75,19 @@ extern "C" { * @since Huawei LiteOS V100R001C00 */ #define LOS_ASSERT_COND(expression) LOS_ASSERT(expression) - +//这是一个宏函数,它接受一个表达式作为参数,并将该表达式作为参数传递给另一个名为LOS_ASSERT的宏函数。它的作用是在满足给定条件时执行断言。 /** * @ingroup los_base * Define the timeout interval as LOS_NO_WAIT. */ #define LOS_NO_WAIT 0 - +//这是一个常量,被定义为0。它表示一个超时时间间隔,即表示不等待,立即返回。 /** * @ingroup los_base * Define the timeout interval as LOS_WAIT_FOREVER. */ #define LOS_WAIT_FOREVER 0xFFFFFFFF - +//这是另一个常量,被定义为0xFFFFFFFF。它表示一个超时时间间隔,即表示永远等待,直到条件满足或者被中断。 /** * @ingroup los_base * @brief Align the value (addr) by some bytes (boundary). @@ -111,8 +111,8 @@ extern "C" { * @see LOS_Align | TRUNCATE * @since Huawei LiteOS V100R001C00 */ -#ifndef ALIGN -#define ALIGN(addr, boundary) LOS_Align(addr, boundary) +#ifndef ALIGN//判断ALIGN是否已经被定义过,如果没有被定义过,则执行接下来的代码。 +#define ALIGN(addr, boundary) LOS_Align(addr, boundary)//分别表示需要对齐的地址和对齐边界。在函数体内部,它调用了LOS_Align函数进行地址对齐操作,将addr地址向上对齐到最接近的boundary的倍数。 #endif /** @@ -139,10 +139,16 @@ extern "C" { * @since Huawei LiteOS V100R001C00 */ #define TRUNCATE(addr, size) ((UINTPTR)(addr) & ~((size) - 1)) - +//宏接受两个参数 addr 和 size,返回一个截断后的地址。具体而言,该宏将地址 addr 按照 size 的大小进行对齐,并将低位多余的位置为零。例如,如果 addr 是 0x12345678,size 是 4,则截断后的地址是 0x12345670。 /** * Read a UINT8 value from addr and stroed in value. */ +/*READ_UINT8(value, addr)、READ_UINT16(value, addr) 和 READ_UINT32(value, addr) +分别用于从地址 addr 中读取 8 位、16 位和 32 位的数值, +并将结果存储到变量 value 中。这几个宏的实现方式类似, +都是通过指针间接读取内存中的数值,并使用 dsb() 函数进行数据同步操作, +以确保读取的数据正确。其中,dsb() 函数是一个汇编指令, +用于进行数据同步操作,防止出现数据不一致的情况。*/ #define READ_UINT8(value, addr) ({ (value) = *((volatile UINT8 *)((UINTPTR)(addr))); dsb(); }) /** @@ -155,6 +161,9 @@ extern "C" { */ #define READ_UINT32(value, addr) ({ (value) = *((volatile UINT32 *)((UINTPTR)(addr))); dsb(); }) + +//判断编译环境是否为 64 位。如果是 64 位环境,则定义了 READ_UINT64 和 WRITE_UINT64 宏。否则,这两个宏将被忽略。 +//宏用于从地址 addr 中读取一个 64 位的整数值,并将结果存储到变量 value 中。这里使用了和之前类似的操作,通过指针间接读取内存中的值,并使用 dsb() 函数进行数据同步操作。 #ifdef __LP64__ /** * Read a UINT64 value from addr and stroed in value. @@ -162,6 +171,11 @@ extern "C" { #define READ_UINT64(value, addr) ({ (value) = *((volatile UINT64 *)((UINTPTR)(addr))); dsb(); }) #endif + +/*WRITE_UINT8(value, addr)、WRITE_UINT16(value, addr) 和 WRITE_UINT32(value, addr) 宏 +分别用于将 8 位、16 位和 32 位的整数值 value 写入到地址 addr 中。 +这些宏也使用了和之前类似的操作,使用 dsb() 函数进行数据同步操作, +并通过指针间接写入内存中的值。*/ /** * Write a UINT8 value to addr. */ @@ -177,6 +191,8 @@ extern "C" { */ #define WRITE_UINT32(value, addr) ({ dsb(); *((volatile UINT32 *)((UINTPTR)(addr))) = (value); }) + +//在 64 位环境下,还定义了 WRITE_UINT64 宏,用于将 64 位的整数值 value 写入到地址 addr 中。 #ifdef __LP64__ /** * Write a UINT64 addr to addr. @@ -187,11 +203,13 @@ extern "C" { /** * Get a UINT8 value from addr. */ +//宏用于从地址 addr 中读取一个 8 位的无符号整数值,并返回读取到的结果。在读取之后,使用 dsb() 函数进行数据同步操作,以确保读取的数据正确。 #define GET_UINT8(addr) ({ UINT8 r = *((volatile UINT8 *)((UINTPTR)(addr))); dsb(); r; }) /** * Get a UINT16 value from addr. */ +//GET_UINT16(addr) 和 GET_UINT32(addr) 宏分别用于从地址 addr 中读取 16 位和 32 位的无符号整数值,并返回读取到的结果。同样地,在读取之后也进行数据同步操作。 #define GET_UINT16(addr) ({ UINT16 r = *((volatile UINT16 *)((UINTPTR)(addr))); dsb(); r; }) /** @@ -199,6 +217,8 @@ extern "C" { */ #define GET_UINT32(addr) ({ UINT32 r = *((volatile UINT32 *)((UINTPTR)(addr))); dsb(); r; }) + +//在 64 位环境下,还定义了 GET_UINT64(addr) 宏,用于从地址 addr 中读取一个 64 位的无符号整数值,并返回读取到的结果。 #ifdef __LP64__ /** * Get a UINT64 value from addr. @@ -226,7 +246,7 @@ extern "C" { * @see LOS_ASSERT_COND * @since Huawei LiteOS V100R001C00 */ -#ifdef LOSCFG_DEBUG_VERSION +#ifdef LOSCFG_DEBUG_VERSION//首先,通过条件编译指令 #ifdef LOSCFG_DEBUG_VERSION 来判断是否处于调试版本。如果定义了 LOSCFG_DEBUG_VERSION 宏,则表示处于调试版本,代码块 #ifdef 和 #endif 之间的内容将会生效;否则,代码块 #else 和 #endif 之间的内容将会生效。 #define LOS_ASSERT(judge) do { \ if ((UINTPTR)(judge) == 0) { \ (VOID)LOS_IntLock(); \ @@ -234,8 +254,12 @@ extern "C" { while (1) {} \ } \ } while (0) +//在调试版本下,宏定义的代码块中,LOS_ASSERT 宏被定义为一个带有参数 judge 的宏函数。它的作用是进行断言检查,如果 judge 表达式的结果为零(即假),则执行以上操作 +//调用 LOS_IntLock() 函数,该函数可能是一个用于禁止中断的操作,以确保在断言失败时不会中断处理。 +//使用 PRINT_ERR 打印一条错误信息,其中包含了出错的文件名、行号和函数名。 +//进入一个无限循环 while (1),程序会一直停留在这个循环中。 #else -#define LOS_ASSERT(judge) +#define LOS_ASSERT(judge)//在非调试版本下,宏定义的代码块中,LOS_ASSERT 宏被定义为空,即不进行任何操作。 #endif /** @@ -261,7 +285,8 @@ extern "C" { * @since Huawei LiteOS V100R001C00 */ extern UINTPTR LOS_Align(UINTPTR addr, UINT32 boundary); - +//具体而言,函数的功能是将 addr 按照 boundary 边界进行对齐,并返回对齐后的地址。例如,如果 addr 是 12,boundary 是 8,那么对齐后的地址就是 16。 +//extern 关键字表示该函数是在其他地方定义的,这里只是对其进行声明。这样做的目的是在当前文件中使用该函数时能够正确引用它,而不需要提供函数的具体实现。 /** * @ingroup los_base * @brief Sleep the current task. diff --git a/src/kernel/include/los_bitmap.h b/src/kernel/include/los_bitmap.h index 81bfb8f..b05e472 100644 --- a/src/kernel/include/los_bitmap.h +++ b/src/kernel/include/los_bitmap.h @@ -31,7 +31,7 @@ * @ingroup kernel */ -#ifndef _LOS_BITMAP_H +#ifndef _LOS_BITMAP_H//这段代码是一个条件编译指令块,用于判断是否定义了宏 _LOS_BITMAP_H。如果未定义该宏,则会执行 #ifndef 和 #endif 之间的代码。 #define _LOS_BITMAP_H #include "los_typedef.h" @@ -48,6 +48,7 @@ extern "C" { * * The effective bit index is from 0 to 31. */ +//由于这里宏定义的值为 32,这个宏的含义是使用 0 到 31 的整数表示位索引值,而 32 则表示无效的位索引值。这种处理方式在计算机编程中比较常见,一般用于标识某些特殊的状态或标志。 #define LOS_INVALID_BIT_INDEX 32 /** @@ -69,6 +70,9 @@ extern "C" { * @see LOS_BitmapClr * @since Huawei LiteOS V100R001C00 */ +/*bitmap 是一个指向 UINT32 类型的指针,表示一个位图(或称为位数组)。 +pos 是一个 UINT16 类型的参数,表示要设置的位索引。 +函数的作用是在给定的位图中将指定的位索引位置设为 1,即将相应位置的比特位设置为 1。*/ VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos); /** @@ -90,6 +94,9 @@ VOID LOS_BitmapSet(UINT32 *bitmap, UINT16 pos); * @see LOS_BitmapSet. * @since Huawei LiteOS V100R001C00 */ +/*bitmap 是一个指向 UINT32 类型的指针,表示一个位图(或称为位数组)。 +pos 是一个 UINT16 类型的参数,表示要清除的位索引。 +函数的作用是在给定的位图中将指定的位索引位置清零,即将相应位置的比特位设置为 0。*/ VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos); /** @@ -108,6 +115,12 @@ VOID LOS_BitmapClr(UINT32 *bitmap, UINT16 pos); * @see LOS_HighBitGet * @since Huawei LiteOS V100R001C00 */ +/*函数的作用是在给定的位图中找到最低位(也就是数值最小的位)的索引, +并返回该索引。如果位图中不存在任何置位的比特位, +则返回 32,即宏 LOS_INVALID_BIT_INDEX 的值。 +具体实现可能会涉及位运算和掩码操作, +以找到最低位的索引号。由于函数返回类型为 UINT16, +即 unsigned short 类型,因此返回值为 0 到 31 的整数(包括 0 和 31)或 32*/ UINT16 LOS_LowBitGet(UINT32 bitmap); /** @@ -126,6 +139,12 @@ UINT16 LOS_LowBitGet(UINT32 bitmap); * @see LOS_LowBitGet * @since Huawei LiteOS V100R001C00 */ +/*函数的作用是在给定的位图中找到最高位(也就是数值最大的位)的索引, +并返回该索引。如果位图中不存在任何置位的比特位, +则返回 32,即宏 LOS_INVALID_BIT_INDEX 的值。 +具体实现可能会涉及位运算和掩码操作,以找到最高位的索引号。 +由于函数返回类型为 UINT16,即 unsigned short 类型, +因此返回值为 0 到 31 的整数(包括 0 和 31)或 32。*/ UINT16 LOS_HighBitGet(UINT32 bitmap); #ifdef __cplusplus diff --git a/src/kernel/include/los_builddef.h b/src/kernel/include/los_builddef.h index 894fd80..192d90a 100644 --- a/src/kernel/include/los_builddef.h +++ b/src/kernel/include/los_builddef.h @@ -35,79 +35,79 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#define OS_LITTLE_ENDIAN 0x1234 /* Little endian */ -#define OS_BIG_ENDIAN 0x4321 /* Big endian */ +#define OS_LITTLE_ENDIAN 0x1234 /* Little endian *///表示小端序,数值为 0x1234 +#define OS_BIG_ENDIAN 0x4321 /* Big endian *///表示大端序,数值为 0x4321 #ifndef OS_BYTE_ORDER -#define OS_BYTE_ORDER OS_LITTLE_ENDIAN +#define OS_BYTE_ORDER OS_LITTLE_ENDIAN//如果未定义 OS_BYTE_ORDER,则将其设置为 OS_LITTLE_ENDIAN #endif /* Define OS code data sections */ /* The indicator function is inline */ #ifndef LITE_OS_SEC_ALW_INLINE -#define LITE_OS_SEC_ALW_INLINE /* __attribute__((always_inline)) */ +#define LITE_OS_SEC_ALW_INLINE /* __attribute__((always_inline)) *///定义了一个宏,用于将函数声明为内联函数 #endif #ifndef LITE_OS_SEC_TEXT -#define LITE_OS_SEC_TEXT /* __attribute__((section(".text.sram"))) */ +#define LITE_OS_SEC_TEXT /* __attribute__((section(".text.sram"))) *///定义了一个宏,用于将代码段放置在 .text.sram 段中 #endif #ifndef LITE_OS_SEC_TEXT_MINOR -#define LITE_OS_SEC_TEXT_MINOR /* __attribute__((section(".text.ddr"))) */ +#define LITE_OS_SEC_TEXT_MINOR /* __attribute__((section(".text.ddr"))) *///定义了一个宏,用于将代码段放置在 .text.ddr 段中 #endif #ifndef LITE_OS_SEC_TEXT_INIT -#define LITE_OS_SEC_TEXT_INIT /* __attribute__((section(".text.init"))) */ +#define LITE_OS_SEC_TEXT_INIT /* __attribute__((section(".text.init"))) *///宏定义了一个代码段,用于放置初始化代码,其位置在 .text.init 段中。 #endif #ifndef LITE_OS_SEC_DATA -#define LITE_OS_SEC_DATA /* __attribute__((section(".data.sram"))) */ +#define LITE_OS_SEC_DATA /* __attribute__((section(".data.sram"))) *///宏定义了一个数据段,用于放置数据,其位置在 .data.sram 段中。 #endif #ifndef LITE_OS_SEC_DATA_MINOR -#define LITE_OS_SEC_DATA_MINOR /* __attribute__((section(".data.ddr"))) */ +#define LITE_OS_SEC_DATA_MINOR /* __attribute__((section(".data.ddr"))) *///定义了一个次要数据段,用于放置次要的数据,其位置在 .data.ddr 段中。 #endif #ifndef LITE_OS_SEC_DATA_INIT -#define LITE_OS_SEC_DATA_INIT /* __attribute__((section(".data.init"))) */ +#define LITE_OS_SEC_DATA_INIT /* __attribute__((section(".data.init"))) *///宏定义了一个数据段,用于放置初始化数据,其位置在 .data.init 段中。 #endif #ifndef LITE_OS_SEC_DATA_VEC -#define LITE_OS_SEC_DATA_VEC __attribute__((section(".data.vector"))) +#define LITE_OS_SEC_DATA_VEC __attribute__((section(".data.vector")))//宏定义了一个数据段,用于放置向量表数据,其位置在 .data.vector 段中。 #endif #ifndef LITE_OS_SEC_BSS -#define LITE_OS_SEC_BSS /* __attribute__((section(".bss.sram"))) */ +#define LITE_OS_SEC_BSS /* __attribute__((section(".bss.sram"))) *///宏定义了一个数据段,用于放置未初始化的数据(BSS段),其位置在 .bss.sram 段中。 #endif #ifndef LITE_OS_SEC_BSS_MINOR -#define LITE_OS_SEC_BSS_MINOR /* __attribute__((section(".bss.ddr"))) */ +#define LITE_OS_SEC_BSS_MINOR /* __attribute__((section(".bss.ddr"))) */// 宏定义了一个数据段,用于放置未初始化的次要数据(BSS段),其位置在 .bss.ddr 段中。 #endif #ifndef LITE_OS_SEC_BSS_INIT -#define LITE_OS_SEC_BSS_INIT /* __attribute__((section(".bss.init"))) */ +#define LITE_OS_SEC_BSS_INIT /* __attribute__((section(".bss.init"))) *///宏定义了一个数据段,用于放置未初始化的初始化数据(BSS段),其位置在 .bss.init 段中。 #endif #ifndef LITE_OS_SEC_ITCM -#define LITE_OS_SEC_ITCM /* __attribute__((section(".itcm "))) */ +#define LITE_OS_SEC_ITCM /* __attribute__((section(".itcm "))) */// 宏定义了一个代码段,用于放置代码(指令)和只读数据,在 ITCM 中运行。 ITCM 与其他内存有所不同,它位于 CPU 内部,具有高速访问和低延迟的优势。 #endif #ifndef LITE_OS_SEC_DTCM -#define LITE_OS_SEC_DTCM /* __attribute__((section(".dtcm"))) */ +#define LITE_OS_SEC_DTCM /* __attribute__((section(".dtcm"))) *///宏定义了一个数据段,用于放置数据,位于 DTCM 中。 DTCM 与其他内存有所不同,它位于 CPU 内部,具有高速访问和低延迟的优势。 #endif -#define PACK1 +#define PACK1//宏定义了一个结构体成员变量的对齐方式,将结构体的成员变量紧密地打包在一起,不使用空间来对齐。 #ifndef LITE_OS_ATTR_SEC -#define LITE_OS_ATTR_SEC(name) __attribute__((section(#name))) +#define LITE_OS_ATTR_SEC(name) __attribute__((section(#name)))//宏定义了一个函数或变量所在的段,通过 #name 将 name 转换为字符串,将函数或变量放置到指定名称的段中。 #endif #ifndef LITE_OS_ATTR_ALIGN -#define LITE_OS_ATTR_ALIGN(x) __attribute__((aligned(x))) +#define LITE_OS_ATTR_ALIGN(x) __attribute__((aligned(x)))//宏定义了数据的对齐方式,即几个字节对齐,x 表示对齐的字节数。 #endif #ifndef LITE_OS_ATTR_SEC_ALIGN -#define LITE_OS_ATTR_SEC_ALIGN(name, x) __attribute__((section(#name), aligned(x))) +#define LITE_OS_ATTR_SEC_ALIGN(name, x) __attribute__((section(#name), aligned(x)))//宏定义了某段数据的对齐方式,即将数据放置到指定名称的段中,并按照指定的对齐方式对齐。 #endif #ifndef OS_EMBED_ASM -#define OS_EMBED_ASM __asm__ __volatile__ +#define OS_EMBED_ASM __asm__ __volatile__//宏定义了嵌入汇编指令的方式,将 asm volatile 作为嵌入汇编指令的前缀,使得编译器可以将其识别为汇编指令。 #endif #ifdef __cplusplus diff --git a/src/kernel/include/los_config.h b/src/kernel/include/los_config.h index 75b9ea0..bd14843 100644 --- a/src/kernel/include/los_config.h +++ b/src/kernel/include/los_config.h @@ -30,6 +30,22 @@ * @defgroup los_config System configuration items * @ingroup kernel */ +/*具体而言,los_config.h 文件通常包含以下内容: + +任务(Task)配置:可以定义任务的数量、优先级范围、堆栈大小等参数,以满足不同应用场景的需求。 + +中断(Interrupt)配置:可以定义中断服务例程的数量、优先级范围,以及中断处理的策略等。 + +内存管理(Memory Management)配置:可以定义动态内存分配算法、内存池的大小和数量等相关参数。 + +定时器(Timer)配置:可以定义定时器的数量、精度、触发方式等。 + +任务调度(Task Scheduling)配置:可以配置任务调度算法、时间片轮转的时间等。 + +系统时钟(System Clock)配置:可以定义系统时钟的频率、定时器的输入时钟源等。 + +通过修改 los_config.h 文件中的宏定义和全局变量,开发人员可以根据应用需求对操作系统进行定制和优化。 +然后,将修改后的 los_config.h 文件编译进入 LiteOS 内核,即可实现对操作系统行为和功能的定制化配置。*/ #ifndef _LOS_CONFIG_H #define _LOS_CONFIG_H @@ -45,53 +61,53 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#ifdef LOSCFG_LIB_CONFIGURABLE -extern UINT32 g_osSysClock; -extern UINT32 g_tickPerSecond; -extern UINT32 g_taskLimit; -extern UINT32 g_taskMinStkSize; -extern UINT32 g_taskIdleStkSize; -extern UINT32 g_taskDfltStkSize; -extern UINT32 g_taskSwtmrStkSize; -extern UINT32 g_swtmrLimit; -extern UINT32 g_semLimit; -extern UINT32 g_muxLimit; -extern UINT32 g_queueLimit; -extern UINT32 g_timeSliceTimeOut; - -extern BOOL g_nxEnabled; -extern UINTPTR g_dlNxHeapBase; -extern UINT32 g_dlNxHeapSize; - -#define LOS_GET_NX_CFG() (g_nxEnabled) -#define LOS_SET_NX_CFG(value) (g_nxEnabled = (value)) -#define LOS_GET_DL_NX_HEAP_BASE() (g_dlNxHeapBase) -#define LOS_SET_DL_NX_HEAP_BASE(addr) (g_dlNxHeapBase = (addr)) -#define LOS_GET_DL_NX_HEAP_SIZE() (g_dlNxHeapSize) -#define LOS_SET_DL_NX_HEAP_SIZE(size) (g_dlNxHeapSize = (size)) - -#define OS_SYS_CLOCK g_osSysClock -#define KERNEL_TICK_PER_SECOND g_tickPerSecond -#define KERNEL_TSK_LIMIT g_taskLimit -#define KERNEL_TSK_MIN_STACK_SIZE g_taskMinStkSize -#define KERNEL_TSK_DEFAULT_STACK_SIZE g_taskDfltStkSize -#define KERNEL_TSK_IDLE_STACK_SIZE g_taskIdleStkSize -#define KERNEL_TSK_SWTMR_STACK_SIZE g_taskSwtmrStkSize -#define KERNEL_SWTMR_LIMIT g_swtmrLimit -#define KERNEL_SEM_LIMIT g_semLimit -#define KERNEL_MUX_LIMIT g_muxLimit -#define KERNEL_QUEUE_LIMIT g_queueLimit -#define KERNEL_TIMESLICE_TIMEOUT g_timeSliceTimeOut +#ifdef LOSCFG_LIB_CONFIGURABLE//判断宏定义 LOSCFG_LIB_CONFIGURABLE 是否被定义。如果该宏被定义,那么以下变量声明将会被编译进程序中。 +extern UINT32 g_osSysClock;//系统时钟频率 +extern UINT32 g_tickPerSecond;//系统时钟滴答数 +extern UINT32 g_taskLimit;//最大任务数量 +extern UINT32 g_taskMinStkSize;//任务最小堆栈大小 +extern UINT32 g_taskIdleStkSize;//空闲任务堆栈大小 +extern UINT32 g_taskDfltStkSize;//默认任务堆栈大小 +extern UINT32 g_taskSwtmrStkSize;//软件定时器任务堆栈大小 +extern UINT32 g_swtmrLimit;//最大软件定时器数量 +extern UINT32 g_semLimit;//最大信号量数量 +extern UINT32 g_muxLimit;//最大互斥量数量 +extern UINT32 g_queueLimit;//最大队列数量 +extern UINT32 g_timeSliceTimeOut;//时间片轮转的时间 + +extern BOOL g_nxEnabled;//是否启用内存保护机制 +extern UINTPTR g_dlNxHeapBase;//内存保护机制的起始地址 +extern UINT32 g_dlNxHeapSize;//内存保护机制的大小 + +#define LOS_GET_NX_CFG() (g_nxEnabled)//宏用于获取一个名为g_nxEnabled的变量的值。 +#define LOS_SET_NX_CFG(value) (g_nxEnabled = (value))//宏用于设置一个名为g_nxEnabled的变量的值。 +#define LOS_GET_DL_NX_HEAP_BASE() (g_dlNxHeapBase)//宏用于获取一个名为g_dlNxHeapBase的变量的值。 +#define LOS_SET_DL_NX_HEAP_BASE(addr) (g_dlNxHeapBase = (addr))//宏用于设置一个名为g_dlNxHeapBase的变量的值。 +#define LOS_GET_DL_NX_HEAP_SIZE() (g_dlNxHeapSize)//宏用于获取一个名为g_dlNxHeapSize的变量的值。 +#define LOS_SET_DL_NX_HEAP_SIZE(size) (g_dlNxHeapSize = (size))//宏用于设置一个名为g_dlNxHeapSize的变量的值。 + +#define OS_SYS_CLOCK g_osSysClock//定义系统时间频率 +#define KERNEL_TICK_PER_SECOND g_tickPerSecond//定义系统时针滴答数 +#define KERNEL_TSK_LIMIT g_taskLimit//定义最大任务数量 +#define KERNEL_TSK_MIN_STACK_SIZE g_taskMinStkSize//定义任务最小堆栈大小 +#define KERNEL_TSK_DEFAULT_STACK_SIZE g_taskDfltStkSize//定义默认任务堆栈大小 +#define KERNEL_TSK_IDLE_STACK_SIZE g_taskIdleStkSize//定义默认任务堆栈大小 +#define KERNEL_TSK_SWTMR_STACK_SIZE g_taskSwtmrStkSize//定义软件定时器任务堆栈大小 +#define KERNEL_SWTMR_LIMIT g_swtmrLimit//定义最大软件定时器数量 +#define KERNEL_SEM_LIMIT g_semLimit//定义最大信号量数量 +#define KERNEL_MUX_LIMIT g_muxLimit//定义最大互斥量数量 +#define KERNEL_QUEUE_LIMIT g_queueLimit//定义最大对列数量 +#define KERNEL_TIMESLICE_TIMEOUT g_timeSliceTimeOut//定义时间片轮转的时间 #else /* LOSCFG_LIB_CONFIGURABLE */ #ifdef LOSCFG_KERNEL_NX -#define LOS_GET_NX_CFG() true -#define LOS_SET_NX_CFG(value) -#define LOS_GET_DL_NX_HEAP_BASE() LOS_DL_HEAP_BASE -#define LOS_SET_DL_NX_HEAP_BASE(addr) -#define LOS_GET_DL_NX_HEAP_SIZE() LOS_DL_HEAP_SIZE -#define LOS_SET_DL_NX_HEAP_SIZE(size) +#define LOS_GET_NX_CFG() true//获取内存保护机制是否开启的配置值,当 LOSCFG_KERNEL_NX 宏被定义时,返回 true;否则返回 false。 +#define LOS_SET_NX_CFG(value)//设置内存保护机制的配置值,该宏定义为空白,没有实际操作。 +#define LOS_GET_DL_NX_HEAP_BASE() LOS_DL_HEAP_BASE//获取内存保护机制的起始地址,当 LOSCFG_KERNEL_NX 宏被定义时,返回 LOS_DL_HEAP_BASE;否则返回 NULL。 +#define LOS_SET_DL_NX_HEAP_BASE(addr)//设置内存保护机制的起始地址,该宏定义为空白,没有实际操作。 +#define LOS_GET_DL_NX_HEAP_SIZE() LOS_DL_HEAP_SIZE//获取内存保护机制的大小,当 LOSCFG_KERNEL_NX 宏被定义时,返回 LOS_DL_HEAP_SIZE;否则返回 0。 +#define LOS_SET_DL_NX_HEAP_SIZE(size)//设置内存保护机制的大小,该宏定义为空白,没有实际操作。 #else /* LOSCFG_KERNEL_NX */ #define LOS_GET_NX_CFG() false #define LOS_SET_NX_CFG(value) @@ -101,7 +117,9 @@ extern UINT32 g_dlNxHeapSize; #define LOS_SET_DL_NX_HEAP_SIZE(size) #endif /* LOSCFG_KERNEL_NX */ -#define KERNEL_TICK_PER_SECOND LOSCFG_BASE_CORE_TICK_PER_SECOND +//这段代码是一系列宏定义,用于将一些配置参数映射到对应的宏定义。 +//这样做的目的是将配置参数与代码解耦,使得修改配置参数时只需要修改相应的宏定义,而无需修改引用该参数的代码。这样可以提高代码的可维护性和可移植性。 +#define KERNEL_TICK_PER_SECOND LOSCFG_BASE_CORE_TICK_PER_SECOND//如KERNEL_TICK_PER_SECOND宏定义为LOSCFG_BASE_CORE_TICK_PER_SECOND,意味着在代码中使用KERNEL_TICK_PER_SECOND时,实际上是使用了配置参数 #define KERNEL_TSK_LIMIT LOSCFG_BASE_CORE_TSK_LIMIT #define KERNEL_TSK_MIN_STACK_SIZE LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE #define KERNEL_TSK_DEFAULT_STACK_SIZE LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE @@ -112,27 +130,27 @@ extern UINT32 g_dlNxHeapSize; #define KERNEL_MUX_LIMIT LOSCFG_BASE_IPC_MUX_LIMIT #define KERNEL_QUEUE_LIMIT LOSCFG_BASE_IPC_QUEUE_LIMIT #define KERNEL_TIMESLICE_TIMEOUT LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT - +//最后的#endif /* LOSCFG_LIB_CONFIGURABLE */表示这组宏定义的结束,在条件LOSCFG_LIB_CONFIGURABLE不成立时,这组宏定义不起作用,因为它们是在这个条件下定义的。 #endif /* LOSCFG_LIB_CONFIGURABLE */ /** * system sections start and end address */ -extern CHAR __int_stack_start; -extern CHAR __int_stack_end; -extern CHAR __rodata_start; -extern CHAR __rodata_end; -extern CHAR __bss_start; -extern CHAR __bss_end; -extern CHAR __text_start; -extern CHAR __text_end; -extern CHAR __ram_data_start; -extern CHAR __ram_data_end; -extern CHAR __exc_heap_start; -extern CHAR __exc_heap_end; -extern CHAR __heap_start; -extern CHAR __init_array_start__; -extern CHAR __init_array_end__; +extern CHAR __int_stack_start;//内部栈的起始地址 +extern CHAR __int_stack_end;//内部栈的结束地址 +extern CHAR __rodata_start;//只读数据段的起始地址。 +extern CHAR __rodata_end;//只读数据段的结束地址。 +extern CHAR __bss_start;//未初始化的全局变量段(BSS Segment)的起始地址。 +extern CHAR __bss_end;//未初始化的全局变量段(BSS Segment)的结束地址。 +extern CHAR __text_start;//可执行代码段(Text Segment)的起始地址。 +extern CHAR __text_end;//可执行代码段(Text Segment)的结束地址。 +extern CHAR __ram_data_start;//RAM 数据段的起始地址。 +extern CHAR __ram_data_end;//RAM 数据段的结束地址。 +extern CHAR __exc_heap_start;//异常堆(Exception Heap)的起始地址。 +extern CHAR __exc_heap_end;//异常堆(Exception Heap)的结束地址。 +extern CHAR __heap_start;//堆(Heap)的起始地址。 +extern CHAR __init_array_start__;//初始化数组的起始地址。 +extern CHAR __init_array_end__; //初始化数组的结束地址。 /****************************** System clock module configuration ****************************/ /** @@ -140,24 +158,24 @@ extern CHAR __init_array_end__; * System clock (unit: HZ) */ #ifndef OS_SYS_CLOCK -#define OS_SYS_CLOCK (get_bus_clk()) +#define OS_SYS_CLOCK (get_bus_clk())//定义系统时钟频率,默认值为get_bus_clk() #endif /** * @ingroup los_config * time timer clock (unit: HZ) */ #ifndef OS_TIME_TIMER_CLOCK -#define OS_TIME_TIMER_CLOCK OS_SYS_CLOCK +#define OS_TIME_TIMER_CLOCK OS_SYS_CLOCK//定义定时器时钟频率,默认值为 OS_SYS_CLOCK #endif /** * limit addr range when search for 'func local(frame pointer)' or 'func name' */ #ifndef OS_SYS_FUNC_ADDR_START -#define OS_SYS_FUNC_ADDR_START ((UINTPTR)&__int_stack_start) +#define OS_SYS_FUNC_ADDR_START ((UINTPTR)&__int_stack_start)//定义函数起始地址,默认值为&__int_stack_start #endif #ifndef OS_SYS_FUNC_ADDR_END -#define OS_SYS_FUNC_ADDR_END g_sys_mem_addr_end +#define OS_SYS_FUNC_ADDR_END g_sys_mem_addr_end//定义函数终止地址,默认值为g_sys_mem_addr_end #endif /** @@ -165,14 +183,14 @@ extern CHAR __init_array_end__; * Microseconds of adjtime in one second */ #ifndef LOSCFG_BASE_CORE_ADJ_PER_SECOND -#define LOSCFG_BASE_CORE_ADJ_PER_SECOND 500 +#define LOSCFG_BASE_CORE_ADJ_PER_SECOND 500//每秒钟的微调时间。如果没有定义过LOSCFG_BASE_CORE_ADJ_PER_SECOND,则将其定义为500。这意味着系统在进行时间微调时,每秒钟可以微调500微秒。 #endif /** * @ingroup los_config * Sched clck interval */ -#define SCHED_CLOCK_INTETRVAL_TICKS 100 +#define SCHED_CLOCK_INTETRVAL_TICKS 100//表示调度时钟的间隔。这个宏定义的值为100,表示调度时钟的间隔为100个时钟节拍。 /****************************** Interrupt module configuration ****************************/ /** @@ -184,7 +202,7 @@ extern CHAR __init_array_end__; */ #ifdef LOSCFG_ARCH_INTERRUPT_PREEMPTION #ifndef MAX_BINARY_POINT_VALUE -#define MAX_BINARY_POINT_VALUE 4 +#define MAX_BINARY_POINT_VALUE 4//使用条件编译来检查是否已经定义了MAX_BINARY_POINT_VALUE宏。如果没有定义,则将其定义为4。 #endif #endif @@ -197,6 +215,11 @@ extern CHAR __init_array_end__; * 0xFFFF: max number of all software timers */ #ifndef OS_SWTMR_MAX_TIMERID +/*表示软件定时器ID的最大数量。 +默认值为((0xFFFF / KERNEL_SWTMR_LIMIT) * KERNEL_SWTMR_LIMIT), +其中KERNEL_SWTMR_LIMIT表示系统中每个任务可以创建的最大软件定时器数。 +这个宏定义的作用是将可用的ID数量限制在一个整数倍的软件定时器数范围内, +这样可以更好地利用ID资源。*/ #define OS_SWTMR_MAX_TIMERID ((0xFFFF / KERNEL_SWTMR_LIMIT) * KERNEL_SWTMR_LIMIT) #endif /** @@ -204,6 +227,11 @@ extern CHAR __init_array_end__; * Maximum size of a software timer queue. The default value of LOSCFG_BASE_CORE_SWTMR_LIMIT is 16. */ #ifndef OS_SWTMR_HANDLE_QUEUE_SIZE +/*示软件定时器队列的最大大小。 +默认值为KERNEL_SWTMR_LIMIT, +也就是系统中每个任务可以同时管理的软件定时器数。 +这个宏定义的作用是限制任务能够管理的软件定时器数量, +以避免资源浪费和性能问题。*/ #define OS_SWTMR_HANDLE_QUEUE_SIZE KERNEL_SWTMR_LIMIT #endif #endif @@ -214,6 +242,10 @@ extern CHAR __init_array_end__; * Starting address of the system memory */ #ifndef OS_SYS_MEM_ADDR +/*__heap_start是在链接脚本中定义的符号, +表示内存池的起始地址。 +因此,OS_SYS_MEM_ADDR的值就是内存池的起始地址的指针, +可以通过该宏来访问系统内存池。*/ #define OS_SYS_MEM_ADDR (&__heap_start) #endif @@ -223,9 +255,11 @@ extern CHAR __init_array_end__; * Starting address of dynload heap */ #if defined (LOSCFG_KERNEL_NX) && defined (LOSCFG_KERNEL_DYNLOAD) -#define LOS_DL_HEAP_SIZE (LOSCFG_KERNLE_DYN_HEAPSIZE * 0x100000) -#define LOS_DL_HEAP_BASE (SYS_MEM_END - LOS_DL_HEAP_SIZE) +//如果这两个宏都被定义了,那么将动态加载模块堆的大小定义为 +#define LOS_DL_HEAP_SIZE (LOSCFG_KERNLE_DYN_HEAPSIZE * 0x100000)//(LOSCFG_KERNLE_DYN_HEAPSIZE * 0x100000) +#define LOS_DL_HEAP_BASE (SYS_MEM_END - LOS_DL_HEAP_SIZE)//SYS_MEM_END - LOS_DL_HEAP_SIZE,其中SYS_MEM_END表示系统内存池的结束地址 #else +//如果没有定义LOSCFG_KERNEL_NX和LOSCFG_KERNEL_DYNLOAD宏,则将动态加载模块堆的大小和起始地址都定义为0。 #define LOS_DL_HEAP_SIZE 0 #define LOS_DL_HEAP_BASE 0 #endif @@ -236,7 +270,7 @@ extern CHAR __init_array_end__; */ #ifndef OS_SYS_MEM_SIZE #define OS_SYS_MEM_SIZE ((g_sys_mem_addr_end) - \ - ((LOS_DL_HEAP_SIZE + ((UINTPTR)&__heap_start) + (64 - 1)) & ~(64 - 1))) + ((LOS_DL_HEAP_SIZE + ((UINTPTR)&__heap_start) + (64 - 1)) & ~(64 - 1)))//定义内存池的大小 #endif /****************************** fw Interface configuration **************************/ @@ -245,11 +279,12 @@ extern CHAR __init_array_end__; * The core number is one in non-SMP architecture. */ #ifdef LOSCFG_KERNEL_SMP +//LOSCFG_KERNEL_CORE_NUM 将被设置为 LOSCFG_KERNEL_SMP_CORE_NUM 的值;否则,LOSCFG_KERNEL_CORE_NUM 将被设置为 1。 #define LOSCFG_KERNEL_CORE_NUM LOSCFG_KERNEL_SMP_CORE_NUM #else #define LOSCFG_KERNEL_CORE_NUM 1 #endif - +//LOSCFG_KERNEL_CPU_MASK 被定义为用于表示 CPU 核心掩码的表达式。它使用了位运算,通过将 1 左移 LOSCFG_KERNEL_CORE_NUM 位,然后减去 1,来生成一个包含 LOSCFG_KERNEL_CORE_NUM 个 1 的二进制数。这个数字通常用于设置 CPU 亲和性,以确定线程可以运行在哪些 CPU 核心上。 #define LOSCFG_KERNEL_CPU_MASK ((1 << LOSCFG_KERNEL_CORE_NUM) - 1) /****************************** trace module configuration **************************/ @@ -259,6 +294,10 @@ extern CHAR __init_array_end__; */ #ifdef LOSCFG_KERNEL_TRACE #ifdef LOSCFG_RECORDER_MODE_OFFLINE +/*LOSCFG_KERNEL_TRACE 被定义的情况下,该代码块会被编译。 +如果同时定义了 LOSCFG_RECORDER_MODE_OFFLINE, +则 LOSTRACE_BUFFER_SIZE 会被设置为 LOSCFG_TRACE_BUFFER_SIZE 的值; +否则,LOSTRACE_BUFFER_SIZE 会被设置为 0。*/ #define LOS_TRACE_BUFFER_SIZE LOSCFG_TRACE_BUFFER_SIZE #else #define LOS_TRACE_BUFFER_SIZE 0 @@ -277,39 +316,44 @@ extern CHAR __init_array_end__; /** * Version number */ -#define _T(x) x -#define HW_LITEOS_SYSNAME "Huawei LiteOS" -#define HW_LITEOS_SEP " " -#define _V(v) _T(HW_LITEOS_SYSNAME)_T(HW_LITEOS_SEP)_T(v) +//这段代码是一组宏定义,用于定义操作系统的版本号和系统名称。 +#define _T(x) x//宏定义将传入的参数 x 原样返回,用于在宏定义中表示字符串。 +#define HW_LITEOS_SYSNAME "Huawei LiteOS"//宏定义为字符串 "Huawei LiteOS",表示操作系统的名称。 +#define HW_LITEOS_SEP " "//宏定义为字符串 " ",表示名称和版本号之间的分隔符。 +#define _V(v) _T(HW_LITEOS_SYSNAME)_T(HW_LITEOS_SEP)_T(v)//宏定义通过将操作系统名称和版本号连接起来,生成一个完整的版本字符串。 -#define HW_LITEOS_VERSION "V200R005C20B053" -#define HW_LITEOS_VER _V(HW_LITEOS_VERSION"-SMP") +#define HW_LITEOS_VERSION "V200R005C20B053"//宏定义为字符串 "V200R005C20B053",表示操作系统的具体版本号。 +#define HW_LITEOS_VER _V(HW_LITEOS_VERSION"-SMP")//宏定义使用了 _V 宏,将操作系统名称和版本号连接起来,形成类似 "Huawei LiteOS V200R005C20B053-SMP" 的完整版本号字符串。 /** * The Version number of Public */ -#define MAJ_V 5 -#define MIN_V 1 -#define REL_V 0 +#define MAJ_V 5//宏定义为整数 5,表示操作系统的主要版本号。 +#define MIN_V 1//宏定义为整数 1,表示操作系统的次要版本号。 +#define REL_V 0//宏定义为整数 0,表示操作系统的发布版本号。 /** * The release candidate version number */ -#define EXTRA_V 0 +//这些宏定义和函数声明用于管理操作系统的版本号,并提供了一种将版本号转换为字符串格式的机制。 +#define EXTRA_V 0//宏定义为整数 0,表示操作系统的额外版本号或候选版本号。 -#define VERSION_NUM(a, b, c) (((a) << 16) | ((b) << 8) | (c)) -#define HW_LITEOS_OPEN_VERSION_NUM VERSION_NUM(MAJ_V, MIN_V, REL_V) +#define VERSION_NUM(a, b, c) (((a) << 16) | ((b) << 8) | (c))//宏定义将主版本号 a、次版本号 b 和发布版本号 c 组合成一个无符号整数,通过位运算实现。 +#define HW_LITEOS_OPEN_VERSION_NUM VERSION_NUM(MAJ_V, MIN_V, REL_V)// 宏定义使用了 VERSION_NUM 宏,将主版本号、次版本号和发布版本号组成一个表示版本号的无符号整数。 -#define STRINGIFY_1(x) #x -#define STRINGIFY(x) STRINGIFY_1(x) +#define STRINGIFY_1(x) #x//宏定义将参数 x 转换为字符串。 +#define STRINGIFY(x) STRINGIFY_1(x)//宏定义调用 STRINGIFY_1 宏,将参数转换为字符串。 -#define HW_LITEOS_OPEN_VERSION_STRING STRINGIFY(MAJ_V) "." STRINGIFY(MIN_V) "." STRINGIFY(REL_V) +#define HW_LITEOS_OPEN_VERSION_STRING STRINGIFY(MAJ_V) "." STRINGIFY(MIN_V) "." STRINGIFY(REL_V)//宏定义使用了 STRINGIFY 宏,将主版本号、次版本号和发布版本号转换为形如 "5.1.0" 的字符串格式。 #if (EXTRA_V != 0) +/*不等于 0,则 HW_LITEOS_KERNEL_VERSION_STRING 宏定义为带有候选版本号的版本字符串; +否则,它被定义为不带候选版本号的版本字符串。*/ #define HW_LITEOS_KERNEL_VERSION_STRING HW_LITEOS_OPEN_VERSION_STRING "-rc" STRINGIFY(EXTRA_V) #else #define HW_LITEOS_KERNEL_VERSION_STRING HW_LITEOS_OPEN_VERSION_STRING #endif +//不等于 0,则 HW_LITEOS_KERNEL_VERSION_STRING 宏定义为带有候选版本号的版本字符串;否则,它被定义为不带候选版本号的版本字符串。 extern VOID OsStart(VOID); extern UINT32 OsMain(VOID); extern VOID *OsGetMainTask(VOID); diff --git a/src/kernel/include/los_cppsupport.h b/src/kernel/include/los_cppsupport.h index cdf3fd4..c02d5e4 100644 --- a/src/kernel/include/los_cppsupport.h +++ b/src/kernel/include/los_cppsupport.h @@ -47,6 +47,8 @@ extern "C" { * If LOS_CppSystemInit() is called in the first stage of scatter load, * this flag should be passed as the third parameter. */ +/*如果在散射加载的第一阶段调用 LOS_CppSystemInit(), +则此标志应作为第三个参数传递。*/ #define BEFORE_SCATTER 0 /** @@ -54,6 +56,8 @@ extern "C" { * If LOS_CppSystemInit() is called in the second stage of scatter load, * this flag should be passed as the third parameter. */ +/*如果在散射加载的第二阶段调用 LOS_CppSystemInit(), +则此标志应作为第三个参数传递。*/ #define AFTER_SCATTER 1 /** @@ -61,6 +65,8 @@ extern "C" { * If scatter load is disabled, this flag should be passed as the third * parameter when LOS_CppSystemInit() is called. */ +/*如果禁用了分散加载,则在调用 LOS_CppSystemInit() 时, +应将此标志作为第三个参数传递。*/ #define NO_SCATTER 2 /** @@ -87,6 +93,16 @@ extern "C" { * * @since Huawei LiteOS V100R001C00 */ +//初始化操作系统C++运行环境的函数 +/*具体来说,LOS_CppSystemInit函数的主要工作包括: +调用全局静态对象的构造函数:在C++中, +全局静态对象的构造函数需要在程序开始运行前被调用。 +LOS_CppSystemInit函数会遍历全局静态对象列表, +并依次调用它们的构造函数。 +执行其他C++运行时环境的初始化工作: +除了全局静态对象的构造函数之外, +还可能需要执行其他与C++运行时环境相关的初始化工作。 +例如,可以初始化C++异常处理机制、动态内存分配器等。*/ extern INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd, INT32 flag); #ifdef __cplusplus diff --git a/src/kernel/include/los_cpup.h b/src/kernel/include/los_cpup.h index 3591a26..690cea4 100644 --- a/src/kernel/include/los_cpup.h +++ b/src/kernel/include/los_cpup.h @@ -53,6 +53,9 @@ extern "C" { * * Solution: Decrease the maximum number of tasks. */ +/*在 CPU调度器模块中发生了内存不足的错误, +并且具体的错误码是由 LOS_ERRNO_OS_ERROR 宏根据模块ID(LOS_MOD_CPUP)和错误码(0x00)生成的。 +这个错误码可以被用于在程序中标识和处理这个特定的错误情况。*/ #define LOS_ERRNO_CPUP_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x00) /** @@ -63,6 +66,9 @@ extern "C" { * * Solution: Check whether the pointer to the input parameter is usable. */ +/*在 CPU调度器模块中发生了空指针错误, +并且具体的错误码是由 LOS_ERRNO_OS_ERROR 宏根据模块ID(LOS_MOD_CPUP)和错误码(0x01)生成的。 +这个错误码可以被用于在程序中标识和处理这个特定的错误情况。*/ #define LOS_ERRNO_CPUP_TASK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x01) /** @@ -73,6 +79,9 @@ extern "C" { * * Solution: Check whether the CPU usage is initialized. */ +/*在 CPU调度器模块中发生了未初始化的错误, +具体的错误码是由 LOS_ERRNO_OS_ERROR 宏根据模块ID(LOS_MOD_CPUP)和错误码(0x02)生成的。 +这个错误码可以被用于在程序中标识和处理这个特定的错误情况。*/ #define LOS_ERRNO_CPUP_NO_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x02) /** @@ -83,6 +92,9 @@ extern "C" { * * Solution: Check whether the number of threads is applicable for the current operation. */ +/*在 CPU调度器模块中发生了无效的最大数量错误, +具体的错误码是由 LOS_ERRNO_OS_ERROR 宏根据模块ID(LOS_MOD_CPUP)和错误码(0x03)生成的。 +这个错误码可以被用于在程序中标识和处理这个特定的错误情况。*/ #define LOS_ERRNO_CPUP_MAXNUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x03) /** @@ -93,6 +105,9 @@ extern "C" { * * Solution: Check whether the target thread is created. */ +/*在 CPU调度器模块中发生了线程未创建的错误, +具体的错误码是由 LOS_ERRNO_OS_ERROR 宏根据模块ID(LOS_MOD_CPUP)和错误码(0x04)生成的。 +这个错误码可以被用于在程序中标识和处理这个特定的错误情况。*/ #define LOS_ERRNO_CPUP_THREAD_NO_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x04) /** @@ -103,12 +118,22 @@ extern "C" { * * Solution: Check whether the target task ID is applicable for the current operation. */ +/*在CPU调度器模块中发生了无效的任务ID错误, +具体的错误码是由 LOS_ERRNO_OS_ERROR 宏根据模块ID(LOS_MOD_CPUP)和错误码(0x05)生成的。 +这个错误码可以被用于在程序中标识和处理这个特定的错误情况。*/ #define LOS_ERRNO_CPUP_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_CPUP, 0x05) /** * @ingroup los_cpup * The structure of the CPU usage information of all tasks. */ +/*用于描述CPU调度器的信息。 +结构体包含两个成员变量: +usStatus:表示任务的状态,是一个 16 位的无符号整数。 +uwUsage:表示所有任务的 CPU 使用率,是一个 32 位的无符号整数,单位为 permillage,即千分之一。 +在操作系统中,CPU 调度器会负责管理系统中各个任务的执行。 +CPUP_INFO_S 结构体则提供了一种方式, +可以帮助了解任务状态和系统 CPU 使用情况的信息。*/ typedef struct tagCpupInfo { UINT16 usStatus; /**< The task status. */ UINT32 uwUsage; /**< CPU usage of all tasks. It is a permillage. And the value range is [0,1000]. */ @@ -118,9 +143,13 @@ typedef struct tagCpupInfo { * @ingroup los_cpup * The time period which the CPU usage collects in. */ +//用于表示 CPU 使用率的时间范围。 enum { + //表示显示最近 10 秒钟的 CPU 使用率,值为0。 CPUP_LAST_TEN_SECONDS = 0, /**< Display CPU usage in the last ten seconds, the value is 0. */ + //表示显示最近 1 秒钟的 CPU 使用率,值为1。 CPUP_LAST_ONE_SECONDS = 1, /**< Display CPU usage in the last one second, the value is 1. */ + //表示显示从系统启动到现在的 CPU 使用率,值为 0xffff。 CPUP_ALL_TIME = 0xffff /**< Display CPU usage from system startup to now, the value is 0xffff. */ }; @@ -149,6 +178,7 @@ enum { * @see LOS_HistoryTaskCpuUsage | LOS_AllCpuUsage * @since Huawei LiteOS V100R001C00 */ +//获取历史系统CPU使用率。参数 mode 是用来指定获取 CPU 使用率的时间范围或者其他相关设置。 extern UINT32 LOS_HistorySysCpuUsage(UINT32 mode); /** @@ -182,6 +212,9 @@ extern UINT32 LOS_HistorySysCpuUsage(UINT32 mode); * @see LOS_HistorySysCpuUsage * @since Huawei LiteOS V100R001C00 */ +/*用于获取历史任务的CPU使用率。 +其中 taskId 参数表示任务的ID或标识符, +mode 参数可能表示获取CPU使用率的模式或配置选项。*/ extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskId, UINT32 mode); /** @@ -224,6 +257,10 @@ extern UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskId, UINT32 mode); * * @since Huawei LiteOS V100R001C00 */ +/*用于获取系统中所有CPU的使用率信息。 +其中 maxNum 参数表示最大的CPU数量,cpupInfo 参数表示用于存储CPU使用率信息的结构体指针, +mode 参数可能表示获取CPU使用率的模式或配置选项, +flag 参数则可能表示其他的控制标志位。*/ extern UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT32 mode, UINT16 flag); /** @@ -244,6 +281,10 @@ extern UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT32 mode, * * @since Huawei LiteOS V100R001C00 */ +/*LOS_CpupReset 函数会遍历系统中所有任务和中断, +将它们的 CPU 使用率统计信息清零。 +这样,在下一次任务或中断执行时, +操作系统就会重新开始记录它们的 CPU 使用率。*/ extern VOID LOS_CpupReset(VOID); #ifdef __cplusplus diff --git a/src/kernel/include/los_err.h b/src/kernel/include/los_err.h index ff84c03..ef1f1dc 100644 --- a/src/kernel/include/los_err.h +++ b/src/kernel/include/los_err.h @@ -62,11 +62,12 @@ extern "C" { * * @since Huawei LiteOS V100R001C00 */ -typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName, - UINT32 lineNo, - UINT32 errorNo, - UINT32 paraLen, - VOID *para); +//LOS_ERRORHANDLE_FUNC 是一个函数指针类型,它指向一个函数,该函数具有以下特征: +typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName,//表示发生错误的文件名。 + UINT32 lineNo,//表示发生错误的行号。 + UINT32 errorNo,//表示错误代码或错误号。 + UINT32 paraLen,//表示附加参数的长度。 + VOID *para);//表示附加参数的指针。 /** * @ingroup los_err @@ -88,6 +89,15 @@ typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName, * * @since Huawei LiteOS V100R001C00 */ +/*函数的作用是处理错误。当程序运行过程中发生错误时, +可以调用这个函数来进行错误处理,包括记录错误信息、输出错误日志等操作。 +传入的参数可以用于定位和描述错误的具体信息, +从而更好地进行错误分析和排查。 +CHAR *fileName:表示发生错误的文件名。 +UINT32 lineNo:表示发生错误的行号。 +UINT32 errorNo:表示错误码或错误类型。 +UINT32 paraLen:表示传递的参数长度。 +VOID *para:表示传递的参数。*/ extern UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, UINT32 errorNo, UINT32 paraLen, VOID *para); diff --git a/src/kernel/include/los_errno.h b/src/kernel/include/los_errno.h index 9d05458..106b7ef 100644 --- a/src/kernel/include/los_errno.h +++ b/src/kernel/include/los_errno.h @@ -46,31 +46,31 @@ extern "C" { * @ingroup los_errno * OS error code flag. It is a 24-bit unsigned integer. Its value is 0x000000U. */ -#define LOS_ERRNO_OS_ID (0x00U << 16) +#define LOS_ERRNO_OS_ID (0x00U << 16)//宏定义为 0x00U << 16,表示操作系统相关的错误码。 /** * @ingroup los_errno * Define the error level as informative. It is a 32-bit unsigned integer. Its value is 0x00000000U. */ -#define LOS_ERRTYPE_NORMAL (0x00U << 24) +#define LOS_ERRTYPE_NORMAL (0x00U << 24)//宏定义表示错误级别为 "informative"(信息级别),其值为 0x00U << 24。 /** * @ingroup los_errno * Define the error level as warning. It is a 32-bit unsigned integer. Its value is 0x01000000U. */ -#define LOS_ERRTYPE_WARN (0x01U << 24) +#define LOS_ERRTYPE_WARN (0x01U << 24)//宏定义表示错误级别为 "warning"(警告级别),其值为 0x01U << 24。 /** * @ingroup los_errno * Define the error level as critical. It is a 32-bit unsigned integer. Its value is 0x02000000U. */ -#define LOS_ERRTYPE_ERROR (0x02U << 24) +#define LOS_ERRTYPE_ERROR (0x02U << 24)//宏定义表示错误级别为 "critical"(严重级别),其值为 0x02U << 24。 /** * @ingroup los_errno * Define the error level as fatal. It is a 32-bit unsigned integer. Its value is 0x03000000U. */ -#define LOS_ERRTYPE_FATAL (0x03U << 24) +#define LOS_ERRTYPE_FATAL (0x03U << 24)//宏定义表示错误级别为 "fatal"(致命级别),其值为 0x03U << 24。 /** * @ingroup los_errno @@ -82,6 +82,14 @@ extern "C" { *
  • 0-7 bits indicate the error code number. It is specified by ERRNO.
  • * */ +/*用于生成操作系统致命错误码。 +LOS_ERRTYPE_FATAL 表示错误级别为 "fatal"(致命级别),其值为 0x03U << 24。 +LOS_ERRNO_OS_ID 表示操作系统相关的错误码,其值为 0x00U << 16。 +(UINT32)(MID) << 8 将参数 MID 左移 8 位,用于表示错误码的模块标识。 +(UINT32)(ERRNO) 表示具体的错误码。 +将上述宏和位运算组合起来,LOS_ERRNO_OS_FATAL 宏可以生成一个操作系统致命错误码, +其格式为:错误级别(LOS_ERRTYPE_FATAL)+ 错误码来源(LOS_ERRNO_OS_ID)+ 模块标识(MID)+ 具体错误码(ERRNO)。 +通过定义这样的宏,可以方便地生成不同类型的错误码,并根据错误码的不同属性进行分类和处理。*/ #define LOS_ERRNO_OS_FATAL(MID, ERRNO) \ (LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO))) @@ -95,6 +103,15 @@ extern "C" { *
  • 0-7 bits indicate the error code number. It is specified by ERRNO.
  • * */ +/*这段代码定义了一个宏 LOS_ERRNO_OS_ERROR,用于生成操作系统严重错误码。 +该宏使用了以下几个宏和位运算操作: +LOS_ERRTYPE_ERROR 表示错误级别为 "critical"(严重级别),其值为 0x02U << 24。 +LOS_ERRNO_OS_ID 表示操作系统相关的错误码,其值为 0x00U << 16。 +(UINT32)(MID) << 8 将参数 MID 左移 8 位,用于表示错误码的模块标识。 +(UINT32)(ERRNO) 表示具体的错误码。 +将上述宏和位运算组合起来,LOS_ERRNO_OS_ERROR 宏可以生成一个操作系统严重错误码, +其格式为:错误级别(LOS_ERRTYPE_ERROR)+ 错误码来源(LOS_ERRNO_OS_ID)+ 模块标识(MID)+ 具体错误码(ERRNO)。 +通过定义这样的宏,可以方便地生成不同类型的错误码,并根据错误码的不同属性进行分类和处理。*/ #define LOS_ERRNO_OS_ERROR(MID, ERRNO) \ (LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO))) @@ -108,6 +125,15 @@ extern "C" { *
  • 0-7 bits indicate the error code number. It is specified by ERRNO.
  • * */ +/*这段代码定义了一个宏 LOS_ERRNO_OS_WARN,用于生成操作系统警告错误码。 +该宏使用了以下几个宏和位运算操作: +LOS_ERRTYPE_WARN 表示错误级别为 "warning"(警告级别),其值为 0x01U << 24。 +LOS_ERRNO_OS_ID 表示操作系统相关的错误码,其值为 0x00U << 16。 +(UINT32)(MID) << 8 将参数 MID 左移 8 位,用于表示错误码的模块标识。 +(UINT32)(ERRNO) 表示具体的错误码。 +将上述宏和位运算组合起来,LOS_ERRNO_OS_WARN 宏可以生成一个操作系统警告错误码, +其格式为:错误级别(LOS_ERRTYPE_WARN)+ 错误码来源(LOS_ERRNO_OS_ID)+ 模块标识(MID)+ 具体错误码(ERRNO)。 +通过定义这样的宏,可以方便地生成不同类型的错误码,并根据错误码的不同属性进行分类和处理。在发生警告级别的错误时,可以采取相应的处理措施以避免潜在问题的发生。*/ #define LOS_ERRNO_OS_WARN(MID, ERRNO) \ (LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO))) @@ -121,13 +147,29 @@ extern "C" { *
  • 0-7 bits indicate the error code number. It is specified by ERRNO.
  • * */ +/*这段代码定义了一个宏 LOS_ERRNO_OS_NORMAL,用于生成操作系统普通错误码。 +该宏使用了以下几个宏和位运算操作: +LOS_ERRTYPE_NORMAL 表示错误级别为 "normal"(普通级别),其值为 0x00U << 24。 +LOS_ERRNO_OS_ID 表示操作系统相关的错误码,其值为 0x00U << 16。 +(UINT32)(MID) << 8 将参数 MID 左移 8 位,用于表示错误码的模块标识。 +(UINT32)(ERRNO) 表示具体的错误码。 +将上述宏和位运算组合起来,LOS_ERRNO_OS_NORMAL 宏可以生成一个操作系统普通错误码, +其格式为:错误级别(LOS_ERRTYPE_NORMAL)+ 错误码来源(LOS_ERRNO_OS_ID)+ 模块标识(MID)+ 具体错误码(ERRNO)。 +通过定义这样的宏,可以方便地生成不同类型的错误码,并根据错误码的不同属性进行分类和处理。在发生普通级别的错误时,可以根据需要进行相应的处理或记录。*/ #define LOS_ERRNO_OS_NORMAL(MID, ERRNO) \ (LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO))) /** * @ingroup los_errno * Define the ID of each module in kernel. The ID is used in error code. + * 在内核中定义每个模块的 ID。该 ID 用于错误代码。 */ +/*这段代码定义了一个枚举类型 LOS_MODULE_ID,它包含了一系列的模块标识符及其对应的数值。 +每个模块都有一个唯一的标识符,用于在代码中进行识别和引用。这些标识符的值是以十六进制表示的,比如 LOS_MOD_SYS 的值是 0x0,LOS_MOD_MEM 的值是 0x1,以此类推。 +在这个枚举类型中,最后一个标识符 LOS_MOD_BUTT 是一个结束标志,表示枚举的结束。 +通过使用这个枚举类型,你可以方便地使用这些模块标识符来表示、操作和传递不同的模块。 +例如,你可以使用 LOS_MOD_SYS 来表示系统模块,在代码中进行相关的操作或者判断。 +总之,这个枚举类型提供了一种简单而有序的方式来管理和使用各个模块的标识符。*/ enum LOS_MOUDLE_ID { LOS_MOD_SYS = 0x0, /**< System ID. Its value is 0x0. */ LOS_MOD_MEM = 0x1, /**< Dynamic memory module ID. Its value is 0x1. */ diff --git a/src/kernel/include/los_event.h b/src/kernel/include/los_event.h index 7f1f653..47abca9 100644 --- a/src/kernel/include/los_event.h +++ b/src/kernel/include/los_event.h @@ -47,19 +47,19 @@ extern "C" { * @ingroup los_event * Event reading mode: The task waits for all its expected events to occur. */ -#define LOS_WAITMODE_AND 4U +#define LOS_WAITMODE_AND 4U//该模式表示任务等待所有期望的事件发生。也就是说,任务只有当所有的事件都发生时才会继续执行。 /** * @ingroup los_event * Event reading mode: The task waits for any of its expected events to occur. */ -#define LOS_WAITMODE_OR 2U +#define LOS_WAITMODE_OR 2U//该模式表示任务等待任何一个期望的事件发生。也就是说,任务只要有任何一个事件发生就会继续执行。 /** * @ingroup los_event * Event reading mode: The event flag is immediately cleared after the event is read. */ -#define LOS_WAITMODE_CLR 1U +#define LOS_WAITMODE_CLR 1U//该模式表示在事件被读取后立即清除事件标志。也就是说,一旦任务读取了事件,事件标志就会被清除。 /** * @ingroup los_event @@ -69,6 +69,14 @@ extern "C" { * Value: 0x02001c00. * * Solution: Set bits excluding bit 25 of the event mask to events. + * 这段代码定义了一个错误码 LOS_ERRNO_EVENT_SETBIT_INVALID, + 表示事件设置位无效。在这个宏定义中使用了 LOS_ERRNO_OS_ERROR 宏, + 该宏通常用于定义操作系统相关的错误码。 + 在这里,LOS_MOD_EVENT 表示错误码所属的模块是事件模块, + 0x00 是该错误码在事件模块内部的具体编号。 + 通过使用这样的宏定义,可以方便地在代码中引用和传播错误码, + 同时也有助于对错误进行分类和定位。当某个操作导致事件设置位无效时, + 可以返回这个错误码,从而让调用者知道发生了什么问题并进行相应的处理。 */ #define LOS_ERRNO_EVENT_SETBIT_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x00) @@ -81,6 +89,13 @@ extern "C" { * Solution: Increase the waiting time for event reading, or make another task write a * mask for the event. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_READ_TIMEOUT,表示事件读取超时。同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏,表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x01。 + +当某个任务等待事件时,如果设定了超时时间, +并且在该时间内没有等到事件发生,那么就会返回这个错误码, +告知调用者事件读取超时。 +这个错误码的定义可以帮助开发人员更好地判断和处理超时情况, +从而提高系统的稳定性和可靠性。*/ #define LOS_ERRNO_EVENT_READ_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x01) /** @@ -92,6 +107,13 @@ extern "C" { * * Solution: Pass in a valid EVENTMASK value. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_EVENTMASK_INVALID,表示事件掩码无效。 +同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏, +表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x02。 +事件掩码用于标识期望等待的事件,如果事件掩码无效, +则表示指定的事件掩码不符合规范或不可识别。当发生这种情况时, +可以返回这个错误码,告知调用者事件掩码无效。通过这个错误码的定义, +开发人员可以更好地检测和处理事件掩码相关的错误,从而提高系统的健壮性和可维护性。*/ #define LOS_ERRNO_EVENT_EVENTMASK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x02) /** @@ -102,6 +124,15 @@ extern "C" { * * Solution: Read the event in a task. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_READ_IN_INTERRUPT,表示在中断中进行事件读取。 +同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏, +表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x03。 +通常情况下,事件读取操作应该在任务上下文中进行,而不是在中断处理程序中执行。 +因为中断处理程序具有高优先级,可能会引起任务调度的竞争和冲突。 +当事件读取操作发生在中断上下文中时,就会返回这个错误码, +告知调用者在中断中进行了事件读取,这是不被支持的。 +通过这个错误码的定义,可以帮助开发人员及时发现并修复在中断上下文中执行事件读取的问题, +确保系统的正确运行和可靠性。*/ #define LOS_ERRNO_EVENT_READ_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x03) /** @@ -115,6 +146,15 @@ extern "C" { * * Solution: Pass in a valid flag value. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_FLAGS_INVALID,表示事件标志无效。 +同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏, +表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x04。 +事件标志用于标识特定的事件或状态,在进行事件操作时需要使用有效的事件标志。 +当事件标志无效时,可能是因为传递了错误的标志参数或者标志参数不符合预期。 +当发生这种情况时,可以返回这个错误码,告知调用者事件标志无效。 +通过这个错误码的定义,可以帮助开发人员更好地检测和处理事件标志相关的错误, +从而提高系统的稳定性和可维护性。开发人员可以根据错误码来定位并修复导致事件标志无效的问题, +确保事件操作的准确性和可靠性。*/ #define LOS_ERRNO_EVENT_FLAGS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x04) /** @@ -125,6 +165,15 @@ extern "C" { * * Solution: Unlock the task and read the event. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_READ_IN_LOCK,表示在锁定状态下进行事件读取。 +同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏, +表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x05。 +通常情况下,事件读取操作应该在非锁定状态下进行, +因为在锁定状态下进行事件读取可能导致资源竞争和死锁等问题。 +当发生在锁定状态下进行事件读取的情况时,可以返回这个错误码, +告知调用者事件读取发生在不合适的锁定状态下。 +通过这个错误码的定义,开发人员可以及时发现并修复在锁定状态下执行事件读取的问题, +确保系统的正确运行和可靠性。这有助于提高系统的并发性和避免潜在的问题。*/ #define LOS_ERRNO_EVENT_READ_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x05) /** @@ -135,6 +184,14 @@ extern "C" { * * Solution: Check whether the input parameter is null. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_PTR_NULL,表示传入的指针为空指针。 +同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏, +表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x06。 +在进行事件操作时,通常需要传递一些参数,如事件掩码、事件标志、事件句柄等。 +如果传递的指针为空指针,可能会导致访问非法内存、程序崩溃等问题。当发生这种情况时, +可以返回这个错误码,告知调用者传入的指针为空指针。 +通过这个错误码的定义,开发人员可以及时发现并修复传入空指针的问题, +确保系统的正确运行和可靠性。这有助于提高系统的稳定性和可维护性。*/ #define LOS_ERRNO_EVENT_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x06) /** @@ -147,6 +204,15 @@ extern "C" { * Solution: Read the event in a vailid task. * @deprecated This error code is obsolete since LiteOS 5.0.0. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_READ_IN_SYSTEM_TASK, +表示在系统任务中进行了事件读取操作。同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏, +表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x07。 +一般来说,系统任务具有较高的特权级别,并且用于操作系统内部的关键任务, +而不是用于普通的应用程序任务。因此,在系统任务中进行事件读取可能会引起不可预期的行为, +破坏系统的稳定性和可靠性。当发生在系统任务中进行事件读取的情况时, +可以返回这个错误码,告知调用者不应该在系统任务中执行事件读取操作。 +通过这个错误码的定义,可以帮助开发人员避免在系统任务中执行事件读取操作, +从而确保系统的正常运行和安全性。这有助于提高系统的稳定性和可维护性。*/ #define LOS_ERRNO_EVENT_READ_IN_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x07) /** @@ -157,12 +223,29 @@ extern "C" { * * Solution: Check whether the event list is not empty. */ +/*这段代码定义了一个错误码 LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY, +表示试图销毁不应该被销毁的事件。同样地,该宏定义中也使用了 LOS_ERRNO_OS_ERROR 宏, +表示该错误码属于操作系统的错误码,并且在事件模块内部的具体编号是 0x08。 +在事件处理过程中,有些事件可能不应该被销毁,因为它们可能仍在被其他任务或线程使用。 +如果试图销毁这些事件,可能会导致错误的行为,如资源泄漏、程序崩溃等问题。当发生这种情况时,可以返回这个错误码,告知调用者不应该销毁这些事件。 +通过这个错误码的定义,可以帮助开发人员避免销毁不应该被销毁的事件, +从而确保系统的正常运行和可靠性。这有助于提高系统的稳定性和可维护性。*/ #define LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY LOS_ERRNO_OS_ERROR(LOS_MOD_EVENT, 0x08) /** * @ingroup los_event * Event control structure */ +/*这段代码定义了一个名为 tagEvent 的结构体,其中包含两个成员变量: +uwEventID:表示事件掩码,在事件控制块中指示已经逻辑处理的事件。 +通常用于标识事件的类型或属性。 +stEventList:是一个链表节点,用于将事件控制块进行链接,以支持对事件的管理操作。 +此外,通过 typedef 关键字将 struct tagEvent 重新定义为 EVENT_CB_S 类型, +同时定义了指向 EVENT_CB_S 结构体的指针类型 PEVENT_CB_S。 +这种结构体的设计通常用于事件管理模块,用于存储和管理事件相关的信息, +包括事件的标识和事件控制块的链表关系。 +开发人员可以使用这样的结构体来实现事件的创建、删除、等待和触发等功能, +从而更好地管理系统中的异步事件,提高系统的并发处理能力。*/ typedef struct tagEvent { UINT32 uwEventID; /**< Event mask in the event control block, indicating the event that has been logically processed. */ @@ -187,6 +270,15 @@ typedef struct tagEvent { * @see LOS_EventClear * @since Huawei LiteOS V100R001C00 */ +/*UINT32 LOS_EventInit(PEVENT_CB_S eventCB) 是 LiteOS 操作系统中的一个函数, +用于初始化事件控制块。 +参数 eventCB 是指向事件控制块结构体 EVENT_CB_S 的指针, +该结构体用于存储和管理事件相关的信息。 +函数的返回值 UINT32 是一个无符号整数,表示函数执行的结果或错误码。 +通常,如果函数成功执行,则返回 LOS_OK 表示成功;如果发生错误,则返回对应的错误码。 +调用 LOS_EventInit 函数可以在使用事件之前对事件控制块进行初始化。 +通过此函数,可以确保事件控制块的初始状态正确, +并且可以安全地使用事件控制块进行事件的等待、触发和处理等操作。*/ extern UINT32 LOS_EventInit(PEVENT_CB_S eventCB); /** @@ -223,6 +315,25 @@ extern UINT32 LOS_EventInit(PEVENT_CB_S eventCB); * @see LOS_EventRead | LOS_EventWrite * @since Huawei LiteOS V100R001C00 */ +/*UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode) 是 LiteOS 操作系统中的一个函数,用于轮询事件。 + +参数说明: + +eventId 是一个指向无符号整数的指针,用于存储轮询到的事件ID。 +eventMask 是一个无符号整数,表示希望轮询的事件掩码。 +mode 是一个无符号整数,表示轮询模式,可以是以下几种值之一: +OS_EVENT_OR:轮询任意一个在事件掩码中设置的事件。 +OS_EVENT_AND:轮询所有在事件掩码中设置的事件。 +函数的返回值 UINT32 是一个无符号整数, +表示函数执行的结果或错误码。通常,如果函数成功执行,则返回 LOS_OK 表示成功; +如果发生错误,则返回对应的错误码。 +调用 LOS_EventPoll 函数可以轮询指定的事件,并根据指定的模式检查事件是否已经触发。 +如果有事件符合条件, +函数会将事件ID写入 eventId 指向的地址,并返回 LOS_OK;如果没有事件符合条件, +函数会根据轮询模式返回相应的错误码(如 LOS_ERRNO_EVENT_UNAVAILABLE)。 +此函数通常与其他事件管理函数配合使用,用于实现任务的等待和事件驱动的机制。 +通过轮询事件,任务可以根据不同的事件状态来决定后续的操作, +实现异步事件处理和任务调度的功能。*/ extern UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode); /** @@ -263,6 +374,24 @@ extern UINT32 LOS_EventPoll(UINT32 *eventId, UINT32 eventMask, UINT32 mode); * @see LOS_EventPoll | LOS_EventWrite * @since Huawei LiteOS V100R001C00 */ +/*UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout) +是 LiteOS 操作系统中的一个函数,用于读取事件。 +参数说明: +eventCB 是一个指向事件控制块结构体 EVENT_CB_S 的指针,表示要读取的事件控制块。 +eventMask 是一个无符号整数,表示希望读取的事件掩码。 +mode 是一个无符号整数,表示读取模式,可以是以下几种值之一: +OS_EVENT_OR:等待任意一个在事件掩码中设置的事件。 +OS_EVENT_AND:等待所有在事件掩码中设置的事件。 +timeout 是一个无符号整数,表示超时时间,单位为系统时钟节拍数。 +如果超过指定时间仍未满足读取条件,则函数返回超时错误码。 +函数的返回值 UINT32 是一个无符号整数,表示函数执行的结果或错误码。 +通常,如果函数成功执行,则返回 LOS_OK 表示成功;如果发生错误或超时,则返回对应的错误码。 +调用 LOS_EventRead 函数可以等待指定的事件触发,并根据指定的模式检查事件是否已经触发。 +如果有事件符合条件,函数会返回 LOS_OK;如果没有事件符合条件, +函数会根据读取模式等待事件的触发,直到满足条件或超时。在等待期间,任务可能会被挂起, +直到事件满足读取条件。 +此函数通常与其他事件管理函数配合使用,用于实现任务的等待和事件驱动的机制。通过读取事件, +任务可以根据不同的事件状态来决定后续的操作,实现异步事件处理和任务调度的功能。*/ extern UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout); /** @@ -311,6 +440,17 @@ extern UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events); * @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite * @since Huawei LiteOS V100R001C00 */ +/*UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events) 是 LiteOS 操作系统中的一个函数,用于写入事件。 +参数说明: +eventCB 是一个指向事件控制块结构体 EVENT_CB_S 的指针,表示要写入事件的事件控制块。 +events 是一个无符号整数,表示要写入的事件掩码。 +函数的返回值 UINT32 是一个无符号整数,表示函数执行的结果或错误码。 +通常,如果函数成功执行,则返回 LOS_OK 表示成功;如果发生错误,则返回对应的错误码。 +调用 LOS_EventWrite 函数可以向指定的事件控制块写入事件。 +事件掩码表示一个或多个事件的状态,通过将相应的事件位设置为 1 来表示事件已经触发。 +当事件写入后,等待该事件的任务可能会被唤醒,根据事件的状态来决定后续的操作。 +此函数通常与其他事件管理函数配合使用,用于实现任务之间的同步与通信。 +通过写入事件,任务可以触发其他任务的执行,实现任务的协调与同步的功能。*/ extern UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events); /** @@ -333,6 +473,22 @@ extern UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 events); * @see LOS_EventPoll | LOS_EventRead | LOS_EventWrite * @since Huawei LiteOS V100R001C00 */ +/*UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB) 是 LiteOS 操作系统中的一个函数,用于销毁事件控制块。 +参数说明: + +eventCB 是一个指向事件控制块结构体 EVENT_CB_S 的指针,表示要销毁的事件控制块。 +函数的返回值 UINT32 是一个无符号整数,表示函数执行的结果或错误码。 +通常,如果函数成功执行,则返回 LOS_OK 表示成功;如果发生错误,则返回对应的错误码。 + +调用 LOS_EventDestroy 函数可以销毁一个事件控制块,释放该事件控制块所占用的资源。 +一旦事件控制块被销毁,将不能再使用该事件控制块进行事件管理操作。 + +在实际应用中,当不再需要某个事件控制块时, +可以通过调用 LOS_EventDestroy 函数来释放相关资源,防止资源泄漏和系统资源浪费。 + +需要注意的是,在销毁事件控制块之前, +需要确保没有任务正在等待该事件或者使用该事件进行同步操作, +否则可能会导致系统行为异常。*/ extern UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB); #ifdef __cplusplus diff --git a/src/kernel/include/los_exc.h b/src/kernel/include/los_exc.h index 07c38e9..56ec150 100644 --- a/src/kernel/include/los_exc.h +++ b/src/kernel/include/los_exc.h @@ -61,6 +61,23 @@ extern "C" { * los_exc.h: the header file that contains the API declaration. * @since Huawei LiteOS V100R001C00 */ +/*LOS_Panic(const CHAR *fmt, ...) 是 LiteOS 操作系统中的一个函数,用于触发系统崩溃。 +参数说明: +fmt 是一个格式化字符串,表示崩溃信息的格式。 +... 是可变参数列表,根据格式化字符串 fmt 的要求,传入相应的参数。 +该函数没有返回值。 + +调用 LOS_Panic 函数会导致系统进入崩溃状态,即系统无法正常继续执行下去。 +通常情况下,该函数用于处理严重错误或不可恢复的异常情况, +以防止系统继续执行可能导致更严重问题的代码。 + +该函数允许通过格式化字符串传递一些额外的信息, +从而提供关于崩溃原因、位置或其他相关信息的描述。这 +些信息可能对于调试和排查问题非常有用。 + +需要注意的是,LOS_Panic 函数应该谨慎使用,仅在必要时使用。 +由于该函数触发系统崩溃,会导致系统停止运行并且无法继续恢复, +因此应该避免在正常的业务逻辑中调用该函数,以免造成不必要的系统中断。*/ VOID LOS_Panic(const CHAR *fmt, ...); /** @@ -79,8 +96,22 @@ VOID LOS_Panic(const CHAR *fmt, ...); * los_exc.h: the header file that contains the API declaration. * @since Huawei LiteOS V200R005C10 */ +/*VOID LOS_BackTrace(VOID) 是 LiteOS 操作系统中的函数,用于获取当前线程的函数调用栈信息。 +该函数没有参数,也没有返回值。 +调用 LOS_BackTrace 函数会获取当前线程的函数调用栈信息, +包括每个函数的调用地址以及相应的函数名。这些信息对于调试和排查问题非常有用, +可以帮助开发人员了解程序执行时的函数调用流程,定位问题所在。 + +通常情况下,LOS_BackTrace 函数用于调试目的,在程序出现异常或错误时, +可以通过打印函数调用栈信息来辅助分析问题原因。 +这对于定位崩溃、死锁或其他异常情况非常有帮助。 + +需要注意的是,LOS_BackTrace 函数的实现可能依赖于具体的硬件平台和编译器, +不同的平台和编译器可能会有不同的实现方式和限制。 +因此,在使用该函数时需要了解相关的平台和编译器特性,以确保获取到准确的函数调用栈信息。*/ extern VOID LOS_BackTrace(VOID); #define OsBackTrace LOS_BackTrace +//宏定义将 OsBackTrace 替换为 LOS_BackTrace,意味着在代码中使用 OsBackTrace 时,实际上是调用 LOS_BackTrace 函数。 /** * @ingroup los_exc @@ -99,9 +130,28 @@ extern VOID LOS_BackTrace(VOID); * los_exc.h: the header file that contains the API declaration. * @since Huawei LiteOS V100R001C00 */ +/*VOID LOS_TaskBackTrace(UINT32 taskID) 是 LiteOS 操作系统中的函数,用于获取指定任务的函数调用栈信息。 +参数说明: +taskID 是一个无符号整数,表示要获取函数调用栈信息的目标任务的任务ID。 +该函数没有返回值。 + +调用 LOS_TaskBackTrace 函数可以获取指定任务的函数调用栈信息, +包括每个函数的调用地址以及相应的函数名。这些信息对于调试和排查问题非常有用, +可以帮助开发人员了解指定任务执行时的函数调用流程,定位问题所在。 + +通常情况下,LOS_TaskBackTrace 函数用于调试目的,在特定任务出现异常或错误时, +可以通过打印该任务的函数调用栈信息来辅助分析问题原因。 +这对于定位崩溃、死锁或其他异常情况非常有帮助。 + +需要注意的是,LOS_TaskBackTrace 函数的实现可能依赖于具体的硬件平台和编译器, +不同的平台和编译器可能会有不同的实现方式和限制。 +因此,在使用该函数时需要了解相关的平台和编译器特性,以确保获取到准确的函数调用栈信息。 + +另外,需要确保指定的任务ID是有效的、存在的任务ID, +否则可能导致获取不到正确的函数调用栈信息。*/ extern VOID LOS_TaskBackTrace(UINT32 taskID); #define OsTaskBackTrace LOS_TaskBackTrace - +//宏定义将 OsTaskBackTrace 替换为 LOS_TaskBackTrace,意味着在代码中使用 OsTaskBackTrace 时,实际上是调用 LOS_TaskBackTrace 函数。 #ifdef LOSCFG_SHELL_EXCINFO_DUMP /** * @ingroup los_exc @@ -122,7 +172,14 @@ extern VOID LOS_TaskBackTrace(UINT32 taskID); * * @since Huawei LiteOS V200R005C10 */ +/*这是一个函数指针类型的定义。它定义了一个名为 LogReadWriteFunc 的函数指针类型, +该函数指针指向一个返回类型为 VOID 的函数, +函数参数为 UINTPTR startAddr、UINT32 space、UINT32 rwFlag 和 CHAR *buf。 +这种定义方式可以用来声明符合特定函数签名的函数指针类型,以便在代码中使用。*/ typedef VOID (*LogReadWriteFunc)(UINTPTR startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf); +/*这是一个宏定义,将 log_read_write_fn 替换为 LogReadWriteFunc。 +注释中指出这是一个旧的API,并建议避免使用它。通过这个宏定义, +可以将 log_read_write_fn 在整个代码中替换为 LogReadWriteFunc,以达到简化和统一的目的。*/ #define log_read_write_fn LogReadWriteFunc /* old API since V200R002C00, please avoid use of it */ /** @@ -146,6 +203,22 @@ typedef VOID (*LogReadWriteFunc)(UINTPTR startAddr, UINT32 space, UINT32 rwFlag, * * @since Huawei LiteOS V200R002C00 */ +/*函数 LOS_ExcInfoRegHook 是在 LiteOS 操作系统中的一个函数。它的作用是设置异常信息寄存器的回调钩子函数。 + +该函数有四个参数: + +startAddr:异常信息寄存器的起始地址。 +space:异常信息寄存器的大小(以字节为单位)。 +buf:用于存储异常信息寄存器内容的缓冲区。 +hook:回调钩子函数,类型为 LogReadWriteFunc,即函数指针类型。 +具体来说,当发生异常时,LiteOS 将会调用 LOS_ExcInfoRegHook 函数, +并将异常信息寄存器的起始地址、大小和缓冲区作为参数传递给它。 +然后,在 LOS_ExcInfoRegHook 函数内部, +可以通过回调钩子函数 hook 来处理异常信息寄存器的内容。 + +这个功能可以用于自定义异常处理和异常信息记录。通过设置回调钩子函数, +可以在异常发生时获取并处理异常信息寄存器的内容, +以便进行进一步的分析或记录。*/ VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 space, CHAR *buf, LogReadWriteFunc hook); #endif diff --git a/src/kernel/include/los_hw.h b/src/kernel/include/los_hw.h index db1cf00..2105a21 100644 --- a/src/kernel/include/los_hw.h +++ b/src/kernel/include/los_hw.h @@ -59,9 +59,10 @@ extern "C" { * los_hw.h: the header file that contains the API declaration. * @since Huawei LiteOS V200R003C00 */ +/*这段代码定义了一个静态内联函数 LOS_CpuInfo,该函数返回一个指向常量字符的指针。*/ STATIC INLINE const CHAR *LOS_CpuInfo(VOID) { - return ArchCpuInfo(); + return ArchCpuInfo();//函数会根据当前的硬件平台调用对应的底层函数,以获取关于CPU的信息,例如型号、频率、核心数等等。这个函数的实现通常是与硬件平台紧密相关的,并且可能需要一些底层的寄存器读取或其他特定平台相关的操作。 } #ifdef __cplusplus diff --git a/src/kernel/include/los_hwi.h b/src/kernel/include/los_hwi.h index 95233f2..4603103 100644 --- a/src/kernel/include/los_hwi.h +++ b/src/kernel/include/los_hwi.h @@ -48,12 +48,16 @@ extern "C" { * @ingroup los_hwi * Count of interrupts. */ +/*这行代码声明了一个名为g_intCount的数组,但它的定义并不在当前的源文件中。 +关键字"extern"告诉编译器该数组是在其他地方定义的,这通常意味着它在其他源文件或库中。 +在链接阶段,编译器会去找到实际的g_intCount的定义,然后将其与当前的代码进行链接。*/ extern size_t g_intCount[]; /** * An interrupt is active. */ -extern size_t IntActive(VOID); + +extern size_t IntActive(VOID);//IntActive(VOID)函数是用于获取当前活动的中断数量的函数。该函数没有参数,返回类型为无符号整数类型(size_t)。 /** * @ingroup los_hwi @@ -61,6 +65,16 @@ extern size_t IntActive(VOID); * * @see OS_INT_INACTIVE */ + + /*在LiteOS操作系统中,#define OS_INT_ACTIVE IntActive() 是一个预处理指令,用来定义一个宏。它将OS_INT_ACTIVE 定义为调用 IntActive() 函数的结果。 + + 宏定义是一种在代码中使用的文本替换机制。在这种情况下, + 当代码中出现 OS_INT_ACTIVE 时,预处理器会将其替换为 IntActive() 函数的调用,从 + 而实际上就是将函数调用作为一个宏使用。 + + 这种宏定义的目的可能是为了简化代码书写或提高代码的可读性。 + 通过定义宏,可以通过简单的名称(OS_INT_ACTIVE)来表示复杂的函数调用(IntActive()), + 从而使代码更加简洁和易于理解。*/ #define OS_INT_ACTIVE IntActive() /** @@ -71,6 +85,21 @@ extern size_t IntActive(VOID); * * @see OS_INT_ACTIVE */ +/*在LiteOS操作系统中,#define OS_INT_INACTIVE (!(OS_INT_ACTIVE)) 是一个预处理指令, +用来定义一个宏。它将OS_INT_INACTIVE 定义为对 OS_INT_ACTIVE 取反的结果。 + +具体来说,OS_INT_ACTIVE 是一个宏,表示调用 IntActive() 函数的结果。 +而 OS_INT_INACTIVE 是另一个宏,表示对 OS_INT_ACTIVE 取反的结果。 +在这种情况下,使用逻辑非运算符 ! 将 OS_INT_ACTIVE 的结果取反。 + +这个宏定义的目的可能是用于表示当前中断是否处于非活动状态。 +如果 OS_INT_ACTIVE 为真(非零),则表示中断处于活动状态; +而 OS_INT_INACTIVE 则为假(零),表示中断处于非活动状态。 + +通过这种方式定义宏,可以方便地在代码中判断中断状态并进行相应的处理。 +代码中使用 OS_INT_INACTIVE 可以更加直观地表示中断是否处于非活动状态, +提高代码的可读性和可维护性。 +*/ #define OS_INT_INACTIVE (!(OS_INT_ACTIVE)) /** @@ -78,6 +107,18 @@ extern size_t IntActive(VOID); * Highest priority of a hardware interrupt.This is an external parameter. * The priority range is [OS_HWI_PRIO_HIGHEST, OS_HWI_PRIO_HIGHEST + LOSCFG_HWI_PRIO_LIMIT - 1]. */ +/*在LiteOS操作系统中,#define OS_HWI_PRIO_HIGHEST 0 是一个预处理指令, +用来定义一个宏。它将 OS_HWI_PRIO_HIGHEST 定义为数字 0。 + +在LiteOS操作系统中,中断(Interrupt)也被称为硬件中断(Hardware Interrupt), +简称为 HWI。HWI具有不同的优先级(Priority),优先级越高,中断响应的时间越短。 +OS_HWI_PRIO_HIGHEST 是一个表示最高中断优先级的宏,其值为 0。 + +在LiteOS操作系统中,中断的优先级是用数字表示的,数字越小表示优先级越高。 +因此,OS_HWI_PRIO_HIGHEST 表示的是最高中断优先级,也就是数字最小的中断优先级。 +在一些特定场景下,需要使用最高中断优先级, +这时候可以使用 OS_HWI_PRIO_HIGHEST 宏来表示最高中断优先级的数字值 0, +从而方便地进行代码编写。*/ #define OS_HWI_PRIO_HIGHEST 0 /** @@ -85,12 +126,36 @@ extern size_t IntActive(VOID); * This represents the interrupt priority range, the larger number, the lower priority, the interrupt processor is * modified uniformly. */ +/*在LiteOS操作系统中, +#define OS_HWI_PRIO_LOWEST (LOSCFG_HWI_PRIO_LIMIT - 1) 是一个预处理指令, +用来定义一个宏。它将 OS_HWI_PRIO_LOWEST 定义为 LOSCFG_HWI_PRIO_LIMIT 减去 1 的结果。 + +在LiteOS操作系统中,中断(Interrupt)也被称为硬件中断(Hardware Interrupt), +简称为 HWI。HWI具有不同的优先级(Priority),优先级越高,中断响应的时间越短。OS_HWI_PRIO_LOWEST 是一个表示最低中断优先级的宏,其值为 LOSCFG_HWI_PRIO_LIMIT - 1。 + +LOSCFG_HWI_PRIO_LIMIT 是一个配置参数,用于表示系统支持的最大中断优先级数。 +因此,OS_HWI_PRIO_LOWEST 表示的是最低中断优先级,也就是数字最大的中断优先级, +其值等于最大中断优先级数减去 1。 +在一些特定场景下,需要使用最低中断优先级, +这时候可以使用 OS_HWI_PRIO_LOWEST 宏来表示最低中断优先级的数字值,从而方便地进行代码编写。*/ #define OS_HWI_PRIO_LOWEST (LOSCFG_HWI_PRIO_LIMIT - 1) /** * @ingroup los_hwi * The lower priority number, the higher priority, so OS_HWI_PRIO_LOWEST big than OS_HWI_PRIO_HIGHEST. */ +/*该宏接受一个参数 pri,表示要判断的中断优先级值。 +宏的定义使用了逻辑与运算符 && 和比较运算符 >=、<=。 +具体解释如下: + +((pri) >= OS_HWI_PRIO_HIGHEST) 表示判断 pri 是否大于等于最高中断优先级(OS_HWI_PRIO_HIGHEST)。如果 pri 大于等于最高中断优先级,则该条件结果为真(非零);否则为假(零)。 +((pri) <= OS_HWI_PRIO_LOWEST) 表示判断 pri 是否小于等于最低中断优先级(OS_HWI_PRIO_LOWEST)。如果 pri 小于等于最低中断优先级,则该条件结果为真(非零);否则为假(零)。 +整个宏定义将以上两个条件使用逻辑与运算符 && 连接起来, +即 (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST))。 +只有当 pri 同时满足大于等于最高中断优先级和小于等于最低中断优先级时, +该条件结果为真(非零),表示中断优先级有效;否则为假(零),表示中断优先级无效。 +这个宏的作用是在进行中断优先级的判断和设置时, +确保所使用的中断优先级值在有效范围内,避免出现错误的中断优先级设置。*/ #define HWI_PRI_VALID(pri) (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST)) /** @@ -105,6 +170,23 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用来定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误。 +它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_NUM_INVALID 是一个表示无效中断号的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成, +它接受两个参数:模块号和错误码值。 +其中,LOS_MOD_HWI 表示HWI模块的模块号,0x00 表示错误码值。 +因此,LOS_ERRNO_HWI_NUM_INVALID 的值就是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_NUM_INVALID 是 LOS_ERRNO_HWI_NUM_INVALID 的别名。 +通过将其定义为相同的值,可以在代码中使用更简洁的名称来表示无效中断号的错误码。 +这些错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在配置和使用中断时,如果遇到了无效的中断号, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_NUM_INVALID 或 OS_ERRNO_HWI_NUM_INVALID, +来判断中断号是否有效,进而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00) #define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_HWI_NUM_INVALID @@ -120,6 +202,22 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用来定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误。 +它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_PROC_FUNC_NULL 是一个表示中断处理函数为空的错误码。该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成, +它接受两个参数:模块号和错误码值。 +其中,LOS_MOD_HWI 表示HWI模块的模块号,0x01 表示错误码值。 +因此,LOS_ERRNO_HWI_PROC_FUNC_NULL 的值就是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_PROC_FUNC_NULL 是 LOS_ERRNO_HWI_PROC_FUNC_NULL 的别名。 +通过将其定义为相同的值,可以在代码中使用更简洁的名称来表示中断处理函数为空的错误码。 +这些错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在配置和使用中断时,如果中断处理函数为空, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_PROC_FUNC_NULL 或 OS_ERRNO_HWI_PROC_FUNC_NULL,来判断中断处理函数是否正确设置, +进而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01) #define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_HWI_PROC_FUNC_NULL @@ -132,6 +230,18 @@ extern size_t IntActive(VOID); * Solution: This error code is not in use temporarily. * @deprecated This error code is obsolete since LiteOS 5.0.0. */ +/**/ +/*定义了一个错误码,表示硬件中断(HWI)回调函数不可用的情况。 +具体解释如下: + +OS_ERRNO_HWI_CB_UNAVAILABLE 是用来表示硬件中断(HWI)回调函数不可用的错误码。 +它由 LOS_ERRNO_OS_ERROR 宏生成,该宏接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x02 表示错误码值。 +因此,OS_ERRNO_HWI_CB_UNAVAILABLE 的值是根据模块号和错误码值计算得出的。 +这个错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在设置和注册中断回调函数时,如果回调函数不可用, +可以通过检查返回的错误码是否等于 OS_ERRNO_HWI_CB_UNAVAILABLE,来判断回调函数的可用性, +从而进行相应的错误处理。*/ #define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02) /** @@ -146,6 +256,21 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用来定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误。它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_NO_MEMORY 是一个表示无法分配内存的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成,它接受两个参数:模块号和错误码值。 +其中,LOS_MOD_HWI 表示HWI模块的模块号,0x03 表示错误码值。 +因此,LOS_ERRNO_HWI_NO_MEMORY 的值就是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_NO_MEMORY 是 LOS_ERRNO_HWI_NO_MEMORY 的别名。通过将其定义为相同的值, +可以在代码中使用更简洁的名称来表示无法分配内存的错误码。 +这些错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在设置和注册中断处理函数时,如果出现无法分配内存的情况, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_NO_MEMORY 或 OS_ERRNO_HWI_NO_MEMORY, +来判断内存是否分配成功,进而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03) #define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_HWI_NO_MEMORY @@ -162,6 +287,22 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用于定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误。 +它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_ALREADY_CREATED 是一个表示中断已经被创建的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成,它接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x04 表示错误码值。 +因此,LOS_ERRNO_HWI_ALREADY_CREATED 的值是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_ALREADY_CREATED 是 LOS_ERRNO_HWI_ALREADY_CREATED 的别名。 +通过将其定义为相同的值,可以在代码中使用更简洁的名称来表示中断已经被创建的错误码。 +这些错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在创建中断时,如果中断已经被创建, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_ALREADY_CREATED 或 OS_ERRNO_HWI_ALREADY_CREATED, +来判断中断是否已经存在,从而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04) #define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_HWI_ALREADY_CREATED @@ -177,6 +318,22 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用于定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误。 +它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_PRIO_INVALID 是一个表示中断优先级无效的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成,它接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x05 表示错误码值。 +因此,LOS_ERRNO_HWI_PRIO_INVALID 的值是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_PRIO_INVALID 是 LOS_ERRNO_HWI_PRIO_INVALID 的别名。 +通过将其定义为相同的值,可以在代码中使用更简洁的名称来表示中断优先级无效的错误码。 +这些错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在设置中断优先级时,如果提供了无效的优先级值, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_PRIO_INVALID 或 OS_ERRNO_HWI_PRIO_INVALID,来判断优先级是否有效, +进而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05) #define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_HWI_PRIO_INVALID @@ -189,6 +346,18 @@ extern size_t IntActive(VOID); * Solution: This error code is not in use temporarily. * @deprecated This error code is obsolete since LiteOS 5.0.0. */ +/*是一个预处理指令,用于定义错误码。 + +该错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误, +具体来说是中断模式无效的错误。 +它是通过使用LiteOS提供的错误码宏 LOS_ERRNO_OS_ERROR 来定义的。 +该宏接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x06 表示错误码值。 +因此,OS_ERRNO_HWI_MODE_INVALID 的值是根据模块号和错误码值计算得出的。 +这个错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在设置中断模式时,如果提供了无效的模式值, +可以通过检查返回的错误码是否等于 OS_ERRNO_HWI_MODE_INVALID , +来判断模式是否有效,进而进行相应的错误处理。*/ #define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06) /** @@ -200,6 +369,19 @@ extern size_t IntActive(VOID); * Solution: This error code is not in use temporarily. * @deprecated This error code is obsolete since LiteOS 5.0.0. */ +/*是一个预处理指令,用于定义错误码。 + +该错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误, +具体来说是快速中断模式已经被创建的错误。 +它是通过使用LiteOS提供的错误码宏 LOS_ERRNO_OS_ERROR 来定义的。 +该宏接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x07 表示错误码值。 +因此,OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED 的值是根据模块号和错误码值计算得出的。 + +这个错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在创建快速中断模式时,如果该模式已经被创建, +可以通过检查返回的错误码是否等于 OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED , +来判断快速中断模式是否已经存在,从而进行相应的错误处理。*/ #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) /** @@ -214,6 +396,23 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用于定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误,具体来说是硬件中断发生错误的错误。 +它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_INTERR 是一个表示硬件中断发生错误的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成, +它接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x08 表示错误码值。 +因此,LOS_ERRNO_HWI_INTERR 的值是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_INTERR 是 LOS_ERRNO_HWI_INTERR 的别名。 +通过将其定义为相同的值,可以在代码中使用更简洁的名称来表示硬件中断发生错误的错误码。 +这些错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在中断处理函数中,如果硬件中断发生错误, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_INTERR 或 OS_ERRNO_HWI_INTERR, +来判断中断是否发生了错误,进而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) #define OS_ERRNO_HWI_INTERR LOS_ERRNO_HWI_INTERR @@ -230,6 +429,22 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用于定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误,具体来说是共享中断错误的错误。 +它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_SHARED_ERROR 是一个表示共享中断错误的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成,它接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x09 表示错误码值。 +因此,LOS_ERRNO_HWI_SHARED_ERROR 的值是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_SHARED_ERROR 是 LOS_ERRNO_HWI_SHARED_ERROR 的别名。 +通过将其定义为相同的值,可以在代码中使用更简洁的名称来表示共享中断错误的错误码。 +这些错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在设置共享中断时,如果发生了错误, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_SHARED_ERROR 或 OS_ERRNO_HWI_SHARED_ERROR, +来判断共享中断是否设置成功,进而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09) #define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_HWI_SHARED_ERROR @@ -242,6 +457,20 @@ extern size_t IntActive(VOID); * Solution: This error code is not in use temporarily. * @deprecated This error code is obsolete since LiteOS 5.0.0. */ +/*是一个预处理指令,用于定义错误码。 + +这个错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误,具体来说是硬件中断参数无效的错误。 +它是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +OS_ERRNO_HWI_ARG_INVALID 是一个表示硬件中断参数无效的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成,它接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x0a 表示错误码值。 +因此,OS_ERRNO_HWI_ARG_INVALID 的值是根据模块号和错误码值计算得出的。 +这个错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在注册硬件中断处理函数时,如果传递给函数的参数无效, +可以通过检查返回的错误码是否等于 OS_ERRNO_HWI_ARG_INVALID,来判断参数是否有效, +进而进行相应的错误处理。*/ #define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a) /** @@ -257,6 +486,22 @@ extern size_t IntActive(VOID); *
  • Please use macros starting with LOS, and macros starting with OS will not be supported.
  • * */ +/*是两个预处理指令,用于定义错误码。 + +这些错误码用于表示在操作系统的硬件中断(HWI)模块中发生的错误,具体来说是硬件中断号未创建的错误。 +它们是通过使用LiteOS提供的错误码宏来定义的。 +具体解释如下: + +LOS_ERRNO_HWI_HWINUM_UNCREATE 是一个表示硬件中断号未创建的错误码。 +该错误码的值由 LOS_ERRNO_OS_ERROR 宏生成,它接受两个参数:模块号和错误码值。 +在这里,LOS_MOD_HWI 表示HWI模块的模块号,0x0b 表示错误码值。 +因此,LOS_ERRNO_HWI_HWINUM_UNCREATE 的值是根据模块号和错误码值计算得出的。 +OS_ERRNO_HWI_HWINUM_UNCREATE 是 LOS_ERRNO_HWI_HWINUM_UNCREATE 的别名。 +通过将其定义为相同的值,可以在代码中使用更简洁的名称来表示硬件中断号未创建的错误码。 +这个错误码可以在编程过程中用于判断和处理HWI模块相关的错误情况。 +例如,在请求处理某个硬件中断时,如果指定的中断号未创建, +可以通过检查返回的错误码是否等于 LOS_ERRNO_HWI_HWINUM_UNCREATE 或 OS_ERRNO_HWI_HWINUM_UNCREATE, +来判断中断号是否有效,进而进行相应的错误处理。*/ #define LOS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b) #define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_HWI_HWINUM_UNCREATE @@ -264,18 +509,21 @@ extern size_t IntActive(VOID); * @ingroup los_hwi * Define the type HWI_HANDLE_T for a hardware interrupt number, the type is an unsigned int. */ +//这行代码定义了一个新的类型 HWI_HANDLE_T,它被定义为 UINT32,即无符号32位整数。在这里,HWI_HANDLE_T 被用来表示硬件中断的句柄或标识符。 typedef UINT32 HWI_HANDLE_T; /** * @ingroup los_hwi * Define the type HWI_PRIOR_T for a hardware interrupt priority, the type is an unsigned short. */ +//这行代码定义了一个新的类型 HWI_PRIOR_T,它被定义为 UINT16,即无符号16位整数。在这里,HWI_PRIOR_T 被用来表示硬件中断的优先级。 typedef UINT16 HWI_PRIOR_T; /** * @ingroup los_hwi * Define the type HWI_MODE_T for hardware interrupt mode configurations, the type is an unsigned short. */ +//这行代码定义了一个新的类型 HWI_MODE_T,它被定义为 UINT16,即无符号16位整数。在这里,HWI_MODE_T 被用来表示硬件中断的模式配置。 typedef UINT16 HWI_MODE_T; /** @@ -283,6 +531,9 @@ typedef UINT16 HWI_MODE_T; * Define the type HWI_ARG_T for the parameter used for the hardware interrupt creation function. * The function of this parameter varies among platforms. */ +/*这行代码定义了一个新的类型 HWI_ARG_T,它被定义为 UINTPTR, +即一个无符号整数,其大小与指针大小相同。 +在这里,HWI_ARG_T 被用来表示硬件中断创建函数的参数,其具体含义会因平台而异。*/ typedef UINTPTR HWI_ARG_T; /** @@ -303,6 +554,8 @@ typedef UINTPTR HWI_ARG_T; * @see LOS_HwiCreate * @since Huawei LiteOS V100R001C00 */ +/*这行代码定义了一个函数指针类型 HWI_PROC_FUNC,它指向一个没有参数和返回值的函数。 +在这里,HWI_PROC_FUNC 被用来表示硬件中断处理函数的类型。*/ typedef VOID (*HWI_PROC_FUNC)(VOID); /** @@ -311,12 +564,22 @@ typedef VOID (*HWI_PROC_FUNC)(VOID); * * The flag only used by the kernel as part of the IRQ handling routines. */ +/*这个宏定义了一个常量 IRQF_SHARED,其值为 0x8000U。 +在这里,IRQF_SHARED 用于表示一个共享的硬件中断。*/ #define IRQF_SHARED 0x8000U /** * @ingroup los_hwi * The hardware interrupt parameter for #LOS_HwiDelete and interrupt handler in #LOS_HwiCreate. */ +/*这个代码定义了一个名为 HWI_IRQ_PARAM_S 的结构体类型,结构体内包含了以下成员: +int swIrq: 表示中断号的整数变量。 +VOID *pDevId: 表示触发中断的设备ID的指针变量。 +const CHAR *pName: 表示中断名称的指针变量。 + +这个结构体类型 HWI_IRQ_PARAM_S 用作 LOS_HwiDelete 函数和 LOS_HwiCreate 函数中的硬件中断参数。 +通过使用这个结构体, +可以传递中断号、设备ID和中断名称等信息给函数,以进行相应的操作或处理。*/ typedef struct tagIrqParam { int swIrq; /**< The interrupt number */ VOID *pDevId; /**< The pointer to the device ID that launches the interrupt */ @@ -340,6 +603,27 @@ typedef struct tagIrqParam { * @see LOS_IntRestore * @since Huawei LiteOS V100R001C00 */ +/*这段代码定义了一个静态内联函数 LOS_IntLock(),具体解释如下: + +STATIC INLINE: + +STATIC 关键字指示该函数的作用域为当前文件,在其他文件中不可见。 +INLINE 关键字告诉编译器将该函数的代码插入到调用处,而不是生成函数调用。 +UINT32: + +UINT32 表示返回值类型为无符号32位整数。 +LOS_IntLock(VOID): + +LOS_IntLock 是函数的名称,它接受一个 VOID 参数,表示没有输入参数。 +return ArchIntLock();: + +这行代码调用了 ArchIntLock() 函数,并将其返回值作为 LOS_IntLock() 函数的返回值。 +ArchIntLock() 是一个硬件相关的函数,用于禁用中断,并返回之前的中断状态。 +因为函数声明为内联函数且函数体非常简单, +所以编译器会在调用处直接插入 ArchIntLock() 的代码,提高执行效率。 +总结:LOS_IntLock() 函数是一个内联函数, +它调用底层的 ArchIntLock() 函数来禁用中断,并返回之前的中断状态。 +这个函数的目的是为了保护关键代码区域,防止被中断打断,以确保数据的一致性和可靠性。*/ STATIC INLINE UINT32 LOS_IntLock(VOID) { return ArchIntLock(); @@ -361,6 +645,13 @@ STATIC INLINE UINT32 LOS_IntLock(VOID) * * @see LOS_IntLock */ +/*return ArchIntUnlock();: + +这行代码调用了 ArchIntUnlock() 函数,并将其返回值作为 LOS_IntUnLock() 函数的返回值。 +ArchIntUnlock() 是一个硬件相关的函数,用于恢复之前被禁用的中断状态。 +总结:LOS_IntUnLock() 函数是一个内联函数, +它调用底层的 ArchIntUnlock() 函数来恢复之前被禁用的中断状态。 +这个函数的目的是为了在临界区执行完毕后,恢复中断,允许其他中断事件发生。*/ STATIC INLINE UINT32 LOS_IntUnLock(VOID) { return ArchIntUnlock(); @@ -384,6 +675,14 @@ STATIC INLINE UINT32 LOS_IntUnLock(VOID) * @see LOS_IntLock * @since Huawei LiteOS V100R001C00 */ +/*ArchIntRestore(intSave);: + +这行代码调用了 ArchIntRestore() 函数,将之前保存的中断状态作为参数传递给它。 +ArchIntRestore() 是一个硬件相关的函数,用于根据传入的中断状态值恢复中断。 +总结:LOS_IntRestore() 函数是一个内联函数, +它调用底层的 ArchIntRestore() 函数来根据之前保存的中断状态恢复中断。 +这个函数的目的是在一段被禁用中断的代码执行完毕后,恢复中断状态,允许其他中断事件发生。 +由于函数没有返回值,所以不会返回任何结果。*/ STATIC INLINE VOID LOS_IntRestore(UINT32 intSave) { ArchIntRestore(intSave); @@ -430,11 +729,11 @@ STATIC INLINE VOID LOS_IntRestore(UINT32 intSave) * @see LOS_HwiDelete * @since Huawei LiteOS V100R001C00 */ -extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, - HWI_PRIOR_T hwiPrio, - HWI_MODE_T hwiMode, - HWI_PROC_FUNC hwiHandler, - HWI_IRQ_PARAM_S *irqParam); +extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,//表示中断号或中断向量的标识。 + HWI_PRIOR_T hwiPrio,//表示中断的优先级。 + HWI_MODE_T hwiMode,//表示中断的模式(如边沿触发、电平触发等)。 + HWI_PROC_FUNC hwiHandler,//表示中断处理函数的指针。 + HWI_IRQ_PARAM_S *irqParam);//表示中断参数的结构体指针。 /** * @ingroup los_hwi @@ -470,6 +769,9 @@ extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, * @see LOS_HwiCreate * @since Huawei LiteOS V100R001C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中删除一个中断处理程序。 +/*HWI_HANDLE_T hwiNum 是函数的第一个参数,表示要删除的中断号或中断向量的标识。 +HWI_IRQ_PARAM_S *irqParam 是函数的第二个参数,表示中断参数的结构体指针。*/ extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam); /** @@ -492,6 +794,8 @@ extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HWI_IRQ_PARAM_S *irqParam); * * @since Huawei LiteOS V200R005C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中触发一个指定的中断。 +//HWI_HANDLE_T hwiNum 是函数的参数,表示要触发的中断号或中断向量的标识。 extern UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum); /** @@ -513,6 +817,10 @@ extern UINT32 LOS_HwiTrigger(HWI_HANDLE_T hwiNum); * * @since Huawei LiteOS V200R005C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中清除(复位)一个指定的中断。 +/*HWI_HANDLE_T hwiNum 是函数的参数,表示要清除的中断号或中断向量的标识。 +函数的作用是根据指定的中断号,将相应的中断标志位清除,即将中断状态复位。 +通过调用该函数,可以清除中断触发后的状态,以便重新准备下一次中断处理。*/ extern UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum); /** @@ -536,6 +844,10 @@ extern UINT32 LOS_HwiClear(HWI_HANDLE_T hwiNum); * @see LOS_HwiDisable * @since Huawei LiteOS V200R005C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中使能(启用)一个指定的中断。 +/*HWI_HANDLE_T hwiNum 是函数的参数,表示要使能的中断号或中断向量的标识。 +函数的作用是根据指定的中断号,将相应的中断使能位设置为有效,即启用该中断。 +启用中断后,当满足中断触发条件时,系统将会跳转执行对应的中断处理程序。*/ extern UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum); /** @@ -558,6 +870,10 @@ extern UINT32 LOS_HwiEnable(HWI_HANDLE_T hwiNum); * @see LOS_HwiEnable * @since Huawei LiteOS V200R005C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中禁用(关闭)一个指定的中断。 +/*HWI_HANDLE_T hwiNum 是函数的参数,表示要禁用的中断号或中断向量的标识。 +函数的作用是根据指定的中断号,将相应的中断使能位设置为无效,即禁用该中断。 +禁用中断后,即使满足中断触发条件,系统也不会跳转执行对应的中断处理程序。*/ extern UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum); #ifdef LOSCFG_KERNEL_SMP @@ -582,6 +898,11 @@ extern UINT32 LOS_HwiDisable(HWI_HANDLE_T hwiNum); * * @since Huawei LiteOS V200R005C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中向指定的处理器发送中断请求。 +/*HWI_HANDLE_T hwiNum 是函数的第一个参数,表示要发送的中断号或中断向量的标识。 +UINT32 cpuMask 是函数的第二个参数,表示中断发送的目标处理器掩码,用于指定将中断发送到哪些处理器上。 +函数的作用是向指定的处理器发送中断请求, +即通过中断控制器向目标处理器发送中断信号,触发相应的中断处理操作。*/ extern UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask); /** @@ -605,6 +926,12 @@ extern UINT32 LOS_HwiSendIpi(HWI_HANDLE_T hwiNum, UINT32 cpuMask); * * @since Huawei LiteOS V200R005C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中设置指定中断的亲和性(Affinity)。 +/*HWI_HANDLE_T hwiNum 是函数的第一个参数,表示要设置亲和性的中断号或中断向量的标识。 +UINT32 cpuMask 是函数的第二个参数,表示要设置的中断亲和性掩码,用于指定该中断可以在哪些处理器上执行。 +函数的作用是设置指定中断的亲和性,即将中断与特定的处理器相关联。当中断被触发时, +只有与中断亲和性相关的处理器才会尝试执行中断处理程序, +从而避免了不必要的中断传递和处理开销。*/ extern UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask); #endif /* LOSCFG_KERNEL_SMP */ @@ -632,6 +959,11 @@ extern UINT32 LOS_HwiSetAffinity(HWI_HANDLE_T hwiNum, UINT32 cpuMask); * @see None * @since Huawei LiteOS V200R005C00 */ +//是一个函数声明,用于在 LiteOS 操作系统中设置指定中断的优先级(Priority)。 +/*HWI_HANDLE_T hwiNum 是函数的第一个参数,表示要设置优先级的中断号或中断向量的标识。 +HWI_PRIOR_T priority 是函数的第二个参数,表示要设置的中断优先级。 +函数的作用是设置指定中断的优先级,即确定中断在系统中的相对执行优先级。 +较高优先级的中断将优先获得处理器资源,并在其他中断之前得到响应和执行。*/ extern UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority); #ifdef LOSCFG_KERNEL_LOWPOWER @@ -652,6 +984,10 @@ extern UINT32 LOS_HwiSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority); * @see None. * @since Huawei LiteOS V200R005C10 */ +//是一个函数指针类型的定义。 +/*这部分定义了函数指针所指向的函数的参数列表,其中包含一个名为 hwiNum 的参数,其类型为 HWI_HANDLE_T。 +因此,整体来说,typedef VOID (*WAKEUPFROMINTHOOK)(HWI_HANDLE_T hwiNum) 定义了一个函数指针类型 WAKEUPFROMINTHOOK, +它指向一个不返回数值的函数,并且该函数接受一个 HWI_HANDLE_T 类型的参数 hwiNum。*/ typedef VOID (*WAKEUPFROMINTHOOK)(HWI_HANDLE_T hwiNum); /** @@ -671,6 +1007,11 @@ typedef VOID (*WAKEUPFROMINTHOOK)(HWI_HANDLE_T hwiNum); * @see None. * @since Huawei LiteOS V200R005C10 */ +//是用于注册中断唤醒钩子函数的外部声明。 +/*WAKEUPFROMINTHOOK hook 是函数的参数,它是一个指向中断唤醒钩子函数的指针。 +函数的作用是注册中断唤醒钩子函数, +即将指定的函数指针(指向中断唤醒处理函数的指针)注册到系统中, +以便在特定的中断事件发生时执行相应的处理操作。*/ extern VOID LOS_IntWakeupHookReg(WAKEUPFROMINTHOOK hook); #endif diff --git a/src/kernel/include/los_typedef.h b/src/kernel/include/los_typedef.h index aa5e5e1..dedd290 100644 --- a/src/kernel/include/los_typedef.h +++ b/src/kernel/include/los_typedef.h @@ -49,6 +49,7 @@ extern "C" { #define X_STRING(x) OS_STRING(x) /* type definitions */ +//瀹氫箟鏁版嵁绫诲瀷 typedef unsigned char UINT8; typedef unsigned short UINT16; typedef unsigned int UINT32; @@ -59,7 +60,10 @@ typedef float FLOAT; typedef double DOUBLE; typedef char CHAR; + + #ifdef __LP64__ +//64浣嶆暟鎹ā鍨 typedef long unsigned int UINT64; typedef long signed int INT64; typedef unsigned long UINTPTR; @@ -71,6 +75,7 @@ typedef INT64 ssize_t; typedef UINT64 size_t; #endif #else +//32浣嶆暟鎹ā鍨 typedef unsigned long long UINT64; typedef signed long long INT64; typedef unsigned int UINTPTR; @@ -80,7 +85,7 @@ typedef INT32 ssize_t; typedef UINT32 size_t; #endif #endif - +//涓浜涘父鏁扮殑瀹氫箟 typedef UINTPTR AARCHPTR; typedef size_t BOOL; diff --git a/鏂囪豹-鐢ㄤ緥鎻忚堪.docx b/鏂囪豹-鐢ㄤ緥鎻忚堪.docx new file mode 100644 index 0000000..a5be5e4 Binary files /dev/null and b/鏂囪豹-鐢ㄤ緥鎻忚堪.docx differ diff --git a/鏂囪豹/cppsupport/los_cppsupport.c b/鏂囪豹/cppsupport/los_cppsupport.c new file mode 100644 index 0000000..e6239ab --- /dev/null +++ b/鏂囪豹/cppsupport/los_cppsupport.c @@ -0,0 +1,74 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. + * Description: LiteOS Cpp Support Implementation + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_cppsupport_pri.h" +#include "los_printf.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +typedef VOID (*InitFunc)(VOID); + +/*------------------------------------------- +*`LITE_OS_SEC_TEXT_MINOR`、`UINTPTR`等。 +*在`LOS_CppSystemInit`函数中,它遍历了一个初始化函数的数组, +*并依次调用这些初始化函数。根据传入的`flag`参数, +*它会在特定的位置执行初始化函数。 +*--------------------------------------------*/ +LITE_OS_SEC_TEXT_MINOR INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd, INT32 flag) +{ + UINTPTR fastEnd = (UINTPTR)&__fast_end; + UINTPTR *start = (UINTPTR *)initArrayStart; + InitFunc initFunc = NULL; + +#ifdef LOSCFG_AARCH64 + __register_frame(__EH_FRAME_BEGIN__); +#endif + + for (; start != (UINTPTR *)initArrayEnd; ++start) { + if ((flag == BEFORE_SCATTER) && ((UINTPTR)*start > fastEnd)) { + continue; + } else if ((flag == AFTER_SCATTER) && ((UINTPTR)*start <= fastEnd)) { + continue; + } + + initFunc = (InitFunc)(*start); + initFunc(); + } + + return 0; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/鏂囪豹/cpup/cpup_shellcmd.c b/鏂囪豹/cpup/cpup_shellcmd.c new file mode 100644 index 0000000..8e4160b --- /dev/null +++ b/鏂囪豹/cpup/cpup_shellcmd.c @@ -0,0 +1,134 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved. + * Description: ShellCmd Cpup + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_config.h" +#ifdef LOSCFG_SHELL +#include "stdio.h" +#include "stdlib.h" +#include "los_cpup_pri.h" +#include "los_task_pri.h" +#include "shcmd.h" +#include "shell.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +VOID OsCmdCpupOperateOneParam(UINT32 mode) //根据参数mode获取系统CPU使用率的历史数据// +{ + UINT32 ret; + + if (mode == CPUP_LAST_TEN_SECONDS) { //过去10s内// + PRINTK("\nSysCpuUsage in 10s: "); + } else if (mode == CPUP_LAST_ONE_SECONDS) { //过去1s内// + PRINTK("\nSysCpuUsage in 1s: "); + } else { //历史平均CPU使用率// + PRINTK("\nSysCpuUsage in all time: "); + } + ret = LOS_HistorySysCpuUsage(mode); //获取CPU使用率的数值// + PRINTK("%u.%u", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT); +} + +VOID OsCmdCpupOperateTwoParam(UINT32 mode, UINT32 taskId) //根据参数mode获取参数taskId所指定// +{ //的任务的CPU使用率的历史数据// + UINT32 ret; + + if (mode == CPUP_LAST_TEN_SECONDS) { //过去10s内// + PRINTK("\nTaskId %u CpuUsage in 10s: ", taskId); + } else if (mode == CPUP_LAST_ONE_SECONDS) { //过去1s内// + PRINTK("\nTaskId %u CpuUsage in 1s: ", taskId); + } else { //历史平均CPU使用率// + PRINTK("\nTaskId %u CpuUsage in all time: ", taskId); + } + ret = LOS_HistoryTaskCpuUsage(taskId, mode); //获取CPU使用率的数值// + PRINTK("%u.%u", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT); +} + +LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdCpup(INT32 argc, const CHAR **argv) //根据输入的参数来获取系统或指定任务的CPU使用率// +{ + size_t mode, taskId; + CHAR *bufMode = NULL; + CHAR *bufId = NULL; + LosTaskCB *taskCB = NULL; + UINT32 ret; + + if (argc <= 0) { //检查参数个数,如果没有参数,则获取系统过去10秒的CPU使用率并打印输出// + ret = LOS_HistorySysCpuUsage(CPUP_LAST_TEN_SECONDS); + PRINTK("\nSysCpuUsage in 10s: %u.%u", ret / LOS_CPUP_PRECISION_MULT, ret % LOS_CPUP_PRECISION_MULT); + return 0; + } + + mode = strtoul(argv[0], &bufMode, 0); //将第一个参数转换为无符号整型数mode,表示CPU使用率的获取模式// +/*------------------------------------------------------------------*/ + //判断输入的mode是否有效// + if ((bufMode == NULL) || (*bufMode != 0)) { + PRINTK("\nThe input mode is invalid. Please try again.\n"); + return 0; + } + + if (mode > CPUP_ALL_TIME) { + mode = CPUP_ALL_TIME; + } +/*------------------------------------------------------------------*/ +//如果只有一个参数,则调用OsCmdCpupOperateOneParam函数来获取系统CPU使用率// + if (argc == 1) { + OsCmdCpupOperateOneParam((UINT32)mode); + return 0; + } +/*------------------------------------------------------------------*/ +//判断输入的taskId是否有效// + taskId = strtoul(argv[1], &bufId, 0); + if ((taskId >= g_taskMaxNum) || (*bufId != 0)) { + PRINTK("\nThe input taskId is invalid. Please try again.\n"); + return 0; + } + taskCB = OS_TCB_FROM_TID(taskId); + if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) { + PRINTK("\nThe task is unused. Please try again.\n"); + return 0; + } +/*-----------------------------------------------------------------*/ +//如果有两个参数,则第二个参数为任务ID,然后调用OsCmdCpupOperateTwoParam函数来获取指定任务的CPU使用率// + if (argc == 2) { + OsCmdCpupOperateTwoParam((UINT32)mode, (UINT32)taskId); + return 0; + } + + PRINTK("cpup [MODE] \ncpup [MODE] [TASKID] \n"); + return 0; +} +//通过在Shell终端输入cpup命令,根据输入相应的参数来获取CPU使用率的历史数据// +SHELLCMD_ENTRY(cpup_shellcmd, CMD_TYPE_EX, "cpup", XARGS, (CmdCallBackFunc)OsShellCmdCpup); +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif /* LOSCFG_SHELL */ diff --git a/鏂囪豹/cpup/los_cpup.c b/鏂囪豹/cpup/los_cpup.c new file mode 100644 index 0000000..688ff34 --- /dev/null +++ b/鏂囪豹/cpup/los_cpup.c @@ -0,0 +1,593 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved. + * Description : LiteOS Cpu Usage Calculation Module Implementation + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_cpup_pri.h" +#include "los_task_pri.h" +#include "los_base.h" +#include "los_swtmr.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_KERNEL_CPUP + +LITE_OS_SEC_BSS STATIC UINT16 g_cpupSwtmrId; //用于记录CPU使用率统计定时器的ID// +LITE_OS_SEC_BSS STATIC UINT16 g_cpupInitFlg = 0; //用于标记CPU使用率模块是否已经初始化// +LITE_OS_SEC_BSS OsCpupCB *g_cpup = NULL; //用于保存CPU使用率相关的信息// +LITE_OS_SEC_BSS STATIC UINT16 g_cpupMaxNum; //表示CPU使用率统计信息的最大数量// +LITE_OS_SEC_BSS STATIC UINT16 g_cpupTaskMaxNum; //表示CPU使用率统计信息的最大任务数量// +LITE_OS_SEC_BSS STATIC UINT16 g_hisPos = 0; /* current Sampling point of historyTime */ +LITE_OS_SEC_DATA_INIT STATIC UINT32 runningTasks[LOSCFG_KERNEL_CORE_NUM] = { + [0 ... (LOSCFG_KERNEL_CORE_NUM - 1)] = (UINT32)-1 +}; //用于记录每个核心上正在运行的任务的ID// +LITE_OS_SEC_BSS STATIC UINT64 cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM + 1]; + //用于保存CPU历史时间记录// +LITE_OS_SEC_BSS STATIC UINT64 g_startCycles = 0; //用于记录任务切换前的时钟周期数// +#ifdef LOSCFG_CPUP_INCLUDE_IRQ //用于判断是否包含中断相关的功能// +//若满足条件编译// +LITE_OS_SEC_BSS UINT64 g_timeInIrqPerTskSwitch[LOSCFG_KERNEL_CORE_NUM]; //用于记录每个核心上任务切换期间发生的中断的时间// +LITE_OS_SEC_BSS STATIC UINT64 g_intTimeStart[LOSCFG_KERNEL_CORE_NUM]; //用于记录每个核心上中断开始的时间// +#endif + +#define HIGH_BITS 32 + +#define CPUP_PRE_POS(pos) (((pos) == 0) ? (OS_CPUP_HISTORY_RECORD_NUM - 1) : ((pos) - 1)) +#define CPUP_POST_POS(pos) (((pos) == (OS_CPUP_HISTORY_RECORD_NUM - 1)) ? 0 : ((pos) + 1)) + +LITE_OS_SEC_TEXT_INIT OsCpupCB *OsCpupCBGet(UINT32 index) +{ + return &g_cpup[index]; +} + +/*定期更新历史时间采样点和任务的历史运行时间,以便后续计算CPU使用率*/ +LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID) +{ + UINT16 prevPos = g_hisPos; + UINT16 loop; + UINT16 runTaskId; + UINT64 curCycle; + UINT32 intSave; + + if (g_cpupInitFlg == 0) { //表示CPU使用率模块尚未初始化,直接返回// + return; + } + //若已初始化,则禁止中断,并获取当前时钟周期数// + intSave = LOS_IntLock(); + curCycle = OsCpupGetCycle(); + + g_hisPos = CPUP_POST_POS(g_hisPos); //更新历史时间采样点的位置// + cpuHistoryTime[prevPos] = curCycle; //记录本次采样的时钟周期数// + +/*更新每个任务和CPU核心的历史运行时间*/ + for (loop = 0; loop < g_cpupMaxNum; loop++) { + g_cpup[loop].historyTime[prevPos] = g_cpup[loop].allTime; + } + + for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) { + runTaskId = runningTasks[loop]; //获取该任务在当前核心上的ID// + /* reacquire the cycle to prevent flip */ + curCycle = OsCpupGetCycle(); + /*将该任务从开始到当前时刻所用的时钟周期数加入该任务在历史时间采样点上的历史运行时间中*/ + g_cpup[runTaskId].historyTime[prevPos] += curCycle - g_cpup[runTaskId].startTime; +#ifdef LOSCFG_CPUP_INCLUDE_IRQ //判断中断功能是否被包含在配置中// + /*从该任务的历史运行时间中减去该任务在任务切换期间发生的中断所用的时间*/ + g_cpup[runTaskId].historyTime[prevPos] -= g_timeInIrqPerTskSwitch[loop]; +#endif + } + + LOS_IntRestore(intSave); //恢复中断状态// +} + +/*创建一个软件定时器,以便定期更新历史时间采样点和任务的历史运行时间,从而实现CPU使用率的统计*/ +LITE_OS_SEC_TEXT_INIT VOID OsCpupGuardCreator(VOID) +{ + /*下面函数的参数分别为*/ + //设定定时器的周期是每秒钟的基本核心时钟滴答数// + //工作模式为周期模式// + //回调函数// + //定时器ID保存在g_cpupSwtmrId变量中// + //最后一个参数为0表示不携带额外参数// + (VOID)LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND, LOS_SWTMR_MODE_PERIOD, + (SWTMR_PROC_FUNC)OsCpupGuard, &g_cpupSwtmrId, 0); + + (VOID)LOS_SwtmrStart(g_cpupSwtmrId); //启动该软件定时器// +} + +/*初始化CPU使用率统计模块,其中包括创建一个最高优先级的任务, +该任务的入口函数为OsCpupGuardCreator, +用于创建和启动周期性调用OsCpupGuard()函数的软件定时器*/ +LITE_OS_SEC_TEXT_INIT VOID OsCpupGuardInit(VOID) +{ + TSK_INIT_PARAM_S taskInitParam; + UINT32 tempId; + //初始化taskInitParam,并将其内容清零// + (VOID)memset_s((void *)(&taskInitParam), sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); + taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsCpupGuardCreator; //指定任务入口函数为OsCpupGuardCreator,即创建和启动软件定时器的函数// + taskInitParam.uwStackSize = LOS_TASK_MIN_STACK_SIZE; //指定任务栈的大小为最小任务栈大小// + taskInitParam.pcName = "CpupGuardCreator"; //指定任务的名称为"CpupGuardCreator"// + taskInitParam.usTaskPrio = OS_TASK_PRIORITY_HIGHEST; //指定任务的优先级为最高优先级// + taskInitParam.uwResved = LOS_TASK_STATUS_DETACHED; //指定任务状态为LOS_TASK_STATUS_DETACHED// +#ifdef LOSCFG_KERNEL_SMP //判断操作系统是否支持多核// + taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid()); //设置任务的CPU亲和性掩码// +#endif + /*传入上述初始化好的参数taskInitParam,并将任务ID保存在tempId中*/ + (VOID)LOS_TaskCreate(&tempId, &taskInitParam); +} + +/* + * Description: initialization of CPUP + * Return : LOS_OK or Error Information + */ +LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit(VOID) +{ + UINT32 size; + + g_cpupTaskMaxNum = g_taskMaxNum; + g_cpupMaxNum = g_cpupTaskMaxNum; +/*如果配置了包含中断的CPU使用率统计(LOSCFG_CPUP_INCLUDE_IRQ), +则将g_cpupMaxNum增加LOSCFG_PLATFORM_HWI_LIMIT*/ +#ifdef LOSCFG_CPUP_INCLUDE_IRQ + g_cpupMaxNum += LOSCFG_PLATFORM_HWI_LIMIT; +#endif + + /* every task has only one record, and it won't operated at the same time */ + size = g_cpupMaxNum * sizeof(OsCpupCB); //计算需要分配的内存空间大小// + g_cpup = (OsCpupCB *)LOS_MemAlloc(m_aucSysMem0, size); //分配内存,用于存储OsCpupCB结构体数组// + if (g_cpup == NULL) { //内存分配失败// + return LOS_ERRNO_CPUP_NO_MEMORY; + } + + OsCpupGuardInit(); //初始化CPU使用率统计模块// + + (VOID)memset_s(g_cpup, size, 0, size); //将分配的内存空间清零// + g_cpupInitFlg = 1; //表示CPU使用率统计模块已经初始化完成// + + return LOS_OK; //初始化成功// +} + +LITE_OS_SEC_TEXT_INIT VOID LOS_CpupReset(VOID) //用于重置CPU使用率统计模块// +{ + UINT32 cpupIndex; + UINT32 maxNum = g_cpupMaxNum; + UINT64 curCycle; + UINT16 loop; + UINT32 intSave; + + /*检查全局变量g_cpup是否为NULL,如果是,则直接返回,不执行任何操作*/ + if (g_cpup == NULL) { + return; + } + + g_cpupInitFlg = 0; //表示CPU使用率统计模块未初始化// + intSave = LOS_IntLock(); //锁定中断,防止在重置过程中发生中断// + (VOID)LOS_SwtmrStop(g_cpupSwtmrId); //停止CPU使用率统计定时器// + curCycle = OsCpupGetCycle(); //获取当前的CPU周期数// + + /*将cpuHistoryTime数组中的所有元素都设置为curCycle,清空历史时间记录*/ + for (loop = 0; loop < (OS_CPUP_HISTORY_RECORD_NUM + 1); loop++) { + cpuHistoryTime[loop] = curCycle; + } + + /*遍历每个CPU使用率统计结构体, + 并将其起始时间和总时间都设置为curCycle, + 同时清空每个结构体中的历史时间记录*/ + for (cpupIndex = 0; cpupIndex < maxNum; cpupIndex++) { + g_cpup[cpupIndex].startTime = curCycle; + g_cpup[cpupIndex].allTime = curCycle; + for (loop = 0; loop < (OS_CPUP_HISTORY_RECORD_NUM + 1); loop++) { + g_cpup[cpupIndex].historyTime[loop] = curCycle; + } + } + +/*如果配置了包含中断的CPU使用率统计, +则将g_timeInIrqPerTskSwitch数组中的所有元素都设置为0, +用于记录任务切换期间的中断时间*/ +#ifdef LOSCFG_CPUP_INCLUDE_IRQ + for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) { + g_timeInIrqPerTskSwitch[loop] = 0; + } +#endif + + (VOID)LOS_SwtmrStart(g_cpupSwtmrId); //重新启动CPU使用率统计定时器// + LOS_IntRestore(intSave); //恢复中断状态// + g_cpupInitFlg = 1; //表示CPU使用率统计模块已经重新初始化完成// + + return; +} + +/*用于设置CPU周期数起始值,以便后面记录时间时 +能够正确计算CPU周期数的差值,从而得到时间间隔*/ +LITE_OS_SEC_TEXT_MINOR VOID OsCpupSetCycle(UINT64 startCycles) +{ + g_startCycles = startCycles; + return; +} + +/* + * Description: get current cycles count + * Return : current cycles count + */ +LITE_OS_SEC_TEXT_MINOR UINT64 OsCpupGetCycle(VOID) +{ + UINT32 high; + UINT32 low; + UINT64 cycles; + + LOS_GetCpuCycle(&high, &low); + cycles = ((UINT64)high << HIGH_BITS) + low; //将高位和低位的计数值合并成一个64位计数值// + if (g_startCycles == 0) { + g_startCycles = cycles; + } + + /* + * The cycles should keep growing, if the checking failed, + * it mean LOS_GetCpuCycle has the problem which should be fixed. + */ + LOS_ASSERT(cycles >= g_startCycles); + + return (cycles - g_startCycles); +} + +/* + * Description: start task to get cycles count in current task beginning + */ +LITE_OS_SEC_TEXT_MINOR VOID OsTaskCycleStart(VOID) //用于在任务开始时获取CPU周期计数// +{ + UINT32 taskId; + LosTaskCB *runTask = NULL; + + if (g_cpupInitFlg == 0) { //如果为0则表示还未进行CPU周期计数的初始化,直接返回// + return; + } + + runTask = OsCurrTaskGet(); //获取当前正在运行的任务// + taskId = runTask->taskId; //获取当前任务的ID// + + g_cpup[taskId].id = taskId; + g_cpup[taskId].startTime = OsCpupGetCycle(); + + return; +} + +/* + * Description: quit task and get cycle count + */ +LITE_OS_SEC_TEXT_MINOR VOID OsTaskCycleEnd(VOID) +{ + UINT32 taskId; + UINT64 cpuCycle; + LosTaskCB *runTask = NULL; + + if (g_cpupInitFlg == 0) { + return; + } + + runTask = OsCurrTaskGet(); + taskId = runTask->taskId; + + if (g_cpup[taskId].startTime == 0) { //判断是否已经记录了任务的开始时间,// + return; //若为0则表示未记录开始时间,直接返回// + } + + cpuCycle = OsCpupGetCycle(); + g_cpup[taskId].allTime += cpuCycle - g_cpup[taskId].startTime; //获取任务从开始到结束的CPU周期数// + +#ifdef LOSCFG_CPUP_INCLUDE_IRQ //如果开启了包含中断处理时间的统计,需要对任务的总运行时间进行修正// + UINT32 cpuId = ArchCurrCpuid(); + g_cpup[taskId].allTime -= g_timeInIrqPerTskSwitch[cpuId]; //减去当前CPU核心上中断处理所占用的时间 + g_timeInIrqPerTskSwitch[cpuId] = 0; +#endif + g_cpup[taskId].startTime = 0; //表示任务的运行时间统计结束// + + return; +} + +/* + * Description: start task to get cycles count in current task ending + */ +LITE_OS_SEC_TEXT_MINOR VOID OsTaskCycleEndStart(const LosTaskCB *newTask) +{ + UINT64 cpuCycle; + LosTaskCB *runTask = NULL; + OsCpupCB *cpup = NULL; + UINT32 cpuId = ArchCurrCpuid(); + + if ((g_cpupInitFlg == 0) || (newTask == NULL)) { + return; + } + + runTask = OsCurrTaskGet(); + cpuCycle = OsCpupGetCycle(); + + cpup = &g_cpup[runTask->taskId]; + if (cpup->startTime != 0) { + cpup->allTime += cpuCycle - cpup->startTime; //表示该任务之前已经开始了CPU周期计数,需要对其总运行时间进行更新// +#ifdef LOSCFG_CPUP_INCLUDE_IRQ //根据是否满足条件配置,对总运行时间进行修正// + cpup->allTime -= g_timeInIrqPerTskSwitch[cpuId]; + g_timeInIrqPerTskSwitch[cpuId] = 0; +#endif + } + + cpup = &g_cpup[newTask->taskId]; + /*将新任务的ID和当前CPU周期计数值保存,表示新任务的CPU周期计数开始*/ + cpup->id = newTask->taskId; + cpup->startTime = cpuCycle; + runningTasks[cpuId] = newTask->taskId; //更新当前CPU核心上正在运行的任务ID// + + return; +} + +/*用于获取CPU周期计数数据在数组中的位置*/ +LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos(UINT32 mode, UINT16 *curPosPointer, UINT16 *prePosPointer) +{ + UINT16 curPos; + UINT16 tmpPos; + UINT16 prePos; + + tmpPos = g_hisPos; //获取当前位置// + curPos = CPUP_PRE_POS(tmpPos); //获取前一个位置// + + /* + * The current position has nothing to do with the CPUP modes, + * however, the previous position differs. + */ + switch (mode) { + /*表示需要获取最近一秒内的CPU周期计数数据, + 此时将前一个位置设置为当前位置的前一个位置*/ + case CPUP_LAST_ONE_SECONDS: + prePos = CPUP_PRE_POS(curPos); + break; + /*表示需要获取最近十秒内的CPU周期计数数据, + 此时将前一个位置设置为当前位置*/ + case CPUP_LAST_TEN_SECONDS: + prePos = tmpPos; + break; + /*表示需要获取所有时间内的CPU周期计数数据, + 此时将前一个位置设置为数组的最后一个位置*/ + case CPUP_ALL_TIME: + /* fall-through */ + default: + prePos = OS_CPUP_HISTORY_RECORD_NUM; + break; + } + + *curPosPointer = curPos; //保存当前位置// + *prePosPointer = prePos; //保存前一个位置// + + return; +} + +/*用于检查CPU使用率统计参数的合法性*/ +LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsCpuUsageParaCheck(UINT32 taskId) +{ + if (g_cpupInitFlg == 0) { + return LOS_ERRNO_CPUP_NO_INIT; + } + + if (OS_TSK_GET_INDEX(taskId) >= g_taskMaxNum) { //任务ID索引值超过了最大任务数,// + return LOS_ERRNO_CPUP_TSK_ID_INVALID; //表示任务ID无效,返回错误码// + } + + /* weather the task is created */ + if (g_cpup[taskId].id != taskId) { + return LOS_ERRNO_CPUP_THREAD_NO_CREATED; //表示该任务尚未创建,返回错误码// + } + + if ((g_cpup[taskId].status & OS_TASK_STATUS_UNUSED) || (g_cpup[taskId].status == 0)) { + return LOS_ERRNO_CPUP_THREAD_NO_CREATED; //表示该任务尚未创建,返回错误码// + } + + return LOS_OK; //表示通过检查// +} + +LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage(UINT32 mode) //用于获取历史系统CPU使用率// +{ + UINT64 cpuCycleAll; + UINT64 idleCycleAll = 0; + UINT32 cpup = 0; + UINT16 pos; + UINT16 prePos; + UINT32 intSave; + UINT32 idleTaskId; +#ifdef LOSCFG_KERNEL_SMP + UINT32 cpuId = 0; +#endif + + if (g_cpupInitFlg == 0) { + return LOS_ERRNO_CPUP_NO_INIT; + } + + /* get end time of current task */ + intSave = LOS_IntLock(); //锁定中断状态// + OsTaskCycleEnd(); //获取当前任务的结束时间// + + OsCpupGetPos(mode, &pos, &prePos); //获取历史CPU使用率数据的位置信息// + cpuCycleAll = cpuHistoryTime[pos] - cpuHistoryTime[prePos]; //计算CPU的总周期数// + +#ifdef LOSCFG_KERNEL_SMP //判断是否为SMP系统// + /* For SMP system, each idle task needs to be accounted */ + while (cpuId < LOSCFG_KERNEL_CORE_NUM) { + idleTaskId = g_percpu[cpuId].idleTaskId; + //累加各核心的空闲任务的周期数到idleCycleAll中// + idleCycleAll += g_cpup[idleTaskId].historyTime[pos] - g_cpup[idleTaskId].historyTime[prePos]; + cpuId++; + } + cpuCycleAll *= LOSCFG_KERNEL_CORE_NUM; +#else + idleTaskId = OsGetIdleTaskId(); //直接获取空闲任务的周期数。// + idleCycleAll = g_cpup[idleTaskId].historyTime[pos] - g_cpup[idleTaskId].historyTime[prePos]; +#endif + + if (cpuCycleAll) { + cpup = (LOS_CPUP_PRECISION - (UINT32)((LOS_CPUP_PRECISION * idleCycleAll) / cpuCycleAll)); + } //得出CPU使用率// + + OsTaskCycleStart(); //重新开始任务的时间统计// + LOS_IntRestore(intSave); //恢复中断状态// + + return cpup; +} + +LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage(UINT32 taskId, UINT32 mode) +{ + UINT64 cpuCycleAll; + UINT64 cpuCycleCurTask; + UINT16 pos; + UINT16 prePos; + UINT32 intSave; + UINT32 cpup = 0; + UINT32 ret; + + if (g_cpupInitFlg == 0) { + return LOS_ERRNO_CPUP_NO_INIT; + } + + //对传入的任务ID进行参数检查,检查结果不等于LOS_OK,则返回相应的错误码// + ret = OsCpuUsageParaCheck(taskId); + if (ret != LOS_OK) { + return ret; + } + OsCpupCB *taskCpup = &g_cpup[taskId]; + + intSave = LOS_IntLock(); + OsTaskCycleEnd(); + + OsCpupGetPos(mode, &pos, &prePos); //获取历史CPU使用率数据的位置信息// + cpuCycleAll = cpuHistoryTime[pos] - cpuHistoryTime[prePos]; //计算CPU的总周期数// + cpuCycleCurTask = taskCpup->historyTime[pos] - taskCpup->historyTime[prePos]; //计算当前任务的CPU周期数// + if (cpuCycleAll) { + cpup = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurTask) / cpuCycleAll); + } //计算得出CPU使用率// + + OsTaskCycleStart(); + LOS_IntRestore(intSave); + + return cpup; +} + +//用于获取所有任务历史CPU使用率// +LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT32 mode, UINT16 flag) +{ + UINT16 loop; + UINT16 pos; + UINT16 prePos; + UINT32 intSave; + UINT64 cpuCycleAll; + UINT64 cpuCycleCurTask; + UINT16 numTmpMax = maxNum; + UINT16 numTmpMin = 0; + UINT16 numMax = g_cpupTaskMaxNum; + + if (g_cpupInitFlg == 0) { + return LOS_ERRNO_CPUP_NO_INIT; + } + + if (cpupInfo == NULL) { //检查传入的指针cpupInfo是否为空,如果为空,返回错误码// + return LOS_ERRNO_CPUP_TASK_PTR_NULL; + } + + if (maxNum == 0) { //检查传入的maxNum是否等于0,如果等于0,返回错误码// + return LOS_ERRNO_CPUP_MAXNUM_INVALID; + } + +#ifdef LOSCFG_CPUP_INCLUDE_IRQ //如果宏被定义// + if (flag == 0) { + numTmpMax += g_cpupTaskMaxNum; + numTmpMin += g_cpupTaskMaxNum; + numMax = g_cpupMaxNum; + } +#endif + + if (numTmpMax > numMax) { + numTmpMax = numMax; + } + + intSave = LOS_IntLock(); + OsTaskCycleEnd(); + + OsCpupGetPos(mode, &pos, &prePos); //获取历史CPU使用率数据的位置信息// + cpuCycleAll = cpuHistoryTime[pos] - cpuHistoryTime[prePos]; //计算CPU的总周期数// + + /*通过循环遍历所有任务的CPU使用率数据,计算当前任务的CPU周期数并保存*/ + for (loop = numTmpMin; loop < numTmpMax; loop++) { + if ((g_cpup[loop].status & OS_TASK_STATUS_UNUSED) || (g_cpup[loop].status == 0)) { + continue; + } + + cpuCycleCurTask = g_cpup[loop].historyTime[pos] - g_cpup[loop].historyTime[prePos]; + cpupInfo[loop - numTmpMin].usStatus = g_cpup[loop].status; + + if (cpuCycleAll) { + cpupInfo[loop - numTmpMin].uwUsage = (UINT32)((LOS_CPUP_PRECISION * cpuCycleCurTask) / cpuCycleAll); + } + } + + OsTaskCycleStart(); + LOS_IntRestore(intSave); + + return LOS_OK; +} + +#ifdef LOSCFG_CPUP_INCLUDE_IRQ +/*用于在中断开始时记录当前的时钟周期数,以便于后续做中断处理时间的统计和分析*/ +LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart(VOID) +{ + g_intTimeStart[ArchCurrCpuid()] = OsCpupGetCycle(); + return; +} + +/*在中断结束时进行统计操作, +包括记录中断号、更新中断期间任务切换的时间以及累加中断期间的总时间*/ +LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd(UINT32 intNum) +{ + UINT64 intTimeEnd = OsCpupGetCycle(); //获取当前的时钟周期数// + UINT32 cpuId = ArchCurrCpuid(); //获取当前CPU的ID// + + if (g_cpupInitFlg == 0) { + return; + } + + g_cpup[g_taskMaxNum + intNum].id = intNum; + g_cpup[g_taskMaxNum + intNum].status = OS_TASK_STATUS_RUNNING; //将中断状态设为运行中// + g_timeInIrqPerTskSwitch[cpuId] += (intTimeEnd - g_intTimeStart[cpuId]); //增加中断期间任务切换所消耗的时间// + g_cpup[g_taskMaxNum + intNum].allTime += (intTimeEnd - g_intTimeStart[cpuId]); + + return; +} +#endif + +#endif /* LOSCFG_KERNEL_CPUP */ +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + diff --git a/鏂囪豹/los_cppsupport_pri.h b/鏂囪豹/los_cppsupport_pri.h new file mode 100644 index 0000000..5e3fcb9 --- /dev/null +++ b/鏂囪豹/los_cppsupport_pri.h @@ -0,0 +1,53 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. + * Description: Cpp Support HeadFile + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#ifndef _LOS_CPPSUPPORT_PRI_H +#define _LOS_CPPSUPPORT_PRI_H //防止多次包含同一个头文件// + +#include "los_cppsupport.h" + +#ifdef __cplusplus //根据编译器是否为C++// +#if __cplusplus //来使用“extern 'C'”// +extern "C" { //对以下代码块内容进行// +#endif /* __cplusplus */ //正确处理函数名// +#endif /* __cplusplus */ + +extern CHAR __fast_end; //声明一个_fast_end的CHAR类型变量// + +#ifdef LOSCFG_AARCH64 //条件编译// +extern UINT8 __EH_FRAME_BEGIN__[]; //声明一个UINT8类型的数组// +VOID __register_frame(VOID *begin); +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ //关闭extern'C'作用域// +#endif /* __cplusplus */ + +#endif /* _LOS_CPPSUPPORT_PRI_H */ diff --git a/鏂囪豹/los_cpup_pri.h b/鏂囪豹/los_cpup_pri.h new file mode 100644 index 0000000..f8da73e --- /dev/null +++ b/鏂囪豹/los_cpup_pri.h @@ -0,0 +1,74 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved. + * Description: Cpup HeadFile + * Author: Huawei LiteOS Team + * Create: 2013-01-01 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#ifndef _LOS_CPUP_PRI_H +#define _LOS_CPUP_PRI_H //防止多次包含同一个头文件// + +#include "los_cpup.h" //可能包含了一些与CPU使用率// +#include "los_task_pri.h" //统计相关的公共声明和定义// + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define OS_CPUP_HISTORY_RECORD_NUM 11 //定义历史记录的数量为11// +#define LOS_CPUP_PRECISION 1000 //定义CPU使用率的精度为1000// +#define LOS_CPUP_PRECISION_MULT (LOS_CPUP_PRECISION / 100) //可能用于计算CPU使用率// + +typedef struct { + UINT32 id; /* Task ID */ + UINT16 status; /* Task status */ + UINT64 allTime; /* Total running time */ + UINT64 startTime; /* Time before a task is invoked */ + UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM + 1]; /* Historical running time, the last one saves zero */ +} OsCpupCB; + +extern OsCpupCB *OsCpupCBGet(UINT32 index); //根据索引获取 `OsCpupCB` 结构体指针// +extern UINT32 OsCpupInit(VOID); //CPU使用率统计模块的初始化函数// +extern VOID OsCpupSetCycle(UINT64 startCycles); //设置CPU周期计数// +extern UINT64 OsCpupGetCycle(VOID); //获取CPU周期计数// +extern VOID OsTaskCycleStart(VOID); //任务运行周期的起始// +extern VOID OsTaskCycleEnd(VOID); //任务运行周期的结束// +extern VOID OsTaskCycleEndStart(const LosTaskCB *newTask); //更新任务运行周期,并开始新的任务周期// +#ifdef LOSCFG_CPUP_INCLUDE_IRQ +VOID OsCpupIrqStart(VOID); //在前一条条件定义下,用于处理// +VOID OsCpupIrqEnd(UINT32); //中断的CPU使用率统计函数// +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_CPUP_PRI_H */ + +/*这段代码定义了一些用于CPU使用率统计的数据结构和函数声明, +用于在操作系统中实现对任务和中断的CPU利用率进行监控和统计。*/ \ No newline at end of file diff --git a/鏂囪豹/los_trace_pri.h b/鏂囪豹/los_trace_pri.h new file mode 100644 index 0000000..762fd9f --- /dev/null +++ b/鏂囪豹/los_trace_pri.h @@ -0,0 +1,150 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved. + * Description: LiteOS Trace Module Private HeadFile + * Author: Huawei LiteOS Team + * Create: 2019-08-30 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#ifndef _LOS_TRACE_PRI_H +#define _LOS_TRACE_PRI_H + +#include "los_trace.h" +#include "los_task_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_TRACE_CONTROL_AGENT +#define TRACE_CMD_END_CHAR 0xD +#endif + +#define TRACE_ERROR PRINT_ERR +#define TRACE_MODE_OFFLINE 0 +#define TRACE_MODE_ONLINE 1 + +/* just task and hwi were traced */ +#define TRACE_DEFAULT_MASK (TRACE_HWI_FLAG | TRACE_TASK_FLAG) +#define TRACE_CTL_MAGIC_NUM 0xDEADBEEF +#define TRACE_BIGLITTLE_WORD 0x12345678 +#define TRACE_VERSION(MODE) (0xFFFFFFFF & (MODE)) +#define TRACE_MASK_COMBINE(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4)) + +#define TRACE_GET_MODE_FLAG(type) ((type) & 0xFFFFFFF0) + +extern SPIN_LOCK_S g_traceSpin; +#define TRACE_LOCK(state) LOS_SpinLockSave(&g_traceSpin, &(state)) +#define TRACE_UNLOCK(state) LOS_SpinUnlockRestore(&g_traceSpin, (state)) + +typedef VOID (*TRACE_DUMP_HOOK)(BOOL toClient); +extern TRACE_DUMP_HOOK g_traceDumpHook; + +enum TraceCmd { + TRACE_CMD_START = 1, + TRACE_CMD_STOP, + TRACE_CMD_SET_EVENT_MASK, + TRACE_CMD_RECODE_DUMP, + TRACE_CMD_MAX_CODE, +}; + +/** + * @ingroup los_trace + * struct to store the trace cmd from traceClient. + */ +typedef struct { + UINT8 cmd; + UINT8 param1; + UINT8 param2; + UINT8 param3; + UINT8 param4; + UINT8 param5; + UINT8 end; +} TraceClientCmd; + +/** + * @ingroup los_trace + * struct to store the event infomation + */ +typedef struct { + UINT32 cmd; /* trace start or stop cmd */ + UINT32 param; /* magic numb stand for notify msg */ +} TraceNotifyFrame; + +/** + * @ingroup los_trace + * struct to store the trace config information. + */ +typedef struct { + struct WriteCtrl { + UINT16 curIndex; /* The current record index */ + UINT16 maxRecordCount; /* The max num of track items */ + UINT16 curObjIndex; /* The current obj index */ + UINT16 maxObjCount; /* The max num of obj index */ + ObjData *objBuf; /* Pointer to obj info data */ + TraceEventFrame *frameBuf; /* Pointer to the track items */ + } ctrl; + OfflineHead *head; +} TraceOfflineHeaderInfo; + +extern UINT32 OsTraceGetMaskTid(UINT32 taskId); +extern VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb); +extern VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame); +extern UINT32 OsTraceBufInit(VOID *buf, UINT32 size); +extern VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId); +extern BOOL OsTraceIsEnable(VOID); +extern OfflineHead *OsTraceRecordGet(VOID); + +#ifdef LOSCFG_RECORDER_MODE_ONLINE +extern VOID OsTraceSendHead(VOID); +extern VOID OsTraceSendObjTable(VOID); +extern VOID OsTraceSendNotify(UINT32 type, UINT32 value); + +#define OsTraceNotifyStart() do { \ + OsTraceSendNotify(SYS_START, TRACE_CTL_MAGIC_NUM); \ + OsTraceSendHead(); \ + OsTraceSendObjTable(); \ + } while (0) + +#define OsTraceNotifyStop() do { \ + OsTraceSendNotify(SYS_STOP, TRACE_CTL_MAGIC_NUM); \ + } while (0) + +#define OsTraceReset() +#define OsTraceRecordDump(toClient) +#else +extern VOID OsTraceReset(VOID); +extern VOID OsTraceRecordDump(BOOL toClient); +#define OsTraceNotifyStart() +#define OsTraceNotifyStop() +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_TRACE_PRI_H */ diff --git a/鏂囪豹/trace/los_trace.c b/鏂囪豹/trace/los_trace.c new file mode 100644 index 0000000..1f19ec2 --- /dev/null +++ b/鏂囪豹/trace/los_trace.c @@ -0,0 +1,424 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved. + * Description: LiteOS Trace Implementation + * Author: Huawei LiteOS Team + * Create: 2019-08-31 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ +#include "uart.h" +#include "los_trace_pri.h" +#include "trace_pipeline.h" + +#ifdef LOSCFG_KERNEL_SMP +#include "los_mp_pri.h" +#endif + +#ifdef LOSCFG_SHELL +#include "shcmd.h" +#include "shell.h" +#endif + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_KERNEL_TRACE +LITE_OS_SEC_BSS STATIC UINT32 g_traceEventCount; //追踪事件计数// +LITE_OS_SEC_BSS STATIC volatile enum TraceState g_traceState = TRACE_UNINIT; //追踪状态// +LITE_OS_SEC_DATA_INIT STATIC volatile BOOL g_enableTrace = FALSE; //是否启用追踪功能// +LITE_OS_SEC_BSS STATIC UINT32 g_traceMask = TRACE_DEFAULT_MASK; //追踪掩码,用于过滤追踪事件// + +#ifdef LOSCFG_TRACE_CONTROL_AGENT +LITE_OS_SEC_BSS STATIC UINT32 g_traceTaskId; //追踪任务的ID// +#endif + +#define EVENT_MASK 0xFFFFFFF0 +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + +LITE_OS_SEC_BSS STATIC TRACE_HWI_FILTER_HOOK g_traceHwiFliterHook = NULL; + +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_traceSpin); + +STATIC_INLINE BOOL OsTraceHwiFilter(UINT32 hwiNum) //用于判断是否需要过滤某个硬件中断// +{ + BOOL ret = ((hwiNum == NUM_HAL_INTERRUPT_UART) || (hwiNum == OS_TICK_INT_NUM)); +#ifdef LOSCFG_KERNEL_SMP + ret |= (hwiNum == LOS_MP_IPI_SCHEDULE); +#endif + if (g_traceHwiFliterHook != NULL) { + ret |= g_traceHwiFliterHook(hwiNum); + } + return ret; +} + +//用于设置追踪事件的帧信息// +STATIC VOID OsTraceSetFrame(TraceEventFrame *frame, UINT32 eventType, UINTPTR identity, const UINTPTR *params, + UINT16 paramCount) +{ + INT32 i; + UINT32 intSave; + + (VOID)memset_s(frame, sizeof(TraceEventFrame), 0, sizeof(TraceEventFrame)); + + if (paramCount > LOSCFG_TRACE_FRAME_MAX_PARAMS) { + paramCount = LOSCFG_TRACE_FRAME_MAX_PARAMS; + } + + TRACE_LOCK(intSave); + frame->curTask = OsTraceGetMaskTid(OsCurrTaskGet()->taskId); + frame->identity = identity; + frame->curTime = HalClockGetCycles(); + frame->eventType = eventType; + +#ifdef LOSCFG_TRACE_FRAME_CORE_MSG + frame->core.cpuId = ArchCurrCpuid(); //CPU的ID// + frame->core.hwiActive = OS_INT_ACTIVE ? TRUE : FALSE; //硬件中断活动状态// + frame->core.taskLockCnt = MIN(OsPercpuGet()->taskLockCnt, 0xF); /* taskLockCnt is 4 bits, max vaule = 0xF */ //任务锁计数// + frame->core.paramCount = paramCount; //参数数目// +#endif + +#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT + frame->eventCount = g_traceEventCount; //追踪事件的计数// + g_traceEventCount++; +#endif + TRACE_UNLOCK(intSave); + + for (i = 0; i < paramCount; i++) { + frame->params[i] = params[i]; + } +} + +VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb) //设置对象的追踪信息// +{ + errno_t ret; + (VOID)memset_s(obj, sizeof(ObjData), 0, sizeof(ObjData)); + + obj->id = OsTraceGetMaskTid(tcb->taskId); //获取任务ID// + obj->prio = tcb->priority; //获取任务优先级// + + ret = strncpy_s(obj->name, LOSCFG_TRACE_OBJ_MAX_NAME_SIZE, tcb->taskName, LOSCFG_TRACE_OBJ_MAX_NAME_SIZE - 1); + if (ret != EOK) { + TRACE_ERROR("Task name copy failed!\n"); + } +} + +//处理追踪事件钩子// +VOID OsTraceHook(UINT32 eventType, UINTPTR identity, const UINTPTR *params, UINT16 paramCount) +{ + if ((eventType == TASK_CREATE) || (eventType == TASK_PRIOSET)) { + OsTraceObjAdd(eventType, identity); /* handle important obj info, these can not be filtered */ + } + + if ((g_enableTrace == TRUE) && (eventType & g_traceMask)) { + UINTPTR id = identity; + if (TRACE_GET_MODE_FLAG(eventType) == TRACE_HWI_FLAG) { + if (OsTraceHwiFilter(identity)) { + return; + } + } else if (TRACE_GET_MODE_FLAG(eventType) == TRACE_TASK_FLAG) { + id = OsTraceGetMaskTid(identity); + } else if (eventType == MEM_INFO_REQ) { + LOS_MEM_POOL_STATUS status; + LOS_MemInfoGet((VOID *)identity, &status); + LOS_TRACE(MEM_INFO, identity, status.uwTotalUsedSize, status.uwTotalFreeSize); + return; + } + + TraceEventFrame frame; + OsTraceSetFrame(&frame, eventType, id, params, paramCount); + + OsTraceWriteOrSendEvent(&frame); //将追踪事件信息写入或发送出去// + } +} + +BOOL OsTraceIsEnable(VOID) //判断追踪是否处于启用状态// +{ + return g_enableTrace == TRUE; +} + +STATIC VOID OsTraceHookInstall(VOID) //安装追踪钩子// +{ + g_traceEventHook = OsTraceHook; +#ifdef LOSCFG_RECORDER_MODE_OFFLINE + g_traceDumpHook = OsTraceRecordDump; //在离线记录模式下设置追踪转储钩子// +#endif +} + +#ifdef LOSCFG_TRACE_CONTROL_AGENT +STATIC BOOL OsTraceCmdIsValid(const TraceClientCmd *msg) //判断传入的TraceClientCmd结构体是否有效// +{ + return ((msg->end == TRACE_CMD_END_CHAR) && (msg->cmd < TRACE_CMD_MAX_CODE)); +} + +STATIC VOID OsTraceCmdHandle(const TraceClientCmd *msg) //处理传入的TraceClientCmd结构体// +{ + if (!OsTraceCmdIsValid(msg)) { + return; + } + + switch (msg->cmd) { + case TRACE_CMD_START: //启动追踪// + LOS_TraceStart(); + break; + case TRACE_CMD_STOP: //停止追踪// + LOS_TraceStop(); + break; + case TRACE_CMD_SET_EVENT_MASK: //设置事件掩码// + /* 4 params(UINT8) composition the mask(UINT32) */ + LOS_TraceEventMaskSet(TRACE_MASK_COMBINE(msg->param1, msg->param2, msg->param3, msg->param4)); + break; + case TRACE_CMD_RECODE_DUMP: //追踪记录转储// + LOS_TraceRecordDump(TRUE); + break; + default: + break; + } +} + +VOID TraceAgent(VOID) //不断等待追踪数据的到达,并处理接收到的追踪命令// +{ + UINT32 ret; + TraceClientCmd msg; + + while (1) { + (VOID)memset_s(&msg, sizeof(TraceClientCmd), 0, sizeof(TraceClientCmd)); + ret = OsTraceDataWait(); + if (ret == LOS_OK) { + OsTraceDataRecv((UINT8 *)&msg, sizeof(TraceClientCmd), 0); + OsTraceCmdHandle(&msg); + } + } +} + +STATIC UINT32 OsCreateTraceAgentTask(VOID) //创建一个追踪代理任务,用于执行追踪逻辑// +{ + UINT32 ret; + TSK_INIT_PARAM_S taskInitParam; + + (VOID)memset_s((VOID *)(&taskInitParam), sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S)); + taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)TraceAgent; + taskInitParam.usTaskPrio = LOSCFG_TRACE_TASK_PRIORITY; + taskInitParam.pcName = "TraceAgent"; + taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; +#ifdef LOSCFG_KERNEL_SMP + taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid()); +#endif + ret = LOS_TaskCreate(&g_traceTaskId, &taskInitParam); + return ret; +} +#endif + +UINT32 LOS_TraceInit(VOID *buf, UINT32 size) //初始化追踪功能// +{ + UINT32 intSave; + UINT32 ret; + + TRACE_LOCK(intSave); + if (g_traceState != TRACE_UNINIT) { + TRACE_ERROR("trace has been initialized already, the current state is :%d\n", g_traceState); + ret = LOS_ERRNO_TRACE_ERROR_STATUS; + goto LOS_ERREND; + } + +#ifdef LOSCFG_TRACE_CLIENT_INTERACT //判断是否需要初始化追踪管道// + ret = OsTracePipelineInit(); + if (ret != LOS_OK) { + goto LOS_ERREND; + } +#endif + +#ifdef LOSCFG_TRACE_CONTROL_AGENT //判断是否需要创建追踪代理任务// + ret = OsCreateTraceAgentTask(); + if (ret != LOS_OK) { + TRACE_ERROR("trace init create agentTask error :0x%x\n", ret); + goto LOS_ERREND; + } +#endif + + ret = OsTraceBufInit(buf, size); //初始化追踪缓冲区// + if (ret != LOS_OK) { + goto LOS_RELEASE; + } + + OsTraceHookInstall(); //安装追踪钩子// + + g_traceEventCount = 0; + + /*判断是否需要等待追踪客户端启动追踪*/ +#ifdef LOSCFG_RECORDER_MODE_ONLINE /* Wait trace client to start trace */ + g_enableTrace = FALSE; + g_traceState = TRACE_INITED; +#else + g_enableTrace = TRUE; + g_traceState = TRACE_STARTED; +#endif + TRACE_UNLOCK(intSave); + return LOS_OK; +LOS_RELEASE: +#ifdef LOSCFG_TRACE_CONTROL_AGENT //判断是否需要删除追踪代理任务// + LOS_TaskDelete(g_traceTaskId); +#endif +LOS_ERREND: + TRACE_UNLOCK(intSave); + return ret; +} + +UINT32 LOS_TraceStart(VOID) //用于启动追踪功能// +{ + UINT32 intSave; + UINT32 ret = LOS_OK; + + TRACE_LOCK(intSave); + if (g_traceState == TRACE_STARTED) { + goto START_END; + } + + if (g_traceState == TRACE_UNINIT) { + TRACE_ERROR("trace not inited, be sure LOS_TraceInit excute success\n"); + ret = LOS_ERRNO_TRACE_ERROR_STATUS; + goto START_END; + } + + OsTraceNotifyStart(); //通知追踪功能开始工作// + + g_enableTrace = TRUE; + g_traceState = TRACE_STARTED; + + TRACE_UNLOCK(intSave); + LOS_TRACE(MEM_INFO_REQ, m_aucSysMem0); //发送追踪信息// + return ret; +START_END: + TRACE_UNLOCK(intSave); + return ret; +} + +VOID LOS_TraceStop(VOID) //用于停止追踪功能// +{ + UINT32 intSave; + + TRACE_LOCK(intSave); + if (g_traceState != TRACE_STARTED) { + goto STOP_END; + } + + g_enableTrace = FALSE; + g_traceState = TRACE_STOPED; + OsTraceNotifyStop(); //通知追踪功能停止工作// +STOP_END: + TRACE_UNLOCK(intSave); +} + +VOID LOS_TraceEventMaskSet(UINT32 mask) //设置追踪事件掩码// +{ + g_traceMask = mask & EVENT_MASK; +} + +VOID LOS_TraceRecordDump(BOOL toClient) //转储追踪记录// +{ + if (g_traceState != TRACE_STOPED) { + TRACE_ERROR("trace dump must after trace stopped , the current state is : %d\n", g_traceState); + return; + } + OsTraceRecordDump(toClient); +} + +OfflineHead *LOS_TraceRecordGet(VOID) //获取追踪记录// +{ + return OsTraceRecordGet(); +} + +VOID LOS_TraceReset(VOID) //重置追踪功能// +{ + if (g_traceState == TRACE_UNINIT) { + TRACE_ERROR("trace not inited, be sure LOS_TraceInit excute success\n"); + return; + } + + OsTraceReset(); +} + +VOID LOS_TraceHwiFilterHookReg(TRACE_HWI_FILTER_HOOK hook) //注册中断过滤钩子// +{ + UINT32 intSave; + + TRACE_LOCK(intSave); + g_traceHwiFliterHook = hook; + TRACE_UNLOCK(intSave); +} + +#ifdef LOSCFG_SHELL +LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTraceSetMask(INT32 argc, const CHAR **argv) //设置追踪事件掩码// +{ + size_t mask; + CHAR *endPtr = NULL; + + if (argc >= 2) { /* 2:Just as number of parameters */ + PRINTK("\nUsage: trace_mask or trace_mask ID\n"); + return OS_ERROR; + } + + if (argc == 0) { + mask = TRACE_DEFAULT_MASK; + } else { + mask = strtoul(argv[0], &endPtr, 0); + } + LOS_TraceEventMaskSet((UINT32)mask); + return LOS_OK; +} + +LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTraceDump(INT32 argc, const CHAR **argv) //进行追踪记录的转储// +{ + BOOL toClient; + CHAR *endPtr = NULL; + + if (argc >= 2) { /* 2:Just as number of parameters */ + PRINTK("\nUsage: trace_dump or trace_dump [1/0]\n"); + return OS_ERROR; + } + + if (argc == 0) { + toClient = FALSE; + } else { + toClient = strtoul(argv[0], &endPtr, 0) != 0 ? TRUE : FALSE; + } + LOS_TraceRecordDump(toClient); + return LOS_OK; +} + +/*命令行函数的注册*/ +SHELLCMD_ENTRY(tracestart_shellcmd, CMD_TYPE_EX, "trace_start", 0, (CmdCallBackFunc)LOS_TraceStart); //追踪功能的启动// +SHELLCMD_ENTRY(tracestop_shellcmd, CMD_TYPE_EX, "trace_stop", 0, (CmdCallBackFunc)LOS_TraceStop); //追踪功能的停止// +SHELLCMD_ENTRY(tracesetmask_shellcmd, CMD_TYPE_EX, "trace_mask", 1, (CmdCallBackFunc)OsShellCmdTraceSetMask); //设置追踪事件掩码// +SHELLCMD_ENTRY(tracereset_shellcmd, CMD_TYPE_EX, "trace_reset", 0, (CmdCallBackFunc)LOS_TraceReset); //重置追踪记录// +SHELLCMD_ENTRY(tracedump_shellcmd, CMD_TYPE_EX, "trace_dump", 1, (CmdCallBackFunc)OsShellCmdTraceDump); //转储追踪记录// +#endif + +#endif /* LOSCFG_KERNEL_TRACE */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/鏂囪豹/trace/pipeline/serial/trace_pipeline_serial.c b/鏂囪豹/trace/pipeline/serial/trace_pipeline_serial.c new file mode 100644 index 0000000..e61300b --- /dev/null +++ b/鏂囪豹/trace/pipeline/serial/trace_pipeline_serial.c @@ -0,0 +1,98 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Pipeline of Serial Implementation + * Author: Huawei LiteOS Team + * Create: 2020-03-31 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "trace_pipeline_serial.h" +#include "trace_pipeline.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_TRACE_CONTROL_AGENT +UINT32 SerialPipelineInit(VOID) //用于初始化串行管道// +{ + return uart_hwiCreate(); +} + +UINT32 SerialDataReceive(UINT8 *data, UINT32 size, UINT32 timeout) //用于从串行管道接收数据// +{ + return uart_read(data, size, timeout); +} + +UINT32 SerialWait(VOID) //用于等待串行管道准备就绪// +{ + return uart_wait_adapt(); +} + +#else//4号车,密码2930 + +UINT32 SerialPipelineInit(VOID) //表示初始化成功// +{ + return LOS_OK; +} + +UINT32 SerialDataReceive(UINT8 *data, UINT32 size, UINT32 timeout) //表示接收到了数据// +{ + return LOS_OK; +} + +UINT32 SerialWait(VOID) //表示已经准备就绪// +{ + return LOS_OK; +} +#endif + +VOID SerialDataSend(UINT16 len, UINT8 *data) //用于向串行管道发送数据// +{ + UINT32 i; + + for (i = 0; i < len; i++) { + UART_PUTC(data[i]); + } +} + +STATIC const TracePipelineOps g_serialOps = { + .init = SerialPipelineInit, + .dataSend = SerialDataSend, + .dataRecv = SerialDataReceive, + .wait = SerialWait, +}; + +UINT32 OsTracePipelineInit(VOID) //用于初始化追踪管道并注册与之相关的操作接口// +{ + OsTracePipelineReg(&g_serialOps); + return g_serialOps.init(); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/鏂囪豹/trace/pipeline/serial/trace_pipeline_serial.h b/鏂囪豹/trace/pipeline/serial/trace_pipeline_serial.h new file mode 100644 index 0000000..a3cf977 --- /dev/null +++ b/鏂囪豹/trace/pipeline/serial/trace_pipeline_serial.h @@ -0,0 +1,50 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Pipeline of Serial Implementation HeadFile + * Author: Huawei LiteOS Team + * Create: 2020-03-16 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#ifndef _TRACE_PIPELINE_SERIAL_H +#define _TRACE_PIPELINE_SERIAL_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +extern INT32 uart_putc(CHAR c); //用于向串口发送一个字符// + +#define UART_PUTC(c) uart_putc((c)) //调用uart_putc函数// + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _TRACE_PIPELINE_SERIAL_H */ diff --git a/鏂囪豹/trace/pipeline/trace_pipeline.c b/鏂囪豹/trace/pipeline/trace_pipeline.c new file mode 100644 index 0000000..33e5f63 --- /dev/null +++ b/鏂囪豹/trace/pipeline/trace_pipeline.c @@ -0,0 +1,156 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Pipeline Implementation + * Author: Huawei LiteOS Team + * Create: 2020-03-31 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "trace_pipeline.h" +#include "trace_tlv.h" +#include "los_trace_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +//防止缓冲区溢出// +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_pipeSpin); //初始化一个自旋锁// +#define PIPE_LOCK(state) LOS_SpinLockSave(&g_pipeSpin, &(state)) //对自旋锁加锁操作// +#define PIPE_UNLOCK(state) LOS_SpinUnlockRestore(&g_pipeSpin, (state)) //对自旋锁解锁操作// + +STATIC TlvTable g_traceTlvTblNotify[] = { //定义结构体的成员变量类型和大小// + { CMD, LOS_OFF_SET_OF(TraceNotifyFrame, cmd), sizeof(UINT32) }, + { PARAMS, LOS_OFF_SET_OF(TraceNotifyFrame, param), sizeof(UINT32) }, + { TRACE_TLV_TYPE_NULL, 0, 0 }, +}; + +STATIC TlvTable g_traceTlvTblHead[] = { //定义结构体的成员变量类型和大小// + { ENDIAN, LOS_OFF_SET_OF(TraceBaseHeaderInfo, bigLittleEndian), sizeof(UINT32) }, + { VERSION, LOS_OFF_SET_OF(TraceBaseHeaderInfo, version), sizeof(UINT32) }, + { CLOCK_FREQ, LOS_OFF_SET_OF(TraceBaseHeaderInfo, clockFreq), sizeof(UINT32) }, + { TRACE_TLV_TYPE_NULL, 0, 0 }, +}; + +STATIC TlvTable g_traceTlvTblObj[] = { //定义结构体的成员变量类型、偏移位置和大小// + { ADDR, LOS_OFF_SET_OF(ObjData, id), sizeof(UINT32) }, + { PRIO, LOS_OFF_SET_OF(ObjData, prio), sizeof(UINT32) }, + { NAME, LOS_OFF_SET_OF(ObjData, name), sizeof(CHAR) * LOSCFG_TRACE_OBJ_MAX_NAME_SIZE }, + { TRACE_TLV_TYPE_NULL, 0, 0 }, +}; + +STATIC TlvTable g_traceTlvTblEvent[] = { //定义结构体的成员变量类型和大小// +#ifdef LOSCFG_TRACE_FRAME_CORE_MSG + { CORE, LOS_OFF_SET_OF(TraceEventFrame, core), sizeof(UINT32) }, +#endif + { EVENT_CODE, LOS_OFF_SET_OF(TraceEventFrame, eventType), sizeof(UINT32) }, + { CUR_TIME, LOS_OFF_SET_OF(TraceEventFrame, curTime), sizeof(UINT64) }, + +#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT + { EVENT_COUNT, LOS_OFF_SET_OF(TraceEventFrame, eventCount), sizeof(UINT32) }, +#endif + { CUR_TASK, LOS_OFF_SET_OF(TraceEventFrame, curTask), sizeof(UINT32) }, + { IDENTITY, LOS_OFF_SET_OF(TraceEventFrame, identity), sizeof(UINTPTR) }, + { EVENT_PARAMS, LOS_OFF_SET_OF(TraceEventFrame, params), sizeof(UINTPTR) * LOSCFG_TRACE_FRAME_MAX_PARAMS }, + { TRACE_TLV_TYPE_NULL, 0, 0 }, +}; + +STATIC TlvTable *g_traceTlvTbl[] = { + g_traceTlvTblNotify, + g_traceTlvTblHead, + g_traceTlvTblObj, + g_traceTlvTblEvent +}; + +STATIC UINT32 DefaultPipelineInit(VOID) +{ + return LOS_OK; +} + +STATIC VOID DefaultDataSend(UINT16 len, UINT8 *data) +{ //将len和data参数标记为"未使用"// + (VOID)len; //避免编译器产生警告// + (VOID)data; +} + +STATIC UINT32 DefaultDataReceive(UINT8 *data, UINT32 size, UINT32 timeout) +{ + (VOID)data; //将data、size和timeout参数标记为"未使用"// + (VOID)size; + (VOID)timeout; + return LOS_OK; +} + +STATIC UINT32 DefaultWait(VOID) +{ + return LOS_OK; +} + +STATIC TracePipelineOps g_defaultOps = { + .init = DefaultPipelineInit, + .dataSend = DefaultDataSend, + .dataRecv = DefaultDataReceive, + .wait = DefaultWait, +}; + +STATIC const TracePipelineOps *g_tracePipelineOps = &g_defaultOps; + +VOID OsTracePipelineReg(const TracePipelineOps *ops) +{ + g_tracePipelineOps = ops; //用于注册一个TracePipelineOps结构体指针// +} + +VOID OsTraceDataSend(UINT8 type, UINT16 len, UINT8 *data) //用于发送追踪数据// +{ + UINT32 intSave; + UINT8 outBuf[LOSCFG_TRACE_TLV_BUF_SIZE] = {0}; + + if ((type > TRACE_MSG_MAX) || (len > LOSCFG_TRACE_TLV_BUF_SIZE)) { //输入参数的合法性检查// + return; + } + + //对数据进行编码// + len = OsTraceDataEncode(type, g_traceTlvTbl[type], data, &outBuf[0], sizeof(outBuf)); + + PIPE_LOCK(intSave); //获取管道锁,防止多线程并发访问// + g_tracePipelineOps->dataSend(len, &outBuf[0]); //发送编码后的数据// + PIPE_UNLOCK(intSave); //释放管道锁// +} + +UINT32 OsTraceDataRecv(UINT8 *data, UINT32 size, UINT32 timeout) //用于接收追踪数据// +{ + return g_tracePipelineOps->dataRecv(data, size, timeout); +} + +UINT32 OsTraceDataWait(VOID) //用于等待追踪数据// +{ + return g_tracePipelineOps->wait(); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/鏂囪豹/trace/pipeline/trace_pipeline.h b/鏂囪豹/trace/pipeline/trace_pipeline.h new file mode 100644 index 0000000..49e292b --- /dev/null +++ b/鏂囪豹/trace/pipeline/trace_pipeline.h @@ -0,0 +1,104 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Pipeline Implementation HeadFile + * Author: Huawei LiteOS Team + * Create: 2020-03-16 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#ifndef _TRACE_PIPELINE_H +#define _TRACE_PIPELINE_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/*用于实现追踪流水线的功能*/ +typedef struct { + UINT32 (*init)(VOID); //用于初始化// + VOID (*dataSend)(UINT16 len, UINT8 *data); //用于发送数据// + UINT32 (*dataRecv)(UINT8 *data, UINT32 size, UINT32 timeout); //用于接收数据// + UINT32 (*wait)(VOID); //用于等待操作// +} TracePipelineOps; + +/* used as tlv's tag */ +enum TraceMsgType { //用于表示追踪消息的类型// + //类型如下// + NOTIFY, //通知// + HEAD, //头部// + OBJ, //对象// + EVENT, //事件// + + TRACE_MSG_MAX, //最大值// +}; + +enum TraceNotifySubType { //用于表示通知消息的子类型// + CMD = 0x1, + PARAMS, +}; + +enum TraceHeadSubType { //用于表示追踪头部信息的子类型// + ENDIAN = 0x1, //字节序// + VERSION, //版本// + OBJ_SIZE, //对象大小// + OBJ_COUNT, //对象计数// + CUR_INDEX, //当前索引// + MAX_RECODE, + CUR_OBJ_INDEX, + CLOCK_FREQ, +}; + +enum TraceObjSubType { //用于表示追踪对象的子类型// + ADDR = 0x1, //地址// + PRIO, //优先级/ + NAME, //名称// +}; + +enum TraceEvtSubType { //用于表示追踪事件的子类型// + CORE = 0x1, //核心编号// + EVENT_CODE, //事件码// + CUR_TIME, //当前时间// + EVENT_COUNT, //事件计数// + CUR_TASK, //当前任务// + IDENTITY, //身份信息// + EVENT_PARAMS, //事件参数// +}; + +extern VOID OsTracePipelineReg(const TracePipelineOps *ops); //用于注册追踪管道操作// +extern UINT32 OsTracePipelineInit(VOID); //用于初始化追踪管道// + +extern VOID OsTraceDataSend(UINT8 type, UINT16 len, UINT8 *data); //用于发送追踪数据// +extern UINT32 OsTraceDataRecv(UINT8 *data, UINT32 size, UINT32 timeout); //用于接收追踪数据// +extern UINT32 OsTraceDataWait(VOID); //用于等待追踪数据// + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _TRACE_PIPELINE_H */ diff --git a/鏂囪豹/trace/pipeline/trace_tlv.c b/鏂囪豹/trace/pipeline/trace_tlv.c new file mode 100644 index 0000000..4545766 --- /dev/null +++ b/鏂囪豹/trace/pipeline/trace_tlv.c @@ -0,0 +1,121 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Tlv Implementation + * Author: Huawei LiteOS Team + * Create: 2020-03-31 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "trace_tlv.h" +#include "securec.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define CRC_WIDTH 8 //CRC的位宽// +#define CRC_POLY 0x1021 //CRC多项式// +#define CRC_TOPBIT 0x8000 //CRC计算中的最高位// + +STATIC UINT16 CalcCrc16(const UINT8 *buf, UINT32 len) //用于计算16位CRC校验值// +{ + UINT32 i; + UINT16 crc = 0; + + for (; len > 0; len--) { + crc = crc ^ (*buf++ << CRC_WIDTH); + for (i = 0; i < CRC_WIDTH; i++) { + if (crc & CRC_TOPBIT) { + crc = (crc << 1) ^ CRC_POLY; + } else { + crc <<= 1; + } + } + } + return crc; +} + +STATIC UINT32 OsWriteTlv(UINT8 *tlvBuf, UINT8 type, UINT8 len, UINT8 *value) //将TLV数据写入TLV缓冲区// +{ + TraceMsgTlvBody *body = (TraceMsgTlvBody *)tlvBuf; + + if (len == 0) { + return 0; + } + + body->type = type; + body->len = len; + /* Do not check return value for performance, if copy failed, only this package will be discarded */ + (VOID)memcpy_s(body->value, len, value, len); + return len + sizeof(body->type) + sizeof(body->len); //返回实际写入的字节数// +} + +/*根据TLV表中的定义,将源数据编码成TLV格式并写入TLV缓冲区*/ +STATIC UINT32 OsTlvEncode(const TlvTable *table, UINT8 *srcBuf, UINT8 *tlvBuf, INT32 tlvBufLen) +{ + UINT32 len = 0; + const TlvTable *tlvTableItem = table; + + while (tlvTableItem->tag != TRACE_TLV_TYPE_NULL) { + if ((len + tlvTableItem->elemSize + sizeof(UINT8) + sizeof(UINT8)) > tlvBufLen) { + break; + } + len += OsWriteTlv(tlvBuf + len, tlvTableItem->tag, tlvTableItem->elemSize, srcBuf + tlvTableItem->elemOffset); + tlvTableItem++; + } + return len; +} + +/*将源数据按照TLV表的定义编码,并写入目标缓冲区*/ +UINT32 OsTraceDataEncode(UINT8 type, const TlvTable *table, UINT8 *src, UINT8 *dest, INT32 destLen) +{ + UINT16 crc; + INT32 len; + INT32 tlvBufLen; + UINT8 *tlvBuf = NULL; + + TraceMsgTlvHead *head = (TraceMsgTlvHead *)dest; + tlvBufLen = destLen - sizeof(TraceMsgTlvHead); + + if ((tlvBufLen <= 0) || (table == NULL)) { + return 0; + } + + tlvBuf = dest + sizeof(TraceMsgTlvHead); + len = OsTlvEncode(table, src, tlvBuf, tlvBufLen); + crc = CalcCrc16(tlvBuf, len); + + head->magicNum = TRACE_TLV_MSG_HEAD; + head->msgType = type; + head->len = len; + head->crc = crc; + return len + sizeof(TraceMsgTlvHead); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/鏂囪豹/trace/pipeline/trace_tlv.h b/鏂囪豹/trace/pipeline/trace_tlv.h new file mode 100644 index 0000000..1871012 --- /dev/null +++ b/鏂囪豹/trace/pipeline/trace_tlv.h @@ -0,0 +1,95 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Tlv Implementation HeadFile + * Author: Huawei LiteOS Team + * Create: 2020-03-16 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#ifndef _TRACE_TLV_H +#define _TRACE_TLV_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define TRACE_TLV_MSG_HEAD 0xFF +#define TRACE_TLV_TYPE_NULL 0xFF + +typedef struct { + UINT8 magicNum; //魔术数字// + UINT8 msgType; //消息类型// + UINT16 len; //消息长度// + UINT16 crc; //CRC校验码// +} TraceMsgTlvHead; //TLV消息的头部// + +typedef struct { + UINT8 type; //消息类型/// + UINT8 len; //消息长度// + UINT8 value[]; //数据内容// +} TraceMsgTlvBody; //TLV消息的消息体// + +typedef struct { + UINT8 tag; //标签// + UINT8 elemOffset; //元素偏移// + UINT8 elemSize; //元素大小// +} TlvTable; //TLV表项// + +/** + * @ingroup los_trace + * @brief Encode trace raw data. + * + * @par Description: + * This API is used to encode trace raw data to tlv data. + * @attention + * + * + * @param type [IN] Type #UINT8. The type stands for different struct of src data. + * @param src [IN] Type #UINT8 *. The raw trace data. + * @param table [IN] Type #const TlvTable *. The tlv table descript elemOffset and elemSize. + * @param dest [OUT] Type #UINT8 *. The tlv data. + * @param destLen [IN] Type #UINT8 *. The tlv buf max len. + + * @retval #0 convert failed. + * @retval #UINT32 convert success bytes. + * + * @par Dependency: + * + * @see LOS_TraceDataEncode + * @since Huawei LiteOS V200R005C00 + */ +extern UINT32 OsTraceDataEncode(UINT8 type, const TlvTable *table, UINT8 *src, UINT8 *dest, INT32 destLen); +/*根据TLV表的描述信息,将原始追踪数据进行编码,生成相应的TLV数据*/ +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _TRACE_TLV_H */ \ No newline at end of file diff --git a/鏂囪豹/trace/trace_offline.c b/鏂囪豹/trace/trace_offline.c new file mode 100644 index 0000000..f23a43f --- /dev/null +++ b/鏂囪豹/trace/trace_offline.c @@ -0,0 +1,264 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Offline Mode Implementation + * Author: Huawei LiteOS Team + * Create: 2020-03-31 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_trace_pri.h" +#include "trace_pipeline.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_RECORDER_MODE_OFFLINE +#define BITS_NUM_FOR_TASK_ID 16 //指定了任务ID的位数// + +LITE_OS_SEC_BSS STATIC TraceOfflineHeaderInfo g_traceRecoder; //用来记录离线跟踪记录的相关信息// +LITE_OS_SEC_BSS STATIC UINT32 g_tidMask[LOSCFG_BASE_CORE_TSK_LIMIT] = {0}; //用于存储任务ID的掩码// + +UINT32 OsTraceGetMaskTid(UINT32 tid) //用于获取掩码后的任务ID// +{ + return tid | ((tid < LOSCFG_BASE_CORE_TSK_LIMIT) ? g_tidMask[tid] << BITS_NUM_FOR_TASK_ID : 0); /* tid < 65535 */ +} + +UINT32 OsTraceBufInit(VOID *buf, UINT32 size) //用于初始化离线跟踪缓冲区// +{ + UINT32 headSize; + + headSize = sizeof(OfflineHead) + sizeof(ObjData) * LOSCFG_TRACE_OBJ_MAX_NUM; //用于存储离线跟踪记录头部信息// + if (size <= headSize) { + TRACE_ERROR("trace buf size not enough than 0x%x\n", headSize); + return LOS_ERRNO_TRACE_BUF_TOO_SMALL; + } + + if (buf == NULL) { + buf = LOS_MemAlloc(m_aucSysMem1, size); + if (buf == NULL) { + return LOS_ERRNO_TRACE_NO_MEMORY; + } + } + + (VOID)memset_s(buf, size, 0, size); + g_traceRecoder.head = (OfflineHead *)buf; + g_traceRecoder.head->baseInfo.bigLittleEndian = TRACE_BIGLITTLE_WORD; + g_traceRecoder.head->baseInfo.version = TRACE_VERSION(TRACE_MODE_OFFLINE); + g_traceRecoder.head->baseInfo.clockFreq = GET_SYS_CLOCK(); + g_traceRecoder.head->objSize = sizeof(ObjData); + g_traceRecoder.head->frameSize = sizeof(TraceEventFrame); + g_traceRecoder.head->objOffset = sizeof(OfflineHead); + g_traceRecoder.head->frameOffset = headSize; + g_traceRecoder.head->totalLen = size; + + g_traceRecoder.ctrl.curIndex = 0; + g_traceRecoder.ctrl.curObjIndex = 0; + g_traceRecoder.ctrl.maxObjCount = LOSCFG_TRACE_OBJ_MAX_NUM; + g_traceRecoder.ctrl.maxRecordCount = (size - headSize) / sizeof(TraceEventFrame); + g_traceRecoder.ctrl.objBuf = (ObjData *)((UINTPTR)buf + g_traceRecoder.head->objOffset); + g_traceRecoder.ctrl.frameBuf = (TraceEventFrame *)((UINTPTR)buf + g_traceRecoder.head->frameOffset); + + return LOS_OK; +} + +VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId) //用于向离线跟踪缓冲区中添加对象数据// +{ + UINT32 intSave; + UINT32 index; + ObjData *obj = NULL; + + TRACE_LOCK(intSave); + /* add obj begin */ + index = g_traceRecoder.ctrl.curObjIndex; + if (index >= LOSCFG_TRACE_OBJ_MAX_NUM) { /* do nothing when config LOSCFG_TRACE_OBJ_MAX_NUM = 0 */ + TRACE_UNLOCK(intSave); + return; + } + obj = &g_traceRecoder.ctrl.objBuf[index]; + + if (taskId < LOSCFG_BASE_CORE_TSK_LIMIT) { + g_tidMask[taskId]++; + } + + OsTraceSetObj(obj, OS_TCB_FROM_TID(taskId)); + + g_traceRecoder.ctrl.curObjIndex++; + if (g_traceRecoder.ctrl.curObjIndex >= g_traceRecoder.ctrl.maxObjCount) { + g_traceRecoder.ctrl.curObjIndex = 0; /* turn around */ + } + /* add obj end */ + TRACE_UNLOCK(intSave); +} + +VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame) //用于向离线跟踪缓冲区中写入或发送事件帧数据// +{ + UINT16 index; + UINT32 intSave; + + TRACE_LOCK(intSave); + index = g_traceRecoder.ctrl.curIndex; + (VOID)memcpy_s(&g_traceRecoder.ctrl.frameBuf[index], sizeof(TraceEventFrame), frame, sizeof(TraceEventFrame)); + + g_traceRecoder.ctrl.curIndex++; + if (g_traceRecoder.ctrl.curIndex >= g_traceRecoder.ctrl.maxRecordCount) { + g_traceRecoder.ctrl.curIndex = 0; + } + TRACE_UNLOCK(intSave); +} + +VOID OsTraceReset(VOID) //用于重置离线跟踪缓冲区// +{ + UINT32 intSave; + UINT32 bufLen; + + TRACE_LOCK(intSave); + bufLen = sizeof(TraceEventFrame) * g_traceRecoder.ctrl.maxRecordCount; + (VOID)memset_s(g_traceRecoder.ctrl.frameBuf, bufLen, 0, bufLen); + g_traceRecoder.ctrl.curIndex = 0; + TRACE_UNLOCK(intSave); +} + +STATIC VOID OsTraceInfoObj(VOID) //用于打印离线跟踪对象信息// +{ + UINT32 i; + ObjData *obj = &g_traceRecoder.ctrl.objBuf[0]; + + if (g_traceRecoder.ctrl.maxObjCount > 0) { + PRINTK("CurObjIndex = %u\n", g_traceRecoder.ctrl.curObjIndex); + PRINTK("Index TaskID TaskPrio TaskName \n"); + for (i = 0; i < g_traceRecoder.ctrl.maxObjCount; i++, obj++) { + PRINTK("%-7u 0x%-6x %-10u %s\n", i, obj->id, obj->prio, obj->name); + } + PRINTK("\n"); + } +} + +STATIC VOID OsTraceInfoEventTitle(VOID) //用于打印离线跟踪事件标题// +{ + PRINTK("CurEvtIndex = %u\n", g_traceRecoder.ctrl.curIndex); + + PRINTK("Index Time(cycles) EventType CurTask Identity "); +#ifdef LOSCFG_TRACE_FRAME_CORE_MSG + PRINTK("cpuId hwiActive taskLockCnt "); +#endif +#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT + PRINTK("eventCount "); +#endif + if (LOSCFG_TRACE_FRAME_MAX_PARAMS > 0) { + PRINTK("params "); + } + PRINTK("\n"); +} + +STATIC VOID OsTraceInfoEventData(VOID) //用于打印离线跟踪事件数据// +{ + UINT32 i, j; + TraceEventFrame *frame = &g_traceRecoder.ctrl.frameBuf[0]; + + for (i = 0; i < g_traceRecoder.ctrl.maxRecordCount; i++, frame++) { + PRINTK("%-7u 0x%-15llx 0x%-12x 0x%-7x 0x%-11x ", i, frame->curTime, frame->eventType, + frame->curTask, frame->identity); +#ifdef LOSCFG_TRACE_FRAME_CORE_MSG + UINT32 taskLockCnt = frame->core.taskLockCnt; +#ifdef LOSCFG_KERNEL_SMP + /* + * For smp systems, TRACE_LOCK will requst taskLock, and this counter + * will increase by 1 in that case. + */ + taskLockCnt -= 1; +#endif + PRINTK("%-11u %-11u %-11u", frame->core.cpuId, frame->core.hwiActive, taskLockCnt); +#endif +#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT + PRINTK("%-11u", frame->eventCount); +#endif + for (j = 0; j < LOSCFG_TRACE_FRAME_MAX_PARAMS; j++) { + PRINTK("0x%-11x", frame->params[j]); + } + PRINTK("\n"); + } +} + +STATIC VOID OsTraceInfoDisplay(VOID) //用于显示离线跟踪信息// +{ + OfflineHead *head = g_traceRecoder.head; + + PRINTK("*******TraceInfo begin*******\n"); + PRINTK("clockFreq = %u\n", head->baseInfo.clockFreq); + + OsTraceInfoObj(); + + OsTraceInfoEventTitle(); + OsTraceInfoEventData(); + + PRINTK("*******TraceInfo end*******\n"); +} + +#ifdef LOSCFG_TRACE_CLIENT_INTERACT +STATIC VOID OsTraceSendInfo(VOID) //用于发送离线跟踪信息// +{ + UINT32 i; + ObjData *obj = NULL; + TraceEventFrame *frame = NULL; + + OsTraceDataSend(HEAD, sizeof(OfflineHead), (UINT8 *)g_traceRecoder.head); + + obj = &g_traceRecoder.ctrl.objBuf[0]; + for (i = 0; i < g_traceRecoder.ctrl.maxObjCount; i++) { + OsTraceDataSend(OBJ, sizeof(ObjData), (UINT8 *)(obj + i)); + } + + frame = &g_traceRecoder.ctrl.frameBuf[0]; + for (i = 0; i < g_traceRecoder.ctrl.maxRecordCount; i++) { + OsTraceDataSend(EVENT, sizeof(TraceEventFrame), (UINT8 *)(frame + i)); + } +} +#endif + +VOID OsTraceRecordDump(BOOL toClient) //用于输出或发送离线跟踪信息// +{ + if (!toClient) { //用于指示是输出还是发送离线跟踪信息// + OsTraceInfoDisplay(); + return; + } + +#ifdef LOSCFG_TRACE_CLIENT_INTERACT + OsTraceSendInfo(); +#endif +} + +OfflineHead *OsTraceRecordGet(VOID) //用于获取离线跟踪记录的头信息// +{ + return g_traceRecoder.head; +} + +#endif /* LOSCFG_RECORDER_MODE_OFFLINE */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/鏂囪豹/trace/trace_online.c b/鏂囪豹/trace/trace_online.c new file mode 100644 index 0000000..6faba44 --- /dev/null +++ b/鏂囪豹/trace/trace_online.c @@ -0,0 +1,117 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: LiteOS Trace Online Mode Implementation + * Author: Huawei LiteOS Team + * Create: 2020-03-31 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#include "los_trace_pri.h" +#include "trace_pipeline.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_RECORDER_MODE_ONLINE +UINT32 OsTraceGetMaskTid(UINT32 taskId) //用于获取任务ID的掩码// +{ + return taskId; +} + +UINT32 OsTraceBufInit(VOID *buf, UINT32 size) //初始化跟踪缓冲区// +{ + (VOID)buf; + (VOID)size; + return LOS_OK; +} + +VOID OsTraceSendHead(VOID) //发送跟踪数据的头信息// +{ + TraceBaseHeaderInfo head = { + .bigLittleEndian = TRACE_BIGLITTLE_WORD, + .version = TRACE_VERSION(TRACE_MODE_ONLINE), + .clockFreq = GET_SYS_CLOCK(), + }; + + OsTraceDataSend(HEAD, sizeof(TraceBaseHeaderInfo), (UINT8 *)&head); +} + +VOID OsTraceSendNotify(UINT32 type, UINT32 value) //发送通知类型的跟踪数据// +{ + TraceNotifyFrame frame = { + .cmd = type, + .param = value, + }; + + OsTraceDataSend(NOTIFY, sizeof(TraceNotifyFrame), (UINT8 *)&frame); +} + +STATIC VOID OsTraceSendObj(const LosTaskCB *tcb) //发送对象类型为obj的跟踪数据// +{ + ObjData obj; + + OsTraceSetObj(&obj, tcb); + OsTraceDataSend(OBJ, sizeof(ObjData), (UINT8 *)&obj); +} + +VOID OsTraceSendObjTable(VOID) //发送对象表类型的跟踪数据// +{ + UINT32 loop; + LosTaskCB *tcb = NULL; + + for (loop = 0; loop < g_taskMaxNum; ++loop) { + tcb = g_taskCBArray + loop; + if (tcb->taskStatus & OS_TASK_STATUS_UNUSED) { + continue; + } + OsTraceSendObj(tcb); + } +} + +VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId) //向跟踪记录中添加对象// +{ + if (OsTraceIsEnable()) { + OsTraceSendObj(OS_TCB_FROM_TID(taskId)); + } +} + +VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame) //发送事件数据// +{ + OsTraceDataSend(EVENT, sizeof(TraceEventFrame), (UINT8 *)frame); +} + +OfflineHead *OsTraceRecordGet(VOID) //获取离线跟踪记录头// +{ + return NULL; //表示没有离线跟踪记录可用// +} + +#endif /* LOSCFG_RECORDER_MODE_ONLINE */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */