Skip to content

Commit dd86578

Browse files
olsajirianakryiko
authored andcommitted
bpf: Count missed stats in trace_call_bpf
Increase misses stats in case bpf array execution is skipped because of recursion check in trace_call_bpf. Adding bpf_prog_inc_misses_counters that increase misses counts for all bpf programs in bpf_prog_array. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Tested-by: Song Liu <song@kernel.org> Reviewed-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/bpf/20230920213145.1941596-5-jolsa@kernel.org
1 parent 3acf8ac commit dd86578

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

include/linux/bpf.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,6 +2922,22 @@ static inline int sock_map_bpf_prog_query(const union bpf_attr *attr,
29222922
#endif /* CONFIG_BPF_SYSCALL */
29232923
#endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */
29242924

2925+
static __always_inline void
2926+
bpf_prog_inc_misses_counters(const struct bpf_prog_array *array)
2927+
{
2928+
const struct bpf_prog_array_item *item;
2929+
struct bpf_prog *prog;
2930+
2931+
if (unlikely(!array))
2932+
return;
2933+
2934+
item = &array->items[0];
2935+
while ((prog = READ_ONCE(item->prog))) {
2936+
bpf_prog_inc_misses_counter(prog);
2937+
item++;
2938+
}
2939+
}
2940+
29252941
#if defined(CONFIG_INET) && defined(CONFIG_BPF_SYSCALL)
29262942
void bpf_sk_reuseport_detach(struct sock *sk);
29272943
int bpf_fd_reuseport_array_lookup_elem(struct bpf_map *map, void *key,

kernel/trace/bpf_trace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
117117
* and don't send kprobe event into ring-buffer,
118118
* so return zero here
119119
*/
120+
rcu_read_lock();
121+
bpf_prog_inc_misses_counters(rcu_dereference(call->prog_array));
122+
rcu_read_unlock();
120123
ret = 0;
121124
goto out;
122125
}

0 commit comments

Comments
 (0)