Skip to contentSkip to conversation

bitops: add generic implementation of ext2 atomic bitops by test_and_{set,clear}_bit

PATCH In review Akinobu Mita 6 participants 13 messages Oct 8, 2010 – Oct 12, 2010

Subsystems (15)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 bitops: add generic implementation of ext2 atomic bitops by test_and_{set,clear}_bit

This introduces asm-generic header file for generic implementation of ext2 atomic bit operations by test_and_set_bit() and test_and_clear_bit().

alpha, arm, cris, frv, ia64, m68k, mn10300, parisc, powerpc, s390, sparc64, x86, xtensa can use this header file in its asm/bitops.h.

---
 arch/alpha/include/asm/bitops.h               |    4 +--
 arch/arm/include/asm/bitops.h                 |    6 +---
 arch/cris/include/asm/bitops.h                |    4 +--
 arch/frv/include/asm/bitops.h                 |    4 +--
 arch/ia64/include/asm/bitops.h                |    4 +--
 arch/m68k/include/asm/bitops_mm.h             |    4 +-
 arch/mn10300/include/asm/bitops.h             |    6 +----
 arch/parisc/include/asm/bitops.h              |    9 +-------
 arch/powerpc/include/asm/bitops.h             |    8 ++----
 arch/s390/include/asm/bitops.h                |    6 +---
 arch/sparc/include/asm/bitops_64.h            |    6 +----
 arch/x86/include/asm/bitops.h                 |    6 +----
 arch/xtensa/include/asm/bitops.h              |   15 +-------------
 include/asm-generic/bitops/ext2-atomic-test.h |   26 +++++++++++++++++++++++++
 include/asm-generic/bitops/ext2-atomic.h      |    4 +++
 15 files changed, 48 insertions(+), 64 deletions(-)
 create mode 100644 include/asm-generic/bitops/ext2-atomic-test.h
arch/alpha/include/asm/bitops.h +1 -3
index adfab8a..778468b 100644
@@ -455,9 +455,7 @@ sched_find_first_bit(const unsigned long b[2])
 }
 
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-#define ext2_set_bit_atomic(l,n,a)   test_and_set_bit(n,a)
-#define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a)
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #include <asm-generic/bitops/minix.h>
 
arch/arm/include/asm/bitops.h +2 -4
index 338ff19..f98b8c8 100644
@@ -309,12 +309,8 @@ static inline int fls(int x)
  */
 #define ext2_set_bit(nr,p)			\
 		__test_and_set_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
-#define ext2_set_bit_atomic(lock,nr,p)          \
-                test_and_set_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define ext2_clear_bit(nr,p)			\
 		__test_and_clear_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
-#define ext2_clear_bit_atomic(lock,nr,p)        \
-                test_and_clear_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define ext2_test_bit(nr,p)			\
 		test_bit(WORD_BITOFF_TO_LE(nr), (unsigned long *)(p))
 #define ext2_find_first_zero_bit(p,sz)		\
@@ -324,6 +320,8 @@ static inline int fls(int x)
 #define ext2_find_next_bit(p, sz, off) \
 		_find_next_bit_le(p, sz, off)
 
