From 159d0cf55f62ecd7f1dfb9c4e44ce442f13c78a6 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Sat, 15 Jun 2024 06:49:37 -1000 Subject: [PATCH] scx: Cosmetic changes - Whitespace and comment adj. - Use sched_class_above() instead of naked comparison. - Reorder hotplug functions. - s/promote_op_nth_arg()/set_arg_maybe_null()/. Relocate @arg_n after @op and remove promote_op_arg(). - Reorder declarations and dummy defs in kernel/sched/ext.h. No functional changes. --- kernel/sched/ext.c | 40 ++++++++++++++++------------------------ kernel/sched/ext.h | 14 +++++++------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 55a9c4fd208db..a57576ed5855d 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1017,7 +1017,7 @@ static u32 higher_bits(u32 flags) static u32 highest_bit(u32 flags) { int bit = fls(flags); - return ((u64) 1 << bit) >> 1; + return ((u64)1 << bit) >> 1; } /* @@ -1820,8 +1820,8 @@ static void do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags, goto local_norefill; /* - * If !rq->online, we already told the BPF scheduler that the CPU is - * offline. We're just trying to on/offline the CPU. Don't bother the + * If !scx_rq_online(), we already told the BPF scheduler that the CPU + * is offline and are just running the hotplug path. Don't bother the * BPF scheduler. */ if (!scx_rq_online(rq)) @@ -2402,7 +2402,8 @@ dispatch_to_local_dsq(struct rq *rq, struct rq_flags *rf, u64 dsq_id, } /* if the destination CPU is idle, wake it up */ - if (dsp && p->sched_class < dst_rq->curr->sched_class) + if (dsp && sched_class_above(p->sched_class, + dst_rq->curr->sched_class)) resched_curr(dst_rq); dispatch_to_local_dsq_unlock(rq, rf, src_rq, locked_dst_rq); @@ -3218,24 +3219,24 @@ static void handle_hotplug(struct rq *rq, bool online) online ? "online" : "offline"); } -static void rq_online_scx(struct rq *rq) +void scx_rq_activate(struct rq *rq) { - rq->scx.flags |= SCX_RQ_ONLINE; + handle_hotplug(rq, true); } -static void rq_offline_scx(struct rq *rq) +void scx_rq_deactivate(struct rq *rq) { - rq->scx.flags &= ~SCX_RQ_ONLINE; + handle_hotplug(rq, false); } -void scx_rq_activate(struct rq *rq) +static void rq_online_scx(struct rq *rq) { - handle_hotplug(rq, true); + rq->scx.flags |= SCX_RQ_ONLINE; } -void scx_rq_deactivate(struct rq *rq) +static void rq_offline_scx(struct rq *rq) { - handle_hotplug(rq, false); + rq->scx.flags &= ~SCX_RQ_ONLINE; } #else /* CONFIG_SMP */ @@ -5183,8 +5184,7 @@ extern struct btf *btf_vmlinux; static const struct btf_type *task_struct_type; static u32 task_struct_type_id; -static bool promote_op_nth_arg(int arg_n, const char *op, - int off, int size, +static bool set_arg_maybe_null(const char *op, int arg_n, int off, int size, enum bpf_access_type type, const struct bpf_prog *prog, struct bpf_insn_access_aux *info) @@ -5242,15 +5242,6 @@ static bool promote_op_nth_arg(int arg_n, const char *op, return false; } -static bool promote_op_arg(int off, int size, - enum bpf_access_type type, - const struct bpf_prog *prog, - struct bpf_insn_access_aux *info) -{ - return promote_op_nth_arg(1, "dispatch", off, size, type, prog, info) || - promote_op_nth_arg(1, "yield", off, size, type, prog, info); -} - static bool bpf_scx_is_valid_access(int off, int size, enum bpf_access_type type, const struct bpf_prog *prog, @@ -5258,7 +5249,8 @@ static bool bpf_scx_is_valid_access(int off, int size, { if (type != BPF_READ) return false; - if (promote_op_arg(off, size, type, prog, info)) + if (set_arg_maybe_null("dispatch", 1, off, size, type, prog, info) || + set_arg_maybe_null("yield", 1, off, size, type, prog, info)) return true; if (off < 0 || off >= sizeof(__u64) * MAX_BPF_FUNC_ARGS) return false; diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h index 52d9b7df2a253..dddcf36b76a77 100644 --- a/kernel/sched/ext.h +++ b/kernel/sched/ext.h @@ -41,12 +41,12 @@ void scx_pre_fork(struct task_struct *p); int scx_fork(struct task_struct *p); void scx_post_fork(struct task_struct *p); void scx_cancel_fork(struct task_struct *p); -int scx_check_setscheduler(struct task_struct *p, int policy); bool scx_can_stop_tick(struct rq *rq); -bool task_should_scx(struct task_struct *p); -void init_sched_ext_class(void); void scx_rq_activate(struct rq *rq); void scx_rq_deactivate(struct rq *rq); +int scx_check_setscheduler(struct task_struct *p, int policy); +bool task_should_scx(struct task_struct *p); +void init_sched_ext_class(void); static inline u32 scx_cpuperf_target(s32 cpu) { @@ -97,13 +97,13 @@ static inline void scx_pre_fork(struct task_struct *p) {} static inline int scx_fork(struct task_struct *p) { return 0; } static inline void scx_post_fork(struct task_struct *p) {} static inline void scx_cancel_fork(struct task_struct *p) {} -static inline int scx_check_setscheduler(struct task_struct *p, int policy) { return 0; } -static inline bool scx_can_stop_tick(struct rq *rq) { return true; } -static inline bool task_on_scx(const struct task_struct *p) { return false; } -static inline void init_sched_ext_class(void) {} static inline u32 scx_cpuperf_target(s32 cpu) { return 0; } +static inline bool scx_can_stop_tick(struct rq *rq) { return true; } static inline void scx_rq_activate(struct rq *rq) {} static inline void scx_rq_deactivate(struct rq *rq) {} +static inline int scx_check_setscheduler(struct task_struct *p, int policy) { return 0; } +static inline bool task_on_scx(const struct task_struct *p) { return false; } +static inline void init_sched_ext_class(void) {} #define for_each_active_class for_each_class #define for_balance_class_range for_class_range