public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: John Stultz <jstultz@google.com>, LKML <linux-kernel@vger.kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	<kernel-team@android.com>
Subject: Re: [RFC][PATCH] sched/core: Tweak wait_task_inactive() to force dequeue sched_delayed tasks
Date: Tue, 22 Apr 2025 12:13:53 +0530	[thread overview]
Message-ID: <70647a05-00f7-40aa-ae46-caae3c5c244a@amd.com> (raw)
In-Reply-To: <20250422044355.390780-1-jstultz@google.com>

Hello John,

On 4/22/2025 10:13 AM, John Stultz wrote:
> It was reported that in 6.12, smpboot_create_threads() was
> taking much longer then in 6.6.
> 
> I narrowed down the call path to:
>   smpboot_create_threads()
>   -> kthread_create_on_cpu()
>      -> kthread_bind()
>         -> __kthread_bind_mask()
>            ->wait_task_inactive()
> 
> Where in wait_task_inactive() we were regularly hitting the
> queued case, which sets a 1 tick timeout, which when called
> multiple times in a row, accumulates quickly into a long
> delay.
> 
> I noticed disabling the DELAY_DEQUEUE sched feature recovered
> the performance, and it seems the newly create tasks are usually
> sched_delayed and left on the runqueue.
> 
> So in wait_task_inactive() when we see the task
> task_on_rq_queued(p) and p->se.sched_delayed, manually dequeue
> the sched_delayed task with DEQUEUE_DELAYED, so we don't have to
> constantly wait a tick.
> 
> This seems to work, but I've only lightly tested it, so I'd love
> close review and feedback in case I've missed something in
> wait_task_inactive(), or if there is a simpler alternative
> approach.
> 
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Vincent Guittot <vincent.guittot@linaro.org>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ben Segall <bsegall@google.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Valentin Schneider <vschneid@redhat.com>
> Cc: K Prateek Nayak <kprateek.nayak@amd.com>
> Cc: kernel-team@android.com
> Signed-off-by: John Stultz <jstultz@google.com>
> ---
>   kernel/sched/core.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index c81cf642dba05..43f0931a3cd8a 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2287,6 +2287,14 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state
>   		running = task_on_cpu(rq, p);
>   		queued = task_on_rq_queued(p);
>   		ncsw = 0;
> +		/*
> +		 * If task is sched_delayed, force dequeue it, to avoid always
> +		 * hitting the tick timeout in the queued case
> +		 */
> +		if (!running && queued && p->se.sched_delayed) {

I think an "update_rq_clock(rq)" is required here before dequeue but other
than that ...

> +			dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);

I think this makes sense since the comment above the hrtimeout considers
a "queued" task to be preempted and still runnable but a delayed task
doesn't fit that description.

You can perhaps move dequeuing of delayed task to just after the
task_rq_lock() bit since once the rq lock and the pi_lock are acquired,
task cannot be requeued and simply checking "p->se.sched_delayed"
should be enough. Something like:

     rq = task_rq_lock(p, &rf);
     trace_sched_wait_task(p);

     if (p->se.sched_delayed) {
             update_rq_clock(rq);
             dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
     }

     queued = task_on_rq_queued(p);
     ...

Similar pattern exists for __sched_setscheduler() and
rt_mutex_setprio().

Other than that, feel free to include:

Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>

> +			queued = task_on_rq_queued(p);
> +		}
>   		if ((match = __task_state_match(p, match_state))) {
>   			/*
>   			 * When matching on p->saved_state, consider this task

-- 
Thanks and Regards,
Prateek


  reply	other threads:[~2025-04-22  6:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22  4:43 [RFC][PATCH] sched/core: Tweak wait_task_inactive() to force dequeue sched_delayed tasks John Stultz
2025-04-22  6:43 ` K Prateek Nayak [this message]
2025-04-22  7:57   ` K Prateek Nayak
2025-04-22  8:56 ` Peter Zijlstra
2025-04-22  9:55   ` Frederic Weisbecker
2025-04-22 10:19     ` Peter Zijlstra
2025-04-23 21:41   ` John Stultz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70647a05-00f7-40aa-ae46-caae3c5c244a@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox