Skip to content

Commit

Permalink
uprobe-stress: add uprobe stress-testing tool
Browse files Browse the repository at this point in the history
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 <andrii@kernel.org>
  • Loading branch information
anakryiko committed Jul 12, 2024
1 parent 598ea6c commit 2f88cef
Show file tree
Hide file tree
Showing 5 changed files with 856 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/c/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
/lsm
/cmake-build-debug/
/cmake-build-release/
/uprobe-stress
.gdb_history

3 changes: 2 additions & 1 deletion examples/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ INCLUDES := -I$(OUTPUT) -I../../libbpf/include/uapi -I$(dir $(VMLINUX)) -I$(LIBB
CFLAGS := -g -Wall
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)

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

CARGO ?= $(shell which cargo)
ifeq ($(strip $(CARGO)),)
Expand Down
30 changes: 30 additions & 0 deletions examples/c/uprobe-stress.bpf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "uprobe-stress.h"

char LICENSE[] SEC("license") = "Dual BSD/GPL";

struct counter enter_hits[MAX_CPUS];
struct counter exit_hits[MAX_CPUS];

SEC("uprobe.multi")
int uprobe(struct pt_regs *ctx)
{
int cpu = bpf_get_smp_processor_id();

__sync_add_and_fetch(&enter_hits[cpu & CPU_MASK].value, 1);

return 0;
}

SEC("uretprobe.multi")
int uretprobe(struct pt_regs *ctx)
{
int cpu = bpf_get_smp_processor_id();

__sync_add_and_fetch(&exit_hits[cpu & CPU_MASK].value, 1);

return 0;
}
Loading

0 comments on commit 2f88cef

Please sign in to comment.