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: cpu占用率模块的内部公共头文件 1454568cb3Sopenharmony_ci */ 1554568cb3Sopenharmony_ci#ifndef PRT_CPUP_EXTERNAL_H 1654568cb3Sopenharmony_ci#define PRT_CPUP_EXTERNAL_H 1754568cb3Sopenharmony_ci 1854568cb3Sopenharmony_ci#include "prt_cpup.h" 1954568cb3Sopenharmony_ci 2054568cb3Sopenharmony_ci/* 2154568cb3Sopenharmony_ci * 设置cpu占用率的注册信息结构体。 2254568cb3Sopenharmony_ci */ 2354568cb3Sopenharmony_cistruct TagOsCpupWarnInfo { 2454568cb3Sopenharmony_ci /* CPU占用率告警阈值 */ 2554568cb3Sopenharmony_ci U32 warn; 2654568cb3Sopenharmony_ci /* CPU占用率告警恢复阈值 */ 2754568cb3Sopenharmony_ci U32 resume; 2854568cb3Sopenharmony_ci}; 2954568cb3Sopenharmony_ci 3054568cb3Sopenharmony_ci/* 3154568cb3Sopenharmony_ci * 线程级CPU占用率结构体 3254568cb3Sopenharmony_ci */ 3354568cb3Sopenharmony_cistruct TagCpupThread { 3454568cb3Sopenharmony_ci /* 运行总时间记录 */ 3554568cb3Sopenharmony_ci U64 allTime; 3654568cb3Sopenharmony_ci /* 调用前时间记录 */ 3754568cb3Sopenharmony_ci U64 startTime; 3854568cb3Sopenharmony_ci /* CPU占用率 */ 3954568cb3Sopenharmony_ci U16 usage; 4054568cb3Sopenharmony_ci /* 保留 */ 4154568cb3Sopenharmony_ci U16 reserve; 4254568cb3Sopenharmony_ci /* 保留,64位对齐(R8 cacheline)> */ 4354568cb3Sopenharmony_ci U32 reserve2; 4454568cb3Sopenharmony_ci}; 4554568cb3Sopenharmony_ci 4654568cb3Sopenharmony_ci#define OS_CPUP_INT_ID 0xffffffff /* 中断线程ID */ 4754568cb3Sopenharmony_ci#define CPUP_USE_RATE 10000 /* CPUP使用比率 10000:万分比 1000:千分比 100:百分比 */ 4854568cb3Sopenharmony_ci 4954568cb3Sopenharmony_citypedef void (*CpupWarnFunc)(void); 5054568cb3Sopenharmony_citypedef U32(*CpupNowFunc)(void); 5154568cb3Sopenharmony_citypedef void (*CpupCoreSleepFunc)(void); 5254568cb3Sopenharmony_ci 5354568cb3Sopenharmony_ciextern struct TagOsCpupWarnInfo g_cpupWarnInfo; 5454568cb3Sopenharmony_ciextern struct TagCpupThread *g_cpup; 5554568cb3Sopenharmony_ciextern U16 g_sysUsage; 5654568cb3Sopenharmony_ci 5754568cb3Sopenharmony_ciextern bool OsCpupInitIsDone(void); 5854568cb3Sopenharmony_ciextern U32 OsCpupLazyInit(void); 5954568cb3Sopenharmony_ci 6054568cb3Sopenharmony_ci/* 核休眠钩子函数 */ 6154568cb3Sopenharmony_ciextern volatile CpupCoreSleepFunc g_cpupCoreSleep; 6254568cb3Sopenharmony_ci 6354568cb3Sopenharmony_ci#if defined(OS_OPTION_CPUP) 6454568cb3Sopenharmony_ci/* CPUP核休眠钩子注册 */ 6554568cb3Sopenharmony_ci#define OS_CPUP_CORE_SLEEP_HOOK_SET(handle) \ 6654568cb3Sopenharmony_ci do { \ 6754568cb3Sopenharmony_ci if (OsCpupInitIsDone()) { \ 6854568cb3Sopenharmony_ci g_cpupCoreSleep = (handle); \ 6954568cb3Sopenharmony_ci } \ 7054568cb3Sopenharmony_ci } while (0) 7154568cb3Sopenharmony_ci#else 7254568cb3Sopenharmony_ci#define OS_CPUP_CORE_SLEEP_HOOK_SET(handle) 7354568cb3Sopenharmony_ci#endif 7454568cb3Sopenharmony_ci 7554568cb3Sopenharmony_ci#endif /* PRT_CPUP_EXTERNAL_H */ 76