tools/testing/selftests/bpf/progs/task_work_stress.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/task_work_stress.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/task_work_stress.c- Extension
.c- Size
- 1591 bytes
- Lines
- 74
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hstring.hstdbool.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf_misc.h
Detected Declarations
struct elemfunction process_workfunction schedule_task_workfunction delete_task_work
Annotated Snippet
struct elem {
__u32 count;
struct bpf_task_work tw;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(map_flags, BPF_F_NO_PREALLOC);
__uint(max_entries, ENTRIES);
__type(key, int);
__type(value, struct elem);
} hmap SEC(".maps");
static int process_work(struct bpf_map *map, void *key, void *value)
{
__sync_fetch_and_add(&callback_success, 1);
return 0;
}
SEC("syscall")
int schedule_task_work(void *ctx)
{
struct elem empty_work = {.count = 0};
struct elem *work;
int key = 0, err;
key = bpf_ktime_get_ns() % ENTRIES;
work = bpf_map_lookup_elem(&hmap, &key);
if (!work) {
bpf_map_update_elem(&hmap, &key, &empty_work, BPF_NOEXIST);
work = bpf_map_lookup_elem(&hmap, &key);
if (!work)
return 0;
}
err = bpf_task_work_schedule_signal(bpf_get_current_task_btf(), &work->tw, &hmap,
process_work);
if (err)
__sync_fetch_and_add(&schedule_error, 1);
else
__sync_fetch_and_add(&callback_scheduled, 1);
return 0;
}
SEC("syscall")
int delete_task_work(void *ctx)
{
int key = 0, err;
key = bpf_get_prandom_u32() % ENTRIES;
err = bpf_map_delete_elem(&hmap, &key);
if (!err)
__sync_fetch_and_add(&delete_success, 1);
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `string.h`, `stdbool.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_misc.h`.
- Detected declarations: `struct elem`, `function process_work`, `function schedule_task_work`, `function delete_task_work`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.