Skip to contentSkip to conversation

perf trace: Handle task exit in BPF syscall summary

PATCH Applied Namhyung Kim 3 participants 4 messages Feb 26 – Feb 27 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf trace: Handle task exit in BPF syscall summary

Some system calls never return because it'd terminate the calling thread. Let's hook the task exit path and update the duration of the last syscall.

Before:

  $ sudo perf trace -as --bpf-summary -- true |& grep exit
  (nothing)

After:

  $ sudo perf trace -as --bpf-summary -- true |& grep exit
     exit_group             1      0     0.004     0.004     0.004     0.004      0.00%
---
 tools/perf/util/bpf_skel/syscall_summary.bpf.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tools/perf/util/bpf_skel/syscall_summary.bpf.c +15 -3
index 1bcd066a5199a476..4172f3c9fc483955 100644
@@ -118,13 +118,11 @@ int sys_enter(u64 *ctx)
 	return 0;
 }
 
-SEC("tp_btf/sys_exit")
-int sys_exit(u64 *ctx)
+static int do_exit(long ret)
 {
 	int tid;
 	int key = 0;
 	u64 cgroup = 0;
-	long ret = ctx[1]; /* return value of the syscall */
 	struct syscall_trace *st;
 	s64 delta;
 
@@ -150,4 +148,18 @@ int sys_exit(u64 *ctx)
 	return 0;
 }
 
+SEC("tp_btf/sys_exit")
+int sys_exit(u64 *ctx)
+{
+	long ret = ctx[1]; /* return value of the syscall */
+
+	return do_exit(ret);
+}
+
+SEC("tp_btf/sched_process_exit")
+int process_exit(u64 *ctx)
+{
+	return do_exit(0);
+}
+
 char _license[] SEC("license") = "GPL";
Signature · 1 line
2.53.0.414.gf7e9f6c205-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Namhyung Kim

Some system calls never return because it'd terminate the calling thread. Let's hook the task exit path and update the duration of the last syscall.

Before:

Quoted 8 lines
  $ sudo perf trace -as --bpf-summary -- true |& grep exit
  (nothing)

After:

  $ sudo perf trace -as --bpf-summary -- true |& grep exit
     exit_group             1      0     0.004     0.004     0.004     0.004      0.00%

Thanks,
Ian

Quoted 45 lines
---
 tools/perf/util/bpf_skel/syscall_summary.bpf.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tools/perf/util/bpf_skel/syscall_summary.bpf.c +15 -4
index 1bcd066a5199a476..4172f3c9fc483955 100644
@@ -118,13 +118,11 @@ int sys_enter(u64 *ctx)
        return 0;
 }
 
-SEC("tp_btf/sys_exit")
-int sys_exit(u64 *ctx)
+static int do_exit(long ret)
 {
        int tid;
        int key = 0;
        u64 cgroup = 0;
-       long ret = ctx[1]; /* return value of the syscall */
        struct syscall_trace *st;
        s64 delta;
 
@@ -150,4 +148,18 @@ int sys_exit(u64 *ctx)
        return 0;
 }
 
+SEC("tp_btf/sys_exit")
+int sys_exit(u64 *ctx)
+{
+       long ret = ctx[1]; /* return value of the syscall */
+
+       return do_exit(ret);
+}
+
+SEC("tp_btf/sched_process_exit")
+int process_exit(u64 *ctx)
+{
+       return do_exit(0);
+}
+
 char _license[] SEC("license") = "GPL";
--

2.53.0.414.gf7e9f6c205-goog

Acked-by on v1 1/1
#2 lore raw
In reply to Namhyung Kim

Hi Namhyung,

Quoted 6 lines · Namhyung Kim

Some system calls never return because it'd terminate the calling thread. Let's hook the task exit path and update the duration of the last syscall.

Before:

Quoted 8 lines
  $ sudo perf trace -as --bpf-summary -- true |& grep exit
  (nothing)

After:

  $ sudo perf trace -as --bpf-summary -- true |& grep exit
     exit_group             1      0     0.004     0.004     0.004     0.004      0.00%

Thanks,
Howard

Quoted 45 lines
---
 tools/perf/util/bpf_skel/syscall_summary.bpf.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tools/perf/util/bpf_skel/syscall_summary.bpf.c +15 -4
index 1bcd066a5199a476..4172f3c9fc483955 100644
@@ -118,13 +118,11 @@ int sys_enter(u64 *ctx)
        return 0;
 }
 
-SEC("tp_btf/sys_exit")
-int sys_exit(u64 *ctx)
+static int do_exit(long ret)
 {
        int tid;
        int key = 0;
        u64 cgroup = 0;
-       long ret = ctx[1]; /* return value of the syscall */
        struct syscall_trace *st;
        s64 delta;
 
@@ -150,4 +148,18 @@ int sys_exit(u64 *ctx)
        return 0;
 }
 
+SEC("tp_btf/sys_exit")
+int sys_exit(u64 *ctx)
+{
+       long ret = ctx[1]; /* return value of the syscall */
+
+       return do_exit(ret);
+}
+
+SEC("tp_btf/sched_process_exit")
+int process_exit(u64 *ctx)
+{
+       return do_exit(0);
+}
+
 char _license[] SEC("license") = "GPL";
--

2.53.0.414.gf7e9f6c205-goog

author maintainer Applied
#3 lore raw
In reply to Namhyung Kim
Quoted 9 lines · Namhyung Kim

Some system calls never return because it'd terminate the calling thread. Let's hook the task exit path and update the duration of the last syscall.

Before:

  $ sudo perf trace -as --bpf-summary -- true |& grep exit
  (nothing)

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung