diff --git a/BUILD.gn b/BUILD.gn
index c4adbc0a..442d1356 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -53,6 +53,9 @@ group("kernel") {
if (enable_ohos_kernel_liteos_m_pm == true) {
deps += [ "components/power:pm" ]
}
+ if (enable_ohos_kernel_liteos_m_trace == true) {
+ deps += [ "components/trace:trace" ]
+ }
if (enable_ohos_kernel_liteos_m_kal == true) {
deps += [ "kal:kal" ]
}
diff --git a/components/trace/BUILD.gn b/components/trace/BUILD.gn
new file mode 100644
index 00000000..9ae74537
--- /dev/null
+++ b/components/trace/BUILD.gn
@@ -0,0 +1,51 @@
+# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+#
+# 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.
+
+static_library("trace") {
+ sources = [
+ "los_trace.c",
+ "trace_offline.c",
+ "trace_online.c",
+ "cnv/trace_cnv.c",
+ "pipeline/trace_pipeline.c",
+ "pipeline/trace_tlv.c",
+ "pipeline/serial/trace_pipeline_serial.c"
+ ]
+
+ include_dirs = [
+ "../../kernel/include",
+ "../../kernel/arch/include",
+ "../../utils",
+ "./",
+ "cnv",
+ "pipeline",
+ "pipeline/serial",
+ "//third_party/bounds_checking_function/include",
+ ]
+}
diff --git a/components/trace/cnv/trace_cnv.c b/components/trace/cnv/trace_cnv.c
new file mode 100644
index 00000000..3be7a07a
--- /dev/null
+++ b/components/trace/cnv/trace_cnv.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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_cnv.h"
+#include "los_trace.h"
+#include "los_task.h"
+#include "los_sem.h"
+#include "los_mux.h"
+#include "los_queue.h"
+#include "los_event.h"
+#include "los_swtmr.h"
+#include "los_hook.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+STATIC VOID LOS_TraceMemInit(VOID *pool, UINT32 size)
+{
+ LOS_TRACE(MEM_INFO_REQ, pool);
+}
+
+STATIC VOID LOS_TraceMemAlloc(VOID *pool, VOID *ptr, UINT32 size)
+{
+ LOS_TRACE(MEM_ALLOC, pool, (UINTPTR)ptr, size);
+}
+
+STATIC VOID LOS_TraceMemFree(VOID *pool, VOID *ptr)
+{
+ LOS_TRACE(MEM_FREE, pool, (UINTPTR)ptr);
+}
+
+STATIC VOID LOS_TraceMemRealloc(VOID *pool, VOID *ptr, UINT32 size)
+{
+ LOS_TRACE(MEM_REALLOC, pool, (UINTPTR)ptr, size);
+}
+
+STATIC VOID LOS_TraceMemAllocAlign(VOID *pool, VOID *ptr, UINT32 size, UINT32 boundary)
+{
+ LOS_TRACE(MEM_ALLOC_ALIGN, pool, (UINTPTR)ptr, size, boundary);
+}
+
+STATIC VOID LOS_TraceEventInit(PEVENT_CB_S eventCB)
+{
+ LOS_TRACE(EVENT_CREATE, (UINTPTR)eventCB);
+}
+
+STATIC VOID LOS_TraceEventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
+{
+ LOS_TRACE(EVENT_READ, (UINTPTR)eventCB, eventCB->uwEventID, eventMask, mode, timeout);
+}
+
+STATIC VOID LOS_TraceEventWrite(PEVENT_CB_S eventCB, UINT32 events)
+{
+ LOS_TRACE(EVENT_WRITE, (UINTPTR)eventCB, eventCB->uwEventID, events);
+}
+
+STATIC VOID LOS_TraceEventClear(PEVENT_CB_S eventCB, UINT32 events)
+{
+ LOS_TRACE(EVENT_CLEAR, (UINTPTR)eventCB, eventCB->uwEventID, events);
+}
+
+STATIC VOID LOS_TraceEventDestroy(PEVENT_CB_S eventCB)
+{
+ LOS_TRACE(EVENT_DELETE, (UINTPTR)eventCB, LOS_OK);
+}
+
+STATIC VOID LOS_TraceQueueCreate(const LosQueueCB *queueCB)
+{
+ LOS_TRACE(QUEUE_CREATE, queueCB->queueID, queueCB->queueLen, queueCB->queueSize - sizeof(UINT32),
+ (UINTPTR)queueCB, 0);
+}
+
+STATIC VOID LOS_TraceQueueRW(const LosQueueCB *queueCB, UINT32 operateType,
+ UINT32 bufferSize, UINT32 timeout)
+{
+ LOS_TRACE(QUEUE_RW, queueCB->queueID, queueCB->queueSize, bufferSize, operateType,
+ queueCB->readWriteableCnt[OS_QUEUE_READ], queueCB->readWriteableCnt[OS_QUEUE_WRITE], timeout);
+}
+
+STATIC VOID LOS_TraceQueueDelete(const LosQueueCB *queueCB)
+{
+ LOS_TRACE(QUEUE_DELETE, queueCB->queueID, queueCB->queueState, queueCB->readWriteableCnt[OS_QUEUE_READ]);
+}
+
+STATIC VOID LOS_TraceSemCreate(const LosSemCB *semCB)
+{
+ LOS_TRACE(SEM_CREATE, semCB->semID, 0, semCB->semCount);
+}
+
+STATIC VOID LOS_TraceSemPost(const LosSemCB *semCB, const LosTaskCB *resumedTask)
+{
+ (VOID)resumedTask;
+ LOS_TRACE(SEM_POST, semCB->semID, 0, semCB->semCount);
+}
+
+STATIC VOID LOS_TraceSemPend(const LosSemCB *semCB, const LosTaskCB *runningTask, UINT32 timeout)
+{
+ (VOID)runningTask;
+ LOS_TRACE(SEM_PEND, semCB->semID, semCB->semCount, timeout);
+}
+
+STATIC VOID LOS_TraceSemDelete(const LosSemCB *semCB)
+{
+ LOS_TRACE(SEM_DELETE, semCB->semID, LOS_OK);
+}
+
+STATIC VOID LOS_TraceMuxCreate(const LosMuxCB *muxCB)
+{
+ LOS_TRACE(MUX_CREATE, muxCB->muxID);
+}
+
+STATIC VOID LOS_TraceMuxPost(const LosMuxCB *muxCB)
+{
+ LOS_TRACE(MUX_POST, muxCB->muxID, muxCB->muxCount,
+ (muxCB->owner == NULL) ? 0xffffffff : muxCB->owner->taskID);
+}
+
+STATIC VOID LOS_TraceMuxPend(const LosMuxCB *muxCB, UINT32 timeout)
+{
+ LOS_TRACE(MUX_PEND, muxCB->muxID, muxCB->muxCount,
+ (muxCB->owner == NULL) ? 0xffffffff : muxCB->owner->taskID, timeout);
+}
+
+STATIC VOID LOS_TraceMuxDelete(const LosMuxCB *muxCB)
+{
+ LOS_TRACE(MUX_DELETE, muxCB->muxID, muxCB->muxStat, muxCB->muxCount,
+ (muxCB->owner == NULL) ? 0xffffffff : muxCB->owner->taskID);
+}
+
+STATIC VOID LOS_TraceTaskCreate(const LosTaskCB *taskCB)
+{
+ LOS_TRACE(TASK_CREATE, taskCB->taskID, taskCB->taskStatus, taskCB->priority);
+}
+
+STATIC VOID LOS_TraceTaskPriModify(const LosTaskCB *taskCB, UINT32 prio)
+{
+ LOS_TRACE(TASK_PRIOSET, taskCB->taskID, taskCB->taskStatus, taskCB->priority, prio);
+}
+
+STATIC VOID LOS_TraceTaskDelete(const LosTaskCB *taskCB)
+{
+ LOS_TRACE(TASK_DELETE, taskCB->taskID, taskCB->taskStatus, (UINTPTR)taskCB->stackPointer);
+}
+
+STATIC VOID LOS_TraceTaskSwitchedIn(VOID)
+{
+ LosTaskCB *newTask = g_losTask.newTask;
+ LosTaskCB *runTask = g_losTask.runTask;
+ LOS_TRACE(TASK_SWITCH, newTask->taskID, runTask->priority, runTask->taskStatus,
+ newTask->priority, newTask->taskStatus);
+}
+
+STATIC VOID LOS_TraceTaskResume(const LosTaskCB *taskCB)
+{
+ LOS_TRACE(TASK_RESUME, taskCB->taskID, taskCB->taskStatus, taskCB->priority);
+}
+
+STATIC VOID LOS_TraceTaskSuspend(const LosTaskCB *taskCB)
+{
+ LOS_TRACE(TASK_SUSPEND, taskCB->taskID, taskCB->taskStatus, g_losTask.runTask->taskID);
+}
+
+STATIC VOID LOS_TraceIsrEnter(UINT32 hwiNum)
+{
+ LOS_TRACE(HWI_RESPONSE_IN, hwiNum);
+}
+
+STATIC VOID LOS_TraceIsrExit(UINT32 hwiNum)
+{
+ LOS_TRACE(HWI_RESPONSE_OUT, hwiNum);
+}
+
+STATIC VOID LOS_TraceSwtmrCreate(const SWTMR_CTRL_S *swtmr)
+{
+ LOS_TRACE(SWTMR_CREATE, swtmr->usTimerID);
+}
+
+STATIC VOID LOS_TraceSwtmrDelete(const SWTMR_CTRL_S *swtmr)
+{
+ LOS_TRACE(SWTMR_DELETE, swtmr->usTimerID);
+}
+
+STATIC VOID LOS_TraceSwtmrExpired(const SWTMR_CTRL_S *swtmr)
+{
+ LOS_TRACE(SWTMR_EXPIRED, swtmr->usTimerID);
+}
+
+STATIC VOID LOS_TraceSwtmrStart(const SWTMR_CTRL_S *swtmr)
+{
+ LOS_TRACE(SWTMR_START, swtmr->usTimerID, swtmr->ucMode, swtmr->uwCount, swtmr->uwInterval, 0);
+}
+
+STATIC VOID LOS_TraceSwtmrStop(const SWTMR_CTRL_S *swtmr)
+{
+ LOS_TRACE(SWTMR_STOP, swtmr->usTimerID);
+}
+
+VOID OsTraceCnvInit(VOID)
+{
+ LOS_HookReg(LOS_HOOK_TYPE_MEM_ALLOC, LOS_TraceMemAlloc);
+ LOS_HookReg(LOS_HOOK_TYPE_MEM_FREE, LOS_TraceMemFree);
+ LOS_HookReg(LOS_HOOK_TYPE_MEM_INIT, LOS_TraceMemInit);
+ LOS_HookReg(LOS_HOOK_TYPE_MEM_REALLOC, LOS_TraceMemRealloc);
+ LOS_HookReg(LOS_HOOK_TYPE_MEM_ALLOCALIGN, LOS_TraceMemAllocAlign);
+ LOS_HookReg(LOS_HOOK_TYPE_EVENT_INIT, LOS_TraceEventInit);
+ LOS_HookReg(LOS_HOOK_TYPE_EVENT_READ, LOS_TraceEventRead);
+ LOS_HookReg(LOS_HOOK_TYPE_EVENT_WRITE, LOS_TraceEventWrite);
+ LOS_HookReg(LOS_HOOK_TYPE_EVENT_CLEAR, LOS_TraceEventClear);
+ LOS_HookReg(LOS_HOOK_TYPE_EVENT_DESTROY, LOS_TraceEventDestroy);
+ LOS_HookReg(LOS_HOOK_TYPE_QUEUE_CREATE, LOS_TraceQueueCreate);
+ LOS_HookReg(LOS_HOOK_TYPE_QUEUE_DELETE, LOS_TraceQueueDelete);
+ LOS_HookReg(LOS_HOOK_TYPE_QUEUE_READ, LOS_TraceQueueRW);
+ LOS_HookReg(LOS_HOOK_TYPE_QUEUE_WRITE, LOS_TraceQueueRW);
+ LOS_HookReg(LOS_HOOK_TYPE_SEM_CREATE, LOS_TraceSemCreate);
+ LOS_HookReg(LOS_HOOK_TYPE_SEM_DELETE, LOS_TraceSemDelete);
+ LOS_HookReg(LOS_HOOK_TYPE_SEM_POST, LOS_TraceSemPost);
+ LOS_HookReg(LOS_HOOK_TYPE_SEM_PEND, LOS_TraceSemPend);
+ LOS_HookReg(LOS_HOOK_TYPE_MUX_CREATE, LOS_TraceMuxCreate);
+ LOS_HookReg(LOS_HOOK_TYPE_MUX_POST, LOS_TraceMuxPost);
+ LOS_HookReg(LOS_HOOK_TYPE_MUX_PEND, LOS_TraceMuxPend);
+ LOS_HookReg(LOS_HOOK_TYPE_MUX_DELETE, LOS_TraceMuxDelete);
+ LOS_HookReg(LOS_HOOK_TYPE_TASK_PRIMODIFY, LOS_TraceTaskPriModify);
+ LOS_HookReg(LOS_HOOK_TYPE_TASK_DELETE, LOS_TraceTaskDelete);
+ LOS_HookReg(LOS_HOOK_TYPE_TASK_CREATE, LOS_TraceTaskCreate);
+ LOS_HookReg(LOS_HOOK_TYPE_TASK_SWITCHEDIN, LOS_TraceTaskSwitchedIn);
+ LOS_HookReg(LOS_HOOK_TYPE_MOVEDTASKTOREADYSTATE, LOS_TraceTaskResume);
+ LOS_HookReg(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, LOS_TraceTaskSuspend);
+ LOS_HookReg(LOS_HOOK_TYPE_ISR_ENTER, LOS_TraceIsrEnter);
+ LOS_HookReg(LOS_HOOK_TYPE_ISR_EXIT, LOS_TraceIsrExit);
+ LOS_HookReg(LOS_HOOK_TYPE_SWTMR_CREATE, LOS_TraceSwtmrCreate);
+ LOS_HookReg(LOS_HOOK_TYPE_SWTMR_DELETE, LOS_TraceSwtmrDelete);
+ LOS_HookReg(LOS_HOOK_TYPE_SWTMR_EXPIRED, LOS_TraceSwtmrExpired);
+ LOS_HookReg(LOS_HOOK_TYPE_SWTMR_START, LOS_TraceSwtmrStart);
+ LOS_HookReg(LOS_HOOK_TYPE_SWTMR_STOP, LOS_TraceSwtmrStop);
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/components/trace/cnv/trace_cnv.h b/components/trace/cnv/trace_cnv.h
new file mode 100644
index 00000000..c2c84faa
--- /dev/null
+++ b/components/trace/cnv/trace_cnv.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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_CNV_H
+#define _TRACE_CNV_H
+
+#include "stdarg.h"
+#include "los_compiler.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+extern VOID OsTraceCnvInit(VOID);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* _TRACE_CNV_H */
diff --git a/components/trace/los_trace.c b/components/trace/los_trace.c
new file mode 100644
index 00000000..838db540
--- /dev/null
+++ b/components/trace/los_trace.c
@@ -0,0 +1,433 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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"
+#include "los_memory.h"
+#include "los_config.h"
+#include "securec.h"
+#include "trace_cnv.h"
+
+#if (LOSCFG_KERNEL_SMP == 1)
+#include "los_mp_pri.h"
+#endif
+
+#if (LOSCFG_SHELL == 1)
+#include "shcmd.h"
+#include "shell.h"
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#if (LOSCFG_KERNEL_TRACE == 1)
+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;
+
+TRACE_EVENT_HOOK g_traceEventHook = NULL;
+TRACE_DUMP_HOOK g_traceDumpHook = NULL;
+
+#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
+LITE_OS_SEC_BSS STATIC UINT32 g_traceTaskId;
+#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;
+
+#if (LOSCFG_KERNEL_SMP == 1)
+LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_traceSpin);
+#endif
+
+STATIC_INLINE BOOL OsTraceHwiFilter(UINT32 hwiNum)
+{
+ BOOL ret = ((hwiNum == NUM_HAL_INTERRUPT_UART) || (hwiNum == OS_TICK_INT_NUM));
+#if (LOSCFG_KERNEL_SMP == 1)
+ 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(LOS_CurTaskIDGet());
+ frame->identity = identity;
+ frame->curTime = LOS_SysCycleGet();
+ frame->eventType = eventType;
+
+#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
+ frame->core.cpuId = ArchCurrCpuid();
+ 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
+
+#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
+ 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);
+ 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.totalUsedSize, status.totalFreeSize);
+ 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;
+#if (LOSCFG_RECORDER_MODE_OFFLINE == 1)
+ g_traceDumpHook = OsTraceRecordDump;
+#endif
+}
+
+#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
+STATIC BOOL OsTraceCmdIsValid(const TraceClientCmd *msg)
+{
+ return ((msg->end == TRACE_CMD_END_CHAR) && (msg->cmd < TRACE_CMD_MAX_CODE));
+}
+
+STATIC VOID OsTraceCmdHandle(const TraceClientCmd *msg)
+{
+ 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;
+#if (LOSCFG_KERNEL_SMP == 1)
+ 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;
+ }
+
+#if (LOSCFG_TRACE_CLIENT_INTERACT == 1)
+ ret = OsTracePipelineInit();
+ if (ret != LOS_OK) {
+ goto LOS_ERREND;
+ }
+#endif
+
+#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
+ 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();
+ OsTraceCnvInit();
+
+ g_traceEventCount = 0;
+
+#if (LOSCFG_RECORDER_MODE_ONLINE == 1) /* 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:
+#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
+ 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);
+}
+
+#if (LOSCFG_SHELL == 1)
+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 == 1 */
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/components/trace/los_trace.h b/components/trace/los_trace.h
new file mode 100644
index 00000000..5932efa9
--- /dev/null
+++ b/components/trace/los_trace.h
@@ -0,0 +1,628 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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.
+ */
+
+/**
+ * @defgroup los_trace Trace
+ * @ingroup kernel
+ */
+
+#ifndef _LOS_TRACE_H
+#define _LOS_TRACE_H
+
+#include "los_task.h"
+#include "trace_cnv.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
+
+/**
+ * @ingroup los_trace
+ * Trace Control agent task's priority.
+ */
+#define LOSCFG_TRACE_TASK_PRIORITY 2
+#endif
+
+#define LOSCFG_TRACE_OBJ_MAX_NAME_SIZE LOS_TASK_NAMELEN
+
+/**
+ * @ingroup los_trace
+ * Trace records the max number of objects(kernel object, like tasks), range is [0, LOSCFG_BASE_CORE_TSK_LIMIT].
+ * if set to 0, trace will not record any object.
+ */
+#define LOSCFG_TRACE_OBJ_MAX_NUM 0
+
+/**
+ * @ingroup los_trace
+ * Trace tlv encode buffer size, the buffer is used to encode one piece raw frame to tlv message in online mode.
+ */
+#define LOSCFG_TRACE_TLV_BUF_SIZE 100
+
+/**
+ * @ingroup los_trace
+ * Trace error code: init trace failed.
+ *
+ * Value: 0x02001400
+ *
+ * Solution: Follow the trace State Machine.
+ */
+#define LOS_ERRNO_TRACE_ERROR_STATUS LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
+
+/**
+ * @ingroup los_trace
+ * Trace error code: Insufficient memory for trace buf init.
+ *
+ * Value: 0x02001401
+ *
+ * Solution: Expand the configured system memory or decrease the value defined by LOS_TRACE_BUFFER_SIZE.
+ */
+#define LOS_ERRNO_TRACE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
+
+/**
+ * @ingroup los_trace
+ * Trace error code: Insufficient memory for trace struct.
+ *
+ * Value: 0x02001402
+ *
+ * Solution: Increase trace buffer's size.
+ */
+#define LOS_ERRNO_TRACE_BUF_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
+
+/**
+ * @ingroup los_trace
+ * Trace state.
+ */
+enum TraceState {
+ TRACE_UNINIT = 0, /**< trace isn't inited */
+ TRACE_INITED, /**< trace is inited but not started yet */
+ TRACE_STARTED, /**< trace is started and system is tracing */
+ TRACE_STOPED, /**< trace is stopped */
+};
+
+/**
+ * @ingroup los_trace
+ * Trace mask is used to filter events in runtime. Each mask keep only one unique bit to 1, and user can define own
+ * module's trace mask.
+ */
+typedef enum {
+ TRACE_SYS_FLAG = 0x10,
+ TRACE_HWI_FLAG = 0x20,
+ TRACE_TASK_FLAG = 0x40,
+ TRACE_SWTMR_FLAG = 0x80,
+ TRACE_MEM_FLAG = 0x100,
+ TRACE_QUE_FLAG = 0x200,
+ TRACE_EVENT_FLAG = 0x400,
+ TRACE_SEM_FLAG = 0x800,
+ TRACE_MUX_FLAG = 0x1000,
+
+ TRACE_MAX_FLAG = 0x80000000,
+ TRACE_USER_DEFAULT_FLAG = 0xFFFFFFF0,
+} LOS_TRACE_MASK;
+
+/**
+ * @ingroup los_trace
+ * Trace event type which indicate the exactly happend events, user can define own module's event type like
+ * TRACE_#MODULE#_FLAG | NUMBER.
+ * 28 4
+ * 0 0 0 0 0 0 0 0 X X X X X X X X 0 0 0 0 0 0
+ * | | |
+ * trace_module_flag number
+ *
+ */
+typedef enum {
+ /* 0x10~0x1F */
+ SYS_ERROR = TRACE_SYS_FLAG | 0,
+ SYS_START = TRACE_SYS_FLAG | 1,
+ SYS_STOP = TRACE_SYS_FLAG | 2,
+
+ /* 0x20~0x2F */
+ HWI_CREATE = TRACE_HWI_FLAG | 0,
+ HWI_CREATE_SHARE = TRACE_HWI_FLAG | 1,
+ HWI_DELETE = TRACE_HWI_FLAG | 2,
+ HWI_DELETE_SHARE = TRACE_HWI_FLAG | 3,
+ HWI_RESPONSE_IN = TRACE_HWI_FLAG | 4,
+ HWI_RESPONSE_OUT = TRACE_HWI_FLAG | 5,
+ HWI_ENABLE = TRACE_HWI_FLAG | 6,
+ HWI_DISABLE = TRACE_HWI_FLAG | 7,
+ HWI_TRIGGER = TRACE_HWI_FLAG | 8,
+ HWI_SETPRI = TRACE_HWI_FLAG | 9,
+ HWI_CLEAR = TRACE_HWI_FLAG | 10,
+ HWI_SETAFFINITY = TRACE_HWI_FLAG | 11,
+ HWI_SENDIPI = TRACE_HWI_FLAG | 12,
+
+ /* 0x40~0x4F */
+ TASK_CREATE = TRACE_TASK_FLAG | 0,
+ TASK_PRIOSET = TRACE_TASK_FLAG | 1,
+ TASK_DELETE = TRACE_TASK_FLAG | 2,
+ TASK_SUSPEND = TRACE_TASK_FLAG | 3,
+ TASK_RESUME = TRACE_TASK_FLAG | 4,
+ TASK_SWITCH = TRACE_TASK_FLAG | 5,
+ TASK_SIGNAL = TRACE_TASK_FLAG | 6,
+
+ /* 0x80~0x8F */
+ SWTMR_CREATE = TRACE_SWTMR_FLAG | 0,
+ SWTMR_DELETE = TRACE_SWTMR_FLAG | 1,
+ SWTMR_START = TRACE_SWTMR_FLAG | 2,
+ SWTMR_STOP = TRACE_SWTMR_FLAG | 3,
+ SWTMR_EXPIRED = TRACE_SWTMR_FLAG | 4,
+
+ /* 0x100~0x10F */
+ MEM_ALLOC = TRACE_MEM_FLAG | 0,
+ MEM_ALLOC_ALIGN = TRACE_MEM_FLAG | 1,
+ MEM_REALLOC = TRACE_MEM_FLAG | 2,
+ MEM_FREE = TRACE_MEM_FLAG | 3,
+ MEM_INFO_REQ = TRACE_MEM_FLAG | 4,
+ MEM_INFO = TRACE_MEM_FLAG | 5,
+
+ /* 0x200~0x20F */
+ QUEUE_CREATE = TRACE_QUE_FLAG | 0,
+ QUEUE_DELETE = TRACE_QUE_FLAG | 1,
+ QUEUE_RW = TRACE_QUE_FLAG | 2,
+
+ /* 0x400~0x40F */
+ EVENT_CREATE = TRACE_EVENT_FLAG | 0,
+ EVENT_DELETE = TRACE_EVENT_FLAG | 1,
+ EVENT_READ = TRACE_EVENT_FLAG | 2,
+ EVENT_WRITE = TRACE_EVENT_FLAG | 3,
+ EVENT_CLEAR = TRACE_EVENT_FLAG | 4,
+
+ /* 0x800~0x80F */
+ SEM_CREATE = TRACE_SEM_FLAG | 0,
+ SEM_DELETE = TRACE_SEM_FLAG | 1,
+ SEM_PEND = TRACE_SEM_FLAG | 2,
+ SEM_POST = TRACE_SEM_FLAG | 3,
+
+ /* 0x1000~0x100F */
+ MUX_CREATE = TRACE_MUX_FLAG | 0,
+ MUX_DELETE = TRACE_MUX_FLAG | 1,
+ MUX_PEND = TRACE_MUX_FLAG | 2,
+ MUX_POST = TRACE_MUX_FLAG | 3,
+} LOS_TRACE_TYPE;
+
+/**
+ * @ingroup los_trace
+ * struct to store the trace config information.
+ */
+typedef struct {
+ UINT32 bigLittleEndian; /**< big little endian flag */
+ UINT32 clockFreq; /**< system clock frequency */
+ UINT32 version; /**< trace version */
+} TraceBaseHeaderInfo;
+
+/**
+ * @ingroup los_trace
+ * struct to store the event infomation
+ */
+typedef struct {
+ UINT32 eventType; /**< event type */
+ UINT32 curTask; /**< current running task */
+ UINT64 curTime; /**< current timestamp */
+ UINTPTR identity; /**< subject of the event description */
+#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
+ struct CoreStatus {
+ UINT32 cpuId : 8, /**< cpuid */
+ hwiActive : 4, /**< whether is in hwi response */
+ taskLockCnt : 4, /**< task lock count */
+ paramCount : 4, /**< event frame params' number */
+ reserves : 12; /**< reserves */
+ } core;
+#endif
+
+#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
+ UINT32 eventCount; /**< the sequence of happend events */
+#endif
+
+ UINTPTR params[LOSCFG_TRACE_FRAME_MAX_PARAMS]; /**< event frame's params */
+} TraceEventFrame;
+
+/**
+ * @ingroup los_trace
+ * struct to store the kernel obj information, we defined task as kernel obj in this system.
+ */
+typedef struct {
+ UINT32 id; /**< kernel obj's id */
+ UINT32 prio; /**< kernel obj's priority */
+ CHAR name[LOSCFG_TRACE_OBJ_MAX_NAME_SIZE]; /**< kernel obj's name */
+} ObjData;
+
+/**
+ * @ingroup los_trace
+ * struct to store the trace data.
+ */
+typedef struct {
+ TraceBaseHeaderInfo baseInfo; /**< basic info, include bigLittleEndian flag, system clock freq */
+ UINT16 totalLen; /**< trace data's total length */
+ UINT16 objSize; /**< sizeof #ObjData */
+ UINT16 frameSize; /**< sizeof #TraceEventFrame */
+ UINT16 objOffset; /**< the offset of the first obj data to record beginning */
+ UINT16 frameOffset; /**< the offset of the first event frame data to record beginning */
+} OfflineHead;
+
+/**
+ * @ingroup los_trace
+ * @brief Define the type of trace hardware interrupt filter hook function.
+ *
+ * @par Description:
+ * User can register fliter function by LOS_TraceHwiFilterHookReg to filter hardware interrupt events. Return true if
+ * user don't need trace the certain number.
+ *
+ * @attention
+ * None.
+ *
+ * @param hwiNum [IN] Type #UINT32. The hardware interrupt number.
+ * @retval #TRUE 0x00000001: Not record the certain number.
+ * @retval #FALSE 0x00000000: Need record the certain number.
+ *
+ * @par Dependency:
+ *
- los_trace.h: the header file that contains the API declaration.
+ * @since Huawei LiteOS V200R005C00
+ */
+typedef BOOL (*TRACE_HWI_FILTER_HOOK)(UINT32 hwiNum);
+
+typedef VOID (*TRACE_EVENT_HOOK)(UINT32 eventType, UINTPTR identity, const UINTPTR *params, UINT16 paramCount);
+extern TRACE_EVENT_HOOK g_traceEventHook;
+
+/**
+ * @ingroup los_trace
+ * Trace event params:
+ 1. Configure the macro without parameters so as not to record events of this type;
+ 2. Configure the macro at least with one parameter to record this type of event;
+ 3. User can delete unnecessary parameters which defined in corresponding marco;
+ * @attention
+ *
+ * - The first param is treat as key, keep at least this param if you want trace this event.
+ * - All parameters were treated as UINTPTR.
+ *
+ * eg. Trace a event as:
+ * #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId, taskStatus, oldPrio, newPrio
+ * eg. Not Trace a event as:
+ * #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio)
+ * eg. Trace only you need parmas as:
+ * #define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId
+ */
+#define TASK_SWITCH_PARAMS(taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus) \
+ taskId, oldPriority, oldTaskStatus, newPriority, newTaskStatus
+#define TASK_PRIOSET_PARAMS(taskId, taskStatus, oldPrio, newPrio) taskId, taskStatus, oldPrio, newPrio
+#define TASK_CREATE_PARAMS(taskId, taskStatus, prio) taskId, taskStatus, prio
+#define TASK_DELETE_PARAMS(taskId, taskStatus, usrStack) taskId, taskStatus, usrStack
+#define TASK_SUSPEND_PARAMS(taskId, taskStatus, runTaskId) taskId, taskStatus, runTaskId
+#define TASK_RESUME_PARAMS(taskId, taskStatus, prio) taskId, taskStatus, prio
+#define TASK_SIGNAL_PARAMS(taskId, signal, schedFlag) // taskId, signal, schedFlag
+
+#define SWTMR_START_PARAMS(swtmrId, mode, overrun, interval, expiry) swtmrId, mode, overrun, interval, expiry
+#define SWTMR_DELETE_PARAMS(swtmrId) swtmrId
+#define SWTMR_EXPIRED_PARAMS(swtmrId) swtmrId
+#define SWTMR_STOP_PARAMS(swtmrId) swtmrId
+#define SWTMR_CREATE_PARAMS(swtmrId) swtmrId
+
+#define HWI_CREATE_PARAMS(hwiNum, hwiPrio, hwiMode, hwiHandler) hwiNum, hwiPrio, hwiMode, hwiHandler
+#define HWI_CREATE_SHARE_PARAMS(hwiNum, pDevId, ret) hwiNum, pDevId, ret
+#define HWI_DELETE_PARAMS(hwiNum) hwiNum
+#define HWI_DELETE_SHARE_PARAMS(hwiNum, pDevId, ret) hwiNum, pDevId, ret
+#define HWI_RESPONSE_IN_PARAMS(hwiNum) hwiNum
+#define HWI_RESPONSE_OUT_PARAMS(hwiNum) hwiNum
+#define HWI_ENABLE_PARAMS(hwiNum) hwiNum
+#define HWI_DISABLE_PARAMS(hwiNum) hwiNum
+#define HWI_TRIGGER_PARAMS(hwiNum) hwiNum
+#define HWI_SETPRI_PARAMS(hwiNum, priority) hwiNum, priority
+#define HWI_CLEAR_PARAMS(hwiNum) hwiNum
+#define HWI_SETAFFINITY_PARAMS(hwiNum, cpuMask) hwiNum, cpuMask
+#define HWI_SENDIPI_PARAMS(hwiNum, cpuMask) hwiNum, cpuMask
+
+#define EVENT_CREATE_PARAMS(eventCB) eventCB
+#define EVENT_DELETE_PARAMS(eventCB, delRetCode) eventCB, delRetCode
+#define EVENT_READ_PARAMS(eventCB, eventId, mask, mode, timeout) \
+ eventCB, eventId, mask, mode, timeout
+#define EVENT_WRITE_PARAMS(eventCB, eventId, events) eventCB, eventId, events
+#define EVENT_CLEAR_PARAMS(eventCB, eventId, events) eventCB, eventId, events
+
+#define QUEUE_CREATE_PARAMS(queueId, queueSz, itemSz, queueAddr, memType) \
+ queueId, queueSz, itemSz, queueAddr, memType
+#define QUEUE_DELETE_PARAMS(queueId, state, readable) queueId, state, readable
+#define QUEUE_RW_PARAMS(queueId, queueSize, bufSize, operateType, readable, writeable, timeout) \
+ queueId, queueSize, bufSize, operateType, readable, writeable, timeout
+
+#define SEM_CREATE_PARAMS(semId, type, count) semId, type, count
+#define SEM_DELETE_PARAMS(semId, delRetCode) semId, delRetCode
+#define SEM_PEND_PARAMS(semId, count, timeout) semId, count, timeout
+#define SEM_POST_PARAMS(semId, type, count) semId, type, count
+
+#define MUX_CREATE_PARAMS(muxId) muxId
+#define MUX_DELETE_PARAMS(muxId, state, count, owner) muxId, state, count, owner
+#define MUX_PEND_PARAMS(muxId, count, owner, timeout) muxId, count, owner, timeout
+#define MUX_POST_PARAMS(muxId, count, owner) muxId, count, owner
+
+#define MEM_ALLOC_PARAMS(pool, ptr, size) pool, ptr, size
+#define MEM_ALLOC_ALIGN_PARAMS(pool, ptr, size, boundary) pool, ptr, size, boundary
+#define MEM_REALLOC_PARAMS(pool, ptr, size) pool, ptr, size
+#define MEM_FREE_PARAMS(pool, ptr) pool, ptr
+#define MEM_INFO_REQ_PARAMS(pool) pool
+#define MEM_INFO_PARAMS(pool, usedSize, freeSize) pool, usedSize, freeSize
+
+#define SYS_ERROR_PARAMS(errno) errno
+
+#if (LOSCFG_KERNEL_TRACE == 1)
+
+/**
+ * @ingroup los_trace
+ * @brief Trace static code stub.
+ *
+ * @par Description:
+ * This API is used to instrument trace code stub in source code, to track events.
+ * @attention
+ * None.
+ *
+ * @param TYPE [IN] Type #LOS_TRACE_TYPE. The event type.
+ * @param IDENTITY [IN] Type #UINTPTR. The subject of this event description.
+ * @param ... [IN] Type #UINTPTR. This piece of event's params.
+ * @retval None.
+ *
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @since Huawei LiteOS V200R005C00
+ */
+#define LOS_TRACE(TYPE, IDENTITY, ...) \
+ do { \
+ UINTPTR _inner[] = {0, TYPE##_PARAMS((UINTPTR)IDENTITY, ##__VA_ARGS__)}; \
+ UINTPTR _n = sizeof(_inner) / sizeof(UINTPTR); \
+ if ((_n > 1) && (g_traceEventHook != NULL)) { \
+ g_traceEventHook(TYPE, _inner[1], _n > 2 ? &_inner[2] : NULL, _n - 2); \
+ } \
+ } while (0)
+#else
+#define LOS_TRACE(TYPE, ...)
+#endif
+
+#if (LOSCFG_KERNEL_TRACE == 1)
+
+/**
+ * @ingroup los_trace
+ * @brief Trace static easier user-defined code stub.
+ *
+ * @par Description:
+ * This API is used to instrument user-defined trace code stub in source code, to track events simply.
+ * @attention
+ * None.
+ *
+ * @param TYPE [IN] Type #UINT32. The event type, only low 4 bits take effect.
+ * @param IDENTITY [IN] Type #UINTPTR. The subject of this event description.
+ * @param ... [IN] Type #UINTPTR. This piece of event's params.
+ * @retval None.
+ *
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @since Huawei LiteOS V200R005C00
+ */
+#define LOS_TRACE_EASY(TYPE, IDENTITY, ...) \
+ do { \
+ UINTPTR _inner[] = {0, ##__VA_ARGS__}; \
+ UINTPTR _n = sizeof(_inner) / sizeof(UINTPTR); \
+ if (g_traceEventHook != NULL) { \
+ g_traceEventHook(TRACE_USER_DEFAULT_FLAG | TYPE, (UINTPTR)IDENTITY, _n > 1 ? &_inner[1] : NULL, _n - 1); \
+ } \
+ } while (0)
+#else
+#define LOS_TRACE_EASY(...)
+#endif
+
+/**
+ * @ingroup los_trace
+ * @brief Intialize the trace when the system startup.
+ *
+ * @par Description:
+ * This API is used to intilize the trace for system level.
+ * @attention
+ *
+ * - This API can be called only after the memory is initialized. Otherwise, the Trace Init will be fail.
+ *
+ *
+ * @param buf [IN] Type #VOID *. The ptr is trace buffer address, if ptr is NULL, system will malloc a new one in
+ * trace offline mode.
+ * @param size [IN] Type #UINT32. The trace buffer's size.
+ *
+ * @retval #LOS_ERRNO_TRACE_ERROR_STATUS 0x02001400: The trace status is not TRACE_UNINIT.
+ * @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001401: The memory is not enough for initilize.
+ * @retval #LOS_ERRNO_TRACE_BUF_TOO_SMALL 0x02001402: Trace buf size not enough.
+ * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE 0x02000211: No free task control block is available.
+ * @retval #LOS_ERRNO_TSK_MP_SYNC_RESOURCE 0x02000225: Mp sync resource create failed
+ * @retval #LOS_OK 0x00000000: The intialization is successful.
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceInit
+ * @since Huawei LiteOS V200R005C00
+ */
+extern UINT32 LOS_TraceInit(VOID *buf, UINT32 size);
+
+/**
+ * @ingroup los_trace
+ * @brief Start trace.
+ *
+ * @par Description:
+ * This API is used to start trace.
+ * @attention
+ *
+ *
+ * @param None.
+ * @retval #LOS_ERRNO_TRACE_ERROR_STATUS 0x02001400: Trace start failed.
+ * @retval #LOS_OK 0x00000000: Trace start success.
+ *
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceStart
+ * @since Huawei LiteOS V200R005C00
+ */
+extern UINT32 LOS_TraceStart(VOID);
+
+/**
+ * @ingroup los_trace
+ * @brief Stop trace sample.
+ *
+ * @par Description:
+ * This API is used to start trace sample.
+ * @attention
+ *
+ * - Stop trace sample
+ *
+ *
+ * @param None.
+ * @retval #None.
+ *
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceStop
+ * @since Huawei LiteOS V200R005C00
+ */
+extern VOID LOS_TraceStop(VOID);
+
+/**
+ * @ingroup los_trace
+ * @brief Clear the trace buf.
+ *
+ * @par Description:
+ * Clear the event frames in trace buf only at offline mode.
+ * @attention
+ *
+ * - This API can be called only after that trace buffer has been established.
+ * Otherwise, the trace will be failed.
+ *
+ *
+ * @param None.
+ * @retval #NA
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceReset
+ * @since Huawei LiteOS V200R005C00
+ */
+extern VOID LOS_TraceReset(VOID);
+
+/**
+ * @ingroup los_trace
+ * @brief Set trace event mask.
+ *
+ * @par Description:
+ * Set trace event mask.
+ * @attention
+ *
+ * - Set trace event filter mask.
+ * - The Default mask is (TRACE_HWI_FLAG | TRACE_TASK_FLAG), stands for switch on task and hwi events.
+ * - Customize mask according to the type defined in enum LOS_TRACE_MASK to switch on corresponding module's
+ * trace.
+ * - The system's trace mask will be overrode by the input parameter.
+ *
+ *
+ * @param mask [IN] Type #UINT32. The mask used to filter events of LOS_TRACE_MASK.
+ * @retval #NA.
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceEventMaskSet
+ * @since Huawei LiteOS V200R005C00
+ */
+extern VOID LOS_TraceEventMaskSet(UINT32 mask);
+
+/**
+ * @ingroup los_trace
+ * @brief Offline trace buffer display.
+ *
+ * @par Description:
+ * Display trace buf data only at offline mode.
+ * @attention
+ *
+ * - This API can be called only after that trace stopped. Otherwise the trace dump will be failed.
+ * - Trace data will be send to pipeline when user set toClient = TRUE. Otherwise it will be formatted and printed
+ * out.
+ *
+ *
+ * @param toClient [IN] Type #BOOL. Whether send trace data to Client through pipeline.
+ * @retval #NA
+ *
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceRecordDump
+ * @since Huawei LiteOS V200R005C00
+ */
+extern VOID LOS_TraceRecordDump(BOOL toClient);
+
+/**
+ * @ingroup los_trace
+ * @brief Offline trace buffer export.
+ *
+ * @par Description:
+ * Return the trace buf only at offline mode.
+ * @attention
+ *
+ * - This API can be called only after that trace buffer has been established.
+ * - The return buffer's address is a critical resource, user can only ready.
+ *
+ *
+ * @param NA
+ * @retval #OfflineHead* The trace buffer's address, analyze this buffer according to the structure of
+ * OfflineHead.
+ *
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceRecordGet
+ * @since Huawei LiteOS V200R005C00
+ */
+extern OfflineHead *LOS_TraceRecordGet(VOID);
+
+/**
+ * @ingroup los_trace
+ * @brief Hwi num fliter hook.
+ *
+ * @par Description:
+ * Hwi fliter function.
+ * @attention
+ *
+ * - Filter the hwi events by hwi num
+ *
+ *
+ * @param hook [IN] Type #TRACE_HWI_FILTER_HOOK. The user defined hook for hwi num filter,
+ * the hook should return true if you don't want trace this hwi num.
+ * @retval #None
+ * @par Dependency:
+ * - los_trace.h: the header file that contains the API declaration.
+ * @see LOS_TraceHwiFilterHookReg
+ * @since Huawei LiteOS V200R005C00
+ */
+extern VOID LOS_TraceHwiFilterHookReg(TRACE_HWI_FILTER_HOOK hook);
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* _LOS_TRACE_H */
diff --git a/components/trace/los_trace_pri.h b/components/trace/los_trace_pri.h
new file mode 100644
index 00000000..6d8d1abd
--- /dev/null
+++ b/components/trace/los_trace_pri.h
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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.h"
+#include "los_debug.h"
+#include "los_interrupt.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
+#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)
+
+#if (LOSCFG_KERNEL_SMP == 1)
+extern SPIN_LOCK_S g_traceSpin;
+#define TRACE_LOCK(state) LOS_SpinLockSave(&g_traceSpin, &(state))
+#define TRACE_UNLOCK(state) LOS_SpinUnlockRestore(&g_traceSpin, (state))
+#else
+#define TRACE_LOCK(state) (state) = LOS_IntLock()
+#define TRACE_UNLOCK(state) LOS_IntRestore(state)
+#endif
+
+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);
+
+#if (LOSCFG_RECORDER_MODE_ONLINE == 1)
+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/components/trace/pipeline/serial/trace_pipeline_serial.c b/components/trace/pipeline/serial/trace_pipeline_serial.c
new file mode 100644
index 00000000..b7131e7c
--- /dev/null
+++ b/components/trace/pipeline/serial/trace_pipeline_serial.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 */
+
+#if (LOSCFG_TRACE_CONTROL_AGENT == 1)
+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
+
+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/components/trace/pipeline/serial/trace_pipeline_serial.h b/components/trace/pipeline/serial/trace_pipeline_serial.h
new file mode 100644
index 00000000..f4085d8a
--- /dev/null
+++ b/components/trace/pipeline/serial/trace_pipeline_serial.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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_compiler.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+extern INT32 uart_putc(CHAR c);
+
+#define UART_PUTC(c) uart_putc((c))
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* _TRACE_PIPELINE_SERIAL_H */
diff --git a/components/trace/pipeline/trace_pipeline.c b/components/trace/pipeline/trace_pipeline.c
new file mode 100644
index 00000000..9fc1ffc9
--- /dev/null
+++ b/components/trace/pipeline/trace_pipeline.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 */
+
+#if (LOSCFG_KERNEL_SMP == 1)
+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))
+#else
+#define PIPE_LOCK(state) (state) = LOS_IntLock()
+#define PIPE_UNLOCK(state) LOS_IntRestore(state)
+#endif
+
+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[] = {
+#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
+ { 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) },
+
+#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
+ { 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)
+{
+ (VOID)len;
+ (VOID)data;
+}
+
+STATIC UINT32 DefaultDataReceive(UINT8 *data, UINT32 size, UINT32 timeout)
+{
+ (VOID)data;
+ (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;
+}
+
+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/components/trace/pipeline/trace_pipeline.h b/components/trace/pipeline/trace_pipeline.h
new file mode 100644
index 00000000..70a496ae
--- /dev/null
+++ b/components/trace/pipeline/trace_pipeline.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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_compiler.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/components/trace/pipeline/trace_tlv.c b/components/trace/pipeline/trace_tlv.c
new file mode 100644
index 00000000..fd89da4c
--- /dev/null
+++ b/components/trace/pipeline/trace_tlv.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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
+#define CRC_POLY 0x1021
+#define CRC_TOPBIT 0x8000
+
+STATIC UINT16 CalcCrc16(const UINT8 *buf, UINT32 len)
+{
+ 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)
+{
+ 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);
+}
+
+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;
+}
+
+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/components/trace/pipeline/trace_tlv.h b/components/trace/pipeline/trace_tlv.h
new file mode 100644
index 00000000..27d2749b
--- /dev/null
+++ b/components/trace/pipeline/trace_tlv.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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_compiler.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;
+} TraceMsgTlvHead;
+
+typedef struct {
+ UINT8 type;
+ UINT8 len;
+ UINT8 value[];
+} TraceMsgTlvBody;
+
+typedef struct {
+ UINT8 tag;
+ UINT8 elemOffset;
+ UINT8 elemSize;
+} TlvTable;
+
+/**
+ * @ingroup los_trace
+ * @brief Encode trace raw data.
+ *
+ * @par Description:
+ * This API is used to encode trace raw data to tlv data.
+ * @attention
+ *
+ * - Encade trace data
+ *
+ *
+ * @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:
+ * - trace_tlv.h: the header file that contains the API declaration.
+ * @see LOS_TraceDataEncode
+ * @since Huawei LiteOS V200R005C00
+ */
+extern UINT32 OsTraceDataEncode(UINT8 type, const TlvTable *table, UINT8 *src, UINT8 *dest, INT32 destLen);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif /* _TRACE_TLV_H */
diff --git a/components/trace/trace_offline.c b/components/trace/trace_offline.c
new file mode 100644
index 00000000..0d972996
--- /dev/null
+++ b/components/trace/trace_offline.c
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 */
+
+#if (LOSCFG_RECORDER_MODE_OFFLINE == 1)
+#define BITS_NUM_FOR_TASK_ID 16
+
+LITE_OS_SEC_BSS STATIC TraceOfflineHeaderInfo g_traceRecoder;
+LITE_OS_SEC_BSS STATIC UINT32 g_tidMask[LOSCFG_BASE_CORE_TSK_LIMIT] = {0};
+
+UINT32 OsTraceGetMaskTid(UINT32 tid)
+{
+ 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_aucSysMem0, 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 = OS_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 ");
+#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
+ PRINTK("cpuId hwiActive taskLockCnt ");
+#endif
+#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
+ 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, (UINT32)frame->curTime, frame->eventType,
+ frame->curTask, frame->identity);
+#if (LOSCFG_TRACE_FRAME_CORE_MSG == 1)
+ UINT32 taskLockCnt = frame->core.taskLockCnt;
+#if (LOSCFG_KERNEL_SMP == 1)
+ /*
+ * 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
+#if (LOSCFG_TRACE_FRAME_EVENT_COUNT == 1)
+ 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");
+}
+
+#if (LOSCFG_TRACE_CLIENT_INTERACT == 1)
+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;
+ }
+
+#if (LOSCFG_TRACE_CLIENT_INTERACT == 1)
+ OsTraceSendInfo();
+#endif
+}
+
+OfflineHead *OsTraceRecordGet(VOID)
+{
+ return g_traceRecoder.head;
+}
+
+#endif /* LOSCFG_RECORDER_MODE_OFFLINE == 1 */
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/components/trace/trace_online.c b/components/trace/trace_online.c
new file mode 100644
index 00000000..57be79ec
--- /dev/null
+++ b/components/trace/trace_online.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * 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 */
+
+#if (LOSCFG_RECORDER_MODE_ONLINE == 1)
+UINT32 OsTraceGetMaskTid(UINT32 taskId)
+{
+ 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 = OS_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)
+{
+ 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 == 1 */
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
diff --git a/config.gni b/config.gni
index d9c0f837..68919cc7 100644
--- a/config.gni
+++ b/config.gni
@@ -37,6 +37,7 @@ declare_args() {
enable_ohos_kernel_liteos_m_backtrace = true
enable_ohos_kernel_liteos_m_test = false
enable_ohos_kernel_liteos_m_pm = true
+ enable_ohos_kernel_liteos_m_trace = false
enable_ohos_kernel_liteos_m_lwip = false
ohos_kernel_liteos_m_lwip_path = "components/net/lwip-2.1:lwip"
}
diff --git a/kernel/include/los_config.h b/kernel/include/los_config.h
index c5cd8616..fec0de38 100644
--- a/kernel/include/los_config.h
+++ b/kernel/include/los_config.h
@@ -613,6 +613,52 @@ extern UINT8 *m_aucSysMem0;
#define LOSCFG_DEBUG_HOOK 0
#endif
+#if (LOSCFG_DEBUG_HOOK == 1)
+#ifndef LOSCFG_KERNEL_TRACE
+#define LOSCFG_KERNEL_TRACE 0
+#endif
+#endif
+
+#if (LOSCFG_KERNEL_TRACE == 1)
+
+#ifndef LOSCFG_TRACE_FRAME_MAX_PARAMS
+#define LOSCFG_TRACE_FRAME_MAX_PARAMS 3
+#endif
+
+#ifndef LOSCFG_TRACE_FRAME_EVENT_COUNT
+#define LOSCFG_TRACE_FRAME_EVENT_COUNT 0
+#endif
+
+#ifndef LOSCFG_RECORDER_MODE_OFFLINE
+#define LOSCFG_RECORDER_MODE_OFFLINE 1
+#endif
+
+#ifndef LOSCFG_RECORDER_MODE_ONLINE
+#define LOSCFG_RECORDER_MODE_ONLINE 0
+#endif
+
+#if (!(LOSCFG_RECORDER_MODE_OFFLINE ^ LOSCFG_RECORDER_MODE_ONLINE))
+#error One of LOSCFG_RECORDER_MODE_OFFLINE and LOSCFG_RECORDER_MODE_ONLINE should be set to 1 and only.
+#endif
+
+#ifndef LOSCFG_TRACE_CLIENT_INTERACT
+#define LOSCFG_TRACE_CLIENT_INTERACT 1
+#endif
+
+#ifndef LOSCFG_TRACE_BUFFER_SIZE
+#define LOSCFG_TRACE_BUFFER_SIZE 2048
+#endif
+
+#ifndef NUM_HAL_INTERRUPT_UART
+#define NUM_HAL_INTERRUPT_UART 0xff
+#endif
+
+#ifndef OS_TICK_INT_NUM
+#define OS_TICK_INT_NUM 0xff
+#endif
+
+#endif
+
/* =============================================================================
PM module configuration
============================================================================= */
diff --git a/kernel/src/los_event.c b/kernel/src/los_event.c
index d2e5520c..f81f1ff5 100644
--- a/kernel/src/los_event.c
+++ b/kernel/src/los_event.c
@@ -110,7 +110,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UIN
}
intSave = LOS_IntLock();
ret = LOS_EventPoll(&(eventCB->uwEventID), eventMask, mode);
- OsHookCall(LOS_HOOK_TYPE_EVENT_READ, eventCB, eventMask, mode);
+ OsHookCall(LOS_HOOK_TYPE_EVENT_READ, eventCB, eventMask, mode, timeOut);
if (ret == 0) {
if (timeOut == 0) {
LOS_IntRestore(intSave);
@@ -158,8 +158,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
return LOS_ERRNO_EVENT_SETBIT_INVALID;
}
intSave = LOS_IntLock();
+ OsHookCall(LOS_HOOK_TYPE_EVENT_WRITE, eventCB, events);
eventCB->uwEventID |= events;
- OsHookCall(LOS_HOOK_TYPE_EVENT_WRITE, eventCB);
if (!LOS_ListEmpty(&eventCB->stEventList)) {
for (resumedTask = LOS_DL_LIST_ENTRY((&eventCB->stEventList)->pstNext, LosTaskCB, pendList);
&resumedTask->pendList != (&eventCB->stEventList);) {
@@ -210,10 +210,10 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 eventMa
if (eventCB == NULL) {
return LOS_ERRNO_EVENT_PTR_NULL;
}
+ OsHookCall(LOS_HOOK_TYPE_EVENT_CLEAR, eventCB, eventMask);
intSave = LOS_IntLock();
eventCB->uwEventID &= eventMask;
LOS_IntRestore(intSave);
- OsHookCall(LOS_HOOK_TYPE_EVENT_CLEAR, eventCB);
return LOS_OK;
}
diff --git a/kernel/src/los_init.c b/kernel/src/los_init.c
index 93b7e01a..2dde91fa 100644
--- a/kernel/src/los_init.c
+++ b/kernel/src/los_init.c
@@ -182,6 +182,14 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
return ret;
}
+#if (LOSCFG_KERNEL_TRACE == 1)
+ ret = LOS_TraceInit(NULL, LOSCFG_TRACE_BUFFER_SIZE);
+ if (ret != LOS_OK) {
+ PRINT_ERR("LOS_TraceInit error\n");
+ return ret;
+ }
+#endif
+
#if (LOSCFG_KERNEL_PM == 1)
ret = OsPmInit();
if (ret != LOS_OK) {
diff --git a/kernel/src/los_mux.c b/kernel/src/los_mux.c
index 4f3f5923..cefddd7d 100644
--- a/kernel/src/los_mux.c
+++ b/kernel/src/los_mux.c
@@ -230,7 +230,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout)
OsSchedTaskWait(&muxPended->muxList, timeout);
LOS_IntRestore(intSave);
- OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended);
+ OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout);
LOS_Schedule();
intSave = LOS_IntLock();
@@ -244,7 +244,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout)
return LOS_OK;
HOOK:
- OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended);
+ OsHookCall(LOS_HOOK_TYPE_MUX_PEND, muxPended, timeout);
return LOS_OK;
ERROR_MUX_PEND:
diff --git a/kernel/src/los_queue.c b/kernel/src/los_queue.c
index 863d0a22..3c19f92e 100644
--- a/kernel/src/los_queue.c
+++ b/kernel/src/los_queue.c
@@ -397,7 +397,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueID, VOID *bufferAddr, UINT32 b
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD, OS_QUEUE_POINT);
- OsHookCall(LOS_HOOK_TYPE_QUEUE_READ, (LosQueueCB *)GET_QUEUE_HANDLE(queueID));
+ OsHookCall(LOS_HOOK_TYPE_QUEUE_READ, (LosQueueCB *)GET_QUEUE_HANDLE(queueID), operateType, bufferSize, timeOut);
return OsQueueOperate(queueID, operateType, bufferAddr, &bufferSize, timeOut);
}
@@ -416,7 +416,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueID, VOID *bufferAddr, UINT32
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL, OS_QUEUE_POINT);
- OsHookCall(LOS_HOOK_TYPE_QUEUE_WRITE, (LosQueueCB *)GET_QUEUE_HANDLE(queueID));
+ OsHookCall(LOS_HOOK_TYPE_QUEUE_WRITE, (LosQueueCB *)GET_QUEUE_HANDLE(queueID), operateType, size, timeOut);
return OsQueueOperate(queueID, operateType, &bufferAddr, &size, timeOut);
}
diff --git a/kernel/src/los_sem.c b/kernel/src/los_sem.c
index 13e0fb6c..ebc31328 100644
--- a/kernel/src/los_sem.c
+++ b/kernel/src/los_sem.c
@@ -235,7 +235,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
if (semPended->semCount > 0) {
semPended->semCount--;
LOS_IntRestore(intSave);
- OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask);
+ OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask, timeout);
return LOS_OK;
}
@@ -248,7 +248,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
runningTask->taskSem = (VOID *)semPended;
OsSchedTaskWait(&semPended->semList, timeout);
LOS_IntRestore(intSave);
- OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask);
+ OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runningTask, timeout);
LOS_Schedule();
intSave = LOS_IntLock();
diff --git a/kernel/src/los_swtmr.c b/kernel/src/los_swtmr.c
index 3171aa58..22e41f97 100644
--- a/kernel/src/los_swtmr.c
+++ b/kernel/src/los_swtmr.c
@@ -36,6 +36,7 @@
#include "los_memory.h"
#include "los_queue.h"
#include "los_debug.h"
+#include "los_hook.h"
#include "los_sched.h"
@@ -292,6 +293,7 @@ STATIC BOOL OsSwtmrScan(VOID)
OsDeleteNodeSortLink(g_swtmrSortLinkList, sortList);
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
+ OsHookCall(LOS_HOOK_TYPE_SWTMR_EXPIRED, swtmr);
OsSwtmrTimeoutHandle(swtmr);
needSchedule = TRUE;
@@ -475,7 +477,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
*swtmrId = swtmr->usTimerID;
SET_SORTLIST_VALUE(&swtmr->stSortList, OS_SORT_LINK_INVALID_TIME);
-
+ OsHookCall(LOS_HOOK_TYPE_SWTMR_CREATE, swtmr);
return LOS_OK;
}
@@ -529,6 +531,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT32 swtmrId)
}
LOS_IntRestore(intSave);
+ OsHookCall(LOS_HOOK_TYPE_SWTMR_START, swtmr);
return ret;
}
@@ -573,6 +576,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT32 swtmrId)
}
LOS_IntRestore(intSave);
+ OsHookCall(LOS_HOOK_TYPE_SWTMR_STOP, swtmr);
return ret;
}
@@ -658,6 +662,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT32 swtmrId)
}
LOS_IntRestore(intSave);
+ OsHookCall(LOS_HOOK_TYPE_SWTMR_DELETE, swtmr);
return ret;
}
diff --git a/kernel/src/mm/los_memory.c b/kernel/src/mm/los_memory.c
index ba6ce980..efb84e55 100644
--- a/kernel/src/mm/los_memory.c
+++ b/kernel/src/mm/los_memory.c
@@ -1013,7 +1013,7 @@ VOID *LOS_MemAlloc(VOID *pool, UINT32 size)
} while (0);
MEM_UNLOCK(poolHead, intSave);
- OsHookCall(LOS_HOOK_TYPE_MEM_ALLOC, pool, size);
+ OsHookCall(LOS_HOOK_TYPE_MEM_ALLOC, pool, ptr, size);
return ptr;
}
@@ -1068,7 +1068,7 @@ VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
} while (0);
MEM_UNLOCK(poolHead, intSave);
- OsHookCall(LOS_HOOK_TYPE_MEM_ALLOCALIGN, pool, size, boundary);
+ OsHookCall(LOS_HOOK_TYPE_MEM_ALLOCALIGN, pool, ptr, size, boundary);
return ptr;
}
diff --git a/utils/internal/los_hook_types.h b/utils/internal/los_hook_types.h
index 999c90cf..bd4165e1 100644
--- a/utils/internal/los_hook_types.h
+++ b/utils/internal/los_hook_types.h
@@ -40,6 +40,7 @@
#include "los_queue.h"
#include "los_sem.h"
#include "los_task.h"
+#include "los_swtmr.h"
#ifdef __cplusplus
#if __cplusplus
@@ -52,30 +53,34 @@ extern "C" {
/* Hook types supported by memory modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_INIT, (VOID *pool, UINT32 size)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_DEINIT, (VOID *pool)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOC, (VOID *pool, UINT32 size)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOC, (VOID *pool, VOID *ptr, UINT32 size)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_FREE, (VOID *pool, VOID *ptr)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_REALLOC, (VOID *pool, VOID *ptr, UINT32 size)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOCALIGN, (VOID *pool, UINT32 size, UINT32 boundary)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOCALIGN, (VOID *pool, VOID *ptr, UINT32 size, UINT32 boundary)) \
/* Hook types supported by event modules */ \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_INIT, (PEVENT_CB_S eventCB)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_READ, (PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_WRITE, (PEVENT_CB_S eventCB)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_CLEAR, (PEVENT_CB_S eventCB)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_DESTROY, (PEVENT_CB_S eventCB)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_INIT, (PEVENT_CB_S eventCB)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_READ, (PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, \
+ UINT32 timeout)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_WRITE, (PEVENT_CB_S eventCB, UINT32 events)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_CLEAR, (PEVENT_CB_S eventCB, UINT32 events)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_DESTROY, (PEVENT_CB_S eventCB)) \
/* Hook types supported by queue modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_CREATE, (const LosQueueCB *queueCB)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_READ, (const LosQueueCB *queueCB)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_WRITE, (const LosQueueCB *queueCB)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_READ, (const LosQueueCB *queueCB, UINT32 operateType, \
+ UINT32 bufferSize, UINT32 timeout)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_WRITE, (const LosQueueCB *queueCB, UINT32 operateType, \
+ UINT32 bufferSize, UINT32 timeout)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_DELETE, (const LosQueueCB *queueCB)) \
/* Hook types supported by semphore modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_CREATE, (const LosSemCB *semCreated)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_POST, (const LosSemCB *semPosted, const LosTaskCB *resumedTask)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_PEND, (const LosSemCB *semPended, const LosTaskCB *runningTask)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_PEND, (const LosSemCB *semPended, const LosTaskCB *runningTask, \
+ UINT32 timeout)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_DELETE, (const LosSemCB *semDeleted)) \
/* Hook types supported by mutex modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_CREATE, (const LosMuxCB *muxCreated)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_POST, (const LosMuxCB *muxPosted)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_PEND, (const LosMuxCB *muxPended)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_PEND, (const LosMuxCB *muxPended, UINT32 timeout)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_DELETE, (const LosMuxCB *muxDeleted)) \
/* Hook types supported by task modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_CREATE, (const LosTaskCB *taskCB)) \
@@ -89,7 +94,13 @@ extern "C" {
/* Hook types supported by interrupt modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_EXITTOSCHEDULER, (VOID)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_ENTER, (UINT32 hwiIndex)) \
- LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_EXIT, (UINT32 hwiIndex))
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_EXIT, (UINT32 hwiIndex)) \
+ /* Hook types supported by swtmr modules */ \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_CREATE, (const SWTMR_CTRL_S *swtmr)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_DELETE, (const SWTMR_CTRL_S *swtmr)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_EXPIRED, (const SWTMR_CTRL_S *swtmr)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_START, (const SWTMR_CTRL_S *swtmr)) \
+ LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SWTMR_STOP, (const SWTMR_CTRL_S *swtmr))
/**
* Defines the types of all hooks.
diff --git a/utils/internal/los_hook_types_parse.h b/utils/internal/los_hook_types_parse.h
index 287ad81a..cd01859d 100644
--- a/utils/internal/los_hook_types_parse.h
+++ b/utils/internal/los_hook_types_parse.h
@@ -48,6 +48,7 @@
#define ARG_CP_UINT32 ADDR(
#define ARG_CP_LosMuxCB ADDR(
#define ARG_CP_LosQueueCB ADDR(
+#define ARG_CP_SWTMR_CTRL_S ADDR(
#define ARG_UINT32 ARGS(
#define ARG_PEVENT_CB_S ARGS(
#define ARG_void ADDRn(