mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Valentin Schneider <valentin.schneider@arm.com>
Cc: Dave Jones <davej@codemonkey.org.uk>,
	Mel Gorman <mgorman@techsingularity.net>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	mingo@kernel.org, Linus Torvalds <torvalds@linux-foundation.org>,
	paul.gortmaker@windriver.com, paulmck@kernel.org
Subject: Re: weird loadavg on idle machine post 5.7
Date: Tue, 7 Jul 2020 10:17:19 +0200	[thread overview]
Message-ID: <20200707081719.GK4800@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <jhj5zb08agb.mognet@arm.com>

On Tue, Jul 07, 2020 at 12:56:04AM +0100, Valentin Schneider wrote:

> > @@ -2605,8 +2596,20 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> >        *
> >        * Pairs with the LOCK+smp_mb__after_spinlock() on rq->lock in
> >        * __schedule().  See the comment for smp_mb__after_spinlock().
> > +	 *
> > +	 * Form a control-dep-acquire with p->on_rq == 0 above, to ensure
> > +	 * schedule()'s deactivate_task() has 'happened' and p will no longer
> > +	 * care about it's own p->state. See the comment in __schedule().
> >        */
> > -	smp_rmb();
> > +	smp_acquire__after_ctrl_dep();
> 
> Apologies for asking again, but I'm foolishly hopeful I'll someday be able
> to grok those things without half a dozen tabs open with documentation and
> Paul McKenney papers.
> 
> Do I get it right that the 'acquire' part hints this is equivalent to
> issuing a load-acquire on whatever was needed to figure out whether or not
> the take the branch (in this case, p->on_rq, amongst other things); IOW
> ensures any memory access appearing later in program order has to happen
> after the load?
> 
> That at least explains to me the load->{load,store} wording in
> smp_acquire__after_ctrl_dep().

Yes.

So the thing is that hardware MUST NOT speculate stores, or rather, if
it does, it must take extreme measures to ensure they do not become
visible in any way shape or form, since speculative stores lead to
instant OOTA problems.

Therefore we can say that branches order stores and if the branch
condition depends on a load, we get a load->store order. IOW the load
must complete before we can resolve the branch, which in turn enables
the store to become visible/happen.

If we then add an smp_rmb() to the branch to order load->load, we end up
with a load->{load,store} ordering, which is equivalent to a
load-acquire.

The reason to do it like that, is that load-aquire would otherwise
require an smp_mb(), since for many platforms that's the only barrier
that has load->store ordering.

The down-side of doing it like this, as Paul will be quick to point out,
is that the C standard doesn't recognise control dependencies and thus
the compiler would be in its right to 'optimize' our conditional away.

We're relying on the compilers not having done this in the past and
there being sufficient compiler people interested in compiling Linux to
avoid this from happening.


Anyway, this patch is basically:

	LOAD p->state		LOAD-ACQUIRE p->on_rq == 0
	MB
	STORE p->on_rq, 0	STORE p->state, TASK_WAKING

which ensures the TASK_WAKING store happens after the p->state load.
Just a wee bit complicated due to not actually adding any barriers while
adding additional ordering.

Anyway, let me now endeavour to write a coherent Changelog for this mess
:-(

  reply	other threads:[~2020-07-07  8:17 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
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 [this message]
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=20200707081719.GK4800@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=paul.gortmaker@windriver.com \
    --cc=paulmck@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=valentin.schneider@arm.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