[RFC,1/3] sched/core: Provide a method to check if a task is PI-boosted.

Message ID 20230804113039.419794-2-bigeasy@linutronix.de
State New
Headers
Series Allow to preempt a timer softirq on PREEMPT_RT. |

Commit Message

Sebastian Andrzej Siewior Aug. 4, 2023, 11:30 a.m. UTC
  Provide a method to check if a task inherited the priority from another
task. This happens if a task owns a lock which is requested by a task
with higher priority. This can be used as a hint to add a preemption
point to the critical section.

Provide a function which reports true if the task is PI-boosted.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/sched.h |  1 +
 kernel/sched/core.c   | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
  

Comments

Juri Lelli Nov. 2, 2023, 9:30 a.m. UTC | #1
Hi,

Apologies for noticing only now, but I believe this is still part of the
6.6-rt patches and I've got the below question to ask.

On 04/08/23 13:30, Sebastian Andrzej Siewior wrote:
> Provide a method to check if a task inherited the priority from another
> task. This happens if a task owns a lock which is requested by a task
> with higher priority. This can be used as a hint to add a preemption
> point to the critical section.
> 
> Provide a function which reports true if the task is PI-boosted.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  include/linux/sched.h |  1 +
>  kernel/sched/core.c   | 15 +++++++++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 609bde814cb06..77fd274133750 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1887,6 +1887,7 @@ static inline int dl_task_check_affinity(struct task_struct *p, const struct cpu
>  }
>  #endif
>  
> +extern bool task_is_pi_boosted(const struct task_struct *p);
>  extern int yield_to(struct task_struct *p, bool preempt);
>  extern void set_user_nice(struct task_struct *p, long nice);
>  extern int task_prio(const struct task_struct *p);
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index c52c2eba7c739..132f06522efa0 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8886,6 +8886,21 @@ static inline void preempt_dynamic_init(void) { }
>  
>  #endif /* #ifdef CONFIG_PREEMPT_DYNAMIC */
>  
> +/*
> + * task_is_pi_boosted - Check if task has been PI boosted.
> + * @p:	Task to check.
> + *
> + * Return true if task is subject to priority inheritance.
> + */
> +bool task_is_pi_boosted(const struct task_struct *p)
> +{
> +	int prio = p->prio;
> +
> +	if (!rt_prio(prio))
> +		return false;
> +	return prio != p->normal_prio;

Does this need to also take DEADLINE tasks into consideration? We don't
change priority when they are boosted, only pi_se changes (please check
is_dl_boosted()).

Thanks,
Juri
  
Sebastian Andrzej Siewior Nov. 2, 2023, 4:03 p.m. UTC | #2
On 2023-11-02 10:30:50 [+0100], Juri Lelli wrote:
> Hi,
Hi,

> Apologies for noticing only now, but I believe this is still part of the
> 6.6-rt patches and I've got the below question to ask.

I'm not sure if we want this. I do have an alternative solution in the
meantime.

> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -8886,6 +8886,21 @@ static inline void preempt_dynamic_init(void) { }
> >  
> >  #endif /* #ifdef CONFIG_PREEMPT_DYNAMIC */
> >  
> > +/*
> > + * task_is_pi_boosted - Check if task has been PI boosted.
> > + * @p:	Task to check.
> > + *
> > + * Return true if task is subject to priority inheritance.
> > + */
> > +bool task_is_pi_boosted(const struct task_struct *p)
> > +{
> > +	int prio = p->prio;
> > +
> > +	if (!rt_prio(prio))
> > +		return false;
> > +	return prio != p->normal_prio;
> 
> Does this need to also take DEADLINE tasks into consideration? We don't
> change priority when they are boosted, only pi_se changes (please check
> is_dl_boosted()).

If we want this, then probably yes.
Isn't task_struct::prio for the DL (boosted) task set to 0? While the RT
priority go from 1…MAX_RT_PRIO - 1.
 
> Thanks,
> Juri

Sebastian
  
Juri Lelli Nov. 3, 2023, 7:11 a.m. UTC | #3
On 02/11/23 17:03, Sebastian Andrzej Siewior wrote:
> On 2023-11-02 10:30:50 [+0100], Juri Lelli wrote:
> > Hi,
> Hi,
> 
> > Apologies for noticing only now, but I believe this is still part of the
> > 6.6-rt patches and I've got the below question to ask.
> 
> I'm not sure if we want this. I do have an alternative solution in the
> meantime.

Ah, OK. Guess what below is moot then. :) Will be watching for the
alternative solution to show up.
> 
> > > --- a/kernel/sched/core.c
> > > +++ b/kernel/sched/core.c
> > > @@ -8886,6 +8886,21 @@ static inline void preempt_dynamic_init(void) { }
> > >  
> > >  #endif /* #ifdef CONFIG_PREEMPT_DYNAMIC */
> > >  
> > > +/*
> > > + * task_is_pi_boosted - Check if task has been PI boosted.
> > > + * @p:	Task to check.
> > > + *
> > > + * Return true if task is subject to priority inheritance.
> > > + */
> > > +bool task_is_pi_boosted(const struct task_struct *p)
> > > +{
> > > +	int prio = p->prio;
> > > +
> > > +	if (!rt_prio(prio))
> > > +		return false;
> > > +	return prio != p->normal_prio;
> > 
> > Does this need to also take DEADLINE tasks into consideration? We don't
> > change priority when they are boosted, only pi_se changes (please check
> > is_dl_boosted()).
> 
> If we want this, then probably yes.
> Isn't task_struct::prio for the DL (boosted) task set to 0? While the RT
> priority go from 1…MAX_RT_PRIO - 1.

But then we can also have DL on DL boosting and in this case only the
pi_se changes while prio stays the same. But, again, looks like this is
moot anyway.

Thanks!
Juri
  

Patch

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 609bde814cb06..77fd274133750 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1887,6 +1887,7 @@  static inline int dl_task_check_affinity(struct task_struct *p, const struct cpu
 }
 #endif
 
+extern bool task_is_pi_boosted(const struct task_struct *p);
 extern int yield_to(struct task_struct *p, bool preempt);
 extern void set_user_nice(struct task_struct *p, long nice);
 extern int task_prio(const struct task_struct *p);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index c52c2eba7c739..132f06522efa0 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8886,6 +8886,21 @@  static inline void preempt_dynamic_init(void) { }
 
 #endif /* #ifdef CONFIG_PREEMPT_DYNAMIC */
 
+/*
+ * task_is_pi_boosted - Check if task has been PI boosted.
+ * @p:	Task to check.
+ *
+ * Return true if task is subject to priority inheritance.
+ */
+bool task_is_pi_boosted(const struct task_struct *p)
+{
+	int prio = p->prio;
+
+	if (!rt_prio(prio))
+		return false;
+	return prio != p->normal_prio;
+}
+
 /**
  * yield - yield the current processor to other threads.
  *