public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: David Rientjes <rientjes@google.com>,
	Randy Dunlap <randy.dunlap@oracle.com>,
	Satyam Sharma <satyam.sharma@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Paul Sokolovsky <pmiscml@gmail.com>,
	linux-kernel@vger.kernel.org, jeremy@goop.org
Subject: Re: [PATCH] doc: volatile considered evil
Date: Wed, 09 May 2007 19:26:51 +1000	[thread overview]
Message-ID: <464193DB.70205@yahoo.com.au> (raw)
In-Reply-To: <20070509102134.5d722386@the-village.bc.nu>

Alan Cox wrote:
>>It's still ambiguous.  A much more explicit title that nobody could argue 
>>with would be "do not use the 'volatile' keyword as a type qualifier for 
>>an object."
> 
> 
> Except when you do. The kernel uses the C volatile in various places
> itself for specific good reasons (and some for historical bad ones)
> 
> Perhaps a closer summary would be
> 
> Do Not Use Volatile
> -------------------
> 
> 1.	volatile is not a locking mechanism
> 
> Volatile does not define sufficiently sane or strong semantics for
> locking. The kernel has proper locking mechanisms which also act as
> compiler fetch/store barriers and where neccessary hardware barriers for
> SMP systems. The kernel knows about all the corner cases, you probably
> don't.
> 
> 2.	volatile is not needed for mmio space
> 
> I/O memory access are done via readb/writeb and friends. They deal with
> volatility themselves so you don't have to. They may nor may not use
> volatile internally to their implementation, but that is none of your
> business.
> 
> 3.	volatile is not atomic
> 
> Using volatile does not guarantee atomic behaviour. This often requires
> special instructions or code sequences too. We have atomic_t and the
> atomic_* operators for this.
> 
> 4.	volatile is not a store or read barrier
> 
> Using volatile is not always sufficient to order accesses on SMP or to
> ensure things execute in the order expected. Instead the kernel provides
> a set of barrier operations which have clearly defined semantics on all
> systems. Make use of rmb, wmb, barrier, smp_wmb etc instead
> 
> When Might You Need volatile ?
> ------------------------------
> 
> When you are implementing the locking primitives on a new platform. When
> you are implementing the I/O and atomic prmitives on a new platform. Also
> in inline gcc assembler where "volatile" is used for subtly different
> purposes.

Is there a good reason for using volatile in atomic/locking primitives?
AFAIKS there is not.

-- 
SUSE Labs, Novell Inc.

  reply	other threads:[~2007-05-09  9:27 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-01  5:08 [RFC, PATCH 2/4] SoC base drivers: ASIC3 SoC hardware definitions Paul Sokolovsky
2007-05-01  6:56 ` Andrew Morton
2007-05-01 10:27   ` Alan Cox
2007-05-01 12:04     ` Paul Sokolovsky
2007-05-01 12:21       ` Jamey Hicks
2007-05-08 19:14   ` [RFC/PATCH] doc: volatile considered evil Randy Dunlap
2007-05-08 19:18     ` David Rientjes
2007-05-08 20:00       ` Krzysztof Halasa
2007-05-08 20:20         ` David Rientjes
2007-05-08 23:13           ` Randy Dunlap
2007-05-08 23:54             ` David Rientjes
2007-05-09  0:00               ` Randy Dunlap
2007-05-08 21:05         ` Jeremy Fitzhardinge
2007-05-08 21:10           ` Krzysztof Halasa
2007-05-08 21:16           ` Jeff Garzik
2007-05-08 21:26             ` Randy Dunlap
2007-05-08 21:25               ` Jeff Garzik
2007-05-08 21:20       ` Jeremy Fitzhardinge
2007-05-08 21:27         ` David Rientjes
2007-05-08 21:37           ` Jeremy Fitzhardinge
2007-05-08 21:59             ` David Rientjes
2007-05-08 22:04               ` Jeremy Fitzhardinge
2007-05-08 22:19                 ` David Rientjes
2007-05-08 22:29                   ` Jeremy Fitzhardinge
2007-05-08 22:35                     ` David Rientjes
2007-05-08 23:09           ` Randy Dunlap
2007-05-08 21:29         ` Randy Dunlap
2007-05-08 20:07     ` Satyam Sharma
2007-05-08 23:34       ` [PATCH] " Randy Dunlap
2007-05-09  0:06         ` David Rientjes
2007-05-09  2:08           ` Randy Dunlap
2007-05-09  2:38             ` David Rientjes
2007-05-09  3:15               ` Randy Dunlap
2007-05-09  9:21               ` Alan Cox
2007-05-09  9:26                 ` Nick Piggin [this message]
2007-05-09 13:31                   ` Alan Cox
2007-05-09 10:25                 ` David Rientjes
2007-05-09 13:36                   ` Alan Cox
2007-05-09 18:41                     ` David Rientjes
2007-05-09 20:23                       ` Alan Cox
2007-05-09 20:25                         ` David Rientjes
2007-05-09 22:47                         ` Rob Landley
2007-05-09  8:50         ` Stefan Richter
2007-05-09 15:52           ` Randy Dunlap
2007-05-09 19:04             ` Satyam Sharma
2007-05-09  1:47     ` [RFC/PATCH] " Jonathan Corbet
2007-05-09  9:43       ` Johannes Stezenbach
2007-05-09 19:34         ` Satyam Sharma

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=464193DB.70205@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmiscml@gmail.com \
    --cc=randy.dunlap@oracle.com \
    --cc=rientjes@google.com \
    --cc=satyam.sharma@gmail.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