kernel/sched/sched.h
Source file repositories/reference/linux-study-clean/kernel/sched/sched.h
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/sched.h- Extension
.h- Size
- 117337 bytes
- Lines
- 4217
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/prandom.hlinux/sched/affinity.hlinux/sched/autogroup.hlinux/sched/cpufreq.hlinux/sched/deadline.hlinux/sched.hlinux/sched/loadavg.hlinux/sched/mm.hlinux/sched/rseq_api.hlinux/sched/signal.hlinux/sched/smt.hlinux/sched/stat.hlinux/sched/sysctl.hlinux/sched/task_flags.hlinux/sched/task.hlinux/sched/topology.hlinux/atomic.hlinux/bitmap.hlinux/bug.hlinux/capability.hlinux/cgroup_api.hlinux/cgroup.hlinux/context_tracking.hlinux/cpufreq.hlinux/cpumask_api.hlinux/cpuset.hlinux/ctype.hlinux/file.hlinux/fs_api.hlinux/hrtimer_api.hlinux/interrupt.hlinux/irq_work.h
Detected Declarations
struct rqstruct cfs_rqstruct rt_rqstruct sched_groupstruct cpuidle_statestruct asym_cap_datastruct rt_prio_arraystruct rt_bandwidthstruct dl_bwstruct cfs_bandwidthstruct task_groupstruct cfs_bandwidthstruct balance_callbackstruct cfs_rqstruct scx_rqstruct rt_rqstruct dl_rqstruct perf_domainstruct root_domainstruct uclamp_bucketstruct uclamp_rqstruct rqstruct rq_flagsstruct sched_group_capacitystruct sched_groupstruct cfs_tg_statestruct affinity_contextstruct sched_classstruct irqtimestruct sched_change_ctxenum scx_rq_flagsenum numa_topology_typeenum numa_faults_statsfunction weightfunction normal_policyfunction fair_policyfunction rt_policyfunction dl_policyfunction valid_policyfunction task_has_idle_policyfunction task_has_rt_policyfunction task_has_dl_policyfunction update_avgfunction sched_weight_from_cgroupfunction sched_weight_to_cgroupfunction kworkerfunction dl_entity_preemptfunction dl_bandwidth_enabled
Annotated Snippet
struct asym_cap_data {
struct list_head link;
struct rcu_head rcu;
unsigned long capacity;
unsigned long cpus[];
};
extern struct list_head asym_cap_list;
#define cpu_capacity_span(asym_data) to_cpumask((asym_data)->cpus)
/*
* Helpers for converting nanosecond timing to jiffy resolution
*/
#define NS_TO_JIFFIES(time) ((unsigned long)(time) / (NSEC_PER_SEC/HZ))
/*
* Increase resolution of nice-level calculations for 64-bit architectures.
* The extra resolution improves shares distribution and load balancing of
* low-weight task groups (eg. nice +19 on an autogroup), deeper task-group
* hierarchies, especially on larger systems. This is not a user-visible change
* and does not change the user-interface for setting shares/weights.
*
* We increase resolution only if we have enough bits to allow this increased
* resolution (i.e. 64-bit). The costs for increasing resolution when 32-bit
* are pretty high and the returns do not justify the increased costs.
*
* Really only required when CONFIG_FAIR_GROUP_SCHED=y is also set, but to
* increase coverage and consistency always enable it on 64-bit platforms.
*/
#ifdef CONFIG_64BIT
# define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT + SCHED_FIXEDPOINT_SHIFT)
# define scale_load(w) ((w) << SCHED_FIXEDPOINT_SHIFT)
# define scale_load_down(w) \
({ \
unsigned long __w = (w); \
\
if (__w) \
__w = max(2UL, __w >> SCHED_FIXEDPOINT_SHIFT); \
__w; \
})
#else
# define NICE_0_LOAD_SHIFT (SCHED_FIXEDPOINT_SHIFT)
# define scale_load(w) (w)
# define scale_load_down(w) (w)
#endif
/*
* Task weight (visible to users) and its load (invisible to users) have
* independent resolution, but they should be well calibrated. We use
* scale_load() and scale_load_down(w) to convert between them. The
* following must be true:
*
* scale_load(sched_prio_to_weight[NICE_TO_PRIO(0)-MAX_RT_PRIO]) == NICE_0_LOAD
*
*/
#define NICE_0_LOAD (1L << NICE_0_LOAD_SHIFT)
/*
* Single value that decides SCHED_DEADLINE internal math precision.
* 10 -> just above 1us
* 9 -> just above 0.5us
*/
#define DL_SCALE 10
/*
* Single value that denotes runtime == period, ie unlimited time.
*/
#define RUNTIME_INF ((u64)~0ULL)
static inline int idle_policy(int policy)
{
return policy == SCHED_IDLE;
}
static inline int normal_policy(int policy)
{
#ifdef CONFIG_SCHED_CLASS_EXT
if (policy == SCHED_EXT)
return true;
#endif
return policy == SCHED_NORMAL;
}
static inline int fair_policy(int policy)
{
return normal_policy(policy) || policy == SCHED_BATCH;
}
static inline int rt_policy(int policy)
Annotation
- Immediate include surface: `linux/prandom.h`, `linux/sched/affinity.h`, `linux/sched/autogroup.h`, `linux/sched/cpufreq.h`, `linux/sched/deadline.h`, `linux/sched.h`, `linux/sched/loadavg.h`, `linux/sched/mm.h`.
- Detected declarations: `struct rq`, `struct cfs_rq`, `struct rt_rq`, `struct sched_group`, `struct cpuidle_state`, `struct asym_cap_data`, `struct rt_prio_array`, `struct rt_bandwidth`, `struct dl_bw`, `struct cfs_bandwidth`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source 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.