All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Eliot Blennerhassett <linux@audioscience.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: asihpi: Need help converting volatile to memory barriers
Date: Fri, 22 Feb 2008 11:44:20 +0100	[thread overview]
Message-ID: <47BEA784.5060006@ladisch.de> (raw)
In-Reply-To: <200802221218.18249.linux@audioscience.com>

Eliot Blennerhassett wrote:
> Theres quite a bit written about barriers, but most seems to be assuming SMP
> situation or memory mapped devices. Not much about devices doing DMA.
> I.e I have read Documentation/memory-barriers.txt

See also <Documentation/DMA-mapping.txt>.

> interface->cmd = command;
> wmb();
> iowrite(device_interrupt, 1);
> [device reads interface->cmd by dma]
>
> Is the wmb() a guarantee that the command will be in memory visible to the
> device when the driver informs it of a new command?

Yes.  Please not that accesses to I/O space have an implicit barrier, so
you don't even need the wmb() in this case.

> One assumption I am making is that the compiler is not going to optimise
> across functions
> E.g. in the following scenario, is the compiler going to optimise the loop
> away without a rmb()?  If not, is this because of something inherent in the C
> standard, or just because the optimiser isn't yet smart enough to see it?
> I.e. it might work now, but when whole-file-optimisation is introduced, it
> will fail?
>
> int get_ack(interface) { return interface->ack }
> ...
> while (get_ack(interface) != OK) {
> 	sleep(a while);
> }

The get_ack() function is an obvious candidate for inlining.  The C
standard definitely allows it to be optimized away (if the compiler can
prove that sleep() doesn't write to interface->ack).  Both gcc an icc
are able to do (or plan to introduce) this optimization.


HTH
Clemens

  reply	other threads:[~2008-02-22 10:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-21 23:18 asihpi: Need help converting volatile to memory barriers Eliot Blennerhassett
2008-02-22 10:44 ` Clemens Ladisch [this message]
2008-02-22 17:37 ` Greg KH

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=47BEA784.5060006@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux@audioscience.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 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.