kernel/time/posix-timers.c
Source file repositories/reference/linux-study-clean/kernel/time/posix-timers.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/posix-timers.c- Extension
.c- Size
- 44896 bytes
- Lines
- 1583
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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
linux/compat.hlinux/compiler.hlinux/init.hlinux/jhash.hlinux/interrupt.hlinux/list.hlinux/memblock.hlinux/nospec.hlinux/posix-clock.hlinux/posix-timers.hlinux/prctl.hlinux/sched/task.hlinux/slab.hlinux/syscalls.hlinux/time.hlinux/time_namespace.hlinux/uaccess.htimekeeping.hposix-timers.h
Detected Declarations
syscall timer_createsyscall timer_gettimesyscall timer_gettime32syscall timer_getoverrunsyscall timer_settimesyscall timer_settime32syscall timer_deletesyscall clock_settimesyscall clock_gettimesyscall clock_adjtimesyscall clock_getressyscall clock_settime32syscall clock_gettime32syscall clock_adjtime32syscall clock_getres_time32syscall clock_nanosleepsyscall clock_nanosleep_time32struct timer_hash_bucketfunction unlock_timerfunction hlist_for_each_entry_rcufunction posix_timer_hashedfunction hlist_for_each_entry_rcufunction posix_timer_add_atfunction scoped_guardfunction posix_timer_addfunction posix_get_realtime_timespecfunction posix_get_realtime_ktimefunction posix_clock_realtime_setfunction posix_clock_realtime_adjfunction posix_get_monotonic_timespecfunction posix_get_monotonic_ktimefunction posix_get_monotonic_rawfunction posix_get_realtime_coarsefunction posix_get_monotonic_coarsefunction posix_get_coarse_resfunction posix_get_boottime_timespecfunction posix_get_boottime_ktimefunction posix_get_tai_timespecfunction posix_get_tai_ktimefunction posix_get_hrtimer_resfunction timer_getoverrunfunction common_hrtimer_rearmfunction __posixtimer_deliver_signalfunction posixtimer_deliver_signalfunction posix_timer_queue_signalfunction interruptfunction posixtimer_create_prctlfunction posixtimer_free_timer
Annotated Snippet
SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
struct sigevent __user *, timer_event_spec,
timer_t __user *, created_timer_id)
{
if (timer_event_spec) {
sigevent_t event;
if (copy_from_user(&event, timer_event_spec, sizeof (event)))
return -EFAULT;
return do_timer_create(which_clock, &event, created_timer_id);
}
return do_timer_create(which_clock, NULL, created_timer_id);
}
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock,
struct compat_sigevent __user *, timer_event_spec,
timer_t __user *, created_timer_id)
{
if (timer_event_spec) {
sigevent_t event;
if (get_compat_sigevent(&event, timer_event_spec))
return -EFAULT;
return do_timer_create(which_clock, &event, created_timer_id);
}
return do_timer_create(which_clock, NULL, created_timer_id);
}
#endif
static struct k_itimer *lock_timer(timer_t timer_id)
{
struct k_itimer *timr;
/*
* timer_t could be any type >= int and we want to make sure any
* @timer_id outside positive int range fails lookup.
*/
if ((unsigned long long)timer_id > INT_MAX)
return NULL;
/*
* The hash lookup and the timers are RCU protected.
*
* Timers are added to the hash in invalid state where
* timr::it_signal is marked invalid. timer::it_signal is only set
* after the rest of the initialization succeeded.
*
* Timer destruction happens in steps:
* 1) Set timr::it_signal marked invalid with timr::it_lock held
* 2) Release timr::it_lock
* 3) Remove from the hash under hash_lock
* 4) Put the reference count.
*
* The reference count might not drop to zero if timr::sigq is
* queued. In that case the signal delivery or flush will put the
* last reference count.
*
* When the reference count reaches zero, the timer is scheduled
* for RCU removal after the grace period.
*
* Holding rcu_read_lock() across the lookup ensures that
* the timer cannot be freed.
*
* The lookup validates locklessly that timr::it_signal ==
* current::it_signal and timr::it_id == @timer_id. timr::it_id
* can't change, but timr::it_signal can become invalid during
* destruction, which makes the locked check fail.
*/
guard(rcu)();
timr = posix_timer_by_id(timer_id);
if (timr) {
spin_lock_irq(&timr->it_lock);
/*
* Validate under timr::it_lock that timr::it_signal is
* still valid. Pairs with #1 above.
*/
if (timr->it_signal == current->signal)
return timr;
spin_unlock_irq(&timr->it_lock);
}
return NULL;
}
static ktime_t common_hrtimer_remaining(struct k_itimer *timr, ktime_t now)
{
struct hrtimer *timer = &timr->it.real.timer;
return __hrtimer_expires_remaining_adjusted(timer, now);
}
Annotation
- Immediate include surface: `linux/compat.h`, `linux/compiler.h`, `linux/init.h`, `linux/jhash.h`, `linux/interrupt.h`, `linux/list.h`, `linux/memblock.h`, `linux/nospec.h`.
- Detected declarations: `syscall timer_create`, `syscall timer_gettime`, `syscall timer_gettime32`, `syscall timer_getoverrun`, `syscall timer_settime`, `syscall timer_settime32`, `syscall timer_delete`, `syscall clock_settime`, `syscall clock_gettime`, `syscall clock_adjtime`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.