From: Peter Zijlstra <peterz@infradead.org>
To: Mel Gorman <mgorman@techsingularity.net>
Cc: Dave Jones <davej@codemonkey.org.uk>,
Linux Kernel <linux-kernel@vger.kernel.org>,
mingo@kernel.org, Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: weird loadavg on idle machine post 5.7
Date: Fri, 3 Jul 2020 12:40:33 +0200 [thread overview]
Message-ID: <20200703104033.GK117543@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200703090226.GV4800@hirez.programming.kicks-ass.net>
On Fri, Jul 03, 2020 at 11:02:26AM +0200, Peter Zijlstra wrote:
> On Thu, Jul 02, 2020 at 10:36:27PM +0100, Mel Gorman wrote:
>
> > > commit c6e7bd7afaeb3af55ffac122828035f1c01d1d7b (refs/bisect/bad)
> > > Author: Peter Zijlstra <peterz@infradead.org>
>
> > Peter, I'm not supremely confident about this but could it be because
> > "p->sched_contributes_to_load = !!task_contributes_to_load(p)" potentially
> > happens while a task is still being dequeued? In the final stages of a
> > task switch we have
> >
> > prev_state = prev->state;
> > vtime_task_switch(prev);
> > perf_event_task_sched_in(prev, current);
> > finish_task(prev);
> >
> > finish_task is when p->on_cpu is cleared after the state is updated.
> > With the patch, we potentially update sched_contributes_to_load while
> > p->state is transient so if the check below is true and ttwu_queue_wakelist
> > is used then sched_contributes_to_load was based on a transient value
> > and potentially wrong.
>
> I'm not seeing it. Once a task hits schedule(), p->state doesn't change,
> except through wakeup.
>
> And while dequeue depends on p->state, it doesn't change it.
>
> At this point in ttwu() we know p->on_rq == 0, which implies dequeue has
> started, which means we've (at least) stopped executing the task -- we
> started or finished schedule().
>
> Let me stare at this more...
So ARM/Power/etc.. can speculate the load such that the
task_contributes_to_load() value is from before ->on_rq.
The compiler might similar re-order things -- although I've not found it
doing so with the few builds I looked at.
So I think at the very least we should do something like this. But i've
no idea how to reproduce this problem.
Mel's patch placed it too far down, as the WF_ON_CPU path also relies on
this, and by not resetting p->sched_contributes_to_load it would skew
accounting even worse.
---
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fcd56f04b706..cba8a56d0f7f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2799,9 +2799,6 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
}
#ifdef CONFIG_SMP
- p->sched_contributes_to_load = !!task_contributes_to_load(p);
- p->state = TASK_WAKING;
-
/*
* Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be
* possible to, falsely, observe p->on_cpu == 0.
@@ -2823,6 +2820,9 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
*/
smp_rmb();
+ p->sched_contributes_to_load = !!task_contributes_to_load(p);
+ p->state = TASK_WAKING;
+
/*
* If the owning (remote) CPU is still in the middle of schedule() with
* this task as prev, considering queueing p on the remote CPUs wake_list
next prev parent reply other threads:[~2020-07-03 10:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 17:15 Dave Jones
2020-07-02 19:46 ` Dave Jones
2020-07-02 21:15 ` Paul Gortmaker
2020-07-03 13:23 ` Paul Gortmaker
2020-07-02 21:36 ` Mel Gorman
2020-07-02 23:11 ` Michal Kubecek
2020-07-02 23:24 ` Dave Jones
2020-07-03 9:02 ` Peter Zijlstra
2020-07-03 10:40 ` Peter Zijlstra [this message]
2020-07-03 20:51 ` Dave Jones
2020-07-06 14:59 ` Peter Zijlstra
2020-07-06 21:20 ` Dave Jones
2020-07-07 7:48 ` Peter Zijlstra
2020-07-06 23:56 ` Valentin Schneider
2020-07-07 8:17 ` Peter Zijlstra
2020-07-07 10:20 ` Valentin Schneider
2020-07-07 10:29 ` Peter Zijlstra
2020-07-08 9:46 ` [tip: sched/urgent] sched: Fix loadavg accounting race tip-bot2 for Peter Zijlstra
2020-07-07 9:20 ` weird loadavg on idle machine post 5.7 Qais Yousef
2020-07-07 9:47 ` Peter Zijlstra
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=20200703104033.GK117543@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=davej@codemonkey.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@kernel.org \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®