feat: L0-L1 支持Trace

1.【需求描述】
            L0~L1 支持Trace,提供两种工作模式:在线模式、离线缓存模式, 用于按时间线追踪系统事件,如任务切换、中断、ipc等。
        2.【方案描述】
            L0:
            (1).在内核模块预置静态代码桩
            (2).触发桩后,收集系统上下文信息
            (3).离线模式则写入内存,用户可通过dump导出;
            (4).在线模式通过pipeline对接IDE进行可视化解析和展示;
            L1:
            新增trace字符设备,位于"/dev/trace",通过对设备节点的read\write\ioctl,实现用户态trace;

        BREAKING CHANGE:
        1.新增一系列trace的对外API,位于los_trace.h中.
        LOS_TRACE_EASY简易插桩
        LOS_TRACE标准插桩
        LOS_TraceInit配置Trace缓冲区的地址和大小
        LOS_TraceStart开启事件记录
        LOS_TraceStop停止事件记录
        LOS_TraceRecordDump输出Trace缓冲区数据
        LOS_TraceRecordGet获取Trace缓冲区的首地址
        LOS_TraceReset清除Trace缓冲区中的事件
        LOS_TraceEventMaskSet设置事件掩码,仅记录某些模块的事件
        LOS_TraceHwiFilterHookReg注册过滤特定中断号事件的钩子函数

        Close #I46WA0

    Signed-off-by: LiteOS2021 <dinglu@huawei.com>

Change-Id: I6a8e64794c4852f2c2980993a06180e09ec6ee0d
This commit is contained in:
LiteOS2021
2021-08-31 16:36:04 +08:00
parent 658fafe83b
commit dc9ec6856f
62 changed files with 3972 additions and 1050 deletions

View File

@@ -38,6 +38,7 @@ group("extended") {
"liteipc",
"pipes",
"power",
"hook",
"trace",
"vdso",
]
@@ -48,7 +49,7 @@ config("public") {
"cpup:public",
"dynload:public",
"vdso:public",
"trace:public",
"hook:public",
"liteipc:public",
"pipes:public",
"hilog:public",

View File

@@ -0,0 +1,42 @@
# 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.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_KERNEL_HOOK)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "los_hook.c" ]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "include" ]
}

View File

@@ -0,0 +1,36 @@
# 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 $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
include $(MODULE)

View File

