public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
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 19:03:59 -0500	[thread overview]
Message-ID: <1350000239.6903.22@snotra> (raw)
In-Reply-To: <20121012013740.69a04294@lilith> (from albert.u.boot@aribaud.net on Thu Oct 11 18:37:40 2012)

On 10/11/2012 06:37:40 PM, Albert ARIBAUD wrote:
> Hi Scott,
> 
> On Thu, 11 Oct 2012 15:21:28 -0500, Scott Wood
> <scottwood@freescale.com> wrote:
> 
> > > 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.
> 
> It does not necessarily include "all memory". Besides, "that"  -- to  
> me
> -- cleary means "the memory mentioned in the statement, for instance  
> in
> the inputs or outputs.

The whole point of the memory clobber is for when you can't easily  
express the memory in terms of input/output constraints.

> > 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.
> 
> The memory clobber definition says no memory values are kept cached
> in registers across the instruction, that implies that if a volatile
> access was prepared (a memory value was cached in a register) it is
> finished before the asm statement executes, and similarly, since the
> desciption says "across" the instruction, volatiles reads or writes
> located after the instruction won't have been started before ithe
> instruction executest, or they would have needed to cache the value,
> which is contrary to the memory clobber definition.
> 
> This is not to say that only volatiles are affected by the barrier;  
> but
> volatiles certainly are.

Sure, but that first paragraph without the second is misleading as it  
implies that it is only volatiles that are affected.  Maybe not in  
terms of logical inference, but in terms of natural language and the  
meaning people are likely to take from it.

> Regarding Linux spinlocks vs these patches: it's not the same
> situation. spinlock functions are inlined, as you noted, thus a code
> sequence that takes a spinlock, does some accesses, then releases the
> spinlock ends up as a long sequence of instructions. On the contrary,
> the cache functions (which are not going to be inlined any time soon  
> as
> they are strong versions of weak symbols, incompatible with inlining)
> contain a single asm statement, thus adding a memory clobber to this
> statement won't have any effect for lack of preceding or following
> instructions to (not) reorder.

Fine.  I still think it's good practice to always use the memory  
clobber in these situations, as it doesn't hurt anything, and if  
nothing else you'd be setting a good example for others in situations  
that may not be as inline-averse -- but such style issues are up to you  
as maintainer.

-Scott

  reply	other threads:[~2012-10-12  0:03 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
2012-10-11 23:37         ` Albert ARIBAUD
2012-10-12  0:03           ` Scott Wood [this message]
     [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=1350000239.6903.22@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