Re: [PATCH v2] sched/rt: Clean up usage of rt_task()
From: Qais Yousef
Date: Mon May 27 2024 - 13:37:20 EST
On 05/23/24 11:45, Steven Rostedt wrote:
> On Wed, 15 May 2024 23:05:36 +0100
> Qais Yousef <qyousef@xxxxxxxxxxx> wrote:
> > diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h
> > index df3aca89d4f5..5cb88b748ad6 100644
> > --- a/include/linux/sched/deadline.h
> > +++ b/include/linux/sched/deadline.h
> > @@ -10,8 +10,6 @@
> >
> > #include <linux/sched.h>
> >
> > -#define MAX_DL_PRIO 0
> > -
> > static inline int dl_prio(int prio)
> > {
> > if (unlikely(prio < MAX_DL_PRIO))
> > @@ -19,6 +17,10 @@ static inline int dl_prio(int prio)
> > return 0;
> > }
> >
> > +/*
> > + * Returns true if a task has a priority that belongs to DL class. PI-boosted
> > + * tasks will return true. Use dl_policy() to ignore PI-boosted tasks.
> > + */
> > static inline int dl_task(struct task_struct *p)
> > {
> > return dl_prio(p->prio);
> > diff --git a/include/linux/sched/prio.h b/include/linux/sched/prio.h
> > index ab83d85e1183..6ab43b4f72f9 100644
> > --- a/include/linux/sched/prio.h
> > +++ b/include/linux/sched/prio.h
> > @@ -14,6 +14,7 @@
> > */
> >
> > #define MAX_RT_PRIO 100
> > +#define MAX_DL_PRIO 0
> >
> > #define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH)
> > #define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2)
> > diff --git a/include/linux/sched/rt.h b/include/linux/sched/rt.h
> > index b2b9e6eb9683..a055dd68a77c 100644
> > --- a/include/linux/sched/rt.h
> > +++ b/include/linux/sched/rt.h
> > @@ -7,18 +7,43 @@
> > struct task_struct;
> >
> > static inline int rt_prio(int prio)
> > +{
> > + if (unlikely(prio < MAX_RT_PRIO && prio >= MAX_DL_PRIO))
> > + return 1;
> > + return 0;
> > +}
> > +
> > +static inline int realtime_prio(int prio)
> > {
> > if (unlikely(prio < MAX_RT_PRIO))
> > return 1;
> > return 0;
> > }
>
> I'm thinking we should change the above to bool (separate patch), as
> returning an int may give one the impression that it returns the actual
> priority number. Having it return bool will clear that up.
>
> In fact, if we are touching theses functions, might as well change all of
> them to bool when returning true/false. Just to make it easier to
> understand what they are doing.
I can add a patch on top, sure.
>
> >
> > +/*
> > + * Returns true if a task has a priority that belongs to RT class. PI-boosted
> > + * tasks will return true. Use rt_policy() to ignore PI-boosted tasks.
> > + */
> > static inline int rt_task(struct task_struct *p)
> > {
> > return rt_prio(p->prio);
> > }
> >
> > -static inline bool task_is_realtime(struct task_struct *tsk)
> > +/*
> > + * Returns true if a task has a priority that belongs to RT or DL classes.
> > + * PI-boosted tasks will return true. Use realtime_task_policy() to ignore
> > + * PI-boosted tasks.
> > + */
> > +static inline int realtime_task(struct task_struct *p)
> > +{
> > + return realtime_prio(p->prio);
> > +}
> > +
> > +/*
> > + * Returns true if a task has a policy that belongs to RT or DL classes.
> > + * PI-boosted tasks will return false.
> > + */
> > +static inline bool realtime_task_policy(struct task_struct *tsk)
> > {
> > int policy = tsk->policy;
> >
>
>
>
> > diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c
> > index 0469a04a355f..19d737742e29 100644
> > --- a/kernel/trace/trace_sched_wakeup.c
> > +++ b/kernel/trace/trace_sched_wakeup.c
> > @@ -545,7 +545,7 @@ probe_wakeup(void *ignore, struct task_struct *p)
> > * - wakeup_dl handles tasks belonging to sched_dl class only.
> > */
> > if (tracing_dl || (wakeup_dl && !dl_task(p)) ||
> > - (wakeup_rt && !dl_task(p) && !rt_task(p)) ||
> > + (wakeup_rt && !realtime_task(p)) ||
> > (!dl_task(p) && (p->prio >= wakeup_prio || p->prio >= current->prio)))
> > return;
> >
>
> Reviewed-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
Thanks!
--
Qais Yousef
>
>