From: Andy Isaacson <adi@hexapodia.org>
To: moreau francis <francis_moreau2000@yahoo.fr>
Cc: "linux-os (Dick Johnson)" <linux-os@analogic.com>,
linux-kernel@vger.kernel.org
Subject: Re: question on memory barrier
Date: Wed, 24 Aug 2005 12:48:36 -0700 [thread overview]
Message-ID: <20050824194836.GA26526@hexapodia.org> (raw)
In-Reply-To: <20050824173131.50938.qmail@web25809.mail.ukl.yahoo.com>
On Wed, Aug 24, 2005 at 07:31:31PM +0200, moreau francis wrote:
> --- "linux-os (Dick Johnson)" <linux-os@analogic.com> a écrit :
> > On Wed, 24 Aug 2005, moreau francis wrote:
> > > I'm currently trying to write a USB driver for Linux. The device must be
> > > configured by writing some values into the same register but I want to be
> > > sure that the writing order is respected by either the compiler and the
> > > cpu.
[snip]
> > > static inline void dev_out(u32 *reg, u32 value)
> > > {
> > > writel(value, regs);
> > > }
> > >
> > > void config_dev(void)
> > > {
> > > dev_out(reg_a, 0x0); /* first io */
> > > dev_out(reg_a, 0xA); /* second io */
> > > }
> > >
> >
> > This should be fine. The effect of the first bit of code
> > plus all side-effects (if any) should be complete at the
> > first effective sequence-point (;) but you need to
While sequence points are relevant for purposes of reasoning about the
effects of C code on the abstract state machine as defined by the C
standard, they are irrelevant when talking about IO.
> sorry but I'm not sure to understand you...Do you mean that the first write
> into reg_a pointer will be completed before the second write because they're
> separated by a (;) ?
> Or because writes are encapsulated inside an inline function,
> therefore compiler must execute every single writes before returning
> from the inline function ?
The first register write will be completed before the second register
write because you use writel, which is defined to have the semantics you
want. (It uses a platform-specific method to guarantee this, possibly
"volatile" or "asm("eieio")" or whatever method your platform requires.)
The sequence points, by themselves, do not make any requirements on the
externally visible behavior of the program. Nor does the fact that
there's an inline function involved. It's just the writel() that
contains the magic to force in-order execution.
You might benefit by running your source code through gcc -E and seeing
what the writel() expands to. (I do something like "rm drivers/mydev.o;
make V=1" and then copy-n-paste the gcc line, replacing the "-c -o mydev.o"
options with -E.)
The sequence point argument is obviously wrong, BTW - if it were the
case that a mere sequence point required the compiler to have completed
all externally-visible side effects, then almost every optimization that
gcc does with -O2 would be impossible. CSE, loop splitting, etc.
-andy
next prev parent reply other threads:[~2005-08-24 19:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-24 12:43 question on memory barrier moreau francis
2005-08-24 13:04 ` linux-os (Dick Johnson)
2005-08-24 17:31 ` moreau francis
2005-08-24 18:22 ` linux-os (Dick Johnson)
2005-08-24 19:32 ` Oliver Neukum
2005-08-24 19:47 ` linux-os (Dick Johnson)
2005-08-24 19:55 ` Oliver Neukum
2005-08-24 19:48 ` Andy Isaacson [this message]
2005-08-24 19:53 ` Jesse Barnes
2005-08-24 21:45 ` Alan Cox
2005-08-24 21:22 ` Jesse Barnes
2005-08-24 20:03 ` linux-os (Dick Johnson)
2005-08-24 20:21 ` Oliver Neukum
2005-08-25 2:25 ` David Schwartz
2005-08-25 8:49 ` Denis Vlasenko
2005-08-25 9:14 ` moreau francis
2005-08-25 10:07 ` Alan Cox
2005-08-25 14:54 ` Andy Isaacson
2005-08-26 7:21 ` moreau francis
2005-08-26 10:37 ` Maciej W. Rozycki
2005-08-25 10:32 ` Maciej W. Rozycki
2005-08-24 21:57 ` Alan Cox
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=20050824194836.GA26526@hexapodia.org \
--to=adi@hexapodia.org \
--cc=francis_moreau2000@yahoo.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.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