• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LOS_TRACE_PRI_H
33 #define _LOS_TRACE_PRI_H
34 
35 #include "los_trace.h"
36 #include "los_task.h"
37 #include "los_debug.h"
38 #include "los_interrupt.h"
39 
40 #ifdef __cplusplus
41 #if __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44 #endif /* __cplusplus */
45 
46 #if (LOSCFG_TRACE_CONTROL_AGENT == 1)
47 #define TRACE_CMD_END_CHAR                  0xD
48 #endif
49 
50 #define TRACE_ERROR                         PRINT_ERR
51 #define TRACE_MODE_OFFLINE                  0
52 #define TRACE_MODE_ONLINE                   1
53 
54 /* just task and hwi were traced */
55 #define TRACE_DEFAULT_MASK                  (TRACE_HWI_FLAG | TRACE_TASK_FLAG)
56 #define TRACE_CTL_MAGIC_NUM                 0xDEADBEEF
57 #define TRACE_BIGLITTLE_WORD                0x12345678
58 #define TRACE_VERSION(MODE)                 (0xFFFFFFFF & (MODE))
59 #define TRACE_MASK_COMBINE(c1, c2, c3, c4)  (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4))
60 
61 #define TRACE_GET_MODE_FLAG(type)           ((type) & 0xFFFFFFF0)
62 
63 #if (LOSCFG_KERNEL_SMP == 1)
64 extern SPIN_LOCK_S g_traceSpin;
65 #define TRACE_LOCK(state)                   LOS_SpinLockSave(&g_traceSpin, &(state))
66 #define TRACE_UNLOCK(state)                 LOS_SpinUnlockRestore(&g_traceSpin, (state))
67 #else
68 #define TRACE_LOCK(state)		    (state) = LOS_IntLock()
69 #define TRACE_UNLOCK(state)     	    LOS_IntRestore(state)
70 #endif
71 
72 typedef VOID (*TRACE_DUMP_HOOK)(BOOL toClient);
73 extern TRACE_DUMP_HOOK g_traceDumpHook;
74 
75 enum TraceCmd {
76     TRACE_CMD_START = 1,
77     TRACE_CMD_STOP,
78     TRACE_CMD_SET_EVENT_MASK,
79     TRACE_CMD_RECODE_DUMP,
80     TRACE_CMD_MAX_CODE,
81 };
82 
83 /**
84  * @ingroup los_trace
85  * struct to store the trace cmd from traceClient.
86  */
87 typedef struct {
88     UINT8 cmd;
89     UINT8 param1;
90     UINT8 param2;
91     UINT8 param3;
92     UINT8 param4;
93     UINT8 param5;
94     UINT8 end;
95 } TraceClientCmd;
96 
97 /**
98  * @ingroup los_trace
99  * struct to store the event information
100  */
101 typedef struct {
102     UINT32 cmd;     /* trace start or stop cmd */
103     UINT32 param;   /* magic numb stand for notify msg */
104 } TraceNotifyFrame;
105 
106 /**
107  * @ingroup los_trace
108  * struct to store the trace config information.
109  */
110 typedef struct {
111     struct WriteCtrl {
112         UINT16 curIndex;            /* The current record index */
113         UINT16 maxRecordCount;      /* The max num of track items */
114         UINT16 curObjIndex;         /* The current obj index */
115         UINT16 maxObjCount;         /* The max num of obj index */
116         ObjData *objBuf;            /* Pointer to obj info data */
117         TraceEventFrame *frameBuf;  /* Pointer to the track items */
118     } ctrl;
119     OfflineHead *head;
120 } TraceOfflineHeaderInfo;
121 
122 extern UINT32 OsTraceInit(VOID);
123 extern UINT32 OsTraceGetMaskTid(UINT32 taskId);
124 extern VOID OsTraceSetObj(ObjData *obj, const LosTaskCB *tcb);
125 extern VOID OsTraceWriteOrSendEvent(const TraceEventFrame *frame);
126 extern VOID OsTraceObjAdd(UINT32 eventType, UINT32 taskId);
127 extern BOOL OsTraceIsEnable(VOID);
128 extern OfflineHead *OsTraceRecordGet(VOID);
129 
130 #if (LOSCFG_RECORDER_MODE_ONLINE == 1)
131 extern VOID OsTraceSendHead(VOID);
132 extern VOID OsTraceSendObjTable(VOID);
133 extern VOID OsTraceSendNotify(UINT32 type, UINT32 value);
134 
135 #define OsTraceNotifyStart() do {                                \
136         OsTraceSendNotify(SYS_START, TRACE_CTL_MAGIC_NUM);       \
137         OsTraceSendHead();                                       \
138         OsTraceSendObjTable();                                   \
139     } while (0)
140 
141 #define OsTraceNotifyStop() do {                                 \
142         OsTraceSendNotify(SYS_STOP, TRACE_CTL_MAGIC_NUM);        \
143     } while (0)
144 
145 #define OsTraceReset()
146 #define OsTraceRecordDump(toClient)
147 #else
148 extern UINT32 OsTraceBufInit(UINT32 size);
149 extern VOID OsTraceReset(VOID);
150 extern VOID OsTraceRecordDump(BOOL toClient);
151 #define OsTraceNotifyStart()
152 #define OsTraceNotifyStop()
153 #endif
154 
155 #if (LOSCFG_SHELL == 1)
156 extern UINT32 OsShellCmdTraceSetMask(INT32 argc, const CHAR **argv);
157 extern UINT32 OsShellCmdTraceDump(INT32 argc, const CHAR **argv);
158 #endif
159 
160 #ifdef __cplusplus
161 #if __cplusplus
162 }
163 #endif /* __cplusplus */
164 #endif /* __cplusplus */
165 
166 #endif /* _LOS_TRACE_PRI_H */
167