+#include <asm-generic/bitops/ext2-atomic-test.h>
+
 /*
  * Minix is defined to use little-endian byte ordering.
  * These do not need to be atomic.
arch/cris/include/asm/bitops.h +1 -3
index 9e69cfb..e1f77fc 100644
@@ -155,9 +155,7 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
 #include <asm-generic/bitops/lock.h>
 
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-#define ext2_set_bit_atomic(l,n,a)   test_and_set_bit(n,a)
-#define ext2_clear_bit_atomic(l,n,a) test_and_clear_bit(n,a)
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #include <asm-generic/bitops/minix.h>
 #include <asm-generic/bitops/sched.h>
arch/frv/include/asm/bitops.h +1 -3
index 50ae91b..0d718ce 100644
@@ -402,9 +402,7 @@ int __ilog2_u64(u64 n)
 #include <asm-generic/bitops/lock.h>
 
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-#define ext2_set_bit_atomic(lock,nr,addr)	test_and_set_bit  ((nr) ^ 0x18, (addr))
-#define ext2_clear_bit_atomic(lock,nr,addr)	test_and_clear_bit((nr) ^ 0x18, (addr))
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #include <asm-generic/bitops/minix-le.h>
 
arch/ia64/include/asm/bitops.h +1 -3
index 9da3df6..22ba18b 100644
@@ -457,9 +457,7 @@ static __inline__ unsigned long __arch_hweight64(unsigned long x)
 #ifdef __KERNEL__
 
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-#define ext2_set_bit_atomic(l,n,a)	test_and_set_bit(n,a)
-#define ext2_clear_bit_atomic(l,n,a)	test_and_clear_bit(n,a)
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #include <asm-generic/bitops/minix.h>
 #include <asm-generic/bitops/sched.h>
arch/m68k/include/asm/bitops_mm.h +2 -2
index b4ecdaa..776d7b3 100644
@@ -362,9 +362,7 @@ static inline int minix_test_bit(int nr, const void *vaddr)
 /* Bitmap functions for the ext2 filesystem. */
 
 #define ext2_set_bit(nr, addr)			__test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
-#define ext2_set_bit_atomic(lock, nr, addr)	test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
 #define ext2_clear_bit(nr, addr)		__test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
-#define ext2_clear_bit_atomic(lock, nr, addr)	test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
 #define ext2_find_next_zero_bit(addr, size, offset) \
 	generic_find_next_zero_le_bit((unsigned long *)addr, size, offset)
 #define ext2_find_next_bit(addr, size, offset) \
@@ -461,6 +459,8 @@ static inline unsigned long generic_find_next_le_bit(const unsigned long *addr,
 	return (p - addr) * 32 + res;
 }
 
+#include <asm-generic/bitops/ext2-atomic-test.h>
+
 #endif /* __KERNEL__ */
 
 #endif /* _M68K_BITOPS_H */
arch/mn10300/include/asm/bitops.h +1 -5
index 3f50e96..23e3a5a 100644
@@ -228,11 +228,7 @@ int ffs(int x)
 #include <asm-generic/bitops/sched.h>
 #include <asm-generic/bitops/hweight.h>
 
-#define ext2_set_bit_atomic(lock, nr, addr) \
-	test_and_set_bit((nr), (addr))
-#define ext2_clear_bit_atomic(lock, nr, addr) \
-	test_and_clear_bit((nr), (addr))
-
+#include <asm-generic/bitops/ext2-atomic-test.h>
 #include <asm-generic/bitops/ext2-non-atomic.h>
 #include <asm-generic/bitops/minix-le.h>
 
arch/parisc/include/asm/bitops.h +1 -8
index 7a6ea10..2bd003d 100644
@@ -223,14 +223,7 @@ static __inline__ int fls(int x)
 #ifdef __KERNEL__
 
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-/* '3' is bits per byte */
-#define LE_BYTE_ADDR ((sizeof(unsigned long) - 1) << 3)
-
-#define ext2_set_bit_atomic(l,nr,addr) \
-		test_and_set_bit((nr)   ^ LE_BYTE_ADDR, (unsigned long *)addr)
-#define ext2_clear_bit_atomic(l,nr,addr) \
-		test_and_clear_bit( (nr) ^ LE_BYTE_ADDR, (unsigned long *)addr)
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #endif	/* __KERNEL__ */
 
