[PATCH] sched/deadline: Do not start hrtick if its disabled for DL

Joel Fernandes (Google) posted 1 patch 1 week, 4 days ago
kernel/sched/deadline.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] sched/deadline: Do not start hrtick if its disabled for DL
Posted by Joel Fernandes (Google) 1 week, 4 days ago
Fix an issue where high-resolution timers causes aggressive preemptions,
leading to increased idle times in CFS tasks (which are inside the DL
server). The problem was traced to improper usage of hrtick_enabled(),
which could start high-resolution ticks unexpectedly causing repeated
preemptions.

The fix replaces this call with hrtick_enabled_dl(), aligning it with
scheduler feature checks.

Reported-by: Aashish Sharma <shraash@google.com>
Reported-by: Vineeth Pillai <vineeth@bitbyteword.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 kernel/sched/deadline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index b216e6deeac4..d46502b9ce58 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -2121,7 +2121,7 @@ static struct task_struct *pick_next_task_dl(struct rq *rq)
 	if (!p->dl_server)
 		set_next_task_dl(rq, p, true);
 
-	if (hrtick_enabled(rq))
+	if (hrtick_enabled_dl(rq))
 		start_hrtick_dl(rq, &p->dl);
 
 	return p;
-- 
2.47.0.277.g8800431eea-goog
Re: [PATCH] sched/deadline: Do not start hrtick if its disabled for DL
Posted by Juri Lelli 1 week, 4 days ago
Hi Joel,

On 12/11/24 01:22, Joel Fernandes (Google) wrote:
> Fix an issue where high-resolution timers causes aggressive preemptions,
> leading to increased idle times in CFS tasks (which are inside the DL
> server). The problem was traced to improper usage of hrtick_enabled(),
> which could start high-resolution ticks unexpectedly causing repeated
> preemptions.
> 
> The fix replaces this call with hrtick_enabled_dl(), aligning it with
> scheduler feature checks.
> 
> Reported-by: Aashish Sharma <shraash@google.com>
> Reported-by: Vineeth Pillai <vineeth@bitbyteword.org>
> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> ---
>  kernel/sched/deadline.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index b216e6deeac4..d46502b9ce58 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -2121,7 +2121,7 @@ static struct task_struct *pick_next_task_dl(struct rq *rq)
>  	if (!p->dl_server)
>  		set_next_task_dl(rq, p, true);
>  
> -	if (hrtick_enabled(rq))
> +	if (hrtick_enabled_dl(rq))
>  		start_hrtick_dl(rq, &p->dl);
>  
>  	return p;
> -- 

I'm not sure I'm seeing this in current code. We have two users in
deadline.c and they both use hrtick_enabled_dl (after a recent fix by
Phil).

Best,
Juri
Re: [PATCH] sched/deadline: Do not start hrtick if its disabled for DL
Posted by Joel Fernandes 1 week, 3 days ago
On Tue, Nov 12, 2024 at 07:51:17AM +0000, Juri Lelli wrote:
> Hi Joel,
> 
> On 12/11/24 01:22, Joel Fernandes (Google) wrote:
> > Fix an issue where high-resolution timers causes aggressive preemptions,
> > leading to increased idle times in CFS tasks (which are inside the DL
> > server). The problem was traced to improper usage of hrtick_enabled(),
> > which could start high-resolution ticks unexpectedly causing repeated
> > preemptions.
> > 
> > The fix replaces this call with hrtick_enabled_dl(), aligning it with
> > scheduler feature checks.
> > 
> > Reported-by: Aashish Sharma <shraash@google.com>
> > Reported-by: Vineeth Pillai <vineeth@bitbyteword.org>
> > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> > ---
> >  kernel/sched/deadline.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> > index b216e6deeac4..d46502b9ce58 100644
> > --- a/kernel/sched/deadline.c
> > +++ b/kernel/sched/deadline.c
> > @@ -2121,7 +2121,7 @@ static struct task_struct *pick_next_task_dl(struct rq *rq)
> >  	if (!p->dl_server)
> >  		set_next_task_dl(rq, p, true);
> >  
> > -	if (hrtick_enabled(rq))
> > +	if (hrtick_enabled_dl(rq))
> >  		start_hrtick_dl(rq, &p->dl);
> >  
> >  	return p;
> > -- 
> 
> I'm not sure I'm seeing this in current code. We have two users in
> deadline.c and they both use hrtick_enabled_dl (after a recent fix by
> Phil).

Ah you're right. The latest kernel we are on is on 6.6 so this got missed.

Thanks Juri for your quick reply and pointing out the missing patches!

 - Joel