tools/sched_ext/scx_flatcg.bpf.c
Source file repositories/reference/linux-study-clean/tools/sched_ext/scx_flatcg.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/sched_ext/scx_flatcg.bpf.c- Extension
.c- Size
- 25218 bytes
- Lines
- 967
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
scx/common.bpf.hscx_flatcg.h
Detected Declarations
struct fcg_cpu_ctxstruct cgv_nodestruct cgv_node_stashstruct fcg_task_ctxfunction stat_incfunction div_round_upfunction cgv_node_lessfunction cgrp_refresh_hweightfunction cgrp_cap_budgetfunction cgrp_enqueuedfunction set_bypassed_atfunction BPF_STRUCT_OPSfunction select_cpu_dflfunction BPF_STRUCT_OPSfunction update_active_weight_sumsfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction try_pick_next_cgroupfunction BPF_STRUCT_OPSfunction bpf_repeatfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPS_SLEEPABLEfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPSfunction BPF_STRUCT_OPS_SLEEPABLEfunction BPF_STRUCT_OPS
Annotated Snippet
struct fcg_cpu_ctx {
u64 cur_cgid;
u64 cur_at;
};
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__type(key, u32);
__type(value, struct fcg_cpu_ctx);
__uint(max_entries, 1);
} cpu_ctx SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_CGRP_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct fcg_cgrp_ctx);
} cgrp_ctx SEC(".maps");
struct cgv_node {
struct bpf_rb_node rb_node;
__u64 cvtime;
__u64 cgid;
};
private(CGV_TREE) struct bpf_spin_lock cgv_tree_lock;
private(CGV_TREE) struct bpf_rb_root cgv_tree __contains(cgv_node, rb_node);
struct cgv_node_stash {
struct cgv_node __kptr *node;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 16384);
__type(key, __u64);
__type(value, struct cgv_node_stash);
} cgv_node_stash SEC(".maps");
struct fcg_task_ctx {
u64 bypassed_at;
};
struct {
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct fcg_task_ctx);
} task_ctx SEC(".maps");
/* gets inc'd on weight tree changes to expire the cached hweights */
u64 hweight_gen = 1;
static u64 div_round_up(u64 dividend, u64 divisor)
{
return (dividend + divisor - 1) / divisor;
}
static bool cgv_node_less(struct bpf_rb_node *a, const struct bpf_rb_node *b)
{
struct cgv_node *cgc_a, *cgc_b;
cgc_a = container_of(a, struct cgv_node, rb_node);
cgc_b = container_of(b, struct cgv_node, rb_node);
return cgc_a->cvtime < cgc_b->cvtime;
}
static struct fcg_cpu_ctx *find_cpu_ctx(void)
{
struct fcg_cpu_ctx *cpuc;
u32 idx = 0;
cpuc = bpf_map_lookup_elem(&cpu_ctx, &idx);
if (!cpuc) {
scx_bpf_error("cpu_ctx lookup failed");
return NULL;
}
return cpuc;
}
static struct fcg_cgrp_ctx *find_cgrp_ctx(struct cgroup *cgrp)
{
struct fcg_cgrp_ctx *cgc;
cgc = bpf_cgrp_storage_get(&cgrp_ctx, cgrp, 0, 0);
if (!cgc) {
scx_bpf_error("cgrp_ctx lookup failed for cgid %llu", cgrp->kn->id);
return NULL;
}
Annotation
- Immediate include surface: `scx/common.bpf.h`, `scx_flatcg.h`.
- Detected declarations: `struct fcg_cpu_ctx`, `struct cgv_node`, `struct cgv_node_stash`, `struct fcg_task_ctx`, `function stat_inc`, `function div_round_up`, `function cgv_node_less`, `function cgrp_refresh_hweight`, `function cgrp_cap_budget`, `function cgrp_enqueued`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.