arch/powerpc/include/asm/bitops.h +3 -5
index 30964ae..d8dba27 100644
@@ -307,11 +307,6 @@ unsigned long generic_find_next_le_bit(const unsigned long *addr,
 #define ext2_clear_bit(nr, addr) \
 	__test_and_clear_le_bit((nr), (unsigned long*)addr)
 
-#define ext2_set_bit_atomic(lock, nr, addr) \
-	test_and_set_le_bit((nr), (unsigned long*)addr)
-#define ext2_clear_bit_atomic(lock, nr, addr) \
-	test_and_clear_le_bit((nr), (unsigned long*)addr)
-
 #define ext2_test_bit(nr, addr)      test_le_bit((nr),(unsigned long*)addr)
 
 #define ext2_find_first_zero_bit(addr, size) \
@@ -321,6 +316,9 @@ unsigned long generic_find_next_le_bit(const unsigned long *addr,
 
 #define ext2_find_next_bit(addr, size, off) \
 	generic_find_next_le_bit((unsigned long *)addr, size, off)
+
+#include <asm-generic/bitops/ext2-atomic-test.h>
+
 /* Bitmap functions for the minix filesystem.  */
 
 #define minix_test_and_set_bit(nr,addr) \
arch/s390/include/asm/bitops.h +2 -4
index 2e05972..052b4fb 100644
@@ -744,12 +744,8 @@ static inline int sched_find_first_bit(unsigned long *b)
 
 #define ext2_set_bit(nr, addr)       \
 	__test_and_set_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
-#define ext2_set_bit_atomic(lock, nr, addr)       \
-	test_and_set_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
 #define ext2_clear_bit(nr, addr)     \
 	__test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
-#define ext2_clear_bit_atomic(lock, nr, addr)     \
-	test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
 #define ext2_test_bit(nr, addr)      \
 	test_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)
 
@@ -834,6 +830,8 @@ static inline int ext2_find_next_bit(void *vaddr, unsigned long size,
 	return offset + ext2_find_first_bit(p, size);
 }
 
+#include <asm-generic/bitops/ext2-atomic-test.h>
+
 #include <asm-generic/bitops/minix.h>
 
 #endif /* __KERNEL__ */
arch/sparc/include/asm/bitops_64.h +1 -5
index 766121a..fd12692 100644
@@ -90,11 +90,7 @@ static inline unsigned int __arch_hweight8(unsigned int w)
 #ifdef __KERNEL__
 
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-#define ext2_set_bit_atomic(lock,nr,addr) \
-	test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
-#define ext2_clear_bit_atomic(lock,nr,addr) \
-	test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #include <asm-generic/bitops/minix.h>
 
arch/x86/include/asm/bitops.h +1 -5
index 903683b..601f4c4 100644
@@ -457,11 +457,7 @@ static inline int fls(int x)
 #ifdef __KERNEL__
 
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-#define ext2_set_bit_atomic(lock, nr, addr)			\
-	test_and_set_bit((nr), (unsigned long *)(addr))
-#define ext2_clear_bit_atomic(lock, nr, addr)			\
-	test_and_clear_bit((nr), (unsigned long *)(addr))
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #include <asm-generic/bitops/minix.h>
 
arch/xtensa/include/asm/bitops.h +1 -14
index 6c39303..1aa0a5c 100644
@@ -107,20 +107,7 @@ static inline unsigned long __fls(unsigned long word)
 #include <asm-generic/bitops/fls64.h>
 #include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/ext2-non-atomic.h>
-
-#ifdef __XTENSA_EL__
-# define ext2_set_bit_atomic(lock,nr,addr)				\
-	test_and_set_bit((nr), (unsigned long*)(addr))
-# define ext2_clear_bit_atomic(lock,nr,addr)				\
-	test_and_clear_bit((nr), (unsigned long*)(addr))
-#elif defined(__XTENSA_EB__)
-# define ext2_set_bit_atomic(lock,nr,addr)				\
-	test_and_set_bit((nr) ^ 0x18, (unsigned long*)(addr))
-# define ext2_clear_bit_atomic(lock,nr,addr)				\
-	test_and_clear_bit((nr) ^ 0x18, (unsigned long*)(addr))
-#else
-# error processor byte order undefined!
-#endif
+#include <asm-generic/bitops/ext2-atomic-test.h>
 
 #include <asm-generic/bitops/hweight.h>
 #include <asm-generic/bitops/lock.h>
include/asm-generic/bitops/ext2-atomic-test.h new file +26 -0
new file mode 100644
index 0000000..ece193a
@@ -0,0 +1,26 @@
+#ifndef _ASM_GENERIC_BITOPS_EXT2_ATOMIC_TEST_H_
+#define _ASM_GENERIC_BITOPS_EXT2_ATOMIC_TEST_H_
+
+/*
+ * Generic implementation of ext2 atomic bit operations
+ * by test_and_set_bit() and test_and_clear_bit()
+ */
+
+#include <asm/byteorder.h>
+
+#if defined(__LITTLE_ENDIAN)
+#define LE_BYTE_ADDR 0
+#elif defined(__BIG_ENDIAN)
+/* '3' is bits per byte */
+#define LE_BYTE_ADDR ((sizeof(unsigned long) - 1) << 3)
+#else
+#error processor byte order undefined!
+#endif
+
+#define ext2_set_bit_atomic(l, nr, addr) \
+	test_and_set_bit((nr) ^ LE_BYTE_ADDR, (unsigned long *)(addr))
+
+#define ext2_clear_bit_atomic(l, nr, addr) \
+	test_and_clear_bit((nr) ^ LE_BYTE_ADDR, (unsigned long *)(addr))
+
+#endif /* _ASM_GENERIC_BITOPS_EXT2_ATOMIC_TEST_H_ */
include/asm-generic/bitops/ext2-atomic.h +4 -0
index ab1c875..151219f 100644
@@ -1,6 +1,10 @@
 #ifndef _ASM_GENERIC_BITOPS_EXT2_ATOMIC_H_
 #define _ASM_GENERIC_BITOPS_EXT2_ATOMIC_H_
 
+/*
+ * Generic implementation of ext2 atomic bit operations by spinlock
+ */
+
 #define ext2_set_bit_atomic(lock, nr, addr)		\
 	({						\
 		int ret;				\
Signature · 1 line
1.7.1.231.gd0b16
#1 lore raw

PATCH 2/5 bitops: cleanup asm-generic/bitops/le.h

- Remove unused BITOP_WORD macro
- Merge definisions for big endian and little endian as much as possible

---
 include/asm-generic/bitops/le.h |   38 +++++++++++++++-----------------------
 1 files changed, 15 insertions(+), 23 deletions(-)
include/asm-generic/bitops/le.h +15 -23
index 80e3bf1..db2be81 100644
@@ -4,27 +4,28 @@
 #include <asm/types.h>
 #include <asm/byteorder.h>
 
-#define BITOP_WORD(nr)		((nr) / BITS_PER_LONG)
-#define BITOP_LE_SWIZZLE	((BITS_PER_LONG-1) & ~0x7)
-
 #if defined(__LITTLE_ENDIAN)
 
-#define generic_test_le_bit(nr, addr) test_bit(nr, addr)
-#define generic___set_le_bit(nr, addr) __set_bit(nr, addr)
-#define generic___clear_le_bit(nr, addr) __clear_bit(nr, addr)
-
-#define generic_test_and_set_le_bit(nr, addr) test_and_set_bit(nr, addr)
-#define generic_test_and_clear_le_bit(nr, addr) test_and_clear_bit(nr, addr)
+#define BITOP_LE_SWIZZLE	0
 
-#define generic___test_and_set_le_bit(nr, addr) __test_and_set_bit(nr, addr)
-#define generic___test_and_clear_le_bit(nr, addr) __test_and_clear_bit(nr, addr)
-
-#define generic_find_next_zero_le_bit(addr, size, offset) find_next_zero_bit(addr, size, offset)
+#define generic_find_next_zero_le_bit(addr, size, offset) \
+	find_next_zero_bit(addr, size, offset)
 #define generic_find_next_le_bit(addr, size, offset) \
-			find_next_bit(addr, size, offset)
+	find_next_bit(addr, size, offset)
 
 #elif defined(__BIG_ENDIAN)
 
+#define BITOP_LE_SWIZZLE	((BITS_PER_LONG-1) & ~0x7)
+
+extern unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,
+		unsigned long size, unsigned long offset);
+extern unsigned long generic_find_next_le_bit(const unsigned long *addr,
+		unsigned long size, unsigned long offset);
+
+#else
+#error "Please fix <asm/byteorder.h>"
+#endif
+
 #define generic_test_le_bit(nr, addr) \
 	test_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
 #define generic___set_le_bit(nr, addr) \
@@ -42,15 +43,6 @@
 #define generic___test_and_clear_le_bit(nr, addr) \
 	__test_and_clear_bit((nr) ^ BITOP_LE_SWIZZLE, (addr))
 
-extern unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,
-		unsigned long size, unsigned long offset);
-extern unsigned long generic_find_next_le_bit(const unsigned long *addr,
-		unsigned long size, unsigned long offset);
-
-#else
-#error "Please fix <asm/byteorder.h>"
-#endif
-
 #define generic_find_first_zero_le_bit(addr, size) \
         generic_find_next_zero_le_bit((addr), (size), 0)
 
Signature · 1 line
1.7.1.231.gd0b16
#2 lore raw

PATCH 3/5 kvm: stop including asm-generic/bitops/le.h directly

In reply to Akinobu Mita

asm-generic/bitops/le.h is only intended to be included directly from asm-generic/bitops/ext2-non-atomic.h or asm-generic/bitops/minix-le.h which implements generic ext2 or minix bit operations.

This stops including asm-generic/bitops/le.h directly and use ext2 non-atomic bit operations instead.

An alternative approach is introducing little endian bit operations in linux/bitops.h. But it needs to touch more files than this change does.

---
 virt/kvm/kvm_main.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
virt/kvm/kvm_main.c +1 -2
index 5186e72..780b71d 100644
@@ -52,7 +52,6 @@
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
-#include <asm-generic/bitops/le.h>
 
 #include "coalesced_mmio.h"
 
@@ -1208,7 +1207,7 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
 	if (memslot && memslot->dirty_bitmap) {
 		unsigned long rel_gfn = gfn - memslot->base_gfn;
 
-		generic___set_le_bit(rel_gfn, memslot->dirty_bitmap);
+		ext2_set_bit(rel_gfn, memslot->dirty_bitmap);
 	}
 }
 
