Skip to content

Commit 2ed4a64

Browse files
Xu KuohaiKernel Patches Daemon
authored andcommitted
selftests/bpf/benchs: Add overwrite mode bench for rb-libbpf
Add overwrite mode bench for ring buffer. For reference, below are bench numbers collected from x86_64 and arm64. - x86_64 (AMD EPYC 9654) Ringbuf, multi-producer contention, overwrite mode ================================================== rb-libbpf nr_prod 1 14.970 ± 0.012M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 2 14.064 ± 0.007M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 3 7.493 ± 0.003M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 4 6.575 ± 0.001M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 8 3.696 ± 0.011M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 12 2.612 ± 0.012M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 16 2.335 ± 0.005M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 20 2.079 ± 0.005M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 24 1.965 ± 0.004M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 28 1.846 ± 0.004M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 32 1.790 ± 0.002M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 36 1.735 ± 0.002M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 40 1.701 ± 0.002M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 44 1.669 ± 0.001M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 48 1.749 ± 0.001M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 52 1.709 ± 0.001M/s (drops 0.000 ± 0.000M/s) - arm64 (HiSilicon Kunpeng 920) Ringbuf, multi-producer contention, overwrite mode ================================================== rb-libbpf nr_prod 1 10.319 ± 0.231M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 2 9.219 ± 0.006M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 3 6.699 ± 0.013M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 4 4.608 ± 0.001M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 8 3.905 ± 0.001M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 12 3.282 ± 0.004M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 16 3.182 ± 0.008M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 20 3.029 ± 0.006M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 24 3.116 ± 0.004M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 28 2.869 ± 0.005M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 32 3.075 ± 0.010M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 36 2.795 ± 0.003M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 40 2.947 ± 0.005M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 44 2.748 ± 0.006M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 48 2.767 ± 0.003M/s (drops 0.000 ± 0.000M/s) rb-libbpf nr_prod 52 2.858 ± 0.002M/s (drops 0.000 ± 0.000M/s) Signed-off-by: Xu Kuohai <[email protected]>
1 parent 2311ce2 commit 2ed4a64

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

tools/testing/selftests/bpf/benchs/bench_ringbufs.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static struct {
1919
int ringbuf_sz; /* per-ringbuf, in bytes */
2020
bool ringbuf_use_output; /* use slower output API */
2121
int perfbuf_sz; /* per-CPU size, in pages */
22+
bool overwrite_mode;
2223
} args = {
2324
.back2back = false,
2425
.batch_cnt = 500,
@@ -27,6 +28,7 @@ static struct {
2728
.ringbuf_sz = 512 * 1024,
2829
.ringbuf_use_output = false,
2930
.perfbuf_sz = 128,
31+
.overwrite_mode = false,
3032
};
3133

3234
enum {
@@ -35,6 +37,7 @@ enum {
3537
ARG_RB_BATCH_CNT = 2002,
3638
ARG_RB_SAMPLED = 2003,
3739
ARG_RB_SAMPLE_RATE = 2004,
40+
ARG_RB_OVERWRITE = 2005,
3841
};
3942

4043
static const struct argp_option opts[] = {
@@ -43,6 +46,7 @@ static const struct argp_option opts[] = {
4346
{ "rb-batch-cnt", ARG_RB_BATCH_CNT, "CNT", 0, "Set BPF-side record batch count"},
4447
{ "rb-sampled", ARG_RB_SAMPLED, NULL, 0, "Notification sampling"},
4548
{ "rb-sample-rate", ARG_RB_SAMPLE_RATE, "RATE", 0, "Notification sample rate"},
49+
{ "rb-overwrite", ARG_RB_OVERWRITE, NULL, 0, "overwrite mode"},
4650
{},
4751
};
4852

@@ -72,6 +76,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
7276
argp_usage(state);
7377
}
7478
break;
79+
case ARG_RB_OVERWRITE:
80+
args.overwrite_mode = true;
81+
break;
7582
default:
7683
return ARGP_ERR_UNKNOWN;
7784
}
@@ -104,6 +111,11 @@ static void bufs_validate(void)
104111
fprintf(stderr, "back-to-back mode makes sense only for single-producer case!\n");
105112
exit(1);
106113
}
114+
115+
if (args.overwrite_mode && strcmp(env.bench_name, "rb-libbpf") != 0) {
116+
fprintf(stderr, "rb-overwrite mode only supports rb-libbpf!\n");
117+
exit(1);
118+
}
107119
}
108120

109121
static void *bufs_sample_producer(void *input)
@@ -134,6 +146,8 @@ static void ringbuf_libbpf_measure(struct bench_res *res)
134146

135147
static struct ringbuf_bench *ringbuf_setup_skeleton(void)
136148
{
149+
__u32 flags;
150+
struct bpf_map *ringbuf;
137151
struct ringbuf_bench *skel;
138152

139153
setup_libbpf();
@@ -151,7 +165,13 @@ static struct ringbuf_bench *ringbuf_setup_skeleton(void)
151165
/* record data + header take 16 bytes */
152166
skel->rodata->wakeup_data_size = args.sample_rate * 16;
153167

154-
bpf_map__set_max_entries(skel->maps.ringbuf, args.ringbuf_sz);
168+
ringbuf = skel->maps.ringbuf;
169+
if (args.overwrite_mode) {
170+
flags = bpf_map__map_flags(ringbuf) | BPF_F_OVERWRITE;
171+
bpf_map__set_map_flags(ringbuf, flags);
172+
}
173+
174+
bpf_map__set_max_entries(ringbuf, args.ringbuf_sz);
155175

156176
if (ringbuf_bench__load(skel)) {
157177
fprintf(stderr, "failed to load skeleton\n");

tools/testing/selftests/bpf/benchs/run_bench_ringbufs.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ for b in 1 2 3 4 8 12 16 20 24 28 32 36 40 44 48 52; do
4949
summarize "rb-libbpf nr_prod $b" "$($RUN_RB_BENCH -p$b --rb-batch-cnt 50 rb-libbpf)"
5050
done
5151

52+
header "Ringbuf, multi-producer contention, overwrite mode"
53+
for b in 1 2 3 4 8 12 16 20 24 28 32 36 40 44 48 52; do
54+
summarize "rb-libbpf nr_prod $b" "$($RUN_RB_BENCH -p$b --rb-overwrite --rb-batch-cnt 50 rb-libbpf)"
55+
done

0 commit comments

Comments
 (0)