更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_cpup.c 文件参考

http://weharmonyos.com/openharmony/zh-cn/device-dev/kernel/kernel-small-debug-process-cpu.html 更多...

浏览源代码.

函数

STATIC UINT64 OsGetCpuCycle (VOID)
 
LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard (VOID)
 
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupGuardCreator (VOID)
 创建cpu使用统计定时器 更多...
 
 LOS_MODULE_INIT (OsCpupGuardCreator, LOS_INIT_LEVEL_KMOD_TASK)
 
LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit (VOID)
 
 LOS_MODULE_INIT (OsCpupInit, LOS_INIT_LEVEL_KMOD_EXTENDED)
 
STATIC VOID OsResetCpup (OsCpupBase *cpup, UINT64 cycle)
 
LITE_OS_SEC_TEXT_INIT VOID LOS_CpupReset (VOID)
 Reset the data of CPU usage. 更多...
 
VOID OsCpupCycleEndStart (UINT32 runTaskID, UINT32 newTaskID)
 
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos (UINT16 mode, UINT16 *curPosPointer, UINT16 *prePosPointer)
 
STATIC INLINE UINT32 OsCalculateCpupUsage (const OsCpupBase *cpup, UINT16 pos, UINT16 prePos, UINT64 allCycle)
 
STATIC UINT32 OsHistorySysCpuUsageUnsafe (UINT16 mode)
 
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistorySysCpuUsage (UINT16 mode)
 获取系统历史CPU占用率 指周期时间内系统的CPU占用率,用于表示系统一段时间内的闲忙程度,也表示CPU的负载情况。系统CPU 占用率的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示系统满负荷运转。 更多...
 
STATIC UINT32 OsHistoryProcessCpuUsageUnsafe (UINT32 pid, UINT16 mode)
 
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryProcessCpuUsage (UINT32 pid, UINT16 mode)
 获取指定进程历史CPU占用率 指单个进程的CPU占用率,用于表示单个进程在一段时间内的闲忙程度。进程CPU占用率的有效表示范围为0~100, 其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该进程。 更多...
 
STATIC UINT32 OsHistoryTaskCpuUsageUnsafe (UINT32 tid, UINT16 mode)
 
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryTaskCpuUsage (UINT32 tid, UINT16 mode)
 获取指定任务历史CPU占用率 指单个任务的CPU占用率,用于表示单个任务在一段时间内的闲忙程度。任务CPU占用率的有效表示范围为0~100, 其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该任务。 更多...
 
