kernel/time/hrtimer.c
Source file repositories/reference/linux-study-clean/kernel/time/hrtimer.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/hrtimer.c- Extension
.c- Size
- 77816 bytes
- Lines
- 2610
- 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.
- 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/cpu.hlinux/export.hlinux/percpu.hlinux/hrtimer.hlinux/notifier.hlinux/syscalls.hlinux/interrupt.hlinux/tick.hlinux/err.hlinux/debugobjects.hlinux/sched/signal.hlinux/sched/sysctl.hlinux/sched/rt.hlinux/sched/deadline.hlinux/sched/nohz.hlinux/sched/debug.hlinux/sched/isolation.hlinux/timer.hlinux/freezer.hlinux/compat.hlinux/uaccess.htrace/events/timer.htick-internal.h
Detected Declarations
syscall nanosleepsyscall nanosleep_time32function hrtimer_base_is_onlinefunction hrtimer_hres_workfnfunction hrtimer_schedule_hres_workfunction hrtimer_schedule_hres_workfunction hrtimer_suitable_targetfunction switch_hrtimer_basefunction __ktime_divnsfunction ktime_add_safefunction hrtimer_fixup_initfunction hrtimer_fixup_activatefunction hrtimer_fixup_freefunction stub_timerfunction hrtimer_fixup_assert_initfunction debug_hrtimer_initfunction debug_hrtimer_init_on_stackfunction debug_hrtimer_activatefunction debug_hrtimer_deactivatefunction debug_hrtimer_assert_initfunction destroy_hrtimer_on_stackfunction debug_hrtimer_initfunction debug_setup_on_stackfunction debug_activatefunction hrtimer_bases_next_eventfunction for_each_active_basefunction hrtimer_bases_firstfunction for_each_active_basefunction hrtimer_run_softirqfunction hrtimer_update_next_eventfunction hrtimer_update_basefunction hrtimer_hres_activefunction hrtimer_rearm_eventfunction __hrtimer_reprogramfunction hrtimer_force_reprogramfunction setup_hrtimer_hresfunction hrtimer_is_hres_enabledfunction hrtimer_switch_to_hresfunction hrtimer_is_hres_enabledfunction hrtimer_switch_to_hresfunction hrtimer_reprogramfunction update_needs_ipifunction for_each_active_basefunction CLOCK_BOOTTIMEfunction for_each_online_cpufunction clock_was_set_workfunction clock_was_set_delayedfunction timekeeping_resume
Annotated Snippet
SYSCALL_DEFINE2(nanosleep, struct __kernel_timespec __user *, rqtp,
struct __kernel_timespec __user *, rmtp)
{
struct timespec64 tu;
if (get_timespec64(&tu, rqtp))
return -EFAULT;
if (!timespec64_valid(&tu))
return -EINVAL;
current->restart_block.fn = do_no_restart_syscall;
current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE;
current->restart_block.nanosleep.rmtp = rmtp;
return hrtimer_nanosleep(timespec64_to_ktime(tu), HRTIMER_MODE_REL, CLOCK_MONOTONIC);
}
#endif
#ifdef CONFIG_COMPAT_32BIT_TIME
SYSCALL_DEFINE2(nanosleep_time32, struct old_timespec32 __user *, rqtp,
struct old_timespec32 __user *, rmtp)
{
struct timespec64 tu;
if (get_old_timespec32(&tu, rqtp))
return -EFAULT;
if (!timespec64_valid(&tu))
return -EINVAL;
current->restart_block.fn = do_no_restart_syscall;
current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE;
current->restart_block.nanosleep.compat_rmtp = rmtp;
return hrtimer_nanosleep(timespec64_to_ktime(tu), HRTIMER_MODE_REL, CLOCK_MONOTONIC);
}
#endif
/*
* Functions related to boot-time initialization:
*/
int hrtimers_prepare_cpu(unsigned int cpu)
{
struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
for (int i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
struct hrtimer_clock_base *clock_b = &cpu_base->clock_base[i];
clock_b->cpu_base = cpu_base;
seqcount_raw_spinlock_init(&clock_b->seq, &cpu_base->lock);
timerqueue_linked_init_head(&clock_b->active);
}
cpu_base->cpu = cpu;
hrtimer_cpu_base_init_expiry_lock(cpu_base);
return 0;
}
int hrtimers_cpu_starting(unsigned int cpu)
{
struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
/* Clear out any left over state from a CPU down operation */
cpu_base->active_bases = 0;
cpu_base->hres_active = false;
cpu_base->hang_detected = false;
cpu_base->next_timer = NULL;
cpu_base->softirq_next_timer = NULL;
cpu_base->expires_next = KTIME_MAX;
cpu_base->softirq_expires_next = KTIME_MAX;
cpu_base->softirq_activated = false;
cpu_base->online = true;
return 0;
}
#ifdef CONFIG_HOTPLUG_CPU
static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
struct hrtimer_clock_base *new_base)
{
struct timerqueue_linked_node *node;
struct hrtimer *timer;
while ((node = timerqueue_linked_first(&old_base->active))) {
timer = hrtimer_from_timerqueue_node(node);
BUG_ON(hrtimer_callback_running(timer));
debug_hrtimer_deactivate(timer);
/*
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/export.h`, `linux/percpu.h`, `linux/hrtimer.h`, `linux/notifier.h`, `linux/syscalls.h`, `linux/interrupt.h`, `linux/tick.h`.
- Detected declarations: `syscall nanosleep`, `syscall nanosleep_time32`, `function hrtimer_base_is_online`, `function hrtimer_hres_workfn`, `function hrtimer_schedule_hres_work`, `function hrtimer_schedule_hres_work`, `function hrtimer_suitable_target`, `function switch_hrtimer_base`, `function __ktime_divns`, `function ktime_add_safe`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core 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.