Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Wed, 2014-02-19 at 16:53 -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 11:47 AM, Torvald Riegel wrote: > > On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: > >> > >> Can you point to it? Because I can find a draft standard, and it sure > >> as hell does *not* contain any

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 12:30 AM, Paul E. McKenney wrote: >> >> So lets make this really simple: if you have a consume->cmp->read, is >> the ordering of the two reads guaranteed? > > Not as far as I know. Also, as far as I know, there is no difference > between consume and relaxed in the

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 12:30:32AM -0800, Paul E. McKenney wrote: > On Wed, Feb 19, 2014 at 08:43:14PM -0800, Linus Torvalds wrote: [ . . . ] > So, if you make one of two changes to your example, then I will agree > with you. The first change is to have a real data dependency between > the read

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 08:43:14PM -0800, Linus Torvalds wrote: > On Wed, Feb 19, 2014 at 8:01 PM, Paul E. McKenney > wrote: > > > > The control dependency should order subsequent stores, at least assuming > > that "a" and "b" don't start off with identical stores that the compiler > > could pull

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 08:43:14PM -0800, Linus Torvalds wrote: On Wed, Feb 19, 2014 at 8:01 PM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: The control dependency should order subsequent stores, at least assuming that a and b don't start off with identical stores that the compiler

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 12:30:32AM -0800, Paul E. McKenney wrote: On Wed, Feb 19, 2014 at 08:43:14PM -0800, Linus Torvalds wrote: [ . . . ] So, if you make one of two changes to your example, then I will agree with you. The first change is to have a real data dependency between the read of

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 12:30 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: So lets make this really simple: if you have a consume-cmp-read, is the ordering of the two reads guaranteed? Not as far as I know. Also, as far as I know, there is no difference between consume and relaxed

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Wed, 2014-02-19 at 16:53 -0800, Linus Torvalds wrote: On Tue, Feb 18, 2014 at 11:47 AM, Torvald Riegel trie...@redhat.com wrote: On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: Can you point to it? Because I can find a draft standard, and it sure as hell does *not* contain any

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Wed, 2014-02-19 at 20:01 -0800, Paul E. McKenney wrote: On Wed, Feb 19, 2014 at 04:53:49PM -0800, Linus Torvalds wrote: On Tue, Feb 18, 2014 at 11:47 AM, Torvald Riegel trie...@redhat.com wrote: On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: Can you point to it? Because I

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 9:14 AM, Torvald Riegel trie...@redhat.com wrote: So the clarification is basically to the statement that the if (consume(p)) a version *would* have an ordering guarantee between the read of p and a, but the consume(p) ? a : b would *not* have such an ordering

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Wed, 2014-02-19 at 20:43 -0800, Linus Torvalds wrote: [Paul has already answered many of your questions, and my reply to your previous email should also answer some.] If the consumer of an atomic load isn't a pointer chasing operation, then the consume should be defined to be the same as

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Thu, 2014-02-20 at 00:30 -0800, Paul E. McKenney wrote: Well, all the compilers currently convert consume to acquire, so you have your wish there. Of course, that also means that they generate actual unneeded memory-barrier instructions, which seems extremely sub-optimal to me. GCC

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 09:01:06AM -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 12:30 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: So lets make this really simple: if you have a consume-cmp-read, is the ordering of the two reads guaranteed? Not as far as I know.

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 06:54:06PM +0100, Torvald Riegel wrote: xagsmtp4.20140220175519.1...@vmsdvm6.vnet.ibm.com X-Xagent-Gateway: vmsdvm6.vnet.ibm.com (XAGSMTP4 at VMSDVM6) On Thu, 2014-02-20 at 00:30 -0800, Paul E. McKenney wrote: Well, all the compilers currently convert consume to

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Thu, 2014-02-20 at 09:34 -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 9:14 AM, Torvald Riegel trie...@redhat.com wrote: So the clarification is basically to the statement that the if (consume(p)) a version *would* have an ordering guarantee between the read of p and a, but the

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 06:26:08PM +0100, Torvald Riegel wrote: xagsmtp2.20140220172700.0...@vmsdvm4.vnet.ibm.com X-Xagent-Gateway: vmsdvm4.vnet.ibm.com (XAGSMTP2 at VMSDVM4) On Wed, 2014-02-19 at 20:01 -0800, Paul E. McKenney wrote: On Wed, Feb 19, 2014 at 04:53:49PM -0800, Linus Torvalds

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Thu, 2014-02-20 at 09:01 -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 12:30 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: So lets make this really simple: if you have a consume-cmp-read, is the ordering of the two reads guaranteed? Not as far as I know. Also, as

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 9:49 AM, Torvald Riegel trie...@redhat.com wrote: Yes, mo_consume is more tricky than mo_acquire. However, that has an advantage because you can avoid getting stronger barriers if you don't need them (ie, you can avoid the auto-update to acquire you seem to have in

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 09:34:57AM -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 9:14 AM, Torvald Riegel trie...@redhat.com wrote: So the clarification is basically to the statement that the if (consume(p)) a version *would* have an ordering guarantee between the read of p and a,

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 10:11 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: You really need that consume to be acquire. So I think we now all agree that that is what the standard is saying. And I'm saying that that is wrong, that the standard is badly written, and should be fixed.

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Thu, 2014-02-20 at 10:11 -0800, Paul E. McKenney wrote: But yes, the compiler guys would be extremely happy to simply drop memory_order_consume from the standard, as it is the memory order that they most love to hate. Getting them to agree to any sort of peep-hole optimization semantics

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Torvald Riegel
On Thu, 2014-02-20 at 10:32 -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 10:11 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: You really need that consume to be acquire. So I think we now all agree that that is what the standard is saying. Huh? The standard says that

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 10:32:51AM -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 10:11 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: You really need that consume to be acquire. So I think we now all agree that that is what the standard is saying. And I'm saying that

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 07:44:32PM +0100, Torvald Riegel wrote: xagsmtp3.20140220184514.1...@bldgate.vnet.ibm.com X-Xagent-Gateway: bldgate.vnet.ibm.com (XAGSMTP3 at BLDGATE) On Thu, 2014-02-20 at 10:11 -0800, Paul E. McKenney wrote: But yes, the compiler guys would be extremely happy to

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 10:25 AM, Linus Torvalds torva...@linux-foundation.org wrote: While in my *sane* model, where you can consume things even if they then result in control dependencies, there will still eventually be a sync instruction on powerpc (because you really need one between the

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 11:02 AM, Linus Torvalds torva...@linux-foundation.org wrote: Again, the way I'd expect a compiler writer to actually *do* this is to just default to ac Oops, pressed send by mistake too early. I was almost done: I'd expect a compiler to just default to acquire

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 10:53 AM, Torvald Riegel trie...@redhat.com wrote: On Thu, 2014-02-20 at 10:32 -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 10:11 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: You really need that consume to be acquire. So I think we now all agree

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 10:56 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: The example gcc breakage was something like this: i = atomic_load(idx, memory_order_consume); x = array[0 + i - i]; Then gcc optimized this to: i = atomic_load(idx,

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Paul E. McKenney
On Thu, Feb 20, 2014 at 11:45:29AM -0800, Linus Torvalds wrote: On Thu, Feb 20, 2014 at 10:56 AM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: The example gcc breakage was something like this: i = atomic_load(idx, memory_order_consume); x = array[0 + i - i];

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-20 Thread Linus Torvalds
On Thu, Feb 20, 2014 at 2:10 PM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: Linus, given that you are calling me out for pushing legalistic and bad things, syntactic bullshit, and playing little games, I am forced to conclude that you have never attended any sort of standards-committee

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Linus Torvalds
On Wed, Feb 19, 2014 at 8:01 PM, Paul E. McKenney wrote: > > The control dependency should order subsequent stores, at least assuming > that "a" and "b" don't start off with identical stores that the compiler > could pull out of the "if" and merge. The same might also be true for ?: > for all I

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 04:53:49PM -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 11:47 AM, Torvald Riegel wrote: > > On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: > >> > >> Can you point to it? Because I can find a draft standard, and it sure > >> as hell does *not* contain

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 11:47 AM, Torvald Riegel wrote: > On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: >> >> Can you point to it? Because I can find a draft standard, and it sure >> as hell does *not* contain any clarity of the model. It has a *lot* of >> verbiage, but it's pretty

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 06:55:51PM +0100, Torvald Riegel wrote: > On Wed, 2014-02-19 at 07:14 -0800, Paul E. McKenney wrote: > > On Wed, Feb 19, 2014 at 11:59:08AM +0100, Torvald Riegel wrote: [ . . . ] > > > On both sides, the compiler will see that mmap() (or similar) is called, > > > so that

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Linus Torvalds
On Wed, Feb 19, 2014 at 6:40 AM, Torvald Riegel wrote: > > If all those other threads written in whichever way use the same memory > model and ABI for synchronization (e.g., choice of HW barriers for a > certain memory_order), it doesn't matter whether it's a hardware thread, > microcode,

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Wed, 2014-02-19 at 07:23 -0800, David Lang wrote: > On Tue, 18 Feb 2014, Torvald Riegel wrote: > > > On Tue, 2014-02-18 at 22:40 +0100, Peter Zijlstra wrote: > >> On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: > >>> Well, that's how atomics that aren't volatile are defined in

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Wed, 2014-02-19 at 07:14 -0800, Paul E. McKenney wrote: > On Wed, Feb 19, 2014 at 11:59:08AM +0100, Torvald Riegel wrote: > > On Tue, 2014-02-18 at 14:58 -0800, Paul E. McKenney wrote: > > > On Tue, Feb 18, 2014 at 10:40:15PM +0100, Torvald Riegel wrote: > > > >

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 11:59:08AM +0100, Torvald Riegel wrote: > On Tue, 2014-02-18 at 14:58 -0800, Paul E. McKenney wrote: > > On Tue, Feb 18, 2014 at 10:40:15PM +0100, Torvald Riegel wrote: > > > xagsmtp4.20140218214207.8...@vmsdvm9.vnet.ibm.com > > > X-Xagent-Gateway: vmsdvm9.vnet.ibm.com

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread David Lang
On Tue, 18 Feb 2014, Torvald Riegel wrote: On Tue, 2014-02-18 at 22:40 +0100, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: Well, that's how atomics that aren't volatile are defined in the standard. I can see that you want something else too, but that

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 14:14 -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 1:21 PM, Torvald Riegel wrote: > >> > >> So imagine that you have some clever global optimizer that sees that > >> the program never ever actually sets the dirty bit at all in any > >> thread, and then uses that

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Peter Zijlstra
On Wed, Feb 19, 2014 at 12:07:02PM +0100, Torvald Riegel wrote: > > Its not only hardware; also the kernel/user boundary has this same > > problem. We cannot a-priory say what userspace will do; in fact, because > > we're a general purpose OS, we must assume it will willfully try its > > bestest

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 22:47 +0100, Peter Zijlstra wrote: > On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: > > Yes, I do. But that seems to be "volatile" territory. It crosses the > > boundaries of the abstract machine, and thus is input/output. Which > > fraction of your atomic

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 14:58 -0800, Paul E. McKenney wrote: > On Tue, Feb 18, 2014 at 10:40:15PM +0100, Torvald Riegel wrote: > > xagsmtp4.20140218214207.8...@vmsdvm9.vnet.ibm.com > > X-Xagent-Gateway: vmsdvm9.vnet.ibm.com (XAGSMTP4 at VMSDVM9) > > > > On Tue, 2014-02-18 at 09:16 -0800, Paul E.

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 22:52 +0100, Peter Zijlstra wrote: > > > 4.Some drivers allow user-mode code to mmap() some of their > > > state. Any changes undertaken by the user-mode code would > > > be invisible to the compiler. > > > > A good point, but a compiler that doesn't try to

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 23:48 +, Peter Sewell wrote: > On 18 February 2014 20:43, Torvald Riegel wrote: > > On Tue, 2014-02-18 at 12:12 +, Peter Sewell wrote: > >> Several of you have said that the standard and compiler should not > >> permit speculative writes of atomics, or (effectively)

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 23:48 +, Peter Sewell wrote: On 18 February 2014 20:43, Torvald Riegel trie...@redhat.com wrote: On Tue, 2014-02-18 at 12:12 +, Peter Sewell wrote: Several of you have said that the standard and compiler should not permit speculative writes of atomics, or

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 22:52 +0100, Peter Zijlstra wrote: 4.Some drivers allow user-mode code to mmap() some of their state. Any changes undertaken by the user-mode code would be invisible to the compiler. A good point, but a compiler that doesn't try to (incorrectly)

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 14:58 -0800, Paul E. McKenney wrote: On Tue, Feb 18, 2014 at 10:40:15PM +0100, Torvald Riegel wrote: xagsmtp4.20140218214207.8...@vmsdvm9.vnet.ibm.com X-Xagent-Gateway: vmsdvm9.vnet.ibm.com (XAGSMTP4 at VMSDVM9) On Tue, 2014-02-18 at 09:16 -0800, Paul E. McKenney

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 22:47 +0100, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: Yes, I do. But that seems to be volatile territory. It crosses the boundaries of the abstract machine, and thus is input/output. Which fraction of your atomic accesses

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Peter Zijlstra
On Wed, Feb 19, 2014 at 12:07:02PM +0100, Torvald Riegel wrote: Its not only hardware; also the kernel/user boundary has this same problem. We cannot a-priory say what userspace will do; in fact, because we're a general purpose OS, we must assume it will willfully try its bestest to wreck

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Tue, 2014-02-18 at 14:14 -0800, Linus Torvalds wrote: On Tue, Feb 18, 2014 at 1:21 PM, Torvald Riegel trie...@redhat.com wrote: So imagine that you have some clever global optimizer that sees that the program never ever actually sets the dirty bit at all in any thread, and then uses

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread David Lang
On Tue, 18 Feb 2014, Torvald Riegel wrote: On Tue, 2014-02-18 at 22:40 +0100, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: Well, that's how atomics that aren't volatile are defined in the standard. I can see that you want something else too, but that

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 11:59:08AM +0100, Torvald Riegel wrote: On Tue, 2014-02-18 at 14:58 -0800, Paul E. McKenney wrote: On Tue, Feb 18, 2014 at 10:40:15PM +0100, Torvald Riegel wrote: xagsmtp4.20140218214207.8...@vmsdvm9.vnet.ibm.com X-Xagent-Gateway: vmsdvm9.vnet.ibm.com (XAGSMTP4 at

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Wed, 2014-02-19 at 07:14 -0800, Paul E. McKenney wrote: On Wed, Feb 19, 2014 at 11:59:08AM +0100, Torvald Riegel wrote: On Tue, 2014-02-18 at 14:58 -0800, Paul E. McKenney wrote: On Tue, Feb 18, 2014 at 10:40:15PM +0100, Torvald Riegel wrote:

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Torvald Riegel
On Wed, 2014-02-19 at 07:23 -0800, David Lang wrote: On Tue, 18 Feb 2014, Torvald Riegel wrote: On Tue, 2014-02-18 at 22:40 +0100, Peter Zijlstra wrote: On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: Well, that's how atomics that aren't volatile are defined in the

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Linus Torvalds
On Wed, Feb 19, 2014 at 6:40 AM, Torvald Riegel trie...@redhat.com wrote: If all those other threads written in whichever way use the same memory model and ABI for synchronization (e.g., choice of HW barriers for a certain memory_order), it doesn't matter whether it's a hardware thread,

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 06:55:51PM +0100, Torvald Riegel wrote: On Wed, 2014-02-19 at 07:14 -0800, Paul E. McKenney wrote: On Wed, Feb 19, 2014 at 11:59:08AM +0100, Torvald Riegel wrote: [ . . . ] On both sides, the compiler will see that mmap() (or similar) is called, so that means the

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 11:47 AM, Torvald Riegel trie...@redhat.com wrote: On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: Can you point to it? Because I can find a draft standard, and it sure as hell does *not* contain any clarity of the model. It has a *lot* of verbiage, but it's

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Paul E. McKenney
On Wed, Feb 19, 2014 at 04:53:49PM -0800, Linus Torvalds wrote: On Tue, Feb 18, 2014 at 11:47 AM, Torvald Riegel trie...@redhat.com wrote: On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: Can you point to it? Because I can find a draft standard, and it sure as hell does *not*

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-19 Thread Linus Torvalds
On Wed, Feb 19, 2014 at 8:01 PM, Paul E. McKenney paul...@linux.vnet.ibm.com wrote: The control dependency should order subsequent stores, at least assuming that a and b don't start off with identical stores that the compiler could pull out of the if and merge. The same might also be true for

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Sewell
On 18 February 2014 20:43, Torvald Riegel wrote: > On Tue, 2014-02-18 at 12:12 +, Peter Sewell wrote: >> Several of you have said that the standard and compiler should not >> permit speculative writes of atomics, or (effectively) that the >> compiler should preserve dependencies. In simple

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 10:40:15PM +0100, Torvald Riegel wrote: > xagsmtp4.20140218214207.8...@vmsdvm9.vnet.ibm.com > X-Xagent-Gateway: vmsdvm9.vnet.ibm.com (XAGSMTP4 at VMSDVM9) > > On Tue, 2014-02-18 at 09:16 -0800, Paul E. McKenney wrote: > > On Tue, Feb 18, 2014 at 08:49:13AM -0800, Linus

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 1:21 PM, Torvald Riegel wrote: >> >> So imagine that you have some clever global optimizer that sees that >> the program never ever actually sets the dirty bit at all in any >> thread, and then uses that kind of non-local knowledge to make >> optimization decisions. THAT

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Zijlstra
> > 4. Some drivers allow user-mode code to mmap() some of their > > state. Any changes undertaken by the user-mode code would > > be invisible to the compiler. > > A good point, but a compiler that doesn't try to (incorrectly) assume > something about the semantics of mmap will simply

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Zijlstra
On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: > Yes, I do. But that seems to be "volatile" territory. It crosses the > boundaries of the abstract machine, and thus is input/output. Which > fraction of your atomic accesses can read values produced by hardware? > I would still

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Tue, 2014-02-18 at 22:40 +0100, Peter Zijlstra wrote: > On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: > > Well, that's how atomics that aren't volatile are defined in the > > standard. I can see that you want something else too, but that doesn't > > mean that the other thing

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Tue, 2014-02-18 at 09:16 -0800, Paul E. McKenney wrote: > On Tue, Feb 18, 2014 at 08:49:13AM -0800, Linus Torvalds wrote: > > On Tue, Feb 18, 2014 at 7:31 AM, Torvald Riegel wrote: > > > On Mon, 2014-02-17 at 16:05 -0800, Linus Torvalds wrote: > > >> And exactly because I know enough, I would

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Zijlstra
On Tue, Feb 18, 2014 at 10:21:56PM +0100, Torvald Riegel wrote: > Well, that's how atomics that aren't volatile are defined in the > standard. I can see that you want something else too, but that doesn't > mean that the other thing is broken. Well that other thing depends on being able to see

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 09:43:31PM +0100, Torvald Riegel wrote: > xagsmtp5.20140218204423.3...@bldgate.vnet.ibm.com > X-Xagent-Gateway: bldgate.vnet.ibm.com (XAGSMTP5 at BLDGATE) > > On Tue, 2014-02-18 at 12:12 +, Peter Sewell wrote: > > Several of you have said that the standard and compiler

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Tue, 2014-02-18 at 08:49 -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 7:31 AM, Torvald Riegel wrote: > > On Mon, 2014-02-17 at 16:05 -0800, Linus Torvalds wrote: > >> And exactly because I know enough, I would *really* like atomics to be > >> well-defined, and have very clear - and

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Tue, 2014-02-18 at 18:21 +, Peter Sewell wrote: > On 18 February 2014 17:38, Linus Torvalds > wrote: > > On Tue, Feb 18, 2014 at 4:12 AM, Peter Sewell > > wrote: > >> > >> For example, suppose we have, in one compilation unit: > >> > >> void f(int ra, int*rb) { > >> if

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Tue, 2014-02-18 at 12:12 +, Peter Sewell wrote: > Several of you have said that the standard and compiler should not > permit speculative writes of atomics, or (effectively) that the > compiler should preserve dependencies. In simple examples it's easy > to see what that means, but in

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Tue, 2014-02-18 at 08:55 -0800, Paul E. McKenney wrote: > On Tue, Feb 18, 2014 at 04:38:40PM +0100, Torvald Riegel wrote: > > On Mon, 2014-02-17 at 16:18 -0800, Linus Torvalds wrote: > > > On Mon, Feb 17, 2014 at 3:41 PM, Torvald Riegel > > > wrote: > > > > > > > > There's an underlying

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Tue, 2014-02-18 at 09:44 -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 8:17 AM, Torvald Riegel wrote: > > The standard is clear on what's required. I strongly suggest reading > > the formalization of the memory model by Batty et al. > > Can you point to it? Because I can find a

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 10:49:27AM -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 10:21 AM, Peter Sewell > wrote: > > > > This is a bit more subtle, because (on ARM and POWER) removing the > > dependency and conditional branch is actually in general *not* equivalent > > in the hardware,

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 06:23:47PM +, Peter Sewell wrote: > On 18 February 2014 17:16, Paul E. McKenney > wrote: > > On Tue, Feb 18, 2014 at 08:49:13AM -0800, Linus Torvalds wrote: > >> On Tue, Feb 18, 2014 at 7:31 AM, Torvald Riegel wrote: > >> > On Mon, 2014-02-17 at 16:05 -0800, Linus

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 09:44:48AM -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 8:17 AM, Torvald Riegel wrote: [ . . . ] > > The standard is clear on what's required. I strongly suggest reading > > the formalization of the memory model by Batty et al. > > Can you point to it?

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 10:23 AM, Peter Sewell wrote: > > interesting list. So are you saying that value-range-analysis and > such-like (I say glibly, without really knowing what "such-like" > refers to here) are fundamentally incompatible with > the kernel code No, it's fine to do things like

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 10:21 AM, Peter Sewell wrote: > > This is a bit more subtle, because (on ARM and POWER) removing the > dependency and conditional branch is actually in general *not* equivalent > in the hardware, in a concurrent context. So I agree, but I think that's a generic issue with

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Sewell
On 18 February 2014 17:16, Paul E. McKenney wrote: > On Tue, Feb 18, 2014 at 08:49:13AM -0800, Linus Torvalds wrote: >> On Tue, Feb 18, 2014 at 7:31 AM, Torvald Riegel wrote: >> > On Mon, 2014-02-17 at 16:05 -0800, Linus Torvalds wrote: >> >> And exactly because I know enough, I would *really*

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Sewell
On 18 February 2014 17:38, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 4:12 AM, Peter Sewell > wrote: >> >> For example, suppose we have, in one compilation unit: >> >> void f(int ra, int*rb) { >> if (ra==42) >> *rb=42; >> else >> *rb=42; >> } > > So this

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Mon, 2014-02-17 at 16:09 -0800, Linus Torvalds wrote: > On Mon, Feb 17, 2014 at 3:17 PM, Torvald Riegel wrote: > > On Mon, 2014-02-17 at 14:32 -0800, > > > >> Stop claiming it "can return 1".. It *never* returns 1 unless you do > >> the load and *verify* it, or unless the load itself can be

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 8:17 AM, Torvald Riegel wrote: >> >> "Consume operation: no reads in the current thread dependent on the >> value currently loaded can be reordered before this load" > > I can't remember seeing that language in the standard (ie, C or C++). > Where is this from? That's

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 4:12 AM, Peter Sewell wrote: > > For example, suppose we have, in one compilation unit: > > void f(int ra, int*rb) { > if (ra==42) > *rb=42; > else > *rb=42; > } So this is a great example, and in general I really like your page at: >

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 03:16:33PM +, Mark Batty wrote: > Hi Paul, > > Thanks for the document. I'm looking forward to reading the bits about > dependency chains in Linux. And I am looking forward to your thoughts on those bits! > > One point of confusion for me... Example 4 says "language

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 08:49:13AM -0800, Linus Torvalds wrote: > On Tue, Feb 18, 2014 at 7:31 AM, Torvald Riegel wrote: > > On Mon, 2014-02-17 at 16:05 -0800, Linus Torvalds wrote: > >> And exactly because I know enough, I would *really* like atomics to be > >> well-defined, and have very clear

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 04:38:40PM +0100, Torvald Riegel wrote: > On Mon, 2014-02-17 at 16:18 -0800, Linus Torvalds wrote: > > On Mon, Feb 17, 2014 at 3:41 PM, Torvald Riegel wrote: > > > > > > There's an underlying problem here that's independent from the actual > > > instance that you're

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 04:56:40PM +0100, Torvald Riegel wrote: > On Mon, 2014-02-17 at 19:00 -0800, Paul E. McKenney wrote: > > On Mon, Feb 17, 2014 at 12:18:21PM -0800, Linus Torvalds wrote: > > > On Mon, Feb 17, 2014 at 11:55 AM, Torvald Riegel > > > wrote: > > > > > > > > Which example do

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Linus Torvalds
On Tue, Feb 18, 2014 at 7:31 AM, Torvald Riegel wrote: > On Mon, 2014-02-17 at 16:05 -0800, Linus Torvalds wrote: >> And exactly because I know enough, I would *really* like atomics to be >> well-defined, and have very clear - and *local* - rules about how they >> can be combined and optimized. >

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 03:33:35PM +, Peter Sewell wrote: > Hi Paul, > > On 18 February 2014 14:56, Paul E. McKenney > wrote: > > On Tue, Feb 18, 2014 at 12:12:06PM +, Peter Sewell wrote: > >> Several of you have said that the standard and compiler should not > >> permit speculative

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Mon, 2014-02-17 at 19:42 -0800, Linus Torvalds wrote: > On Mon, Feb 17, 2014 at 7:24 PM, Linus Torvalds > wrote: > > > > As far as I can tell, the intent is that you can't do value > > speculation (except perhaps for the "relaxed", which quite frankly > > sounds largely useless). > > Hmm. The

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Sewell
On 18 February 2014 12:53, Peter Zijlstra wrote: > On Tue, Feb 18, 2014 at 12:12:06PM +, Peter Sewell wrote: >> Several of you have said that the standard and compiler should not >> permit speculative writes of atomics, or (effectively) that the >> compiler should preserve dependencies. > >

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Mon, 2014-02-17 at 19:00 -0800, Paul E. McKenney wrote: > On Mon, Feb 17, 2014 at 12:18:21PM -0800, Linus Torvalds wrote: > > On Mon, Feb 17, 2014 at 11:55 AM, Torvald Riegel wrote: > > > > > > Which example do you have in mind here? Haven't we resolved all the > > > debated examples, or did

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Mon, 2014-02-17 at 16:18 -0800, Linus Torvalds wrote: > On Mon, Feb 17, 2014 at 3:41 PM, Torvald Riegel wrote: > > > > There's an underlying problem here that's independent from the actual > > instance that you're worried about here: "no sense" is a ultimately a > > matter of

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Sewell
Hi Paul, On 18 February 2014 14:56, Paul E. McKenney wrote: > On Tue, Feb 18, 2014 at 12:12:06PM +, Peter Sewell wrote: >> Several of you have said that the standard and compiler should not >> permit speculative writes of atomics, or (effectively) that the >> compiler should preserve

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Torvald Riegel
On Mon, 2014-02-17 at 16:05 -0800, Linus Torvalds wrote: > And exactly because I know enough, I would *really* like atomics to be > well-defined, and have very clear - and *local* - rules about how they > can be combined and optimized. "Local"? > None of this "if you can prove that the read has

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Mark Batty
Hi Paul, Thanks for the document. I'm looking forward to reading the bits about dependency chains in Linux. > One point of confusion for me... Example 4 says "language must allow". > Shouldn't that be "language is permitted to allow"? When we say "allow", we mean that the optimised execution

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Paul E. McKenney
On Tue, Feb 18, 2014 at 12:12:06PM +, Peter Sewell wrote: > Several of you have said that the standard and compiler should not > permit speculative writes of atomics, or (effectively) that the > compiler should preserve dependencies. In simple examples it's easy > to see what that means, but

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Zijlstra
On Tue, Feb 18, 2014 at 12:12:06PM +, Peter Sewell wrote: > Several of you have said that the standard and compiler should not > permit speculative writes of atomics, or (effectively) that the > compiler should preserve dependencies. The example below only deals with control dependencies; so

Re: [RFC][PATCH 0/5] arch: atomic rework

2014-02-18 Thread Peter Sewell
Several of you have said that the standard and compiler should not permit speculative writes of atomics, or (effectively) that the compiler should preserve dependencies. In simple examples it's easy to see what that means, but in general it's not so clear what the language should guarantee,

<    1   2   3   4   5   6   >