更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
CPU usage
CPU usage 的协作图:

结构体

struct  OsIrqCpupCB
 
struct  tagCpupInfo
 

类型定义

typedef struct tagCpupInfo CPUP_INFO_S
 

枚举

enum  { CPUP_LAST_TEN_SECONDS = 0 , CPUP_LAST_ONE_SECONDS = 1 , CPUP_ALL_TIME = 0xffff }
 

函数

UINT32 LOS_HistorySysCpuUsage (UINT16 mode)
 Obtain the historical CPU usage. 更多...
 
UINT32 LOS_HistoryProcessCpuUsage (UINT32 pid, UINT16 mode)
 Obtain the historical CPU usage of a specified process. 更多...
 
UINT32 LOS_HistoryTaskCpuUsage (UINT32 tid, UINT16 mode)
 Obtain the historical CPU usage of a specified task. 更多...
 
UINT32 LOS_GetAllProcessCpuUsage (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 Obtain the CPU usage of processes. 更多...
 
UINT32 LOS_GetAllIrqCpuUsage (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 Obtain the CPU usage of hwi. 更多...
 
VOID LOS_CpupReset (VOID)
 Reset the data of CPU usage. 更多...
 

详细描述

类型定义说明

◆ CPUP_INFO_S

typedef struct tagCpupInfo CPUP_INFO_S

Count the CPU usage structures of all cpup.

枚举类型说明

◆ anonymous enum

anonymous enum

Query the CPU usage of the system.

枚举值
CPUP_LAST_TEN_SECONDS 

Display CPU usage in the last ten seconds.

CPUP_LAST_ONE_SECONDS 

Display CPU usage in the last one seconds.

CPUP_ALL_TIME 

Display CPU usage from system startup to now.

在文件 los_cpup.h131 行定义.

131 {
132 CPUP_LAST_TEN_SECONDS = 0, /**< Display CPU usage in the last ten seconds. */
133 CPUP_LAST_ONE_SECONDS = 1, /**< Display CPU usage in the last one seconds. */
134 CPUP_ALL_TIME = 0xffff /**< Display CPU usage from system startup to now. */
135};
@ 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

函数说明

◆ LOS_CpupReset()

VOID LOS_CpupReset ( VOID  )

Reset the data of CPU usage.

Description:
This API is used to reset the data of CPU usage.
注意
  • None.
参数
None.
返回值
#None.
Dependency:
  • los_cpup.h: the header file that contains the API declaration.
参见

在文件 los_cpup.c281 行定义.

282{
283 LosProcessCB *processCB = NULL;
284 LosTaskCB *taskCB = NULL;
285 UINT32 index;
286 UINT64 cycle;
287 UINT32 intSave;
288
289 cpupInitFlg = 0;
290 intSave = LOS_IntLock();
292 cycle = OsGetCpuCycle();
293
294 for (index = 0; index < (OS_CPUP_HISTORY_RECORD_NUM + 1); index++) {
295 cpuHistoryTime[index] = cycle;
296 }
297
298 for (index = 0; index < g_processMaxNum; index++) {
299 processCB = OS_PCB_FROM_PID(index);
300 if (processCB->processCpup == NULL) {
301 continue;
302 }
303 OsResetCpup(processCB->processCpup, cycle);
304 }
305
306 for (index = 0; index < g_taskMaxNum; index++) {
307 taskCB = OS_TCB_FROM_TID(index);
308 OsResetCpup(&taskCB->taskCpup, cycle);
309 }
310
311#ifdef LOSCFG_CPUP_INCLUDE_IRQ
312 if (g_irqCpup != NULL) {
313 for (index = 0; index < cpupMaxNum; index++) {
314 OsResetCpup(&g_irqCpup[index].cpup, cycle);
315 g_irqCpup[index].timeMax = 0;
316 }
317
318 for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
319 timeInIrqSwitch[index] = 0;
320 }
321 }
322#endif
323
325 LOS_IntRestore(intSave);
326 cpupInitFlg = 1;
327
328 return;
329}
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
Restore interrupts. | 恢复到使用LOS_IntLock关闭所有中断之前的状态
Definition: los_hwi.h:337
STATIC INLINE UINT32 LOS_IntLock(VOID)
Disable all interrupts. | 关闭当前处理器所有中断响应
Definition: los_hwi.h:286
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrID)
接口函数 停止定时器 参数定时任务ID
Definition: los_swtmr.c:808
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
接口函数 启动定时器 参数定时任务ID
Definition: los_swtmr.c:764
LITE_OS_SEC_BSS UINT32 g_taskMaxNum
任务最大数量 默认128个
Definition: los_task.c:150
STATIC VOID OsResetCpup(OsCpupBase *cpup, UINT64 cycle)
Definition: los_cpup.c:270
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 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 STATIC UINT16 cpupSwtmrID
监测CPU使用情况定时器s
Definition: los_cpup.c:123
LITE_OS_SEC_BSS UINT64 timeInIrqSwitch[LOSCFG_KERNEL_CORE_NUM]
Definition: los_cpup.c:132
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
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned int UINT32
Definition: los_typedef.h:57
UINT64 timeMax
Definition: los_cpup_pri.h:63
OsCpupBase * processCpup
OsCpupBase taskCpup
函数调用图:

