Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
e99aba9d
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
464
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e99aba9d
编写于
11月 04, 2021
作者:
O
openharmony_ci
提交者:
Gitee
11月 04, 2021
浏览文件
操作
浏览文件
下载
差异文件
!695 feat: 进程cpup占用率结构优化为动态分配
Merge pull request !695 from zhushengle/cpup
上级
0f8ff8f5
f06e090a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
14 deletion
+50
-14
compat/posix/src/time.c
compat/posix/src/time.c
+5
-1
kernel/base/core/los_process.c
kernel/base/core/los_process.c
+18
-0
kernel/base/include/los_process_pri.h
kernel/base/include/los_process_pri.h
+1
-1
kernel/extended/cpup/los_cpup.c
kernel/extended/cpup/los_cpup.c
+26
-12
未找到文件。
compat/posix/src/time.c
浏览文件 @
e99aba9d
...
...
@@ -509,7 +509,11 @@ static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
}
SCHEDULER_LOCK
(
intSave
);
runtime
=
spcb
->
processCpup
.
allTime
;
if
(
spcb
->
processCpup
==
NULL
)
{
SCHEDULER_UNLOCK
(
intSave
);
return
-
EINVAL
;
}
runtime
=
spcb
->
processCpup
->
allTime
;
SCHEDULER_UNLOCK
(
intSave
);
ats
->
tv_sec
=
runtime
/
OS_SYS_NS_PER_SECOND
;
...
...
kernel/base/core/los_process.c
浏览文件 @
e99aba9d
...
...
@@ -376,6 +376,15 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
(
VOID
)
LiteIpcPoolDestroy
(
processCB
->
processID
);
#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
)
{
(
VOID
)
LOS_MemFree
((
VOID
*
)
m_aucSysMem0
,
processCB
->
resourceLimit
);
processCB
->
resourceLimit
=
NULL
;
...
...
@@ -654,12 +663,21 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, c
}
#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
status_t
status
=
VidMapListInit
(
processCB
);
if
(
status
!=
LOS_OK
)
{
return
LOS_ENOMEM
;
}
#endif
#ifdef LOSCFG_SECURITY_CAPABILITY
OsInitCapability
(
processCB
);
#endif
...
...
kernel/base/include/los_process_pri.h
浏览文件 @
e99aba9d
...
...
@@ -125,7 +125,7 @@ typedef struct ProcessCB {
#endif
mode_t
umask
;
#ifdef LOSCFG_KERNEL_CPUP
OsCpupBase
processCpup
;
/**< Process cpu usage */
OsCpupBase
*
processCpup
;
/**< Process cpu usage */
#endif
struct
rlimit
*
resourceLimit
;
}
LosProcessCB
;
...
...
kernel/extended/cpup/los_cpup.c
浏览文件 @
e99aba9d
...
...
@@ -106,7 +106,10 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
for
(
loop
=
0
;
loop
<
g_processMaxNum
;
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
++
)
{
...
...
@@ -129,7 +132,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsCpupGuard(VOID)
#endif
taskCB
->
taskCpup
.
historyTime
[
prevPos
]
+=
cycleIncrement
;
processCB
=
OS_PCB_FROM_PID
(
taskCB
->
processID
);
processCB
->
processCpup
.
historyTime
[
prevPos
]
+=
cycleIncrement
;
processCB
->
processCpup
->
historyTime
[
prevPos
]
+=
cycleIncrement
;
}
SCHEDULER_UNLOCK
(
intSave
);
...
...
@@ -209,7 +212,10 @@ LITE_OS_SEC_TEXT_INIT VOID LOS_CpupReset(VOID)
for
(
index
=
0
;
index
<
g_processMaxNum
;
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
++
)
{
...
...
@@ -242,7 +248,7 @@ VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
LosTaskCB
*
runTask
=
OS_TCB_FROM_TID
(
runTaskID
);
OsCpupBase
*
runTaskCpup
=
&
runTask
->
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
;
UINT16
cpuID
=
ArchCurrCpuid
();
...
...
@@ -258,7 +264,9 @@ VOID OsCpupCycleEndStart(UINT32 runTaskID, UINT32 newTaskID)
timeInIrqSwitch
[
cpuID
]
=
0
;
#endif
runTaskCpup
->
allTime
+=
cycleIncrement
;
processCpup
->
allTime
+=
cycleIncrement
;
if
(
processCpup
!=
NULL
)
{
processCpup
->
allTime
+=
cycleIncrement
;
}
runTaskCpup
->
startTime
=
0
;
}
...
...
@@ -326,7 +334,7 @@ STATIC UINT32 OsHistorySysCpuUsageUnsafe(UINT16 mode)
cpuAllCycle
=
cpuHistoryTime
[
pos
]
-
cpuHistoryTime
[
prePos
];
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
));
}
...
...
@@ -361,10 +369,14 @@ STATIC UINT32 OsHistoryProcessCpuUsageUnsafe(UINT32 pid, UINT16 mode)
return
LOS_ERRNO_CPUP_NO_CREATED
;
}
if
(
processCB
->
processCpup
==
NULL
)
{
return
LOS_ERRNO_CPUP_ID_INVALID
;
}
OsCpupGetPos
(
mode
,
&
pos
,
&
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
)
...
...
@@ -446,11 +458,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessCpuUsageUnsafe(UINT16 mode, CPUP_IN
for
(
processID
=
0
;
processID
<
g_processMaxNum
;
processID
++
)
{
processCB
=
OS_PCB_FROM_PID
(
processID
);
if
(
OsProcessIsUnused
(
processCB
))
{
if
(
OsProcessIsUnused
(
processCB
)
||
(
processCB
->
processCpup
==
NULL
)
)
{
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
;
}
...
...
@@ -496,9 +508,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe(UINT16 mode,
taskCpup
[
taskID
].
usage
=
OsCalculateCpupUsage
(
&
taskCB
->
taskCpup
,
pos
,
prePos
,
cpuAllCycle
);
taskCpup
[
taskID
].
status
=
OS_CPUP_USED
;
if
(
processCpup
[
taskCB
->
processID
].
status
==
OS_CPUP_UNUSED
)
{
processCpupBase
=
&
(
OS_PCB_FROM_PID
(
taskCB
->
processID
)
->
processCpup
);
processCpup
[
taskCB
->
processID
].
usage
=
OsCalculateCpupUsage
(
processCpupBase
,
pos
,
prePos
,
cpuAllCycle
);
processCpup
[
taskCB
->
processID
].
status
=
OS_CPUP_USED
;
processCpupBase
=
OS_PCB_FROM_PID
(
taskCB
->
processID
)
->
processCpup
;
if
(
processCpupBase
!=
NULL
)
{
processCpup
[
taskCB
->
processID
].
usage
=
OsCalculateCpupUsage
(
processCpupBase
,
pos
,
prePos
,
cpuAllCycle
);
processCpup
[
taskCB
->
processID
].
status
=
OS_CPUP_USED
;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录