Re: Is gcc thread-unsafe?

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Nick Piggin <nickpiggin@...>
Cc: Linux Kernel Mailing List <linux-kernel@...>, Linus Torvalds <torvalds@...>
Date: Thursday, October 25, 2007 - 7:09 pm

On Friday 26 October 2007 00:49:42 Nick Piggin wrote:

Poor code is better than broken code I would say. Besides
the cross CPU synchronization paths are likely dominated by 
cache misses anyways; it's unlikely they're actually limited
by the core CPU. So it'll probably not matter all that much
if the code is poor or not.

But it's all theoretical for now.


I checked my kernel for "adc" at least (for the trylock/++ pattern) 
and couldn't find any (in fact all of them were in 
data the compiler thought to be code). That was not a allyesconfig build,
so i missed some code. 

For cmov it's at first harder because they're much more frequent
and cmov to memory is a multiple instruction pattern (the instruction
does only support memory source operands). Luckily gcc
doesn't know the if (x) mem = a; => ptr = cmov(x, &a, &dummy); *ptr = a; 
transformation trick so I don't think there are actually any conditional 
stores on current x86. 

It might be a problem on other architectures which support true
conditional stores though (like IA64 or ARM) 

Also I'm not sure if gcc doesn't know any other tricks like the
conditional add using carry, although I cannot think of any related
to stores from the top of my hat.

Anyways, if it's only conditional add if we ever catch such a case
it could be also handled with inline assembly similar to local_inc()

-Andi
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Is gcc thread-unsafe?, Nick Piggin, (Wed Oct 24, 11:24 pm)
Re: Is gcc thread-unsafe?, Phillip Susi, (Wed Oct 31, 6:10 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 10:55 am)
Re: Is gcc thread-unsafe?, Ismail , (Thu Oct 25, 6:26 pm)
Re: Is gcc thread-unsafe?, Jeff Garzik, (Thu Oct 25, 6:56 pm)
Re: Is gcc thread-unsafe?, Jeff Garzik, (Thu Oct 25, 7:04 pm)
RE: Is gcc thread-unsafe?, David Schwartz, (Thu Oct 25, 5:42 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 7:22 pm)
Re: Is gcc thread-unsafe?, Andrew Haley, (Fri Oct 26, 7:59 am)
Re: Is gcc thread-unsafe?, Andrew Haley, (Fri Oct 26, 7:59 am)
Re: Is gcc thread-unsafe?, Chris Friesen, (Fri Oct 26, 1:39 pm)
Re: Is gcc thread-unsafe?, Pekka Enberg, (Thu Oct 25, 11:12 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 3:15 am)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 6:49 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:09 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 7:43 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:55 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 7:57 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 7:14 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:16 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 7:32 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 7:42 pm)
Re: Is gcc thread-unsafe?, Willy Tarreau, (Fri Oct 26, 12:57 am)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 7:57 pm)
Re: Is gcc thread-unsafe?, Zachary Amsden, (Thu Oct 25, 9:15 pm)
Re: Is gcc thread-unsafe?, linux-os (Dick Johnson), (Thu Oct 25, 7:58 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 8:16 am)
Re: Is gcc thread-unsafe?, Arjan van de Ven, (Wed Oct 24, 11:46 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Wed Oct 24, 11:58 pm)
RE: Is gcc thread-unsafe?, David Schwartz, (Thu Oct 25, 12:29 am)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 12:47 am)
Re: Is gcc thread-unsafe?, Samuel Tardieu, (Thu Oct 25, 5:44 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 5:55 am)
Re: Is gcc thread-unsafe?, Arjan van de Ven, (Thu Oct 25, 12:35 am)