mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	<linux-kernel@vger.kernel.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>,
	"Gautham R. Shenoy" <gautham.shenoy@amd.com>,
	Swapnil Sapkal <swapnil.sapkal@amd.com>
Subject: Re: [PATCH] sched/fair: Fix inaccurate h_nr_runnable accounting with delayed dequeue
Date: Fri, 17 Jan 2025 21:29:12 +0530	[thread overview]
Message-ID: <79cef0b2-4ed2-4141-9a66-150d04b82476@amd.com> (raw)
In-Reply-To: <CAKfTPtBRf7-Kt4xxLsNHbjM=n_txHWePNKssV3Sxepqh6oM4WA@mail.gmail.com>

Hello Vincent,

On 1/17/2025 6:55 PM, Vincent Guittot wrote:
> Hi Prateek,
> 
> On Fri, 17 Jan 2025 at 11:59, K Prateek Nayak <kprateek.nayak@amd.com> wrote:
>>
>> set_delayed() adjusts cfs_rq->h_nr_runnable for the hierarchy when an
>> entity is delayed irrespective of whether the entity corresponds to a
>> task or a cfs_rq.
>>
>> Consider the following scenario:
>>
>>          root
>>         /    \
>>        A      B (*) delayed since B is no longer eligible on root
>>        |      |
>>      Task0  Task1 <--- dequeue_task_fair() - task blocks
>>
>> When Task1 blocks (dequeue_entity() for task's se returns true),
>> dequeue_entities() will continue adjusting cfs_rq->h_nr_* for the
>> hierarchy of Task1. However, when the sched_entity corresponding to
>> cfs_rq B is delayed, set_delayed() will adjust the h_nr_runnable for the
>> hierarchy too leading to both dequeue_entity() and set_delayed()
>> decrementing h_nr_runnable for the dequeue of the same task.
>>
>> A SCHED_WARN_ON() to inspect h_nr_runnable post its update in
>> dequeue_entities() like below:
>>
>>      cfs_rq->h_nr_runnable -= h_nr_runnable;
>>      SCHED_WARN_ON(((int) cfs_rq->h_nr_runnable) < 0);
>>
>> is consistently tripped when running wakeup intensive workloads like
>> hackbench in a cgroup.
>>
>> This error is self correcting since cfs_rq are per-cpu and cannot
>> migrate. The entitiy is either picked for full dequeue or is requeued
>> when a task wakes up below it. Both those paths call clear_delayed()
>> which again increments h_nr_runnable of the hierarchy without
>> considering if the entity corresponds to a task or not.
>>
>> h_nr_runnable will eventually reflect the correct value however in the
>> interim, the incorrect values can still influence PELT calculation which
>> uses se->runnable_weight or cfs_rq->h_nr_runnable.
>>
>> Since only delayed tasks take the early return path in
>> dequeue_entities() and enqueue_task_fair(), adjust the
>> h_nr_runnable in {set,clear}_delayed() only when a task is delayed as
>> this path skips the h_nr_* update loops and returns early.
>>
>> For entities corresponding to cfs_rq, the h_nr_* update loop in the
>> caller will do the right thing.
>>
>> Fixes: 76f2f783294d ("sched/eevdf: More PELT vs DELAYED_DEQUEUE")
> 
> You probably mean  c2a295bffeaf ("sched/fair: Add new cfs_rq.h_nr_runnable")

You are right! I had done a git blame on set_delayed() ad landed at
commit 76f2f783294d but you are right, it should be c2a295bffeaf
("sched/fair: Add new cfs_rq.h_nr_runnable") when the accounting was
inverted to account runnable tasks. Thank you for pointing that out.

> Before we were tracking the opposite h_nr_delayed. Did you see the
> problem only on tip/sched/core or also before the rework which added
> h_nr_runnable and removed h_nr_delayed

The problem is on tip:sched/core. I did not encounter any anomalies on
76f2f783294d ("sched/eevdf: More PELT vs DELAYED_DEQUEUE")

"h_nr_delayed" was only adjusted in dequeue_entities() for "!seep &&
!delayed" which would imply migration or a save + restore type operation
and the whole "h_nr_delayed" adjusting was contained in
{set,clear}_delayed() for delayed dequeue, finish delayed dequeue, and
requeue.

> 
> I'm going to have a closer look

Thank you!

> 
> 
>> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
>> Tested-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
>> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
>> ---
>>
>> [..snip..]
>>

-- 
Thanks and Regards,
Prateek


  reply	other threads:[~2025-01-17 15:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-17 10:58 K Prateek Nayak
2025-01-17 13:25 ` Vincent Guittot
2025-01-17 15:59   ` K Prateek Nayak [this message]
2025-01-18  8:30     ` Vincent Guittot
2025-01-21  8:09       ` K Prateek Nayak
2025-01-21  9:53         ` Vincent Guittot
2025-01-20  5:06 ` Madadi Vineeth Reddy
2025-01-20  8:44   ` Madadi Vineeth Reddy
2025-01-20  9:14     ` K Prateek Nayak
2025-01-20  9:12   ` K Prateek Nayak
2025-01-21 12:21 ` [tip: sched/urgent] " tip-bot2 for K Prateek Nayak

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=79cef0b2-4ed2-4141-9a66-150d04b82476@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=gautham.shenoy@amd.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=swapnil.sapkal@amd.com \
    --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

Powered by JetHome