kernel/sched/rt.c
Source file repositories/reference/linux-study-clean/kernel/sched/rt.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/rt.c- Extension
.c- Size
- 71182 bytes
- Lines
- 2946
- 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
sched.hpelt.h
Detected Declarations
struct rt_schedulable_datafunction sched_rt_sysctl_initfunction init_rt_rqfunction sched_rt_period_timerfunction init_rt_bandwidthfunction do_start_rt_bandwidthfunction start_rt_bandwidthfunction destroy_rt_bandwidthfunction unregister_rt_sched_groupfunction free_rt_sched_groupfunction for_each_possible_cpufunction init_tg_rt_entryfunction alloc_rt_sched_groupfunction for_each_possible_cpufunction unregister_rt_sched_groupfunction need_pull_rt_taskfunction rt_overloadedfunction rt_set_overloadfunction rt_clear_overloadfunction has_pushable_tasksfunction rt_queue_push_tasksfunction rt_queue_pull_taskfunction enqueue_pushable_taskfunction dequeue_pushable_taskfunction on_rt_rqfunction rt_task_fits_capacityfunction rt_task_fits_capacityfunction sched_rt_runtimefunction sched_rt_periodfunction sched_rt_rq_enqueuefunction sched_rt_rq_dequeuefunction rt_rq_throttledfunction rt_se_boostedfunction sched_rt_bandwidth_accountfunction do_balance_runtimefunction __disable_runtimefunction for_each_rt_rqfunction for_each_cpufunction __enable_runtimefunction balance_runtimefunction do_sched_rt_period_timerfunction for_each_cpufunction sched_rt_runtime_exceededfunction sched_rt_rq_enqueuefunction sched_rt_rq_dequeuefunction rt_rq_throttledfunction __enable_runtimefunction update_curr_rt
Annotated Snippet
struct rt_schedulable_data {
struct task_group *tg;
u64 rt_period;
u64 rt_runtime;
};
static int tg_rt_schedulable(struct task_group *tg, void *data)
{
struct rt_schedulable_data *d = data;
struct task_group *child;
u64 total, sum = 0;
u64 period, runtime;
period = ktime_to_ns(tg->rt_bandwidth.rt_period);
runtime = tg->rt_bandwidth.rt_runtime;
if (tg == d->tg) {
period = d->rt_period;
runtime = d->rt_runtime;
}
/*
* Cannot have more runtime than the period.
*/
if (runtime > period && runtime != RUNTIME_INF)
return -EINVAL;
/*
* Ensure we don't starve existing RT tasks if runtime turns zero.
*/
if (rt_bandwidth_enabled() && !runtime &&
tg->rt_bandwidth.rt_runtime && tg_has_rt_tasks(tg))
return -EBUSY;
total = to_ratio(period, runtime);
/*
* Nobody can have more than the global setting allows.
*/
if (total > to_ratio(global_rt_period(), global_rt_runtime()))
return -EINVAL;
/*
* The sum of our children's runtime should not exceed our own.
*/
list_for_each_entry_rcu(child, &tg->children, siblings) {
period = ktime_to_ns(child->rt_bandwidth.rt_period);
runtime = child->rt_bandwidth.rt_runtime;
if (child == d->tg) {
period = d->rt_period;
runtime = d->rt_runtime;
}
sum += to_ratio(period, runtime);
}
if (sum > total)
return -EINVAL;
return 0;
}
static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
{
int ret;
struct rt_schedulable_data data = {
.tg = tg,
.rt_period = period,
.rt_runtime = runtime,
};
rcu_read_lock();
ret = walk_tg_tree(tg_rt_schedulable, tg_nop, &data);
rcu_read_unlock();
return ret;
}
static int tg_set_rt_bandwidth(struct task_group *tg,
u64 rt_period, u64 rt_runtime)
{
int i, err = 0;
/*
* Disallowing the root group RT runtime is BAD, it would disallow the
* kernel creating (and or operating) RT threads.
*/
if (tg == &root_task_group && rt_runtime == 0)
Annotation
- Immediate include surface: `sched.h`, `pelt.h`.
- Detected declarations: `struct rt_schedulable_data`, `function sched_rt_sysctl_init`, `function init_rt_rq`, `function sched_rt_period_timer`, `function init_rt_bandwidth`, `function do_start_rt_bandwidth`, `function start_rt_bandwidth`, `function destroy_rt_bandwidth`, `function unregister_rt_sched_group`, `function free_rt_sched_group`.
- 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.