Skip to content

Commit 2f88cef

Browse files
committed
uprobe-stress: add uprobe stress-testing tool
Implemented a stress-testing tool for uprobes/uretprobes. It constantly triggers a set of user space functions, in parallel it attached and detached uprobes and uretprobes to random subset of them. To make things more interesting we also randomly and in parallel mmap() /proc/self/exe and fork() process, to trigger all the different code paths in uprobe-related functionality in the kernel. Signed-off-by: Andrii Nakryiko <[email protected]>
1 parent 598ea6c commit 2f88cef

File tree

5 files changed

+856
-1
lines changed

5 files changed

+856
-1
lines changed

Diff for: examples/c/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
/lsm
1515
/cmake-build-debug/
1616
/cmake-build-release/
17+
/uprobe-stress
18+
.gdb_history
19+

Diff for: examples/c/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ INCLUDES := -I$(OUTPUT) -I../../libbpf/include/uapi -I$(dir $(VMLINUX)) -I$(LIBB
2424
CFLAGS := -g -Wall
2525
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
2626

27-
APPS = minimal minimal_legacy bootstrap uprobe kprobe fentry usdt sockfilter tc ksyscall task_iter lsm
27+
APPS = minimal minimal_legacy bootstrap uprobe kprobe fentry usdt sockfilter tc ksyscall task_iter lsm \
28+
uprobe-stress
2829

2930
CARGO ?= $(shell which cargo)
3031
ifeq ($(strip $(CARGO)),)

Diff for: examples/c/uprobe-stress.bpf.c

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2+
#include "vmlinux.h"
3+
#include <bpf/bpf_helpers.h>
4+
#include <bpf/bpf_tracing.h>
5+
#include "uprobe-stress.h"
6+
7+
char LICENSE[] SEC("license") = "Dual BSD/GPL";
8+
9+
struct counter enter_hits[MAX_CPUS];
10+
struct counter exit_hits[MAX_CPUS];
11+
12+
SEC("uprobe.multi")
13+
int uprobe(struct pt_regs *ctx)
14+
{
15+
int cpu = bpf_get_smp_processor_id();
16+
17+
__sync_add_and_fetch(&enter_hits[cpu & CPU_MASK].value, 1);
18+
19+
return 0;
20+
}
21+
22+
SEC("uretprobe.multi")
23+
int uretprobe(struct pt_regs *ctx)
24+
{
25+
int cpu = bpf_get_smp_processor_id();
26+
27+
__sync_add_and_fetch(&exit_hits[cpu & CPU_MASK].value, 1);
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)