STATIC UINT32 OsCpupUsageParamCheckAndReset (CPUP_INFO_S *cpupInfo, UINT32 len, UINT32 number)
 
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessCpuUsageUnsafe (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllProcessCpuUsage (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 获取系统所有进程的历史CPU占用率 更多...
 
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart (UINT16 cpuid)
 
LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd (UINT16 cpuid, UINT32 intNum)
 
LITE_OS_SEC_TEXT_MINOR OsIrqCpupCBOsGetIrqCpupArrayBase (VOID)
 
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllIrqCpuUsageUnsafe (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_GetAllIrqCpuUsage (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 获取系统所有中断的历史CPU占用率 指单个中断的CPU占用率,用于表示单个中断在一段时间内的闲忙程度。中断CPU占用率的有效表示范围为0~100, 其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该中断。 更多...
 

变量

LITE_OS_SEC_BSS STATIC UINT16 cpupSwtmrID
 监测CPU使用情况定时器s 更多...
 
LITE_OS_SEC_BSS STATIC UINT16 cpupInitFlg = 0
 
LITE_OS_SEC_BSS OsIrqCpupCBg_irqCpup = NULL
 
LITE_OS_SEC_BSS STATIC UINT32 cpupMaxNum
 
LITE_OS_SEC_BSS STATIC UINT16 cpupHisPos = 0
 
LITE_OS_SEC_BSS STATIC UINT64 cpuHistoryTime [OS_CPUP_HISTORY_RECORD_NUM+1]
 
LITE_OS_SEC_BSS STATIC UINT32 runningTasks [LOSCFG_KERNEL_CORE_NUM]
 
LITE_OS_SEC_BSS STATIC UINT64 cpupStartCycles = 0
 记录 更多...
 
LITE_OS_SEC_BSS UINT64 timeInIrqSwitch [LOSCFG_KERNEL_CORE_NUM]
 
LITE_OS_SEC_BSS STATIC UINT64 cpupIntTimeStart [LOSCFG_KERNEL_CORE_NUM]
 

详细描述

http://weharmonyos.com/openharmony/zh-cn/device-dev/kernel/kernel-small-debug-process-cpu.html

基本概念
    CPU(中央处理器,Central Processing Unit)占用率分为系统CPU占用率、进程CPU占用率、任务CPU占用率
    和中断CPU占用率。用户通过系统级的CPU占用率,判断当前系统负载是否超出设计规格。通过系统中各个
    进程/任务/中断的CPU占用情况,判断各个进程/任务/中断的CPU占用率是否符合设计的预期。
    
       系统CPU占用率(CPU Percent)

       指周期时间内系统的CPU占用率,用于表示系统一段时间内的闲忙程度,也表示CPU的负载情况。系统CPU占用率
       的有效表示范围为0~100,其精度(可通过配置调整)为百分比。100表示系统满负荷运转。
    
       进程CPU占用率
       
       指单个进程的CPU占用率,用于表示单个进程在一段时间内的闲忙程度。进程CPU占用率的有效表示范围为0~100,
       其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该进程。
       
       任务CPU占用率
       
       指单个任务的CPU占用率,用于表示单个任务在一段时间内的闲忙程度。任务CPU占用率的有效表示范围为0~100,
       其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该任务。
       
       中断CPU占用率
       
       指单个中断的CPU占用率,用于表示单个中断在一段时间内的闲忙程度。中断CPU占用率的有效表示范围为0~100,
       其精度(可通过配置调整)为百分比。100表示在一段时间内系统一直在运行该中断。

运行机制
    OpenHarmony LiteOS-A内核CPUP(CPU Percent,CPU占用率)模块采用进程、任务和中断级记录的方式,在进程/任务切换时,
    记录进程/任务启动时间,进程/任务切出或者退出时,系统会累加整个进程/任务的占用时间; 在执行中断时系统会累加记录
    每个中断的执行时间。
    
    OpenHarmony 提供以下四种CPU占用率的信息查询:
    
       系统CPU占用率
       进程CPU占用率
       任务CPU占用率
       中断CPU占用率
       
    CPU占用率的计算方法:
    
    系统CPU占用率=系统中除idle任务外其他任务运行总时间/系统运行总时间
    
    进程CPU占用率=进程运行总时间/系统运行总时间
    
    任务CPU占用率=任务运行总时间/系统运行总时间
    
    中断CPU占用率=中断运行总时间/系统运行总时间
    
开发流程
    CPU占用率的典型开发流程:
    
    调用获取系统历史CPU占用率函数LOS_HistorySysCpuUsage。
    
    调用获取指定进程历史CPU占用率函数LOS_HistoryProcessCpuUsage。
    
    若进程已创建,则关中断,根据不同模式正常获取,恢复中断;
    若进程未创建,则返回错误码;
    调用获取所有进程CPU占用率函数LOS_GetAllProcessCpuUsage。
    
    若CPUP已初始化,则关中断,根据不同模式正常获取,恢复中断;
    若CPUP未初始化或有非法入参,则返回错误码;
    调用获取指定任务历史CPU占用率函数LOS_HistoryTaskCpuUsage。
    
    若任务已创建,则关中断,根据不同模式正常获取,恢复中断;
    若任务未创建,则返回错误码;
    调用获取所有中断CPU占用率函数LOS_GetAllIrqCpuUsage。
    
    若CPUP已初始化,则关中断,根据不同模式正常获取,恢复中断;
    若CPUP未初始化或有非法入参,则返回错误码;
注意

版本
作者
weharmonyos.com | 鸿蒙研究站 | 每天死磕一点点
日期
2021-11-21

在文件 los_cpup.c 中定义.

函数说明

◆ LOS_MODULE_INIT() [1/2]

LOS_MODULE_INIT ( OsCpupGuardCreator  ,
LOS_INIT_LEVEL_KMOD_TASK   
)

◆ LOS_MODULE_INIT() [2/2]

LOS_MODULE_INIT ( OsCpupInit  ,
LOS_INIT_LEVEL_KMOD_EXTENDED   
)

◆ OsCalculateCpupUsage()

STATIC INLINE UINT32 OsCalculateCpupUsage ( const OsCpupBase cpup,
UINT16  pos,
UINT16  prePos,
UINT64  allCycle 
)

在文件 los_cpup.c396 行定义.

397{
398 UINT32 usage = 0;
399 UINT64 cpuCycle = cpup->historyTime[pos] - cpup->historyTime[prePos];
400
401 if (allCycle) {
402 usage = (UINT32)((LOS_CPUP_SINGLE_CORE_PRECISION * cpuCycle) / allCycle);
403 }
404 return usage;
405}
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned int UINT32
Definition: los_typedef.h:57
UINT64 historyTime[OS_CPUP_HISTORY_RECORD_NUM+1]
Definition: los_cpup_pri.h:52
这是这个函数的调用关系图:

◆ OsCpupCycleEndStart()

VOID OsCpupCycleEndStart ( UINT32  runTaskID,
UINT32  newTaskID 
)

在文件 los_cpup.c331 行定义.

332{
333 /* OsCurrTaskGet and OsCurrProcessGet are not allowed to be called. */
334 LosTaskCB *runTask = OS_TCB_FROM_TID(runTaskID);
335 OsCpupBase *runTaskCpup = &runTask->taskCpup;
336 OsCpupBase *newTaskCpup = (OsCpupBase *)&(OS_TCB_FROM_TID(newTaskID)->taskCpup);
337 OsCpupBase *processCpup = OS_PCB_FROM_PID(runTask->processID)->processCpup;
338 UINT64 cpuCycle, cycleIncrement;
339 UINT16 cpuid = ArchCurrCpuid();
340
341 if (cpupInitFlg == 0) {
342 return;
343 }
344
345 cpuCycle = OsGetCpuCycle();
346 if (runTaskCpup->startTime != 0) {
347 cycleIncrement = cpuCycle - runTaskCpup->startTime;
348#ifdef LOSCFG_CPUP_INCLUDE_IRQ
349 cycleIncrement -= timeInIrqSwitch[cpuid];
350 timeInIrqSwitch[cpuid] = 0;
351#endif
352 runTaskCpup->allTime += cycleIncrement;
353 if (processCpup != NULL) {
354 processCpup->allTime += cycleIncrement;
355 }
356 runTaskCpup->startTime = 0;
357 }
358
359 newTaskCpup->startTime = cpuCycle;
360 runningTasks[cpuid] = newTaskID;
361}
STATIC UINT64 OsGetCpuCycle(VOID)
Definition: los_cpup.c:145
LITE_OS_SEC_BSS STATIC UINT16 cpupInitFlg
Definition: los_cpup.c:124
LITE_OS_SEC_BSS STATIC UINT32 runningTasks[LOSCFG_KERNEL_CORE_NUM]
Definition: los_cpup.c:129
LITE_OS_SEC_BSS UINT64 timeInIrqSwitch[LOSCFG_KERNEL_CORE_NUM]
Definition: los_cpup.c:132
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
Definition: los_hw_cpu.h:168
unsigned short UINT16
Definition: los_typedef.h:56
UINT64 allTime
Definition: los_cpup_pri.h:50
UINT64 startTime
Definition: los_cpup_pri.h:51
OsCpupBase taskCpup
UINT32 processID
函数调用图:
这是这个函数的调用关系图:

◆ OsCpupGetPos()

LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos ( UINT16  mode,
UINT16 curPosPointer,
UINT16 prePosPointer 
)

在文件 los_cpup.c363 行定义.

364{
365 UINT16 curPos;
366 UINT16 tmpPos;
367 UINT16 prePos;
368
369 tmpPos = cpupHisPos;
370 curPos = CPUP_PRE_POS(tmpPos);
371
372 /*
373 * The current postion has nothing to do with the CPUP modes,
374 * however, the previous postion differs.
375 */
376 switch (mode) {
378 prePos = CPUP_PRE_POS(curPos);
379 break;
381 prePos = tmpPos;
382 break;
383 case CPUP_ALL_TIME:
384 /* fall-through */
385 default:
386 prePos = OS_CPUP_HISTORY_RECORD_NUM;
387 break;
388 }
389
390 *curPosPointer = curPos;
391 *prePosPointer = prePos;
392
393 return;
394}
@ CPUP_LAST_TEN_SECONDS
Definition: los_cpup.h:132
@ CPUP_ALL_TIME
Definition: los_cpup.h:134
@ CPUP_LAST_ONE_SECONDS
Definition: los_cpup.h:133
LITE_OS_SEC_BSS STATIC UINT16 cpupHisPos
Definition: los_cpup.c:127
这是这个函数的调用关系图:

◆ OsCpupGuard()

LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard ( VOID  )

在文件 los_cpup.c166 行定义.

167{
168 UINT16 prevPos;
169 UINT32 loop;
170 UINT32 runTaskID;
171 UINT32 intSave;
172 UINT64 cycle, cycleIncrement;
173 LosTaskCB *taskCB = NULL;
174 LosProcessCB *processCB = NULL;
175
176 SCHEDULER_LOCK(intSave);
177
178 cycle = OsGetCpuCycle();
179 prevPos = cpupHisPos;
180 cpupHisPos = CPUP_POST_POS(cpupHisPos);
181 cpuHistoryTime[prevPos] = cycle;
182
183#ifdef LOSCFG_CPUP_INCLUDE_IRQ
184 for (loop = 0; loop < cpupMaxNum; loop++) {
185 if (g_irqCpup[loop].status == OS_CPUP_UNUSED) {
186 continue;
187 }
188 g_irqCpup[loop].cpup.historyTime[prevPos] = g_irqCpup[loop].cpup.allTime;
189 }
190#endif
191
192 for (loop = 0; loop < g_processMaxNum; loop++) {
193 processCB = OS_PCB_FROM_PID(loop);
194 if (processCB->processCpup == NULL) {
195 continue;
196 }
197 processCB->processCpup->historyTime[prevPos] = processCB->processCpup->allTime;
198 }
199
200 for (loop = 0; loop < g_taskMaxNum; loop++) {
201 taskCB = OS_TCB_FROM_TID(loop);
202 taskCB->taskCpup.historyTime[prevPos] = taskCB->taskCpup.allTime;
203 }
204
205 for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
206 runTaskID = runningTasks[loop];
207 if (runTaskID == INVALID_ID) {
208 continue;
209 }
210 taskCB = OS_TCB_FROM_TID(runTaskID);
211
212 /* reacquire the cycle to prevent flip */
213 cycle = OsGetCpuCycle();
214 cycleIncrement = cycle - taskCB->taskCpup.startTime;
215#ifdef LOSCFG_CPUP_INCLUDE_IRQ
216 cycleIncrement -= timeInIrqSwitch[loop];
217#endif
218 taskCB->taskCpup.historyTime[prevPos] += cycleIncrement;
219 processCB = OS_PCB_FROM_PID(taskCB->processID);
220 processCB->processCpup->historyTime[prevPos] += cycleIncrement;
221 }
222
223 SCHEDULER_UNLOCK(intSave);
224}
LITE_OS_SEC_BSS UINT32 g_taskMaxNum
任务最大数量 默认128个
Definition: los_task.c:150
LITE_OS_SEC_BSS STATIC UINT32 cpupMaxNum
Definition: los_cpup.c:126
LITE_OS_SEC_BSS STATIC UINT64 cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM+1]
Definition: los_cpup.c:128
LITE_OS_SEC_BSS OsIrqCpupCB * g_irqCpup
Definition: los_cpup.c:125
LITE_OS_SEC_BSS UINT32 g_processMaxNum
进程最大数量,默认64个
Definition: los_process.c:86
OsCpupBase cpup
Definition: los_cpup_pri.h:65
OsCpupBase * processCpup
函数调用图:
这是这个函数的调用关系图:

◆ OsCpupGuardCreator()

LITE_OS_SEC_TEXT_INIT UINT32 OsCpupGuardCreator ( VOID  )

创建cpu使用统计定时器

在文件 los_cpup.c226 行定义.

227{
228 (VOID)LOS_SwtmrCreate(LOSCFG_BASE_CORE_TICK_PER_SECOND, LOS_SWTMR_MODE_PERIOD,
230
232
233 return LOS_OK;
234}
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
接口函数 启动定时器 参数定时任务ID
Definition: los_swtmr.c:764
VOID(* SWTMR_PROC_FUNC)(UINTPTR arg)
Define the type of a callback function that handles software timer timeout.
Definition: los_swtmr.h:260
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval, UINT8 mode, SWTMR_PROC_FUNC handler, UINT16 *swtmrID, UINTPTR arg)
创建定时器,设置定时器的定时时长、定时器模式、回调函数,并返回定时器ID
Definition: los_swtmr.c:712
@ LOS_SWTMR_MODE_PERIOD
Definition: los_swtmr.h:233
LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
Definition: los_cpup.c:166
LITE_OS_SEC_BSS STATIC UINT16 cpupSwtmrID
监测CPU使用情况定时器s
Definition: los_cpup.c:123
函数调用图:

◆ OsCpupInit()

LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit ( VOID  )

在文件 los_cpup.c242 行定义.

243{
244 UINT16 loop;
245#ifdef LOSCFG_CPUP_INCLUDE_IRQ
246 UINT32 size;
247
248 cpupMaxNum = OS_HWI_MAX_NUM * LOSCFG_KERNEL_CORE_NUM;
249
250 /* every process has only one record, and it won't operated at the same time */
251 size = cpupMaxNum * sizeof(OsIrqCpupCB);
253 if (g_irqCpup == NULL) {
254 PRINT_ERR("OsCpupInit error\n");
255 return LOS_ERRNO_CPUP_NO_MEMORY;
256 }
257
258 (VOID)memset_s(g_irqCpup, size, 0, size);
259#endif
260
261 for (loop = 0; loop < LOSCFG_KERNEL_CORE_NUM; loop++) {
262 runningTasks[loop] = INVALID_ID;
263 }
264 cpupInitFlg = 1;
265 return LOS_OK;
266}
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
Definition: los_memory.c:107
函数调用图:

◆ OsCpupIrqEnd()

LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqEnd ( UINT16  cpuid,
UINT32  intNum 
)

在文件 los_cpup.c645 行定义.

646{
647 UINT32 high;
648 UINT32 low;
649 UINT64 intTimeEnd;
650 UINT64 usedTime;
651
652 LOS_GetCpuCycle(&high, &low);
653 intTimeEnd = ((UINT64)high << HIGH_BITS) + low;
654 OsIrqCpupCB *irqCb = &g_irqCpup[(intNum * LOSCFG_KERNEL_CORE_NUM) + cpuid];
655 irqCb->id = intNum;
656 irqCb->status = OS_CPUP_USED;
657 usedTime = intTimeEnd - cpupIntTimeStart[cpuid];
658 timeInIrqSwitch[cpuid] += usedTime;
659 irqCb->cpup.allTime += usedTime;
660 if (irqCb->count <= 100) { /* Take 100 samples */
661 irqCb->allTime += usedTime;
662 irqCb->count++;
663 } else {
664 irqCb->allTime = 0;
665 irqCb->count = 0;
666 }
667 if (usedTime > irqCb->timeMax) {
668 irqCb->timeMax = usedTime;
669 }
670 return;
671}
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt)
获取自系统启动以来的Cycle数
Definition: los_hw_tick.c:54
LITE_OS_SEC_BSS STATIC UINT64 cpupIntTimeStart[LOSCFG_KERNEL_CORE_NUM]
Definition: los_cpup.c:133
UINT64 count
Definition: los_cpup_pri.h:64
UINT64 allTime
Definition: los_cpup_pri.h:62
UINT64 timeMax
Definition: los_cpup_pri.h:63
UINT16 status
Definition: los_cpup_pri.h:61
函数调用图:
这是这个函数的调用关系图:

◆ OsCpupIrqStart()

LITE_OS_SEC_TEXT_MINOR VOID OsCpupIrqStart ( UINT16  cpuid)

在文件 los_cpup.c635 行定义.

636{
637 UINT32 high;
638 UINT32 low;
639
640 LOS_GetCpuCycle(&high, &low);
641 cpupIntTimeStart[cpuid] = ((UINT64)high << HIGH_BITS) + low;
642 return;
643}
函数调用图:
这是这个函数的调用关系图:

◆ OsCpupUsageParamCheckAndReset()

STATIC UINT32 OsCpupUsageParamCheckAndReset ( CPUP_INFO_S cpupInfo,
UINT32  len,
UINT32  number 
)

在文件 los_cpup.c541 行定义.

542{
543 if (cpupInitFlg == 0) {
544 return LOS_ERRNO_CPUP_NO_INIT;
545 }
546
547 if ((cpupInfo == NULL) || (len < (sizeof(CPUP_INFO_S) * number))) {
548 return LOS_ERRNO_CPUP_PTR_ERR;
549 }
550
551 (VOID)memset_s(cpupInfo, len, 0, len);
552 return LOS_OK;
553}
这是这个函数的调用关系图:

◆ OsGetAllIrqCpuUsageUnsafe()

LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllIrqCpuUsageUnsafe ( UINT16  mode,
CPUP_INFO_S cpupInfo,
UINT32  len 
)

在文件 los_cpup.c678 行定义.

679{
680 UINT16 pos, prePos;
681 UINT64 cpuAllCycle;
682 UINT32 loop;
683 UINT32 ret;
684
685 ret = OsCpupUsageParamCheckAndReset(cpupInfo, len, cpupMaxNum);
686 if (ret != LOS_OK) {
687 return ret;
688 }
689
690 OsCpupGetPos(mode, &pos, &prePos);
691 cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
692
693 for (loop = 0; loop < cpupMaxNum; loop++) {
694 if (g_irqCpup[loop].status == OS_CPUP_UNUSED) {
695 continue;
696 }
697
698 cpupInfo[loop].usage = OsCalculateCpupUsage(&g_irqCpup[loop].cpup, pos, prePos, cpuAllCycle);
699 cpupInfo[loop].status = g_irqCpup[loop].status;
700 }
701
702 return LOS_OK;
703}
STATIC UINT32 OsCpupUsageParamCheckAndReset(CPUP_INFO_S *cpupInfo, UINT32 len, UINT32 number)
Definition: los_cpup.c:541
STATIC INLINE UINT32 OsCalculateCpupUsage(const OsCpupBase *cpup, UINT16 pos, UINT16 prePos, UINT64 allCycle)
Definition: los_cpup.c:396
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsCpupGetPos(UINT16 mode, UINT16 *curPosPointer, UINT16 *prePosPointer)
Definition: los_cpup.c:363
UINT32 usage
Definition: los_cpup.h:124
UINT16 status
Definition: los_cpup.h:123
函数调用图:
这是这个函数的调用关系图:

◆ OsGetAllProcessAndTaskCpuUsageUnsafe()

LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe ( UINT16  mode,
CPUP_INFO_S cpupInfo,
UINT32  len 
)

在文件 los_cpup.c595 行定义.

596{
597 UINT64 cpuAllCycle;
598 UINT16 pos, prePos;
599 UINT32 taskID;
600 UINT32 ret;
601 LosTaskCB *taskCB = NULL;
602 OsCpupBase *processCpupBase = NULL;
603 CPUP_INFO_S *processCpup = cpupInfo;
604 CPUP_INFO_S *taskCpup = (CPUP_INFO_S *)((UINTPTR)cpupInfo + sizeof(CPUP_INFO_S) * g_processMaxNum);
605
607 if (ret != LOS_OK) {
608 return ret;
609 }
610
611 OsCpupGetPos(mode, &pos, &prePos);
612 cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
613
614 for (taskID = 0; taskID < g_taskMaxNum; taskID++) {
615 taskCB = OS_TCB_FROM_TID(taskID);
616 if (OsTaskIsUnused(taskCB)) {
617 continue;
618 }
619
620 taskCpup[taskID].usage = OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
621 taskCpup[taskID].status = OS_CPUP_USED;
622 if (processCpup[taskCB->processID].status == OS_CPUP_UNUSED) {
623 processCpupBase = OS_PCB_FROM_PID(taskCB->processID)->processCpup;
624 if (processCpupBase != NULL) {
625 processCpup[taskCB->processID].usage = OsCalculateCpupUsage(processCpupBase, pos, prePos, cpuAllCycle);
626 processCpup[taskCB->processID].status = OS_CPUP_USED;
627 }
628 }
629 }
630
631 return LOS_OK;
632}
struct tagCpupInfo CPUP_INFO_S
STATIC INLINE BOOL OsTaskIsUnused(const LosTaskCB *taskCB)
任务是否在使用
Definition: los_task_pri.h:255
unsigned long UINTPTR
Definition: los_typedef.h:68
函数调用图:
这是这个函数的调用关系图:

◆ OsGetAllProcessCpuUsageUnsafe()

LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessCpuUsageUnsafe ( UINT16  mode,
CPUP_INFO_S cpupInfo,
UINT32  len 
)

在文件 los_cpup.c555 行定义.

556{
557 LosProcessCB *processCB = NULL;
558 UINT64 cpuAllCycle;
559 UINT16 pos, prePos;
560 UINT32 processID;
561 UINT32 ret;
562
564 if (ret != LOS_OK) {
565 return ret;
566 }
567
568 OsCpupGetPos(mode, &pos, &prePos);
569 cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
570
571 for (processID = 0; processID < g_processMaxNum; processID++) {
572 processCB = OS_PCB_FROM_PID(processID);
573 if (OsProcessIsUnused(processCB) || (processCB->processCpup == NULL)) {
574 continue;
575 }
576
577 cpupInfo[processID].usage = OsCalculateCpupUsage(processCB->processCpup, pos, prePos, cpuAllCycle);
578 cpupInfo[processID].status = OS_CPUP_USED;
579 }
580
581 return LOS_OK;
582}
STATIC INLINE BOOL OsProcessIsUnused(const LosProcessCB *processCB)
函数调用图:
这是这个函数的调用关系图:

◆ OsGetCpuCycle()

STATIC UINT64 OsGetCpuCycle ( VOID  )

在文件 los_cpup.c145 行定义.

146{
147 UINT32 high;
148 UINT32 low;
149 UINT64 cycles;//周期数用 64位计算,读取分成高低位
150
151 LOS_GetCpuCycle(&high, &low);//将64位拆成两个32位
152 cycles = ((UINT64)high << HIGH_BITS) + low;
153 if (cpupStartCycles == 0) {
154 cpupStartCycles = cycles;
155 }
156
157 /*
158 * The cycles should keep growing, if the checking failed,
159 * it mean LOS_GetCpuCycle has the problem which should be fixed.
160 */
161 LOS_ASSERT(cycles >= cpupStartCycles);
162
163 return (cycles - cpupStartCycles);
164}
LITE_OS_SEC_BSS STATIC UINT64 cpupStartCycles
记录
Definition: los_cpup.c:130
函数调用图:
这是这个函数的调用关系图:

◆ OsGetIrqCpupArrayBase()

LITE_OS_SEC_TEXT_MINOR OsIrqCpupCB * OsGetIrqCpupArrayBase ( VOID  )

在文件 los_cpup.c673 行定义.

674{
675 return g_irqCpup;
676}
这是这个函数的调用关系图:

◆ OsHistoryProcessCpuUsageUnsafe()

STATIC UINT32 OsHistoryProcessCpuUsageUnsafe ( UINT32  pid,
UINT16  mode 
)

在文件 los_cpup.c447 行定义.

448{
449 LosProcessCB *processCB = NULL;
450 UINT64 cpuAllCycle;
451 UINT16 pos, prePos;
452
453 if (cpupInitFlg == 0) {
454 return LOS_ERRNO_CPUP_NO_INIT;
455 }
456
457 if (OS_PID_CHECK_INVALID(pid)) {
458 return LOS_ERRNO_CPUP_ID_INVALID;
459 }
460
461 processCB = OS_PCB_FROM_PID(pid);
462 if (OsProcessIsUnused(processCB)) {
463 return LOS_ERRNO_CPUP_NO_CREATED;
464 }
465
466 if (processCB->processCpup == NULL) {
467 return LOS_ERRNO_CPUP_ID_INVALID;
468 }
469
470 OsCpupGetPos(mode, &pos, &prePos);
471 cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
472
473 return OsCalculateCpupUsage(processCB->processCpup, pos, prePos, cpuAllCycle);
474}
函数调用图:
这是这个函数的调用关系图:

◆ OsHistorySysCpuUsageUnsafe()

STATIC UINT32 OsHistorySysCpuUsageUnsafe ( UINT16  mode)

在文件 los_cpup.c407 行定义.

408{
409 UINT64 cpuAllCycle;
410 UINT16 pos;
411 UINT16 prePos;
412 UINT32 idleProcessID;
413 OsCpupBase *processCpup = NULL;
414
415 if (cpupInitFlg == 0) {
416 return LOS_ERRNO_CPUP_NO_INIT;
417 }
418
419 OsCpupGetPos(mode, &pos, &prePos);
420 cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
421
422 idleProcessID = OsGetIdleProcessID();
423 processCpup = OS_PCB_FROM_PID(idleProcessID)->processCpup;
424 return (LOS_CPUP_PRECISION - OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle));
425}
LITE_OS_SEC_TEXT UINT32 OsGetIdleProcessID(VOID)
获取内核态空闲进程
Definition: los_process.c:2254
函数调用图:
这是这个函数的调用关系图:

