Skip to content

Commit d02fdd7

Browse files
mykyta5anakryiko
authored andcommitted
selftests/bpf: Add stress test for timer async cancel
Extend BPF timer selftest to run stress test for async cancel. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20260201025403.66625-6-alexei.starovoitov@gmail.com
1 parent 10653c0 commit d02fdd7

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

tools/testing/selftests/bpf/prog_tests/timer.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ static void *spin_lock_thread(void *arg)
2323
}
2424

2525

26-
static int timer_stress(struct timer *timer_skel)
26+
static int timer_stress_runner(struct timer *timer_skel, bool async_cancel)
2727
{
2828
int i, err = 1, prog_fd;
2929
LIBBPF_OPTS(bpf_test_run_opts, topts);
3030
pthread_t thread_id[NUM_THR];
3131
void *ret;
3232

33+
timer_skel->bss->async_cancel = async_cancel;
3334
prog_fd = bpf_program__fd(timer_skel->progs.race);
3435
for (i = 0; i < NUM_THR; i++) {
3536
err = pthread_create(&thread_id[i], NULL,
@@ -46,6 +47,16 @@ static int timer_stress(struct timer *timer_skel)
4647
return err;
4748
}
4849

50+
static int timer_stress(struct timer *timer_skel)
51+
{
52+
return timer_stress_runner(timer_skel, false);
53+
}
54+
55+
static int timer_stress_async_cancel(struct timer *timer_skel)
56+
{
57+
return timer_stress_runner(timer_skel, true);
58+
}
59+
4960
static int timer(struct timer *timer_skel)
5061
{
5162
int err, prog_fd;
@@ -118,6 +129,11 @@ void serial_test_timer_stress(void)
118129
test_timer(timer_stress);
119130
}
120131

132+
void serial_test_timer_stress_async_cancel(void)
133+
{
134+
test_timer(timer_stress_async_cancel);
135+
}
136+
121137
void test_timer_interrupt(void)
122138
{
123139
struct timer_interrupt *skel = NULL;

tools/testing/selftests/bpf/progs/timer.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright (c) 2021 Facebook */
3-
#include <linux/bpf.h>
4-
#include <time.h>
3+
4+
#include <vmlinux.h>
55
#include <stdbool.h>
66
#include <errno.h>
77
#include <bpf/bpf_helpers.h>
88
#include <bpf/bpf_tracing.h>
99

10+
#define CLOCK_MONOTONIC 1
11+
#define CLOCK_BOOTTIME 7
12+
1013
char _license[] SEC("license") = "GPL";
14+
1115
struct hmap_elem {
1216
int counter;
1317
struct bpf_timer timer;
@@ -63,6 +67,7 @@ __u64 callback_check = 52;
6367
__u64 callback2_check = 52;
6468
__u64 pinned_callback_check;
6569
__s32 pinned_cpu;
70+
bool async_cancel = 0;
6671

6772
#define ARRAY 1
6873
#define HTAB 2
@@ -419,7 +424,10 @@ int race(void *ctx)
419424

420425
bpf_timer_set_callback(timer, race_timer_callback);
421426
bpf_timer_start(timer, 0, 0);
422-
bpf_timer_cancel(timer);
427+
if (async_cancel)
428+
bpf_timer_cancel_async(timer);
429+
else
430+
bpf_timer_cancel(timer);
423431

424432
return 0;
425433
}

0 commit comments

Comments
 (0)