Skip to contentSkip to conversation

swiotlb: replace free array with bitmap

PATCH In review Jon Mason 2 participants 2 messages May 4, 2006 – May 7, 2006 Library code

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

PATCH 3/3 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 aperature. So for the default SWIOTLB aperature size of 64MB, the io_tlb_list array is 1MB. The bitmap is 1/2000 the size of the aperature. So for the default SWIOTLB aperature 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 62dc1eb0c5e2 -r 99976643895a 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 62dc1eb0c5e2 -r 99976643895a 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 +37 -75

202 lines not on this page · raw message

arch/ia64/lib/bitstr.c new file +30 -0
diff -r 62dc1eb0c5e2 -r 99976643895a 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);
#1 lore raw

lib/swiotlb.c line 322

Quoted 7 lines · Jon Mason
lib/swiotlb.c +7 -0
+		index = find_next_zero_string(io_tlb_list, io_tlb_index,
+				io_tlb_nslabs, nslots);
+		if (index = ~0U) {
+			index = find_next_zero_string(io_tlb_list, 0,
+					io_tlb_nslabs, nslots);
+			if (index = ~0U)
+				return NULL;

If we run out of space in the bitmap we return here with the io_tlb_lock held. Also, an informative message saying that we've run out of space in the bitmap is probably a good idea.

Cheers,
Muli