From: "Jan Beulich" Subject: =?utf-8?q?=5BPATCH_v3_1/2=5D_x86=3A_simplify_non?= =?utf-8?q?=E2=80=91atomic_bitops?= Date: Fri, 20 Mar 2015 14:53:29 +0000 Message-ID: <550C4279020000780006C16B@mail.emea.novell.com> References: <550C4120020000780006C14E@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part7C482879.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYyIl-0001Ab-6a for xen-devel@lists.xenproject.org; Fri, 20 Mar 2015 14:53:31 +0000 In-Reply-To: <550C4120020000780006C14E@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part7C482879.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline - being non-atomic, their pointer arguments shouldn't be volatile- qualified - their (half fake) memory operands can be a single "+m" instead of being both an output and an input Signed-off-by: Jan Beulich --- v3: Replace ADDR uses by *(int *)addr to not re-gain the volatile qualifier. v2: Drop "+m" related sentence from comment at the top of the file as being wrong (the referenced indication in gcc's documentation got removed quite some time ago too). --- a/xen/include/asm-x86/bitops.h +++ b/xen/include/asm-x86/bitops.h @@ -14,8 +14,7 @@ * operand is both read from and written to. Since the operand is in fact = a * word array, we also specify "memory" in the clobbers list to indicate = that * words other than the one directly addressed by the memory operand may = be - * modified. We don't use "+m" because the gcc manual says that it should = be - * used only when the constraint allows the operand to reside in a = register. + * modified. */ =20 #define ADDR (*(volatile long *) addr) @@ -55,12 +54,9 @@ static inline void set_bit(int nr, volat * If it's called on the same region of memory simultaneously, the effect * may be that only one operation succeeds. */ -static inline void __set_bit(int nr, volatile void *addr) +static inline void __set_bit(int nr, void *addr) { - asm volatile ( - "btsl %1,%0" - : "=3Dm" (ADDR) - : "Ir" (nr), "m" (ADDR) : "memory"); + asm volatile ( "btsl %1,%0" : "+m" (*(int *)addr) : "Ir" (nr) : = "memory" ); } #define __set_bit(nr, addr) ({ \ if ( bitop_bad_size(addr) ) __bitop_bad_size(); \ @@ -95,12 +91,9 @@ static inline void clear_bit(int nr, vol * If it's called on the same region of memory simultaneously, the effect * may be that only one operation succeeds. */ -static inline void __clear_bit(int nr, volatile void *addr) +static inline void __clear_bit(int nr, void *addr) { - asm volatile ( - "btrl %1,%0" - : "=3Dm" (ADDR) - : "Ir" (nr), "m" (ADDR) : "memory"); + asm volatile ( "btrl %1,%0" : "+m" (*(int *)addr) : "Ir" (nr) : = "memory" ); } #define __clear_bit(nr, addr) ({ \ if ( bitop_bad_size(addr) ) __bitop_bad_size(); \ @@ -116,12 +109,9 @@ static inline void __clear_bit(int nr, v * If it's called on the same region of memory simultaneously, the effect * may be that only one operation succeeds. */ -static inline void __change_bit(int nr, volatile void *addr) +static inline void __change_bit(int nr, void *addr) { - asm volatile ( - "btcl %1,%0" - : "=3Dm" (ADDR) - : "Ir" (nr), "m" (ADDR) : "memory"); + asm volatile ( "btcl %1,%0" : "+m" (*(int *)addr) : "Ir" (nr) : = "memory" ); } #define __change_bit(nr, addr) ({ \ if ( bitop_bad_size(addr) ) __bitop_bad_size(); \ @@ -181,14 +171,14 @@ static inline int test_and_set_bit(int n * If two examples of this operation race, one can appear to succeed * but actually fail. You must protect multiple accesses with a lock. */ -static inline int __test_and_set_bit(int nr, volatile void *addr) +static inline int __test_and_set_bit(int nr, void *addr) { int oldbit; =20 asm volatile ( "btsl %2,%1\n\tsbbl %0,%0" - : "=3Dr" (oldbit), "=3Dm" (ADDR) - : "Ir" (nr), "m" (ADDR) : "memory"); + : "=3Dr" (oldbit), "+m" (*(int *)addr) + : "Ir" (nr) : "memory" ); return oldbit; } #define __test_and_set_bit(nr, addr) ({ \ @@ -228,14 +218,14 @@ static inline int test_and_clear_bit(int * If two examples of this operation race, one can appear to succeed * but actually fail. You must protect multiple accesses with a lock. */ -static inline int __test_and_clear_bit(int nr, volatile void *addr) +static inline int __test_and_clear_bit(int nr, void *addr) { int oldbit; =20 asm volatile ( "btrl %2,%1\n\tsbbl %0,%0" - : "=3Dr" (oldbit), "=3Dm" (ADDR) - : "Ir" (nr), "m" (ADDR) : "memory"); + : "=3Dr" (oldbit), "+m" (*(int *)addr) + : "Ir" (nr) : "memory" ); return oldbit; } #define __test_and_clear_bit(nr, addr) ({ \ @@ -244,14 +234,14 @@ static inline int __test_and_clear_bit(i }) =20 /* WARNING: non atomic and it can be reordered! */ -static inline int __test_and_change_bit(int nr, volatile void *addr) +static inline int __test_and_change_bit(int nr, void *addr) { int oldbit; =20 asm volatile ( "btcl %2,%1\n\tsbbl %0,%0" - : "=3Dr" (oldbit), "=3Dm" (ADDR) - : "Ir" (nr), "m" (ADDR) : "memory"); + : "=3Dr" (oldbit), "+m" (*(int *)addr) + : "Ir" (nr) : "memory" ); return oldbit; } #define __test_and_change_bit(nr, addr) ({ \ --=__Part7C482879.1__= Content-Type: text/plain; name="x86-non-atomic-bitops.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-non-atomic-bitops.patch" x86: simplify non-atomic bitops=0A=0A- being non-atomic, their pointer = arguments shouldn't be volatile-=0A qualified=0A- their (half fake) = memory operands can be a single "+m" instead of=0A being both an output = and an input=0A=0ASigned-off-by: Jan Beulich =0A---=0Av3= : Replace ADDR uses by *(int *)addr to not re-gain the volatile=0A = qualifier.=0Av2: Drop "+m" related sentence from comment at the top of the = file as=0A being wrong (the referenced indication in gcc's documentation= got=0A removed quite some time ago too).=0A=0A--- a/xen/include/asm-x86= /bitops.h=0A+++ b/xen/include/asm-x86/bitops.h=0A@@ -14,8 +14,7 @@=0A * = operand is both read from and written to. Since the operand is in fact = a=0A * word array, we also specify "memory" in the clobbers list to = indicate that=0A * words other than the one directly addressed by the = memory operand may be=0A- * modified. We don't use "+m" because the gcc = manual says that it should be=0A- * used only when the constraint allows = the operand to reside in a register.=0A+ * modified.=0A */=0A =0A #define = ADDR (*(volatile long *) addr)=0A@@ -55,12 +54,9 @@ static inline void = set_bit(int nr, volat=0A * If it's called on the same region of memory = simultaneously, the effect=0A * may be that only one operation = succeeds.=0A */=0A-static inline void __set_bit(int nr, volatile void = *addr)=0A+static inline void __set_bit(int nr, void *addr)=0A {=0A- asm = volatile (=0A- "btsl %1,%0"=0A- : "=3Dm" (ADDR)=0A- : = "Ir" (nr), "m" (ADDR) : "memory");=0A+ asm volatile ( "btsl %1,%0" : = "+m" (*(int *)addr) : "Ir" (nr) : "memory" );=0A }=0A #define __set_bit(nr,= addr) ({ \=0A if ( bitop_bad_size(addr) ) = __bitop_bad_size(); \=0A@@ -95,12 +91,9 @@ static inline void = clear_bit(int nr, vol=0A * If it's called on the same region of memory = simultaneously, the effect=0A * may be that only one operation = succeeds.=0A */=0A-static inline void __clear_bit(int nr, volatile void = *addr)=0A+static inline void __clear_bit(int nr, void *addr)=0A {=0A- = asm volatile (=0A- "btrl %1,%0"=0A- : "=3Dm" (ADDR)=0A- = : "Ir" (nr), "m" (ADDR) : "memory");=0A+ asm volatile ( "btrl %1,%0" = : "+m" (*(int *)addr) : "Ir" (nr) : "memory" );=0A }=0A #define __clear_bit= (nr, addr) ({ \=0A if ( bitop_bad_size(addr) ) = __bitop_bad_size(); \=0A@@ -116,12 +109,9 @@ static inline void = __clear_bit(int nr, v=0A * If it's called on the same region of memory = simultaneously, the effect=0A * may be that only one operation = succeeds.=0A */=0A-static inline void __change_bit(int nr, volatile void = *addr)=0A+static inline void __change_bit(int nr, void *addr)=0A {=0A- = asm volatile (=0A- "btcl %1,%0"=0A- : "=3Dm" (ADDR)=0A- = : "Ir" (nr), "m" (ADDR) : "memory");=0A+ asm volatile ( "btcl %1,%0" = : "+m" (*(int *)addr) : "Ir" (nr) : "memory" );=0A }=0A #define __change_bi= t(nr, addr) ({ \=0A if ( bitop_bad_size(addr) ) = __bitop_bad_size(); \=0A@@ -181,14 +171,14 @@ static inline int = test_and_set_bit(int n=0A * If two examples of this operation race, one = can appear to succeed=0A * but actually fail. You must protect multiple = accesses with a lock.=0A */=0A-static inline int __test_and_set_bit(int = nr, volatile void *addr)=0A+static inline int __test_and_set_bit(int nr, = void *addr)=0A {=0A int oldbit;=0A =0A asm volatile (=0A = "btsl %2,%1\n\tsbbl %0,%0"=0A- : "=3Dr" (oldbit), "=3Dm" (ADDR)=0A- = : "Ir" (nr), "m" (ADDR) : "memory");=0A+ : "=3Dr" (oldbit), = "+m" (*(int *)addr)=0A+ : "Ir" (nr) : "memory" );=0A return = oldbit;=0A }=0A #define __test_and_set_bit(nr, addr) ({ = \=0A@@ -228,14 +218,14 @@ static inline int test_and_clear_bit(int=0A * = If two examples of this operation race, one can appear to succeed=0A * = but actually fail. You must protect multiple accesses with a lock.=0A = */=0A-static inline int __test_and_clear_bit(int nr, volatile void = *addr)=0A+static inline int __test_and_clear_bit(int nr, void *addr)=0A = {=0A int oldbit;=0A =0A asm volatile (=0A "btrl %2,%1\n\tsb= bl %0,%0"=0A- : "=3Dr" (oldbit), "=3Dm" (ADDR)=0A- : "Ir" = (nr), "m" (ADDR) : "memory");=0A+ : "=3Dr" (oldbit), "+m" (*(int = *)addr)=0A+ : "Ir" (nr) : "memory" );=0A return oldbit;=0A }=0A = #define __test_and_clear_bit(nr, addr) ({ \=0A@@ -244,14 = +234,14 @@ static inline int __test_and_clear_bit(i=0A })=0A =0A /* = WARNING: non atomic and it can be reordered! */=0A-static inline int = __test_and_change_bit(int nr, volatile void *addr)=0A+static inline int = __test_and_change_bit(int nr, void *addr)=0A {=0A int oldbit;=0A =0A = asm volatile (=0A "btcl %2,%1\n\tsbbl %0,%0"=0A- : "=3Dr" = (oldbit), "=3Dm" (ADDR)=0A- : "Ir" (nr), "m" (ADDR) : "memory");=0A+= : "=3Dr" (oldbit), "+m" (*(int *)addr)=0A+ : "Ir" (nr) : = "memory" );=0A return oldbit;=0A }=0A #define __test_and_change_bit(nr,= addr) ({ \=0A --=__Part7C482879.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part7C482879.1__=--