1 /*
2 * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3 *
4 * UniProton is licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 * http://license.coscl.org.cn/MulanPSL2
8 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11 * See the Mulan PSL v2 for more details.
12 * Create: 2009-12-22
13 * Description: cpup模块的模块内头文件
14 */
15 #ifndef PRT_CPUP_THREAD_INTERNAL_H
16 #define PRT_CPUP_THREAD_INTERNAL_H
17
18 #include "prt_lib_external.h"
19 #include "prt_err_external.h"
20 #include "prt_sys_external.h"
21 #include "prt_cpu_external.h"
22 #include "prt_cpup_external.h"
23 #include "prt_mem_external.h"
24 #include "prt_sys_external.h"
25 #include "prt_task_external.h"
26 #include "prt_hook_external.h"
27 #include "prt_exc_external.h"
28 #include "prt_tick_external.h"
29 #include "prt_cpup_internal.h"
30
31 /*
32 * 模块内宏定义
33 */
34 #define OS_CPUP_ENTRY_FLAG 0 /* 处理中断进入钩子时需要计算CPUP标志 */
35 #define OS_CPUP_EXIT_FLAG 1 /* 处理中断退出钩子时需要计算CPUP标志 */
36
37 #define OS_CPUP_LOW_VALUE 0xffffffff
38
39 #define OS_CPUP_PTR(taskId) (&g_cpup[TSK_GET_INDEX((taskId))])
40
41 #define OS_TASK_CYCLE_START(taskId, curCycle) (OS_CPUP_PTR(taskId)->startTime = (curCycle))
42
43 #define OS_TASK_CYCLE_END(taskId, curCycle) \
44 (OS_CPUP_PTR(taskId)->allTime += ((curCycle) - OS_CPUP_PTR(taskId)->startTime))
45
46 /* 硬中断、Tick钩子是否需要计算CPUP标识 */
47 extern U32 g_cpupFlag;
48 #define CPUP_FLAG g_cpupFlag
49
50 extern U16 g_cpupDelTask;
51 extern U64 g_cpuWinStart;
52 extern U64 g_cpuTimeDelTask;
53
54 /*
55 * 模块内函数声明
56 */
57 extern U32 OsCpupThreadNow(void);
58 extern void OsCpupThreadTickTask(void);
59 extern void OsCpupFirstSwitch(void);
60 extern void OsCpupTskSwitch(U32 lastTaskId, U32 nextTaskId);
61 extern void OsNowTskCycleStart(void);
62 extern void OsNowTskCycleEnd(void);
63 extern U32 OsCpupPreCheck(void);
64 extern U16 OsCpupIntGet(void);
65 extern U64 OsCpupAllTaskTimeGet(void);
66 extern void OsCpupStartEnd(U32 lastTaskId, U32 nextTaskId, U64 curCycle);
67 extern void OsCpupTickCal(void);
68 extern void OsCpupTimeClear(void);
69
OsCpupGetWinCycles(U64 curCycle)70 OS_SEC_ALW_INLINE INLINE U64 OsCpupGetWinCycles(U64 curCycle)
71 {
72 U64 cycles = curCycle - g_cpuWinStart;
73
74 /* 理论上当前cycle必然大于时间窗起始值,如果相等,即认为当前cycle值已翻转,取时间窗大小为最大值 */
75 if (cycles == 0) {
76 cycles = (U64)(-1);
77 }
78
79 return cycles;
80 }
81 #endif /* PRT_CPUP_THREAD_INTERNAL_H */
82