tools/testing/selftests/bpf/prog_tests/htab_reuse.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/htab_reuse.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/htab_reuse.c- Extension
.c- Size
- 5545 bytes
- Lines
- 269
- 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
sched.hstdbool.htest_progs.hhtab_reuse.skel.h
Detected Declarations
struct htab_op_ctxstruct htab_valstruct htab_val_largestruct consistency_ctxfunction test_htab_reuse_basicfunction wait_for_startfunction test_htab_reuse_consistencyfunction test_htab_reuse
Annotated Snippet
struct htab_op_ctx {
int fd;
int loop;
bool stop;
};
struct htab_val {
unsigned int lock;
unsigned int data;
};
static void *htab_lookup_fn(void *arg)
{
struct htab_op_ctx *ctx = arg;
int i = 0;
while (i++ < ctx->loop && !ctx->stop) {
struct htab_val value;
unsigned int key;
/* Use BPF_F_LOCK to use spin-lock in map value. */
key = 7;
bpf_map_lookup_elem_flags(ctx->fd, &key, &value, BPF_F_LOCK);
}
return NULL;
}
static void *htab_update_fn(void *arg)
{
struct htab_op_ctx *ctx = arg;
int i = 0;
while (i++ < ctx->loop && !ctx->stop) {
struct htab_val value;
unsigned int key;
key = 7;
value.lock = 0;
value.data = key;
bpf_map_update_elem(ctx->fd, &key, &value, BPF_F_LOCK);
bpf_map_delete_elem(ctx->fd, &key);
key = 24;
value.lock = 0;
value.data = key;
bpf_map_update_elem(ctx->fd, &key, &value, BPF_F_LOCK);
bpf_map_delete_elem(ctx->fd, &key);
}
return NULL;
}
static void test_htab_reuse_basic(void)
{
unsigned int i, wr_nr = 1, rd_nr = 4;
pthread_t tids[wr_nr + rd_nr];
struct htab_reuse *skel;
struct htab_op_ctx ctx;
int err;
skel = htab_reuse__open_and_load();
if (!ASSERT_OK_PTR(skel, "htab_reuse__open_and_load"))
return;
ctx.fd = bpf_map__fd(skel->maps.htab);
ctx.loop = 500;
ctx.stop = false;
memset(tids, 0, sizeof(tids));
for (i = 0; i < wr_nr; i++) {
err = pthread_create(&tids[i], NULL, htab_update_fn, &ctx);
if (!ASSERT_OK(err, "pthread_create")) {
ctx.stop = true;
goto reap;
}
}
for (i = 0; i < rd_nr; i++) {
err = pthread_create(&tids[i + wr_nr], NULL, htab_lookup_fn, &ctx);
if (!ASSERT_OK(err, "pthread_create")) {
ctx.stop = true;
goto reap;
}
}
reap:
for (i = 0; i < wr_nr + rd_nr; i++) {
if (!tids[i])
continue;
pthread_join(tids[i], NULL);
Annotation
- Immediate include surface: `sched.h`, `stdbool.h`, `test_progs.h`, `htab_reuse.skel.h`.
- Detected declarations: `struct htab_op_ctx`, `struct htab_val`, `struct htab_val_large`, `struct consistency_ctx`, `function test_htab_reuse_basic`, `function wait_for_start`, `function test_htab_reuse_consistency`, `function test_htab_reuse`.
- 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.