summaryrefslogtreecommitdiff
path: root/tools/sched_ext/scx_qmap.h
blob: d15a705d5ac5205142c16719cbc2fdf7555e1883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Shared definitions between scx_qmap.bpf.c and scx_qmap.c.
 *
 * The scheduler keeps all state in a single BPF arena map. struct
 * qmap_arena is the one object that lives at the base of the arena and is
 * mmap'd into userspace so the loader can read counters directly.
 *
 * Copyright (c) 2026 Meta Platforms, Inc. and affiliates.
 * Copyright (c) 2026 Tejun Heo <tj@kernel.org>
 */
#ifndef __SCX_QMAP_H
#define __SCX_QMAP_H

#ifdef __BPF__
#include <scx/bpf_arena_common.bpf.h>
#else
#include <linux/types.h>
#include <scx/bpf_arena_common.h>
#endif

#define MAX_SUB_SCHEDS		8

/*
 * cpu_ctxs[] is sized to a fixed cap so the layout is shared between BPF and
 * userspace. Keep this in sync with NR_CPUS used by the BPF side.
 */
#define SCX_QMAP_MAX_CPUS	1024

struct cpu_ctx {
	__u64 dsp_idx;		/* dispatch index */
	__u64 dsp_cnt;		/* remaining count */
	__u32 avg_weight;
	__u32 cpuperf_target;
};

/* Opaque to userspace; defined in scx_qmap.bpf.c. */
struct task_ctx;

struct qmap_fifo {
	struct task_ctx __arena *head;
	struct task_ctx __arena *tail;
	__s32 idx;
};

struct qmap_arena {
	/* userspace-visible stats */
	__u64 nr_enqueued, nr_dispatched, nr_reenqueued, nr_reenqueued_cid0;
	__u64 nr_dequeued, nr_ddsp_from_enq;
	__u64 nr_core_sched_execed;
	__u64 nr_expedited_local, nr_expedited_remote;
	__u64 nr_expedited_lost, nr_expedited_from_timer;
	__u64 nr_highpri_queued;
	__u32 test_error_cnt;
	__u32 cpuperf_min, cpuperf_avg, cpuperf_max;
	__u32 cpuperf_target_min, cpuperf_target_avg, cpuperf_target_max;

	/* kernel-side runtime state */
	__u64 sub_sched_cgroup_ids[MAX_SUB_SCHEDS];
	__u64 core_sched_head_seqs[5];
	__u64 core_sched_tail_seqs[5];

	struct cpu_ctx cpu_ctxs[SCX_QMAP_MAX_CPUS];

	/* task_ctx slab; allocated and threaded by qmap_init() */
	struct task_ctx __arena *task_ctxs;
	struct task_ctx __arena *task_free_head;

	/* five priority FIFOs, each a doubly-linked list through task_ctx */
	struct qmap_fifo fifos[5];
};

#endif /* __SCX_QMAP_H */