lkml.org 
[lkml]   [2007]   [May]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] "volatile considered harmful" document
Jeff Garzik wrote:
> On Sun, May 13, 2007 at 07:26:13PM -0400, Bill Davidsen wrote:
>
>> Krzysztof Halasa wrote:
>>
>>> Robert Hancock <hancockr@shaw.ca> writes:
>>>
>>>> You don't need volatile in that case, rmb() can be used.
>>>>
>
>
>>> rmb() invalidates all compiler assumptions, it can be much slower.
>>>
>
> It does not invalidate /all/ assumptions.
>
>
>
>> Yes, why would you use rmb() when a read of a volatile generates optimal
>> code?
>>
>
> Read of a volatile is guaranteed to generate the least optimal code.
> That's what volatile does, guarantee no optimization of that particular
> access.
>
By optimal you seem to mean "generate fewer CPU cycles by risking use of
an obsolete value," while by the same term I mean read the correct and
current value from the memory location without the overhead of locks. If
your logic doesn't require the correct value, why read it at all? And if
it does, how fewer cycles and cache impact can anything have than a
single register load from memory?

Locks are useful when the value will be changed by a thread, or when the
value must not be changed briefly. That's not always the case.

--
bill davidsen <davidsen@tmr.com>
CTO TMR Associates, Inc
Doing interesting things with small computers since 1979

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-05-14 16:13    [W:0.066 / U:0.228 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site