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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
154
kernel/extended/trace/pipeline/trace_pipeline.c
Normal file
154
kernel/extended/trace/pipeline/trace_pipeline.c
Normal 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();
|
||||
}
|
||||
106
kernel/extended/trace/pipeline/trace_pipeline.h
Normal file
106
kernel/extended/trace/pipeline/trace_pipeline.h
Normal 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 */
|
||||
110
kernel/extended/trace/pipeline/trace_tlv.c
Normal file
110
kernel/extended/trace/pipeline/trace_tlv.c
Normal 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);
|
||||
}
|
||||
97
kernel/extended/trace/pipeline/trace_tlv.h
Normal file
97
kernel/extended/trace/pipeline/trace_tlv.h
Normal 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 */
|
||||
Reference in New Issue
Block a user