Skip to contentSkip to conversation

swiotlb: replace free array with bitmap

PATCH New Jon Mason 1 participant 1 message May 10, 2006 Library code

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

PATCH 5/5 swiotlb: replace free array with bitmap

This patch removes the io_tlb_list array used to keep track of the bounce buffers available, and replaces it with a bitmap with the same name. The benefit in doing this is the reduction in memory between the two (and simplification of the code).

The array is 1/64 the size of the aperture. So for the default SWIOTLB aperture size of 64MB, the io_tlb_list array is 1MB. The bitmap is 1/2000 the size of the aperture. So for the default SWIOTLB aperture size of 64MB, the bitmap is 32kB.

This necessitates the addition of some string handling functions in ia64.

This patch has been tested individually and cumulatively on x86_64 and cross-compile tested on IA64. Since I have no IA64 hardware, any testing on that platform would be appreciated.

Thanks,
Jon

arch/ia64/lib/Makefile +1 -1
diff -r c3a828849dd4 -r ae6b9f9e155e arch/ia64/lib/Makefile
@@ -9,7 +9,7 @@
 	checksum.o clear_page.o csum_partial_copy.o			\
 	clear_user.o strncpy_from_user.o strlen_user.o strnlen_user.o	\
 	flush.o ip_fast_csum.o do_csum.o				\
-	memset.o strlen.o
+	memset.o strlen.o bitstr.o
 
 lib-$(CONFIG_ITANIUM)	+= copy_page.o copy_user.o memcpy.o
 lib-$(CONFIG_MCKINLEY)	+= copy_page_mck.o memcpy_mck.o
include/asm-ia64/bitops.h +26 -0
diff -r c3a828849dd4 -r ae6b9f9e155e include/asm-ia64/bitops.h
@@ -372,6 +372,32 @@
 #define hweight16(x)	(unsigned int) hweight64((x) & 0xfffful)
 #define hweight8(x)	(unsigned int) hweight64((x) & 0xfful)
 
+/*
+ * Find string of zero bits in a bitmap. -1 when not found.
+ */
+extern unsigned long 
+find_next_zero_string(unsigned long *bitmap, long start, long nbits, int len);
+
+static inline void set_bit_string(unsigned long *bitmap, unsigned long i,
+				  int len)
+{
+	unsigned long end = i + len;
+	while (i < end) {
+		__set_bit(i, bitmap);
+		i++;
+	}
+}
+
+static inline void __clear_bit_string(unsigned long *bitmap, unsigned long i,
+				    int len)
+{
+	unsigned long end = i + len;
+	while (i < end) {
+		__clear_bit(i, bitmap);
+		i++;
+	}
+}
+
 #endif /* __KERNEL__ */
 
 #include <asm-generic/bitops/find.h>
lib/swiotlb.c +66 -98

272 lines not on this page · raw message

arch/ia64/lib/bitstr.c new file +30 -0
diff -r c3a828849dd4 -r ae6b9f9e155e arch/ia64/lib/bitstr.c
@@ -0,0 +1,30 @@
+/* Copied from arch/x86_64/lib/bitstr.c for IA64 usage. */
+
+#include <linux/module.h>
+#include <linux/bitops.h>
+
+/* Find string of zero bits in a bitmap */
+unsigned long
+find_next_zero_string(unsigned long *bitmap, long start, long nbits, int len)
+{
+	unsigned long n, end, i;
+
+ again:
+	n = find_next_zero_bit(bitmap, nbits, start);
+	if (n = -1) 
+		return -1;
+
+	/* could test bitsliced, but it's hardly worth it */
+	end = n+len;
+	if (end >= nbits)
+		return -1;
+	for (i = n+1; i < end; i++) {
+		if (test_bit(i, bitmap)) {
+			start = i+1;
+			goto again;
+		}
+	}
+	return n;
+}
+
+EXPORT_SYMBOL(find_next_zero_string);