selftests/bpf: Skip res_spin_lock_stress if no perf support
Subsystems (3)
PATCH 1/1 selftests/bpf: Skip res_spin_lock_stress if no perf support
Probe PMU support before loading bpf_test_rqspinlock.ko, otherwise the test fails with not obvious error without proper perf event support:
Failed to load bpf_test_rqspinlock.ko into the kernel: -2 serial_test_res_spin_lock_stress:FAIL:load module AA
unexpected error: -22 (errno 2)
--- .../selftests/bpf/prog_tests/res_spin_lock.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+)
tools/testing/selftests/bpf/prog_tests/res_spin_lock.c +20 -0
@@ -3,6 +3,8 @@#include <test_progs.h> #include <network_helpers.h> #include <sys/sysinfo.h> +#include <sys/syscall.h> +#include <linux/perf_event.h> #include "res_spin_lock.skel.h" #include "res_spin_lock_fail.skel.h"
@@ -102,11 +104,29 @@ void test_res_spin_lock_success(void)void serial_test_res_spin_lock_stress (void ) { +struct perf_event_attr attr = { + .size =sizeof (attr), + .type =PERF_TYPE_HARDWARE , + .config =PERF_COUNT_HW_CPU_CYCLES , + }; +int pmu_fd; +if (libbpf_num_possible_cpus () <3 ) {test__skip ();return ; } + pmu_fd =syscall (__NR_perf_event_open, &attr,0 ,-1 ,-1 ,0 ); +if (pmu_fd <0 ) { +if (errno ==ENOENT || errno ==EOPNOTSUPP ) { +test__skip (); +return ; + } +ASSERT_OK (-errno,"perf_event_open pmu probe" ); +return ; + } +close (pmu_fd); +ASSERT_OK (load_module ("bpf_test_rqspinlock.ko" , false),"load module AA" );sleep (5 );unload_module ("bpf_test_rqspinlock" , false);
Signature · 1 line
2.54.0
This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Kumar Kartikeya Dwivedi <[email protected]>:
Quoted 9 lines · On Wed, 8 Jul 2026 12:47:17 +0200 you wrote:
Probe PMU support before loading bpf_test_rqspinlock.ko, otherwise the test fails with not obvious error without proper perf event support:
Failed to load bpf_test_rqspinlock.ko into the kernel: -2 serial_test_res_spin_lock_stress:FAIL:load module AA
unexpected error: -22 (errno 2)[...]
Here is the summary with links:
- [bpf-next] selftests/bpf: Skip res_spin_lock_stress if no perf support
https://git.kernel.org/bpf/bpf-next/c/41ec7e4a1779
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html