Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
4b3b2f6c
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b3b2f6c
编写于
2月 14, 2014
作者:
T
Thorsten Behrens
提交者:
Michal Privoznik
2月 20, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement domainGetCPUStats for lxc driver.
上级
65158899
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
132 addition
and
0 deletion
+132
-0
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/lxc/lxc_driver.c
src/lxc/lxc_driver.c
+49
-0
src/util/vircgroup.c
src/util/vircgroup.c
+75
-0
src/util/vircgroup.h
src/util/vircgroup.h
+7
-0
未找到文件。
src/libvirt_private.syms
浏览文件 @
4b3b2f6c
...
...
@@ -1032,6 +1032,7 @@ virCgroupGetMemorySoftLimit;
virCgroupGetMemoryUsage;
virCgroupGetMemSwapHardLimit;
virCgroupGetMemSwapUsage;
virCgroupGetPercpuStats;
virCgroupHasController;
virCgroupIsolateMount;
virCgroupKill;
...
...
src/lxc/lxc_driver.c
浏览文件 @
4b3b2f6c
...
...
@@ -77,6 +77,7 @@
#define LXC_NB_MEM_PARAM 3
static
int
lxcStateInitialize
(
bool
privileged
,
virStateInhibitCallback
callback
,
void
*
opaque
);
...
...
@@ -5420,6 +5421,53 @@ cleanup:
}
static
int
lxcDomainGetCPUStats
(
virDomainPtr
dom
,
virTypedParameterPtr
params
,
unsigned
int
nparams
,
int
start_cpu
,
unsigned
int
ncpus
,
unsigned
int
flags
)
{
virDomainObjPtr
vm
=
NULL
;
int
ret
=
-
1
;
virLXCDomainObjPrivatePtr
priv
;
virCheckFlags
(
VIR_TYPED_PARAM_STRING_OKAY
,
-
1
);
if
(
!
(
vm
=
lxcDomObjFromDomain
(
dom
)))
return
ret
;
priv
=
vm
->
privateData
;
if
(
virDomainGetCPUStatsEnsureACL
(
dom
->
conn
,
vm
->
def
)
<
0
)
goto
cleanup
;
if
(
!
virDomainObjIsActive
(
vm
))
{
virReportError
(
VIR_ERR_OPERATION_INVALID
,
"%s"
,
_
(
"domain is not running"
));
goto
cleanup
;
}
if
(
!
virCgroupHasController
(
priv
->
cgroup
,
VIR_CGROUP_CONTROLLER_CPUACCT
))
{
virReportError
(
VIR_ERR_OPERATION_INVALID
,
"%s"
,
_
(
"cgroup CPUACCT controller is not mounted"
));
goto
cleanup
;
}
if
(
start_cpu
==
-
1
)
ret
=
virCgroupGetDomainTotalCpuStats
(
priv
->
cgroup
,
params
,
nparams
);
else
ret
=
virCgroupGetPercpuStats
(
priv
->
cgroup
,
params
,
nparams
,
start_cpu
,
ncpus
);
cleanup:
if
(
vm
)
virObjectUnlock
(
vm
);
return
ret
;
}
/* Function Tables */
static
virDriver
lxcDriver
=
{
.
no
=
VIR_DRV_LXC
,
...
...
@@ -5499,6 +5547,7 @@ static virDriver lxcDriver = {
.
nodeSuspendForDuration
=
lxcNodeSuspendForDuration
,
/* 0.9.8 */
.
domainSetMetadata
=
lxcDomainSetMetadata
,
/* 1.1.3 */
.
domainGetMetadata
=
lxcDomainGetMetadata
,
/* 1.1.3 */
.
domainGetCPUStats
=
lxcDomainGetCPUStats
,
/* 1.2.2 */
.
nodeGetMemoryParameters
=
lxcNodeGetMemoryParameters
,
/* 0.10.2 */
.
nodeSetMemoryParameters
=
lxcNodeSetMemoryParameters
,
/* 0.10.2 */
.
domainSendProcessSignal
=
lxcDomainSendProcessSignal
,
/* 1.0.1 */
...
...
src/util/vircgroup.c
浏览文件 @
4b3b2f6c
...
...
@@ -53,11 +53,14 @@
#include "virsystemd.h"
#include "virtypedparam.h"
#include "nodeinfo.h"
#define CGROUP_MAX_VAL 512
#define VIR_FROM_THIS VIR_FROM_CGROUP
#define CGROUP_NB_TOTAL_CPU_STAT_PARAM 3
#define CGROUP_NB_PER_CPU_STAT_PARAM 1
#if defined(__linux__) && defined(HAVE_GETMNTENT_R) && \
defined(_DIRENT_HAVE_D_TYPE) && defined(_SC_CLK_TCK)
...
...
@@ -2824,6 +2827,78 @@ virCgroupDenyDevicePath(virCgroupPtr group, const char *path, int perms)
}
int
virCgroupGetPercpuStats
(
virCgroupPtr
group
,
virTypedParameterPtr
params
,
unsigned
int
nparams
,
int
start_cpu
,
unsigned
int
ncpus
)
{
int
rv
=
-
1
;
size_t
i
;
int
id
,
max_id
;
char
*
pos
;
char
*
buf
=
NULL
;
virTypedParameterPtr
ent
;
int
param_idx
;
unsigned
long
long
cpu_time
;
/* return the number of supported params */
if
(
nparams
==
0
&&
ncpus
!=
0
)
return
CGROUP_NB_PER_CPU_STAT_PARAM
;
/* To parse account file, we need to know how many cpus are present. */
max_id
=
nodeGetCPUCount
();
if
(
max_id
<
0
)
return
rv
;
if
(
ncpus
==
0
)
{
/* returns max cpu ID */
rv
=
max_id
;
goto
cleanup
;
}
if
(
start_cpu
>
max_id
)
{
virReportError
(
VIR_ERR_INVALID_ARG
,
_
(
"start_cpu %d larger than maximum of %d"
),
start_cpu
,
max_id
);
goto
cleanup
;
}
/* we get percpu cputime accounting info. */
if
(
virCgroupGetCpuacctPercpuUsage
(
group
,
&
buf
))
goto
cleanup
;
pos
=
buf
;
/* return percpu cputime in index 0 */
param_idx
=
0
;
/* number of cpus to compute */
if
(
start_cpu
>=
max_id
-
ncpus
)
id
=
max_id
-
1
;
else
id
=
start_cpu
+
ncpus
-
1
;
for
(
i
=
0
;
i
<=
id
;
i
++
)
{
if
(
virStrToLong_ull
(
pos
,
&
pos
,
10
,
&
cpu_time
)
<
0
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cpuacct parse error"
));
goto
cleanup
;
}
if
(
i
<
start_cpu
)
continue
;
ent
=
&
params
[(
i
-
start_cpu
)
*
nparams
+
param_idx
];
if
(
virTypedParameterAssign
(
ent
,
VIR_DOMAIN_CPU_STATS_CPUTIME
,
VIR_TYPED_PARAM_ULLONG
,
cpu_time
)
<
0
)
goto
cleanup
;
}
rv
=
nparams
;
cleanup:
VIR_FREE
(
buf
);
return
rv
;
}
int
virCgroupGetDomainTotalCpuStats
(
virCgroupPtr
group
,
...
...
src/util/vircgroup.h
浏览文件 @
4b3b2f6c
...
...
@@ -201,6 +201,13 @@ int virCgroupDenyDevicePath(virCgroupPtr group,
const
char
*
path
,
int
perms
);
int
virCgroupGetPercpuStats
(
virCgroupPtr
group
,
virTypedParameterPtr
params
,
unsigned
int
nparams
,
int
start_cpu
,
unsigned
int
ncpus
);
int
virCgroupGetDomainTotalCpuStats
(
virCgroupPtr
group
,
virTypedParameterPtr
params
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录