tools/testing/selftests/bpf/progs/wq.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/wq.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/wq.c- Extension
.c- Size
- 3936 bytes
- Lines
- 207
- 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
bpf_experimental.hbpf/bpf_helpers.hbpf_misc.h../test_kmods/bpf_testmod_kfunc.h
Detected Declarations
struct hmap_elemstruct elemfunction test_elem_callbackfunction test_hmap_elem_callbackfunction wq_callbackfunction wq_cb_sleepablefunction test_call_array_sleepablefunction test_syscall_array_sleepablefunction test_call_hash_sleepablefunction test_call_hash_malloc_sleepablefunction test_call_lru_sleepablefunction test_map_no_btf
Annotated Snippet
struct hmap_elem {
int counter;
struct bpf_timer timer; /* unused */
struct bpf_spin_lock lock; /* unused */
struct bpf_wq work;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1000);
__type(key, int);
__type(value, struct hmap_elem);
} hmap SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(map_flags, BPF_F_NO_PREALLOC);
__uint(max_entries, 1000);
__type(key, int);
__type(value, struct hmap_elem);
} hmap_malloc SEC(".maps");
struct elem {
int ok_offset;
struct bpf_wq w;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 2);
__type(key, int);
__type(value, struct elem);
} array SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__uint(max_entries, 4);
__type(key, int);
__type(value, struct elem);
} lru SEC(".maps");
__u32 ok;
__u32 ok_sleepable;
static int test_elem_callback(void *map, int *key,
int (callback_fn)(void *map, int *key, void *value))
{
struct elem init = {}, *val;
struct bpf_wq *wq;
if ((ok & (1 << *key) ||
(ok_sleepable & (1 << *key))))
return -22;
if (map == &lru &&
bpf_map_update_elem(map, key, &init, 0))
return -1;
val = bpf_map_lookup_elem(map, key);
if (!val)
return -2;
val->ok_offset = *key;
wq = &val->w;
if (bpf_wq_init(wq, map, 0) != 0)
return -3;
if (bpf_wq_set_callback(wq, callback_fn, 0))
return -4;
if (bpf_wq_start(wq, 0))
return -5;
return 0;
}
static int test_hmap_elem_callback(void *map, int *key,
int (callback_fn)(void *map, int *key, void *value))
{
struct hmap_elem init = {}, *val;
struct bpf_wq *wq;
if ((ok & (1 << *key) ||
(ok_sleepable & (1 << *key))))
return -22;
if (bpf_map_update_elem(map, key, &init, 0))
return -1;
Annotation
- Immediate include surface: `bpf_experimental.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `../test_kmods/bpf_testmod_kfunc.h`.
- Detected declarations: `struct hmap_elem`, `struct elem`, `function test_elem_callback`, `function test_hmap_elem_callback`, `function wq_callback`, `function wq_cb_sleepable`, `function test_call_array_sleepable`, `function test_syscall_array_sleepable`, `function test_call_hash_sleepable`, `function test_call_hash_malloc_sleepable`.
- 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.