From aa43a7ec88db2f47c27eb2aa3d7e30285cd294bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E8=B1=AA?= <2548632733@qq.com> Date: Mon, 4 Dec 2023 00:24:26 +0800 Subject: [PATCH 1/4] Code reading --- 文豪/cppsupport/los_cppsupport.c | 74 +++ 文豪/cpup/cpup_shellcmd.c | 134 ++++ 文豪/cpup/los_cpup.c | 593 ++++++++++++++++++ 文豪/los_cppsupport_pri.h | 53 ++ 文豪/los_cpup_pri.h | 74 +++ 文豪/los_trace_pri.h | 150 +++++ 文豪/trace/los_trace.c | 424 +++++++++++++ .../pipeline/serial/trace_pipeline_serial.c | 98 +++ .../pipeline/serial/trace_pipeline_serial.h | 50 ++ 文豪/trace/pipeline/trace_pipeline.c | 156 +++++ 文豪/trace/pipeline/trace_pipeline.h | 104 +++ 文豪/trace/pipeline/trace_tlv.c | 121 ++++ 文豪/trace/pipeline/trace_tlv.h | 95 +++ 文豪/trace/trace_offline.c | 264 ++++++++ 文豪/trace/trace_online.c | 117 ++++ 15 files changed, 2507 insertions(+) create mode 100644 文豪/cppsupport/los_cppsupport.c create mode 100644 文豪/cpup/cpup_shellcmd.c create mode 100644 文豪/cpup/los_cpup.c create mode 100644 文豪/los_cppsupport_pri.h create mode 100644 文豪/los_cpup_pri.h create mode 100644 文豪/los_trace_pri.h create mode 100644 文豪/trace/los_trace.c create mode 100644 文豪/trace/pipeline/serial/trace_pipeline_serial.c create mode 100644 文豪/trace/pipeline/serial/trace_pipeline_serial.h create mode 100644 文豪/trace/pipeline/trace_pipeline.c create mode 100644 文豪/trace/pipeline/trace_pipeline.h create mode 100644 文豪/trace/pipeline/trace_tlv.c create mode 100644 文豪/trace/pipeline/trace_tlv.h create mode 100644 文豪/trace/trace_offline.c create mode 100644 文豪/trace/trace_online.c 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) //IJȡϵͳָCPUʹ// +{ + size_t mode, taskId; + CHAR *bufMode = NULL; + CHAR *bufId = NULL; + LosTaskCB *taskCB = NULL; + UINT32 ret; + + if (argc <= 0) { //ûвȡϵͳȥ10CPUʹʲӡ// + 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ӦIJȡ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) +{ + /*溯IJֱΪ*/ + //趨ʱÿӵĻʱӵδ// + //ģʽΪģʽ// + //ص// + //ʱIDg_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 + /*ʼõIJtaskInitParamIDtempId*/ + (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_cpupMaxNumLOSCFG_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ʼֵԱ¼ʱʱ +ܹȷCPUIJֵӶõʱ*/ +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ڼijʼֱӷ// + 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Ƿ00ش// + 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(); //ȡǰCPUID// + + 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_endCHARͱ// + +#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ʹͳģijʼ// +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) //жǷҪijӲж// +{ + 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(); //CPUID// + 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) //ڳʼٹܵע֮صIJӿ// +{ + 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[] = { //ṹijԱͺʹС// + { 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[] = { //ṹijԱͺʹС// + { 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[] = { //ṹijԱ͡ƫλúʹС// + { 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[] = { //ṹijԱͺʹС// +#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) +{ //lendataΪ"δʹ"// + (VOID)len; //// + (VOID)data; +} + +STATIC UINT32 DefaultDataReceive(UINT8 *data, UINT32 size, UINT32 timeout) +{ + (VOID)data; //datasizetimeoutΪ"δʹ"// + (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 + *
@ZQcpVKYH!H)3v})qheLTNSptb-U$6D*
zSQ#4`37DPK0tyC=t3nlZ&tIe&MGZhW%)9453VH;y_JVP3Au4)Rq@eVmVI9Q>^1fwm
zylXe23$Sc`J!-adKOYZs=ehH*^l$1B1L;B3 6g=MkJ;>(l13D^~oZR0vT$1macapb=93!fp^X*vey5OuTD~
z2q&*Lk?RL(O-Z&?0hr|JDm-#`vl6egPe0kE^{i^8)d0M7K<`{rby8qYH)T3iAzENb
zR3!GInaUC_K+K1;?65RIIjB$w`wM2%Rj@W@y-b8RoNb#B?mvgiX6x3iygy*aN9O`5
z85Dw7d(#jRonjW%>h|y9Iu2JJt8;DMM7R1pk|0dEDJf-jo-8=2;v}|`d8uLcOV$?|
zF1uw{vo1Y-3q2GW7kB>#$Y*gE8nNkXYcpmPe9xj-^jP8E;{JY1jB`)|V>L_25QhSl
zh!bK9i SoB(`zLD@-gobDY-liCq2?`QOaYICBhPK|?6gz`APWY)vs15vNi(D`jmmM?cbtu4LarzM~Ms
zTQ{L$R!|9h1|SNFz(t2^g{vQXF-@w kBjs}fHO+uRjKiYL|*SarHZI=I+9xvPzcwX|4yMIG3NNYH~@U?A$^LlA&^
z@XA=IZh3P)vwwJ60prL3SkO&6>RVgT;E7KQOT={r_8{w2KCQx75zrS|+_|9M`c%b3
z`jEV!bR(^SnCi3Sq$;Y2!ff3Pjjo;thxA1<4>RT59)(EEo8}TXwjU*#fyc;;q%AQQ
z$AV
+Ve;9mk<%lyxnRUd^zV|F(LdTuC%rJ$dFKlyVYmK$VNS_jqJOxCeK20fV3$f#@9JVC;Rq^!
zqmSGwg4J?0AhT;`EZtj%D52e#TV8_Xgq
zVtJW+xOf|}6m!CnXRS76nW^^bbv57f(5bP}+3k$A;rq0>*nKg3BNxe%Y*pLG8eKnb
zI8()j?B@NvbXc*w9!D?{fy5DFbUc$sBYJn;Zg0Cm9qsJZIz&Ms;kv81Yjoo4+<^JZI1~M;V(uyy#i#D%{Aw8jUYG
z$gg_uYX_;9vlstq9=4v?(Ia=S3aTV7=Ev9(Ew*OehF2+52WKC2G`pI}FoK3dbLwln
z_0a>Gm@zYlxXLeeoDn}5G_ftBM)yf