Signature · 1 line
1.7.1.231.gd0b16
#3 lore raw

Re: [PATCH 3/5] kvm: stop including asm-generic/bitops/le.h directly

Quoted 9 lines · Akinobu Mita

asm-generic/bitops/le.h is only intended to be included directly from asm-generic/bitops/ext2-non-atomic.h or asm-generic/bitops/minix-le.h which implements generic ext2 or minix bit operations.

This stops including asm-generic/bitops/le.h directly and use ext2 non-atomic bit operations instead.

An alternative approach is introducing little endian bit operations in linux/bitops.h. But it needs to touch more files than this change does.

That's properly a better idea, given the fact that ext2_set_bit doesn't really say too much to the reader :).

Alex

#4 lore raw

PATCH 4/5 rds: stop including asm-generic/bitops/le.h directly

In reply to Akinobu Mita

asm-generic/bitops/le.h is only intended to be included directly from asm-generic/bitops/ext2-non-atomic.h or asm-generic/bitops/minix-le.h which implements generic ext2 or minix bit operations.

This stops including asm-generic/bitops/le.h directly and use ext2 non-atomic bit operations instead.

An alternative approach is introducing little endian bit operations in linux/bitops.h. But it needs to touch more files than this change does.

---
 net/rds/cong.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
net/rds/cong.c +4 -5
index 0871a29..5bd0f36 100644
@@ -33,8 +33,7 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/rbtree.h>
-
-#include <asm-generic/bitops/le.h>
+#include <linux/bitops.h>
 
 #include "rds.h"
 
