On Thu, 16 Aug 2007, Paul Mackerras wrote: > The uses of atomic_read where one might want it to allow caching of > the result seem to me to fall into 3 categories: > > 1. Places that are buggy because of a race arising from the way it's > used. > > 2. Places where there is a race but it doesn't matter because we're > doing some clever trick. > > 3. Places where there is some locking in place that eliminates any > potential race. > > In case 1, adding volatile won't solve the race, of course, but it's > hard to argue that we shouldn't do something because it will slow down > buggy code. Case 2 is hopefully pretty rare and accompanied by large > comment blocks, and in those cases caching the result of atomic_read > explicitly in a local variable would probably make the code clearer. > And in case 3 there is no reason to use atomic_t at all; we might as > well just use an int. In 2 + 3 you may increment the atomic variable in some places. The value of the atomic variable may not matter because you only do optimizations. Checking a atomic_t for a definite state has to involve either some side conditions (lock only taken if refcount is <= 0 or so) or done by changing the state (see f.e. atomic_inc_unless_zero). > So I don't see any good reason to make the atomic API more complex by > having "volatile" and "non-volatile" versions of atomic_read. It > should just have the "volatile" behaviour. If you want to make it less complex then drop volatile which causes weird side effects without solving any problems as you just pointed out. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: "Paul E. McKenney" <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- References:
- [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Chris Snook <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Christoph Lameter <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Satyam Sharma <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Stefan Richter <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Satyam Sharma <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Paul Mackerras <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Christoph Lameter <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: "Paul E. McKenney" <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Christoph Lameter <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Paul Mackerras <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Herbert Xu <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Paul Mackerras <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Satyam Sharma <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Satyam Sharma <[email protected]>
- Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- From: Paul Mackerras <[email protected]>
- [PATCH 0/24] make atomic_read() behave consistently across all architectures
- Prev by Date: Re: sata_nv + ADMA + Samsung disk problem
- Next by Date: Re: [PATCH take #5] [libata] libata driver for bf548 on chip ATAPI controller.
- Previous by thread: Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- Next by thread: Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
- Index(es):