◆ LOS_GetAllIrqCpuUsage()

UINT32 LOS_GetAllIrqCpuUsage ( UINT16  mode,
CPUP_INFO_S cpupInfo,
UINT32  len 
)

Obtain the CPU usage of hwi.

Description:
This API is used to obtain the CPU usage of hwi.
注意
  • This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.
  • The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.
  • The input parameter pointer should point to the structure array whose size be greater than (LOS_GetSystemHwiMaximum() * sizeof (CPUP_INFO_S)).
参数
mode[IN] UINT16. Time mode. The parameter value 0 indicates that the CPU usage within 10s will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.Other values indicate that the CPU usage in all time will be obtained.
cpupInfo[OUT]Type. CPUP_INFO_S* Pointer to the CPUP information structure to be obtained.
len[IN] UINT32. The Maximum length of hwis.
返回值
#LOS_ERRNO_CPUP_NO_INITThe CPU usage is not initialized.
#LOS_ERRNO_CPUP_PROCESS_PTR_ERRThe input parameter pointer is NULL or len less than LOS_GetSystemHwiMaximum() * sizeof (CPUP_INFO_S).
#LOS_OKThe CPU usage of all hwis is successfully obtained.
Dependency:
  • los_cpup.h: the header file that contains the API declaration.
参见

Obtain the CPU usage of hwi.

参数
mode
cpupInfo
len
返回

在文件 los_cpup.c715 行定义.

716{
717 UINT32 intSave;
718 UINT32 ret;
719
720 SCHEDULER_LOCK(intSave);
721 ret = OsGetAllIrqCpuUsageUnsafe(mode, cpupInfo, len);
722 SCHEDULER_UNLOCK(intSave);
723 return ret;
724}
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllIrqCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
Definition: los_cpup.c:678
函数调用图:
这是这个函数的调用关系图:

◆ LOS_GetAllProcessCpuUsage()

UINT32 LOS_GetAllProcessCpuUsage ( UINT16  mode,
CPUP_INFO_S cpupInfo,
UINT32  len 
)

Obtain the CPU usage of processes.

Description:
This API is used to obtain the CPU usage of processes.
注意
  • This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.
  • The input parameter pointer must not be NULL, Otherwise, the CPU usage fails to be obtained.
  • The input parameter pointer should point to the structure array whose size be greater than (LOS_GetSystemProcessMaximum() * sizeof (CPUP_INFO_S)).
参数
mode[IN] UINT16. Time mode. The parameter value 0 indicates that the CPU usage within 10s will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained.Other values indicate that the CPU usage in all time will be obtained.
cpupInfo[OUT]Type. CPUP_INFO_S* Pointer to the CPUP information structure to be obtained.
len[IN] UINT32. The Maximum length of processes.
返回值
#LOS_ERRNO_CPUP_NO_INITThe CPU usage is not initialized.
#LOS_ERRNO_CPUP_PROCESS_PTR_ERRThe input parameter pointer is NULL or len less than LOS_GetSystemProcessMaximum() * sizeof (CPUP_INFO_S).
#LOS_OKThe CPU usage of all processes is successfully obtained.
Dependency:
  • los_cpup.h: the header file that contains the API declaration.
参见

Obtain the CPU usage of processes.

在文件 los_cpup.c584 行定义.

585{
586 UINT32 intSave;
587 UINT32 ret;
588
589 SCHEDULER_LOCK(intSave);
590 ret = OsGetAllProcessCpuUsageUnsafe(mode, cpupInfo, len);
591 SCHEDULER_UNLOCK(intSave);
592 return ret;
593}
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
Definition: los_cpup.c:555
函数调用图:
这是这个函数的调用关系图:

◆ LOS_HistoryProcessCpuUsage()

UINT32 LOS_HistoryProcessCpuUsage ( UINT32  pid,
UINT16  mode 
)

Obtain the historical CPU usage of a specified process.

