提交 e4a9bbfa 编写于 作者: C Chen Hui 提交者: Zheng Zengkai

sched: programmable: Add convenient helper functions to convert sched entity

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5KUFB
CVE: NA

--------------------------------

Add three helper functions:
1) bpf_sched_entity_is_task is to check whether the sched entity
is a task struct.
2) bpf_sched_entity_to_task is to change the sched entity to a
task struct.
3) bpf_sched_entity_to_tg is to change the sched entity to a task
group.
Signed-off-by: NChen Hui <judy.chenhui@huawei.com>
Signed-off-by: NRen Zhijie <renzhijie2@huawei.com>
上级 09287851
...@@ -3792,6 +3792,24 @@ union bpf_attr { ...@@ -3792,6 +3792,24 @@ union bpf_attr {
* different workloads. * different workloads.
* Return * Return
* Task tag, if used, 0 as default tag, or a negative error in case of failure. * Task tag, if used, 0 as default tag, or a negative error in case of failure.
*
* long bpf_sched_entity_is_task(struct sched_entity *se)
* Description
* Checks whether the sched entity is a task.
* Return
* 1 if true, 0 otherwise.
*
* struct task_struct *bpf_sched_entity_to_task(struct sched_entity *se)
* Description
* Return task struct of *se* if se is a task.
* Return
* Task struct if se is a task, NULL otherwise.
*
* struct task_group *bpf_sched_entity_to_tg(struct sched_entity *se)
* Description
* Return task group of *se* if se is a task group.
* Return
* Task struct if se is a task group, NULL otherwise.
*/ */
#define __BPF_FUNC_MAPPER(FN) \ #define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \ FN(unspec), \
...@@ -3957,6 +3975,9 @@ union bpf_attr { ...@@ -3957,6 +3975,9 @@ union bpf_attr {
FN(sched_entity_belongs_to_cgrp), \ FN(sched_entity_belongs_to_cgrp), \
FN(sched_tg_tag_of), \ FN(sched_tg_tag_of), \
FN(sched_task_tag_of), \ FN(sched_task_tag_of), \
FN(sched_entity_is_task), \
FN(sched_entity_to_task), \
FN(sched_entity_to_tg), \
/* */ /* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper /* integer value in 'imm' field of BPF_CALL instruction selects which helper
......
...@@ -152,6 +152,61 @@ const struct bpf_func_proto bpf_sched_task_tag_of_proto = { ...@@ -152,6 +152,61 @@ const struct bpf_func_proto bpf_sched_task_tag_of_proto = {
.arg1_btf_id = &btf_sched_task_ids[0], .arg1_btf_id = &btf_sched_task_ids[0],
}; };
BPF_CALL_1(bpf_sched_entity_is_task, struct sched_entity *, se)
{
return entity_is_task(se) ? 1 : 0;
}
static const struct bpf_func_proto bpf_sched_entity_is_task_proto = {
.func = bpf_sched_entity_is_task,
.gpl_only = false,
.ret_type = RET_INTEGER,
.arg1_type = ARG_PTR_TO_BTF_ID,
.arg1_btf_id = &btf_sched_entity_ids[0],
};
BPF_CALL_1(bpf_sched_entity_to_task, struct sched_entity *, se)
{
if (entity_is_task(se)) {
struct task_struct *tsk = task_of(se);
return (unsigned long)tsk;
}
return (unsigned long)NULL;
}
static const struct bpf_func_proto bpf_sched_entity_to_task_proto = {
.func = bpf_sched_entity_to_task,
.gpl_only = false,
.ret_type = RET_PTR_TO_BTF_ID_OR_NULL,
.ret_btf_id = &btf_sched_task_ids[0],
.arg1_type = ARG_PTR_TO_BTF_ID,
.arg1_btf_id = &btf_sched_entity_ids[0],
};
BPF_CALL_1(bpf_sched_entity_to_tg, struct sched_entity *, se)
{
#if CONFIG_FAIR_GROUP_SCHED
if (!entity_is_task(se)) {
struct task_group *tg = group_cfs_rq(se)->tg;
return (unsigned long)tg;
}
#endif
return (unsigned long)NULL;
}
static const struct bpf_func_proto bpf_sched_entity_to_tg_proto = {
.func = bpf_sched_entity_to_tg,
.gpl_only = false,
.ret_type = RET_PTR_TO_BTF_ID_OR_NULL,
.ret_btf_id = &btf_sched_tg_ids[0],
.arg1_type = ARG_PTR_TO_BTF_ID,
.arg1_btf_id = &btf_sched_entity_ids[0],
};
static const struct bpf_func_proto * static const struct bpf_func_proto *
bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{ {
...@@ -164,6 +219,12 @@ bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) ...@@ -164,6 +219,12 @@ bpf_sched_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
return &bpf_sched_entity_to_cgrpid_proto; return &bpf_sched_entity_to_cgrpid_proto;
case BPF_FUNC_sched_entity_belongs_to_cgrp: case BPF_FUNC_sched_entity_belongs_to_cgrp:
return &bpf_sched_entity_belongs_to_cgrp_proto; return &bpf_sched_entity_belongs_to_cgrp_proto;
case BPF_FUNC_sched_entity_is_task:
return &bpf_sched_entity_is_task_proto;
case BPF_FUNC_sched_entity_to_task:
return &bpf_sched_entity_to_task_proto;
case BPF_FUNC_sched_entity_to_tg:
return &bpf_sched_entity_to_tg_proto;
default: default:
return bpf_base_func_proto(func_id); return bpf_base_func_proto(func_id);
} }
......
...@@ -3792,6 +3792,24 @@ union bpf_attr { ...@@ -3792,6 +3792,24 @@ union bpf_attr {
* different workloads. * different workloads.
* Return * Return
* Task tag, if used, 0 as default tag, or a negative error in case of failure. * Task tag, if used, 0 as default tag, or a negative error in case of failure.
*
* long bpf_sched_entity_is_task(struct sched_entity *se)
* Description
* Checks whether the sched entity is a task.
* Return
* 1 if true, 0 otherwise.
*
* struct task_struct *bpf_sched_entity_to_task(struct sched_entity *se)
* Description
* Return task struct of *se* if se is a task.
* Return
* Task struct if se is a task, NULL otherwise.
*
* struct task_group *bpf_sched_entity_to_tg(struct sched_entity *se)
* Description
* Return task group of *se* if se is a task group.
* Return
* Task struct if se is a task group, NULL otherwise.
*/ */
#define __BPF_FUNC_MAPPER(FN) \ #define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \ FN(unspec), \
...@@ -3957,6 +3975,9 @@ union bpf_attr { ...@@ -3957,6 +3975,9 @@ union bpf_attr {
FN(sched_entity_belongs_to_cgrp), \ FN(sched_entity_belongs_to_cgrp), \
FN(sched_tg_tag_of), \ FN(sched_tg_tag_of), \
FN(sched_task_tag_of), \ FN(sched_task_tag_of), \
FN(sched_entity_is_task), \
FN(sched_entity_to_task), \
FN(sched_entity_to_tg), \
/* */ /* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper /* integer value in 'imm' field of BPF_CALL instruction selects which helper
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册