Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-23 Thread Robert Haas
On Thu, Sep 22, 2011 at 11:31 AM, Robert Haas robertmh...@gmail.com wrote: On Thu, Sep 22, 2011 at 11:25 AM, Thom Brown t...@linux.com wrote: s/visca-versa/vice-versa/ s/laods/loads/ Fixed.  v4 attached. Since it seems like people are fairly happy with this now, I've gone ahead and committed

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Robert Haas
On Wed, Sep 21, 2011 at 5:07 PM, Kevin Grittner kevin.gritt...@wicourts.gov wrote: That's the sort of thing where it would be helpful to provide one or two URLs for cogent explanations of this.  Even if it takes repeated readings and meditations on the explanations for it to sink in, this is

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Peter Geoghegan
On 14 September 2011 21:29, Robert Haas robertmh...@gmail.com wrote: On Mon, Aug 8, 2011 at 7:47 AM, Robert Haas robertmh...@gmail.com wrote: I've been thinking about this too and actually went so far as to do some research and put together something that I hope covers most of the interesting

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Robert Haas
On Thu, Sep 22, 2011 at 10:53 AM, Peter Geoghegan pe...@2ndquadrant.com wrote: As I've already pointed out, the comment Won't work on Visual Studio 2003 is not accurate: http://msdn.microsoft.com/en-us/library/f20w0x5e(v=vs.71).aspx Besides, if it's not supported, why bother mentioning it?

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Thom Brown
On 22 September 2011 16:18, Robert Haas robertmh...@gmail.com wrote: On Thu, Sep 22, 2011 at 10:53 AM, Peter Geoghegan pe...@2ndquadrant.com wrote: As I've already pointed out, the comment Won't work on Visual Studio 2003 is not accurate:

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Robert Haas
On Thu, Sep 22, 2011 at 11:25 AM, Thom Brown t...@linux.com wrote: s/visca-versa/vice-versa/ s/laods/loads/ Fixed. v4 attached. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company barrier-v4.patch Description: Binary data -- Sent via pgsql-hackers

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Alvaro Herrera
Excerpts from Robert Haas's message of jue sep 22 12:18:47 -0300 2011: I've also added a lengthy README file to the patch that attempts to explain how barriers should be used in PostgreSQL coding. Very enlightening, thanks. Note a typo laods. -- Álvaro Herrera alvhe...@commandprompt.com

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Kevin Grittner
Robert Haas robertmh...@gmail.com wrote: I've also added a lengthy README file to the patch that attempts to explain how barriers should be used in PostgreSQL coding. It's certainly not a comprehensive treatment of the topic, but hopefully it's enough to get people oriented. I've attempted

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Jeff Davis
On Thu, 2011-09-22 at 11:31 -0400, Robert Haas wrote: On Thu, Sep 22, 2011 at 11:25 AM, Thom Brown t...@linux.com wrote: s/visca-versa/vice-versa/ s/laods/loads/ Fixed. v4 attached. Can you please explain the more subtly part below? +A common pattern where this actually does result in

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Robert Haas
On Thu, Sep 22, 2011 at 5:45 PM, Jeff Davis pg...@j-davis.com wrote: +This code turns out to be unsafe, because the writer might increment +q-num_items before it finishes storing the new item into the appropriate slot. +More subtly, the reader might prefetch the contents of the q-items array

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Jeff Davis
On Thu, 2011-09-22 at 19:12 -0400, Robert Haas wrote: But since you asked... as I understand it, unless you're running on Alpha, you actually don't need a barrier here at all, because all currently-used CPUs other than alpha respect data dependencies, which means that if q-num_items is used

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-22 Thread Robert Haas
On Thu, Sep 22, 2011 at 7:46 PM, Jeff Davis pg...@j-davis.com wrote: On Thu, 2011-09-22 at 19:12 -0400, Robert Haas wrote: But since you asked... as I understand it, unless you're running on Alpha, you actually don't need a barrier here at all, because all currently-used CPUs other than alpha

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Robert Haas
On Thu, Sep 15, 2011 at 11:57 AM, Heikki Linnakangas heikki.linnakan...@enterprisedb.com wrote: s/atomic/barrier/ Oops. +/* + * A compiler barrier need not (and preferably should not) emit any actual + * machine code, but must act as an optimization fence: the compiler must not + *

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Kevin Grittner
Robert Haas robertmh...@gmail.com wrote: But even a full explanation of that case seems like almost too much for the comment of a header file, and there are certainly far more complex cases. I think anyone who is using these primitives is going to have to do some independent reading...

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Robert Haas
On Wed, Sep 21, 2011 at 2:48 PM, Kevin Grittner kevin.gritt...@wicourts.gov wrote: Robert Haas robertmh...@gmail.com wrote: But even a full explanation of that case seems like almost too much for the comment of a header file, and there are certainly far more complex cases.  I think anyone who

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Kevin Grittner
Robert Haas robertmh...@gmail.com wrote: On Wed, Sep 21, 2011 at 2:48 PM, Kevin Grittner kevin.gritt...@wicourts.gov wrote: Robert Haas robertmh...@gmail.com wrote: But even a full explanation of that case seems like almost too much for the comment of a header file, and there are certainly

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Gurjeet Singh
On Wed, Sep 14, 2011 at 4:29 PM, Robert Haas robertmh...@gmail.com wrote: On Mon, Aug 8, 2011 at 7:47 AM, Robert Haas robertmh...@gmail.com wrote: I've been thinking about this too and actually went so far as to do some research and put together something that I hope covers most of the

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Robert Haas
On Wed, Sep 21, 2011 at 4:19 PM, Gurjeet Singh singh.gurj...@gmail.com wrote: On Wed, Sep 14, 2011 at 4:29 PM, Robert Haas robertmh...@gmail.com wrote: On Mon, Aug 8, 2011 at 7:47 AM, Robert Haas robertmh...@gmail.com wrote: I've been thinking about this too and actually went so far as to do

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Robert Haas
On Wed, Sep 21, 2011 at 3:39 PM, Kevin Grittner kevin.gritt...@wicourts.gov wrote: Robert Haas robertmh...@gmail.com wrote: On Wed, Sep 21, 2011 at 2:48 PM, Kevin Grittner kevin.gritt...@wicourts.gov wrote: Robert Haas robertmh...@gmail.com wrote: But even a full explanation of that case

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-21 Thread Kevin Grittner
Robert Haas robertmh...@gmail.com wrote: there are three questions that you might want to answer here: 1. I have a new architecture and I want barrier.h to support it. What do I need to do? 2. What is the behavior of the various constructs provided by barrier.h? 3. Why would I

Re: [HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-15 Thread Heikki Linnakangas
On 14.09.2011 23:29, Robert Haas wrote: On Mon, Aug 8, 2011 at 7:47 AM, Robert Haasrobertmh...@gmail.com wrote: I've been thinking about this too and actually went so far as to do some research and put together something that I hope covers most of the interesting cases. The attached patch is

[HACKERS] memory barriers (was: Yes, WaitLatch is vulnerable to weak-memory-ordering bugs)

2011-09-14 Thread Robert Haas
On Mon, Aug 8, 2011 at 7:47 AM, Robert Haas robertmh...@gmail.com wrote: I've been thinking about this too and actually went so far as to do some research and put together something that I hope covers most of the interesting cases.  The attached patch is pretty much entirely untested, but