1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Shared definitions between scx_qmap.bpf.c and scx_qmap.c. 4 * 5 * The scheduler keeps all state in a single BPF arena map. struct 6 * qmap_arena is the one object that lives at the base of the arena and is 7 * mmap'd into userspace so the loader can read counters directly. 8 * 9 * Copyright (c) 2026 Meta Platforms, Inc. and affiliates. 10 * Copyright (c) 2026 Tejun Heo <tj@kernel.org> 11 */ 12 #ifndef __SCX_QMAP_H 13 #define __SCX_QMAP_H 14 15 #ifdef __BPF__ 16 #include <scx/bpf_arena_common.bpf.h> 17 #else 18 #include <linux/types.h> 19 #include <scx/bpf_arena_common.h> 20 #endif 21 22 #define MAX_SUB_SCHEDS 8 23 24 /* 25 * cpu_ctxs[] is sized to a fixed cap so the layout is shared between BPF and 26 * userspace. Keep this in sync with NR_CPUS used by the BPF side. 27 */ 28 #define SCX_QMAP_MAX_CPUS 1024 29 30 struct cpu_ctx { 31 __u64 dsp_idx; /* dispatch index */ 32 __u64 dsp_cnt; /* remaining count */ 33 __u32 avg_weight; 34 __u32 cpuperf_target; 35 }; 36 37 /* Opaque to userspace; defined in scx_qmap.bpf.c. */ 38 struct task_ctx; 39 40 struct qmap_fifo { 41 struct task_ctx __arena *head; 42 struct task_ctx __arena *tail; 43 __s32 idx; 44 }; 45 46 struct qmap_arena { 47 /* userspace-visible stats */ 48 __u64 nr_enqueued, nr_dispatched, nr_reenqueued, nr_reenqueued_cid0; 49 __u64 nr_dequeued, nr_ddsp_from_enq; 50 __u64 nr_core_sched_execed; 51 __u64 nr_expedited_local, nr_expedited_remote; 52 __u64 nr_expedited_lost, nr_expedited_from_timer; 53 __u64 nr_highpri_queued; 54 __u32 test_error_cnt; 55 __u32 cpuperf_min, cpuperf_avg, cpuperf_max; 56 __u32 cpuperf_target_min, cpuperf_target_avg, cpuperf_target_max; 57 58 /* kernel-side runtime state */ 59 __u64 sub_sched_cgroup_ids[MAX_SUB_SCHEDS]; 60 __u64 core_sched_head_seqs[5]; 61 __u64 core_sched_tail_seqs[5]; 62 63 struct cpu_ctx cpu_ctxs[SCX_QMAP_MAX_CPUS]; 64 65 /* task_ctx slab; allocated and threaded by qmap_init() */ 66 struct task_ctx __arena *task_ctxs; 67 struct task_ctx __arena *task_free_head; 68 69 /* five priority FIFOs, each a doubly-linked list through task_ctx */ 70 struct qmap_fifo fifos[5]; 71 }; 72 73 #endif /* __SCX_QMAP_H */ 74