tools/testing/selftests/timers/posix_timers.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/posix_timers.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/timers/posix_timers.c- Extension
.c- Size
- 18177 bytes
- Lines
- 726
- 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
sys/prctl.hsys/time.hsys/types.hstdio.hsignal.hstdint.hstring.hunistd.htime.hinclude/vdso/time64.hpthread.hstdbool.hkselftest.hsys/syscall.h
Detected Declarations
struct tmrsigfunction Copyrightfunction user_loopfunction kernel_loopfunction idle_loopfunction sig_handlerfunction calcdiff_nsfunction check_difffunction check_itimerfunction check_timer_createfunction ctd_sighandlerfunction check_timer_distributionfunction siginfo_handlerfunction check_sig_ignfunction check_rearmfunction check_deletefunction check_sigev_nonefunction check_gettimefunction check_overrunfunction do_timer_createfunction do_timer_deletefunction check_timer_create_exactfunction main
Annotated Snippet
struct tmrsig {
int signals;
int overruns;
};
static void siginfo_handler(int sig, siginfo_t *si, void *uc)
{
struct tmrsig *tsig = si ? si->si_ptr : NULL;
if (tsig) {
tsig->signals++;
tsig->overruns += si->si_overrun;
}
}
static void *ignore_thread(void *arg)
{
unsigned int *tid = arg;
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
if (sigprocmask(SIG_BLOCK, &set, NULL))
fatal_error(NULL, "sigprocmask(SIG_BLOCK)");
*tid = gettid();
sleep(100);
if (sigprocmask(SIG_UNBLOCK, &set, NULL))
fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)");
return NULL;
}
static void check_sig_ign(int thread)
{
struct tmrsig tsig = { };
struct itimerspec its;
unsigned int tid = 0;
struct sigaction sa;
struct sigevent sev;
pthread_t pthread;
timer_t timerid;
sigset_t set;
if (thread) {
if (pthread_create(&pthread, NULL, ignore_thread, &tid))
fatal_error(NULL, "pthread_create()");
sleep(1);
}
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = siginfo_handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGUSR1, &sa, NULL))
fatal_error(NULL, "sigaction()");
/* Block the signal */
sigemptyset(&set);
sigaddset(&set, SIGUSR1);
if (sigprocmask(SIG_BLOCK, &set, NULL))
fatal_error(NULL, "sigprocmask(SIG_BLOCK)");
memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGUSR1;
sev.sigev_value.sival_ptr = &tsig;
if (thread) {
sev.sigev_notify = SIGEV_THREAD_ID;
sev._sigev_un._tid = tid;
}
if (timer_create(CLOCK_MONOTONIC, &sev, &timerid))
fatal_error(NULL, "timer_create()");
/* Start the timer to expire in 100ms and 100ms intervals */
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 100000000;
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 100000000;
timer_settime(timerid, 0, &its, NULL);
sleep(1);
/* Set the signal to be ignored */
if (signal(SIGUSR1, SIG_IGN) == SIG_ERR)
fatal_error(NULL, "signal(SIG_IGN)");
sleep(1);
if (thread) {
Annotation
- Immediate include surface: `sys/prctl.h`, `sys/time.h`, `sys/types.h`, `stdio.h`, `signal.h`, `stdint.h`, `string.h`, `unistd.h`.
- Detected declarations: `struct tmrsig`, `function Copyright`, `function user_loop`, `function kernel_loop`, `function idle_loop`, `function sig_handler`, `function calcdiff_ns`, `function check_diff`, `function check_itimer`, `function check_timer_create`.
- 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.