提交 dc9ec685 编写于 作者: L LiteOS2021

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: NLiteOS2021 <dinglu@huawei.com>

Change-Id: I6a8e64794c4852f2c2980993a06180e09ec6ee0d
上级 658fafe8
......@@ -340,6 +340,7 @@ source "drivers/char/mem/Kconfig"
source "drivers/char/quickstart/Kconfig"
source "drivers/char/random/Kconfig"
source "drivers/char/video/Kconfig"
source "drivers/char/trace/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
source "../../drivers/liteos/hievent/Kconfig"
......
......@@ -47,4 +47,8 @@ group("apps") {
if (defined(LOSCFG_NET_LWIP_SACK_TFTP)) {
deps += [ "tftp" ]
}
if (defined(LOSCFG_DRIVERS_TRACE)) {
deps += [ "trace" ]
}
}
......@@ -66,6 +66,10 @@ ifeq ($(LOSCFG_NET_LWIP_SACK_TFTP), y)
APP_SUBDIRS += tftp
endif
ifeq ($(LOSCFG_DRIVERS_TRACE), y)
APP_SUBDIRS += trace
endif
# clear all local variables
LOCAL_FLAGS :=
LOCAL_CFLAGS :=
......
# 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")
executable("trace") {
sources = [ "src/trace.c" ]
}
\ No newline at end of file
# 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 $(APPSTOPDIR)/config.mk
APP_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := src/trace.c
include $(APP)
\ No newline at end of file
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdint.h>
#define TRACE_IOC_MAGIC 'T'
#define TRACE_START _IO(TRACE_IOC_MAGIC, 1)
#define TRACE_STOP _IO(TRACE_IOC_MAGIC, 2)
#define TRACE_RESET _IO(TRACE_IOC_MAGIC, 3)
#define TRACE_DUMP _IO(TRACE_IOC_MAGIC, 4)
#define TRACE_SET_MASK _IO(TRACE_IOC_MAGIC, 5)
#define TRACE_USR_MAX_PARAMS 3
typedef struct {
unsigned int eventType;
uintptr_t identity;
uintptr_t params[TRACE_USR_MAX_PARAMS];
} UsrEventInfo;
static void TraceUsage(void)
{
printf("\nUsage: ./trace [start] Start to trace events.\n");
printf("\nUsage: ./trace [stop] Stop trace.\n");
printf("\nUsage: ./trace [reset] Clear the trace record buffer.\n");
printf("\nUsage: ./trace [dump 0/1] Format printf trace data,"
"0/1 stands for whether to send data to studio for analysis.\n");
printf("\nUsage: ./trace [mask num] Set trace filter event mask.\n");
printf("\nUsage: ./trace [read nBytes] Read nBytes raw data from trace buffer.\n");
printf("\nUsage: ./trace [write type id params..] Write a user event, no more than 3 parameters.\n");
}
static void TraceRead(int fd, size_t size)
{
ssize_t i;
ssize_t len;
char *buffer = (char *)malloc(size);
if (buffer == NULL) {
printf("Read buffer malloc failed.\n");
return;
}
len = read(fd, buffer, size);
for (i = 0; i < len; i++) {
printf("%02x ", buffer[i] & 0xFF);
}
printf("\n");
free(buffer);
}
static void TraceWrite(int fd, int argc, char **argv)
{
int i;
UsrEventInfo info = {0};
info.eventType = strtoul(argv[2], NULL, 0);
info.identity = strtoul(argv[3], NULL, 0);
int paramNum = (argc - 4) > TRACE_USR_MAX_PARAMS ? TRACE_USR_MAX_PARAMS : (argc - 4);
for (i = 0; i < paramNum; i++) {
info.params[i] = strtoul(argv[4 + i], NULL, 0);
}
(void)write(fd, &info, sizeof(UsrEventInfo));
}
int main(int argc, char **argv)
{
int fd = open("/dev/trace", O_RDWR);
if (fd == -1) {
printf("Trace open failed.\n");
exit(EXIT_FAILURE);
}
if (argc == 1) {
TraceUsage();
} else if (argc == 2 && strcmp(argv[1], "start") == 0) {
ioctl(fd, TRACE_START, NULL);
} else if (argc == 2 && strcmp(argv[1], "stop") == 0) {
ioctl(fd, TRACE_STOP, NULL);
} else if (argc == 2 && strcmp(argv[1], "reset") == 0) {
ioctl(fd, TRACE_RESET, NULL);
} else if (argc == 3 && strcmp(argv[1], "mask") == 0) {
size_t mask = strtoul(argv[2], NULL, 0);
ioctl(fd, TRACE_SET_MASK, mask);
} else if (argc == 3 && strcmp(argv[1], "dump") == 0) {
size_t flag = strtoul(argv[2], NULL, 0);
ioctl(fd, TRACE_DUMP, flag);
} else if (argc == 3 && strcmp(argv[1], "read") == 0) {
size_t size = strtoul(argv[2], NULL, 0);
TraceRead(fd, size);
} else if (argc >= 4 && strcmp(argv[1], "write") == 0) {
TraceWrite(fd, argc, argv);
} else {
printf("Unsupported trace command.\n");
TraceUsage();
}
close(fd);
return 0;
}
......@@ -36,7 +36,7 @@
#include "los_cpup_pri.h"
#endif
#include "los_sched_pri.h"
#include "los_hook.h"
/* spinlock for hwi module, only available on SMP mode */
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin);
......@@ -84,7 +84,7 @@ VOID OsInterrupt(UINT32 intNum)
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
OsCpupIrqStart();
#endif
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, intNum);
hwiForm = (&g_hwiForm[intNum]);
#ifndef LOSCFG_NO_SHARED_IRQ
while (hwiForm->pstNext != NULL) {
......@@ -107,6 +107,7 @@ VOID OsInterrupt(UINT32 intNum)
#endif
++g_hwiFormCnt[intNum];
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, intNum);
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
OsCpupIrqEnd(intNum);
#endif
......
......@@ -36,6 +36,7 @@ group("drivers") {
"char/mem",
"char/quickstart",
"char/random",
"char/trace",
"char/video",
"mtd/multi_partition",
]
......@@ -49,6 +50,7 @@ config("public") {
"char/quickstart:public",
"char/random:public",
"char/video:public",
"char/trace:public",
"mtd/multi_partition:public",
]
}
# 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_DRIVERS_TRACE)
module_name = "trace_dev"
kernel_module(module_name) {
sources = [ "src/trace.c" ]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "include" ]
}
config DRIVERS_TRACE
bool "Enable TRACE DRIVER"
default y
depends on DRIVERS && FS_VFS && KERNEL_TRACE
help
Answer Y to enable LiteOS support trace in userspace.
\ No newline at end of file
# 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 := trace_dev
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/drivers/char/trace/include
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)
......@@ -29,40 +29,21 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/statfs.h>
#include <sys/mount.h>
#include "proc_fs.h"
#ifndef __LOS_DEV_TRACE_H__
#define __LOS_DEV_TRACE_H__
#ifdef LOSCFG_KERNEL_TRACE
#include "los_trace.h"
static int KernelTraceProcFill(struct SeqBuf *m, void *v)
{
(void)v;
if (m == NULL) {
return -LOS_EPERM;
}
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
if (m->buf == NULL) {
m->buf = (char *)LOS_TraceBufDataGet(&(m->size), &(m->count));
}
return 0;
}
static const struct ProcFileOperations KERNEL_TRACE_PROC_FOPS = {
.read = KernelTraceProcFill,
};
#endif
int DevTraceRegister(void);
void ProcKernelTraceInit(void)
{
#ifdef LOSCFG_KERNEL_TRACE
struct ProcDirEntry *pde = CreateProcEntry("ktrace", 0, NULL);
if (pde == NULL) {
PRINT_ERR("create /proc/ktrace error!\n");
return;
}
pde->procFileOps = &KERNEL_TRACE_PROC_FOPS;
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
/*
* 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 "fcntl.h"
#include "linux/kernel.h"
#include "sys/ioctl.h"
#include "fs/driver.h"
#include "los_dev_trace.h"
#include "los_trace.h"
#include "los_hook.h"
#define TRACE_DRIVER "/dev/trace"
#define TRACE_DRIVER_MODE 0666
/* trace ioctl */
#define TRACE_IOC_MAGIC 'T'
#define TRACE_START _IO(TRACE_IOC_MAGIC, 1)
#define TRACE_STOP _IO(TRACE_IOC_MAGIC, 2)
#define TRACE_RESET _IO(TRACE_IOC_MAGIC, 3)
#define TRACE_DUMP _IO(TRACE_IOC_MAGIC, 4)
#define TRACE_SET_MASK _IO(TRACE_IOC_MAGIC, 5)
static int TraceOpen(struct file *filep)
{
return 0;
}
static int TraceClose(struct file *filep)
{
return 0;
}
static ssize_t TraceRead(struct file *filep, char *buffer, size_t buflen)
{
/* trace record buffer read */
ssize_t len = buflen;
OfflineHead *records;
int ret;
int realLen;
if (len % sizeof(unsigned int)) {
PRINT_ERR("Buffer size not aligned by 4 bytes\n");
return -EINVAL;
}
records = LOS_TraceRecordGet();
if (records == NULL) {
PRINT_ERR("Trace read failed, check whether trace mode is set to offline\n");
return -EINVAL;
}
realLen = buflen < records->totalLen ? buflen : records->totalLen;
ret = LOS_CopyFromKernel((void *)buffer, buflen, (void *)records, realLen);
if (ret != 0) {
return -EINVAL;
}
return realLen;
}
static ssize_t TraceWrite(struct file *filep, const char *buffer, size_t buflen)
{
/* trace usr event here */
int ret;
UsrEventInfo *info = NULL;
int infoLen = sizeof(UsrEventInfo);
if (buflen != infoLen) {
PRINT_ERR("Buffer size not %d bytes\n", infoLen);
return -EINVAL;
}
info = LOS_MemAlloc(m_aucSysMem0, infoLen);
if (info == NULL) {
return -ENOMEM;
}
memset_s(info, infoLen, 0, infoLen);
ret = LOS_CopyToKernel(info, infoLen, buffer, buflen);
if (ret != 0) {
LOS_MemFree(m_aucSysMem0, info);
return -EINVAL;
}
OsHookCall(LOS_HOOK_TYPE_USR_EVENT, info, infoLen);
return 0;
}
static int TraceIoctl(struct file *filep, int cmd, unsigned long arg)
{
switch (cmd) {
case TRACE_START:
return LOS_TraceStart();
case TRACE_STOP:
LOS_TraceStop();
break;
case TRACE_RESET:
LOS_TraceReset();
break;
case TRACE_DUMP:
LOS_TraceRecordDump((BOOL)arg);
break;
case TRACE_SET_MASK:
LOS_TraceEventMaskSet((UINT32)arg);
break;
default:
PRINT_ERR("Unknown trace ioctl cmd:%d\n", cmd);
return -EINVAL;
}
return 0;
}
static const struct file_operations_vfs g_traceDevOps = {
TraceOpen, /* open */
TraceClose, /* close */
TraceRead, /* read */
TraceWrite, /* write */
NULL, /* seek */
TraceIoctl, /* ioctl */
NULL, /* mmap */
#ifndef CONFIG_DISABLE_POLL
NULL, /* poll */
#endif
NULL, /* unlink */
};
int DevTraceRegister(void)
{
return register_driver(TRACE_DRIVER, &g_traceDevOps, TRACE_DRIVER_MODE, 0); /* 0666: file mode */
}
......@@ -35,7 +35,6 @@ kernel_module(module_name) {
sources = [
"os_adapt/fd_proc.c",
"os_adapt/fs_cache_proc.c",
"os_adapt/kernel_trace_proc.c",
"os_adapt/mounts_proc.c",
"os_adapt/power_proc.c",
"os_adapt/proc_init.c",
......
......@@ -51,8 +51,6 @@ void ProcVmmInit(void);
void ProcProcessInit(void);
void ProcKernelTraceInit(void);
int ProcMatch(unsigned int len, const char *name, struct ProcDirEntry *pde);
struct ProcDirEntry *ProcFindEntry(const char *path);
......
......@@ -63,7 +63,6 @@ void ProcFsInit(void)
#endif
ProcProcessInit();
ProcUptimeInit();
ProcKernelTraceInit();
ProcFsCacheInit();
ProcFdInit();
#ifdef LOSCFG_KERNEL_PM
......
......@@ -110,12 +110,88 @@ config KERNEL_VDSO
help
If you wish to speed up some system calls.
config KERNEL_HOOK
bool "Enable Hook Feature"
default n
depends on KERNEL_EXTKERNEL && DEBUG_VERSION
config KERNEL_TRACE
bool "Enable Trace Feature"
default n
depends on KERNEL_EXTKERNEL && DEBUG_VERSION
depends on KERNEL_HOOK
config TRACE_MSG_EXTEND
bool "Enable Record more extended content"
default n
depends on KERNEL_TRACE
config TRACE_FRAME_CORE_MSG
bool "Record cpuid, hardware interrupt status, task lock status"
default n
depends on TRACE_MSG_EXTEND
config TRACE_FRAME_EVENT_COUNT
bool "Record event count, which indicate the sequence of happend events"
default n
depends on TRACE_MSG_EXTEND
config TRACE_FRAME_MAX_PARAMS
int "Record max params"
default 3
depends on KERNEL_TRACE
help
If you wish to record LiteOS's task and interrupt switch trace.
Make sure the max value is bigger than the number defined by each #MODULE#_#TYPE#_PARMAS in los_trace.h, e.g. TASK_SWITCH_PARAMS
choice
prompt "Trace work mode"
default RECORDER_MODE_OFFLINE
depends on KERNEL_TRACE
config RECORDER_MODE_ONLINE
bool "Online mode"
select TRACE_CLIENT_INTERACT
config RECORDER_MODE_OFFLINE
bool "Offline mode"
endchoice
config TRACE_BUFFER_SIZE
int "Trace record buffer size"
default 10000
config TRACE_CLIENT_INTERACT
bool "Enable Trace Client Visualization and Control"
default n
depends on KERNEL_TRACE
choice
prompt "Trace Pipeline for Data Transmission"
depends on TRACE_CLIENT_INTERACT
config TRACE_PIPELINE_SERIAL
bool "Via Serial"
endchoice
choice
prompt "Trace Control"
default TRACE_CONTROL_VIA_SHELL
depends on TRACE_CLIENT_INTERACT
help
If you wish to control Trace's start/stop etc.,dynamically by Trace Client.
config TRACE_CONTROL_VIA_SHELL
bool "Via Shell"
select LOSCFG_SHELL
config TRACE_CONTROL_AGENT
bool "Via Trace Agent Task"
config TRACE_NO_CONTROL
bool "No Control"
endchoice
config KERNEL_SHM
bool "Enable Shared Memory"
......
......@@ -36,7 +36,7 @@
#include "los_sched_pri.h"
#include "los_sortlink_pri.h"
#include "los_task_pri.h"
#include "los_hook.h"
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
#if (LOSCFG_BASE_CORE_SWTMR_LIMIT <= 0)
......@@ -268,7 +268,8 @@ LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
swtmr->startTime = GET_SORTLIST_VALUE(sortList);
OsDeleteNodeSortLink(swtmrSortLink, sortList);
LOS_SpinUnlock(&cpu->swtmrSortLinkSpin);
OsHookCall(LOS_HOOK_TYPE_SWTMR_EXPIRED, swtmr);
OsWakePendTimeSwtmr(cpu, currTime, swtmr);
LOS_SpinLock(&cpu->swtmrSortLinkSpin);
......@@ -362,7 +363,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
SET_SORTLIST_VALUE(&swtmr->stSortList, OS_SORT_LINK_INVALID_TIME);
*swtmrID = swtmr->usTimerID;
OsHookCall(LOS_HOOK_TYPE_SWTMR_CREATE, swtmr);
return LOS_OK;
}
......@@ -407,6 +408,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
}
SWTMR_UNLOCK(intSave);
OsHookCall(LOS_HOOK_TYPE_SWTMR_START, swtmr);
return ret;
}
......@@ -446,6 +448,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrID)
}
SWTMR_UNLOCK(intSave);
OsHookCall(LOS_HOOK_TYPE_SWTMR_STOP, swtmr);
return ret;
}
......@@ -526,6 +529,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
}
SWTMR_UNLOCK(intSave);
OsHookCall(LOS_HOOK_TYPE_SWTMR_DELETE, swtmr);
return ret;
}
......
......@@ -47,6 +47,7 @@
#include "los_vm_map.h"
#include "los_vm_syscall.h"
#include "los_signal.h"
#include "los_hook.h"
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
......@@ -208,10 +209,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
LOS_ListTailInsert(&g_losFreeTask, &g_taskCBArray[index].pendList);
}
#ifdef LOSCFG_KERNEL_TRACE
LOS_TraceReg(LOS_TRACE_TASK, OsTaskTrace, LOS_TRACE_TASK_NAME, LOS_TRACE_ENABLE);
#endif
ret = OsSchedInit();
EXIT:
......@@ -652,6 +649,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
}
*taskID = taskCB->taskID;
OsHookCall(LOS_HOOK_TYPE_TASK_CREATE, taskCB);
return LOS_OK;
LOS_ERREND_TCB_INIT:
......@@ -820,7 +818,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
}
taskCB->taskStatus |= OS_TASK_STATUS_SUSPENDED;
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, taskCB);
if (taskCB == OsCurrTaskGet()) {
OsSchedResched();
}
......@@ -990,7 +988,7 @@ LITE_OS_SEC_TEXT UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UIN
OsWriteResourceEvent(OS_RESOURCE_EVENT_FREE);
return errRet;
}
OsHookCall(LOS_HOOK_TYPE_TASK_DELETE, taskCB);
if (mode == OS_USER_MODE) {
SCHEDULER_UNLOCK(intSave);
OsTaskResourcesToFree(taskCB);
......@@ -1075,13 +1073,14 @@ LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
if (!OsPreemptable()) {
return LOS_ERRNO_TSK_DELAY_IN_LOCK;
}
OsHookCall(LOS_HOOK_TYPE_TASK_DELAY, tick);
if (tick == 0) {
return LOS_TaskYield();
}
SCHEDULER_LOCK(intSave);
OsSchedDelay(runTask, tick);
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, runTask);
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
......
......@@ -45,10 +45,6 @@
#include "los_cpup_pri.h"
#endif
#ifdef LOSCFG_KERNEL_TRACE
#include "los_trace.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
......@@ -505,24 +501,12 @@ STATIC INLINE VOID OsTaskWaitSetPendMask(UINT16 mask, UINTPTR lockID, UINT32 tim
runTask->waitID = lockID;
runTask->waitFlag = mask;
(VOID)timeout;
#ifdef LOSCFG_KERNEL_TRACE
UINT16 status = OS_TASK_STATUS_PENDING;
if (timeout != LOS_WAIT_FOREVER) {
status |= OS_TASK_STATUS_PEND_TIME;
}
LOS_Trace(LOS_TRACE_TASK, runTask->taskEntry, status, mask, lockID);
#endif
}
STATIC INLINE VOID OsTaskWakeClearPendMask(LosTaskCB *resumeTask)
{
resumeTask->waitID = 0;
resumeTask->waitFlag = 0;
#ifdef LOSCFG_KERNEL_TRACE
LosTaskCB *runTask = OsCurrTaskGet();
LOS_Trace(LOS_TRACE_TASK, resumeTask->taskEntry, (UINT16)OS_TASK_STATUS_READY,
runTask->taskStatus, runTask->taskEntry);
#endif
}
extern UINT32 OsTaskSetDetachUnsafe(LosTaskCB *taskCB);
......@@ -559,23 +543,6 @@ extern VOID OsWriteResourceEvent(UINT32 events);
extern VOID OsWriteResourceEventUnsafe(UINT32 events);
extern UINT32 OsResourceFreeTaskCreate(VOID);
#ifdef LOSCFG_DEBUG_VERSION
STATIC INLINE VOID OsTraceTaskSchedule(LosTaskCB *newTask, LosTaskCB *runTask)
{
(VOID)newTask;
(VOID)runTask;
#ifdef LOSCFG_KERNEL_TRACE
LOS_Trace(LOS_TRACE_TASK, newTask->taskEntry, (UINT16)OS_TASK_STATUS_RUNNING,
runTask->taskStatus, runTask->taskEntry);
#endif
}
#else
#define OsTraceTaskSchedule(newTask, runTask)
#endif
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -35,6 +35,7 @@
#include "los_mp.h"
#include "los_percpu_pri.h"
#include "los_sched_pri.h"
#include "los_hook.h"
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
#include "los_exc.h"
#endif
......@@ -51,6 +52,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
eventCB->uwEventID = 0;
LOS_ListInit(&eventCB->stEventList);
LOS_IntRestore(intSave);
OsHookCall(LOS_HOOK_TYPE_EVENT_INIT, eventCB);
return LOS_OK;
}
......@@ -126,6 +128,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventM
{
UINT32 ret = 0;
LosTaskCB *runTask = OsCurrTaskGet();
OsHookCall(LOS_HOOK_TYPE_EVENT_READ, eventCB, eventMask, mode, timeout);
if (once == FALSE) {
ret = OsEventPoll(&eventCB->uwEventID, eventMask, mode);
......@@ -193,7 +196,7 @@ LITE_OS_SEC_TEXT VOID OsEventWriteUnsafe(PEVENT_CB_S eventCB, UINT32 events, BOO
LosTaskCB *resumedTask = NULL;
LosTaskCB *nextTask = NULL;
BOOL schedFlag = FALSE;
OsHookCall(LOS_HOOK_TYPE_EVENT_WRITE, eventCB, events);
eventCB->uwEventID |= events;
if (!LOS_ListEmpty(&eventCB->stEventList)) {
for (resumedTask = LOS_DL_LIST_ENTRY((&eventCB->stEventList)->pstNext, LosTaskCB, pendList);
......@@ -292,7 +295,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventDestroy(PEVENT_CB_S eventCB)
eventCB->uwEventID = 0;
LOS_ListDelInit(&eventCB->stEventList);
SCHEDULER_UNLOCK(intSave);
OsHookCall(LOS_HOOK_TYPE_EVENT_DESTROY, eventCB);
return LOS_OK;
}
......@@ -303,6 +306,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_EventClear(PEVENT_CB_S eventCB, UINT32 eventMa
if (eventCB == NULL) {
return LOS_ERRNO_EVENT_PTR_NULL;
}
OsHookCall(LOS_HOOK_TYPE_EVENT_CLEAR, eventCB, eventMask);
SCHEDULER_LOCK(intSave);
eventCB->uwEventID &= eventMask;
SCHEDULER_UNLOCK(intSave);
......
......@@ -36,7 +36,7 @@
#include "los_spinlock.h"
#include "los_mp.h"
#include "los_percpu_pri.h"
#include "los_hook.h"
#ifdef LOSCFG_BASE_IPC_QUEUE
#if (LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0)
......@@ -137,6 +137,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(CHAR *queueName, UINT16 len, UINT32
SCHEDULER_UNLOCK(intSave);
*queueID = queueCB->queueID;
OsHookCall(LOS_HOOK_TYPE_QUEUE_CREATE, queueCB);
return LOS_OK;
}
......@@ -263,6 +264,7 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT
UINT32 ret;
UINT32 readWrite = OS_QUEUE_READ_WRITE_GET(operateType);
UINT32 intSave;
OsHookCall(LOS_HOOK_TYPE_QUEUE_READ, (LosQueueCB *)GET_QUEUE_HANDLE(queueID), operateType, *bufferSize, timeout);
SCHEDULER_LOCK(intSave);
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
......@@ -435,7 +437,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueID)
LOS_ListTailInsert(&g_freeQueueList, &queueCB->readWriteList[OS_QUEUE_WRITE]);
SCHEDULER_UNLOCK(intSave);
OsHookCall(LOS_HOOK_TYPE_QUEUE_DELETE, queueCB);
ret = LOS_MemFree(m_aucSysMem1, (VOID *)queue);
return ret;
......
......@@ -38,7 +38,7 @@
#include "los_spinlock.h"
#include "los_mp.h"
#include "los_percpu_pri.h"
#include "los_hook.h"
#ifdef LOSCFG_BASE_IPC_SEM
......@@ -118,7 +118,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *
semCreated->maxSemCount = maxCount;
LOS_ListInit(&semCreated->semList);
*semHandle = semCreated->semID;
OsHookCall(LOS_HOOK_TYPE_SEM_CREATE, semCreated);
OsSemDbgUpdateHook(semCreated->semID, OsCurrTaskGet()->taskEntry, count);
return LOS_OK;
......@@ -165,6 +165,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle)
semDeleted->semStat = OS_SEM_UNUSED;
semDeleted->semID = SET_SEM_ID(GET_SEM_COUNT(semDeleted->semID) + 1, GET_SEM_INDEX(semDeleted->semID));
OsHookCall(LOS_HOOK_TYPE_SEM_DELETE, semDeleted);
OsSemDbgUpdateHook(semDeleted->semID, NULL, 0);
SCHEDULER_UNLOCK(intSave);
......@@ -203,12 +204,12 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
retErr = LOS_ERRNO_SEM_INVALID;
goto OUT;
}
/* Update the operate time, no matter the actual Pend success or not */
OsSemDbgTimeUpdateHook(semHandle);
if (semPended->semCount > 0) {
semPended->semCount--;
OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runTask, timeout);
goto OUT;
} else if (!timeout) {
retErr = LOS_ERRNO_SEM_UNAVAILABLE;
......@@ -222,6 +223,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
goto OUT;
}
OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runTask, timeout);
OsTaskWaitSetPendMask(OS_TASK_WAIT_SEM, semPended->semID, timeout);
retErr = OsSchedTaskWait(&semPended->semList, timeout, TRUE);
if (retErr == LOS_ERRNO_TSK_TIMEOUT) {
......@@ -259,7 +261,7 @@ LITE_OS_SEC_TEXT UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched)
} else {
semPosted->semCount++;
}
OsHookCall(LOS_HOOK_TYPE_SEM_POST, semPosted, resumedTask);
return LOS_OK;
}
......
......@@ -37,11 +37,7 @@
#include "los_vm_boot.h"
#include "los_vm_filemap.h"
#include "los_task_pri.h"
#ifdef LOSCFG_KERNEL_TRACE
#include "los_trace_frame.h"
#include "los_trace.h"
#endif
#include "los_hook.h"
/* Used to cut non-essential functions. */
#define OS_MEM_FREE_BY_TASKID 0
......@@ -865,11 +861,7 @@ UINT32 LOS_MemInit(VOID *pool, UINT32 size)
}
#endif
#ifdef LOSCFG_KERNEL_TRACE
LOS_TraceReg(LOS_TRACE_MEM_TIME, OsMemTimeTrace, LOS_TRACE_MEM_TIME_NAME, LOS_TRACE_ENABLE);
LOS_TraceReg(LOS_TRACE_MEM_INFO, OsMemInfoTrace, LOS_TRACE_MEM_INFO_NAME, LOS_TRACE_ENABLE);
#endif
OsHookCall(LOS_HOOK_TYPE_MEM_INIT, pool, size);
return LOS_OK;
}
......@@ -886,11 +878,7 @@ UINT32 LOS_MemDeInit(VOID *pool)
OsMemPoolDeinit(pool);
#ifdef LOSCFG_KERNEL_TRACE
LOS_TraceUnreg(LOS_TRACE_MEM_TIME);
LOS_TraceUnreg(LOS_TRACE_MEM_INFO);
#endif
OsHookCall(LOS_HOOK_TYPE_MEM_DEINIT, pool);
return LOS_OK;
}
......@@ -958,10 +946,6 @@ retry:
VOID *LOS_MemAlloc(VOID *pool, UINT32 size)
{
#ifdef LOSCFG_KERNEL_TRACE
UINT64 start = HalClockGetCycles();
#endif
if ((pool == NULL) || (size == 0)) {
return (size > 0) ? OsVmBootMemAlloc(size) : NULL;
}
......@@ -983,28 +967,12 @@ VOID *LOS_MemAlloc(VOID *pool, UINT32 size)
MEM_UNLOCK(poolHead, intSave);
} while (0);
#ifdef LOSCFG_KERNEL_TRACE
UINT64 end = HalClockGetCycles();
UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_MALLOC, timeUsed);
LOS_MEM_POOL_STATUS poolStatus = {0};
(VOID)LOS_MemInfoGet(pool, &poolStatus);
UINT8 fragment = 100 - poolStatus.maxFreeNodeSize * 100 / poolStatus.totalFreeSize; /* 100: percent denominator. */
UINT8 usage = LOS_MemTotalUsedGet(pool) * 100 / LOS_MemPoolSizeGet(pool); /* 100: percent denominator. */
LOS_Trace(LOS_TRACE_MEM_INFO, (UINTPTR)pool & MEM_POOL_ADDR_MASK, fragment, usage, poolStatus.totalFreeSize,
poolStatus.maxFreeNodeSize, poolStatus.usedNodeNum, poolStatus.freeNodeNum);
#endif
OsHookCall(LOS_HOOK_TYPE_MEM_ALLOC, pool, ptr, size);
return ptr;
}
VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
{
#ifdef LOSCFG_KERNEL_TRACE
UINT64 start = HalClockGetCycles();
#endif
UINT32 gapSize;
if ((pool == NULL) || (size == 0) || (boundary == 0) || !OS_MEM_IS_POW_TWO(boundary) ||
......@@ -1053,12 +1021,7 @@ VOID *LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
ptr = alignedPtr;
} while (0);
#ifdef LOSCFG_KERNEL_TRACE
UINT64 end = HalClockGetCycles();
UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_MEMALIGN, timeUsed);
#endif
OsHookCall(LOS_HOOK_TYPE_MEM_ALLOCALIGN, pool, ptr, size, boundary);
return ptr;
}
......@@ -1209,14 +1172,11 @@ STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
{
#ifdef LOSCFG_KERNEL_TRACE
UINT64 start = HalClockGetCycles();
#endif
if ((pool == NULL) || (ptr == NULL) || !OS_MEM_IS_ALIGNED(pool, sizeof(VOID *)) ||
!OS_MEM_IS_ALIGNED(ptr, sizeof(VOID *))) {
return LOS_NOK;
}
OsHookCall(LOS_HOOK_TYPE_MEM_FREE, pool, ptr);
UINT32 ret = LOS_NOK;
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
......@@ -1245,12 +1205,6 @@ UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
MEM_UNLOCK(poolHead, intSave);
} while (0);
#ifdef LOSCFG_KERNEL_TRACE
UINT64 end = HalClockGetCycles();
UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_FREE, timeUsed);
#endif
return ret;
}
......@@ -1345,14 +1299,10 @@ STATIC INLINE VOID *OsMemRealloc(struct OsMemPoolHead *pool, const VOID *ptr,
VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size)
{
#ifdef LOSCFG_KERNEL_TRACE
UINT64 start = HalClockGetCycles();
#endif
if ((pool == NULL) || OS_MEM_NODE_GET_USED_FLAG(size) || OS_MEM_NODE_GET_ALIGNED_FLAG(size)) {
return NULL;
}
OsHookCall(LOS_HOOK_TYPE_MEM_REALLOC, pool, ptr, size);
if (size < OS_MEM_MIN_ALLOC_SIZE) {
size = OS_MEM_MIN_ALLOC_SIZE;
}
......@@ -1387,12 +1337,6 @@ VOID *LOS_MemRealloc(VOID *pool, VOID *ptr, UINT32 size)
} while (0);
MEM_UNLOCK(poolHead, intSave);
#ifdef LOSCFG_KERNEL_TRACE
UINT64 end = HalClockGetCycles();
UINT32 timeUsed = MEM_TRACE_CYCLE_TO_US(end - start);
LOS_Trace(LOS_TRACE_MEM_TIME, (UINTPTR)pool & MEM_POOL_ADDR_MASK, MEM_TRACE_REALLOC, timeUsed);
#endif
return newPtr;
}
......
......@@ -34,6 +34,7 @@
#include "los_task_pri.h"
#include "los_process_pri.h"
#include "los_arch_mmu.h"
#include "los_hook.h"
#ifdef LOSCFG_KERNEL_CPUP
#include "los_cpup_pri.h"
#endif
......@@ -724,6 +725,7 @@ BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 policy, UINT16 priori
}
taskCB->priority = priority;
OsHookCall(LOS_HOOK_TYPE_TASK_PRIMODIFY, taskCB, taskCB->priority);
if (taskCB->taskStatus & OS_TASK_STATUS_INIT) {
OsSchedTaskEnQueue(taskCB);
return TRUE;
......@@ -953,8 +955,7 @@ STATIC INLINE VOID OsSchedSwitchCheck(LosTaskCB *runTask, LosTaskCB *newTask)
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
OsTaskStackCheck(runTask, newTask);
#endif /* LOSCFG_BASE_CORE_TSK_MONITOR */
OsTraceTaskSchedule(newTask, runTask);
OsHookCall(LOS_HOOK_TYPE_TASK_SWITCHEDIN, newTask, runTask);
}
STATIC INLINE VOID OsSchedSwitchProcess(LosProcessCB *runProcess, LosProcessCB *newProcess)
......
......@@ -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",
......
# 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" ]
}
# 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)
/*
* 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 */
/*
* 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 */
/*
* 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 */
......@@ -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;
}
......
......@@ -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",
]
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",
]
}
config("public") {
include_dirs = [ "." ]
if (defined(LOSCFG_TRACE_PIPELINE_SERIAL)) {
sources += [ "pipeline/serial/trace_pipeline_serial.c" ]
include_dirs += [ "pipeline/serial" ]
}
}
......@@ -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)
/*
* 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);
}
/*
* 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 */
此差异已折叠。
......@@ -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 */
#ifdef LOSCFG_TRACE_CONTROL_AGENT
#define TRACE_CMD_END_CHAR 0xD
#endif
#define TRACE_ERROR PRINT_ERR
#define TRACE_MODE_OFFLINE 0
#define TRACE_MODE_ONLINE 1
/* just task and hwi were traced */
#define TRACE_DEFAULT_MASK (TRACE_HWI_FLAG | TRACE_TASK_FLAG)
#define TRACE_CTL_MAGIC_NUM 0xDEADBEEF
#define TRACE_BIGLITTLE_WORD 0x12345678
#define TRACE_VERSION(MODE) (0xFFFFFFFF & (MODE))
#define TRACE_MASK_COMBINE(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
#define TRACE_GET_MODE_FLAG(type) ((type) & 0xFFFFFFF0)
#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 {
TraceSwitch onOff;
WriteHook inputHook;
const CHAR *typeStr;
} TraceHook;
UINT8 cmd;
UINT8 param1;
UINT8 param2;
UINT8 param3;
UINT8 param4;
UINT8 param5;
UINT8 end;
} TraceClientCmd;
/*
* |1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0|
* | |
* readIndex writeIndex
/**
* @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 {
UINT8 *dataBuf;
UINT32 bufLen;
TraceSwitch onOff;
UINT32 writeIndex;
UINT32 readIndex;
} TraceBufferCtl;
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 */
/*
* 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();
}
/*
* 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 */
/*
* 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();
}
/*
* 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 */
......@@ -28,95 +28,83 @@
* 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"
#include "trace_tlv.h"
#include "securec.h"
#ifdef LOSCFG_KERNEL_TRACE
#define CRC_WIDTH 8
#define CRC_POLY 0x1021
#define CRC_TOPBIT 0x8000
INT32 OsTaskTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
STATIC UINT16 CalcCrc16(const UINT8 *buf, UINT32 len)
{
va_list ap2;
va_copy(ap2, ap);
TaskTraceFrame *x = (TaskTraceFrame *)inputBuffer;
if (sizeof(TaskTraceFrame) > bufLen) {
va_end(ap2);
return 0;
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;
}
}
}
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);
return crc;
}
INT32 OsIpcTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
STATIC UINT32 OsWriteTlv(UINT8 *tlvBuf, UINT8 type, UINT8 len, UINT8 *value)
{
va_list ap2;
va_copy(ap2, ap);
TraceMsgTlvBody *body = (TraceMsgTlvBody *)tlvBuf;
IpcTraceFrame *x = (IpcTraceFrame *)inputBuffer;
if (sizeof(IpcTraceFrame) > bufLen) {
va_end(ap2);
if (len == 0) {
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);
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);
}
INT32 OsMemTimeTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
STATIC UINT32 OsTlvEncode(const TlvTable *table, UINT8 *srcBuf, UINT8 *tlvBuf, INT32 tlvBufLen)
{
va_list ap2;
va_copy(ap2, ap);
MemTimeTraceFrame *x = (MemTimeTraceFrame *)inputBuffer;
if (sizeof(MemTimeTraceFrame) > bufLen) {
va_end(ap2);
return 0;
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++;
}
SETPARAM(ap2, x, poolAddr, UINT16);
SETPARAM(ap2, x, type, UINT16);
SETPARAM(ap2, x, timeUsed, UINT32);
va_end(ap2);
return sizeof(MemTimeTraceFrame);
return len;
}
INT32 OsMemInfoTrace(UINT8 *inputBuffer, UINT32 bufLen, va_list ap)
UINT32 OsTraceDataEncode(UINT8 type, const TlvTable *table, UINT8 *src, UINT8 *dest, INT32 destLen)
{
va_list ap2;
va_copy(ap2, ap);
UINT16 crc;
INT32 len;
INT32 tlvBufLen;
UINT8 *tlvBuf = NULL;
MemInfoTraceFrame *x = (MemInfoTraceFrame *)inputBuffer;
if (sizeof(MemInfoTraceFrame) > bufLen) {
va_end(ap2);
TraceMsgTlvHead *head = (TraceMsgTlvHead *)dest;
tlvBufLen = destLen - sizeof(TraceMsgTlvHead);
if ((tlvBufLen <= 0) || (table == NULL)) {
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);
tlvBuf = dest + sizeof(TraceMsgTlvHead);
len = OsTlvEncode(table, src, tlvBuf, tlvBufLen);
crc = CalcCrc16(tlvBuf, len);
va_end(ap2);
return sizeof(MemInfoTraceFrame);
head->magicNum = TRACE_TLV_MSG_HEAD;
head->msgType = type;
head->len = len;
head->crc = crc;
return len + sizeof(TraceMsgTlvHead);
}
#endif
......@@ -28,93 +28,70 @@
* 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
#ifndef _TRACE_TLV_H
#define _TRACE_TLV_H
#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 ()
#include "los_typedef.h"
#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))
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#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"
#define TRACE_TLV_MSG_HEAD 0xFF
#define TRACE_TLV_TYPE_NULL 0xFF
/* 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;
UINT8 magicNum;
UINT8 msgType;
UINT16 len;
UINT16 crc;
} TraceMsgTlvHead;
/* 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 */
UINT8 type;
UINT8 len;
UINT8 value[];
} TraceMsgTlvBody;
/* 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; /* 0:malloc, 1: free, 2: memalign, 3: realloc. */
UINT32 timeUsed; /* Time-consuming for each type of interface about type, uint: us. */
} MemTimeTraceFrame;
UINT8 tag;
UINT8 elemOffset;
UINT8 elemSize;
} TlvTable;
/* 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;
/**
* @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);
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);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
#endif /* _TRACE_TLV_H */
/*
* 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;
}
/*
* 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;
}
......@@ -142,6 +142,7 @@ enum LOS_MOUDLE_ID {
LOS_MOD_EVENT = 0x1c,
LOS_MOD_MUX = 0X1d,
LOS_MOD_CPUP = 0x1e,
LOS_MOD_HOOK = 0x1f,
LOS_MOD_SHELL = 0x31,
LOS_MOD_DRIVER = 0x41,
LOS_MOD_BUTT
......
/*
* 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_H
#define _LOS_HOOK_H
#include "los_config.h"
#include "los_err.h"
#include "los_errno.h"
#ifdef LOSCFG_KERNEL_HOOK
#include "los_hook_types.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_KERNEL_HOOK
/**
* @ingroup los_hook
* Hook error code: The hook pool is insufficient.
*
* Value: 0x02001f00
*
* Solution: Deregister the registered hook.
*/
#define LOS_ERRNO_HOOK_POOL_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x00)
/**
* @ingroup los_hook
* Hook error code: Invalid parameter.
*
* Value: 0x02001f01
*
* Solution: Check the input parameters of LOS_HookReg.
*/
#define LOS_ERRNO_HOOK_REG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x01)
/**
* @ingroup los_hook
* Hook error code: Invalid parameter.
*
* Value: 0x02001f02
*
* Solution: Check the input parameters of LOS_HookUnReg.
*/
#define LOS_ERRNO_HOOK_UNREG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x02)
/**
* @ingroup los_hook
* @brief Registration of hook function.
*
* @par Description:
* This API is used to register hook function.
*
* @attention
* <ul>
* <li> None.</li>
* </ul>
*
* @param hookType [IN] Register the type of the hook.
* @param hookFn [IN] The function to be registered.
*
* @retval None.
* @par Dependency:
* <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_HookReg(hookType, hookFn) hookType##_RegHook(hookFn)
/**
* @ingroup los_hook
* @brief Deregistration of hook function.
*
* @par Description:
* This API is used to deregister hook function.
*
* @attention
* <ul>
* <li> None.</li>
* </ul>
*
* @param hookType [IN] Deregister the type of the hook.
* @param hookFn [IN] The function to be deregistered.
*
* @retval None.
* @par Dependency:
* <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_HookUnReg(hookType, hookFn) hookType##_UnRegHook(hookFn)
/**
* Call hook functions.
*/
#define OsHookCall(hookType, ...) hookType##_CallHook(__VA_ARGS__)
#else
#define LOS_HookReg(hookType, hookFn)
#define LOS_HookUnReg(hookType, hookFn)
#define OsHookCall(hookType, ...)
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HOOK_H */
此差异已折叠。
......@@ -359,14 +359,6 @@ extern UINT32 __heap_end;
#define LOSCFG_KERNEL_CPU_MASK ((1 << LOSCFG_KERNEL_CORE_NUM) - 1)
/**
* @ingroup los_trace
* It's the total size of trace buffer. It's in the unit of char
*/
#ifdef LOSCFG_KERNEL_TRACE
#define LOS_TRACE_BUFFER_SIZE (1024 * 512)
#endif
/**
* @ingroup los_config
* Version number
......
......@@ -330,5 +330,13 @@ group("unittest") {
deps += [ "signal:liteos_a_signal_unittest" ]
}
}
if (LOSCFG_USER_TEST_TRACE == true) {
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
deps += [ "trace:liteos_a_trace_unittest_door" ]
}
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
deps += [ "trace:liteos_a_trace_unittest" ]
}
}
}
}
......@@ -74,3 +74,4 @@ LOSCFG_USER_TEST_SYS = true
LOSCFG_USER_TEST_TIME_CLOCK = true
LOSCFG_USER_TEST_TIME_TIMER = true
LOSCFG_USER_TEST_UTIL = true
LOSCFG_USER_TEST_TRACE = false
此差异已折叠。
此差异已折叠。
/*
* 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 "It_test_trace.h"
static UINT32 TestCase(VOID)
{
int fd = open("/dev/trace", O_RDWR);
ICUNIT_GOTO_NOT_EQUAL(fd, -1, errno, EXIT);
ioctl(fd, TRACE_START, NULL);
sleep(1);
ioctl(fd, TRACE_STOP, NULL);
ioctl(fd, TRACE_DUMP, false);
EXIT:
close(fd);
return 0;
}
VOID ItTestTrace001(VOID)
{
TEST_ADD_CASE("IT_TEST_TRACE_001", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册