tools/testing/selftests/bpf/prog_tests/timer.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/timer.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/timer.c- Extension
.c- Size
- 8148 bytes
- Lines
- 352
- 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
sched.htest_progs.hlinux/perf_event.hsys/syscall.htimer.skel.htimer_failure.skel.htimer_interrupt.skel.h
Detected Declarations
function perf_event_openfunction timer_stress_runnerfunction timer_stressfunction timer_stress_async_cancelfunction run_nmi_testfunction timer_stress_nmi_racefunction timer_stress_nmi_updatefunction timer_stress_nmi_cancelfunction timerfunction timer_cancel_asyncfunction test_timerfunction serial_test_timerfunction serial_test_timer_stressfunction serial_test_timer_stress_async_cancelfunction serial_test_timer_async_cancelfunction serial_test_timer_stress_nmi_racefunction serial_test_timer_stress_nmi_updatefunction serial_test_timer_stress_nmi_cancelfunction test_timer_interrupt
Annotated Snippet
if (errno == ENOENT || errno == EOPNOTSUPP) {
printf("SKIP:no PERF_COUNT_HW_CPU_CYCLES\n");
test__skip();
ret = EOPNOTSUPP;
goto cleanup;
}
ASSERT_GE(pe_fd, 0, "perf_event_open");
goto cleanup;
}
link = bpf_program__attach_perf_event(prog, pe_fd);
if (!ASSERT_OK_PTR(link, "attach_perf_event"))
goto cleanup;
pe_fd = -1; /* Ownership transferred to link */
/* Signal child to start CPU work */
close(pipefd[0]);
pipefd[0] = -1;
write(pipefd[1], &buf, 1);
close(pipefd[1]);
pipefd[1] = -1;
waitpid(pid, &status, 0);
pid = 0;
/* Verify NMI context was hit */
ASSERT_GT(timer_skel->bss->test_hits, 0, "test_hits");
ret = 0;
cleanup:
bpf_link__destroy(link);
if (pe_fd >= 0)
close(pe_fd);
if (pid > 0) {
write(pipefd[1], &buf, 1);
waitpid(pid, &status, 0);
}
if (pipefd[0] >= 0)
close(pipefd[0]);
if (pipefd[1] >= 0)
close(pipefd[1]);
return ret;
}
static int timer_stress_nmi_race(struct timer *timer_skel)
{
int err;
err = run_nmi_test(timer_skel, timer_skel->progs.nmi_race);
if (err == EOPNOTSUPP)
return 0;
return err;
}
static int timer_stress_nmi_update(struct timer *timer_skel)
{
int err;
err = run_nmi_test(timer_skel, timer_skel->progs.nmi_update);
if (err == EOPNOTSUPP)
return 0;
if (err)
return err;
ASSERT_GT(timer_skel->bss->update_hits, 0, "update_hits");
return 0;
}
static int timer_stress_nmi_cancel(struct timer *timer_skel)
{
int err;
err = run_nmi_test(timer_skel, timer_skel->progs.nmi_cancel);
if (err == EOPNOTSUPP)
return 0;
if (err)
return err;
ASSERT_GT(timer_skel->bss->cancel_hits, 0, "cancel_hits");
return 0;
}
static int timer(struct timer *timer_skel)
{
int err, prog_fd;
LIBBPF_OPTS(bpf_test_run_opts, topts);
err = timer__attach(timer_skel);
if (!ASSERT_OK(err, "timer_attach"))
return err;
ASSERT_EQ(timer_skel->data->callback_check, 52, "callback_check1");
Annotation
- Immediate include surface: `sched.h`, `test_progs.h`, `linux/perf_event.h`, `sys/syscall.h`, `timer.skel.h`, `timer_failure.skel.h`, `timer_interrupt.skel.h`.
- Detected declarations: `function perf_event_open`, `function timer_stress_runner`, `function timer_stress`, `function timer_stress_async_cancel`, `function run_nmi_test`, `function timer_stress_nmi_race`, `function timer_stress_nmi_update`, `function timer_stress_nmi_cancel`, `function timer`, `function timer_cancel_async`.
- 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.