!695 feat: 进程cpup占用率结构优化为动态分配
Merge pull request !695 from zhushengle/cpup
This commit is contained in:
commit
e99aba9d0f
|
@ -509,7 +509,11 @@ static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
|
||||||
}
|
}
|
||||||
|
|
||||||
SCHEDULER_LOCK(intSave);
|
SCHEDULER_LOCK(intSave);
|
||||||
runtime = spcb->processCpup.allTime;
|
if (spcb->processCpup == NULL) {
|
||||||
|
SCHEDULER_UNLOCK(intSave);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
runtime = spcb->processCpup->allTime;
|
||||||
SCHEDULER_UNLOCK(intSave);
|
SCHEDULER_UNLOCK(intSave);
|
||||||
|
|
||||||
ats->tv_sec = runtime / OS_SYS_NS_PER_SECOND;
|
ats->tv_sec = runtime / OS_SYS_NS_PER_SECOND;
|
||||||
|
|
|
@ -376,6 +376,15 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
|
||||||
(VOID)LiteIpcPoolDestroy(processCB->processID);
|
(VOID)LiteIpcPoolDestroy(processCB->processID);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LOSCFG_KERNEL_CPUP
|
||||||
|
UINT32 intSave;
|
||||||
|
OsCpupBase *processCpup = processCB->processCpup;
|
||||||
|
SCHEDULER_LOCK(intSave);
|
||||||
|
processCB->processCpup = NULL;
|
||||||
|
SCHEDULER_UNLOCK(intSave);
|
||||||
|
(VOID)LOS_MemFree(m_aucSysMem1, processCpup);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (processCB->resourceLimit != NULL) {
|
if (processCB->resourceLimit != NULL) {
|
||||||
(VOID)LOS_MemFree((VOID *)m_aucSysMem0, processCB->resourceLimit);
|
(VOID)LOS_MemFree((VOID *)m_aucSysMem0, processCB->resourceLimit);
|
||||||
processCB->resourceLimit = NULL;
|
processCB->resourceLimit = NULL;
|
||||||
|
@ -654,12 +663,21 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, c
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LOSCFG_KERNEL_CPUP
|
||||||
|
processCB->processCpup = (OsCpupBase *)LOS_MemAlloc(m_aucSysMem1, sizeof(OsCpupBase));
|
||||||
|
if (processCB->processCpup == NULL) {
|
||||||
|
return LOS_ENOMEM;
|
||||||
|
}
|
||||||
|
(VOID)memset_s(processCB->processCpup, sizeof(OsCpupBase), 0, sizeof(OsCpupBase));
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef LOSCFG_SECURITY_VID
|
#ifdef LOSCFG_SECURITY_VID
|
||||||
status_t status = VidMapListInit(processCB);
|
status_t status = VidMapListInit(processCB);
|
||||||
if (status != LOS_OK) {
|
if (status != LOS_OK) {
|
||||||
return LOS_ENOMEM;
|
return LOS_ENOMEM;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||||
OsInitCapability(processCB);
|
OsInitCapability(processCB);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -125,7 +125,7 @@ typedef struct ProcessCB {
|
||||||
#endif
|
#endif
|
||||||
mode_t umask;
|
mode_t umask;
|
||||||
#ifdef LOSCFG_KERNEL_CPUP
|
#ifdef LOSCFG_KERNEL_CPUP
|
||||||
OsCpupBase processCpup; /**< Process cpu usage */
|
OsCpupBase *processCpup; /**< Process cpu usage */
|
||||||
#endif
|
#endif
|
||||||
struct rlimit *resourceLimit;
|
struct rlimit *resourceLimit;
|
||||||
} LosProcessCB;
|
} LosProcessCB;
|
||||||
|
|
|
@ -106,7 +106,10 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
|
||||||
|
|
||||||
for (loop = 0; loop < g_processMaxNum; loop++) {
|
for (loop = 0; loop < g_processMaxNum; loop++) {
|
||||||
processCB = OS_PCB_FROM_PID(loop);
|
processCB = OS_PCB_FROM_PID(loop);
|
||||||
processCB->processCpup.historyTime[prevPos] = processCB->processCpup.allTime;
|
if (processCB->processCpup == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
processCB->processCpup->historyTime[prevPos] = processCB->processCpup->allTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (loop = 0; loop < g_taskMaxNum; loop++) {
|
for (loop = 0; loop < g_taskMaxNum; loop++) {
|
||||||
|
@ -129,7 +132,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
|
||||||
#endif
|
#endif
|
||||||
taskCB->taskCpup.historyTime[prevPos] += cycleIncrement;
|
taskCB->taskCpup.historyTime[prevPos] += cycleIncrement;
|
||||||
processCB = OS_PCB_FROM_PID(taskCB->processID);
|
processCB = OS_PCB_FROM_PID(taskCB->processID);
|
||||||
processCB->processCpup.historyTime[prevPos] += cycleIncrement;
|
processCB->processCpup->historyTime[prevPos] += cycleIncrement;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCHEDULER_UNLOCK(intSave);
|
SCHEDULER_UNLOCK(intSave);
|
||||||
|
@ -209,7 +212,10 @@ LITE_OS_SEC_TEXT_INIT VOID LOS_CpupReset(VOID)
|
||||||
|
|
||||||
for (index = 0; index < g_processMaxNum; index++) {
|
for (index = 0; index < g_processMaxNum; index++) {
|
||||||
processCB = OS_PCB_FROM_PID(index);
|
processCB = OS_PCB_FROM_PID(index);
|
||||||
OsResetCpup(&processCB->processCpup, cycle);
|
if (processCB->processCpup == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
OsResetCpup(processCB->processCpup, cycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index = 0; index < g_taskMaxNum; index++) {
|
for (index = 0; index < g_taskMaxNum; index++) {
|
||||||
|
@ -242,7 +248,7 @@ VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
|
||||||
LosTaskCB *runTask = OS_TCB_FROM_TID(runTaskID);
|
LosTaskCB *runTask = OS_TCB_FROM_TID(runTaskID);
|
||||||
OsCpupBase *runTaskCpup = &runTask->taskCpup;
|
OsCpupBase *runTaskCpup = &runTask->taskCpup;
|
||||||
OsCpupBase *newTaskCpup = (OsCpupBase *)&(OS_TCB_FROM_TID(newTaskID)->taskCpup);
|
OsCpupBase *newTaskCpup = (OsCpupBase *)&(OS_TCB_FROM_TID(newTaskID)->taskCpup);
|
||||||
OsCpupBase *processCpup = (OsCpupBase *)&(OS_PCB_FROM_PID(runTask->processID)->processCpup);
|
OsCpupBase *processCpup = OS_PCB_FROM_PID(runTask->processID)->processCpup;
|
||||||
UINT64 cpuCycle, cycleIncrement;
|
UINT64 cpuCycle, cycleIncrement;
|
||||||
UINT16 cpuID = ArchCurrCpuid();
|
UINT16 cpuID = ArchCurrCpuid();
|
||||||
|
|
||||||
|
@ -258,7 +264,9 @@ VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
|
||||||
timeInIrqSwitch[cpuID] = 0;
|
timeInIrqSwitch[cpuID] = 0;
|
||||||
#endif
|
#endif
|
||||||
runTaskCpup->allTime += cycleIncrement;
|
runTaskCpup->allTime += cycleIncrement;
|
||||||
|
if (processCpup != NULL) {
|
||||||
processCpup->allTime += cycleIncrement;
|
processCpup->allTime += cycleIncrement;
|
||||||
|
}
|
||||||
runTaskCpup->startTime = 0;
|
runTaskCpup->startTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +334,7 @@ STATIC UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode)
|
||||||
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
|
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
|
||||||
|
|
||||||
idleProcessID = OsGetIdleProcessID();
|
idleProcessID = OsGetIdleProcessID();
|
||||||
processCpup = (OsCpupBase *)&(OS_PCB_FROM_PID(idleProcessID)->processCpup);
|
processCpup = OS_PCB_FROM_PID(idleProcessID)->processCpup;
|
||||||
return (LOS_CPUP_PRECISION - OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle));
|
return (LOS_CPUP_PRECISION - OsCalculateCpupUsage(processCpup, pos, prePos, cpuAllCycle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,10 +369,14 @@ STATIC UINT32 OsHistoryProcessCpuUsageUnsafe(UINT32 pid, UINT16 mode)
|
||||||
return LOS_ERRNO_CPUP_NO_CREATED;
|
return LOS_ERRNO_CPUP_NO_CREATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (processCB->processCpup == NULL) {
|
||||||
|
return LOS_ERRNO_CPUP_ID_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
OsCpupGetPos(mode, &pos, &prePos);
|
OsCpupGetPos(mode, &pos, &prePos);
|
||||||
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
|
cpuAllCycle = cpuHistoryTime[pos] - cpuHistoryTime[prePos];
|
||||||
|
|
||||||
return OsCalculateCpupUsage(&processCB->processCpup, pos, prePos, cpuAllCycle);
|
return OsCalculateCpupUsage(processCB->processCpup, pos, prePos, cpuAllCycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryProcessCpuUsage(UINT32 pid, UINT16 mode)
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_HistoryProcessCpuUsage(UINT32 pid, UINT16 mode)
|
||||||
|
@ -446,11 +458,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_IN
|
||||||
|
|
||||||
for (processID = 0; processID < g_processMaxNum; processID++) {
|
for (processID = 0; processID < g_processMaxNum; processID++) {
|
||||||
processCB = OS_PCB_FROM_PID(processID);
|
processCB = OS_PCB_FROM_PID(processID);
|
||||||
if (OsProcessIsUnused(processCB)) {
|
if (OsProcessIsUnused(processCB) || (processCB->processCpup == NULL)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpupInfo[processID].usage = OsCalculateCpupUsage(&processCB->processCpup, pos, prePos, cpuAllCycle);
|
cpupInfo[processID].usage = OsCalculateCpupUsage(processCB->processCpup, pos, prePos, cpuAllCycle);
|
||||||
cpupInfo[processID].status = OS_CPUP_USED;
|
cpupInfo[processID].status = OS_CPUP_USED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,11 +508,13 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe(UINT16 mode,
|
||||||
taskCpup[taskID].usage = OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
|
taskCpup[taskID].usage = OsCalculateCpupUsage(&taskCB->taskCpup, pos, prePos, cpuAllCycle);
|
||||||
taskCpup[taskID].status = OS_CPUP_USED;
|
taskCpup[taskID].status = OS_CPUP_USED;
|
||||||
if (processCpup[taskCB->processID].status == OS_CPUP_UNUSED) {
|
if (processCpup[taskCB->processID].status == OS_CPUP_UNUSED) {
|
||||||
processCpupBase = &(OS_PCB_FROM_PID(taskCB->processID)->processCpup);
|
processCpupBase = OS_PCB_FROM_PID(taskCB->processID)->processCpup;
|
||||||
|
if (processCpupBase != NULL) {
|
||||||
processCpup[taskCB->processID].usage = OsCalculateCpupUsage(processCpupBase, pos, prePos, cpuAllCycle);
|
processCpup[taskCB->processID].usage = OsCalculateCpupUsage(processCpupBase, pos, prePos, cpuAllCycle);
|
||||||
processCpup[taskCB->processID].status = OS_CPUP_USED;
|
processCpup[taskCB->processID].status = OS_CPUP_USED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return LOS_OK;
|
return LOS_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue