[lkml]   [2011]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 13/15] x86: add cmpxchg_flag() variant
On 08/23/2011 12:01 PM, Christoph Lameter wrote:
> On Mon, 22 Aug 2011, Jeremy Fitzhardinge wrote:
>> Most callers of cmpxchg() direcly compare RETURN with OLD to see if it was
>> successful. This results in unnecessary conditional comparisons
>> and conditionals since the cmpxchg instruction directly sets the flags
>> to indicate success/failure.
>> Add cmpxchg_flag() variants which return a boolean flag directly indicating
>> success. Unfortunately an asm() statement can't directly export status
>> status flags, but sete isn't too bad.
> And so what happens through this patch is that a cmp with a value that is
> likely in a register is replaced by a sete. Is there really a benefit?

There's definitely a benefit for functions which return a bool resulting
from cmpxchg, which occurs in a few places.

> What I wish we would have is the actual use of the processor flag.
> if (cmpxchg_flags(....)) {
> }
> where the cmpxchg is followed immediately by a jump. I tried in the past
> to pass a goto label to cmpxchg but that did not work.

Yes, that would ideal. The closest you can get is asm goto(), but the
syntax for that would be awful; something like:

#define cmpxchg_jump(ptr, old, new, fail)\
asm goto (...)


old = *thingp;
new = frobulate(old);
cmpxchg_jump(thingp, old, new, again);
/* worked */

Would this be useful enough?

Also, cmpxchg_flag() is limited to arch/x86; I hadn't looked into what
it would take to make it a generic part of the cmpxchg API for the rest
of the kernel.


 \ /
  Last update: 2011-08-23 22:06    [W:0.135 / U:51.676 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site