From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] ARM926: Add mb to the cache invalidate/flush
Date: Thu, 11 Oct 2012 15:21:28 -0500 [thread overview]
Message-ID: <1349986888.6903.17@snotra> (raw)
In-Reply-To: <20121011220329.6ff7a84d@lilith> (from albert.u.boot@aribaud.net on Thu Oct 11 15:03:29 2012)
On 10/11/2012 03:03:29 PM, Albert ARIBAUD wrote:
> Hi Scott,
>
> On Thu, 11 Oct 2012 13:03:13 -0500, Scott Wood
> <scottwood@freescale.com> wrote:
>
> > On 10/11/2012 12:31:46 AM, Albert ARIBAUD wrote:
> > > Hi Marek,
> > >
> > > On Wed, 10 Oct 2012 00:44:29 +0200, Marek Vasut <marex@denx.de>
> wrote:
> > >
> > > > Add memory barrier to cache invalidate and flush calls.
> > >
> > > Memory barrier...
> > >
> > > "You keep using that word. I do not think it means what you think
> it
> > > means." :)
> >
> > Could we wait on the condescension until your assertion of what a
> > memory clobber does and does not do is resolved?
>
> Scott, I think you should not mistake as condescension what is just
> humo(u)r. What I wrote above is a quotation from a (light, quite
> humorous and above all, self-mocking) movie, meant to be read by, but
> in
> no way directed against, Marex.
Sure, it just seemed an odd way to resume a conversation that had
already begun on the topic.
> > > A memory barrier's effect is only that all of the volatile
> accesses
> > > placed before it in the source code finish when the barrier
> executes,
> > > and that none of the volatile accesses placed after it in the
> source
> > > code starts before the barrier has executed.
> >
> > Cite from official GCC documentation please, or example code that
> shows
> > a problem.
>
> http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Extended-Asm
>
> "If your assembler instructions access memory in an unpredictable
> fashion, add `memory' to the list of clobbered registers. This will
> cause GCC to not keep memory values cached in registers across the
> assembler instruction and not optimize stores or loads to that memory.
> You will also want to add the volatile keyword if the memory affected
> is not listed in the inputs or outputs of the asm, as the `memory'
> clobber does not count as a side-effect of the asm".
"and not optimize stores or loads to that memory". It's not clear what
"that" refers to, since the memory clobber does not refer to specific
memory, but given that the purpose is "if your assembler instructions
access memory in an unpredictable fashion", I don't see how it could be
interpreted as anything other than "any memory which could possibly be
modified by the program". So it excludes constant data, but that's
about it.
The only reference to volatile is to tell you to add it to the asm
statement (not to other memory accesses) so that the asm statement does
not get removed altogether.
> > We've use memory barriers like this all the time. It works and is
> > standard practice. If it doesn't work like that it needs to be
> fixed.
>
> I have used memory barriers too, and I've already seen some weird
> things happening because they were used in ways that did not match
> their effects. Particularly, we did not use memory clobbers on cache
> flush or invalidate operations, we used them on actual barrier
> operations -- dsb, dmb and their cp15 incarnations.
What specifically did you see the compiler do?
> > That AVR/ARM example you showed on IRC is special because it's
> calling
> > a libgcc function and GCC knows that the function doesn't access
> memory
> > (loading constant data for the argument doesn't count). I couldn't
> get
> > the same thing to happen with a normal function, even when declared
> > with __attribute__((const)). Yes, it's a problem for ordering code
> in
> > general and thus keeping slow stuff out of critical sections, but it
> > shouldn't be a problem for ordering memory accesses.
>
> Can you *guarantee* that no valid C code will ever let a non-volatile
> write slip across a memory clobber?
>
> Memory clobbers do not guarantee this, at least not explicitly in
> their
> description, whereas C sequence points do. For instance, the call to a
> function is a sequence point, reached only after its arguments have
> been evaluated.
I don't know GCC internals, so I personally can't guarantee anything.
What I know is that they're used for this purpose all over the place,
and if there really is a problem it needs to be fixed. If the use in
this patch is wrong, then so are Linux synchronization primitives, for
example. How would you make a spinlock? Certainly you can't insist
that all the variables protected by the lock be volatile.
-Scott
next prev parent reply other threads:[~2012-10-11 20:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-09 22:44 [U-Boot] [PATCH] ARM926: Add mb to the cache invalidate/flush Marek Vasut
2012-10-11 5:31 ` Albert ARIBAUD
2012-10-11 12:09 ` Marek Vasut
2012-10-11 18:03 ` Scott Wood
2012-10-11 20:03 ` Albert ARIBAUD
2012-10-11 20:21 ` Scott Wood [this message]
2012-10-11 23:37 ` Albert ARIBAUD
2012-10-12 0:03 ` Scott Wood
[not found] ` <95DC1AA8EC908B48939B72CF375AA5E3053318DC84@alice.at.omicron.at>
2012-10-11 20:01 ` Albert ARIBAUD
2012-10-11 21:09 ` Scott Wood
2012-10-11 22:44 ` Albert ARIBAUD
2012-10-13 9:56 ` Albert ARIBAUD
-- strict thread matches above, loose matches on Subject: below --
2012-08-29 13:50 Marek Vasut
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=1349986888.6903.17@snotra \
--to=scottwood@freescale.com \
--cc=u-boot@lists.denx.de \
/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