tools/testing/selftests/bpf/progs/timer_start_delete_race.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/timer_start_delete_race.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/timer_start_delete_race.c- Extension
.c- Size
- 1283 bytes
- Lines
- 67
- 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
linux/bpf.htime.hbpf/bpf_helpers.h
Detected Declarations
struct map_valuefunction timer_cbfunction start_timerfunction delete_elem
Annotated Snippet
struct map_value {
struct bpf_timer timer;
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, int);
__type(value, struct map_value);
__uint(max_entries, 1);
} timer_map SEC(".maps");
long cb_cnt;
/*
* Timer callback that accesses the map value.
* If the race bug exists and this runs on freed memory,
* KASAN should detect it.
*/
static int timer_cb(void *map, int *key, struct map_value *value)
{
__sync_fetch_and_add(&cb_cnt, 1);
return 0;
}
SEC("syscall")
int start_timer(void *ctx)
{
struct map_value *value;
int i;
for (i = 0; i < ITER_CNT; i++) {
int key = 0;
value = bpf_map_lookup_elem(&timer_map, &key);
/* hey claude, no if (!value) here. The verifier got smarter */
bpf_timer_init(&value->timer, &timer_map, CLOCK_MONOTONIC);
bpf_timer_set_callback(&value->timer, timer_cb);
bpf_timer_start(&value->timer, 100000000, 0);
}
return 0;
}
SEC("syscall")
int delete_elem(void *ctx)
{
int i;
for (i = 0; i < ITER_CNT; i++) {
int key = 0;
bpf_map_delete_elem(&timer_map, &key);
}
return 0;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `linux/bpf.h`, `time.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `struct map_value`, `function timer_cb`, `function start_timer`, `function delete_elem`.
- 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.