mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Chuyi Zhou <zhouchuyi@bytedance.com>
Cc: <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>, <vschneid@redhat.com>,
	<chengming.zhou@linux.dev>, <linux-kernel@vger.kernel.org>,
	Qais Yousef <qyousef@layalina.io>
Subject: Re: [PATCH v2] sched/fair: Sync se's load_avg with cfs_rq in reweight_task
Date: Mon, 22 Jul 2024 10:47:40 +0530	[thread overview]
Message-ID: <3e88f113-e7b9-9b26-a4c1-52cf92b820c5@amd.com> (raw)
In-Reply-To: <20240720051248.59608-1-zhouchuyi@bytedance.com>

(+ Qais)

Hello Chuyi,

On 7/20/2024 10:42 AM, Chuyi Zhou wrote:
> In reweight_task(), there are two situations:
> 
> 1. The task was on_rq, then the task's load_avg is accurate because we
> synchronized it with cfs_rq through update_load_avg() in dequeue_task().
> 
> 2. The task is sleeping, its load_avg might not have been updated for some
> time, which can result in inaccurate dequeue_load_avg() in
> reweight_entity().
> 
> This patch solves this by using update_load_avg() to synchronize the
> load_avg of se with cfs_rq. For tasks were on_rq, since we already update
> load_avg to accurate values in dequeue_task(), this change will not have
> other effects due to the short time interval between the two updates.
> 
> Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
> ---
> Changes in v2:
> - change the description in commit log.
> - use update_load_avg() in reweight_task() rather than in reweight_entity
> suggested by chengming.
> - Link to v1: https://lore.kernel.org/lkml/20240716150840.23061-1-zhouchuyi@bytedance.com/
> ---
>   kernel/sched/fair.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 9057584ec06d..b1e07ce90284 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -3835,12 +3835,15 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
>   	}
>   }
>   
> +static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags);
> +
>   void reweight_task(struct task_struct *p, const struct load_weight *lw)
>   {
>   	struct sched_entity *se = &p->se;
>   	struct cfs_rq *cfs_rq = cfs_rq_of(se);
>   	struct load_weight *load = &se->load;
>   
> +	update_load_avg(cfs_rq, se, 0);

Seems to be necessary when we reach here from __setscheduler_params() or
set_user_nice() for a sleeping task. Please feel free to add:

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

But since we are on the subject of accurate PELT accounting, one question
I have here is whether a reweight_task() for a sleeping task race with
its wakeup? Something like the following scenario:

CPU0										CPU1
====										====
/* No rq locks held until ttwu_queue() */
try_to_wake_up(p) {
	...
	/* Migrating task */
	set_task_cpu(p, cpu) {
		/* p->sched_class->migrate_task_rq(p, new_cpu); */		/* Called with task_cpu(p)'s rq lock held */
		migrate_task_rq_fair() {					reweight_task(p) {
			/* p is still sleeping */					...
			if (!task_on_rq_migrating(p)) {					dequeue_load_avg(cfs_rq, se);
                 		remove_entity_load_avg(se);				update_load_set(&se->load, weight);
				...							enqueue_load_avg(cfs_rq, se);
			}								...
		}								}
		/* task_cpu() is updated here */
		__set_task_cpu(p, new_cpu);
	}
	ttwu_queue();
}

In theory, the remove_entity_load_avg() could record stale value of
"load_avg" that gets removed at the next dequeue if I'm not mistaken?
But I believe these small inaccuracies are tolerable since they'll decay
in a while anyways?

>   	reweight_entity(cfs_rq, se, lw->weight);
>   	load->inv_weight = lw->inv_weight;
>   }

-- 
Thanks and Regards,
Prateek

  reply	other threads:[~2024-07-22  5:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-20  5:12 Chuyi Zhou
2024-07-22  5:17 ` K Prateek Nayak [this message]
2024-07-22  6:40   ` Chengming Zhou
2024-07-22  8:15     ` K Prateek Nayak
2024-07-28 20:14   ` Qais Yousef
2024-07-22  6:34 ` Dietmar Eggemann
2024-07-22  9:39   ` Chuyi Zhou
     [not found] <66ee1520-48b8-4229-8bdd-9746c8bea5fe@bytedance.com>
2024-07-30 10:26 ` Chuyi Zhou

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=3e88f113-e7b9-9b26-a4c1-52cf92b820c5@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bsegall@google.com \
    --cc=chengming.zhou@linux.dev \
    --cc=dietmar.eggemann@arm.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=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=zhouchuyi@bytedance.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

all inboxes | Powered by JetHome®