tools/testing/selftests/bpf/progs/free_timer.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/free_timer.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/free_timer.c- Extension
.c- Size
- 1800 bytes
- Lines
- 82
- 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_tracing.hbpf/bpf_helpers.h
Detected Declarations
struct map_valuefunction timer_cbfunction start_cbfunction overwrite_cbfunction BPF_PROGfunction BPF_PROG
Annotated Snippet
struct map_value {
struct bpf_timer timer;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, int);
__type(value, struct map_value);
__uint(max_entries, MAX_ENTRIES);
} map SEC(".maps");
static int timer_cb(void *map, void *key, struct map_value *value)
{
volatile int sum = 0;
int i;
bpf_for(i, 0, 1024 * 1024) sum += i;
return 0;
}
static int start_cb(int key)
{
struct map_value *value;
value = bpf_map_lookup_elem(&map, (void *)&key);
if (!value)
return 0;
bpf_timer_init(&value->timer, &map, CLOCK_MONOTONIC);
bpf_timer_set_callback(&value->timer, timer_cb);
/* Hope 100us will be enough to wake-up and run the overwrite thread */
bpf_timer_start(&value->timer, 100000, BPF_F_TIMER_CPU_PIN);
return 0;
}
static int overwrite_cb(int key)
{
struct map_value zero = {};
/* Free the timer which may run on other CPU */
bpf_map_update_elem(&map, (void *)&key, &zero, BPF_ANY);
return 0;
}
SEC("syscall")
int BPF_PROG(start_timer)
{
bpf_loop(MAX_ENTRIES, start_cb, NULL, 0);
return 0;
}
SEC("syscall")
int BPF_PROG(overwrite_timer)
{
bpf_loop(MAX_ENTRIES, overwrite_cb, NULL, 0);
return 0;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `linux/bpf.h`, `time.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `struct map_value`, `function timer_cb`, `function start_cb`, `function overwrite_cb`, `function BPF_PROG`, `function BPF_PROG`.
- 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.