• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: CPU占用率模块的C文件
14  */
15 #include "prt_cpup_internal.h"
16 #include "prt_cpup_thread_internal.h"
17 
18 /* 数据定义放到XXX.c中是为了解决SAI报Data Module */
19 #if defined(OS_OPTION_CPUP_WARN)
20 /* CPUP告警检测函数钩子 */
21 OS_SEC_BSS CpupWarnFunc g_cpupWarnCheck;
22 #endif
23 
24 OS_SEC_BSS CpupNowFunc g_cpupNow;
25 /* 系统级CPUP一个计算周期的的tick数 */
26 OS_SEC_BSS U32 g_ticksPerSample;
27 /* 当前系统级CPUP计数 */
28 OS_SEC_BSS U32 g_cpupIndex;
29 /* 线程级CPU占用率结构体指针 */
30 OS_SEC_BSS struct TagCpupThread *g_cpup;
31 
32 /* 一个采样周期内,当前Tick计数值 */
33 OS_SEC_BSS U32 g_tickCount;
34 /* CPU占用率采样周期值 */
35 OS_SEC_BSS U64 g_baseValue;
36 
OsCpupRegister(struct CpupModInfo * modInfo)37 OS_SEC_L4_TEXT U32 OsCpupRegister(struct CpupModInfo *modInfo)
38 {
39     U32 ret;
40 
41     ret = OsCpupReg(modInfo);
42     if (ret != OS_OK) {
43         return ret;
44     }
45 
46 #if defined(OS_OPTION_CPUP_WARN)
47     if (modInfo->cpupWarnFlag == TRUE) {
48         ret = OsCpupWarnReg(modInfo);
49         if (ret != OS_OK) {
50             return ret;
51         }
52     }
53 #endif
54 
55     return OS_OK;
56 }
57 
58 /*
59  * 描述:模块间接口,获取CPUP是否已经初始化。
60  */
OsCpupInitIsDone(void)61 OS_SEC_L4_TEXT bool OsCpupInitIsDone(void)
62 {
63     if (g_cpupNow == NULL) {
64         return FALSE;
65     }
66     return TRUE;
67 }
68 
69 /*
70  * 描述:根据g_cpupThreadInitFlag判断是否已经初始化CPUP模块如果没有,则进行初始化
71  */
OsCpupLazyInit(void)72 OS_SEC_L2_TEXT U32 OsCpupLazyInit(void)
73 {
74     if (g_cpupNow == NULL) {
75         return OS_ERRNO_CPUP_NOT_INITED;
76     }
77     return OS_OK;
78 }
79