All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
	rjw@rjwysocki.net, linux-kernel@vger.kernel.org,
	Eduardo Valentin <edubezval@gmail.com>,
	Javi Merino <javi.merino@kernel.org>,
	Leo Yan <leo.yan@linaro.org>,
	Kevin Wangtao <kevin.wangtao@linaro.org>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Rui Zhang <rui.zhang@intel.com>,
	Daniel Thompson <daniel.thompson@linaro.org>,
	"open list:POWER MANAGEMENT CORE" <linux-pm@vger.kernel.org>
Subject: Re: [PATCH V5] powercap/drivers/idle_injection: Add an idle injection framework
Date: Thu, 7 Jun 2018 11:09:28 +0200	[thread overview]
Message-ID: <20180607090928.GK12198@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180607084921.toctrooftl6y7kkx@vireshk-i7>

On Thu, Jun 07, 2018 at 02:19:21PM +0530, Viresh Kumar wrote:
> On 07-06-18, 10:46, Daniel Lezcano wrote:
> > Yes, correct.
> > 
> > But if we don't care about who wins to store to value, is there a risk
> > of scramble variable if we just assign a value ?
> 
> Normally no, as the compiler wouldn't screw it up badly. But there is no rule
> which stops the compiler from doing this:
> 
> idle_duration_ms = 5;
> idle_duration_ms = -5;
> idle_duration_ms = 0;
> idle_duration_ms = <real-value-we-want-to-write>;
> 
> So we *must* use READ/WRITE_ONCE() to make sure garbage values aren't seen by
> readers.

That too, however it is far worse..

The compiler is allowed to do store/load-tearing. Basically it can emit
individual byte store/loads in any random order.

So:
	foo = bar = 0;

	P0			P1

	foo = 0x12345678;	bar = foo;

Could result in: bar == 0x12005600 or any other random combination.

Now, it generally doesn't do this, because it is really retarded to
generate code like that. But we've seen cases where it managed to do
really weird things (think constructing 64bit literals with two or more
smaller stores, which total smaller code).

The volatile in READ/WRITE_ONCE() disallows this and ensures the
variables are read / written in a single go (assuming naturally aligned
native word sizes).

      parent reply	other threads:[~2018-06-07  9:09 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05  9:16 [PATCH V5] powercap/drivers/idle_injection: Add an idle injection framework Daniel Lezcano
2018-06-05  9:16 ` Daniel Lezcano
2018-06-05 10:39 ` Viresh Kumar
2018-06-05 14:54   ` Daniel Lezcano
2018-06-06  4:27     ` Viresh Kumar
2018-06-06 10:22       ` Daniel Lezcano
2018-06-06 10:45         ` Viresh Kumar
2018-06-06 12:05           ` Andrea Parri
2018-06-06 12:29             ` Peter Zijlstra
2018-06-07 14:11           ` Daniel Lezcano
2018-06-08  4:48             ` Viresh Kumar
2018-06-08  8:31               ` Daniel Lezcano
2018-06-06 12:23 ` Peter Zijlstra
2018-06-06 13:42   ` Daniel Lezcano
2018-06-06 15:02     ` Peter Zijlstra
2018-06-07  8:18       ` Daniel Lezcano
2018-06-07  8:32         ` Peter Zijlstra
2018-06-07  8:42           ` Viresh Kumar
2018-06-07  8:46             ` Daniel Lezcano
2018-06-07  8:49               ` Viresh Kumar
2018-06-07  9:09                 ` Daniel Lezcano
2018-06-07  9:32                   ` Peter Zijlstra
2018-06-07  9:39                     ` Peter Zijlstra
2018-06-07 12:31                       ` Daniel Lezcano
2018-06-07  9:09                 ` Peter Zijlstra [this message]

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=20180607090928.GK12198@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=daniel.thompson@linaro.org \
    --cc=edubezval@gmail.com \
    --cc=javi.merino@kernel.org \
    --cc=kevin.wangtao@linaro.org \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.