tools/sched_ext/include/scx/compat.bpf.h

Source file repositories/reference/linux-study-clean/tools/sched_ext/include/scx/compat.bpf.h

File Facts

System
Linux kernel
Corpus path
tools/sched_ext/include/scx/compat.bpf.h
Extension
.h
Size
16613 bytes
Lines
462
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.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef __SCX_COMPAT_BPF_H
#define __SCX_COMPAT_BPF_H

#define __COMPAT_ENUM_OR_ZERO(__type, __ent)					\
({										\
	__type __ret = 0;							\
	if (bpf_core_enum_value_exists(__type, __ent))				\
		__ret = __ent;							\
	__ret;									\
})

/* v6.12: 819513666966 ("sched_ext: Add cgroup support") */
struct cgroup *scx_bpf_task_cgroup___new(struct task_struct *p) __ksym __weak;

#define scx_bpf_task_cgroup(p)							\
	(bpf_ksym_exists(scx_bpf_task_cgroup___new) ?				\
	 scx_bpf_task_cgroup___new((p)) : NULL)

/*
 * v6.13: The verb `dispatch` was too overloaded and confusing. kfuncs are
 * renamed to unload the verb.
 *
 * scx_bpf_dispatch_from_dsq() and friends were added during v6.12 by
 * 4c30f5ce4f7a ("sched_ext: Implement scx_bpf_dispatch[_vtime]_from_dsq()").
 *
 * v7.1: scx_bpf_dsq_move_to_local___v2() to add @enq_flags.
 */
bool scx_bpf_dsq_move_to_local___v2(u64 dsq_id, u64 enq_flags) __ksym __weak;
bool scx_bpf_dsq_move_to_local___v1(u64 dsq_id) __ksym __weak;
void scx_bpf_dsq_move_set_slice___new(struct bpf_iter_scx_dsq *it__iter, u64 slice) __ksym __weak;
void scx_bpf_dsq_move_set_vtime___new(struct bpf_iter_scx_dsq *it__iter, u64 vtime) __ksym __weak;
bool scx_bpf_dsq_move___new(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak;
bool scx_bpf_dsq_move_vtime___new(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak;

bool scx_bpf_consume___old(u64 dsq_id) __ksym __weak;
void scx_bpf_dispatch_from_dsq_set_slice___old(struct bpf_iter_scx_dsq *it__iter, u64 slice) __ksym __weak;
void scx_bpf_dispatch_from_dsq_set_vtime___old(struct bpf_iter_scx_dsq *it__iter, u64 vtime) __ksym __weak;
bool scx_bpf_dispatch_from_dsq___old(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak;
bool scx_bpf_dispatch_vtime_from_dsq___old(struct bpf_iter_scx_dsq *it__iter, struct task_struct *p, u64 dsq_id, u64 enq_flags) __ksym __weak;

#define scx_bpf_dsq_move_to_local(dsq_id, enq_flags)				\
	(bpf_ksym_exists(scx_bpf_dsq_move_to_local___v2) ?			\
	 scx_bpf_dsq_move_to_local___v2((dsq_id), (enq_flags)) :		\
	 (bpf_ksym_exists(scx_bpf_dsq_move_to_local___v1) ?			\
	  scx_bpf_dsq_move_to_local___v1((dsq_id)) :				\
	  scx_bpf_consume___old((dsq_id))))

#define scx_bpf_dsq_move_set_slice(it__iter, slice)				\
	(bpf_ksym_exists(scx_bpf_dsq_move_set_slice___new) ?			\
	 scx_bpf_dsq_move_set_slice___new((it__iter), (slice)) :		\
	 (bpf_ksym_exists(scx_bpf_dispatch_from_dsq_set_slice___old) ?		\
	  scx_bpf_dispatch_from_dsq_set_slice___old((it__iter), (slice)) :	\
	  (void)0))

#define scx_bpf_dsq_move_set_vtime(it__iter, vtime)				\
	(bpf_ksym_exists(scx_bpf_dsq_move_set_vtime___new) ?			\
	 scx_bpf_dsq_move_set_vtime___new((it__iter), (vtime)) :		\
	 (bpf_ksym_exists(scx_bpf_dispatch_from_dsq_set_vtime___old) ?		\
	  scx_bpf_dispatch_from_dsq_set_vtime___old((it__iter), (vtime)) :	\
	  (void)0))

#define scx_bpf_dsq_move(it__iter, p, dsq_id, enq_flags)			\
	(bpf_ksym_exists(scx_bpf_dsq_move___new) ?				\
	 scx_bpf_dsq_move___new((it__iter), (p), (dsq_id), (enq_flags)) :	\
	 (bpf_ksym_exists(scx_bpf_dispatch_from_dsq___old) ?			\
	  scx_bpf_dispatch_from_dsq___old((it__iter), (p), (dsq_id), (enq_flags)) : \
	  false))

#define scx_bpf_dsq_move_vtime(it__iter, p, dsq_id, enq_flags)			\
	(bpf_ksym_exists(scx_bpf_dsq_move_vtime___new) ?			\
	 scx_bpf_dsq_move_vtime___new((it__iter), (p), (dsq_id), (enq_flags)) : \
	 (bpf_ksym_exists(scx_bpf_dispatch_vtime_from_dsq___old) ?		\
	  scx_bpf_dispatch_vtime_from_dsq___old((it__iter), (p), (dsq_id), (enq_flags)) : \
	  false))

/*
 * v6.15: 950ad93df2fc ("bpf: add kfunc for populating cpumask bits")
 *
 * Compat macro will be dropped on v6.19 release.
 */
int bpf_cpumask_populate(struct cpumask *dst, void *src, size_t src__sz) __ksym __weak;

#define __COMPAT_bpf_cpumask_populate(cpumask, src, size__sz)		\
	(bpf_ksym_exists(bpf_cpumask_populate) ?			\
	 (bpf_cpumask_populate(cpumask, src, size__sz)) : -EOPNOTSUPP)

/*
 * v6.19: Introduce lockless peek API for user DSQs.
 *
 * Preserve the following macro until v6.21.

Annotation

Implementation Notes