Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

scx: Use the new struct_ops compatibililty mechanism #170

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 3 additions & 44 deletions tools/sched_ext/include/scx/compat.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,13 @@ static inline void __COMPAT_scx_bpf_switch_all(void)
}

/*
* sched_ext_ops.exit_dump_len is a recent addition. Use the following
* definition to support older kernels. See scx_qmap for usage example.
* Define sched_ext_ops. This may be expanded to define multiple variants for
* backward compatibility. See compat.h::SCX_OPS_LOAD/ATTACH().
*/
struct sched_ext_ops___no_exit_dump_len {
s32 (*select_cpu)(struct task_struct *, s32, u64);
void (*enqueue)(struct task_struct *, u64);
void (*dequeue)(struct task_struct *, u64);
void (*dispatch)(s32, struct task_struct *);
void (*runnable)(struct task_struct *, u64);
void (*running)(struct task_struct *);
void (*stopping)(struct task_struct *, bool);
void (*quiescent)(struct task_struct *, u64);
bool (*yield)(struct task_struct *, struct task_struct *);
bool (*core_sched_before)(struct task_struct *, struct task_struct *);
void (*set_weight)(struct task_struct *, u32);
void (*set_cpumask)(struct task_struct *, const struct cpumask *);
void (*update_idle)(s32, bool);
void (*cpu_acquire)(s32, struct scx_cpu_acquire_args *);
void (*cpu_release)(s32, struct scx_cpu_release_args *);
s32 (*init_task)(struct task_struct *, struct scx_init_task_args *);
void (*exit_task)(struct task_struct *, struct scx_exit_task_args *);
void (*enable)(struct task_struct *);
void (*disable)(struct task_struct *);
s32 (*cgroup_init)(struct cgroup *, struct scx_cgroup_init_args *);
void (*cgroup_exit)(struct cgroup *);
s32 (*cgroup_prep_move)(struct task_struct *, struct cgroup *, struct cgroup *);
void (*cgroup_move)(struct task_struct *, struct cgroup *, struct cgroup *);
void (*cgroup_cancel_move)(struct task_struct *, struct cgroup *, struct cgroup *);
void (*cgroup_set_weight)(struct cgroup *, u32);
void (*cpu_online)(s32);
void (*cpu_offline)(s32);
s32 (*init)();
void (*exit)(struct scx_exit_info *);
u32 dispatch_max_batch;
u64 flags;
u32 timeout_ms;
char name[128];
};

/* define sched_ext_ops, see compat.h::SCX_OPS_LOAD/ATTACH() */
#define SCX_OPS_DEFINE(__name, ...) \
SEC(".struct_ops.link") \
struct sched_ext_ops __name = { \
__VA_ARGS__, \
}; \
SEC(".struct_ops.link") \
struct sched_ext_ops___no_exit_dump_len __name##___no_exit_dump_len = { \
__VA_ARGS__ \
}; \
};

#endif /* __SCX_COMPAT_BPF_H */
17 changes: 5 additions & 12 deletions tools/sched_ext/include/scx/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,17 @@ static inline bool __COMPAT_struct_has_field(const char *type, const char *field
*/
#define SCX_OPS_LOAD(__skel, __ops_name, __scx_name, __uei_name) ({ \
UEI_SET_SIZE(__skel, __ops_name, __uei_name); \
if (__COMPAT_struct_has_field("sched_ext_ops", "exit_dump_len")) { \
bpf_map__set_autocreate((__skel)->maps.__ops_name, true); \
bpf_map__set_autocreate((__skel)->maps.__ops_name##___no_exit_dump_len, false); \
} else { \
if ((__skel)->struct_ops.__ops_name->exit_dump_len) \
fprintf(stderr, "WARNING: kernel doesn't support setting exit dump len\n"); \
bpf_map__set_autocreate((__skel)->maps.__ops_name, false); \
bpf_map__set_autocreate((__skel)->maps.__ops_name##___no_exit_dump_len, true); \
if (__COMPAT_struct_has_field("sched_ext_ops", "exit_dump_len") && \
(__skel)->struct_ops.__ops_name->exit_dump_len) { \
fprintf(stderr, "WARNING: kernel doesn't support setting exit dump len\n"); \
(__skel)->struct_ops.__ops_name->exit_dump_len = 0; \
} \
SCX_BUG_ON(__scx_name##__load((__skel)), "Failed to load skel"); \
})

#define SCX_OPS_ATTACH(__skel, __ops_name) ({ \
struct bpf_link *__link; \
if (__COMPAT_struct_has_field("sched_ext_ops", "exit_dump_len")) \
__link = bpf_map__attach_struct_ops((__skel)->maps.__ops_name); \
else \
__link = bpf_map__attach_struct_ops((__skel)->maps.__ops_name##___no_exit_dump_len); \
__link = bpf_map__attach_struct_ops((__skel)->maps.__ops_name); \
SCX_BUG_ON(!__link, "Failed to attach struct_ops"); \
__link; \
})
Expand Down