◆ OsHistoryTaskCpuUsageUnsafe()

STATIC UINT32 OsHistoryTaskCpuUsageUnsafe ( UINT32  tid,
UINT16  mode 
)

在文件 los_cpup.c496 行定义.

497{
498 LosTaskCB *taskCB = NULL;
499 UINT64 cpuAllCycle;
500 UINT16 pos, prePos;
501
502 if (cpupInitFlg == 0) {
503 return LOS_ERRNO_CPUP_NO_INIT;
504 }
505
506 if (OS_TID_CHECK_INVALID(tid)) {
507 return LOS_ERRNO_CPUP_ID_INVALID;
508 }
509
510 taskCB = OS_TCB_FROM_TID(tid);
511 if (OsTaskIsUnused(taskCB)) {
512 return LOS_ERRNO_CPUP_NO_CREATED;
513 }
514
515 OsCpupGetPos(mode, &pos, &prePos);
516 cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
517
518 return OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
519}
函数调用图:
这是这个函数的调用关系图:

◆ OsResetCpup()

STATIC VOID OsResetCpup ( OsCpupBase cpup,
UINT64  cycle 
)

在文件 los_cpup.c270 行定义.

271{
272 UINT16 loop;
273
274 cpup->startTime = cycle;
275 cpup->allTime = cycle;
276 for (loop = 0; loop < (OS_CPUP_HISTORY_RECORD_NUM + 1); loop++) {
277 cpup->historyTime[loop] = cycle;
278 }
279}
这是这个函数的调用关系图:

