kernel/sched/ext.c
Source file repositories/reference/linux-study-clean/kernel/sched/ext.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/ext.c- Extension
.c- Size
- 323496 bytes
- Lines
- 10883
- 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.
- 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
trace/events/sched_ext.hlinux/bpf_verifier.hlinux/bpf.hlinux/btf.h
Detected Declarations
struct scx_kick_syncsstruct scx_tid_allocstruct scx_bstr_bufstruct scx_dump_datastruct bpf_iter_scx_dsq_kernstruct bpf_iter_scx_dsqstruct scx_task_iterstruct scx_enable_cmdstruct scx_arena_scanstruct scx_bpf_dsq_insert_vtime_argsenum scx_dsq_iter_flagsenum scx_kf_allow_flagsfunction scx_tid_to_task_enabledfunction set_slice_usfunction set_bypass_lb_intv_usfunction jiffies_delta_msecsfunction u32_beforefunction scx_for_each_descendant_prefunction scx_set_task_schedfunction scx_set_task_schedfunction disable_bypass_dspfunction rq_is_openfunction update_locked_rqfunction scx_errorfunction scx_cpu_retfunction scx_call_op_set_cpumaskfunction scx_kf_arg_task_okfunction nldsq_cursor_lost_taskfunction scx_get_task_statefunction scx_set_task_statefunction scx_task_iter_stopfunction __scx_task_iter_rq_unlockfunction scx_task_iter_unlockfunction __scx_task_iter_maybe_relockfunction scx_task_iter_unlockfunction scx_task_iter_stopfunction list_for_each_entryfunction cgroup_task_deadfunction scx_enable_statefunction scx_set_enable_statefunction scx_tryset_enable_statefunction wait_ops_statefunction __cpu_validfunction scx_cpu_validfunction IS_ERRfunction deferred_bal_cb_workfnfunction deferred_irq_workfnfunction schedule_deferred
Annotated Snippet
core_initcall(scx_cgroup_lifetime_notifier_init);
#endif /* CONFIG_EXT_SUB_SCHED */
static s32 scx_enable(struct scx_enable_cmd *cmd, struct bpf_link *link)
{
static struct kthread_worker *helper;
static DEFINE_MUTEX(helper_mutex);
if (housekeeping_enabled(HK_TYPE_DOMAIN_BOOT)) {
pr_err("sched_ext: Not compatible with \"isolcpus=\" domain isolation\n");
return -EINVAL;
}
if (!READ_ONCE(helper)) {
mutex_lock(&helper_mutex);
if (!helper) {
struct kthread_worker *w =
kthread_run_worker(0, "scx_enable_helper");
if (IS_ERR_OR_NULL(w)) {
mutex_unlock(&helper_mutex);
return -ENOMEM;
}
sched_set_fifo(w->task);
WRITE_ONCE(helper, w);
}
mutex_unlock(&helper_mutex);
}
#ifdef CONFIG_EXT_SUB_SCHED
if (cmd->ops->sub_cgroup_id > 1)
kthread_init_work(&cmd->work, scx_sub_enable_workfn);
else
#endif /* CONFIG_EXT_SUB_SCHED */
kthread_init_work(&cmd->work, scx_root_enable_workfn);
kthread_queue_work(READ_ONCE(helper), &cmd->work);
kthread_flush_work(&cmd->work);
return cmd->ret;
}
/********************************************************************************
* bpf_struct_ops plumbing.
*/
#include <linux/bpf_verifier.h>
#include <linux/bpf.h>
#include <linux/btf.h>
static const struct btf_type *task_struct_type;
static bool bpf_scx_is_valid_access(int off, int size,
enum bpf_access_type type,
const struct bpf_prog *prog,
struct bpf_insn_access_aux *info)
{
if (type != BPF_READ)
return false;
if (off < 0 || off >= sizeof(__u64) * MAX_BPF_FUNC_ARGS)
return false;
if (off % size != 0)
return false;
return btf_ctx_access(off, size, type, prog, info);
}
static int bpf_scx_btf_struct_access(struct bpf_verifier_log *log,
const struct bpf_reg_state *reg, int off,
int size)
{
const struct btf_type *t;
t = btf_type_by_id(reg->btf, reg->btf_id);
if (t == task_struct_type) {
/*
* COMPAT: Will be removed in v6.23.
*/
if ((off >= offsetof(struct task_struct, scx.slice) &&
off + size <= offsetofend(struct task_struct, scx.slice)) ||
(off >= offsetof(struct task_struct, scx.dsq_vtime) &&
off + size <= offsetofend(struct task_struct, scx.dsq_vtime))) {
pr_warn("sched_ext: Writing directly to p->scx.slice/dsq_vtime is deprecated, use scx_bpf_task_set_slice/dsq_vtime()");
return SCALAR_VALUE;
}
if (off >= offsetof(struct task_struct, scx.disallow) &&
off + size <= offsetofend(struct task_struct, scx.disallow))
return SCALAR_VALUE;
}
return -EACCES;
Annotation
- Immediate include surface: `trace/events/sched_ext.h`, `linux/bpf_verifier.h`, `linux/bpf.h`, `linux/btf.h`.
- Detected declarations: `struct scx_kick_syncs`, `struct scx_tid_alloc`, `struct scx_bstr_buf`, `struct scx_dump_data`, `struct bpf_iter_scx_dsq_kern`, `struct bpf_iter_scx_dsq`, `struct scx_task_iter`, `struct scx_enable_cmd`, `struct scx_arena_scan`, `struct scx_bpf_dsq_insert_vtime_args`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.