@@ -285,7 +284,7 @@ void rds_cong_set_bit(struct rds_cong_map *map, __be16 port)
 	i = be16_to_cpu(port) / RDS_CONG_MAP_PAGE_BITS;
 	off = be16_to_cpu(port) % RDS_CONG_MAP_PAGE_BITS;
 
-	generic___set_le_bit(off, (void *)map->m_page_addrs[i]);
+	ext2_set_bit(off, (void *)map->m_page_addrs[i]);
 }
 
 void rds_cong_clear_bit(struct rds_cong_map *map, __be16 port)
@@ -299,7 +298,7 @@ void rds_cong_clear_bit(struct rds_cong_map *map, __be16 port)
 	i = be16_to_cpu(port) / RDS_CONG_MAP_PAGE_BITS;
 	off = be16_to_cpu(port) % RDS_CONG_MAP_PAGE_BITS;
 
-	generic___clear_le_bit(off, (void *)map->m_page_addrs[i]);
+	ext2_clear_bit(off, (void *)map->m_page_addrs[i]);
 }
 
 static int rds_cong_test_bit(struct rds_cong_map *map, __be16 port)
@@ -310,7 +309,7 @@ static int rds_cong_test_bit(struct rds_cong_map *map, __be16 port)
 	i = be16_to_cpu(port) / RDS_CONG_MAP_PAGE_BITS;
 	off = be16_to_cpu(port) % RDS_CONG_MAP_PAGE_BITS;
 
