Re: [PATCH 12/34] sched_ext: Implement BPF extensible scheduler class

From: Tejun Heo
Date: Wed Aug 16 2023 - 15:21:13 EST


Hello, Vishal.

On Wed, Aug 16, 2023 at 05:15:43PM +0530, Vishal Chourasia wrote:
> > +static inline bool task_on_scx(struct task_struct *p)
> > +{
> > + return scx_enabled() && p->sched_class == &ext_sched_class;
> > +}
> While building the kernel, I encountered the following warning:
>
> {KERNEL_SRC}/kernel/sched/core.c: In function ‘__task_prio’:
> {KERNEL_SRC}/kernel/sched/core.c:170:25: warning: passing argument 1 of ‘task_on_scx’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
> 170 | if (task_on_scx(p))
> | ^
> In file included from {KERNEL_SRC}/kernel/sched/sched.h:3593,
> from {KERNEL_SRC}/kernel/sched/core.c:86:
> {KERNEL_SRC}/kernel/sched/ext.h:124:52: note: expected ‘struct task_struct *’ but argument is of type ‘const struct task_struct *’
> 124 | static inline bool task_on_scx(struct task_struct *p)
> | ~~~~~~~~~~~~~~~~~~~~^
>
> To address this warning, I'd suggest modifying the signature of `task_on_scx` to
> accept `task_struct` argument as `const`. The proposed change is as follows:
>
> diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h
> index 405037a4e6ce..e9c699a87770 100644
> --- a/kernel/sched/ext.h
> +++ b/kernel/sched/ext.h
> @@ -121,7 +121,7 @@ DECLARE_STATIC_KEY_FALSE(__scx_switched_all);
>
> DECLARE_STATIC_KEY_FALSE(scx_ops_cpu_preempt);
>
> -static inline bool task_on_scx(struct task_struct *p)
> +static inline bool task_on_scx(const struct task_struct *p)
> {
> return scx_enabled() && p->sched_class == &ext_sched_class;
> }
> @@ -214,7 +214,7 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,
> #define scx_enabled() false
> #define scx_switched_all() false
>
> -static inline bool task_on_scx(struct task_struct *p) { return false; }
> +static inline bool task_on_scx(const struct task_struct *p) { return false; }
> 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) {}

Yeah, this is already fixed in the github repo by the following commit:

https://github.com/sched-ext/sched_ext/commit/56b278fa8b5136457993f7389e34070d35f17e8a

The fix will be included in the next iteration.

Thanks.

--
tejun