变量说明

◆ cpuHistoryTime

LITE_OS_SEC_BSS STATIC UINT64 cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM+1]

在文件 los_cpup.c128 行定义.

◆ cpupHisPos

LITE_OS_SEC_BSS STATIC UINT16 cpupHisPos = 0

在文件 los_cpup.c127 行定义.

◆ cpupInitFlg

LITE_OS_SEC_BSS STATIC UINT16 cpupInitFlg = 0

在文件 los_cpup.c124 行定义.

◆ cpupIntTimeStart

LITE_OS_SEC_BSS STATIC UINT64 cpupIntTimeStart[LOSCFG_KERNEL_CORE_NUM]

在文件 los_cpup.c133 行定义.

◆ cpupMaxNum

LITE_OS_SEC_BSS STATIC UINT32 cpupMaxNum

在文件 los_cpup.c126 行定义.

◆ cpupStartCycles

LITE_OS_SEC_BSS STATIC UINT64 cpupStartCycles = 0

记录

在文件 los_cpup.c130 行定义.

◆ cpupSwtmrID

LITE_OS_SEC_BSS STATIC UINT16 cpupSwtmrID

监测CPU使用情况定时器s

在文件 los_cpup.c123 行定义.

◆ g_irqCpup

LITE_OS_SEC_BSS OsIrqCpupCB* g_irqCpup = NULL

在文件 los_cpup.c125 行定义.

◆ runningTasks

LITE_OS_SEC_BSS STATIC UINT32 runningTasks[LOSCFG_KERNEL_CORE_NUM]

在文件 los_cpup.c129 行定义.

◆ timeInIrqSwitch

LITE_OS_SEC_BSS UINT64 timeInIrqSwitch[LOSCFG_KERNEL_CORE_NUM]

在文件 los_cpup.c132 行定义.