Skip to content

Commit 27f2992

Browse files
committed
perf augmented_syscalls: Switch to using a struct for the syscalls map values
We'll start adding more perf-syscall stuff, so lets do this prep step so that the next ones are just about adding more fields. Run it with the .c file once to cache the .o file: # trace --filter-pids 2834,2199 -e openat,augmented_raw_syscalls.c LLVM: dumping augmented_raw_syscalls.o 0.000 ( 0.021 ms): tmux: server/4952 openat(dfd: CWD, filename: /proc/5691/cmdline ) = 11 349.807 ( 0.040 ms): DNS Res~er #39/11082 openat(dfd: CWD, filename: /etc/hosts, flags: CLOEXEC ) = 44 4988.759 ( 0.052 ms): gsd-color/2431 openat(dfd: CWD, filename: /etc/localtime ) = 18 4988.976 ( 0.029 ms): gsd-color/2431 openat(dfd: CWD, filename: /etc/localtime ) = 18 ^C[root@quaco bpf]# From now on, we can use just the newly built .o file, skipping the compilation step for a faster startup: # trace --filter-pids 2834,2199 -e openat,augmented_raw_syscalls.o 0.000 ( 0.046 ms): DNS Res~er #39/11088 openat(dfd: CWD, filename: /etc/hosts, flags: CLOEXEC ) = 44 1946.408 ( 0.190 ms): systemd/1 openat(dfd: CWD, filename: /proc/1071/cgroup, flags: CLOEXEC ) = 20 1946.792 ( 0.215 ms): systemd/1 openat(dfd: CWD, filename: /proc/954/cgroup, flags: CLOEXEC ) = 20 ^C# Now on to do the same in the builtin-trace.c side of things. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-k8mwu04l8es29rje5loq9vg7@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 61d0071 commit 27f2992

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tools/perf/examples/bpf/augmented_raw_syscalls.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ struct bpf_map SEC("maps") __augmented_syscalls__ = {
2626
.max_entries = __NR_CPUS__,
2727
};
2828

29+
struct syscall {
30+
bool enabled;
31+
};
32+
2933
struct bpf_map SEC("maps") syscalls = {
3034
.type = BPF_MAP_TYPE_ARRAY,
3135
.key_size = sizeof(int),
32-
.value_size = sizeof(bool),
36+
.value_size = sizeof(struct syscall),
3337
.max_entries = 512,
3438
};
3539

@@ -63,7 +67,7 @@ int sys_enter(struct syscall_enter_args *args)
6367
struct syscall_enter_args args;
6468
struct augmented_filename filename;
6569
} augmented_args;
66-
bool *enabled;
70+
struct syscall *syscall;
6771
unsigned int len = sizeof(augmented_args);
6872
const void *filename_arg = NULL;
6973

@@ -72,8 +76,8 @@ int sys_enter(struct syscall_enter_args *args)
7276

7377
probe_read(&augmented_args.args, sizeof(augmented_args.args), args);
7478

75-
enabled = bpf_map_lookup_elem(&syscalls, &augmented_args.args.syscall_nr);
76-
if (enabled == NULL || !*enabled)
79+
syscall = bpf_map_lookup_elem(&syscalls, &augmented_args.args.syscall_nr);
80+
if (syscall == NULL || !syscall->enabled)
7781
return 0;
7882
/*
7983
* Yonghong and Edward Cree sayz:
@@ -144,15 +148,15 @@ SEC("raw_syscalls:sys_exit")
144148
int sys_exit(struct syscall_exit_args *args)
145149
{
146150
struct syscall_exit_args exit_args;
147-
bool *enabled;
151+
struct syscall *syscall;
148152

149153
if (pid_filter__has(&pids_filtered, getpid()))
150154
return 0;
151155

152156
probe_read(&exit_args, sizeof(exit_args), args);
153157

154-
enabled = bpf_map_lookup_elem(&syscalls, &exit_args.syscall_nr);
155-
if (enabled == NULL || !*enabled)
158+
syscall = bpf_map_lookup_elem(&syscalls, &exit_args.syscall_nr);
159+
if (syscall == NULL || !syscall->enabled)
156160
return 0;
157161

158162
return 1;

0 commit comments

Comments
 (0)