Skip to content

Commit ba1c9d3

Browse files
dtcccchtejun
authored andcommitted
sched_ext: Use btf_ids to resolve task_struct
Save the searching time during bpf_scx_init. Signed-off-by: Tianchen Ding <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 161853a commit ba1c9d3

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

kernel/sched/ext.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5324,7 +5324,6 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
53245324

53255325
extern struct btf *btf_vmlinux;
53265326
static const struct btf_type *task_struct_type;
5327-
static u32 task_struct_type_id;
53285327

53295328
static bool set_arg_maybe_null(const char *op, int arg_n, int off, int size,
53305329
enum bpf_access_type type,
@@ -5376,7 +5375,7 @@ static bool set_arg_maybe_null(const char *op, int arg_n, int off, int size,
53765375
*/
53775376
info->reg_type = PTR_MAYBE_NULL | PTR_TO_BTF_ID | PTR_TRUSTED;
53785377
info->btf = btf_vmlinux;
5379-
info->btf_id = task_struct_type_id;
5378+
info->btf_id = btf_tracing_ids[BTF_TRACING_TYPE_TASK];
53805379

53815380
return true;
53825381
}
@@ -5528,13 +5527,7 @@ static void bpf_scx_unreg(void *kdata, struct bpf_link *link)
55285527

55295528
static int bpf_scx_init(struct btf *btf)
55305529
{
5531-
s32 type_id;
5532-
5533-
type_id = btf_find_by_name_kind(btf, "task_struct", BTF_KIND_STRUCT);
5534-
if (type_id < 0)
5535-
return -EINVAL;
5536-
task_struct_type = btf_type_by_id(btf, type_id);
5537-
task_struct_type_id = type_id;
5530+
task_struct_type = btf_type_by_id(btf, btf_tracing_ids[BTF_TRACING_TYPE_TASK]);
55385531

55395532
return 0;
55405533
}

0 commit comments

Comments
 (0)