更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_perf_pri.h
浏览该文件的文档.
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_PERF_PRI_H
33#define _LOS_PERF_PRI_H
34
35#include "los_perf.h"
36#include "perf.h"
37#include "los_mp.h"
38#include "los_task_pri.h"
39#include "los_exc_pri.h"
40
41#ifdef __cplusplus
42#if __cplusplus
43extern "C" {
44#endif /* __cplusplus */
45#endif /* __cplusplus */
46
47#define PERF_EVENT_TO_CODE 0
48#define PERF_CODE_TO_EVENT 1
49#define PERF_DATA_MAGIC_WORD 0xEFEFEF00
50
51#define SMP_CALL_PERF_FUNC(func) OsMpFuncCall(OS_MP_CPU_ALL, (SMP_FUNC_CALL)func, NULL)
52
56};
57
58typedef struct {
61} PerfRegs;
62
63typedef struct {
65 IpInfo ip[PERF_MAX_CALLCHAIN_DEPTH];
67
68typedef struct {
69 UINT32 cpuid; /* cpu id */
70 UINT32 taskId; /* task id */
71 UINT32 processId; /* process id */
72 UINT32 eventId; /* record type */
73 UINT32 period; /* record period */
74 UINT64 time; /* record time */
75 IpInfo pc; /* instruction pointer */
76 PerfBackTrace callChain; /* number of callChain ips */
78
79typedef struct {
80 UINT32 magic; /* magic number */
81 UINT32 eventType; /* enum PerfEventType */
82 UINT32 len; /* sample data file length */
83 UINT32 sampleType; /* IP | TID | TIMESTAMP... */
84 UINT32 sectionId; /* section id */
86
87typedef struct {
91 UINT64 count[LOSCFG_KERNEL_CORE_NUM];
92} Event;
93
94typedef struct {
95 Event per[PERF_MAX_EVENT];
98} PerfEvent;
99
100typedef struct {
103 UINT32 (*config)(VOID);
104 UINT32 (*start)(VOID);
105 UINT32 (*stop)(VOID);
106 CHAR *(*getName)(Event *event);
107} Pmu;
108
109typedef struct {
110 /* time info */
113
114 /* instrumentation status */
116 enum PmuStatus pmuStatusPerCpu[LOSCFG_KERNEL_CORE_NUM];
117
118 /* configuration info */
120 UINT32 taskIds[PERF_MAX_FILTER_TSKS];
122 UINT32 processIds[PERF_MAX_FILTER_TSKS];
125} PerfCB;
126
127#ifndef OsPerfArchFetchIrqRegs
128STATIC INLINE VOID OsPerfArchFetchIrqRegs(PerfRegs *regs, LosTaskCB *curTask) {}
129#endif
130
131STATIC INLINE VOID OsPerfFetchIrqRegs(PerfRegs *regs)
132{
133 LosTaskCB *curTask = OsCurrTaskGet();
134 OsPerfArchFetchIrqRegs(regs, curTask);
135 PRINT_DEBUG("pc = 0x%x, fp = 0x%x\n", regs->pc, regs->fp);
136}
137
138#ifndef OsPerfArchFetchCallerRegs
139STATIC INLINE VOID OsPerfArchFetchCallerRegs(PerfRegs *regs) {}
140#endif
141
142STATIC INLINE VOID OsPerfFetchCallerRegs(PerfRegs *regs)
143{
145 PRINT_DEBUG("pc = 0x%x, fp = 0x%x\n", regs->pc, regs->fp);
146}
147
148extern VOID OsPerfSetIrqRegs(UINTPTR pc, UINTPTR fp);
149extern VOID OsPerfUpdateEventCount(Event *event, UINT32 value);
150extern VOID OsPerfHandleOverFlow(Event *event, PerfRegs *regs);
151
152#ifdef __cplusplus
153#if __cplusplus
154}
155#endif /* __cplusplus */
156#endif /* __cplusplus */
157
158#endif /* _LOS_PERF_PRI_H */
PerfEventType
Definition: perf.h:56
PerfStatus
Definition: los_perf.h:76
PmuStatus
Definition: los_perf_pri.h:53
@ PERF_PMU_STOPED
Definition: los_perf_pri.h:54
@ PERF_PMU_STARTED
Definition: los_perf_pri.h:55
STATIC INLINE VOID OsPerfFetchIrqRegs(PerfRegs *regs)
Definition: los_perf_pri.h:131
STATIC INLINE VOID OsPerfFetchCallerRegs(PerfRegs *regs)
Definition: los_perf_pri.h:142
VOID OsPerfHandleOverFlow(Event *event, PerfRegs *regs)
Definition: los_perf.c:350
VOID OsPerfUpdateEventCount(Event *event, UINT32 value)
Definition: los_perf.c:342
STATIC INLINE VOID OsPerfArchFetchCallerRegs(PerfRegs *regs)
Definition: los_perf_pri.h:139
VOID OsPerfSetIrqRegs(UINTPTR pc, UINTPTR fp)
Definition: los_perf.c:537
STATIC INLINE VOID OsPerfArchFetchIrqRegs(PerfRegs *regs, LosTaskCB *curTask)
Definition: los_perf_pri.h:128
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned char UINT8
Definition: los_typedef.h:55
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
UINT32 counter
Definition: los_perf_pri.h:88
UINT32 period
Definition: los_perf_pri.h:90
UINT32 eventId
Definition: los_perf_pri.h:89
UINT8 taskIdsNr
Definition: los_perf_pri.h:121
enum PerfStatus status
Definition: los_perf_pri.h:115
UINT64 endTime
Definition: los_perf_pri.h:112
UINT64 startTime
Definition: los_perf_pri.h:111
UINT8 processIdsNr
Definition: los_perf_pri.h:123
UINT32 sampleType
Definition: los_perf_pri.h:119
UINT8 needSample
Definition: los_perf_pri.h:124
UINT32 len
Definition: los_perf_pri.h:82
UINT32 sampleType
Definition: los_perf_pri.h:83
UINT32 eventType
Definition: los_perf_pri.h:81
UINT32 magic
Definition: los_perf_pri.h:80
UINT32 sectionId
Definition: los_perf_pri.h:84
UINT8 nr
Definition: los_perf_pri.h:96
UINT8 cntDivided
Definition: los_perf_pri.h:97
UINTPTR fp
Definition: los_perf_pri.h:60
UINTPTR pc
Definition: los_perf_pri.h:59
PerfBackTrace callChain
Definition: los_perf_pri.h:76
UINT32 processId
Definition: los_perf_pri.h:71
PerfEvent events
Definition: los_perf_pri.h:102
enum PerfEventType type
Definition: los_perf_pri.h:101