public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86 bitops.h commentary on instruction reordering
@ 2004-08-05 20:06 Marcelo Tosatti
  2004-08-06 14:17 ` Vladislav Bolkhovitin
  0 siblings, 1 reply; 19+ messages in thread
From: Marcelo Tosatti @ 2004-08-05 20:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: andrea, akpm

Hi, 

Back when we were discussing the need for a memory barrier in sync_page(), 
it came to me (thanks Andrea!) that the bit operations can be perfectly 
reordered on architectures other than x86. 

I think the commentary on i386 bitops.h is misleading, its worth 
to note that that these operations are not guaranteed not to be 
reordered on different architectures. 

clear_bit() already does that:

 * clear_bit() is atomic and may not be reordered.  However, it does
 * not contain a memory barrier, so if it is used for locking purposes,
 * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
 * in order to ensure changes are visible on other processors.

What you think of the following


--- a/include/asm-i386/bitops.h.orig	2004-08-05 17:35:40.639336160 -0300
+++ b/include/asm-i386/bitops.h	2004-08-05 17:35:12.486616024 -0300
@@ -30,7 +30,12 @@
  * @addr: the address to start counting from
  *
  * This function is atomic and may not be reordered.  See __set_bit()
- * if you do not require the atomic guarantees.
+ * if you do not require the atomic guarantees. 
+ * 
+ * Note: there are no guarantees that this function will not be reordered 
+ * on non x86 architectures, so if you are writting portable code, 
+ * make sure not to rely on its reordering guarantees.
+ * 
  * Note that @nr may be almost arbitrarily large; this function is not
  * restricted to acting on a single-word quantity.
  */
@@ -109,7 +114,8 @@ static inline void __change_bit(int nr, 
  * @nr: Bit to change
  * @addr: Address to start counting from
  *
- * change_bit() is atomic and may not be reordered.
+ * change_bit() is atomic and may not be reordered. It may be
+ * reordered on other architectures than x86.
  * Note that @nr may be almost arbitrarily large; this function is not
  * restricted to acting on a single-word quantity.
  */
@@ -127,6 +133,7 @@ static inline void change_bit(int nr, vo
  * @addr: Address to count from
  *
  * This operation is atomic and cannot be reordered.  
+ * It may be reordered on other architectures than x86.
  * It also implies a memory barrier.
  */
 static inline int test_and_set_bit(int nr, volatile unsigned long * addr)
@@ -165,7 +172,8 @@ static inline int __test_and_set_bit(int
  * @nr: Bit to clear
  * @addr: Address to count from
  *
- * This operation is atomic and cannot be reordered.  
+ * This operation is atomic and cannot be reordered. 
+ * It can be reorderdered on other architectures other than x86.
  * It also implies a memory barrier.
  */
 static inline int test_and_clear_bit(int nr, volatile unsigned long * addr)

^ permalink raw reply	[flat|nested] 19+ messages in thread
[parent not found: <2pY7Y-W1-7@gated-at.bofh.it>]

end of thread, other threads:[~2004-08-10 12:31 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-05 20:06 [PATCH] x86 bitops.h commentary on instruction reordering Marcelo Tosatti
2004-08-06 14:17 ` Vladislav Bolkhovitin
2004-08-06 14:33   ` Marcelo Tosatti
2004-08-06 15:36     ` Vladislav Bolkhovitin
2004-08-06 15:53       ` Marcelo Tosatti
2004-08-06 16:52         ` Vladislav Bolkhovitin
2004-08-06 17:09           ` Marcelo Tosatti
2004-08-06 22:33             ` H. Peter Anvin
2004-08-07  1:01               ` Zwane Mwaikambo
2004-08-07 22:16               ` Alan Cox
2004-08-09 15:14             ` Vladislav Bolkhovitin
2004-08-09 15:50               ` Marcelo Tosatti
2004-08-09 17:35                 ` Vladislav Bolkhovitin
     [not found]                   ` <20040809183437.GD6361@logos.cnet>
2004-08-09 20:12                     ` Vladislav Bolkhovitin
2004-08-09 21:21                       ` Alan Cox
2004-08-10 12:28                         ` Vladislav Bolkhovitin
2004-08-09 11:58         ` Maciej W. Rozycki
     [not found] <2pY7Y-W1-7@gated-at.bofh.it>
     [not found] ` <2qdJL-3sh-27@gated-at.bofh.it>
     [not found]   ` <2qePx-4eM-21@gated-at.bofh.it>
     [not found]     ` <2qf8S-4pI-31@gated-at.bofh.it>
     [not found]       ` <2qg4V-54c-17@gated-at.bofh.it>
     [not found]         ` <2qgoh-5og-29@gated-at.bofh.it>
     [not found]           ` <2qhkn-649-41@gated-at.bofh.it>
     [not found]             ` <2rkgh-zP-45@gated-at.bofh.it>
     [not found]               ` <2rlFk-1wC-27@gated-at.bofh.it>
     [not found]                 ` <2rmhX-20I-17@gated-at.bofh.it>
     [not found]                   ` <2roWw-40d-19@gated-at.bofh.it>
     [not found]                     ` <2roWw-40d-17@gated-at.bofh.it>
2004-08-09 21:23                       ` Andi Kleen
2004-08-10 12:26                         ` Vladislav Bolkhovitin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox