154568cb3Sopenharmony_ci/* 254568cb3Sopenharmony_ci * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved. 354568cb3Sopenharmony_ci * 454568cb3Sopenharmony_ci * UniProton is licensed under Mulan PSL v2. 554568cb3Sopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2. 654568cb3Sopenharmony_ci * You may obtain a copy of Mulan PSL v2 at: 754568cb3Sopenharmony_ci * http://license.coscl.org.cn/MulanPSL2 854568cb3Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 954568cb3Sopenharmony_ci * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 1054568cb3Sopenharmony_ci * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 1154568cb3Sopenharmony_ci * See the Mulan PSL v2 for more details. 1254568cb3Sopenharmony_ci * Create: 2009-12-22 1354568cb3Sopenharmony_ci * Description: cpup模块的模块内头文件 1454568cb3Sopenharmony_ci */ 1554568cb3Sopenharmony_ci#ifndef PRT_CPUP_THREAD_INTERNAL_H 1654568cb3Sopenharmony_ci#define PRT_CPUP_THREAD_INTERNAL_H 1754568cb3Sopenharmony_ci 1854568cb3Sopenharmony_ci#include "prt_lib_external.h" 1954568cb3Sopenharmony_ci#include "prt_err_external.h" 2054568cb3Sopenharmony_ci#include "prt_sys_external.h" 2154568cb3Sopenharmony_ci#include "prt_cpu_external.h" 2254568cb3Sopenharmony_ci#include "prt_cpup_external.h" 2354568cb3Sopenharmony_ci#include "prt_mem_external.h" 2454568cb3Sopenharmony_ci#include "prt_sys_external.h" 2554568cb3Sopenharmony_ci#include "prt_task_external.h" 2654568cb3Sopenharmony_ci#include "prt_hook_external.h" 2754568cb3Sopenharmony_ci#include "prt_exc_external.h" 2854568cb3Sopenharmony_ci#include "prt_tick_external.h" 2954568cb3Sopenharmony_ci#include "prt_cpup_internal.h" 3054568cb3Sopenharmony_ci 3154568cb3Sopenharmony_ci/* 3254568cb3Sopenharmony_ci * 模块内宏定义 3354568cb3Sopenharmony_ci */ 3454568cb3Sopenharmony_ci#define OS_CPUP_ENTRY_FLAG 0 /* 处理中断进入钩子时需要计算CPUP标志 */ 3554568cb3Sopenharmony_ci#define OS_CPUP_EXIT_FLAG 1 /* 处理中断退出钩子时需要计算CPUP标志 */ 3654568cb3Sopenharmony_ci 3754568cb3Sopenharmony_ci#define OS_CPUP_LOW_VALUE 0xffffffff 3854568cb3Sopenharmony_ci 3954568cb3Sopenharmony_ci#define OS_CPUP_PTR(taskId) (&g_cpup[TSK_GET_INDEX((taskId))]) 4054568cb3Sopenharmony_ci 4154568cb3Sopenharmony_ci#define OS_TASK_CYCLE_START(taskId, curCycle) (OS_CPUP_PTR(taskId)->startTime = (curCycle)) 4254568cb3Sopenharmony_ci 4354568cb3Sopenharmony_ci#define OS_TASK_CYCLE_END(taskId, curCycle) \ 4454568cb3Sopenharmony_ci (OS_CPUP_PTR(taskId)->allTime += ((curCycle) - OS_CPUP_PTR(taskId)->startTime)) 4554568cb3Sopenharmony_ci 4654568cb3Sopenharmony_ci/* 硬中断、Tick钩子是否需要计算CPUP标识 */ 4754568cb3Sopenharmony_ciextern U32 g_cpupFlag; 4854568cb3Sopenharmony_ci#define CPUP_FLAG g_cpupFlag 4954568cb3Sopenharmony_ci 5054568cb3Sopenharmony_ciextern U16 g_cpupDelTask; 5154568cb3Sopenharmony_ciextern U64 g_cpuWinStart; 5254568cb3Sopenharmony_ciextern U64 g_cpuTimeDelTask; 5354568cb3Sopenharmony_ci 5454568cb3Sopenharmony_ci/* 5554568cb3Sopenharmony_ci * 模块内函数声明 5654568cb3Sopenharmony_ci */ 5754568cb3Sopenharmony_ciextern U32 OsCpupThreadNow(void); 5854568cb3Sopenharmony_ciextern void OsCpupThreadTickTask(void); 5954568cb3Sopenharmony_ciextern void OsCpupFirstSwitch(void); 6054568cb3Sopenharmony_ciextern void OsCpupTskSwitch(U32 lastTaskId, U32 nextTaskId); 6154568cb3Sopenharmony_ciextern void OsNowTskCycleStart(void); 6254568cb3Sopenharmony_ciextern void OsNowTskCycleEnd(void); 6354568cb3Sopenharmony_ciextern U32 OsCpupPreCheck(void); 6454568cb3Sopenharmony_ciextern U16 OsCpupIntGet(void); 6554568cb3Sopenharmony_ciextern U64 OsCpupAllTaskTimeGet(void); 6654568cb3Sopenharmony_ciextern void OsCpupStartEnd(U32 lastTaskId, U32 nextTaskId, U64 curCycle); 6754568cb3Sopenharmony_ciextern void OsCpupTickCal(void); 6854568cb3Sopenharmony_ciextern void OsCpupTimeClear(void); 6954568cb3Sopenharmony_ci 7054568cb3Sopenharmony_ciOS_SEC_ALW_INLINE INLINE U64 OsCpupGetWinCycles(U64 curCycle) 7154568cb3Sopenharmony_ci{ 7254568cb3Sopenharmony_ci U64 cycles = curCycle - g_cpuWinStart; 7354568cb3Sopenharmony_ci 7454568cb3Sopenharmony_ci /* 理论上当前cycle必然大于时间窗起始值,如果相等,即认为当前cycle值已翻转,取时间窗大小为最大值 */ 7554568cb3Sopenharmony_ci if (cycles == 0) { 7654568cb3Sopenharmony_ci cycles = (U64)(-1); 7754568cb3Sopenharmony_ci } 7854568cb3Sopenharmony_ci 7954568cb3Sopenharmony_ci return cycles; 8054568cb3Sopenharmony_ci} 8154568cb3Sopenharmony_ci#endif /* PRT_CPUP_THREAD_INTERNAL_H */ 82