tools/testing/selftests/bpf/prog_tests/res_spin_lock.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/res_spin_lock.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/res_spin_lock.c- Extension
.c- Size
- 2793 bytes
- Lines
- 118
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hnetwork_helpers.hsys/sysinfo.hres_spin_lock.skel.hres_spin_lock_fail.skel.h
Detected Declarations
function test_res_spin_lock_failurefunction test_res_spin_lock_successfunction serial_test_res_spin_lock_stress
Annotated Snippet
if (err || topts.retval) {
ASSERT_OK(err, "test_run");
ASSERT_OK(topts.retval, "test_run retval");
break;
}
}
pthread_exit(arg);
}
void test_res_spin_lock_success(void)
{
LIBBPF_OPTS(bpf_test_run_opts, topts,
.data_in = &pkt_v4,
.data_size_in = sizeof(pkt_v4),
.repeat = 1,
);
struct res_spin_lock *skel;
pthread_t thread_id[16];
int prog_fd, i, err;
void *ret;
if (get_nprocs() < 2) {
test__skip();
return;
}
skel = res_spin_lock__open_and_load();
if (!ASSERT_OK_PTR(skel, "res_spin_lock__open_and_load"))
return;
/* AA deadlock */
prog_fd = bpf_program__fd(skel->progs.res_spin_lock_test);
err = bpf_prog_test_run_opts(prog_fd, &topts);
ASSERT_OK(err, "error");
ASSERT_OK(topts.retval, "retval");
prog_fd = bpf_program__fd(skel->progs.res_spin_lock_test_held_lock_max);
err = bpf_prog_test_run_opts(prog_fd, &topts);
ASSERT_OK(err, "error");
ASSERT_OK(topts.retval, "retval");
/* Multi-threaded ABBA deadlock. */
prog_fd = bpf_program__fd(skel->progs.res_spin_lock_test_AB);
for (i = 0; i < 16; i++) {
int err;
err = pthread_create(&thread_id[i], NULL, &spin_lock_thread, &prog_fd);
if (!ASSERT_OK(err, "pthread_create"))
goto end;
}
topts.retval = 0;
topts.repeat = 1000;
int fd = bpf_program__fd(skel->progs.res_spin_lock_test_BA);
while (!topts.retval && !err && !READ_ONCE(skel->bss->err)) {
err = bpf_prog_test_run_opts(fd, &topts);
}
WRITE_ONCE(skip, true);
for (i = 0; i < 16; i++) {
if (!ASSERT_OK(pthread_join(thread_id[i], &ret), "pthread_join"))
goto end;
if (!ASSERT_EQ(ret, &prog_fd, "ret == prog_fd"))
goto end;
}
ASSERT_EQ(READ_ONCE(skel->bss->err), -EDEADLK, "timeout err");
ASSERT_OK(err, "err");
ASSERT_EQ(topts.retval, -EDEADLK, "timeout");
end:
res_spin_lock__destroy(skel);
return;
}
void serial_test_res_spin_lock_stress(void)
{
if (libbpf_num_possible_cpus() < 3) {
test__skip();
return;
}
ASSERT_OK(load_module("bpf_test_rqspinlock.ko", false), "load module AA");
sleep(5);
unload_module("bpf_test_rqspinlock", false);
/*
* Insert bpf_test_rqspinlock.ko manually with test_mode=[1|2] to test
* other cases (ABBA, ABBCCA).
*/
}
Annotation
- Immediate include surface: `test_progs.h`, `network_helpers.h`, `sys/sysinfo.h`, `res_spin_lock.skel.h`, `res_spin_lock_fail.skel.h`.
- Detected declarations: `function test_res_spin_lock_failure`, `function test_res_spin_lock_success`, `function serial_test_res_spin_lock_stress`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.