lkml.org 
[lkml]   [2010]   [Dec]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [cpuops cmpxchg V2 5/5] cpuops: Use cmpxchg for xchg to avoid lock semantics


On Tue, 14 Dec 2010, H. Peter Anvin wrote:

> On 12/14/2010 08:55 AM, Christoph Lameter wrote:
> >
> > We do not need to reload the value as pointed out by Eric. It is already in
> > the correct register so just rerun the cmpxchg without the load.
> >
> > Signed-off-by: Christoph Lameter <cl@linux.com>
> >
>
> Is it genuinely faster to do the pre-load mov, or can we drop that too?
> My guess would be that yes it is, but if it happens not to be it would
> be nice to reduce the code size.

Dropping the load increases the cycle count from 11 to 16.

---
arch/x86/include/asm/percpu.h | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

Index: linux-2.6/arch/x86/include/asm/percpu.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/percpu.h 2010-12-14 11:07:18.000000000 -0600
+++ linux-2.6/arch/x86/include/asm/percpu.h 2010-12-14 11:14:37.000000000 -0600
@@ -223,32 +223,28 @@ do { \
typeof(var) __new = (nval); \
switch (sizeof(var)) { \
case 1: \
- asm("\n1:mov "__percpu_arg(1)",%%al" \
- "\n\tcmpxchgb %2, "__percpu_arg(1) \
+ asm("\n1:cmpxchgb %2, "__percpu_arg(1) \
"\n\tjnz 1b" \
: "=a" (__ret), "+m" (var) \
: "q" (__new) \
: "memory"); \
break; \
case 2: \
- asm("\n1:mov "__percpu_arg(1)",%%ax" \
- "\n\tcmpxchgw %2, "__percpu_arg(1) \
+ asm("\n1:cmpxchgw %2, "__percpu_arg(1) \
"\n\tjnz 1b" \
: "=a" (__ret), "+m" (var) \
: "r" (__new) \
: "memory"); \
break; \
case 4: \
- asm("\n1:mov "__percpu_arg(1)",%%eax" \
- "\n\tcmpxchgl %2, "__percpu_arg(1) \
+ asm("\n1:cmpxchgl %2, "__percpu_arg(1) \
"\n\tjnz 1b" \
: "=a" (__ret), "+m" (var) \
: "r" (__new) \
: "memory"); \
break; \
case 8: \
- asm("\n1:mov "__percpu_arg(1)",%%rax" \
- "\n\tcmpxchgq %2, "__percpu_arg(1) \
+ asm("\n1:cmpxchgq %2, "__percpu_arg(1) \
"\n\tjnz 1b" \
: "=a" (__ret), "+m" (var) \
: "r" (__new) \

\
 
 \ /
  Last update: 2010-12-14 18:21    [W:0.141 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site