@@ -0,0 +1,153 @@
/*
* 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_HOOK_TYPES_H
#define _LOS_HOOK_TYPES_H
#include "los_config.h"
#include "los_event_pri.h"
#include "los_mux_pri.h"
#include "los_queue_pri.h"
#include "los_sem_pri.h"
#include "los_task_pri.h"
#include "los_swtmr_pri.h"
#include "hm_liteipc.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_KERNEL_HOOK
#define LOS_HOOK_ALL_TYPES_DEF \
/* 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, 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, 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, \
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, 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, \
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 LosMux *muxCreated)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_POST, (const LosMux *muxPosted)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_PEND, (const LosMux *muxPended, UINT32 timeout)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_DELETE, (const LosMux *muxDeleted)) \
/* Hook types supported by task modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_CREATE, (const LosTaskCB *taskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_DELAY, (UINT32 tick)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_PRIMODIFY, (const LosTaskCB *pxTask, UINT32 uxNewPriority)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_DELETE, (const LosTaskCB *taskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_SWITCHEDIN, (const LosTaskCB *newTask, const LosTaskCB *runTask)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTOREADYSTATE, (const LosTaskCB *pstTaskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, (const LosTaskCB *pstTaskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, (const LosTaskCB *pstTaskCB)) \
/* 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)) \
/* 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)) \
/* Hook types supported by liteipc modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_IPC_WRITE_DROP, (const IpcMsg *msg, UINT32 dstTid, UINT32 dstPid, \
UINT32 ipcStatus)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_IPC_WRITE, (const IpcMsg *msg, UINT32 dstTid, UINT32 dstPid, \
UINT32 ipcStatus)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_IPC_READ_DROP, (const IpcMsg *msg, UINT32 ipcStatus)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_IPC_READ, (const IpcMsg *msg, UINT32 ipcStatus)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_IPC_TRY_READ, (UINT32 msgType, UINT32 ipcStatus)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_IPC_READ_TIMEOUT, (UINT32 msgType, UINT32 ipcStatus)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_IPC_KILL, (UINT32 msgType, UINT32 ipcStatus)) \
/* Hook types supported by usr modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_USR_EVENT, (VOID *buffer, UINT32 len))
/**
* Defines the types of all hooks.
*/
#define LOS_HOOK_TYPE_DEF(type, paramList) type,
typedef enum {
/* Used to manage hook pools */
LOS_HOOK_TYPE_START = 0,
/* All supported hook types */
LOS_HOOK_ALL_TYPES_DEF
/* Used to manage hook pools */
LOS_HOOK_TYPE_END
} HookType;
#undef LOS_HOOK_TYPE_DEF
/**
* Declare the type and interface of the hook functions.
*/
#define LOS_HOOK_TYPE_DEF(type, paramList) \
typedef VOID (*type##_FN) paramList; \
extern UINT32 type##_RegHook(type##_FN func); \
extern UINT32 type##_UnRegHook(type##_FN func); \
extern VOID type##_CallHook paramList;
LOS_HOOK_ALL_TYPES_DEF
#undef LOS_HOOK_TYPE_DEF
#endif /* LOSCFG_KERNEL_HOOK */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HOOK_TYPES_H */

View File

@@ -0,0 +1,76 @@
/*
* 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_HOOK_TYPES_PARSE_H
#define _LOS_HOOK_TYPES_PARSE_H
#define ADDR(a) (&(a))
#define ARGS(a) (a)
#define ADDRn(...) _CONCAT(ADDR, _NARGS(__VA_ARGS__))(__VA_ARGS__)
#define ARGSn(...) _CONCAT(ARGS, _NARGS(__VA_ARGS__))(__VA_ARGS__)
#define ARGS0()
#define ADDR0()
#define ARGS1(a) ARGS(a)
#define ADDR1(a) ADDR(a)
#define ARG_const _ARG_const(
#define _ARG_const(a) ARG_CP_##a)
#define ARG_CP_LosSemCB ADDR(
#define ARG_CP_LosTaskCB ADDR(
#define ARG_CP_UINT32 ADDR(
#define ARG_CP_LosMux ADDR(
#define ARG_CP_LosQueueCB ADDR(
#define ARG_CP_SWTMR_CTRL_S ADDR(
#define ARG_CP_IpcMsg ADDR(
#define ARG_UINT32 ARGS(
#define ARG_PEVENT_CB_S ARGS(
#define ARG_void ADDRn(
#define ARG(a) ARG_##a)
#define PARAM_TO_ARGS1(a) ARG(a)
#define PARAM_TO_ARGS2(a, b) ARG(a), PARAM_TO_ARGS1(b)
#define PARAM_TO_ARGS3(a, b, c) ARG(a), PARAM_TO_ARGS2(b, c)
#define PARAM_TO_ARGS4(a, b, c, d) ARG(a), PARAM_TO_ARGS3(b, c, d)
#define PARAM_TO_ARGS5(a, b, c, d, e) ARG(a), PARAM_TO_ARGS4(b, c, d, e)
#define PARAM_TO_ARGS6(a, b, c, d, e, f) ARG(a), PARAM_TO_ARGS5(b, c, d, e, f)
#define PARAM_TO_ARGS7(a, b, c, d, e, f, g) ARG(a), PARAM_TO_ARGS6(b, c, d, e, f, g)
#define _ZERO_ARGS 7, 6, 5, 4, 3, 2, 1, 0
#define ___NARGS(a, b, c, d, e, f, g, h, n, ...) n
#define __NARGS(...) ___NARGS(__VA_ARGS__)
#define _NARGS(...) __NARGS(x, __VA_ARGS__##_ZERO_ARGS, 7, 6, 5, 4, 3, 2, 1, 0)
#define __CONCAT(a, b) a##b
#define _CONCAT(a, b) __CONCAT(a, b)
#define PARAM_TO_ARGS(...) _CONCAT(PARAM_TO_ARGS, _NARGS(__VA_ARGS__))(__VA_ARGS__)
#define OS_HOOK_PARAM_TO_ARGS(paramList) (PARAM_TO_ARGS paramList)
#endif /* _LOS_HOOK_TYPES_PARSE_H */

View File

@@ -0,0 +1,66 @@
/*
* 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_hook.h"
#include "los_hook_types_parse.h"
#ifdef LOSCFG_KERNEL_HOOK
#define LOS_HOOK_TYPE_DEF(type, paramList) \
STATIC type##_FN g_fn##type; \
UINT32 type##_RegHook(type##_FN func) { \
if ((func) == NULL) { \
return LOS_ERRNO_HOOK_REG_INVALID; \
} \
if (g_fn##type) { \
return LOS_ERRNO_HOOK_POOL_IS_FULL; \
} \
g_fn##type = (func); \
return LOS_OK; \
} \
UINT32 type##_UnRegHook(type##_FN func) { \
if (((func) == NULL) || (g_fn##type != (func))) { \
return LOS_ERRNO_HOOK_UNREG_INVALID; \
} \
g_fn##type = NULL; \
return LOS_OK; \
} \
VOID type##_CallHook paramList { \
if (g_fn##type) { \
g_fn##type(PARAM_TO_ARGS paramList); \
} \
}
LOS_HOOK_ALL_TYPES_DEF;
#undef LOS_HOOK_TYPE_DEF
#endif /* LOSCFG_DEBUG_HOOK */

View File

@@ -40,14 +40,11 @@
#include "los_sched_pri.h"
#include "los_spinlock.h"
#include "los_task_pri.h"
#ifdef LOSCFG_KERNEL_TRACE
#include "los_trace.h"
#include "los_trace_frame.h"
#endif
#include "los_vm_lock.h"
#include "los_vm_map.h"
#include "los_vm_page.h"
#include "los_vm_phys.h"
#include "los_hook.h"
#define USE_TASKID_AS_HANDLE YES
#define USE_MMAP YES
@@ -93,7 +90,6 @@ STATIC UINT32 LiteIpcWrite(IpcContent *content);
STATIC UINT32 GetTid(UINT32 serviceHandle, UINT32 *taskID);
STATIC UINT32 HandleSpecialObjects(UINT32 dstTid, IpcListNode *node, BOOL isRollback);
STATIC const struct file_operations_vfs g_liteIpcFops = {
.open = LiteIpcOpen, /* open */
.close = LiteIpcClose, /* close */
@@ -101,47 +97,6 @@ STATIC const struct file_operations_vfs g_liteIpcFops = {
.mmap = LiteIpcMmap, /* mmap */
};
#ifdef LOSCFG_KERNEL_TRACE
typedef enum {
WRITE,
WRITE_DROP,
TRY_READ,
READ,
READ_DROP,
READ_TIMEOUT,
KILL,
OPERATION_NUM
} IpcOpertion;
const char *g_operStr[OPERATION_NUM] = {"WRITE", "WRITE_DROP", "TRY_READ", "READ", "READ_DROP", "READ_TIMEOUT"};
const char *g_msgTypeStr[MT_NUM] = {"REQUEST", "REPLY", "FAILED_REPLY", "DEATH_NOTIFY"};
const char *g_ipcStatusStr[2] = {"NOT_PEND", "PEND"};
LITE_OS_SEC_TEXT STATIC VOID IpcTrace(IpcMsg *msg, UINT32 operation, UINT32 ipcStatus, UINT32 msgType)
{
UINT32 curTid = LOS_CurTaskIDGet();
UINT32 curPid = LOS_GetCurrProcessID();
UINT32 srcTid;
UINT32 srcPid;
UINT32 dstTid;
UINT32 dstPid;
UINT32 ret = (msg == NULL) ? INVAILD_ID : GetTid(msg->target.handle, &dstTid);
if (operation <= WRITE_DROP) {
srcTid = curTid;
srcPid = curPid;
dstTid = ret ? INVAILD_ID : dstTid;
dstPid = ret ? INVAILD_ID : OS_TCB_FROM_TID(dstTid)->processID;
} else {
srcTid = (msg == NULL) ? INVAILD_ID : msg->taskID;
srcPid = (msg == NULL) ? INVAILD_ID : msg->processID;
dstTid = curTid;
dstPid = curPid;
}
UINT8 code = (msg == NULL) ? INVAILD_ID : (UINT8)msg->code;
LOS_Trace(LOS_TRACE_IPC, srcTid, srcPid, dstTid, dstPid, msgType, code, operation, ipcStatus);
}
#endif
LITE_OS_SEC_TEXT_INIT UINT32 OsLiteIpcInit(VOID)
{
UINT32 ret, i;
@@ -162,12 +117,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsLiteIpcInit(VOID)
for (i = 0; i < LOSCFG_BASE_CORE_PROCESS_LIMIT; i++) {
LOS_ListInit(&(g_ipcUsedNodelist[i]));
}
#ifdef LOSCFG_KERNEL_TRACE
ret = LOS_TraceReg(LOS_TRACE_IPC, OsIpcTrace, LOS_TRACE_IPC_NAME, LOS_TRACE_ENABLE);
if (ret != LOS_OK) {
PRINT_ERR("liteipc LOS_TraceReg failed:%d\n", ret);
}
#endif
return ret;
}
@@ -941,9 +891,14 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckPara(IpcContent *content, UINT32 *dstTid)
}
#if (USE_TIMESTAMP == YES)
if (now > msg->timestamp + LITEIPC_TIMEOUT_NS) {
#ifdef LOSCFG_KERNEL_TRACE
IpcTrace(msg, WRITE_DROP, 0, msg->type);
#ifdef LOSCFG_KERNEL_HOOK
ret = GetTid(msg->target.handle, dstTid);
if (ret != LOS_OK) {
*dstTid = INVAILD_ID;
}
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_WRITE_DROP, msg, *dstTid,
(*dstTid == INVAILD_ID) ? INVAILD_ID : OS_TCB_FROM_TID(*dstTid)->processID, 0);
PRINT_ERR("A timeout reply, request timestamp:%lld, now:%lld\n", msg->timestamp, now);
return -ETIME;
}
@@ -999,9 +954,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcWrite(IpcContent *content)
SCHEDULER_LOCK(intSave);
LosTaskCB *tcb = OS_TCB_FROM_TID(dstTid);
LOS_ListTailInsert(&(tcb->msgListHead), &(buf->listNode));
#ifdef LOSCFG_KERNEL_TRACE
IpcTrace(&buf->msg, WRITE, tcb->ipcStatus, buf->msg.type);
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_WRITE, &buf->msg, dstTid, tcb->processID, tcb->ipcStatus);
if (tcb->ipcStatus & IPC_THREAD_STATUS_PEND) {
tcb->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
OsTaskWakeClearPendMask(tcb);
@@ -1059,15 +1012,11 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckRecievedMsg(IpcListNode *node, IpcContent *c
ret = -EINVAL;
}
if (ret != LOS_OK) {
#ifdef LOSCFG_KERNEL_TRACE
IpcTrace(&node->msg, READ_DROP, tcb->ipcStatus, node->msg.type);
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_READ_DROP, &node->msg, tcb->ipcStatus);
(VOID)HandleSpecialObjects(LOS_CurTaskIDGet(), node, TRUE);
(VOID)LiteIpcNodeFree(LOS_GetCurrProcessID(), (VOID *)node);
} else {
#ifdef LOSCFG_KERNEL_TRACE
IpcTrace(&node->msg, READ, tcb->ipcStatus, node->msg.type);
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_READ, &node->msg, tcb->ipcStatus);
}
return ret;
}
@@ -1087,24 +1036,18 @@ LITE_OS_SEC_TEXT STATIC UINT32 LiteIpcRead(IpcContent *content)
do {
SCHEDULER_LOCK(intSave);
if (LOS_ListEmpty(listHead)) {
#ifdef LOSCFG_KERNEL_TRACE
IpcTrace(NULL, TRY_READ, tcb->ipcStatus, syncFlag ? MT_REPLY : MT_REQUEST);
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_TRY_READ, syncFlag ? MT_REPLY : MT_REQUEST, tcb->ipcStatus);
tcb->ipcStatus |= IPC_THREAD_STATUS_PEND;
OsTaskWaitSetPendMask(OS_TASK_WAIT_LITEIPC, OS_INVALID_VALUE, timeout);
ret = OsSchedTaskWait(&g_ipcPendlist, timeout, TRUE);
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
#ifdef LOSCFG_KERNEL_TRACE
IpcTrace(NULL, READ_TIMEOUT, tcb->ipcStatus, syncFlag ? MT_REPLY : MT_REQUEST);
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_READ_TIMEOUT, syncFlag ? MT_REPLY : MT_REQUEST, tcb->ipcStatus);
SCHEDULER_UNLOCK(intSave);
return -ETIME;
}
if (OsTaskIsKilled(tcb)) {
#if (LOSCFG_KERNEL_TRACE == YES)
IpcTrace(NULL, KILL, tcb->ipcStatus, syncFlag ? MT_REPLY : MT_REQUEST);
#endif
OsHookCall(LOS_HOOK_TYPE_IPC_KILL, syncFlag ? MT_REPLY : MT_REQUEST, tcb->ipcStatus);
SCHEDULER_UNLOCK(intSave);
return -ERFKILL;
}

