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 _PERF_PMU_PRI_H 33 #define _PERF_PMU_PRI_H 34 35 #include "los_perf_pri.h" 36 37 #ifdef LOSCFG_HRTIMER_ENABLE 38 #include "linux/hrtimer.h" 39 #endif 40 41 #ifdef __cplusplus 42 #if __cplusplus 43 extern "C" { 44 #endif /* __cplusplus */ 45 #endif /* __cplusplus */ 46 47 typedef struct { 48 Pmu pmu; 49 BOOL canDivided; 50 UINT32 cntDivided; 51 VOID (*enable)(Event *event); 52 VOID (*disable)(Event *event); 53 VOID (*start)(VOID); 54 VOID (*stop)(VOID); 55 VOID (*clear)(VOID); 56 VOID (*setPeriod)(Event *event); 57 UINTPTR (*readCnt)(Event *event); 58 UINT32 (*mapEvent)(UINT32 eventType, BOOL reverse); 59 } HwPmu; 60 61 typedef struct { 62 Pmu pmu; 63 union { 64 struct { /* trace event */ 65 BOOL enable; 66 }; 67 #ifdef LOSCFG_HRTIMER_ENABLE 68 struct { /* timer event */ 69 struct hrtimer hrtimer; 70 union ktime time; 71 union ktime cfgTime; 72 }; 73 #endif 74 }; 75 } SwPmu; 76 77 #define GET_HW_PMU(item) LOS_DL_LIST_ENTRY(item, HwPmu, pmu) 78 79 #define TIMER_PERIOD_LOWER_BOUND_US 100 80 81 #define CCNT_FULL 0xFFFFFFFF 82 #define CCNT_PERIOD_LOWER_BOUND 0x00000000 83 #define CCNT_PERIOD_UPPER_BOUND 0xFFFFFF00 84 #define PERIOD_CALC(p) (CCNT_FULL - (p)) 85 #define VALID_PERIOD(p) ((PERIOD_CALC(p) > CCNT_PERIOD_LOWER_BOUND) \ 86 && (PERIOD_CALC(p) < CCNT_PERIOD_UPPER_BOUND)) 87 88 #define PERF_HW_INVALID_EVENT_TYPE 0xFFFFFFFF 89 90 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) 91 92 #define PMU_LABEL_INT_1 \ 93 NUM_HAL_INTERRUPT_PMU_0, 94 #define PMU_LABEL_INT_2 \ 95 PMU_LABEL_INT_1 \ 96 NUM_HAL_INTERRUPT_PMU_1, 97 #define PMU_LABEL_INT_3 \ 98 PMU_LABEL_INT_2 \ 99 NUM_HAL_INTERRUPT_PMU_2, 100 #define PMU_LABEL_INT_4 \ 101 PMU_LABEL_INT_3 \ 102 NUM_HAL_INTERRUPT_PMU_3, 103 104 #define PMU_INT(_num) PMU_LABEL_INT_##_num 105 106 #define OS_PMU_INTS(_num, _list) \ 107 STATIC UINT32 _list[_num] = { \ 108 PMU_INT(_num) \ 109 } 110 111 extern UINT32 OsPerfPmuRegister(Pmu *pmu); 112 extern VOID OsPerfPmuRm(UINT32 type); 113 extern Pmu *OsPerfPmuGet(UINT32 type); 114 115 extern UINT32 OsHwPmuInit(VOID); 116 extern UINT32 OsSwPmuInit(VOID); 117 extern UINT32 OsTimedPmuInit(VOID); 118 119 extern UINT32 OsGetPmuCounter0(VOID); 120 extern UINT32 OsGetPmuMaxCounter(VOID); 121 extern UINT32 OsGetPmuCycleCounter(VOID); 122 extern UINT32 OsPerfHwInit(HwPmu *hwPmu); 123 124 #ifdef __cplusplus 125 #if __cplusplus 126 } 127 #endif /* __cplusplus */ 128 #endif /* __cplusplus */ 129 130 #endif /* _PERF_PMU_PRI_H */ 131