kernel/sched/core.c
Source file repositories/reference/linux-study-clean/kernel/sched/core.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/core.c- Extension
.c- Size
- 301324 bytes
- Lines
- 11270
- 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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched.hlinux/highmem.hlinux/hrtimer_api.hlinux/ktime_api.hlinux/sched/signal.hlinux/syscalls_api.hlinux/debug_locks.hlinux/prefetch.hlinux/capability.hlinux/pgtable_api.hlinux/wait_bit.hlinux/jiffies.hlinux/spinlock_api.hlinux/cpumask_api.hlinux/lockdep_api.hlinux/hardirq.hlinux/softirq.hlinux/refcount_api.hlinux/topology.hlinux/sched/clock.hlinux/sched/cond_resched.hlinux/sched/cputime.hlinux/sched/debug.hlinux/sched/hotplug.hlinux/sched/init.hlinux/sched/isolation.hlinux/sched/loadavg.hlinux/sched/mm.hlinux/sched/nohz.hlinux/sched/rseq_api.hlinux/sched/rt.hlinux/blkdev.h
Detected Declarations
struct migration_argstruct set_affinity_pendingstruct migration_swap_argstruct tick_workstruct uclamp_requeststruct cfs_schedulable_datafunction setup_proxy_execfunction setup_proxy_execfunction __task_priofunction lfunction __sched_core_lessfunction rb_sched_core_lessfunction rb_sched_core_cmpfunction sched_core_enqueuefunction sched_core_dequeuefunction sched_task_is_throttledfunction __sched_core_flipfunction sched_core_assert_emptyfunction __sched_core_enablefunction __sched_core_disablefunction sched_core_getfunction __sched_core_putfunction sched_core_putfunction sched_core_enqueuefunction tracepoint_enabledfunction task_llcfunction ttwu_queue_wakelistfunction raw_spin_rq_trylockfunction double_rq_lockfunction RELEASEfunction update_rq_clock_taskfunction update_rq_clockfunction hrtick_clearfunction hrtickfunction hrtick_needs_rearmfunction hrtick_cond_restartfunction hardirqfunction hrtick_startfunction schedulefunction hrtick_schedule_enterfunction hrtick_schedule_exitfunction hrtick_rq_initfunction hrtick_clearfunction set_nr_and_not_pollingfunction sched_ttwu_pendingfunction set_nr_and_not_pollingfunction set_nr_if_pollingfunction __wake_q_add
Annotated Snippet
* copy_process() sysctl_uclamp
* uclamp_min_rt = X;
* write_lock(&tasklist_lock) read_lock(&tasklist_lock)
* // link thread smp_mb__after_spinlock()
* write_unlock(&tasklist_lock) read_unlock(&tasklist_lock);
* sched_post_fork() for_each_process_thread()
* __uclamp_sync_rt() __uclamp_sync_rt()
*
* Ensures that either sched_post_fork() will observe the new
* uclamp_min_rt or for_each_process_thread() will observe the new
* task.
*/
read_lock(&tasklist_lock);
smp_mb__after_spinlock();
read_unlock(&tasklist_lock);
guard(rcu)();
for_each_process_thread(g, p)
uclamp_update_util_min_rt_default(p);
}
static int sysctl_sched_uclamp_handler(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
bool update_root_tg = false;
int old_min, old_max, old_min_rt;
int result;
guard(mutex)(&uclamp_mutex);
old_min = sysctl_sched_uclamp_util_min;
old_max = sysctl_sched_uclamp_util_max;
old_min_rt = sysctl_sched_uclamp_util_min_rt_default;
result = proc_dointvec(table, write, buffer, lenp, ppos);
if (result)
goto undo;
if (!write)
return 0;
if (sysctl_sched_uclamp_util_min > sysctl_sched_uclamp_util_max ||
sysctl_sched_uclamp_util_max > SCHED_CAPACITY_SCALE ||
sysctl_sched_uclamp_util_min_rt_default > SCHED_CAPACITY_SCALE) {
result = -EINVAL;
goto undo;
}
if (old_min != sysctl_sched_uclamp_util_min) {
uclamp_se_set(&uclamp_default[UCLAMP_MIN],
sysctl_sched_uclamp_util_min, false);
update_root_tg = true;
}
if (old_max != sysctl_sched_uclamp_util_max) {
uclamp_se_set(&uclamp_default[UCLAMP_MAX],
sysctl_sched_uclamp_util_max, false);
update_root_tg = true;
}
if (update_root_tg) {
sched_uclamp_enable();
uclamp_update_root_tg();
}
if (old_min_rt != sysctl_sched_uclamp_util_min_rt_default) {
sched_uclamp_enable();
uclamp_sync_util_min_rt_default();
}
/*
* We update all RUNNABLE tasks only when task groups are in use.
* Otherwise, keep it simple and do just a lazy update at each next
* task enqueue time.
*/
return 0;
undo:
sysctl_sched_uclamp_util_min = old_min;
sysctl_sched_uclamp_util_max = old_max;
sysctl_sched_uclamp_util_min_rt_default = old_min_rt;
return result;
}
#endif /* CONFIG_SYSCTL */
static void uclamp_fork(struct task_struct *p)
{
enum uclamp_id clamp_id;
/*
* We don't need to hold task_rq_lock() when updating p->uclamp_* here
Annotation
- Immediate include surface: `linux/sched.h`, `linux/highmem.h`, `linux/hrtimer_api.h`, `linux/ktime_api.h`, `linux/sched/signal.h`, `linux/syscalls_api.h`, `linux/debug_locks.h`, `linux/prefetch.h`.
- Detected declarations: `struct migration_arg`, `struct set_affinity_pending`, `struct migration_swap_arg`, `struct tick_work`, `struct uclamp_request`, `struct cfs_schedulable_data`, `function setup_proxy_exec`, `function setup_proxy_exec`, `function __task_prio`, `function l`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.