Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-12 Thread David Howells
[EMAIL PROTECTED] wrote: > do { > oldvalue = ll(addr) > newvalue = ... oldvalue ... > } while (!sc(addr, oldvalue, newvalue)) > > Where sc() could be a cmpxchg. But, more importantly, if the > architecture did implement LL/SC, it could be a "try plain SC; if > that fails try CMPXCHG

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-12 Thread David Howells
[EMAIL PROTECTED] wrote: do { oldvalue = ll(addr) newvalue = ... oldvalue ... } while (!sc(addr, oldvalue, newvalue)) Where sc() could be a cmpxchg. But, more importantly, if the architecture did implement LL/SC, it could be a try plain SC; if that fails try CMPXCHG built

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-11 Thread linux
>> to keep the amount of code between ll and sc to an absolute minimum >> to avoid interference which causes livelock. Processor timeouts >> are generally much longer than any reasonable code sequence. > "Generally" does not mean you can just ignore it and hope the C compiler > does the right

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-11 Thread David Howells
Russell King <[EMAIL PROTECTED]> wrote: > Yes you can. Well, you can on ARM at least. Between the load exclusive > you can do anything you like until you hit the store exclusive. How come atomic_set() on arm6 is implemented as: static inline void atomic_set(atomic_t *v, int i)

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-11 Thread David Howells
Russell King [EMAIL PROTECTED] wrote: Yes you can. Well, you can on ARM at least. Between the load exclusive you can do anything you like until you hit the store exclusive. How come atomic_set() on arm6 is implemented as: static inline void atomic_set(atomic_t *v, int i) {

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-11 Thread linux
to keep the amount of code between ll and sc to an absolute minimum to avoid interference which causes livelock. Processor timeouts are generally much longer than any reasonable code sequence. Generally does not mean you can just ignore it and hope the C compiler does the right thing. Nor

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread Nick Piggin
[EMAIL PROTECTED] wrote: atomic_ll() / atomic_sc() with the restriction that they cannot be nested, you cannot write any C code between them, and may only call into some specific set of atomic_llsc_xxx primitives, operating on the address given to ll, and must not have more than a given number

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread linux
> atomic_ll() / atomic_sc() with the restriction that they cannot be > nested, you cannot write any C code between them, and may only call > into some specific set of atomic_llsc_xxx primitives, operating on > the address given to ll, and must not have more than a given number > of

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread Linus Torvalds
On Sun, 10 Dec 2006, [EMAIL PROTECTED] wrote: > > While I agree that LL/SC can't be part of the kernel API for people to > get arbitrarily clever with in the device driver du jour, they are *very* > nice abstractions for shrinking the arch-specific code size. I'm not sure. The thing is, it's

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread Nick Piggin
Hi "Linux", [EMAIL PROTECTED] wrote: Even if ARM is able to handle any arbitrary C code between the "load locked" and store conditional API, other architectures can not by definition. Maybe so, but I think you and Linus are missing the middle ground. Nobdy argued against adding nice arch

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread Nick Piggin
Hi Linux, [EMAIL PROTECTED] wrote: Even if ARM is able to handle any arbitrary C code between the load locked and store conditional API, other architectures can not by definition. Maybe so, but I think you and Linus are missing the middle ground. Nobdy argued against adding nice arch

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread Linus Torvalds
On Sun, 10 Dec 2006, [EMAIL PROTECTED] wrote: While I agree that LL/SC can't be part of the kernel API for people to get arbitrarily clever with in the device driver du jour, they are *very* nice abstractions for shrinking the arch-specific code size. I'm not sure. The thing is, it's

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread linux
atomic_ll() / atomic_sc() with the restriction that they cannot be nested, you cannot write any C code between them, and may only call into some specific set of atomic_llsc_xxx primitives, operating on the address given to ll, and must not have more than a given number of instructions

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an

2006-12-10 Thread Nick Piggin
[EMAIL PROTECTED] wrote: atomic_ll() / atomic_sc() with the restriction that they cannot be nested, you cannot write any C code between them, and may only call into some specific set of atomic_llsc_xxx primitives, operating on the address given to ll, and must not have more than a given number

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Nick Piggin
Russell King wrote: On Fri, Dec 08, 2006 at 12:18:52PM +1100, Nick Piggin wrote: Russell King wrote: On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: Implementing ll/sc based accessor macros allows both ll/sc _and_ cmpxchg architectures to produce optimal code. Implementing

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: >> > The only instructions which affect the exclusive access state are the > exclusive access instructions themselves. Not according to the docs I found. The ARM1136 manual explicitly states that any attempt to modify that address clears the tag (for

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: > > No such restriction on ARM. > > Also not true. The architectural implementation is: I checked the ARM manuals, and quite fankly, they don't back you up. They do not claim that the physical address tag is byte-granular, and in fact they make it

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 11:35:39AM -0800, Linus Torvalds wrote: > > > On Fri, 8 Dec 2006, Russell King wrote: > > > > Yes you can. Well, you can on ARM at least. Between the load exclusive > > you can do anything you like until you hit the store exclusive. If you > > haven't touched the

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 11:37:45AM -0800, Linus Torvalds wrote: > > > On Fri, 8 Dec 2006, Russell King wrote: > > > > I utterly disagree. I could code atomic_add() as: > > Sure. And Alpha could do that too. If you write the C code a specific way, > you can make it work. That does NOT mean

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: > > Yes you can. Well, you can on ARM at least. Between the load exclusive > you can do anything you like until you hit the store exclusive. If you > haven't touched the location (with anything other than another load > exclusive) and no other CPU has

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: > > I utterly disagree. I could code atomic_add() as: Sure. And Alpha could do that too. If you write the C code a specific way, you can make it work. That does NOT mean that you can expose it widely as a portable interface - it's still just a very

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 11:15:58AM -0800, Linus Torvalds wrote: > On Fri, 8 Dec 2006, Christoph Lameter wrote: > > > > As also shown in this thread: There are restrictions on what you can do > > between ll/sc > > This, btw, is almost certainly true on ARM too. > > There are three major reasons

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Christoph Lameter wrote: > > As also shown in this thread: There are restrictions on what you can do > between ll/sc This, btw, is almost certainly true on ARM too. There are three major reasons for restrictions on ll/sc: - bus-cycle induced things (eg variations of

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 10:46:17AM -0800, Linus Torvalds wrote: > > > On Fri, 8 Dec 2006, David Howells wrote: > > > > In fact I think more things have LL/SC than have CMPXCHG. > > But you cannot expose ll/sc to C, so that's a bogus argument. Yes you can. Well, you can on ARM at least.

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, David Howells wrote: > > In fact I think more things have LL/SC than have CMPXCHG. But you cannot expose ll/sc to C, so that's a bogus argument. If you do ll/sc, you need to program in assembly language. Linus - To unsubscribe from this list: send the line

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: > As proven previously the reverse is also true. And as shown previously > the cheaper out of the two for all platforms is the LL/SC based > implementation, where the architecture specific implementation can > be _either_ LL/SC based or cmpxchg based

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 09:06:00AM -0800, Christoph Lameter wrote: > On Fri, 8 Dec 2006, David Howells wrote: > > > > It is the most universal atomic instruction that I know of. > > > > I think TAS-type things and XCHG-type things are more common. > > Huh? The most popular architectures are

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, David Howells wrote: > > It is the most universal atomic instruction that I know of. > > I think TAS-type things and XCHG-type things are more common. Huh? The most popular architectures are i386 x86_64 sparc ia64 etc which all have one or the other form of cmpxchg (some

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 08:53:22AM -0800, Christoph Lameter wrote: > On Fri, 8 Dec 2006, Russell King wrote: > > > > Not having cmpxchg is even worse because it requires the introduction and > > > maintenance of large sets of arch specific operations. Much more complex. > > > > And which bit of

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread David Howells
Christoph Lameter <[EMAIL PROTECTED]> wrote: > cmpxchg is the simplest solution to realize many other atomic operations and > its widely available on a wide variety of platforms. But by no means all. Where it doesn't exist it can only be properly emulated by something such as LL/SC if they are

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: > > Not having cmpxchg is even worse because it requires the introduction and > > maintenance of large sets of arch specific operations. Much more complex. > > And which bit of "not available on many architectures" have you not grasped > yet? We

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 08:43:09AM -0800, Christoph Lameter wrote: > On Fri, 8 Dec 2006, Russell King wrote: > > > You're advocating cmpxchg is adopted by all architectures. It isn't > > available on many architectures, and those which it can be requires > > unnecessarily complicated coding. >

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: > You're advocating cmpxchg is adopted by all architectures. It isn't > available on many architectures, and those which it can be requires > unnecessarily complicated coding. Not having cmpxchg is even worse because it requires the introduction and

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 08:06:23AM -0800, Christoph Lameter wrote: > On Fri, 8 Dec 2006, Russell King wrote: > > > I'm trying to suggest a better implementation for atomic ops rather > > than just bowing to this x86-centric "cmpxchg is the best, everyone > > must implement it" mentality. > >

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: > I'm trying to suggest a better implementation for atomic ops rather > than just bowing to this x86-centric "cmpxchg is the best, everyone > must implement it" mentality. cmpxchg is the simplest solution to realize many other atomic operations and its

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Thu, Dec 07, 2006 at 03:06:06PM +, Russell King wrote: > On Wed, Dec 06, 2006 at 11:05:22AM -0800, Linus Torvalds wrote: > > > > > > On Wed, 6 Dec 2006, Christoph Lameter wrote: > > > > > > I'd really appreciate a cmpxchg that is generically available for > > > all arches. It will allow

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 12:18:52PM +1100, Nick Piggin wrote: > Russell King wrote: > >On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: > > >>>Implementing ll/sc based accessor macros allows both ll/sc _and_ cmpxchg > >>>architectures to produce optimal code. > >>> > >>>Implementing an

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 12:18:52PM +1100, Nick Piggin wrote: Russell King wrote: On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: Implementing ll/sc based accessor macros allows both ll/sc _and_ cmpxchg architectures to produce optimal code. Implementing an cmpxchg based

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Thu, Dec 07, 2006 at 03:06:06PM +, Russell King wrote: On Wed, Dec 06, 2006 at 11:05:22AM -0800, Linus Torvalds wrote: On Wed, 6 Dec 2006, Christoph Lameter wrote: I'd really appreciate a cmpxchg that is generically available for all arches. It will allow lockless

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: I'm trying to suggest a better implementation for atomic ops rather than just bowing to this x86-centric cmpxchg is the best, everyone must implement it mentality. cmpxchg is the simplest solution to realize many other atomic operations and its widely

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 08:06:23AM -0800, Christoph Lameter wrote: On Fri, 8 Dec 2006, Russell King wrote: I'm trying to suggest a better implementation for atomic ops rather than just bowing to this x86-centric cmpxchg is the best, everyone must implement it mentality. cmpxchg is the

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: You're advocating cmpxchg is adopted by all architectures. It isn't available on many architectures, and those which it can be requires unnecessarily complicated coding. Not having cmpxchg is even worse because it requires the introduction and

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 08:43:09AM -0800, Christoph Lameter wrote: On Fri, 8 Dec 2006, Russell King wrote: You're advocating cmpxchg is adopted by all architectures. It isn't available on many architectures, and those which it can be requires unnecessarily complicated coding. Not

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread David Howells
Christoph Lameter [EMAIL PROTECTED] wrote: cmpxchg is the simplest solution to realize many other atomic operations and its widely available on a wide variety of platforms. But by no means all. Where it doesn't exist it can only be properly emulated by something such as LL/SC if they are

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: Not having cmpxchg is even worse because it requires the introduction and maintenance of large sets of arch specific operations. Much more complex. And which bit of not available on many architectures have you not grasped yet? We discussed various

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 08:53:22AM -0800, Christoph Lameter wrote: On Fri, 8 Dec 2006, Russell King wrote: Not having cmpxchg is even worse because it requires the introduction and maintenance of large sets of arch specific operations. Much more complex. And which bit of not

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, David Howells wrote: It is the most universal atomic instruction that I know of. I think TAS-type things and XCHG-type things are more common. Huh? The most popular architectures are i386 x86_64 sparc ia64 etc which all have one or the other form of cmpxchg (some issues

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 09:06:00AM -0800, Christoph Lameter wrote: On Fri, 8 Dec 2006, David Howells wrote: It is the most universal atomic instruction that I know of. I think TAS-type things and XCHG-type things are more common. Huh? The most popular architectures are i386 x86_64

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Christoph Lameter
On Fri, 8 Dec 2006, Russell King wrote: As proven previously the reverse is also true. And as shown previously the cheaper out of the two for all platforms is the LL/SC based implementation, where the architecture specific implementation can be _either_ LL/SC based or cmpxchg based depending

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, David Howells wrote: In fact I think more things have LL/SC than have CMPXCHG. But you cannot expose ll/sc to C, so that's a bogus argument. If you do ll/sc, you need to program in assembly language. Linus - To unsubscribe from this list: send the line

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 10:46:17AM -0800, Linus Torvalds wrote: On Fri, 8 Dec 2006, David Howells wrote: In fact I think more things have LL/SC than have CMPXCHG. But you cannot expose ll/sc to C, so that's a bogus argument. Yes you can. Well, you can on ARM at least. Between the

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Christoph Lameter wrote: As also shown in this thread: There are restrictions on what you can do between ll/sc This, btw, is almost certainly true on ARM too. There are three major reasons for restrictions on ll/sc: - bus-cycle induced things (eg variations of you

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 11:15:58AM -0800, Linus Torvalds wrote: On Fri, 8 Dec 2006, Christoph Lameter wrote: As also shown in this thread: There are restrictions on what you can do between ll/sc This, btw, is almost certainly true on ARM too. There are three major reasons for

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: I utterly disagree. I could code atomic_add() as: Sure. And Alpha could do that too. If you write the C code a specific way, you can make it work. That does NOT mean that you can expose it widely as a portable interface - it's still just a very

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: Yes you can. Well, you can on ARM at least. Between the load exclusive you can do anything you like until you hit the store exclusive. If you haven't touched the location (with anything other than another load exclusive) and no other CPU has issued

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 11:37:45AM -0800, Linus Torvalds wrote: On Fri, 8 Dec 2006, Russell King wrote: I utterly disagree. I could code atomic_add() as: Sure. And Alpha could do that too. If you write the C code a specific way, you can make it work. That does NOT mean that you can

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Russell King
On Fri, Dec 08, 2006 at 11:35:39AM -0800, Linus Torvalds wrote: On Fri, 8 Dec 2006, Russell King wrote: Yes you can. Well, you can on ARM at least. Between the load exclusive you can do anything you like until you hit the store exclusive. If you haven't touched the location (with

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: No such restriction on ARM. Also not true. The architectural implementation is: I checked the ARM manuals, and quite fankly, they don't back you up. They do not claim that the physical address tag is byte-granular, and in fact they make it pretty

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Linus Torvalds
On Fri, 8 Dec 2006, Russell King wrote: The only instructions which affect the exclusive access state are the exclusive access instructions themselves. Not according to the docs I found. The ARM1136 manual explicitly states that any attempt to modify that address clears the tag (for

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-08 Thread Nick Piggin
Russell King wrote: On Fri, Dec 08, 2006 at 12:18:52PM +1100, Nick Piggin wrote: Russell King wrote: On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: Implementing ll/sc based accessor macros allows both ll/sc _and_ cmpxchg architectures to produce optimal code. Implementing

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Nick Piggin
Russell King wrote: On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: Implementing ll/sc based accessor macros allows both ll/sc _and_ cmpxchg architectures to produce optimal code. Implementing an cmpxchg based accessor macro allows cmpxchg architectures to produce optimal code

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Ralf Baechle
On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: > Wrong. Your ll/sc implementation with cmpxchg is buggy. The cmpxchg > load_locked is not locked at all, and there can be interleaving writes > between the load and cmpxchg which do not cause the store_conditional > to fail. > > It

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Linus Torvalds
On Thu, 7 Dec 2006, Nick Piggin wrote: > > It might be reasonable to implement this watered down version, but: > don't some architectures have restrictions on what instructions can > be issued between the ll and the sc? Yes. You really probably do not want to expose ll/sc on a C level because

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Russell King
On Wed, Dec 06, 2006 at 11:05:22AM -0800, Linus Torvalds wrote: > > > On Wed, 6 Dec 2006, Christoph Lameter wrote: > > > > I'd really appreciate a cmpxchg that is generically available for > > all arches. It will allow lockless implementation for various performance > > criticial portions of

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Russell King
On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: > Russell King wrote: > >On Wed, Dec 06, 2006 at 11:16:55AM -0800, Christoph Lameter wrote: > > >No. If you read what I said, you'll see that you can _cheaply_ use > >cmpxchg in a ll/sc based implementation. Take an atomic increment >

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Ivan Kokshaysky
On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: > It might be reasonable to implement this watered down version, but: > don't some architectures have restrictions on what instructions can > be issued between the ll and the sc? Yes. On Alpha you cannot execute other load/stores, taken

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Nick Piggin
Russell King wrote: On Wed, Dec 06, 2006 at 11:16:55AM -0800, Christoph Lameter wrote: No. If you read what I said, you'll see that you can _cheaply_ use cmpxchg in a ll/sc based implementation. Take an atomic increment operation. do { old = load_locked(addr);

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Nick Piggin
Linus Torvalds wrote: On Thu, 7 Dec 2006, Roman Zippel wrote: On Wed, 6 Dec 2006, Matthew Wilcox wrote: To be honest, it'd be much easier if we only defined these operations on atomic_t's. We have all the infrastructure in place for them, and they're fairly well understood. If you need

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Nick Piggin
Linus Torvalds wrote: On Thu, 7 Dec 2006, Roman Zippel wrote: On Wed, 6 Dec 2006, Matthew Wilcox wrote: To be honest, it'd be much easier if we only defined these operations on atomic_t's. We have all the infrastructure in place for them, and they're fairly well understood. If you need

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Nick Piggin
Russell King wrote: On Wed, Dec 06, 2006 at 11:16:55AM -0800, Christoph Lameter wrote: No. If you read what I said, you'll see that you can _cheaply_ use cmpxchg in a ll/sc based implementation. Take an atomic increment operation. do { old = load_locked(addr);

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Ivan Kokshaysky
On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: It might be reasonable to implement this watered down version, but: don't some architectures have restrictions on what instructions can be issued between the ll and the sc? Yes. On Alpha you cannot execute other load/stores, taken

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Russell King
On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: Russell King wrote: On Wed, Dec 06, 2006 at 11:16:55AM -0800, Christoph Lameter wrote: No. If you read what I said, you'll see that you can _cheaply_ use cmpxchg in a ll/sc based implementation. Take an atomic increment

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Russell King
On Wed, Dec 06, 2006 at 11:05:22AM -0800, Linus Torvalds wrote: On Wed, 6 Dec 2006, Christoph Lameter wrote: I'd really appreciate a cmpxchg that is generically available for all arches. It will allow lockless implementation for various performance criticial portions of the kernel.

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Linus Torvalds
On Thu, 7 Dec 2006, Nick Piggin wrote: It might be reasonable to implement this watered down version, but: don't some architectures have restrictions on what instructions can be issued between the ll and the sc? Yes. You really probably do not want to expose ll/sc on a C level because of

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Ralf Baechle
On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: Wrong. Your ll/sc implementation with cmpxchg is buggy. The cmpxchg load_locked is not locked at all, and there can be interleaving writes between the load and cmpxchg which do not cause the store_conditional to fail. It might be

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-07 Thread Nick Piggin
Russell King wrote: On Thu, Dec 07, 2006 at 08:31:08PM +1100, Nick Piggin wrote: Implementing ll/sc based accessor macros allows both ll/sc _and_ cmpxchg architectures to produce optimal code. Implementing an cmpxchg based accessor macro allows cmpxchg architectures to produce optimal code

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Douglas McNaught
Matthew Wilcox <[EMAIL PROTECTED]> writes: > On Wed, Dec 06, 2006 at 05:36:29PM -0800, Linus Torvalds wrote: >> Or are you saying that gcc aligns normal 32-bit entities at >> 16-bit alignment? Neither of those sound very likely. > > alignof(u32) is 2 on m68k. Crazy, huh? The original 68000 had

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Roman Zippel
Hi, On Wed, 6 Dec 2006, Linus Torvalds wrote: > > m68060 produces a trap for unaligned atomic access, unfortunately standard > > alignment is smaller than this. > > Umm. on 68060, since it's 32-bit, you'd only have the 32-bit case. Are you > saying that you can't do a 32-bit atomic access at

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Matthew Wilcox
On Wed, Dec 06, 2006 at 05:36:29PM -0800, Linus Torvalds wrote: > Or are you saying that gcc aligns normal 32-bit entities at > 16-bit alignment? Neither of those sound very likely. alignof(u32) is 2 on m68k. Crazy, huh? - To unsubscribe from this list: send the line "unsubscribe linux-kernel"

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Linus Torvalds
On Thu, 7 Dec 2006, Roman Zippel wrote: > > m68060 produces a trap for unaligned atomic access, unfortunately standard > alignment is smaller than this. Umm. on 68060, since it's 32-bit, you'd only have the 32-bit case. Are you saying that you can't do a 32-bit atomic access at any 32-bit

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Roman Zippel
Hi, On Wed, 6 Dec 2006, Linus Torvalds wrote: > > > Any _real_ CPU will simply never care about _anything_ else than just the > > > size of the datum in question. > > > > ..or alignment which a dedicated atomic type would allow to be attached. > > Can you give any example of a real CPU where

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Linus Torvalds
On Thu, 7 Dec 2006, Roman Zippel wrote: > > > > Any _real_ CPU will simply never care about _anything_ else than just the > > size of the datum in question. > > ..or alignment which a dedicated atomic type would allow to be attached. Can you give any example of a real CPU where alignment

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread David Miller
From: Al Viro <[EMAIL PROTECTED]> Date: Wed, 6 Dec 2006 19:08:28 + > On Wed, Dec 06, 2006 at 11:05:22AM -0800, Linus Torvalds wrote: > > > > > > On Wed, 6 Dec 2006, Christoph Lameter wrote: > > > > > > I'd really appreciate a cmpxchg that is generically available for > > > all arches. It

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Roman Zippel
Hi, On Wed, 6 Dec 2006, Linus Torvalds wrote: > > > To be honest, it'd be much easier if we only defined these operations on > > > atomic_t's. We have all the infrastructure in place for them, and > > > they're fairly well understood. If you need different sizes, I'm OK > > > with an

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Linus Torvalds
On Thu, 7 Dec 2006, Roman Zippel wrote: > On Wed, 6 Dec 2006, Matthew Wilcox wrote: > > > To be honest, it'd be much easier if we only defined these operations on > > atomic_t's. We have all the infrastructure in place for them, and > > they're fairly well understood. If you need different

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Ralf Baechle
On Wed, Dec 06, 2006 at 11:16:55AM -0800, Christoph Lameter wrote: > But then its also just requires disable/enable interrupts on UP which may > be cheaper than an atomic operation. > > > For CPUs with load locked + store conditional, it is expensive. > > Because it locks the bus? I am not

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Roman Zippel
Hi, On Wed, 6 Dec 2006, Matthew Wilcox wrote: > To be honest, it'd be much easier if we only defined these operations on > atomic_t's. We have all the infrastructure in place for them, and > they're fairly well understood. If you need different sizes, I'm OK > with an atomic_pointer_t, or

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Linus Torvalds
On Wed, 6 Dec 2006, Christoph Lameter wrote: > > This means we tolerate the assignment race for SMP that was pointed out > earlier? The assignment "race" doesn't really exist in real code, I suspect. There's two cases of assignment: - pure initialization. This one isn't racy, since it's

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Christoph Lameter
On Wed, 6 Dec 2006, Matthew Wilcox wrote: > To be honest, it'd be much easier if we only defined these operations on > atomic_t's. We have all the infrastructure in place for them, and > they're fairly well understood. If you need different sizes, I'm OK > with an atomic_pointer_t, or whatever.

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Matthew Wilcox
On Wed, Dec 06, 2006 at 01:52:20PM -0800, Christoph Lameter wrote: > On Wed, 6 Dec 2006, Matthew Wilcox wrote: > > > And for those of us with only load-and-zero, that's simply: > > > > #define load_locked(addr) spin_lock(hash(addr)), *addr > > #define store_exclusive(addr, old, new) \ > >

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Christoph Lameter
On Wed, 6 Dec 2006, Matthew Wilcox wrote: > And for those of us with only load-and-zero, that's simply: > > #define load_locked(addr) spin_lock(hash(addr)), *addr > #define store_exclusive(addr, old, new) \ > *addr = new, spin_unlock(hash(addr)), 0 > > which is also

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Matthew Wilcox
On Wed, Dec 06, 2006 at 07:58:20PM +, Russell King wrote: > No. If you read what I said, you'll see that you can _cheaply_ use > cmpxchg in a ll/sc based implementation. Take an atomic increment > operation. > > do { > old = load_locked(addr); > } while

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Matthew Wilcox
On Wed, Dec 06, 2006 at 12:11:01PM -0800, Christoph Lameter wrote: > On Wed, 6 Dec 2006, Matthew Wilcox wrote: > > Follow the thread back. I'm talking about parisc. Machines exist (are > > still being sold) with up to 128 cores. I think the largest we've > > confirmed work are 8 CPUs. > > And

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Lennert Buytenhek
On Wed, Dec 06, 2006 at 07:47:22PM +, David Howells wrote: > > > Pre-v6 ARM doesn't support SMP according to ARM's atomic.h, > > > > That's not quite true, there exist ARMv5 processors that in theory > > can support SMP. > > I meant that the Linux ARM arch doesn't support it: Ah, yes, not

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Christoph Lameter
On Wed, 6 Dec 2006, Matthew Wilcox wrote: > On Wed, Dec 06, 2006 at 11:47:40AM -0800, Christoph Lameter wrote: > > Nope this is a UP implementation. There is no cpu B. > > Follow the thread back. I'm talking about parisc. Machines exist (are > still being sold) with up to 128 cores. I think

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Russell King
On Wed, Dec 06, 2006 at 11:16:55AM -0800, Christoph Lameter wrote: > On Wed, 6 Dec 2006, Russell King wrote: > > > On Wed, Dec 06, 2006 at 10:56:14AM -0800, Christoph Lameter wrote: > > > I'd really appreciate a cmpxchg that is generically available for > > > all arches. It will allow lockless

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Russell King
On Wed, Dec 06, 2006 at 11:05:22AM -0800, Linus Torvalds wrote: > > > On Wed, 6 Dec 2006, Christoph Lameter wrote: > > > > I'd really appreciate a cmpxchg that is generically available for > > all arches. It will allow lockless implementation for various performance > > criticial portions of

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Linus Torvalds
On Wed, 6 Dec 2006, Linus Torvalds wrote: > > Your problem will be, of course, that any architecture that does this in > hardware will just DoTheRightThing, and as such, broken architectures with > bad locking primitives will have to test and do source-level analysis > more. (The underlying

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Matthew Wilcox
On Wed, Dec 06, 2006 at 11:47:40AM -0800, Christoph Lameter wrote: > Nope this is a UP implementation. There is no cpu B. Follow the thread back. I'm talking about parisc. Machines exist (are still being sold) with up to 128 cores. I think the largest we've confirmed work are 8 CPUs. - To

Re: [PATCH] WorkStruct: Implement generic UP cmpxchg() where an arch doesn't support it

2006-12-06 Thread Linus Torvalds
On Wed, 6 Dec 2006, Matthew Wilcox wrote: > > That doesn't help, since assignment can't be guarded by any lock. True. Pure assignment will be lost, and is only ok for the case of a pure initializer (where nobody can see the old state). Your problem will be, of course, that any architecture

  1   2   >