Commit 1175f8de authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: rename and clean up userspace-triggered benchmarks

Rename uprobe-base to more precise usermode-count (it will match other
baseline-like benchmarks, kernel-count and syscall-count). Also use
BENCH_TRIG_USERMODE() macro to define all usermode-based triggering
benchmarks, which include usermode-count and uprobe/uretprobe benchmarks.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240326162151.3981687-2-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 55fc888d
...@@ -491,7 +491,12 @@ extern const struct bench bench_rename_kretprobe; ...@@ -491,7 +491,12 @@ extern const struct bench bench_rename_kretprobe;
extern const struct bench bench_rename_rawtp; extern const struct bench bench_rename_rawtp;
extern const struct bench bench_rename_fentry; extern const struct bench bench_rename_fentry;
extern const struct bench bench_rename_fexit; extern const struct bench bench_rename_fexit;
/* pure counting benchmarks to establish theoretical lmits */
extern const struct bench bench_trig_usermode_count;
extern const struct bench bench_trig_base; extern const struct bench bench_trig_base;
/* kernel-side syscall-triggered benchmarks */
extern const struct bench bench_trig_tp; extern const struct bench bench_trig_tp;
extern const struct bench bench_trig_rawtp; extern const struct bench bench_trig_rawtp;
extern const struct bench bench_trig_kprobe; extern const struct bench bench_trig_kprobe;
...@@ -502,13 +507,15 @@ extern const struct bench bench_trig_fentry; ...@@ -502,13 +507,15 @@ extern const struct bench bench_trig_fentry;
extern const struct bench bench_trig_fexit; extern const struct bench bench_trig_fexit;
extern const struct bench bench_trig_fentry_sleep; extern const struct bench bench_trig_fentry_sleep;
extern const struct bench bench_trig_fmodret; extern const struct bench bench_trig_fmodret;
extern const struct bench bench_trig_uprobe_base;
/* uprobe/uretprobe benchmarks */
extern const struct bench bench_trig_uprobe_nop; extern const struct bench bench_trig_uprobe_nop;
extern const struct bench bench_trig_uretprobe_nop; extern const struct bench bench_trig_uretprobe_nop;
extern const struct bench bench_trig_uprobe_push; extern const struct bench bench_trig_uprobe_push;
extern const struct bench bench_trig_uretprobe_push; extern const struct bench bench_trig_uretprobe_push;
extern const struct bench bench_trig_uprobe_ret; extern const struct bench bench_trig_uprobe_ret;
extern const struct bench bench_trig_uretprobe_ret; extern const struct bench bench_trig_uretprobe_ret;
extern const struct bench bench_rb_libbpf; extern const struct bench bench_rb_libbpf;
extern const struct bench bench_rb_custom; extern const struct bench bench_rb_custom;
extern const struct bench bench_pb_libbpf; extern const struct bench bench_pb_libbpf;
...@@ -539,7 +546,10 @@ static const struct bench *benchs[] = { ...@@ -539,7 +546,10 @@ static const struct bench *benchs[] = {
&bench_rename_rawtp, &bench_rename_rawtp,
&bench_rename_fentry, &bench_rename_fentry,
&bench_rename_fexit, &bench_rename_fexit,
/* pure counting benchmarks for establishing theoretical limits */
&bench_trig_usermode_count,
&bench_trig_base, &bench_trig_base,
/* syscall-driven triggering benchmarks */
&bench_trig_tp, &bench_trig_tp,
&bench_trig_rawtp, &bench_trig_rawtp,
&bench_trig_kprobe, &bench_trig_kprobe,
...@@ -550,7 +560,7 @@ static const struct bench *benchs[] = { ...@@ -550,7 +560,7 @@ static const struct bench *benchs[] = {
&bench_trig_fexit, &bench_trig_fexit,
&bench_trig_fentry_sleep, &bench_trig_fentry_sleep,
&bench_trig_fmodret, &bench_trig_fmodret,
&bench_trig_uprobe_base, /* uprobes */
&bench_trig_uprobe_nop, &bench_trig_uprobe_nop,
&bench_trig_uretprobe_nop, &bench_trig_uretprobe_nop,
&bench_trig_uprobe_push, &bench_trig_uprobe_push,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
/* BPF triggering benchmarks */ /* BPF triggering benchmarks */
static struct trigger_ctx { static struct trigger_ctx {
struct trigger_bench *skel; struct trigger_bench *skel;
bool usermode_counters;
} ctx; } ctx;
static struct counter base_hits[MAX_BUCKETS]; static struct counter base_hits[MAX_BUCKETS];
...@@ -74,7 +75,10 @@ static void *trigger_producer(void *input) ...@@ -74,7 +75,10 @@ static void *trigger_producer(void *input)
static void trigger_measure(struct bench_res *res) static void trigger_measure(struct bench_res *res)
{ {
res->hits = sum_and_reset_counters(ctx.skel->bss->hits); if (ctx.usermode_counters)
res->hits = sum_and_reset_counters(base_hits);
else
res->hits = sum_and_reset_counters(ctx.skel->bss->hits);
} }
static void setup_ctx(void) static void setup_ctx(void)
...@@ -192,7 +196,7 @@ __nocf_check __weak void uprobe_target_ret(void) ...@@ -192,7 +196,7 @@ __nocf_check __weak void uprobe_target_ret(void)
asm volatile (""); asm volatile ("");
} }
static void *uprobe_base_producer(void *input) static void *uprobe_producer_count(void *input)
{ {
while (true) { while (true) {
uprobe_target_nop(); uprobe_target_nop();
...@@ -248,32 +252,37 @@ static void usetup(bool use_retprobe, void *target_addr) ...@@ -248,32 +252,37 @@ static void usetup(bool use_retprobe, void *target_addr)
ctx.skel->links.bench_trigger_uprobe = link; ctx.skel->links.bench_trigger_uprobe = link;
} }
static void uprobe_setup_nop(void) static void usermode_count_setup(void)
{
ctx.usermode_counters = true;
}
static void uprobe_nop_setup(void)
{ {
usetup(false, &uprobe_target_nop); usetup(false, &uprobe_target_nop);
} }
static void uretprobe_setup_nop(void) static void uretprobe_nop_setup(void)
{ {
usetup(true, &uprobe_target_nop); usetup(true, &uprobe_target_nop);
} }
static void uprobe_setup_push(void) static void uprobe_push_setup(void)
{ {
usetup(false, &uprobe_target_push); usetup(false, &uprobe_target_push);
} }
static void uretprobe_setup_push(void) static void uretprobe_push_setup(void)
{ {
usetup(true, &uprobe_target_push); usetup(true, &uprobe_target_push);
} }
static void uprobe_setup_ret(void) static void uprobe_ret_setup(void)
{ {
usetup(false, &uprobe_target_ret); usetup(false, &uprobe_target_ret);
} }
static void uretprobe_setup_ret(void) static void uretprobe_ret_setup(void)
{ {
usetup(true, &uprobe_target_ret); usetup(true, &uprobe_target_ret);
} }
...@@ -387,65 +396,22 @@ const struct bench bench_trig_fmodret = { ...@@ -387,65 +396,22 @@ const struct bench bench_trig_fmodret = {
.report_final = hits_drops_report_final, .report_final = hits_drops_report_final,
}; };
const struct bench bench_trig_uprobe_base = { /* uprobe benchmarks */
.name = "trig-uprobe-base", #define BENCH_TRIG_USERMODE(KIND, PRODUCER, NAME) \
.setup = NULL, /* no uprobe/uretprobe is attached */ const struct bench bench_trig_##KIND = { \
.producer_thread = uprobe_base_producer, .name = "trig-" NAME, \
.measure = trigger_base_measure, .validate = trigger_validate, \
.report_progress = hits_drops_report_progress, .setup = KIND##_setup, \
.report_final = hits_drops_report_final, .producer_thread = uprobe_producer_##PRODUCER, \
}; .measure = trigger_measure, \
.report_progress = hits_drops_report_progress, \
const struct bench bench_trig_uprobe_nop = { .report_final = hits_drops_report_final, \
.name = "trig-uprobe-nop", }
.setup = uprobe_setup_nop,
.producer_thread = uprobe_producer_nop, BENCH_TRIG_USERMODE(usermode_count, count, "usermode-count");
.measure = trigger_measure, BENCH_TRIG_USERMODE(uprobe_nop, nop, "uprobe-nop");
.report_progress = hits_drops_report_progress, BENCH_TRIG_USERMODE(uprobe_push, push, "uprobe-push");
.report_final = hits_drops_report_final, BENCH_TRIG_USERMODE(uprobe_ret, ret, "uprobe-ret");
}; BENCH_TRIG_USERMODE(uretprobe_nop, nop, "uretprobe-nop");
BENCH_TRIG_USERMODE(uretprobe_push, push, "uretprobe-push");
const struct bench bench_trig_uretprobe_nop = { BENCH_TRIG_USERMODE(uretprobe_ret, ret, "uretprobe-ret");
.name = "trig-uretprobe-nop",
.setup = uretprobe_setup_nop,
.producer_thread = uprobe_producer_nop,
.measure = trigger_measure,
.report_progress = hits_drops_report_progress,
.report_final = hits_drops_report_final,
};
const struct bench bench_trig_uprobe_push = {
.name = "trig-uprobe-push",
.setup = uprobe_setup_push,
.producer_thread = uprobe_producer_push,
.measure = trigger_measure,
.report_progress = hits_drops_report_progress,
.report_final = hits_drops_report_final,
};
const struct bench bench_trig_uretprobe_push = {
.name = "trig-uretprobe-push",
.setup = uretprobe_setup_push,
.producer_thread = uprobe_producer_push,
.measure = trigger_measure,
.report_progress = hits_drops_report_progress,
.report_final = hits_drops_report_final,
};
const struct bench bench_trig_uprobe_ret = {
.name = "trig-uprobe-ret",
.setup = uprobe_setup_ret,
.producer_thread = uprobe_producer_ret,
.measure = trigger_measure,
.report_progress = hits_drops_report_progress,
.report_final = hits_drops_report_final,
};
const struct bench bench_trig_uretprobe_ret = {
.name = "trig-uretprobe-ret",
.setup = uretprobe_setup_ret,
.producer_thread = uprobe_producer_ret,
.measure = trigger_measure,
.report_progress = hits_drops_report_progress,
.report_final = hits_drops_report_final,
};
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
set -eufo pipefail set -eufo pipefail
for i in base {uprobe,uretprobe}-{nop,push,ret} for i in usermode-count base {uprobe,uretprobe}-{nop,push,ret}
do do
summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-) summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-)
printf "%-15s: %s\n" $i "$summary" printf "%-15s: %s\n" $i "$summary"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment