kernel/sched/idle.c
Source file repositories/reference/linux-study-clean/kernel/sched/idle.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/idle.c- Extension
.c- Size
- 15387 bytes
- Lines
- 594
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpuidle.hlinux/suspend.hlinux/livepatch.hsched.hsmp.h
Detected Declarations
struct idle_timerfunction sched_idle_set_statefunction cpu_idle_poll_ctrlfunction cpu_idle_poll_setupfunction cpu_idle_nopoll_setupfunction cpu_idle_pollfunction arch_cpu_idle_preparefunction arch_cpu_idlefunction cond_tick_broadcast_enterfunction cond_tick_broadcast_exitfunction cond_tick_broadcast_enterfunction call_cpuidle_s2idlefunction call_cpuidlefunction idle_call_stop_or_retain_tickfunction cpuidle_idle_callfunction interruptsfunction do_idlefunction cpu_in_idlefunction idle_inject_timer_fnfunction play_idle_precisefunction cpu_startup_entryfunction select_task_rq_idlefunction balance_idlefunction wakeup_preempt_idlefunction put_prev_task_idlefunction set_next_task_idlefunction dequeue_task_idlefunction task_tick_idlefunction switching_to_idlefunction prio_changed_idlefunction update_curr_idleexport play_idle_precise
Annotated Snippet
struct idle_timer {
struct hrtimer timer;
int done;
};
static enum hrtimer_restart idle_inject_timer_fn(struct hrtimer *timer)
{
struct idle_timer *it = container_of(timer, struct idle_timer, timer);
WRITE_ONCE(it->done, 1);
set_tsk_need_resched(current);
return HRTIMER_NORESTART;
}
void play_idle_precise(u64 duration_ns, u64 latency_ns)
{
struct idle_timer it;
/*
* Only FIFO tasks can disable the tick since they don't need the forced
* preemption.
*/
WARN_ON_ONCE(current->policy != SCHED_FIFO);
WARN_ON_ONCE(current->nr_cpus_allowed != 1);
WARN_ON_ONCE(!(current->flags & PF_KTHREAD));
WARN_ON_ONCE(!(current->flags & PF_NO_SETAFFINITY));
WARN_ON_ONCE(!duration_ns);
WARN_ON_ONCE(current->mm);
rcu_sleep_check();
preempt_disable();
current->flags |= PF_IDLE;
cpuidle_use_deepest_state(latency_ns);
it.done = 0;
hrtimer_setup_on_stack(&it.timer, idle_inject_timer_fn, CLOCK_MONOTONIC,
HRTIMER_MODE_REL_HARD);
hrtimer_start(&it.timer, ns_to_ktime(duration_ns),
HRTIMER_MODE_REL_PINNED_HARD);
while (!READ_ONCE(it.done))
do_idle();
cpuidle_use_deepest_state(0);
current->flags &= ~PF_IDLE;
preempt_fold_need_resched();
preempt_enable();
}
EXPORT_SYMBOL_GPL(play_idle_precise);
void cpu_startup_entry(enum cpuhp_state state)
{
current->flags |= PF_IDLE;
arch_cpu_idle_prepare();
cpuhp_online_idle(state);
while (1)
do_idle();
}
/*
* idle-task scheduling class.
*/
static int
select_task_rq_idle(struct task_struct *p, int cpu, int flags)
{
return task_cpu(p); /* IDLE tasks as never migrated */
}
static int
balance_idle(struct rq *rq, struct rq_flags *rf)
{
return WARN_ON_ONCE(1);
}
/*
* Idle tasks are unconditionally rescheduled:
*/
static void wakeup_preempt_idle(struct rq *rq, struct task_struct *p, int flags)
{
resched_curr(rq);
}
static void update_curr_idle(struct rq *rq);
static void put_prev_task_idle(struct rq *rq, struct task_struct *prev, struct task_struct *next)
{
update_curr_idle(rq);
Annotation
- Immediate include surface: `linux/cpuidle.h`, `linux/suspend.h`, `linux/livepatch.h`, `sched.h`, `smp.h`.
- Detected declarations: `struct idle_timer`, `function sched_idle_set_state`, `function cpu_idle_poll_ctrl`, `function cpu_idle_poll_setup`, `function cpu_idle_nopoll_setup`, `function cpu_idle_poll`, `function arch_cpu_idle_prepare`, `function arch_cpu_idle`, `function cond_tick_broadcast_enter`, `function cond_tick_broadcast_exit`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.