kernel/time/itimer.c
Source file repositories/reference/linux-study-clean/kernel/time/itimer.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/itimer.c- Extension
.c- Size
- 11046 bytes
- Lines
- 423
- 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/mm.hlinux/interrupt.hlinux/syscalls.hlinux/time.hlinux/sched/signal.hlinux/sched/cputime.hlinux/posix-timers.hlinux/hrtimer.htrace/events/timer.hlinux/compat.hlinux/uaccess.h
Detected Declarations
syscall getitimersyscall alarmsyscall setitimerstruct old_itimerval32function Copyrightfunction hrtimer_get_remtimefunction get_cpu_itimerfunction do_getitimerfunction put_itimervalfunction SYSCALL_DEFINE2function put_old_itimerval32function dequeue_signalfunction posixtimer_rearm_itimerfunction set_cpu_itimerfunction do_setitimerfunction clear_itimerfunction tofunction get_itimervalfunction get_old_itimerval32
Annotated Snippet
SYSCALL_DEFINE2(getitimer, int, which, struct __kernel_old_itimerval __user *, value)
{
struct itimerspec64 get_buffer;
int error = do_getitimer(which, &get_buffer);
if (!error && put_itimerval(value, &get_buffer))
error = -EFAULT;
return error;
}
#if defined(CONFIG_COMPAT) || defined(CONFIG_ALPHA)
struct old_itimerval32 {
struct old_timeval32 it_interval;
struct old_timeval32 it_value;
};
static int put_old_itimerval32(struct old_itimerval32 __user *o,
const struct itimerspec64 *i)
{
struct old_itimerval32 v32;
v32.it_interval.tv_sec = i->it_interval.tv_sec;
v32.it_interval.tv_usec = i->it_interval.tv_nsec / NSEC_PER_USEC;
v32.it_value.tv_sec = i->it_value.tv_sec;
v32.it_value.tv_usec = i->it_value.tv_nsec / NSEC_PER_USEC;
return copy_to_user(o, &v32, sizeof(struct old_itimerval32)) ? -EFAULT : 0;
}
COMPAT_SYSCALL_DEFINE2(getitimer, int, which,
struct old_itimerval32 __user *, value)
{
struct itimerspec64 get_buffer;
int error = do_getitimer(which, &get_buffer);
if (!error && put_old_itimerval32(value, &get_buffer))
error = -EFAULT;
return error;
}
#endif
/*
* Invoked from dequeue_signal() when SIG_ALRM is delivered.
*
* Restart the ITIMER_REAL timer if it is armed as periodic timer. Doing
* this in the signal delivery path instead of self rearming prevents a DoS
* with small increments in the high reolution timer case and reduces timer
* noise in general.
*/
void posixtimer_rearm_itimer(struct task_struct *tsk)
{
struct hrtimer *tmr = &tsk->signal->real_timer;
if (!hrtimer_is_queued(tmr) && tsk->signal->it_real_incr != 0) {
hrtimer_forward_now(tmr, tsk->signal->it_real_incr);
hrtimer_restart(tmr);
}
}
/*
* Interval timers are restarted in the signal delivery path. See
* posixtimer_rearm_itimer().
*/
enum hrtimer_restart it_real_fn(struct hrtimer *timer)
{
struct signal_struct *sig =
container_of(timer, struct signal_struct, real_timer);
struct pid *leader_pid = sig->pids[PIDTYPE_TGID];
trace_itimer_expire(ITIMER_REAL, leader_pid, 0);
kill_pid_info(SIGALRM, SEND_SIG_PRIV, leader_pid);
return HRTIMER_NORESTART;
}
static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
const struct itimerspec64 *const value,
struct itimerspec64 *const ovalue)
{
u64 oval, nval, ointerval, ninterval;
struct cpu_itimer *it = &tsk->signal->it[clock_id];
nval = timespec64_to_ns(&value->it_value);
ninterval = timespec64_to_ns(&value->it_interval);
spin_lock_irq(&tsk->sighand->siglock);
oval = it->expires;
ointerval = it->incr;
if (oval || nval) {
if (nval > 0)
Annotation
- Immediate include surface: `linux/mm.h`, `linux/interrupt.h`, `linux/syscalls.h`, `linux/time.h`, `linux/sched/signal.h`, `linux/sched/cputime.h`, `linux/posix-timers.h`, `linux/hrtimer.h`.
- Detected declarations: `syscall getitimer`, `syscall alarm`, `syscall setitimer`, `struct old_itimerval32`, `function Copyright`, `function hrtimer_get_remtime`, `function get_cpu_itimer`, `function do_getitimer`, `function put_itimerval`, `function SYSCALL_DEFINE2`.
- 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.