-	return generic_test_le_bit(off, (void *)map->m_page_addrs[i]);
+	return ext2_test_bit(off, (void *)map->m_page_addrs[i]);
 }
 
 void rds_cong_add_socket(struct rds_sock *rs)
Signature · 1 line
1.7.1.231.gd0b16
#5 lore raw

Re: [PATCH 4/5] rds: stop including asm-generic/bitops/le.h directly

net/rds/cong.c void rds_cong_set_bit(struct rds_cong_map *map, __be16 port) · line 287

Quoted 12 lines · Akinobu Mita

asm-generic/bitops/le.h is only intended to be included directly from asm-generic/bitops/ext2-non-atomic.h or asm-generic/bitops/minix-le.h which implements generic ext2 or minix bit operations.

This stops including asm-generic/bitops/le.h directly and use ext2 non-atomic bit operations instead.

An alternative approach is introducing little endian bit operations in linux/bitops.h. But it needs to touch more files than this change does.

net/rds/cong.c +1 -1
-	generic___set_le_bit(off, (void *)map->m_page_addrs[i]);
+	ext2_set_bit(off, (void *)map->m_page_addrs[i]);

I'd like a solution that doesn't have rds calling a function starting with ext2_. Seems wrong.

Thanks -- Regards -- Andy

maintainer
#6 lore raw

Re: [PATCH 4/5] rds: stop including asm-generic/bitops/le.h directly

From: Andy Grover <[email protected]>
Date: Fri, 08 Oct 2010 11:55:55 -0700

Quoted 12 lines · Akinobu Mita
Quoted 10 lines

asm-generic/bitops/le.h is only intended to be included directly from asm-generic/bitops/ext2-non-atomic.h or asm-generic/bitops/minix-le.h which implements generic ext2 or minix bit operations.

This stops including asm-generic/bitops/le.h directly and use ext2 non-atomic bit operations instead.

An alternative approach is introducing little endian bit operations in linux/bitops.h. But it needs to touch more files than this change does.

Quoted 5 lines

net/rds/cong.c void rds_cong_set_bit(struct rds_cong_map *map, __be16 port) · line 287

Quoted 2 lines
net/rds/cong.c +1 -1
-	generic___set_le_bit(off, (void *)map->m_page_addrs[i]);
+	ext2_set_bit(off, (void *)map->m_page_addrs[i]);

I'd like a solution that doesn't have rds calling a function starting with ext2_. Seems wrong.

Agreed.

#7 lore raw

Re: [PATCH 4/5] rds: stop including asm-generic/bitops/le.h directly

2010/10/9 David Miller <[email protected]>:

Quoted 15 lines

From: Andy Grover <[email protected]>
Date: Fri, 08 Oct 2010 11:55:55 -0700

Quoted 12 lines · Akinobu Mita
Quoted 10 lines

asm-generic/bitops/le.h is only intended to be included directly from asm-generic/bitops/ext2-non-atomic.h or asm-generic/bitops/minix-le.h which implements generic ext2 or minix bit operations.

This stops including asm-generic/bitops/le.h directly and use ext2 non-atomic bit operations instead.

An alternative approach is introducing little endian bit operations in linux/bitops.h. But it needs to touch more files than this change does.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

-    generic___set_le_bit(off, (void *)map->m_page_addrs[i]);
+    ext2_set_bit(off, (void *)map->m_page_addrs[i]);

I'd like a solution that doesn't have rds calling a function starting with ext2_. Seems wrong.

Agreed.

OK, I'll rewrite the patch series to take the alternative approach.

#8 lore raw

PATCH 5/5 bitops: forbid asm-generic/bitops/le.h direct inclusion

In reply to Akinobu Mita

