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

浏览源代码.

结构体

struct  OsCpupBase
 
struct  OsIrqCpupCB
 

函数

UINT32 OsCpupInit (VOID)
 
UINT32 OsCpupGuardCreator (VOID)
 创建cpu使用统计定时器 更多...
 
VOID OsCpupCycleEndStart (UINT32 runTaskID, UINT32 newTaskID)
 
UINT32 OsGetAllTaskCpuUsageUnsafe (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 
UINT32 OsGetAllProcessCpuUsageUnsafe (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 
UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 
UINT32 OsGetAllIrqCpuUsageUnsafe (UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
 
VOID OsCpupIrqStart (UINT16)
 
VOID OsCpupIrqEnd (UINT16, UINT32)
 
OsIrqCpupCBOsGetIrqCpupArrayBase (VOID)
 

函数说明

◆ 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
long unsigned int UINT64
Definition: los_typedef.h:66
UINT64 allTime
Definition: los_cpup_pri.h:50
UINT64 startTime
Definition: los_cpup_pri.h:51
OsCpupBase taskCpup
UINT32 processID
函数调用图:
这是这个函数的调用关系图:

◆ OsCpupGuardCreator()

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()

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
LITE_OS_SEC_BSS STATIC UINT32 cpupMaxNum
Definition: los_cpup.c:126
LITE_OS_SEC_BSS OsIrqCpupCB * g_irqCpup
Definition: los_cpup.c:125
unsigned int UINT32
Definition: los_typedef.h:57
函数调用图:

◆ OsCpupIrqEnd()

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
OsCpupBase cpup
Definition: los_cpup_pri.h:65
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()

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}
函数调用图:
这是这个函数的调用关系图:

◆ OsGetAllIrqCpuUsageUnsafe()

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
LITE_OS_SEC_BSS STATIC UINT64 cpuHistoryTime[OS_CPUP_HISTORY_RECORD_NUM+1]
Definition: los_cpup.c:128
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()

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
LITE_OS_SEC_BSS UINT32 g_taskMaxNum
任务最大数量 默认128个
Definition: los_task.c:150
LITE_OS_SEC_BSS UINT32 g_processMaxNum
进程最大数量,默认64个
Definition: los_process.c:86
STATIC INLINE BOOL OsTaskIsUnused(const LosTaskCB *taskCB)
任务是否在使用
Definition: los_task_pri.h:255
unsigned long UINTPTR
Definition: los_typedef.h:68
函数调用图:
这是这个函数的调用关系图:

◆ OsGetAllProcessCpuUsageUnsafe()

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)
OsCpupBase * processCpup
函数调用图:
这是这个函数的调用关系图:

◆ OsGetAllTaskCpuUsageUnsafe()

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

◆ OsGetIrqCpupArrayBase()

OsIrqCpupCB * OsGetIrqCpupArrayBase ( VOID  )

在文件 los_cpup.c673 行定义.

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