All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Eliot Blennerhassett <linux@audioscience.com>
Cc: Takashi Iwai <tiwai@suse.de>, alsa-devel@alsa-project.org
Subject: Re: asihpi: Need help converting volatile to memory barriers
Date: Fri, 22 Feb 2008 09:37:56 -0800	[thread overview]
Message-ID: <20080222173756.GA29271@kroah.com> (raw)
In-Reply-To: <200802221218.18249.linux@audioscience.com>

On Fri, Feb 22, 2008 at 12:18:18PM +1300, Eliot Blennerhassett wrote:
> Greetings,
> 
> first, the meta-help request:
> Is there another place that I should be making this request? (lkml, kernel 
> newbies, linux driver project etc)?

lkml is best for this.

> 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
> 
> Now the actual question:
> Currently I have a driver that uses "volatile" - heres the relevant source.
> http://hg.alsa-project.org/alsa-driver/file/89222d702376/pci/asihpi/hpi6205.c
> 
> The "volatile" is applied to structures that are either read or written by 
> device DMA.  Certainly the driver in its current state doesn't work without 
> volatile qualifier. (BTW the device doesn't use host interrupts)
> 
> Structures ("interface") used for dma are allocated with dma_alloc_coherent()
> 
> In the following, am I using the barriers correctly?
> 
> 1) Reading something updated by DMA
> 
> volatile struct bus_master_interface *interface;
> while (interface->ack != OK) { 
> 	sleep(a while)  	
> 	[ device changes interface->ack by dma ]
> };
> === after conversion
> struct bus_master_interface *interface;
> while (interface->ack != OK) { 
> 	sleep(a while);
> 	rmb(); 
> };
> 
> Here the volatile or rmb is needed or the loop gets optimised away.

Using rmb() is correct, not volatile, as volatile might not really do
what you are expecting it to do on all versions of gcc and
architectures.

So please remove all instances of volatile, it is not correct to use it
within kernel code.

thanks,

greg k-h

      parent reply	other threads:[~2008-02-22 17:38 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
2008-02-22 17:37 ` Greg KH [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=20080222173756.GA29271@kroah.com \
    --to=greg@kroah.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux@audioscience.com \
    --cc=tiwai@suse.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 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.