asm-generic/bitops/le.h is only intended to be included directly from asm-generic/bitops/ext2-non-atomic.h or asm-generic/bitops/minix-le.h which implements generic ext2 or minix bit operations.

But there were some source files that include it directly. (those are already fixed by other commits)

This forbids asm-generic/bitops/le.h direct inclusion in the future.

---
 include/asm-generic/bitops/le.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
include/asm-generic/bitops/le.h +5 -0
index db2be81..f8d0225 100644
@@ -1,6 +1,11 @@
 #ifndef _ASM_GENERIC_BITOPS_LE_H_
 #define _ASM_GENERIC_BITOPS_LE_H_
 
+#if !defined(_ASM_GENERIC_BITOPS_MINIX_LE_H_) && \
+	!defined(_ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_)
+#error only minix-le.h and ext2-non-atomic.h can be included directly
+#endif
+
 #include <asm/types.h>
 #include <asm/byteorder.h>
 
Signature · 1 line
1.7.1.231.gd0b16
#9 lore raw
In reply to Akinobu Mita
Quoted 5 lines · Akinobu Mita

This introduces asm-generic header file for generic implementation of ext2 atomic bit operations by test_and_set_bit() and test_and_clear_bit().

alpha, arm, cris, frv, ia64, m68k, mn10300, parisc, powerpc, s390, sparc64, x86, xtensa can use this header file in its asm/bitops.h.

Care to rename the functions to le_* instead of ext2_* while you're at it and documenting their semantics?

#10 lore raw

2010/10/8 Christoph Hellwig <[email protected]>:

Quoted 9 lines · Akinobu Mita
Quoted 5 lines

This introduces asm-generic header file for generic implementation of ext2 atomic bit operations by test_and_set_bit() and test_and_clear_bit().

alpha, arm, cris, frv, ia64, m68k, mn10300, parisc, powerpc, s390, sparc64, x86, xtensa can use this header file in its asm/bitops.h.

Care to rename the functions to le_* instead of ext2_* while you're at it and documenting their semantics?

OK, as several people requested in another threads, I'll introduce little endian bit operations for all architectures and rename ext2 bitops to le bitops.

BTW, I have a question about ext2 atomic bit operations.

Some architectures use spinlock to implement it (asm-generic/bitops/ext2-atomic.h). Most other architectures use test_and_set_bit() and test_and_clear_bit() as this patch shows.

Why are there two implementations? test_and_{set,clear}_bit() are more costly operations than spinlock for some architectures?

maintainer
#11 lore raw
Quoted 6 lines · On Sunday 10 October 2010 17:07:26 Akinobu Mita wrote:

Some architectures use spinlock to implement it (asm-generic/bitops/ext2-atomic.h). Most other architectures use test_and_set_bit() and test_and_clear_bit() as this patch shows.

Why are there two implementations? test_and_{set,clear}_bit() are more costly operations than spinlock for some architectures?

I would guess that is only true on architectures that implement all atomics using a hashed spinlock like cris, sparc32 or parisc. This way the user can decide which spinlock to use rather than have the arch code calculate a hash on the pointer.

This is an ext2 specific micro-optimization that I don't think makes sense in the generic le bitops code.

Arnd

#12 lore raw

2010/10/11 Arnd Bergmann <[email protected]>:

Quoted 5 lines · On Sunday 10 October 2010 17:07:26 Akinobu Mita wrote:
Quoted 4 lines

Some architectures use spinlock to implement it (asm-generic/bitops/ext2-atomic.h). Most other architectures use test_and_set_bit() and test_and_clear_bit() as this patch shows.

Quoted 7 lines
Quoted 2 lines

Why are there two implementations? test_and_{set,clear}_bit() are more costly operations than spinlock for some architectures?

I would guess that is only true on architectures that implement all atomics using a hashed spinlock like cris, sparc32 or parisc. This way the user can decide which spinlock to use rather than have the arch code calculate a hash on the pointer.

Thanks. It looks quite right.

Quoted 2 lines

This is an ext2 specific micro-optimization that I don't think makes sense in the generic le bitops code.

OK, I'll only rename ext2 non-atomic bitops to le bitops and keep ext2 atomic bitops for now.