Description:
This API is used to obtain the historical CPU usage of a process specified by a passed-in process ID.
注意
  • This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.
  • The passed-in process ID must be valid and the process specified by the process ID must be created. Otherwise, the CPU usage fails to be obtained.
参数
pid[IN] UINT32. process ID.
mode[IN] UINT16. cpup mode. The parameter value 0 indicates that the CPU usage within 10s will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
返回值
#LOS_ERRNO_CPUP_NO_INITThe CPU usage is not initialized.
#LOS_ERRNO_CPUP_ID_INVALIDThe target process ID is invalid.
#LOS_ERRNO_CPUP_NO_CREATEDThe target process is not created.
UINT32[0, LOS_CPUP_PRECISION], CPU usage of the specified process.
Dependency:
  • los_cpup.h: the header file that contains the API declaration.
参见

Obtain the historical CPU usage of a specified process.

参数
pid
mode
返回

在文件 los_cpup.c485 行定义.

486{
487 UINT32 cpup;
488 UINT32 intSave;
489
490 SCHEDULER_LOCK(intSave);
491 cpup = OsHistoryProcessCpuUsageUnsafe(pid, mode);
492 SCHEDULER_UNLOCK(intSave);
493 return cpup;
494}
STATIC UINT32 OsHistoryProcessCpuUsageUnsafe(UINT32 pid, UINT16 mode)
Definition: los_cpup.c:447
函数调用图:
这是这个函数的调用关系图:

◆ LOS_HistorySysCpuUsage()

UINT32 LOS_HistorySysCpuUsage ( UINT16  mode)

Obtain the historical CPU usage.

Description:
This API is used to obtain the historical CPU usage.
注意
  • This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.
参数
mode[IN] UINT16. process mode. The parameter value 0 indicates that the CPU usage within 10s will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values indicate that the CPU usage in all time will be obtained.
返回值
#LOS_ERRNO_CPUP_NO_INITThe CPU usage is not initialized.
UINT32[0, LOS_CPUP_SINGLE_CORE_PRECISION], historical CPU usage, of which the precision is adjustable.
Dependency:
  • los_cpup.h: the header file that contains the API declaration.
参见

Obtain the historical CPU usage.

参数
mode
返回

在文件 los_cpup.c435 行定义.

436{
437 UINT32 cpup;
438 UINT32 intSave;
439
440 /* get end time of current process */
441 SCHEDULER_LOCK(intSave);
442 cpup = OsHistorySysCpuUsageUnsafe(mode);
443 SCHEDULER_UNLOCK(intSave);
444 return cpup;
445}
STATIC UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode)
Definition: los_cpup.c:407
函数调用图:
这是这个函数的调用关系图:

◆ LOS_HistoryTaskCpuUsage()

UINT32 LOS_HistoryTaskCpuUsage ( UINT32  tid,
UINT16  mode 
)

Obtain the historical CPU usage of a specified task.

Description:
This API is used to obtain the historical CPU usage of a task specified by a passed-in task ID.
注意
  • This API can be called only after the CPU usage is initialized. Otherwise, the CPU usage fails to be obtained.
  • The passed-in task ID must be valid and the task specified by the task ID must be created. Otherwise, the CPU usage fails to be obtained.
参数
tid[IN] UINT32. task ID.
mode[IN] UINT16. cpup mode. The parameter value 0 indicates that the CPU usage within 10s will be obtained, and the parameter value 1 indicates that the CPU usage in the former 1s will be obtained. Other values indicate that the CPU usage in the period that is less than 1s will be obtained.
返回值
#LOS_ERRNO_CPUP_NO_INITThe CPU usage is not initialized.
#LOS_ERRNO_CPUP_ID_INVALIDThe target task ID is invalid.
#LOS_ERRNO_CPUP_NO_CREATEDThe target task is not created.
UINT32[0, LOS_CPUP_SINGLE_CORE_PRECISION], CPU usage of the specified process.
Dependency:
  • los_cpup.h: the header file that contains the API declaration.
参见

Obtain the historical CPU usage of a specified task.

参数
tid
mode
返回

在文件 los_cpup.c530 行定义.

531{
532 UINT32 intSave;
533 UINT32 cpup;
534
535 SCHEDULER_LOCK(intSave);
536 cpup = OsHistoryTaskCpuUsageUnsafe(tid, mode);
537 SCHEDULER_UNLOCK(intSave);
538 return cpup;
539}
STATIC UINT32 OsHistoryTaskCpuUsageUnsafe(UINT32 tid, UINT16 mode)
Definition: los_cpup.c:496
函数调用图: