Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
16895fc2
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
16895fc2
编写于
9月 09, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cpus: add support nano cpus
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
16474cd9
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
195 addition
and
16 deletion
+195
-16
src/client/connect/pack_config.c
src/client/connect/pack_config.c
+5
-0
src/client/libisula.h
src/client/libisula.h
+1
-0
src/cmd/command_parser.c
src/cmd/command_parser.c
+32
-0
src/cmd/command_parser.h
src/cmd/command_parser.h
+2
-0
src/cmd/isula/base/create.c
src/cmd/isula/base/create.c
+3
-0
src/cmd/isula/base/create.h
src/cmd/isula/base/create.h
+3
-1
src/cmd/isula/client_arguments.h
src/cmd/isula/client_arguments.h
+1
-0
src/cmd/isula/extend/update.c
src/cmd/isula/extend/update.c
+2
-0
src/cmd/isula/extend/update.h
src/cmd/isula/extend/update.h
+3
-1
src/daemon/common/sysinfo.c
src/daemon/common/sysinfo.c
+3
-0
src/daemon/common/sysinfo.h
src/daemon/common/sysinfo.h
+1
-1
src/daemon/executor/container_cb/execution_extend.c
src/daemon/executor/container_cb/execution_extend.c
+42
-2
src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
...odules/image/oci/storage/layer_store/graphdriver/driver.c
+2
-2
src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.h
...odules/image/oci/storage/layer_store/graphdriver/driver.h
+2
-2
src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
...torage/layer_store/graphdriver/overlay2/driver_overlay2.c
+2
-2
src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
...torage/layer_store/graphdriver/overlay2/driver_overlay2.h
+1
-1
src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
+10
-0
src/daemon/modules/spec/specs.c
src/daemon/modules/spec/specs.c
+29
-0
src/daemon/modules/spec/verify.c
src/daemon/modules/spec/verify.c
+48
-0
src/utils/cutils/utils_string.c
src/utils/cutils/utils_string.c
+2
-3
src/utils/cutils/utils_string.h
src/utils/cutils/utils_string.h
+1
-1
未找到文件。
src/client/connect/pack_config.c
浏览文件 @
16895fc2
...
...
@@ -598,6 +598,11 @@ static void pack_cgroup_resources_cpu(host_config *dstconfig, const isula_host_c
dstconfig
->
blkio_weight
=
srcconfig
->
cr
->
blkio_weight
;
}
/* cpus */
if
(
srcconfig
->
cr
->
nano_cpus
!=
0
)
{
dstconfig
->
nano_cpus
=
srcconfig
->
cr
->
nano_cpus
;
}
/* cpu shares */
if
(
srcconfig
->
cr
->
cpu_shares
)
{
dstconfig
->
cpu_shares
=
srcconfig
->
cr
->
cpu_shares
;
...
...
src/client/libisula.h
浏览文件 @
16895fc2
...
...
@@ -112,6 +112,7 @@ typedef struct container_cgroup_resources {
int64_t
files_limit
;
int64_t
oom_score_adj
;
int64_t
swappiness
;
int64_t
nano_cpus
;
}
container_cgroup_resources_t
;
typedef
struct
isula_host_config
{
...
...
src/cmd/command_parser.c
浏览文件 @
16895fc2
...
...
@@ -21,6 +21,7 @@
#include <regex.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include "constants.h"
#include "utils.h"
...
...
@@ -551,3 +552,34 @@ int command_convert_swappiness(command_option_t *option, const char *arg)
}
return
0
;
}
int
command_convert_nanocpus
(
command_option_t
*
option
,
const
char
*
arg
)
{
int
ret
=
0
;
char
*
dup
=
NULL
;
if
(
option
==
NULL
)
{
return
-
1
;
}
if
(
!
isdigit
(
arg
[
0
]))
{
COMMAND_ERROR
(
"Invalid value
\"
%s
\"
for flag --%s"
,
arg
,
option
->
large
);
return
EINVALIDARGS
;
}
dup
=
util_strdup_s
(
arg
);
if
(
dup
==
NULL
)
{
COMMAND_ERROR
(
"Invalid value
\"
%s
\"
for flag --%s"
,
arg
,
option
->
large
);
return
EINVALIDARGS
;
}
if
(
util_parse_size_int_and_float
(
arg
,
1e9
,
option
->
data
))
{
COMMAND_ERROR
(
"Invalid value
\"
%s
\"
for flag --%s"
,
arg
,
option
->
large
);
ret
=
EINVALIDARGS
;
goto
out
;
}
out:
free
(
dup
);
return
ret
;
}
src/cmd/command_parser.h
浏览文件 @
16895fc2
...
...
@@ -104,6 +104,8 @@ int check_default_ulimit_type(const char *type);
int
command_convert_swappiness
(
command_option_t
*
option
,
const
char
*
arg
);
int
command_convert_nanocpus
(
command_option_t
*
option
,
const
char
*
arg
);
#ifdef __cplusplus
}
#endif
...
...
src/cmd/isula/base/create.c
浏览文件 @
16895fc2
...
...
@@ -145,6 +145,9 @@ static int request_pack_host_config_cgroup(const struct client_arguments *args,
/* blkio weight */
hostconfig
->
cr
->
blkio_weight
=
args
->
cr
.
blkio_weight
;
/* nano cpus */
hostconfig
->
cr
->
nano_cpus
=
args
->
cr
.
nano_cpus
;
/* cpu shares */
hostconfig
->
cr
->
cpu_shares
=
args
->
cr
.
cpu_shares
;
...
...
src/cmd/isula/base/create.h
浏览文件 @
16895fc2
...
...
@@ -457,7 +457,9 @@ extern "C" {
0, \
&((cmdargs).cr).cpu_rt_runtime, \
"Limit CPU real-time runtime in microseconds.", \
command_convert_llong },
command_convert_llong }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cpus", 0, &((cmdargs).cr).nano_cpus, "Number of CPUs.", \
command_convert_nanocpus },
#define CREATE_EXTEND_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, \
...
...
src/cmd/isula/client_arguments.h
浏览文件 @
16895fc2
...
...
@@ -220,6 +220,7 @@ struct args_cgroup_resources {
int64_t
memory_reservation
;
int64_t
kernel_memory_limit
;
int64_t
swappiness
;
int64_t
nano_cpus
;
};
struct
client_arguments
{
...
...
src/cmd/isula/extend/update.c
浏览文件 @
16895fc2
...
...
@@ -39,6 +39,8 @@ static int pack_update_request(const struct client_arguments *args, struct isula
request
->
updateconfig
->
cr
->
blkio_weight
=
args
->
cr
.
blkio_weight
;
request
->
updateconfig
->
cr
->
nano_cpus
=
args
->
cr
.
nano_cpus
;
request
->
updateconfig
->
cr
->
cpu_shares
=
args
->
cr
.
cpu_shares
;
request
->
updateconfig
->
cr
->
cpu_period
=
args
->
cr
.
cpu_period
;
...
...
src/cmd/isula/extend/update.h
浏览文件 @
16895fc2
...
...
@@ -106,7 +106,9 @@ extern "C" {
0, \
&((cmdargs).cr).cpu_rt_runtime, \
"Limit CPU real-time runtime in microseconds.", \
command_convert_llong },
command_convert_llong }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cpus", 0, &((cmdargs).cr).nano_cpus, "Number of CPUs.", \
command_convert_nanocpus },
extern
const
char
g_cmd_update_desc
[];
extern
const
char
g_cmd_update_usage
[];
...
...
src/daemon/common/sysinfo.c
浏览文件 @
16895fc2
...
...
@@ -18,6 +18,7 @@
#include <limits.h>
#include <dirent.h>
#include <errno.h>
#include <sys/sysinfo.h>
#include "err_msg.h"
#include "sysinfo.h"
...
...
@@ -1170,6 +1171,8 @@ sysinfo_t *get_sys_info(bool quiet)
goto
out
;
}
sysinfo
->
ncpus
=
get_nprocs
();
check_cgroup_mem
(
layers
,
quiet
,
&
sysinfo
->
cgmeminfo
);
check_cgroup_cpu
(
layers
,
quiet
,
&
sysinfo
->
cgcpuinfo
);
check_cgroup_hugetlb
(
layers
,
quiet
,
&
sysinfo
->
hugetlbinfo
);
...
...
src/daemon/common/sysinfo.h
浏览文件 @
16895fc2
...
...
@@ -71,6 +71,7 @@ typedef struct {
}
cgroup_files_info_t
;
typedef
struct
{
int
ncpus
;
cgroup_mem_info_t
cgmeminfo
;
cgroup_cpu_info_t
cgcpuinfo
;
cgroup_hugetlb_info_t
hugetlbinfo
;
...
...
@@ -143,4 +144,3 @@ void free_mounts_info(mountinfo_t **minfos);
#endif
#endif // DAEMON_COMMON_SYSINFO_H
src/daemon/executor/container_cb/execution_extend.c
浏览文件 @
16895fc2
...
...
@@ -834,8 +834,41 @@ static void host_config_restore_unlocking(container_t *cont, host_config *backup
}
}
static
void
update_container_cpu
(
const
host_config
*
hostconfig
,
host_config
*
chostconfig
)
static
int
update_container_cpu
(
const
host_config
*
hostconfig
,
host_config
*
chostconfig
)
{
int
ret
=
0
;
if
(
hostconfig
->
nano_cpus
>
0
&&
chostconfig
->
cpu_period
>
0
)
{
ERROR
(
"Conflicting options: Nano CPUs cannot be updated as CPU Period has already been set"
);
isulad_set_error_message
(
"Conflicting options: Nano CPUs cannot be updated as CPU Period has already been set"
);
ret
=
-
1
;
goto
out
;
}
if
(
hostconfig
->
nano_cpus
>
0
&&
chostconfig
->
cpu_quota
>
0
)
{
ERROR
(
"Conflicting options: Nano CPUs cannot be updated as CPU Quota has already been set"
);
isulad_set_error_message
(
"Conflicting options: Nano CPUs cannot be updated as CPU Quota has already been set"
);
ret
=
-
1
;
goto
out
;
}
if
(
hostconfig
->
cpu_period
>
0
&&
chostconfig
->
nano_cpus
>
0
)
{
ERROR
(
"Conflicting options: CPU Period cannot be updated as NanoCPUs has already been set"
);
isulad_set_error_message
(
"Conflicting options: CPU Period cannot be updated as NanoCPUs has already been set"
);
ret
=
-
1
;
goto
out
;
}
if
(
hostconfig
->
cpu_quota
>
0
&&
chostconfig
->
nano_cpus
>
0
)
{
ERROR
(
"Conflicting options: CPU Quota cannot be updated as NanoCPUs has already been set"
);
isulad_set_error_message
(
"Conflicting options: CPU Quota cannot be updated as NanoCPUs has already been set"
);
ret
=
-
1
;
goto
out
;
}
if
(
hostconfig
->
nano_cpus
!=
0
)
{
chostconfig
->
nano_cpus
=
hostconfig
->
nano_cpus
;
}
if
(
hostconfig
->
cpu_shares
!=
0
)
{
chostconfig
->
cpu_shares
=
hostconfig
->
cpu_shares
;
}
...
...
@@ -859,6 +892,9 @@ static void update_container_cpu(const host_config *hostconfig, host_config *cho
if
(
hostconfig
->
cpu_realtime_runtime
!=
0
)
{
chostconfig
->
cpu_realtime_runtime
=
hostconfig
->
cpu_realtime_runtime
;
}
out:
return
ret
;
}
static
int
update_container_memory
(
const
char
*
id
,
const
host_config
*
hostconfig
,
host_config
*
chostconfig
)
...
...
@@ -932,7 +968,11 @@ static int update_container(const container_t *cont, const host_config *hostconf
chostconfig
->
blkio_weight
=
hostconfig
->
blkio_weight
;
}
update_container_cpu
(
hostconfig
,
chostconfig
);
ret
=
update_container_cpu
(
hostconfig
,
chostconfig
);
if
(
ret
!=
0
)
{
ret
=
-
1
;
goto
out
;
}
ret
=
update_container_memory
(
id
,
hostconfig
,
chostconfig
);
if
(
ret
!=
0
)
{
...
...
src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
浏览文件 @
16895fc2
...
...
@@ -8,8 +8,8 @@
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author:
tany
ifeng
* Create: 20
17-11
-22
* Author:
l
ifeng
* Create: 20
20-04
-22
* Description: provide image functions
******************************************************************************/
...
...
src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.h
浏览文件 @
16895fc2
...
...
@@ -8,8 +8,8 @@
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author:
tany
ifeng
* Create: 20
19-04-0
2
* Author:
l
ifeng
* Create: 20
20-04-2
2
* Description: provide graphdriver function definition
******************************************************************************/
#ifndef DAEMON_MODULES_IMAGE_OCI_STORAGE_LAYER_STORE_GRAPHDRIVER_DRIVER_H
...
...
src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
浏览文件 @
16895fc2
...
...
@@ -8,8 +8,8 @@
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author:
tany
ifeng
* Create: 20
19
-04-02
* Author:
l
ifeng
* Create: 20
20
-04-02
* Description: provide overlay2 function definition
******************************************************************************/
#include "driver_overlay2.h"
...
...
src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
浏览文件 @
16895fc2
...
...
@@ -8,7 +8,7 @@
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author:
tany
ifeng
* Author:
l
ifeng
* Create: 2019-04-02
* Description: provide overlay2 function definition
******************************************************************************/
...
...
src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
浏览文件 @
16895fc2
...
...
@@ -504,6 +504,9 @@ out:
static
void
to_engine_resources
(
const
host_config
*
hostconfig
,
struct
engine_cgroup_resources
*
cr
)
{
uint64_t
period
=
0
;
int64_t
quota
=
0
;
if
(
hostconfig
==
NULL
||
cr
==
NULL
)
{
return
;
}
...
...
@@ -520,6 +523,13 @@ static void to_engine_resources(const host_config *hostconfig, struct engine_cgr
cr
->
kernel_memory_limit
=
(
uint64_t
)
hostconfig
->
kernel_memory
;
cr
->
cpurt_period
=
hostconfig
->
cpu_realtime_period
;
cr
->
cpurt_runtime
=
hostconfig
->
cpu_realtime_runtime
;
if
(
hostconfig
->
nano_cpus
>
0
)
{
period
=
(
uint64_t
)(
100
*
Time_Milli
/
Time_Micro
);
quota
=
hostconfig
->
nano_cpus
*
(
int64_t
)
period
/
1e9
;
cr
->
cpu_period
=
period
;
cr
->
cpu_quota
=
(
uint64_t
)
quota
;
}
}
int
rt_lcr_update
(
const
char
*
id
,
const
char
*
runtime
,
const
rt_update_params_t
*
params
)
...
...
src/daemon/modules/spec/specs.c
浏览文件 @
16895fc2
...
...
@@ -901,10 +901,39 @@ static int merge_hostname(oci_runtime_spec *oci_spec, const host_config *host_sp
return
0
;
}
static
int
merge_nanocpus
(
oci_runtime_spec
*
oci_spec
,
int64_t
nanocpus
)
{
int
ret
=
0
;
uint64_t
period
=
0
;
int64_t
quota
=
0
;
ret
=
make_sure_oci_spec_linux_resources_cpu
(
oci_spec
);
if
(
ret
<
0
)
{
goto
out
;
}
period
=
(
uint64_t
)(
100
*
Time_Milli
/
Time_Micro
);
quota
=
nanocpus
*
(
int64_t
)
period
/
1e9
;
oci_spec
->
linux
->
resources
->
cpu
->
quota
=
quota
;
oci_spec
->
linux
->
resources
->
cpu
->
period
=
period
;
out:
return
ret
;
}
static
int
merge_conf_cgroup_cpu_int64
(
oci_runtime_spec
*
oci_spec
,
const
host_config
*
host_spec
)
{
int
ret
=
0
;
if
(
host_spec
->
nano_cpus
>
0
)
{
ret
=
merge_nanocpus
(
oci_spec
,
host_spec
->
nano_cpus
);
if
(
ret
!=
0
)
{
ERROR
(
"Failed to merge cgroup nano cpus"
);
goto
out
;
}
}
/* cpu shares */
if
(
host_spec
->
cpu_shares
!=
0
)
{
ret
=
merge_cpu_shares
(
oci_spec
,
host_spec
->
cpu_shares
);
...
...
src/daemon/modules/spec/verify.c
浏览文件 @
16895fc2
...
...
@@ -1724,10 +1724,58 @@ out:
return
ret
;
}
static
int
verify_nano_cpus
(
const
sysinfo_t
*
sysinfo
,
const
host_config
*
hostconfig
)
{
int
ret
=
0
;
if
(
hostconfig
->
nano_cpus
==
0
)
{
return
0
;
}
if
(
hostconfig
->
nano_cpus
>
0
&&
hostconfig
->
cpu_period
>
0
)
{
ERROR
(
"Conflicting options: Nano CPUs and CPU Period cannot both be set."
);
isulad_set_error_message
(
"Conflicting options: Nano CPUs and CPU Period cannot both be set."
);
ret
=
-
1
;
goto
out
;
}
if
(
hostconfig
->
nano_cpus
>
0
&&
hostconfig
->
cpu_quota
>
0
)
{
ERROR
(
"Conflicting options: Nano CPUs and CPU Quota cannot both be set."
);
isulad_set_error_message
(
"Conflicting options: Nano CPUs and CPU Quota cannot both be set."
);
ret
=
-
1
;
goto
out
;
}
if
(
hostconfig
->
nano_cpus
>
0
&&
(
!
(
sysinfo
->
cgcpuinfo
.
cpu_cfs_quota
)
||
!
(
sysinfo
->
cgcpuinfo
.
cpu_cfs_period
)))
{
ERROR
(
"NanoCPUs can not be set, as your kernel does not support CPU cfs period/quota or the cgroup is not mounted."
);
isulad_set_error_message
(
"NanoCPUs can not be set, as your kernel does not support CPU cfs period/quota or the cgroup is not mounted."
);
ret
=
-
1
;
goto
out
;
}
if
(
hostconfig
->
nano_cpus
<
0
||
(
hostconfig
->
nano_cpus
>
(
sysinfo
->
ncpus
*
1e9
)))
{
ERROR
(
"Range of CPUs is from 0.01 to %d.00, as there are only %d CPUs available"
,
sysinfo
->
ncpus
,
sysinfo
->
ncpus
);
isulad_set_error_message
(
"Range of CPUs is from 0.01 to %d.00, as there are only %d CPUs available"
,
sysinfo
->
ncpus
,
sysinfo
->
ncpus
);
ret
=
-
1
;
goto
out
;
}
out:
return
ret
;
}
static
int
host_config_settings_cpu
(
const
sysinfo_t
*
sysinfo
,
const
host_config
*
hostconfig
)
{
int
ret
=
0
;
ret
=
verify_nano_cpus
(
sysinfo
,
hostconfig
);
if
(
ret
!=
0
)
{
goto
out
;
}
ret
=
verify_cpu_realtime
(
sysinfo
,
hostconfig
->
cpu_realtime_period
,
hostconfig
->
cpu_realtime_runtime
);
if
(
ret
!=
0
)
{
goto
out
;
...
...
src/utils/cutils/utils_string.c
浏览文件 @
16895fc2
...
...
@@ -182,7 +182,7 @@ static int parse_unit_multiple(const char *unit, int64_t *mltpl)
return
-
EINVAL
;
}
static
int
util_parse_size_int_and_float
(
const
char
*
numstr
,
int64_t
mlt
,
int64_t
*
converted
)
int
util_parse_size_int_and_float
(
const
char
*
numstr
,
int64_t
mlt
,
int64_t
*
converted
)
{
long
long
int_size
=
0
;
double
float_size
=
0
;
...
...
@@ -824,8 +824,7 @@ bool util_has_suffix(const char *str, const char *suffix)
return
true
;
}
int
util_string_array_unique
(
const
char
**
elements
,
size_t
length
,
char
***
unique_elements
,
size_t
*
unique_elements_len
)
int
util_string_array_unique
(
const
char
**
elements
,
size_t
length
,
char
***
unique_elements
,
size_t
*
unique_elements_len
)
{
int
ret
=
0
;
size_t
i
;
...
...
src/utils/cutils/utils_string.h
浏览文件 @
16895fc2
...
...
@@ -81,9 +81,9 @@ int util_string_array_unique(const char **elements, size_t length, char ***uniqu
int
util_parse_bool_string
(
const
char
*
str
,
bool
*
converted
);
int
util_parse_size_int_and_float
(
const
char
*
numstr
,
int64_t
mlt
,
int64_t
*
converted
);
#ifdef __cplusplus
}
#endif
#endif // UTILS_CUTILS_UTILS_STRING_H
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录