perf record: Fix BTF type checks in the off-cpu profiling
Subsystems (2)
Namhyung Kim
maintainerPATCH 1/1 perf record: Fix BTF type checks in the off-cpu profiling
The BTF func proto for a tracepoint has one more argument than the actual tracepoint function since it has a context argument at the begining. So it should compare to 5 when the tracepoint has 4 arguments.
typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int);
Also, recent change in the perf tool would use a hand-written minimal vmlinux.h to generate BTF in the skeleton. So it won't have the info of the tracepoint. Anyway it should use the kernel's vmlinux BTF to check the type in the kernel.
--- tools/perf/util/bpf_off_cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/bpf_off_cpu.c +3 -2
@@ -98,7 +98,7 @@ static void off_cpu_finish(void *arg __maybe_unused)/* v5.18 kernel added prev_state arg, so it needs to check the signature */ static void check_sched_switch_args (void ) { -const struct btf *btf =bpf_object__btf (skel->obj); +const struct btf *btf =btf__load_vmlinux_btf ();const struct btf_type *t1, *t2, *t3;u32 type_id;
@@ -116,7 +116,8 @@ static void check_sched_switch_args(void)return ; t3 =btf__type_by_id (btf, t2->type); -if (t3 &&btf_is_func_proto (t3) &&btf_vlen (t3) ==4 ) { +/* btf_trace func proto has one more argument for the context */ +if (t3 &&btf_is_func_proto (t3) &&btf_vlen (t3) ==5 ) {/* new format: pass prev_state as 4th arg */ skel->rodata->has_prev_state = true; }
Signature · 1 line
2.42.0.515.g380fc7ccd1-goog
Quoted 13 lines · Namhyung Kim
The BTF func proto for a tracepoint has one more argument than the actual tracepoint function since it has a context argument at the begining. So it should compare to 5 when the tracepoint has 4 arguments.
typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int);Also, recent change in the perf tool would use a hand-written minimal
vmlinux.hto generate BTF in the skeleton. So it won't have the info of the tracepoint. Anyway it should use the kernel's vmlinux BTF to check the type in the kernel.
Quoted 5 lines
Fixes b36888f71c85 ("perf record: Handle argument change in sched_switch")Cc Song Liu <[email protected]>Cc Hao Luo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Quoted 18 lines
--- tools/perf/util/bpf_off_cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)tools/perf/util/bpf_off_cpu.c +1
-1@@ -98,7 +98,7 @@ static void off_cpu_finish(void *arg __maybe_unused)/* v5.18 kernel added prev_state arg, so it needs to check the signature */ static void check_sched_switch_args (void ) { -const struct btf *btf =bpf_object__btf (skel->obj); +const struct btf *btf =btf__load_vmlinux_btf ();const struct btf_type *t1, *t2, *t3;u32 type_id;
tools/perf/util/bpf_off_cpu.c static void check_sched_switch_args(void) · line 121
Quoted 7 lines
tools/perf/util/bpf_off_cpu.c +2
-1@@ -116,7 +116,8 @@ static void check_sched_switch_args(void)return ; t3 =btf__type_by_id (btf, t2->type); -if (t3 &&btf_is_func_proto (t3) &&btf_vlen (t3) ==4 ) { +/* btf_trace func proto has one more argument for the context */ +if (t3 &&btf_is_func_proto (t3) &&btf_vlen (t3) ==5 ) {/* new format: pass prev_state as 4th arg */
nit: does this comment need updating?
Quoted 5 lines
tools/perf/util/bpf_off_cpu.c +0
-1skel->rodata->has_prev_state = true; } --2.42.0.515.g380fc7ccd1-goog
Namhyung Kim
maintainerHi Ian,
Quoted 15 lines · Ian Rogers
Quoted 13 lines · Namhyung Kim
The BTF func proto for a tracepoint has one more argument than the actual tracepoint function since it has a context argument at the begining. So it should compare to 5 when the tracepoint has 4 arguments.
typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int);Also, recent change in the perf tool would use a hand-written minimal
vmlinux.hto generate BTF in the skeleton. So it won't have the info of the tracepoint. Anyway it should use the kernel's vmlinux BTF to check the type in the kernel.
Quoted 7 lines
Quoted 5 lines
Fixes b36888f71c85 ("perf record: Handle argument change in sched_switch")Cc Song Liu <[email protected]>Cc Hao Luo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Reviewed-by Ian Rogers <[email protected]>
Thanks for the review!
Quoted 21 lines
Quoted 21 lines
--- tools/perf/util/bpf_off_cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)tools/perf/util/bpf_off_cpu.c +1
-1@@ -98,7 +98,7 @@ static void off_cpu_finish(void *arg __maybe_unused)/* v5.18 kernel added prev_state arg, so it needs to check the signature */ static void check_sched_switch_args (void ) { -const struct btf *btf =bpf_object__btf (skel->obj); +const struct btf *btf =btf__load_vmlinux_btf ();const struct btf_type *t1, *t2, *t3;u32 type_id;@@ -116,7 +116,8 @@ static void check_sched_switch_args(void)return ;
Quoted 7 lines
tools/perf/util/bpf_off_cpu.c static void check_sched_switch_args(void) · line 121
Quoted 5 lines
tools/perf/util/bpf_off_cpu.c +2
-1t3 =btf__type_by_id (btf, t2->type); -if (t3 &&btf_is_func_proto (t3) &&btf_vlen (t3) ==4 ) { +/* btf_trace func proto has one more argument for the context */ +if (t3 &&btf_is_func_proto (t3) &&btf_vlen (t3) ==5 ) {/* new format: pass prev_state as 4th arg */ nit: does this comment need updating?
No, it's the 4th arg and the sched_switch is called like.
trace_sched_switch(sched_mode & SM_MASK_PREEMPT, prev, next,prev_state);
Thanks,
Namhyung
Quoted 13 lines · Namhyung Kim
The BTF func proto for a tracepoint has one more argument than the actual tracepoint function since it has a context argument at the begining. So it should compare to 5 when the tracepoint has 4 arguments.
typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int);Also, recent change in the perf tool would use a hand-written minimal
vmlinux.hto generate BTF in the skeleton. So it won't have the info of the tracepoint. Anyway it should use the kernel's vmlinux BTF to check the type in the kernel.
Quoted 5 lines
Fixes b36888f71c85 ("perf record: Handle argument change in sched_switch")Cc Song Liu <[email protected]>Cc Hao Luo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Quoted 15 lines · Song Liu
Quoted 13 lines · Namhyung Kim
The BTF func proto for a tracepoint has one more argument than the actual tracepoint function since it has a context argument at the begining. So it should compare to 5 when the tracepoint has 4 arguments.
typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int);Also, recent change in the perf tool would use a hand-written minimal
vmlinux.hto generate BTF in the skeleton. So it won't have the info of the tracepoint. Anyway it should use the kernel's vmlinux BTF to check the type in the kernel.
Quoted 7 lines
Quoted 5 lines
Fixes b36888f71c85 ("perf record: Handle argument change in sched_switch")Cc Song Liu <[email protected]>Cc Hao Luo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>Acked-by Song Liu <[email protected]>
Applied to perf-tools-next, thanks!