public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Honglei Wang <jameshongleiwang@126.com>
To: "mingyang.cui" <mingyang.cui@horizon.ai>,
	mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com
Cc: linux-kernel@vger.kernel.org, kernel-team@android.com,
	stable@vger.kernel.org, tkjos@google.com, pjt@google.com,
	quentin.perret@arm.com, Patrick.Bellasi@arm.com,
	Chris.Redpath@arm.com, Morten.Rasmussen@arm.com,
	joaodias@google.com
Subject: Re: [PATCH] sched/fair: Fix forked task check in vruntime_normalized
Date: Mon, 1 Apr 2024 16:04:33 +0800	[thread overview]
Message-ID: <073e5bf0-99c4-4dc5-8894-5442e2d53a34@126.com> (raw)
In-Reply-To: <20240328062757.29803-1-mingyang.cui@horizon.ai>



On 2024/3/28 14:27, mingyang.cui wrote:
> When rt_mutex_setprio changes a task's scheduling class to RT,
> sometimes the task's vruntime is not updated correctly upon
> return to the fair class.
> Specifically, the following is being observed:
> - task has just been created and running for a short time
> - task sleep while still in the fair class
> - task is boosted to RT via rt_mutex_setprio, which changes
>    the task to RT and calls check_class_changed.
> - check_class_changed leads to detach_task_cfs_rq, at which point
>    the vruntime_normalized check sees that the task's sum_exec_runtime
>    is zero, which results in skipping the subtraction of the
>    rq's min_vruntime from the task's vruntime
Hi Mingyang,

Did you do the test on the latest tree? vruntime_normalized was removed 
by e8f331bcc2 (sched/smp: Use lag to simplify cross-runqueue placement).

Thanks,
Honglei

> - later, when the prio is deboosted and the task is moved back
>    to the fair class, the fair rq's min_vruntime is added to
>    the task's vruntime, even though it wasn't subtracted earlier.
> 
> Since the task's vruntime is about double that of other tasks in cfs_rq,
> the task to be unable to run for a long time when there are continuous
> runnable tasks in cfs_rq.
> 
> The immediate result is inflation of the task's vruntime, giving
> it lower priority (starving it if there's enough available work).
> The longer-term effect is inflation of all vruntimes because the
> task's vruntime becomes the rq's min_vruntime when the higher
> priority tasks go idle. That leads to a vicious cycle, where
> the vruntime inflation repeatedly doubled.
> 
> The root cause of the problem is that the vruntime_normalized made a
> misjudgment. Since the sum_exec_runtime of some tasks that were just
> created and run for a short time is zero, the vruntime_normalized
> mistakenly thinks that they are tasks that have just been forked.
> Therefore, sum_exec_runtime is not subtracted from the vruntime of the
> task.
> 
> So, we fix this bug by adding a check condition for newly forked task.
> 
> Signed-off-by: mingyang.cui <mingyang.cui@horizon.ai>
> ---
>   kernel/sched/fair.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 73a89fbd81be..3d0c14f3731f 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -11112,7 +11112,7 @@ static inline bool vruntime_normalized(struct task_struct *p)
>   	 * - A task which has been woken up by try_to_wake_up() and
>   	 *   waiting for actually being woken up by sched_ttwu_pending().
>   	 */
> -	if (!se->sum_exec_runtime ||
> +	if (!se->sum_exec_runtime && p->state == TASK_NEW ||
>   	    (p->state == TASK_WAKING && p->sched_remote_wakeup))
>   		return true;
>   


  parent reply	other threads:[~2024-04-01  8:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28  6:27 [PATCH] sched/fair: Fix forked task check in vruntime_normalized mingyang.cui
2024-03-28  6:45 ` kernel test robot
2024-03-29 19:36 ` John Stultz
2024-04-01  8:04 ` Honglei Wang [this message]
2024-04-01 18:09   ` 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=073e5bf0-99c4-4dc5-8894-5442e2d53a34@126.com \
    --to=jameshongleiwang@126.com \
    --cc=Chris.Redpath@arm.com \
    --cc=Morten.Rasmussen@arm.com \
    --cc=Patrick.Bellasi@arm.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=joaodias@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=mingyang.cui@horizon.ai \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=quentin.perret@arm.com \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=tkjos@google.com \
    --cc=vincent.guittot@linaro.org \
    /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