View File

@@ -34,12 +34,32 @@ module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"los_trace.c",
"los_trace_frame.c",
"cnv/trace_cnv.c",
]
public_configs = [ ":public" ]
}
include_dirs = [
".",
"cnv",
"pipeline",
]
config("public") {
include_dirs = [ "." ]
if (defined(LOSCFG_RECORDER_MODE_OFFLINE)){
sources += [ "trace_offline.c" ]
}
if (defined(LOSCFG_RECORDER_MODE_ONLINE)){
sources += [ "trace_online.c" ]
}
if (defined(LOSCFG_TRACE_CLIENT_INTERACT)) {
sources += [
"pipeline/trace_pipeline.c",
"pipeline/trace_tlv.c",
]
}
if (defined(LOSCFG_TRACE_PIPELINE_SERIAL)) {
sources += [ "pipeline/serial/trace_pipeline_serial.c" ]
include_dirs += [ "pipeline/serial" ]
}
}

View File

@@ -31,12 +31,32 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
LOCAL_SRCS := los_trace.c
LOCAL_SRCS += $(wildcard cnv/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include -I $(LITEOSTOPDIR)/kernel/extended/include
-I $(LITEOSTOPDIR)/kernel/extended/trace \
-I $(LITEOSTOPDIR)/kernel/extended/trace/pipeline \
-I $(LITEOSTOPDIR)/kernel/extended/trace/cnv
LOCAL_FLAGS := $(LOCAL_INCLUDE)
ifeq ($(LOSCFG_RECORDER_MODE_OFFLINE), y)
LOCAL_SRCS += trace_offline.c
endif
ifeq ($(LOSCFG_RECORDER_MODE_ONLINE), y)
LOCAL_SRCS += trace_online.c
endif
ifeq ($(LOSCFG_TRACE_CLIENT_INTERACT), y)
LOCAL_SRCS += $(wildcard pipeline/*.c)
endif
ifeq ($(LOSCFG_TRACE_PIPELINE_SERIAL), y)
LOCAL_SRCS += $(wildcard pipeline/serial/*.c)
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/kernel/extended/trace/pipeline/serial
endif
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -0,0 +1,316 @@
/*
* 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 "hm_liteipc.h"
#include "los_hook.h"
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 LosMux *muxCB)
{
LOS_TRACE(MUX_CREATE, (UINTPTR)muxCB);
}
STATIC VOID LOS_TraceMuxPost(const LosMux *muxCB)
{
LOS_TRACE(MUX_POST, (UINTPTR)muxCB, muxCB->muxCount,
(muxCB->owner == NULL) ? 0xffffffff : ((LosTaskCB *)muxCB->owner)->taskID);
}
STATIC VOID LOS_TraceMuxPend(const LosMux *muxCB, UINT32 timeout)
{
LOS_TRACE(MUX_PEND, (UINTPTR)muxCB, muxCB->muxCount,
(muxCB->owner == NULL) ? 0xffffffff : ((LosTaskCB *)muxCB->owner)->taskID, timeout);
}
STATIC VOID LOS_TraceMuxDelete(const LosMux *muxCB)
{
LOS_TRACE(MUX_DELETE, (UINTPTR)muxCB, muxCB->attr.type, muxCB->muxCount,
(muxCB->owner == NULL) ? 0xffffffff : ((LosTaskCB *)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(const LosTaskCB *newTask, const LosTaskCB *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,OsCurrTaskGet()->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);
}
STATIC VOID LOS_TraceIpcWriteDrop(const IpcMsg *msg, UINT32 dstTid, UINT32 dstPid, UINT32 ipcStatus)
{
LOS_TRACE(IPC_WRITE_DROP, dstTid, dstPid, msg->type, msg->code, ipcStatus);
}
STATIC VOID LOS_TraceIpcWrite(const IpcMsg *msg, UINT32 dstTid, UINT32 dstPid, UINT32 ipcStatus)
{
LOS_TRACE(IPC_WRITE, dstTid, dstPid, msg->type, msg->code, ipcStatus);
}
STATIC VOID LOS_TraceIpcReadDrop(const IpcMsg *msg, UINT32 ipcStatus)
{
LOS_TRACE(IPC_READ_DROP, msg->taskID, msg->processID, msg->type, msg->code, ipcStatus);
}
STATIC VOID LOS_TraceIpcRead(const IpcMsg *msg, UINT32 ipcStatus)
{
LOS_TRACE(IPC_READ_DROP, msg->taskID, msg->processID, msg->type, msg->code, ipcStatus);
}
STATIC VOID LOS_TraceIpcTryRead(UINT32 msgType, UINT32 ipcStatus)
{
LOS_TRACE(IPC_TRY_READ, msgType, ipcStatus);
}
STATIC VOID LOS_TraceIpcReadTimeout(UINT32 msgType, UINT32 ipcStatus)
{
LOS_TRACE(IPC_READ_TIMEOUT, msgType, ipcStatus);
}
STATIC VOID LOS_TraceIpcKill(UINT32 msgType, UINT32 ipcStatus)
{
LOS_TRACE(IPC_KILL, msgType, ipcStatus);
}
STATIC VOID LOS_TraceUsrEvent(VOID *buffer, UINT32 len)
{
#ifdef LOSCFG_DRIVERS_TRACE
UsrEventInfo *info = (UsrEventInfo *)buffer;
if ((info == NULL) || (len != sizeof(UsrEventInfo))) {
return;
}
LOS_TRACE_EASY(info->eventType & (~TRACE_USER_DEFAULT_FLAG), info->identity, info->params[0], info->params[1],
info->params[2]);
LOS_MemFree(m_aucSysMem0, buffer);
#endif
}
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);
LOS_HookReg(LOS_HOOK_TYPE_USR_EVENT, LOS_TraceUsrEvent);
LOS_HookReg(LOS_HOOK_TYPE_IPC_WRITE_DROP, LOS_TraceIpcWriteDrop);
LOS_HookReg(LOS_HOOK_TYPE_IPC_WRITE, LOS_TraceIpcWrite);
LOS_HookReg(LOS_HOOK_TYPE_IPC_READ_DROP, LOS_TraceIpcReadDrop);
LOS_HookReg(LOS_HOOK_TYPE_IPC_READ, LOS_TraceIpcRead);
LOS_HookReg(LOS_HOOK_TYPE_IPC_TRY_READ, LOS_TraceIpcTryRead);
LOS_HookReg(LOS_HOOK_TYPE_IPC_READ_TIMEOUT, LOS_TraceIpcReadTimeout);
LOS_HookReg(LOS_HOOK_TYPE_IPC_KILL, LOS_TraceIpcKill);
}

View File

@@ -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.
*/
#ifndef _TRACE_CNV_H
#define _TRACE_CNV_H
#include "los_typedef.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 */

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved.
* 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,
@@ -30,485 +30,394 @@
*/
#include "los_trace_pri.h"
#include "ctype.h"
#include "trace_pipeline.h"
#include "los_memory.h"
#include "los_config.h"
#include "securec.h"
#include "trace_cnv.h"
#include "los_init.h"
#include "los_task_pri.h"
#include "los_typedef.h"
#include "los_process.h"
#ifdef LOSCFG_KERNEL_SMP
#include "los_mp.h"
#endif
#ifdef LOSCFG_SHELL
#include "shcmd.h"
#include "shell.h"
#include "stdlib.h"
#include "unistd.h"
#endif
#ifndef LOSCFG_KERNEL_TRACE
UINT32 OsTraceInit(VOID)
{
return LOS_OK;
}
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;
UINT32 LOS_TraceReg(TraceType traceType, WriteHook inHook, const CHAR *typeStr, TraceSwitch onOff)
{
(VOID)traceType;
(VOID)inHook;
(VOID)onOff;
(VOID)typeStr;
return LOS_OK;
}
TRACE_EVENT_HOOK g_traceEventHook = NULL;
TRACE_DUMP_HOOK g_traceDumpHook = NULL;
UINT32 LOS_TraceUnreg(TraceType traceType)
{
(VOID)traceType;
return LOS_OK;
}
VOID LOS_Trace(TraceType traceType, ...)
{
(VOID)traceType;
return;
}
VOID LOS_TraceSwitch(TraceSwitch onOff)
{
(VOID)onOff;
}
UINT32 LOS_TraceTypeSwitch(TraceType traceType, TraceSwitch onOff)
{
(VOID)traceType;
(VOID)onOff;
return LOS_OK;
}
VOID LOS_TracePrint(VOID)
{
return;
}
INT32 LOS_Trace2File(const CHAR *filename)
{
(VOID)filename;
return 0;
}
UINT8 *LOS_TraceBufDataGet(UINT32 *desLen, UINT32 *relLen)
{
(VOID)desLen;
(VOID)relLen;
return NULL;
}
#else
SPIN_LOCK_INIT(g_traceSpin);
#define TRACE_LOCK(state) LOS_SpinLockSave(&g_traceSpin, &(state))
#define TRACE_UNLOCK(state) LOS_SpinUnlockRestore(&g_traceSpin, (state))
#define TMP_DATALEN 128
STATIC UINT8 traceBufArray[LOS_TRACE_BUFFER_SIZE];
STATIC TraceBufferCtl traceBufCtl;
STATIC TraceHook traceFunc[LOS_TRACE_TYPE_MAX + 1];
UINT32 OsTraceInit(VOID)
{
UINT32 intSave;
/* Initialize the global variable. */
(VOID)memset_s((VOID *)traceBufArray, LOS_TRACE_BUFFER_SIZE, 0, LOS_TRACE_BUFFER_SIZE);
(VOID)memset_s(&traceBufCtl, sizeof(traceBufCtl), 0, sizeof(traceBufCtl));
(VOID)memset_s((VOID *)traceFunc, sizeof(traceFunc), 0, sizeof(traceFunc));
TRACE_LOCK(intSave);
/* Initialize trace contrl. */
traceBufCtl.bufLen = LOS_TRACE_BUFFER_SIZE;
traceBufCtl.dataBuf = traceBufArray;
traceBufCtl.onOff = LOS_TRACE_ENABLE;
TRACE_UNLOCK(intSave);
return LOS_OK;
}
UINT32 LOS_TraceReg(TraceType traceType, WriteHook inHook, const CHAR *typeStr, TraceSwitch onOff)
{
UINT32 intSave;
INT32 i;
if ((traceType < LOS_TRACE_TYPE_MIN) || (traceType > LOS_TRACE_TYPE_MAX)) {
return LOS_ERRNO_TRACE_TYPE_INVALID;
}
if (inHook == NULL) {
return LOS_ERRNO_TRACE_FUNCTION_NULL;
}
TRACE_LOCK(intSave);
/* if inputHook is NULLreturn failed. */
if (traceFunc[traceType].inputHook != NULL) {
PRINT_ERR("Registered Failed!\n");
for (i = 0; i <= LOS_TRACE_TYPE_MAX; i++) {
if (traceFunc[i].inputHook == NULL) {
PRINTK("type:%d ", i);
}
}
PRINTK("could be registered\n");
TRACE_UNLOCK(intSave);
return LOS_ERRNO_TRACE_TYPE_EXISTED;
} else {
traceFunc[traceType].inputHook = inHook;
traceFunc[traceType].onOff = onOff;
traceFunc[traceType].typeStr = typeStr;
}
TRACE_UNLOCK(intSave);
return LOS_OK;
}
UINT32 LOS_TraceUnreg(TraceType traceType)
{
UINT32 intSave;
if ((traceType < LOS_TRACE_TYPE_MIN) || (traceType > LOS_TRACE_TYPE_MAX)) {
return LOS_ERRNO_TRACE_TYPE_INVALID;
}
TRACE_LOCK(intSave);
/* if inputHook is NULLreturn failed. */
if (traceFunc[traceType].inputHook == NULL) {
PRINT_ERR("Trace not exist!\n");
TRACE_UNLOCK(intSave);
return LOS_ERRNO_TRACE_TYPE_NOT_EXISTED;
} else {
traceFunc[traceType].inputHook = NULL;
traceFunc[traceType].onOff = LOS_TRACE_DISABLE;
traceFunc[traceType].typeStr = NULL;
}
TRACE_UNLOCK(intSave);
return LOS_OK;
}
VOID LOS_TraceSwitch(TraceSwitch onOff)
{
traceBufCtl.onOff = onOff;
}
UINT32 LOS_TraceTypeSwitch(TraceType traceType, TraceSwitch onOff)
{
UINT32 intSave;
if (traceType < LOS_TRACE_TYPE_MIN || traceType > LOS_TRACE_TYPE_MAX) {
return LOS_ERRNO_TRACE_TYPE_INVALID;
}
TRACE_LOCK(intSave);
if (traceFunc[traceType].inputHook != NULL) {
traceFunc[traceType].onOff = onOff;
TRACE_UNLOCK(intSave);
return LOS_OK;
}
TRACE_UNLOCK(intSave);
return LOS_ERRNO_TRACE_TYPE_NOT_EXISTED;
}
STATIC UINT32 OsFindReadFrameHead(UINT32 readIndex, UINT32 dataSize)
{
UINT32 historySize = 0;
UINT32 index = readIndex;
while (historySize < dataSize) {
historySize += ((FrameHead *)&(traceBufCtl.dataBuf[index]))->frameSize;
index = readIndex + historySize;
if (index >= traceBufCtl.bufLen) {
index = index - traceBufCtl.bufLen;
}
}
return index;
}
STATIC VOID OsAddData2Buf(UINT8 *buf, UINT32 dataSize)
{
UINT32 intSave;
UINT32 ret;
TRACE_LOCK(intSave);
UINT32 desLen = traceBufCtl.bufLen;
UINT32 writeIndex = traceBufCtl.writeIndex;
UINT32 readIndex = traceBufCtl.readIndex;
UINT32 writeRange = writeIndex + dataSize;
UINT8 *des = traceBufCtl.dataBuf + writeIndex;
/* update readIndex */
if ((readIndex > writeIndex) && (writeRange > readIndex)) {
traceBufCtl.readIndex = OsFindReadFrameHead(readIndex, writeRange - readIndex);
} else if ((readIndex <= writeIndex) && (writeRange > desLen + readIndex)) {
traceBufCtl.readIndex = OsFindReadFrameHead(readIndex, writeRange - readIndex - desLen);
}
/* copy the data and update writeIndex */
UINT32 tmpLen = desLen - writeIndex;
if (tmpLen >= dataSize) {
ret = (UINT32)memcpy_s(des, tmpLen, buf, dataSize);
if (ret != 0) {
goto EXIT;
}
traceBufCtl.writeIndex = writeIndex + dataSize;
} else {
ret = (UINT32)memcpy_s(des, tmpLen, buf, tmpLen); /* tmpLen: The length of ringbuf that can be written */
if (ret != 0) {
goto EXIT;
}
ret = (UINT32)memcpy_s(traceBufCtl.dataBuf, desLen, buf + tmpLen, dataSize - tmpLen);
if (ret != 0) {
goto EXIT;
}
traceBufCtl.writeIndex = dataSize - tmpLen;
}
EXIT:
TRACE_UNLOCK(intSave);
}
VOID LOS_Trace(TraceType traceType, ...)
{
va_list ap;
if ((traceType > LOS_TRACE_TYPE_MAX) || (traceType < LOS_TRACE_TYPE_MIN) ||
(traceFunc[traceType].inputHook == NULL)) {
return;
}
if ((traceBufCtl.onOff == LOS_TRACE_DISABLE) || (traceFunc[traceType].onOff == LOS_TRACE_DISABLE)) {
return;
}
/* Set the trace frame head */
UINT8 buf[TMP_DATALEN];
FrameHead *frameHead = (FrameHead *)buf;
frameHead->type = traceType;
frameHead->cpuID = ArchCurrCpuid();
frameHead->taskID = LOS_CurTaskIDGet();
frameHead->timestamp = HalClockGetCycles();
#ifdef LOSCFG_TRACE_LR
/* Get the linkreg from stack fp and storage to frameHead */
LOS_RecordLR(frameHead->linkReg, LOSCFG_TRACE_LR_RECORD, LOSCFG_TRACE_LR_RECORD, LOSCFG_TRACE_LR_IGNOR);
#ifdef LOSCFG_TRACE_CONTROL_AGENT
LITE_OS_SEC_BSS STATIC UINT32 g_traceTaskId;
#endif
/* Get the trace message */
va_start(ap, traceType);
INT32 dataSize = (traceFunc[traceType].inputHook)(buf + sizeof(FrameHead), TMP_DATALEN - sizeof(FrameHead), ap);
va_end(ap);
if (dataSize <= 0) {
return;
}
frameHead->frameSize = sizeof(FrameHead) + dataSize;
OsAddData2Buf(buf, frameHead->frameSize);
}
#define EVENT_MASK 0xFFFFFFF0
#define MIN(x, y) ((x) < (y) ? (x) : (y))
UINT8 *LOS_TraceBufDataGet(UINT32 *desLen, UINT32 *relLen)
LITE_OS_SEC_BSS STATIC TRACE_HWI_FILTER_HOOK g_traceHwiFliterHook = NULL;
#ifdef LOSCFG_KERNEL_SMP
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_traceSpin);
#endif
STATIC_INLINE BOOL OsTraceHwiFilter(UINT32 hwiNum)
{
UINT32 traceSwitch = traceBufCtl.onOff;
if (desLen == NULL || relLen == NULL) {
return NULL;
}
if (traceSwitch != LOS_TRACE_DISABLE) {
LOS_TraceSwitch(LOS_TRACE_DISABLE);
}
UINT32 writeIndex = traceBufCtl.writeIndex;
UINT32 readIndex = traceBufCtl.readIndex;
UINT32 srcLen = traceBufCtl.bufLen;
UINT8 *des = (UINT8 *)malloc(srcLen * sizeof(UINT8));
if (des == NULL) {
*desLen = 0;
*relLen = 0;
if (traceSwitch != LOS_TRACE_DISABLE) {
LOS_TraceSwitch(LOS_TRACE_DISABLE);
}
return NULL;
}
*desLen = LOS_TRACE_BUFFER_SIZE;
if (EOK != memset_s(des, srcLen * sizeof(UINT8), 0, LOS_TRACE_BUFFER_SIZE)) {
*desLen = 0;
*relLen = 0;
free(des);
return NULL;
}
if (writeIndex > readIndex) {
*relLen = readIndex - writeIndex;
(VOID)memcpy_s(des, *desLen, &(traceBufArray[readIndex]), *relLen);
} else {
UINT32 sumLen = srcLen - readIndex;
(VOID)memcpy_s(des, *desLen, &(traceBufArray[readIndex]), sumLen);
(VOID)memcpy_s(&(des[sumLen]), *desLen - sumLen, traceBufArray, writeIndex);
*relLen = sumLen + writeIndex;
}
if (traceSwitch != LOS_TRACE_DISABLE) {
LOS_TraceSwitch(LOS_TRACE_ENABLE);
}
return des;
}
#ifdef LOSCFG_FS_VFS
INT32 LOS_Trace2File(const CHAR *filename)
{
INT32 ret;
CHAR *fullpath = NULL;
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
UINT32 traceSwitch = traceBufCtl.onOff;
ret = vfs_normalize_path(shellWorkingDirectory, filename, &fullpath);
if (ret != 0) {
return -1;
}
if (traceSwitch != LOS_TRACE_DISABLE) {
LOS_TraceSwitch(LOS_TRACE_DISABLE);
}
INT32 fd = open(fullpath, O_CREAT | O_RDWR | O_APPEND, 0644); /* 0644:file right */
if (fd < 0) {
return -1;
}
UINT32 writeIndex = traceBufCtl.writeIndex;
UINT32 readIndex = traceBufCtl.readIndex;
if (writeIndex > readIndex) {
ret = write(fd, &(traceBufArray[readIndex]), writeIndex - readIndex);
} else {
ret = write(fd, &(traceBufArray[readIndex]), traceBufCtl.bufLen - readIndex);
ret += write(fd, traceBufArray, writeIndex);
}
(VOID)close(fd);
free(fullpath);
if (traceSwitch != LOS_TRACE_DISABLE) {
LOS_TraceSwitch(LOS_TRACE_ENABLE);
BOOL ret = ((hwiNum == NUM_HAL_INTERRUPT_UART) || (hwiNum == OS_TICK_INT_NUM));
#ifdef LOSCFG_KERNEL_SMP
ret |= (hwiNum == LOS_MP_IPI_SCHEDULE);
#endif
if (g_traceHwiFliterHook != NULL) {
ret |= g_traceHwiFliterHook(hwiNum);
}
return ret;
}
STATIC VOID OsTraceSetFrame(TraceEventFrame *frame, UINT32 eventType, UINTPTR identity, const UINTPTR *params,
UINT16 paramCount)
{
INT32 i;
UINT32 intSave;
(VOID)memset_s(frame, sizeof(TraceEventFrame), 0, sizeof(TraceEventFrame));
if (paramCount > LOSCFG_TRACE_FRAME_MAX_PARAMS) {
paramCount = LOSCFG_TRACE_FRAME_MAX_PARAMS;
}
TRACE_LOCK(intSave);
frame->curTask = OsTraceGetMaskTid(LOS_CurTaskIDGet());
frame->curPid = LOS_GetCurrProcessID();
frame->identity = identity;
frame->curTime = HalClockGetCycles();
frame->eventType = eventType;
#ifdef LOSCFG_TRACE_FRAME_CORE_MSG
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
#ifdef LOS_TRACE_FRAME_LR
/* Get the linkreg from stack fp and storage to frame */
LOS_RecordLR(frame->linkReg, LOS_TRACE_LR_RECORD, LOS_TRACE_LR_RECORD, LOS_TRACE_LR_IGNOR);
#endif
#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT
frame->eventCount = g_traceEventCount;
g_traceEventCount++;
#endif
TRACE_UNLOCK(intSave);
for (i = 0; i < paramCount; i++) {
frame->params[i] = params[i];
}
}
VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb)
{
errno_t ret;
(VOID)memset_s(obj, sizeof(ObjData), 0, sizeof(ObjData));
obj->id = OsTraceGetMaskTid(tcb->taskID);
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)
{
TraceEventFrame frame;
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;
}
OsTraceSetFrame(&frame, eventType, id, params, paramCount);
OsTraceWriteOrSendEvent(&frame);
}
}
BOOL OsTraceIsEnable(VOID)
{
return g_enableTrace;
}
STATIC VOID OsTraceHookInstall(VOID)
{
g_traceEventHook = OsTraceHook;
#ifdef LOSCFG_RECORDER_MODE_OFFLINE
g_traceDumpHook = OsTraceRecordDump;
#endif
}
#ifdef LOSCFG_TRACE_CONTROL_AGENT
STATIC BOOL OsTraceCmdIsValid(const TraceClientCmd *msg)
{
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;
#ifdef LOSCFG_KERNEL_SMP
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
ret = LOS_TaskCreate(&g_traceTaskId, &taskInitParam);
return ret;
}
#endif
STATIC UINT32 OsTraceInit(VOID)
{
UINT32 ret;
if (g_traceState != TRACE_UNINIT) {
TRACE_ERROR("trace has been initialized already, the current state is :%d\n", g_traceState);
ret = LOS_ERRNO_TRACE_ERROR_STATUS;
goto LOS_ERREND;
}
#ifdef LOSCFG_TRACE_CLIENT_INTERACT
ret = OsTracePipelineInit();
if (ret != LOS_OK) {
goto LOS_ERREND;
}
#endif
#ifdef LOSCFG_TRACE_CONTROL_AGENT
ret = OsCreateTraceAgentTask();
if (ret != LOS_OK) {
TRACE_ERROR("trace init create agentTask error :0x%x\n", ret);
goto LOS_ERREND;
}
#endif
ret = OsTraceBufInit(LOSCFG_TRACE_BUFFER_SIZE);
if (ret != LOS_OK) {
goto LOS_RELEASE;
}
OsTraceHookInstall();
OsTraceCnvInit();
g_traceEventCount = 0;
#ifdef LOSCFG_RECORDER_MODE_ONLINE /* Wait trace client to start trace */
g_enableTrace = FALSE;
g_traceState = TRACE_INITED;
#else
g_enableTrace = TRUE;
g_traceState = TRACE_STARTED;
#endif
return LOS_OK;
LOS_RELEASE:
#ifdef LOSCFG_TRACE_CONTROL_AGENT
LOS_TaskDelete(g_traceTaskId);
#endif
LOS_ERREND:
return ret;
}
UINT32 LOS_TraceStart(VOID)
{
UINT32 intSave;
UINT32 ret = LOS_OK;
TRACE_LOCK(intSave);
if (g_traceState == TRACE_STARTED) {
goto START_END;
}
if (g_traceState == TRACE_UNINIT) {
TRACE_ERROR("trace not inited, be sure LOS_TraceInit excute success\n");
ret = LOS_ERRNO_TRACE_ERROR_STATUS;
goto START_END;
}
OsTraceNotifyStart();
g_enableTrace = TRUE;
g_traceState = TRACE_STARTED;
TRACE_UNLOCK(intSave);
LOS_TRACE(MEM_INFO_REQ, m_aucSysMem0);
return ret;
START_END:
TRACE_UNLOCK(intSave);
return ret;
}
VOID LOS_TraceStop(VOID)
{
UINT32 intSave;
TRACE_LOCK(intSave);
if (g_traceState != TRACE_STARTED) {
goto STOP_END;
}
g_enableTrace = FALSE;
g_traceState = TRACE_STOPED;
OsTraceNotifyStop();
STOP_END:
TRACE_UNLOCK(intSave);
}
VOID LOS_TraceEventMaskSet(UINT32 mask)
{
g_traceMask = mask & EVENT_MASK;
}
VOID LOS_TraceRecordDump(BOOL toClient)
{
if (g_traceState != TRACE_STOPED) {
TRACE_ERROR("trace dump must after trace stopped , the current state is : %d\n", g_traceState);
return;
}
OsTraceRecordDump(toClient);
}
OfflineHead *LOS_TraceRecordGet(VOID)
{
return OsTraceRecordGet();
}
VOID LOS_TraceReset(VOID)
{
if (g_traceState == TRACE_UNINIT) {
TRACE_ERROR("trace not inited, be sure LOS_TraceInit excute success\n");
return;
}
OsTraceReset();
}
VOID LOS_TraceHwiFilterHookReg(TRACE_HWI_FILTER_HOOK hook)
{
UINT32 intSave;
TRACE_LOCK(intSave);
g_traceHwiFliterHook = hook;
TRACE_UNLOCK(intSave);
}
#ifdef LOSCFG_SHELL
UINT32 OsShellCmdTraceNumSwitch(TraceType traceType, const CHAR *onOff)
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTraceSetMask(INT32 argc, const CHAR **argv)
{
UINT32 ret = LOS_NOK;
size_t mask;
CHAR *endPtr = NULL;
if (strcmp("on", onOff) == 0) {
ret = LOS_TraceTypeSwitch(traceType, LOS_TRACE_ENABLE);
if (ret == LOS_OK) {
PRINTK("trace %s on\n", traceFunc[traceType].typeStr);
} else {
PRINTK("trace %d is unregistered\n", traceType);
}
} else if (strcmp("off", onOff) == 0) {
ret = LOS_TraceTypeSwitch(traceType, LOS_TRACE_DISABLE);
if (ret == LOS_OK) {
PRINTK("trace %s off\n", traceFunc[traceType].typeStr);
} else {
PRINTK("trace %d is unregistered\n", traceType);
}
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 {
PRINTK("Unknown option: %s\n", onOff);
}
return ret;
}
UINT32 OsShellCmdTraceStrSwitch(const CHAR *typeStr, const CHAR *onOff)
{
UINT32 ret = LOS_NOK;
UINT32 i;
for (i = 0; i <= LOS_TRACE_TYPE_MAX; i++) {
if (traceFunc[i].typeStr != NULL && !strcmp(typeStr, traceFunc[i].typeStr)) {
ret = OsShellCmdTraceNumSwitch(i, onOff);
if (ret != LOS_OK) {
PRINTK("Unknown option: %s\n", onOff);
}
return ret;
}
}
PRINTK("Unknown option: %s\n", typeStr);
return ret;
}
UINT32 OsShellCmdTraceSwitch(INT32 argc, const CHAR **argv)
{
UINT32 ret;
if (argc == 1) {
if (strcmp("on", argv[0]) == 0) {
LOS_TraceSwitch(LOS_TRACE_ENABLE);
PRINTK("trace on\n");
} else if (strcmp("off", argv[0]) == 0) {
LOS_TraceSwitch(LOS_TRACE_DISABLE);
PRINTK("trace off\n");
} else {
PRINTK("Unknown option: %s\n", argv[0]);
goto TRACE_HELP;
}
} else if (argc == 2) { /* 2:argc number limited */
if (isdigit(argv[0][0]) != 0) {
CHAR *endPtr = NULL;
UINT32 traceType = strtoul(argv[0], &endPtr, 0);
if ((endPtr == NULL) || (*endPtr != 0)) {
PRINTK("Unknown option: %s\n", argv[0]);
goto TRACE_HELP;
}
ret = OsShellCmdTraceNumSwitch(traceType, argv[1]);
if (ret != LOS_OK) {
goto TRACE_HELP;
}
} else {
ret = OsShellCmdTraceStrSwitch(argv[0], argv[1]);
if (ret != LOS_OK) {
goto TRACE_HELP;
}
}
} else {
PRINTK("Argc is Incorrect!\n");
goto TRACE_HELP;
mask = strtoul(argv[0], &endPtr, 0);
}
LOS_TraceEventMaskSet((UINT32)mask);
return LOS_OK;
TRACE_HELP:
PRINTK("Usage:trace [typeNum/typeName] on/off\n");
PRINTK(" typeNum range: [%d,%d]\n", LOS_TRACE_TYPE_MIN, LOS_TRACE_TYPE_MAX);
return LOS_NOK;
}
#ifdef LOSCFG_FS_VFS
UINT32 OsShellCmdTrace2File(INT32 argc, const CHAR **argv)
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTraceDump(INT32 argc, const CHAR **argv)
{
INT32 ret;
if (argc == 1) {
ret = LOS_Trace2File(argv[0]);
if (ret == -1) {
PRINTK("Trace to file failed: %s\n", argv[0]);
} else {
PRINTK("Trace to file successed: %s\n", argv[0]);
}
} else {
PRINTK("Trace to file:wrong argc\n");
goto TRACE_HELP;
}
return LOS_OK;
BOOL toClient;
CHAR *endPtr = NULL;
TRACE_HELP:
PRINTK("usage:trace2file filename\n");
return LOS_NOK;
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(trace2file_shellcmd, CMD_TYPE_EX, "trace2file", 1, (CmdCallBackFunc)OsShellCmdTrace2File);
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
SHELLCMD_ENTRY(trace_shellcmd, CMD_TYPE_EX, "trace", 1, (CmdCallBackFunc)OsShellCmdTraceSwitch);
#endif
#endif
LOS_MODULE_INIT(OsTraceInit, LOS_INIT_LEVEL_EARLIEST);
LOS_MODULE_INIT(OsTraceInit, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -1,122 +0,0 @@
/*
* 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_frame.h"
#ifdef LOSCFG_KERNEL_TRACE
INT32 OsTaskTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
TaskTraceFrame *x = (TaskTraceFrame *)inputBuffer;
if (sizeof(TaskTraceFrame) > bufLen) {
va_end(ap2);
return 0;
}
SETPARAM(ap2, x, taskEntry, UINTPTR);
SETPARAM(ap2, x, status, UINT16);
SETPARAM(ap2, x, mask, UINT16);
SETPARAM(ap2, x, ipcId, UINTPTR);
va_end(ap2);
return sizeof(TaskTraceFrame);
}
INT32 OsIpcTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
IpcTraceFrame *x = (IpcTraceFrame *)inputBuffer;
if (sizeof(IpcTraceFrame) > bufLen) {
va_end(ap2);
return 0;
}
SETPARAM(ap2, x, srcTid, UINT32);
SETPARAM(ap2, x, srcPid, UINT32);
SETPARAM(ap2, x, dstTid, UINT32);
SETPARAM(ap2, x, dstPid, UINT32);
SETPARAM(ap2, x, msgType, UINT8);
SETPARAM(ap2, x, code, UINT8);
SETPARAM(ap2, x, operation, UINT8);
SETPARAM(ap2, x, ipcStatus, UINT8);
va_end(ap2);
return sizeof(IpcTraceFrame);
}
INT32 OsMemTimeTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
MemTimeTraceFrame *x = (MemTimeTraceFrame *)inputBuffer;
if (sizeof(MemTimeTraceFrame) > bufLen) {
va_end(ap2);
return 0;
}
SETPARAM(ap2, x, poolAddr, UINT16);
SETPARAM(ap2, x, type, UINT16);
SETPARAM(ap2, x, timeUsed, UINT32);
va_end(ap2);
return sizeof(MemTimeTraceFrame);
}
INT32 OsMemInfoTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
MemInfoTraceFrame *x = (MemInfoTraceFrame *)inputBuffer;
if (sizeof(MemInfoTraceFrame) > bufLen) {
va_end(ap2);
return 0;
}
SETPARAM(ap2, x, poolAddr, UINT16);
SETPARAM(ap2, x, fragment, UINT8);
SETPARAM(ap2, x, usage, UINT8);
SETPARAM(ap2, x, freeTotalSize, UINT32);
SETPARAM(ap2, x, maxFreeSize, UINT32);
SETPARAM(ap2, x, usedNodeNum, UINT16);
SETPARAM(ap2, x, freeNodeNum, UINT16);
va_end(ap2);
return sizeof(MemInfoTraceFrame);
}
#endif

View File

@@ -1,120 +0,0 @@
/*
* 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_FRAME_H
#define _LOS_TRACE_FRAME_H
#include "los_typedef.h"
#include "stdarg.h"
#define LOSCFG_TRACE_LR
#define LOSCFG_TRACE_LR_RECORD 5
#define LOSCFG_TRACE_LR_IGNOR 0
#pragma pack (4)
typedef struct {
UINT16 frameSize;
UINT8 type;
UINT8 cpuID;
INT32 taskID;
UINT64 timestamp;
#ifdef LOSCFG_TRACE_LR
UINTPTR linkReg[LOSCFG_TRACE_LR_RECORD];
#endif
}FrameHead;
#pragma pack ()
#define SETPARAM(ap, st, member, type) ((st)->member = (type)va_arg((ap), unsigned int))
#define SETPARAM_LL(ap, st, member, type) ((st)->member = (type)va_arg((ap), unsigned long long))
#define LOS_TRACE_TASK 0
#define LOS_TRACE_TASK_NAME "task"
#define LOS_TRACE_IPC 1
#define LOS_TRACE_IPC_NAME "liteipc"
#define LOS_TRACE_MEM_TIME 2
#define LOS_TRACE_MEM_TIME_NAME "mem_time"
#define LOS_TRACE_MEM_INFO 3
#define LOS_TRACE_MEM_INFO_NAME "mem_info"
/* task trace frame */
typedef struct {
UINTPTR taskEntry;
UINT16 status; /**< Task status:
OS_TASK_STATUS_READY
OS_TASK_STATUS_RUNNING
OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME */
UINT16 mask; /**< Task status Subdivision */
UINTPTR ipcId;
} TaskTraceFrame;
/* liteipc trace frame */
typedef struct {
UINT32 srcTid;
UINT32 srcPid;
UINT32 dstTid;
UINT32 dstPid;
UINT8 msgType;
UINT8 code;
UINT8 operation;
UINT8 ipcStatus;
} IpcTraceFrame;
#define MEM_POOL_ADDR_MASK 0xffff
#define MEM_TRACE_MALLOC 0
#define MEM_TRACE_FREE 1
#define MEM_TRACE_MEMALIGN 2
#define MEM_TRACE_REALLOC 3
#define MEM_TRACE_CYCLE_TO_US(cycles) (UINT32)((UINT64)(cycles) * 1000000 / OS_SYS_CLOCK) /* 1000000: unit is us */
/* mem time use trace frame */
typedef struct {
UINT32 poolAddr : 16; /* Record the low 16 bits of the memory pool address for distinction. */
UINT32 type : 16; /* 0malloc, 1: free, 2: memalign, 3: realloc. */
UINT32 timeUsed; /* Time-consuming for each type of interface about type, uint: us. */
} MemTimeTraceFrame;
/* mem pool info trace frame */
typedef struct {
UINT32 poolAddr : 16; /* Record the low 16 bits of the memory pool address for distinction. */
UINT32 fragment : 8; /* 100: percent denominator. */
UINT32 usage : 8; /* Memory pool usage. */
UINT32 freeTotalSize; /* Total remaining memory. */
UINT32 maxFreeSize; /* Maximum memory block size. */
UINT32 usedNodeNum : 16; /* Number of used memory blocks. */
UINT32 freeNodeNum : 16; /* Number of unused memory blocks. */
} MemInfoTraceFrame;
extern INT32 OsTaskTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
extern INT32 OsIpcTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
extern INT32 OsMemTimeTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
extern INT32 OsMemInfoTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap);
#endif

View File

@@ -29,12 +29,11 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LOS_TRACE_PRI_H
#define LOS_TRACE_PRI_H
#ifndef _LOS_TRACE_PRI_H
#define _LOS_TRACE_PRI_H
#include "los_trace.h"
#include "los_spinlock.h"
#include "los_seq_buf.h"
#include "los_task_pri.h"
#ifdef __cplusplus
#if __cplusplus
@@ -42,25 +41,113 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct {
TraceSwitch onOff;
WriteHook inputHook;
const CHAR *typeStr;
} TraceHook;
#ifdef LOSCFG_TRACE_CONTROL_AGENT
#define TRACE_CMD_END_CHAR 0xD
#endif
/*
* |1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0|
* | |
* readIndex writeIndex
#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)
#ifdef LOSCFG_KERNEL_SMP
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 *dataBuf;
UINT32 bufLen;
TraceSwitch onOff;
UINT32 writeIndex;
UINT32 readIndex;
} TraceBufferCtl;
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(UINT32 size);
extern VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId);
extern BOOL OsTraceIsEnable(VOID);
extern OfflineHead *OsTraceRecordGet(VOID);
#ifdef LOSCFG_RECORDER_MODE_ONLINE
extern VOID OsTraceSendHead(VOID);
extern VOID OsTraceSendObjTable(VOID);
extern VOID OsTraceSendNotify(UINT32 type, UINT32 value);
#define OsTraceNotifyStart() do { \
OsTraceSendNotify(SYS_START, TRACE_CTL_MAGIC_NUM); \
OsTraceSendHead(); \
OsTraceSendObjTable(); \
} while (0)
#define OsTraceNotifyStop() do { \
OsTraceSendNotify(SYS_STOP, TRACE_CTL_MAGIC_NUM); \
} while (0)
#define OsTraceReset()
#define OsTraceRecordDump(toClient)
#else
extern VOID OsTraceReset(VOID);
extern VOID OsTraceRecordDump(BOOL toClient);
#define OsTraceNotifyStart()
#define OsTraceNotifyStop()
#endif
#ifdef __cplusplus
#if __cplusplus
@@ -68,4 +155,4 @@ typedef struct {
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* LOS_TRACE_PRI_H */
#endif /* _LOS_TRACE_PRI_H */

View File

@@ -0,0 +1,86 @@
/*
* 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 LOSCFG_TRACE_CONTROL_AGENT
UINT32 SerialPipelineInit(VOID)
{
return uart_hwiCreate();
}
UINT32 SerialDataReceive(UINT8 *data, UINT32 size, UINT32 timeout)
{
return uart_read(data, size, timeout);
}
UINT32 SerialWait(VOID)
{
return uart_wait_adapt();
}
#else
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)
{
UartPuts((CHAR *)data, len, 1);
}
STATIC const TracePipelineOps g_serialOps = {
.init = SerialPipelineInit,
.dataSend = SerialDataSend,
.dataRecv = SerialDataReceive,
.wait = SerialWait,
};
UINT32 OsTracePipelineInit(VOID)
{
OsTracePipelineReg(&g_serialOps);
return g_serialOps.init();
}

View File

@@ -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.
*/
#ifndef _TRACE_PIPELINE_SERIAL_H
#define _TRACE_PIPELINE_SERIAL_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
extern VOID UartPuts(const CHAR *s, UINT32 len, BOOL isLock);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TRACE_PIPELINE_SERIAL_H */

View File

@@ -0,0 +1,154 @@
/*
* 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 LOSCFG_KERNEL_SMP
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[] = {
#ifdef LOSCFG_TRACE_FRAME_CORE_MSG
{ CORE, LOS_OFF_SET_OF(TraceEventFrame, core), sizeof(UINT32) },
#endif
{ EVENT_CODE, LOS_OFF_SET_OF(TraceEventFrame, eventType), sizeof(UINT32) },
{ CUR_TIME, LOS_OFF_SET_OF(TraceEventFrame, curTime), sizeof(UINT64) },
#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT
{ EVENT_COUNT, LOS_OFF_SET_OF(TraceEventFrame, eventCount), sizeof(UINT32) },
#endif
{ CUR_TASK, LOS_OFF_SET_OF(TraceEventFrame, curTask), sizeof(UINT32) },
{ IDENTITY, LOS_OFF_SET_OF(TraceEventFrame, identity), sizeof(UINTPTR) },
{ EVENT_PARAMS, LOS_OFF_SET_OF(TraceEventFrame, params), sizeof(UINTPTR) * LOSCFG_TRACE_FRAME_MAX_PARAMS },
{ CUR_PID, LOS_OFF_SET_OF(TraceEventFrame, curPid), sizeof(UINT32) },
#ifdef LOS_TRACE_FRAME_LR
{ EVENT_LR, LOS_OFF_SET_OF(TraceEventFrame, linkReg), sizeof(UINTPTR) * LOS_TRACE_LR_RECORD },
#endif
{ 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();
}

View File

@@ -0,0 +1,106 @@
/*
* 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_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct {
UINT32 (*init)(VOID);
VOID (*dataSend)(UINT16 len, UINT8 *data);
UINT32 (*dataRecv)(UINT8 *data, UINT32 size, UINT32 timeout);
UINT32 (*wait)(VOID);
} TracePipelineOps;
/* used as tlv's tag */
enum TraceMsgType {
NOTIFY,
HEAD,
OBJ,
EVENT,
TRACE_MSG_MAX,
};
enum TraceNotifySubType {
CMD = 0x1,
PARAMS,
};
enum TraceHeadSubType {
ENDIAN = 0x1,
VERSION,
OBJ_SIZE,
OBJ_COUNT,
CUR_INDEX,
MAX_RECODE,
CUR_OBJ_INDEX,
CLOCK_FREQ,
};
enum TraceObjSubType {
ADDR = 0x1,
PRIO,
NAME,
};
enum TraceEvtSubType {
CORE = 0x1,
EVENT_CODE,
CUR_TIME,
EVENT_COUNT,
CUR_TASK,
IDENTITY,
EVENT_PARAMS,
CUR_PID,
EVENT_LR,
};
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 */

View File

@@ -0,0 +1,110 @@
/*
* 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"
#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);
}

View File

@@ -0,0 +1,97 @@
/*
* 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_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define TRACE_TLV_MSG_HEAD 0xFF
#define TRACE_TLV_TYPE_NULL 0xFF
typedef struct {
UINT8 magicNum;
UINT8 msgType;
UINT16 len;
UINT16 crc;
} 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
* <ul>
* <li>Encade trace data</li>
* </ul>
*
* @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:
* <ul><li>trace_tlv.h: the header file that contains the API declaration.</li></ul>
* @see OsTraceDataEncode
*/
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 */

View File

@@ -0,0 +1,263 @@
/*
* 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"
#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(UINT32 size)
{
UINT32 headSize;
VOID *buf = NULL;
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;
}
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 CurPid CurTask Identity ");
#ifdef LOSCFG_TRACE_FRAME_CORE_MSG
PRINTK("cpuId hwiActive taskLockCnt ");
#endif
#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT
PRINTK("eventCount ");
#endif
#ifdef LOS_TRACE_FRAME_LR
UINT32 i;
PRINTK("backtrace ");
for (i = 0; i < LOS_TRACE_LR_RECORD; i++) {
PRINTK(" ");
}
#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%-7x 0x%-11x ", i, frame->curTime, frame->eventType,
frame->curPid, frame->curTask, frame->identity);
#ifdef LOSCFG_TRACE_FRAME_CORE_MSG
UINT32 taskLockCnt = frame->core.taskLockCnt;
#ifdef LOSCFG_KERNEL_SMP
/*
* For smp systems, TRACE_LOCK will requst taskLock, and this counter
* will increase by 1 in that case.
*/
taskLockCnt -= 1;
#endif
PRINTK("%-11u %-11u %-11u", frame->core.cpuId, frame->core.hwiActive, taskLockCnt);
#endif
#ifdef LOSCFG_TRACE_FRAME_EVENT_COUNT
PRINTK("%-11u", frame->eventCount);
#endif
#ifdef LOS_TRACE_FRAME_LR
for (j = 0; j < LOS_TRACE_LR_RECORD; j++) {
PRINTK("0x%-11x", frame->linkReg[j]);
}
#endif
for (j = 0; j < LOSCFG_TRACE_FRAME_MAX_PARAMS; j++) {
PRINTK("0x%-11x", frame->params[j]);
}
PRINTK("\n");
}
}
STATIC VOID OsTraceInfoDisplay(VOID)
{
OfflineHead *head = g_traceRecoder.head;
PRINTK("*******TraceInfo begin*******\n");
PRINTK("clockFreq = %u\n", head->baseInfo.clockFreq);
OsTraceInfoObj();
OsTraceInfoEventTitle();
OsTraceInfoEventData();
PRINTK("*******TraceInfo end*******\n");
}
#ifdef LOSCFG_TRACE_CLIENT_INTERACT
STATIC VOID OsTraceSendInfo(VOID)
{
UINT32 i;
ObjData *obj = NULL;
TraceEventFrame *frame = NULL;
OsTraceDataSend(HEAD, sizeof(OfflineHead), (UINT8 *)g_traceRecoder.head);
obj = &g_traceRecoder.ctrl.objBuf[0];
for (i = 0; i < g_traceRecoder.ctrl.maxObjCount; i++) {
OsTraceDataSend(OBJ, sizeof(ObjData), (UINT8 *)(obj + i));
}
frame = &g_traceRecoder.ctrl.frameBuf[0];
for (i = 0; i < g_traceRecoder.ctrl.maxRecordCount; i++) {
OsTraceDataSend(EVENT, sizeof(TraceEventFrame), (UINT8 *)(frame + i));
}
}
#endif
VOID OsTraceRecordDump(BOOL toClient)
{
if (!toClient) {
OsTraceInfoDisplay();
return;
}
#ifdef LOSCFG_TRACE_CLIENT_INTERACT
OsTraceSendInfo();
#endif
}
OfflineHead *OsTraceRecordGet(VOID)
{
return g_traceRecoder.head;
}

View File

@@ -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.
*/
#include "los_trace_pri.h"
#include "trace_pipeline.h"
UINT32 OsTraceGetMaskTid(UINT32 taskId)
{
return taskId;
}
UINT32 OsTraceBufInit(UINT32 size)
{
(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;
}