mirror of
https://github.com/torvalds/linux.git
synced 2026-05-25 23:52:08 +02:00
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
This commit is contained in:
parent
10653c0dd8
commit
d02fdd7195
|
|
@ -23,13 +23,14 @@ static void *spin_lock_thread(void *arg)
|
|||
}
|
||||
|
||||
|
||||
static int timer_stress(struct timer *timer_skel)
|
||||
static int timer_stress_runner(struct timer *timer_skel, bool async_cancel)
|
||||
{
|
||||
int i, err = 1, prog_fd;
|
||||
LIBBPF_OPTS(bpf_test_run_opts, topts);
|
||||
pthread_t thread_id[NUM_THR];
|
||||
void *ret;
|
||||
|
||||
timer_skel->bss->async_cancel = async_cancel;
|
||||
prog_fd = bpf_program__fd(timer_skel->progs.race);
|
||||
for (i = 0; i < NUM_THR; i++) {
|
||||
err = pthread_create(&thread_id[i], NULL,
|
||||
|
|
@ -46,6 +47,16 @@ static int timer_stress(struct timer *timer_skel)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int timer_stress(struct timer *timer_skel)
|
||||
{
|
||||
return timer_stress_runner(timer_skel, false);
|
||||
}
|
||||
|
||||
static int timer_stress_async_cancel(struct timer *timer_skel)
|
||||
{
|
||||
return timer_stress_runner(timer_skel, true);
|
||||
}
|
||||
|
||||
static int timer(struct timer *timer_skel)
|
||||
{
|
||||
int err, prog_fd;
|
||||
|
|
@ -118,6 +129,11 @@ void serial_test_timer_stress(void)
|
|||
test_timer(timer_stress);
|
||||
}
|
||||
|
||||
void serial_test_timer_stress_async_cancel(void)
|
||||
{
|
||||
test_timer(timer_stress_async_cancel);
|
||||
}
|
||||
|
||||
void test_timer_interrupt(void)
|
||||
{
|
||||
struct timer_interrupt *skel = NULL;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2021 Facebook */
|
||||
#include <linux/bpf.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <vmlinux.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
|
||||
#define CLOCK_MONOTONIC 1
|
||||
#define CLOCK_BOOTTIME 7
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
struct hmap_elem {
|
||||
int counter;
|
||||
struct bpf_timer timer;
|
||||
|
|
@ -63,6 +67,7 @@ __u64 callback_check = 52;
|
|||
__u64 callback2_check = 52;
|
||||
__u64 pinned_callback_check;
|
||||
__s32 pinned_cpu;
|
||||
bool async_cancel = 0;
|
||||
|
||||
#define ARRAY 1
|
||||
#define HTAB 2
|
||||
|
|
@ -419,7 +424,10 @@ int race(void *ctx)
|
|||
|
||||
bpf_timer_set_callback(timer, race_timer_callback);
|
||||
bpf_timer_start(timer, 0, 0);
|
||||
bpf_timer_cancel(timer);
|
||||
if (async_cancel)
|
||||
bpf_timer_cancel_async(timer);
|
||||
else
|
||||
bpf_timer_cancel(timer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user