tools/testing/selftests/bpf/prog_tests/free_timer.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/free_timer.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/free_timer.c- Extension
.c- Size
- 3589 bytes
- Lines
- 170
- 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
unistd.hsys/syscall.htest_progs.hfree_timer.skel.h
Detected Declarations
struct run_ctxfunction start_threadsfunction stop_threadsfunction wait_for_startfunction test_free_timer
Annotated Snippet
struct run_ctx {
struct bpf_program *start_prog;
struct bpf_program *overwrite_prog;
pthread_barrier_t notify;
int loop;
bool start;
bool stop;
};
static void start_threads(struct run_ctx *ctx)
{
ctx->start = true;
}
static void stop_threads(struct run_ctx *ctx)
{
ctx->stop = true;
/* Guarantee the order between ->stop and ->start */
__atomic_store_n(&ctx->start, true, __ATOMIC_RELEASE);
}
static int wait_for_start(struct run_ctx *ctx)
{
while (!__atomic_load_n(&ctx->start, __ATOMIC_ACQUIRE))
usleep(10);
return ctx->stop;
}
static void *overwrite_timer_fn(void *arg)
{
struct run_ctx *ctx = arg;
int loop, fd, err;
cpu_set_t cpuset;
long ret = 0;
/* Pin on CPU 0 */
CPU_ZERO(&cpuset);
CPU_SET(0, &cpuset);
pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
/* Is the thread being stopped ? */
err = wait_for_start(ctx);
if (err)
return NULL;
fd = bpf_program__fd(ctx->overwrite_prog);
loop = ctx->loop;
while (loop-- > 0) {
LIBBPF_OPTS(bpf_test_run_opts, opts);
/* Wait for start thread to complete */
pthread_barrier_wait(&ctx->notify);
/* Overwrite timers */
err = bpf_prog_test_run_opts(fd, &opts);
if (err)
ret |= 1;
else if (opts.retval)
ret |= 2;
/* Notify start thread to start timers */
pthread_barrier_wait(&ctx->notify);
}
return (void *)ret;
}
static void *start_timer_fn(void *arg)
{
struct run_ctx *ctx = arg;
int loop, fd, err;
cpu_set_t cpuset;
long ret = 0;
/* Pin on CPU 1 */
CPU_ZERO(&cpuset);
CPU_SET(1, &cpuset);
pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
/* Is the thread being stopped ? */
err = wait_for_start(ctx);
if (err)
return NULL;
fd = bpf_program__fd(ctx->start_prog);
loop = ctx->loop;
while (loop-- > 0) {
LIBBPF_OPTS(bpf_test_run_opts, opts);
Annotation
- Immediate include surface: `unistd.h`, `sys/syscall.h`, `test_progs.h`, `free_timer.skel.h`.
- Detected declarations: `struct run_ctx`, `function start_threads`, `function stop_threads`, `function wait_for_start`, `function test_free_timer`.
- 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.